uarti2cspi  2.0.0.0
uarti2cspi.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 UARTI2CSPI_H
36 #define UARTI2CSPI_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 #include "drv_spi_master.h"
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define UARTI2CSPI_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
56  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
57  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
58  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
59  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
60  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
61  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
62  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
63 
69 #define UARTI2CSPI_MASTER_I2C 0
70 #define UARTI2CSPI_MASTER_SPI 1
71 
77 #define UARTI2CSPI_RETVAL uint8_t
78 
79 #define UARTI2CSPI_OK 0x00
80 #define UARTI2CSPI_INIT_ERROR 0xFF
81 
87 #define UARTI2CSPI_OSCILATOR_FREQ 1843200.0
88 #define UARTI2CSPI_PRESCALER_DEF 1.0
89 #define UARTI2CSPI_ADDR 0x48
90 #define UARTI2CSPI_RHR 0x00 << 3
91 #define UARTI2CSPI_THR 0x00 << 3
92 #define UARTI2CSPI_IER 0x01 << 3
93 #define UARTI2CSPI_FCR 0x02 << 3
94 #define UARTI2CSPI_IIR 0x02 << 3
95 #define UARTI2CSPI_LCR 0x03 << 3
96 #define UARTI2CSPI_MCR 0x04 << 3
97 #define UARTI2CSPI_LSR 0x05 << 3
98 #define UARTI2CSPI_MSR 0x06 << 3
99 #define UARTI2CSPI_SPR 0x07 << 3
100 #define UARTI2CSPI_TCR 0x06 << 3
101 #define UARTI2CSPI_TLR 0x07 << 3
102 #define UARTI2CSPI_TXLVL 0x08 << 3
103 #define UARTI2CSPI_RXLVL 0x09 << 3
104 #define UARTI2CSPI_EFCR 0x0F << 3
105 
111 #define UARTI2CSPI_DLL 0x00 << 3
112 #define UARTI2CSPI_DLH 0x01 << 3
113 
114 #define UARTI2CSPI_EFR 0x02 << 3
115 #define UARTI2CSPI_XON1 0x04 << 3
116 #define UARTI2CSPI_XON2 0x05 << 3
117 #define UARTI2CSPI_XOFF1 0x06 << 3
118 #define UARTI2CSPI_XOFF2 0x07 << 3
119 
125 #define UARTI2CSPI_UART_5_BIT_DATA 0x00
126 #define UARTI2CSPI_UART_6_BIT_DATA 0x01
127 #define UARTI2CSPI_UART_7_BIT_DATA 0x02
128 #define UARTI2CSPI_UART_8_BIT_DATA 0x03
129 #define UARTI2CSPI_UART_NOPARITY 0x00
130 #define UARTI2CSPI_UART_EVENPARITY 0x18
131 #define UARTI2CSPI_UART_ODDPARITY 0x08
132 #define UARTI2CSPI_UART_PARITY_ONE 0x38
133 #define UARTI2CSPI_UART_PARITY_ZERO 0x28
134 #define UARTI2CSPI_UART_ONE_STOPBIT 0x00
135 #define UARTI2CSPI_UART_TWO_STOPBITS 0x04
136 
142 #define UARTI2CSPI_CTS_INT_EN 0x80
143 #define UARTI2CSPI_RTS_INT_EN 0x40
144 #define UARTI2CSPI_XOFF_INT_EN 0x20
145 #define UARTI2CSPI_SLEEP_INT_EN 0x10
146 #define UARTI2CSPI_MODEM_STATUS_INT_EN 0x08
147 #define UARTI2CSPI_RECEIVE_LINE_STATUS_INT_EN 0x04
148 #define UARTI2CSPI_THR_EMPTY_INT_EN 0x02
149 #define UARTI2CSPI_RXD_INT_EN 0x01
150 
156 #define UARTI2CSPI_DATA_READY 0x01
157 #define UARTI2CSPI_DATA_NOT_READY 0x00
158  // End group macro
160 // --------------------------------------------------------------- PUBLIC TYPES
169 typedef uint8_t uarti2cspi_select_t;
170 
174 typedef void ( *uarti2cspi_master_write_t )( struct uarti2cspi_s*, uint8_t, uint8_t );
175 typedef void ( *uarti2cspi_master_read_t )( struct uarti2cspi_s*, uint8_t, uint8_t* );
176 
180 typedef struct uarti2cspi_s
181 {
182  // Output pins
183 
184  digital_out_t cs;
185  digital_out_t rst;
186 
187  // Input pins
188 
189  digital_in_t int_pin;
190 
191  // Modules
192 
193  i2c_master_t i2c;
194  spi_master_t spi;
195 
196  // ctx variable
197 
198  uint8_t slave_address;
199  pin_name_t chip_select;
203 
205 
209 typedef struct
210 {
211  // Communication gpio pins
212 
213  pin_name_t scl;
214  pin_name_t sda;
215  pin_name_t miso;
216  pin_name_t mosi;
217  pin_name_t sck;
218  pin_name_t cs;
219 
220  // Additional gpio pins
221 
222  pin_name_t rst;
223  pin_name_t int_pin;
224 
225  // static variable
226 
227  uint32_t i2c_speed;
228  uint8_t i2c_address;
229 
230  uint32_t spi_speed;
231  spi_master_mode_t spi_mode;
232  spi_master_chip_select_polarity_t cs_polarity;
233 
235 
237  // End types group
239 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
245 #ifdef __cplusplus
246 extern "C"{
247 #endif
248 
258 
268 
279 void uarti2cspi_generic_write ( uarti2cspi_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
280 
291 void uarti2cspi_generic_read ( uarti2cspi_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
292 
301 void uarti2cspi_set_reset ( uarti2cspi_t *ctx, uint8_t state );
302 
314 void uarti2cspi_advanced_init ( uarti2cspi_t *ctx, uint32_t baud_rate, uint8_t data_bits,
315  uint8_t parity_mode, uint8_t stop_bits );
316 
326 void uarti2cspi_interrupt_enable ( uarti2cspi_t *ctx, uint8_t vector );
327 
336 void uarti2cspi_uart_write_text ( uarti2cspi_t *ctx, uint8_t *w_text );
337 
346 void uarti2cspi_uart_write ( uarti2cspi_t *ctx, uint8_t w_byte );
347 
359 
370 
371 #ifdef __cplusplus
372 }
373 #endif
374 #endif // _UARTI2CSPI_H_
375  // End public_function group
378 
379 // ------------------------------------------------------------------------- END
uarti2cspi_cfg_t::sck
pin_name_t sck
Definition: uarti2cspi.h:217
uarti2cspi_master_write_t
void(* uarti2cspi_master_write_t)(struct uarti2cspi_s *, uint8_t, uint8_t)
Master Input/Output type.
Definition: uarti2cspi.h:174
uarti2cspi_cfg_t::sel
uarti2cspi_select_t sel
Definition: uarti2cspi.h:234
uarti2cspi_s::slave_address
uint8_t slave_address
Definition: uarti2cspi.h:198
uarti2cspi_cfg_t
Click configuration structure definition.
Definition: uarti2cspi.h:210
uarti2cspi_init
UARTI2CSPI_RETVAL uarti2cspi_init(uarti2cspi_t *ctx, uarti2cspi_cfg_t *cfg)
Initialization function.
UARTI2CSPI_RETVAL
#define UARTI2CSPI_RETVAL
Definition: uarti2cspi.h:77
uarti2cspi_cfg_t::int_pin
pin_name_t int_pin
Definition: uarti2cspi.h:223
uarti2cspi_cfg_t::cs
pin_name_t cs
Definition: uarti2cspi.h:218
uarti2cspi_interrupt_enable
void uarti2cspi_interrupt_enable(uarti2cspi_t *ctx, uint8_t vector)
Interrupt enable function.
uarti2cspi_cfg_t::i2c_address
uint8_t i2c_address
Definition: uarti2cspi.h:228
uarti2cspi_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: uarti2cspi.h:227
uarti2cspi_s::spi
spi_master_t spi
Definition: uarti2cspi.h:194
uarti2cspi_generic_read
void uarti2cspi_generic_read(uarti2cspi_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uarti2cspi_select_t
uint8_t uarti2cspi_select_t
Communication type.
Definition: uarti2cspi.h:169
uarti2cspi_uart_write
void uarti2cspi_uart_write(uarti2cspi_t *ctx, uint8_t w_byte)
Uart write function.
uarti2cspi_s::read_f
uarti2cspi_master_read_t read_f
Definition: uarti2cspi.h:201
uarti2cspi_uart_read
uint8_t uarti2cspi_uart_read(uarti2cspi_t *ctx)
Uart read function.
uarti2cspi_generic_write
void uarti2cspi_generic_write(uarti2cspi_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uarti2cspi_cfg_t::rst
pin_name_t rst
Definition: uarti2cspi.h:222
uarti2cspi_s
Click ctx object definition.
Definition: uarti2cspi.h:181
uarti2cspi_cfg_t::mosi
pin_name_t mosi
Definition: uarti2cspi.h:216
uarti2cspi_advanced_init
void uarti2cspi_advanced_init(uarti2cspi_t *ctx, uint32_t baud_rate, uint8_t data_bits, uint8_t parity_mode, uint8_t stop_bits)
Advanced initialization function.
uarti2cspi_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: uarti2cspi.h:232
uarti2cspi_set_reset
void uarti2cspi_set_reset(uarti2cspi_t *ctx, uint8_t state)
Set RST pin state function.
uarti2cspi_uart_data_ready
uint8_t uarti2cspi_uart_data_ready(uarti2cspi_t *ctx)
Uart data ready function.
uarti2cspi_cfg_t::spi_speed
uint32_t spi_speed
Definition: uarti2cspi.h:230
uarti2cspi_t
struct uarti2cspi_s uarti2cspi_t
Click ctx object definition.
uarti2cspi_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: uarti2cspi.h:231
uarti2cspi_s::int_pin
digital_in_t int_pin
Definition: uarti2cspi.h:189
uarti2cspi_s::chip_select
pin_name_t chip_select
Definition: uarti2cspi.h:199
uarti2cspi_s::cs
digital_out_t cs
Definition: uarti2cspi.h:184
uarti2cspi_cfg_t::scl
pin_name_t scl
Definition: uarti2cspi.h:213
uarti2cspi_cfg_t::miso
pin_name_t miso
Definition: uarti2cspi.h:215
uarti2cspi_cfg_t::sda
pin_name_t sda
Definition: uarti2cspi.h:214
uarti2cspi_s::i2c
i2c_master_t i2c
Definition: uarti2cspi.h:193
uarti2cspi_s::master_sel
uarti2cspi_select_t master_sel
Definition: uarti2cspi.h:202
uarti2cspi_s::write_f
uarti2cspi_master_write_t write_f
Definition: uarti2cspi.h:200
uarti2cspi_uart_write_text
void uarti2cspi_uart_write_text(uarti2cspi_t *ctx, uint8_t *w_text)
Uart write text function.
uarti2cspi_cfg_setup
void uarti2cspi_cfg_setup(uarti2cspi_cfg_t *cfg)
Config Object Initialization function.
uarti2cspi_master_read_t
void(* uarti2cspi_master_read_t)(struct uarti2cspi_s *, uint8_t, uint8_t *)
Definition: uarti2cspi.h:175
uarti2cspi_s::rst
digital_out_t rst
Definition: uarti2cspi.h:185