rn4870 2.0.0.0
rn4870.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 RN4870_H
36#define RN4870_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_uart.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define RN4870_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69 cfg.rst_n = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70 cfg.uart_rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71 cfg.uart_cts = MIKROBUS( mikrobus, MIKROBUS_INT )
78#define RN4870_RETVAL uint8_t
79
80#define RN4870_OK 0x00
81#define RN4870_INIT_ERROR 0xFF
88#define RN4870_DEVICETYPE_MASTER 0x02
89#define RN4870_DEVICETYPE_SLAVE 0x03
92#define RN4870_ID_MASTER 0x35
93#define RN4870_ID_SLAVE 0x32
94#define RN4870_MTYPE_MSG 'M'
95#define RN4870_DTYPE_STRING 0x5331
96
97
102#define DRV_RX_BUFFER_SIZE 500
105 // End group macro
106// --------------------------------------------------------------- PUBLIC TYPES
114typedef struct
115{
116 // Output pins
117
118 digital_out_t rst_n;
119 digital_out_t uart_rts;
120
121 // Input pins
122
123 digital_in_t uart_cts;
124
125 // Modules
126
127 uart_t uart;
128
129 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
130 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
131
132 uint8_t end_flag;
134
135 char device_buffer[ 255 ];
137
138} rn4870_t;
139
143typedef struct
144{
145 // Communication gpio pins
146
147 pin_name_t rx_pin;
148 pin_name_t tx_pin;
149
150 // Additional gpio pins
151
152 pin_name_t rst_n;
153 pin_name_t uart_rts;
154 pin_name_t uart_cts;
155
156 // static variable
157
158 uint32_t baud_rate; // Clock speed.
160 uart_data_bits_t data_bit; // Data bits.
161 uart_parity_t parity_bit; // Parity bit.
162 uart_stop_bits_t stop_bit; // Stop bits.
163
165
166 // End types group
167// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
168
174#ifdef __cplusplus
175extern "C"{
176#endif
177
187
197
209void rn4870_reset ( rn4870_t *ctx );
210
220void rn4870_generic_write ( rn4870_t *ctx, char *data_buf, uint16_t len );
221
233int32_t rn4870_generic_read ( rn4870_t *ctx, char *data_buf, uint16_t max_len );
234
244uint8_t rn4870_int_get ( rn4870_t *ctx );
245
254void rn4870_rst_set ( rn4870_t *ctx, uint8_t pin_state );
255
264void rn4870_cs_set ( rn4870_t *ctx, uint8_t pin_state );
265
274void rn4870_uart_write ( rn4870_t *ctx, uint8_t * wr_buf );
275
287void rn4870_initialize ( rn4870_t *ctx, char *p_addr );
288
298void rn4870_connect ( rn4870_t *ctx, char *p_addr );
299
311void rn4870_send( rn4870_t *ctx, uint8_t msg_type, uint16_t data_type, uint8_t id, uint8_t *payload );
312
322
334void rn4870_receive ( rn4870_t *ctx, char tmp );
335
348uint8_t rn4870_read ( rn4870_t *ctx, uint8_t *process_buffer );
349
350#ifdef __cplusplus
351}
352#endif
353#endif // _RN4870_H_
354
355 // End public_function group
357
358// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition rn4870.h:102
#define RN4870_RETVAL
Definition rn4870.h:78
void rn4870_disconnect(rn4870_t *ctx)
Disconnecting from slave device.
uint8_t rn4870_int_get(rn4870_t *ctx)
Get interrupt state function.
RN4870_RETVAL rn4870_init(rn4870_t *ctx, rn4870_cfg_t *cfg)
Initialization function.
void rn4870_cs_set(rn4870_t *ctx, uint8_t pin_state)
Set states of CS pin to desired state.
uint8_t rn4870_read(rn4870_t *ctx, uint8_t *process_buffer)
Reading received message.
void rn4870_receive(rn4870_t *ctx, char tmp)
Receiving character function.
void rn4870_send(rn4870_t *ctx, uint8_t msg_type, uint16_t data_type, uint8_t id, uint8_t *payload)
Send message function.
void rn4870_cfg_setup(rn4870_cfg_t *cfg)
Config Object Initialization function.
int32_t rn4870_generic_read(rn4870_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void rn4870_reset(rn4870_t *ctx)
Hardware reset function.
void rn4870_rst_set(rn4870_t *ctx, uint8_t pin_state)
Set states of RST pin to desired state.
void rn4870_generic_write(rn4870_t *ctx, char *data_buf, uint16_t len)
Generic write function.
void rn4870_uart_write(rn4870_t *ctx, uint8_t *wr_buf)
UART write function.
void rn4870_connect(rn4870_t *ctx, char *p_addr)
Connecting to slave device.
void rn4870_initialize(rn4870_t *ctx, char *p_addr)
Initialization RN4870 module.
Click configuration structure definition.
Definition rn4870.h:144
uint32_t baud_rate
Definition rn4870.h:158
pin_name_t rst_n
Definition rn4870.h:152
pin_name_t uart_rts
Definition rn4870.h:153
bool uart_blocking
Definition rn4870.h:159
uart_data_bits_t data_bit
Definition rn4870.h:160
pin_name_t tx_pin
Definition rn4870.h:148
pin_name_t rx_pin
Definition rn4870.h:147
uart_stop_bits_t stop_bit
Definition rn4870.h:162
uart_parity_t parity_bit
Definition rn4870.h:161
pin_name_t uart_cts
Definition rn4870.h:154
Click ctx object definition.
Definition rn4870.h:115
digital_in_t uart_cts
Definition rn4870.h:123
uint8_t buffer_position
Definition rn4870.h:136
digital_out_t uart_rts
Definition rn4870.h:119
uart_t uart
Definition rn4870.h:127
uint8_t end_flag
Definition rn4870.h:132
digital_out_t rst_n
Definition rn4870.h:118
uint8_t sentence_flag
Definition rn4870.h:133