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
32extern "C"{
33#endif
34
35#include "mikrosdk_version.h"
36
37#ifdef __GNUC__
38#if mikroSDK_GET_VERSION < 20800ul
39#include "rcu_delays.h"
40#else
41#include "delays.h"
42#endif
43#endif
44
45#include "drv_digital_out.h"
46#include "drv_digital_in.h"
47#include "drv_uart.h"
48
69#define B102C_CMD_AT "AT"
70#define B102C_CMD_RESET "AT+RESET"
71#define B102C_CMD_LADDR "AT+LADDR"
72#define B102C_CMD_NAME "AT+NAME"
73#define B102C_CMD_PIN "AT+PIN"
74#define B102C_CMD_BAUD "AT+BAUD"
75#define B102C_CMD_ADVMOD "AT+ADVMOD"
76#define B102C_CMD_ADVEN "AT+ADVEN"
77#define B102C_CMD_ADVINT "AT+ADVINT"
78#define B102C_CMD_POWER "AT+POWER"
79#define B102C_CMD_ROLE "AT+ROLE"
80#define B102C_CMD_INQ "AT+INQ"
81#define B102C_CMD_SINQ "AT+SINQ"
82#define B102C_CMD_SCANRLT "AT+SCANRLT"
83#define B102C_CMD_CONN "AT+CONN"
84#define B102C_CMD_SLEEP "AT+SLEEP"
85#define B102C_CMD_PAIR "AT+PAIR"
86#define B102C_CMD_DEFAULT "AT+DEFAULT"
87#define B102C_CMD_XXX "AT+XXX"
88#define B102C_CMD_ENTERDTS "AT+ENTERDTS"
89#define B102C_CMD_GPIOCFG "AT+GPIOCFG"
90#define B102C_CMD_RSSI "AT+RSSI"
91#define B102C_CMD_MUUID "AT+MUUID"
92
97#define B102C_RSP_OK "OK"
98#define B102C_RSP_ERROR "ERR"
99#define B102C_RSP_READY "Ready"
100
105#define B102C_PIN_STATE_HIGH 0x01
106#define B102C_PIN_STATE_LOW 0x00
107
113#define B102C_TX_DRV_BUFFER_SIZE 100
114#define B102C_RX_DRV_BUFFER_SIZE 300
115 // b102c_cmd
117
132#define B102C_MAP_MIKROBUS( cfg, mikrobus ) \
133 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
134 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
135 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
136 // b102c_map // b102c
139
144typedef struct
145{
146 // Output pins
147 digital_out_t rst;
149 // Modules
150 uart_t uart;
152 // Buffers
153 uint8_t uart_rx_buffer[ B102C_RX_DRV_BUFFER_SIZE ];
154 uint8_t uart_tx_buffer[ B102C_TX_DRV_BUFFER_SIZE ];
156} b102c_t;
157
162typedef struct
163{
164 // Communication gpio pins
165 pin_name_t rx_pin;
166 pin_name_t tx_pin;
168 // Additional gpio pins
169 pin_name_t rst;
171 // Static variable
172 uint32_t baud_rate;
174 uart_data_bits_t data_bit;
175 uart_parity_t parity_bit;
176 uart_stop_bits_t stop_bit;
179
184typedef enum
185{
189 B102C_TIMEOUT = -3
190
192
209
223err_t b102c_init ( b102c_t *ctx, b102c_cfg_t *cfg );
224
238
251err_t b102c_generic_write ( b102c_t *ctx, uint8_t *data_in, uint16_t len );
252
265err_t b102c_generic_read ( b102c_t *ctx, uint8_t *data_out, uint16_t len );
266
276void b102c_set_rst_pin ( b102c_t *ctx, uint8_t pin_state );
277
287
297void b102c_send_cmd ( b102c_t *ctx, uint8_t *cmd );
298
309void b102c_send_cmd_with_params ( b102c_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
310
320void b102c_send_cmd_check ( b102c_t *ctx, uint8_t *at_cmd_buf );
321
331void b102c_send_cmd_params_check ( b102c_t *ctx, uint8_t *at_cmd_buf );
332
333#ifdef __cplusplus
334}
335#endif
336#endif // B102C_H
337 // b102c
339
340// ------------------------------------------------------------------------ END
b102c_return_value_t
B102C Click return value data.
Definition: b102c.h:185
@ B102C_ERROR
Definition: b102c.h:187
@ B102C_TIMEOUT
Definition: b102c.h:189
@ B102C_OK
Definition: b102c.h:186
@ B102C_OVERFLOW
Definition: b102c.h:188
#define B102C_RX_DRV_BUFFER_SIZE
Definition: b102c.h:114
#define B102C_TX_DRV_BUFFER_SIZE
B102C driver buffer size.
Definition: b102c.h:113
void b102c_send_cmd_check(b102c_t *ctx, uint8_t *at_cmd_buf)
B102C check the sent command.
void b102c_cfg_setup(b102c_cfg_t *cfg)
B102C configuration object setup function.
void b102c_send_cmd_with_params(b102c_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
B102C send command function with parameter.
err_t b102c_init(b102c_t *ctx, b102c_cfg_t *cfg)
B102C initialization function.
void b102c_send_cmd_params_check(b102c_t *ctx, uint8_t *at_cmd_buf)
B102C check the command parameters.
void b102c_set_rst_pin(b102c_t *ctx, uint8_t pin_state)
B102C set RST pin state function.
err_t b102c_generic_read(b102c_t *ctx, uint8_t *data_out, uint16_t len)
B102C data reading function.
err_t b102c_generic_write(b102c_t *ctx, uint8_t *data_in, uint16_t len)
B102C data writing function.
void b102c_hw_reset(b102c_t *ctx)
B102C hardware reset function.
void b102c_send_cmd(b102c_t *ctx, uint8_t *cmd)
B102C send command function.
err_t b102c_default_cfg(b102c_t *ctx)
B102C default configuration function.
B102C Click configuration object.
Definition: b102c.h:163
uint32_t baud_rate
Definition: b102c.h:172
bool uart_blocking
Definition: b102c.h:173
uart_data_bits_t data_bit
Definition: b102c.h:174
pin_name_t tx_pin
Definition: b102c.h:166
pin_name_t rx_pin
Definition: b102c.h:165
uart_stop_bits_t stop_bit
Definition: b102c.h:176
uart_parity_t parity_bit
Definition: b102c.h:175
pin_name_t rst
Definition: b102c.h:169
B102C Click context object.
Definition: b102c.h:145
uart_t uart
Definition: b102c.h:150
digital_out_t rst
Definition: b102c.h:147