llci2c  2.0.0.0
llcspi.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef LLCSPI_H
36 #define LLCSPI_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define LLCSPI_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
59 
65 #define LLCSPI_RETVAL uint8_t
66 
67 #define LLCSPI_OK 0x00
68 #define LLCSPI_INIT_ERROR 0xFF
69 
75 #define NULL 0
76  // End group macro
79 // --------------------------------------------------------------- PUBLIC TYPES
88 typedef struct
89 {
90  // Modules
91 
92  spi_master_t spi;
93 
94 } llcspi_t;
95 
99 typedef struct
100 {
101  // Communication gpio pins
102 
103  pin_name_t miso;
104  pin_name_t mosi;
105  pin_name_t sck;
106  pin_name_t cs;
107 
108  // static variable
109 
110  hal_spi_speed_t spi_speed;
111  hal_spi_mode_t spi_mode;
112 
113 } llcspi_cfg_t;
114  // End types group
116 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
117 
122 #ifdef __cplusplus
123 extern "C"{
124 #endif
125 
134 void llcspi_cfg_setup ( llcspi_cfg_t *cfg );
135 
144 
153 void llcspi_generic_transfer ( llcspi_t *ctx, spi_master_transfer_data_t *block );
154 
161 void spillc_set_cs_pin ( llcspi_t *ctx, uint8_t state);
162 
175 void spillc_generic_write ( llcspi_t *ctx, uint8_t *p_buf, uint16_t n_bytes );
176 
189 void spillc_generic_read ( llcspi_t *ctx, uint8_t *p_buf, uint16_t n_bytes );
190 
191 #ifdef __cplusplus
192 }
193 #endif
194 #endif // _LLCSPI_H_
195  // End public_function group
198 
199 // ------------------------------------------------------------------------- END
llcspi_cfg_t::spi_mode
hal_spi_mode_t spi_mode
Definition: llcspi.h:111
LLCSPI_RETVAL
#define LLCSPI_RETVAL
Definition: llcspi.h:65
llcspi_t
Click ctx object definition.
Definition: llcspi.h:88
spillc_generic_write
void spillc_generic_write(llcspi_t *ctx, uint8_t *p_buf, uint16_t n_bytes)
LLC SPI write.
llcspi_cfg_t::sck
pin_name_t sck
Definition: llcspi.h:105
llcspi_cfg_t::cs
pin_name_t cs
Definition: llcspi.h:106
llcspi_cfg_t::miso
pin_name_t miso
Definition: llcspi.h:103
spillc_generic_read
void spillc_generic_read(llcspi_t *ctx, uint8_t *p_buf, uint16_t n_bytes)
LLC SPI read.
llcspi_cfg_t
Click configuration structure definition.
Definition: llcspi.h:99
llcspi_generic_transfer
void llcspi_generic_transfer(llcspi_t *ctx, spi_master_transfer_data_t *block)
Generic transfer function.
llcspi_cfg_t::mosi
pin_name_t mosi
Definition: llcspi.h:104
llcspi_t::spi
spi_master_t spi
Definition: llcspi.h:92
llcspi_cfg_t::spi_speed
hal_spi_speed_t spi_speed
Definition: llcspi.h:110
llcspi_cfg_setup
void llcspi_cfg_setup(llcspi_cfg_t *cfg)
Config Object Initialization function.
spillc_set_cs_pin
void spillc_set_cs_pin(llcspi_t *ctx, uint8_t state)
Function for set CS pin state.
llcspi_init
LLCSPI_RETVAL llcspi_init(llcspi_t *ctx, llcspi_cfg_t *cfg)
Initialization function.