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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55#include "drv_spi_master.h"
56
57// -------------------------------------------------------------- PUBLIC MACROS
68#define UARTI2CSPI_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
70 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
71 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
72 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
73 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
74 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
75 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
76 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
83#define UARTI2CSPI_MASTER_I2C 0
84#define UARTI2CSPI_MASTER_SPI 1
91#define UARTI2CSPI_RETVAL uint8_t
92
93#define UARTI2CSPI_OK 0x00
94#define UARTI2CSPI_INIT_ERROR 0xFF
101#define UARTI2CSPI_OSCILATOR_FREQ 1843200.0
102#define UARTI2CSPI_PRESCALER_DEF 1.0
103#define UARTI2CSPI_ADDR 0x48
104#define UARTI2CSPI_RHR 0x00 << 3
105#define UARTI2CSPI_THR 0x00 << 3
106#define UARTI2CSPI_IER 0x01 << 3
107#define UARTI2CSPI_FCR 0x02 << 3
108#define UARTI2CSPI_IIR 0x02 << 3
109#define UARTI2CSPI_LCR 0x03 << 3
110#define UARTI2CSPI_MCR 0x04 << 3
111#define UARTI2CSPI_LSR 0x05 << 3
112#define UARTI2CSPI_MSR 0x06 << 3
113#define UARTI2CSPI_SPR 0x07 << 3
114#define UARTI2CSPI_TCR 0x06 << 3
115#define UARTI2CSPI_TLR 0x07 << 3
116#define UARTI2CSPI_TXLVL 0x08 << 3
117#define UARTI2CSPI_RXLVL 0x09 << 3
118#define UARTI2CSPI_EFCR 0x0F << 3
125#define UARTI2CSPI_DLL 0x00 << 3
126#define UARTI2CSPI_DLH 0x01 << 3
127
128#define UARTI2CSPI_EFR 0x02 << 3
129#define UARTI2CSPI_XON1 0x04 << 3
130#define UARTI2CSPI_XON2 0x05 << 3
131#define UARTI2CSPI_XOFF1 0x06 << 3
132#define UARTI2CSPI_XOFF2 0x07 << 3
139#define UARTI2CSPI_UART_5_BIT_DATA 0x00
140#define UARTI2CSPI_UART_6_BIT_DATA 0x01
141#define UARTI2CSPI_UART_7_BIT_DATA 0x02
142#define UARTI2CSPI_UART_8_BIT_DATA 0x03
143#define UARTI2CSPI_UART_NOPARITY 0x00
144#define UARTI2CSPI_UART_EVENPARITY 0x18
145#define UARTI2CSPI_UART_ODDPARITY 0x08
146#define UARTI2CSPI_UART_PARITY_ONE 0x38
147#define UARTI2CSPI_UART_PARITY_ZERO 0x28
148#define UARTI2CSPI_UART_ONE_STOPBIT 0x00
149#define UARTI2CSPI_UART_TWO_STOPBITS 0x04
156#define UARTI2CSPI_CTS_INT_EN 0x80
157#define UARTI2CSPI_RTS_INT_EN 0x40
158#define UARTI2CSPI_XOFF_INT_EN 0x20
159#define UARTI2CSPI_SLEEP_INT_EN 0x10
160#define UARTI2CSPI_MODEM_STATUS_INT_EN 0x08
161#define UARTI2CSPI_RECEIVE_LINE_STATUS_INT_EN 0x04
162#define UARTI2CSPI_THR_EMPTY_INT_EN 0x02
163#define UARTI2CSPI_RXD_INT_EN 0x01
170#define UARTI2CSPI_DATA_READY 0x01
171#define UARTI2CSPI_DATA_NOT_READY 0x00
173 // End group macro
174// --------------------------------------------------------------- PUBLIC TYPES
183typedef uint8_t uarti2cspi_select_t;
184
188struct uarti2cspi_s;
189typedef void ( *uarti2cspi_master_write_t )( struct uarti2cspi_s*, uint8_t, uint8_t );
190typedef void ( *uarti2cspi_master_read_t )( struct uarti2cspi_s*, uint8_t, uint8_t* );
191
195typedef struct uarti2cspi_s
196{
197 // Output pins
198
199 digital_out_t cs;
200 digital_out_t rst;
201
202 // Input pins
203
204 digital_in_t int_pin;
205
206 // Modules
207
208 i2c_master_t i2c;
209 spi_master_t spi;
210
211 // ctx variable
212
214 pin_name_t chip_select;
218
220
224typedef struct
225{
226 // Communication gpio pins
227
228 pin_name_t scl;
229 pin_name_t sda;
230 pin_name_t miso;
231 pin_name_t mosi;
232 pin_name_t sck;
233 pin_name_t cs;
234
235 // Additional gpio pins
236
237 pin_name_t rst;
238 pin_name_t int_pin;
239
240 // static variable
241
242 uint32_t i2c_speed;
243 uint8_t i2c_address;
244
245 uint32_t spi_speed;
246 spi_master_mode_t spi_mode;
247 spi_master_chip_select_polarity_t cs_polarity;
248
250
252
253 // End types group
254// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
260#ifdef __cplusplus
261extern "C"{
262#endif
263
273
283
293void uarti2cspi_generic_write ( uarti2cspi_t *ctx, uint8_t reg, uint8_t data_buf );
294
304void uarti2cspi_generic_read ( uarti2cspi_t *ctx, uint8_t reg, uint8_t *data_buf );
305
314void uarti2cspi_set_reset ( uarti2cspi_t *ctx, uint8_t state );
315
327void uarti2cspi_advanced_init ( uarti2cspi_t *ctx, uint32_t baud_rate, uint8_t data_bits,
328 uint8_t parity_mode, uint8_t stop_bits );
329
339void uarti2cspi_interrupt_enable ( uarti2cspi_t *ctx, uint8_t vector );
340
349void uarti2cspi_uart_write_text ( uarti2cspi_t *ctx, uint8_t *w_text );
350
359void uarti2cspi_uart_write ( uarti2cspi_t *ctx, uint8_t w_byte );
360
372
383
384#ifdef __cplusplus
385}
386#endif
387#endif // _UARTI2CSPI_H_
388
389 // End public_function group
391
392// ------------------------------------------------------------------------- END
#define UARTI2CSPI_RETVAL
Definition uarti2cspi.h:91
void uarti2cspi_uart_write_text(uarti2cspi_t *ctx, uint8_t *w_text)
Uart write text function.
void uarti2cspi_generic_read(uarti2cspi_t *ctx, uint8_t reg, uint8_t *data_buf)
Generic read function.
void uarti2cspi_cfg_setup(uarti2cspi_cfg_t *cfg)
Config Object Initialization function.
uint8_t uarti2cspi_uart_data_ready(uarti2cspi_t *ctx)
Uart data ready function.
uint8_t uarti2cspi_uart_read(uarti2cspi_t *ctx)
Uart read function.
void uarti2cspi_generic_write(uarti2cspi_t *ctx, uint8_t reg, uint8_t data_buf)
Generic write function.
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_RETVAL uarti2cspi_init(uarti2cspi_t *ctx, uarti2cspi_cfg_t *cfg)
Initialization function.
void uarti2cspi_set_reset(uarti2cspi_t *ctx, uint8_t state)
Set RST pin state function.
void uarti2cspi_uart_write(uarti2cspi_t *ctx, uint8_t w_byte)
Uart write function.
void uarti2cspi_interrupt_enable(uarti2cspi_t *ctx, uint8_t vector)
Interrupt enable function.
struct uarti2cspi_s uarti2cspi_t
Click ctx object definition.
void(* uarti2cspi_master_write_t)(struct uarti2cspi_s *, uint8_t, uint8_t)
Definition uarti2cspi.h:189
void(* uarti2cspi_master_read_t)(struct uarti2cspi_s *, uint8_t, uint8_t *)
Definition uarti2cspi.h:190
uint8_t uarti2cspi_select_t
Communication type.
Definition uarti2cspi.h:183
Click configuration structure definition.
Definition uarti2cspi.h:225
uint32_t i2c_speed
Definition uarti2cspi.h:242
spi_master_chip_select_polarity_t cs_polarity
Definition uarti2cspi.h:247
pin_name_t sck
Definition uarti2cspi.h:232
uarti2cspi_select_t sel
Definition uarti2cspi.h:249
spi_master_mode_t spi_mode
Definition uarti2cspi.h:246
pin_name_t mosi
Definition uarti2cspi.h:231
uint32_t spi_speed
Definition uarti2cspi.h:245
pin_name_t scl
Definition uarti2cspi.h:228
pin_name_t int_pin
Definition uarti2cspi.h:238
pin_name_t miso
Definition uarti2cspi.h:230
pin_name_t sda
Definition uarti2cspi.h:229
pin_name_t rst
Definition uarti2cspi.h:237
pin_name_t cs
Definition uarti2cspi.h:233
uint8_t i2c_address
Definition uarti2cspi.h:243
Click ctx object definition.
Definition uarti2cspi.h:196
digital_out_t cs
Definition uarti2cspi.h:199
spi_master_t spi
Definition uarti2cspi.h:209
uarti2cspi_master_read_t read_f
Definition uarti2cspi.h:216
uarti2cspi_select_t master_sel
Definition uarti2cspi.h:217
uarti2cspi_master_write_t write_f
Definition uarti2cspi.h:215
digital_in_t int_pin
Definition uarti2cspi.h:204
i2c_master_t i2c
Definition uarti2cspi.h:208
digital_out_t rst
Definition uarti2cspi.h:200
uint8_t slave_address
Definition uarti2cspi.h:213
pin_name_t chip_select
Definition uarti2cspi.h:214