rn4871 2.0.0.0
rn4871.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 RN4871_H
36#define RN4871_H
37
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_uart.h"
41
42// -------------------------------------------------------------- PUBLIC MACROS
52#define RN4871_MAP_MIKROBUS( cfg, mikrobus ) \
53 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55 cfg.rst_n = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56 cfg.uart_rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57 cfg.uart_cts = MIKROBUS( mikrobus, MIKROBUS_INT )
64#define RN4871_RETVAL uint8_t
65
66#define RN4871_OK 0x00
67#define RN4871_INIT_ERROR 0xFF
74#define RN4871_DEVICETYPE_MASTER 0x02
75#define RN4871_DEVICETYPE_SLAVE 0x03
78#define RN4871_ID_MASTER 0x35
79#define RN4871_ID_SLAVE 0x32
80#define RN4871_MTYPE_MSG 'M'
81#define RN4871_DTYPE_STRING 0x5331
82
83
88#define DRV_RX_BUFFER_SIZE 500 // End group macro
92// --------------------------------------------------------------- PUBLIC TYPES
100typedef struct
101{
102 // Output pins
103
104 digital_out_t rst_n;
105 digital_out_t uart_rts;
106
107 // Input pins
108
109 digital_in_t uart_cts;
110
111 // Modules
112
113 uart_t uart;
114
115 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
116 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
117
118 uint8_t end_flag;
120
121 char device_buffer[ 255 ];
123
124} rn4871_t;
125
129typedef struct
130{
131 // Communication gpio pins
132
133 pin_name_t rx_pin;
134 pin_name_t tx_pin;
135
136 // Additional gpio pins
137
138 pin_name_t rst_n;
139 pin_name_t uart_rts;
140 pin_name_t uart_cts;
141
142 // static variable
143
144 uint32_t baud_rate; // Clock speed.
146 uart_data_bits_t data_bit; // Data bits.
147 uart_parity_t parity_bit; // Parity bit.
148 uart_stop_bits_t stop_bit; // Stop bits.
149
151 // End types group
153// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
154
160#ifdef __cplusplus
161extern "C"{
162#endif
163
173
183
195void rn4871_reset ( rn4871_t *ctx );
196
206void rn4871_generic_write ( rn4871_t *ctx, char *data_buf, uint16_t len );
207
219int32_t rn4871_generic_read ( rn4871_t *ctx, char *data_buf, uint16_t max_len );
220
230uint8_t rn4871_int_get ( rn4871_t *ctx );
231
240void rn4871_rst_set ( rn4871_t *ctx, uint8_t pin_state );
241
250void rn4871_cs_set ( rn4871_t *ctx, uint8_t pin_state );
251
260void rn4871_uart_write ( rn4871_t *ctx, uint8_t * wr_buf );
261
273void rn4871_initialize ( rn4871_t *ctx, char *p_addr );
274
284void rn4871_connect ( rn4871_t *ctx, char *p_addr );
285
297void rn4871_send( rn4871_t *ctx, uint8_t msg_type, uint16_t data_type, uint8_t id, uint8_t *payload );
298
308
320void rn4871_receive ( rn4871_t *ctx, char tmp );
321
334uint8_t rn4871_read ( rn4871_t *ctx, uint8_t *process_buffer );
335
336#ifdef __cplusplus
337}
338#endif
339#endif // _RN4871_H_
340 // End public_function group
343
344// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition: rn4871.h:88
#define RN4871_RETVAL
Definition: rn4871.h:64
RN4871_RETVAL rn4871_init(rn4871_t *ctx, rn4871_cfg_t *cfg)
Initialization function.
void rn4871_disconnect(rn4871_t *ctx)
Disconnecting from slave device.
void rn4871_reset(rn4871_t *ctx)
Hardware reset function.
void rn4871_initialize(rn4871_t *ctx, char *p_addr)
Initialization RN4871 module.
void rn4871_uart_write(rn4871_t *ctx, uint8_t *wr_buf)
UART write function.
void rn4871_cfg_setup(rn4871_cfg_t *cfg)
Config Object Initialization function.
uint8_t rn4871_int_get(rn4871_t *ctx)
Get interrupt state function.
void rn4871_rst_set(rn4871_t *ctx, uint8_t pin_state)
Set states of RST pin to desired state.
void rn4871_receive(rn4871_t *ctx, char tmp)
Receiving character function.
int32_t rn4871_generic_read(rn4871_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void rn4871_send(rn4871_t *ctx, uint8_t msg_type, uint16_t data_type, uint8_t id, uint8_t *payload)
Send message function.
void rn4871_connect(rn4871_t *ctx, char *p_addr)
Connecting to slave device.
uint8_t rn4871_read(rn4871_t *ctx, uint8_t *process_buffer)
Reading received message.
void rn4871_generic_write(rn4871_t *ctx, char *data_buf, uint16_t len)
Generic write function.
void rn4871_cs_set(rn4871_t *ctx, uint8_t pin_state)
Set states of CS pin to desired state.
Click configuration structure definition.
Definition: rn4871.h:130
uint32_t baud_rate
Definition: rn4871.h:144
pin_name_t rst_n
Definition: rn4871.h:138
pin_name_t uart_rts
Definition: rn4871.h:139
bool uart_blocking
Definition: rn4871.h:145
uart_data_bits_t data_bit
Definition: rn4871.h:146
pin_name_t tx_pin
Definition: rn4871.h:134
pin_name_t rx_pin
Definition: rn4871.h:133
uart_stop_bits_t stop_bit
Definition: rn4871.h:148
uart_parity_t parity_bit
Definition: rn4871.h:147
pin_name_t uart_cts
Definition: rn4871.h:140
Click ctx object definition.
Definition: rn4871.h:101
digital_in_t uart_cts
Definition: rn4871.h:109
uint8_t buffer_position
Definition: rn4871.h:122
digital_out_t uart_rts
Definition: rn4871.h:105
uart_t uart
Definition: rn4871.h:113
uint8_t end_flag
Definition: rn4871.h:118
digital_out_t rst_n
Definition: rn4871.h:104
uint8_t sentence_flag
Definition: rn4871.h:119