annab412 2.1.0.0
annab412.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 ANNAB412_H
29#define ANNAB412_H
30
31#ifdef __cplusplus
32extern "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 ANNAB412_CMD_AT "AT"
74#define ANNAB412_CMD_ECHO_OFF "ATE0"
75#define ANNAB412_CMD_ECHO_ON "ATE1"
76#define ANNAB412_CMD_DEV_NAME "AT+UBTLN"
77#define ANNAB412_CMD_CONN_MODE "AT+UBTCM"
78#define ANNAB412_CMD_DISCOVER_MODE "AT+UBTDM"
79#define ANNAB412_CMD_ENTER_MODE "ATO"
80
85#define ANNAB412_DELIMITER_TERMINATION 13
86#define ANNAB412_DELIMITER_END_CMD 0
87#define ANNAB412_DELIMITER_QUOTATION 0x22
88#define ANNAB412_DELIMITER_EQUAL 0x3D
89#define ANNAB412_ASCII_CHAR_0 48
90
95#define ANNAB412_DEV_NAME_MIN 1
96#define ANNAB412_DEV_NAME_MAX 38
97
102#define ANNAB412_CONNECTABLE_MODE_OFF 1
103#define ANNAB412_CONNECTABLE_MODE_ON 2
104
109#define ANNAB412_DISCOVERABLE_MODE_OFF 1
110#define ANNAB412_DISCOVERABLE_MODE_LIM 2
111#define ANNAB412_DISCOVERABLE_MODE_ON 3
112
117#define ANNAB412_ENTER_MODE_COMMAND 0
118#define ANNAB412_ENTER_MODE_DATA 1
119#define ANNAB412_ENTER_MODE_EXT_DATA 2
120#define ANNAB412_ENTER_MODE_PPP 3
121
126#define ANNAB412_PIN_STATE_LOW 0
127#define ANNAB412_PIN_STATE_HIGH 1
128
134#define ANNAB412_TX_DRV_BUFFER_SIZE 100
135#define ANNAB412_RX_DRV_BUFFER_SIZE 300
136
137 // annab412_cmd
138
153#define ANNAB412_MAP_MIKROBUS( cfg, mikrobus ) \
154 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
155 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
156 cfg.dtr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
157 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
158 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
159 cfg.dsr = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
160 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
161
162 // annab412_map
163 // annab412
164
169typedef struct
170{
171 // Output pins
172 digital_out_t rst;
173 digital_out_t cts;
174 digital_out_t dsr;
176 // Input pins
177 digital_in_t dtr;
178 digital_in_t rts;
180 // Modules
181 uart_t uart;
183 // Buffers
184 uint8_t uart_rx_buffer[ ANNAB412_RX_DRV_BUFFER_SIZE ];
185 uint8_t uart_tx_buffer[ ANNAB412_TX_DRV_BUFFER_SIZE ];
187} annab412_t;
188
193typedef struct
194{
195 // Communication gpio pins
196 pin_name_t rx_pin;
197 pin_name_t tx_pin;
199 // Additional gpio pins
200 pin_name_t dtr;
201 pin_name_t rst;
202 pin_name_t cts;
203 pin_name_t dsr;
204 pin_name_t rts;
206 // Static variable
207 uint32_t baud_rate;
209 uart_data_bits_t data_bit;
210 uart_parity_t parity_bit;
211 uart_stop_bits_t stop_bit;
214
219typedef enum
220{
222 ANNAB412_ERROR = -1
223
225
242
257
271
284err_t annab412_generic_write ( annab412_t *ctx, uint8_t *data_in, uint16_t len );
285
298err_t annab412_generic_read ( annab412_t *ctx, uint8_t *data_out, uint16_t len );
299
309void annab412_set_rst_pin ( annab412_t *ctx, uint8_t state );
310
320void annab412_set_dsr_pin ( annab412_t *ctx, uint8_t state );
321
331void annab412_set_cts_pin ( annab412_t *ctx, uint8_t state );
332
343
354
364
378err_t annab412_send_command ( annab412_t *ctx, char *command );
379
393
407
421err_t annab412_set_cmd_device_name ( annab412_t *ctx, char *device_name );
422
436err_t annab412_set_cmd_conn_mode ( annab412_t *ctx, uint8_t mode );
437
451err_t annab412_set_cmd_discover_mode ( annab412_t *ctx, uint8_t mode );
452
466err_t annab412_set_cmd_enter_mode ( annab412_t *ctx, uint8_t mode );
467
468#ifdef __cplusplus
469}
470#endif
471#endif // ANNAB412_H
472
473 // annab412
474
475// ------------------------------------------------------------------------ END
annab412_return_value_t
ANNA-B412 Click return value data.
Definition annab412.h:220
@ ANNAB412_ERROR
Definition annab412.h:222
@ ANNAB412_OK
Definition annab412.h:221
#define ANNAB412_TX_DRV_BUFFER_SIZE
ANNA-B412 driver buffer size.
Definition annab412.h:134
#define ANNAB412_RX_DRV_BUFFER_SIZE
Definition annab412.h:135
err_t annab412_set_cmd_enter_mode(annab412_t *ctx, uint8_t mode)
ANNA-B412 set enter mode function.
void annab412_set_dsr_pin(annab412_t *ctx, uint8_t state)
ANNA-B412 set data set ready pin function.
uint8_t annab412_get_rts_pin(annab412_t *ctx)
ANNA-B412 get request to send pin function.
err_t annab412_default_cfg(annab412_t *ctx)
ANNA-B412 default configuration function.
err_t annab412_init(annab412_t *ctx, annab412_cfg_t *cfg)
ANNA-B412 initialization function.
err_t annab412_set_cmd_device_name(annab412_t *ctx, char *device_name)
ANNA-B412 set device name function.
err_t annab412_set_cmd_discover_mode(annab412_t *ctx, uint8_t mode)
ANNA-B412 set discoverability mode function.
uint8_t annab412_get_dtr_pin(annab412_t *ctx)
ANNA-B412 get data terminal ready pin function.
err_t annab412_generic_read(annab412_t *ctx, uint8_t *data_out, uint16_t len)
ANNA-B412 data reading function.
err_t annab412_set_cmd_echo_off(annab412_t *ctx)
ANNA-B412 set command echo on function.
err_t annab412_set_cmd_echo_on(annab412_t *ctx)
ANNA-B412 set command echo on function.
err_t annab412_generic_write(annab412_t *ctx, uint8_t *data_in, uint16_t len)
ANNA-B412 data writing function.
void annab412_set_rst_pin(annab412_t *ctx, uint8_t state)
ANNA-B412 set reset pin function.
err_t annab412_send_command(annab412_t *ctx, char *command)
ANNA-B412 send command function.
void annab412_set_cts_pin(annab412_t *ctx, uint8_t state)
ANNA-B412 set clear to send pin function.
err_t annab412_set_cmd_conn_mode(annab412_t *ctx, uint8_t mode)
ANNA-B412 set connectability mode function.
void annab412_cfg_setup(annab412_cfg_t *cfg)
ANNA-B412 configuration object setup function.
void annab412_hw_reset(annab412_t *ctx)
ANNA-B412 hw reset function.
ANNA-B412 Click configuration object.
Definition annab412.h:194
pin_name_t dtr
Definition annab412.h:200
pin_name_t rts
Definition annab412.h:204
uint32_t baud_rate
Definition annab412.h:207
pin_name_t cts
Definition annab412.h:202
bool uart_blocking
Definition annab412.h:208
uart_data_bits_t data_bit
Definition annab412.h:209
pin_name_t tx_pin
Definition annab412.h:197
pin_name_t rx_pin
Definition annab412.h:196
uart_stop_bits_t stop_bit
Definition annab412.h:211
pin_name_t dsr
Definition annab412.h:203
uart_parity_t parity_bit
Definition annab412.h:210
pin_name_t rst
Definition annab412.h:201
ANNA-B412 Click context object.
Definition annab412.h:170
digital_out_t dsr
Definition annab412.h:174
uart_t uart
Definition annab412.h:181
digital_in_t rts
Definition annab412.h:178
digital_out_t rst
Definition annab412.h:172
digital_out_t cts
Definition annab412.h:173
digital_in_t dtr
Definition annab412.h:177