b102c  2.1.0.0
b102c.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef B102C_H
29 #define B102C_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_uart.h"
52 
73 #define B102C_CMD_AT "AT"
74 #define B102C_CMD_RESET "AT+RESET"
75 #define B102C_CMD_LADDR "AT+LADDR"
76 #define B102C_CMD_NAME "AT+NAME"
77 #define B102C_CMD_PIN "AT+PIN"
78 #define B102C_CMD_BAUD "AT+BAUD"
79 #define B102C_CMD_ADVMOD "AT+ADVMOD"
80 #define B102C_CMD_ADVEN "AT+ADVEN"
81 #define B102C_CMD_ADVINT "AT+ADVINT"
82 #define B102C_CMD_POWER "AT+POWER"
83 #define B102C_CMD_ROLE "AT+ROLE"
84 #define B102C_CMD_INQ "AT+INQ"
85 #define B102C_CMD_SINQ "AT+SINQ"
86 #define B102C_CMD_SCANRLT "AT+SCANRLT"
87 #define B102C_CMD_CONN "AT+CONN"
88 #define B102C_CMD_SLEEP "AT+SLEEP"
89 #define B102C_CMD_PAIR "AT+PAIR"
90 #define B102C_CMD_DEFAULT "AT+DEFAULT"
91 #define B102C_CMD_XXX "AT+XXX"
92 #define B102C_CMD_ENTERDTS "AT+ENTERDTS"
93 #define B102C_CMD_GPIOCFG "AT+GPIOCFG"
94 #define B102C_CMD_RSSI "AT+RSSI"
95 #define B102C_CMD_MUUID "AT+MUUID"
96 
101 #define B102C_RSP_OK "OK"
102 #define B102C_RSP_ERROR "ERR"
103 #define B102C_RSP_READY "Ready"
104 
109 #define B102C_PIN_STATE_HIGH 0x01
110 #define B102C_PIN_STATE_LOW 0x00
111 
117 #define B102C_TX_DRV_BUFFER_SIZE 100
118 #define B102C_RX_DRV_BUFFER_SIZE 300
119  // b102c_cmd
121 
136 #define B102C_MAP_MIKROBUS( cfg, mikrobus ) \
137  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
138  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
139  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
140  // b102c_map // b102c
143 
148 typedef struct
149 {
150  // Output pins
151  digital_out_t rst;
153  // Modules
154  uart_t uart;
156  // Buffers
157  uint8_t uart_rx_buffer[ B102C_RX_DRV_BUFFER_SIZE ];
158  uint8_t uart_tx_buffer[ B102C_TX_DRV_BUFFER_SIZE ];
160 } b102c_t;
161 
166 typedef struct
167 {
168  // Communication gpio pins
169  pin_name_t rx_pin;
170  pin_name_t tx_pin;
172  // Additional gpio pins
173  pin_name_t rst;
175  // Static variable
176  uint32_t baud_rate;
178  uart_data_bits_t data_bit;
179  uart_parity_t parity_bit;
180  uart_stop_bits_t stop_bit;
182 } b102c_cfg_t;
183 
188 typedef enum
189 {
190  B102C_OK = 0,
193  B102C_TIMEOUT = -3
194 
196 
213 
227 err_t b102c_init ( b102c_t *ctx, b102c_cfg_t *cfg );
228 
241 err_t b102c_default_cfg ( b102c_t *ctx );
242 
255 err_t b102c_generic_write ( b102c_t *ctx, uint8_t *data_in, uint16_t len );
256 
269 err_t b102c_generic_read ( b102c_t *ctx, uint8_t *data_out, uint16_t len );
270 
280 void b102c_set_rst_pin ( b102c_t *ctx, uint8_t pin_state );
281 
290 void b102c_hw_reset ( b102c_t *ctx );
291 
301 void b102c_send_cmd ( b102c_t *ctx, uint8_t *cmd );
302 
313 void b102c_send_cmd_with_params ( b102c_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
314 
324 void b102c_send_cmd_check ( b102c_t *ctx, uint8_t *at_cmd_buf );
325 
335 void b102c_send_cmd_params_check ( b102c_t *ctx, uint8_t *at_cmd_buf );
336 
337 #ifdef __cplusplus
338 }
339 #endif
340 #endif // B102C_H
341  // b102c
343 
344 // ------------------------------------------------------------------------ END
b102c_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: b102c.h:179
B102C_OVERFLOW
@ B102C_OVERFLOW
Definition: b102c.h:192
B102C_RX_DRV_BUFFER_SIZE
#define B102C_RX_DRV_BUFFER_SIZE
Definition: b102c.h:118
b102c_generic_read
err_t b102c_generic_read(b102c_t *ctx, uint8_t *data_out, uint16_t len)
B102C data reading function.
b102c_cfg_setup
void b102c_cfg_setup(b102c_cfg_t *cfg)
B102C configuration object setup function.
b102c_cfg_t::uart_blocking
bool uart_blocking
Definition: b102c.h:177
b102c_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: b102c.h:178
b102c_generic_write
err_t b102c_generic_write(b102c_t *ctx, uint8_t *data_in, uint16_t len)
B102C data writing function.
b102c_hw_reset
void b102c_hw_reset(b102c_t *ctx)
B102C hardware reset function.
b102c_return_value_t
b102c_return_value_t
B102C Click return value data.
Definition: b102c.h:189
b102c_cfg_t::rx_pin
pin_name_t rx_pin
Definition: b102c.h:169
B102C_TIMEOUT
@ B102C_TIMEOUT
Definition: b102c.h:193
b102c_send_cmd_check
void b102c_send_cmd_check(b102c_t *ctx, uint8_t *at_cmd_buf)
B102C check the sent command.
b102c_send_cmd_params_check
void b102c_send_cmd_params_check(b102c_t *ctx, uint8_t *at_cmd_buf)
B102C check the command parameters.
b102c_default_cfg
err_t b102c_default_cfg(b102c_t *ctx)
B102C default configuration function.
b102c_cfg_t::rst
pin_name_t rst
Definition: b102c.h:173
B102C_ERROR
@ B102C_ERROR
Definition: b102c.h:191
b102c_t::uart
uart_t uart
Definition: b102c.h:154
b102c_send_cmd
void b102c_send_cmd(b102c_t *ctx, uint8_t *cmd)
B102C send command function.
B102C_OK
@ B102C_OK
Definition: b102c.h:190
b102c_set_rst_pin
void b102c_set_rst_pin(b102c_t *ctx, uint8_t pin_state)
B102C set RST pin state function.
B102C_TX_DRV_BUFFER_SIZE
#define B102C_TX_DRV_BUFFER_SIZE
B102C driver buffer size.
Definition: b102c.h:117
b102c_cfg_t::baud_rate
uint32_t baud_rate
Definition: b102c.h:176
b102c_t::rst
digital_out_t rst
Definition: b102c.h:151
b102c_init
err_t b102c_init(b102c_t *ctx, b102c_cfg_t *cfg)
B102C initialization function.
b102c_send_cmd_with_params
void b102c_send_cmd_with_params(b102c_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
B102C send command function with parameter.
b102c_cfg_t::tx_pin
pin_name_t tx_pin
Definition: b102c.h:170
b102c_cfg_t
B102C Click configuration object.
Definition: b102c.h:167
b102c_t
B102C Click context object.
Definition: b102c.h:149
b102c_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: b102c.h:180