anynet2g 2.0.0.0
anynet2g.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 ANYNET2G_H
29#define ANYNET2G_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 ANYNET2G_CMD_AT "AT"
74#define ANYNET2G_CMD_QCCID "AT+QCCID"
75#define ANYNET2G_CMD_GSN "AT+GSN"
76#define ANYNET2G_CMD_AWSVER "AT+AWSVER"
77#define ANYNET2G_CMD_AWSRESET "AT+AWSRESET"
78#define ANYNET2G_CMD_AWSSTATE "AT+AWSSTATE"
79#define ANYNET2G_CMD_AWSBUTTON "AT+AWSBUTTON"
80#define ANYNET2G_CMD_AWSPUBOPEN "AT+AWSPUBOPEN"
81#define ANYNET2G_CMD_AWSPUBLISH "AT+AWSPUBLISH"
82#define ANYNET2G_CMD_AWSSUBOPEN "AT+AWSSUBOPEN"
83#define ANYNET2G_CMD_AWSPUBCLOSE "AT+AWSPUBCLOSE"
84
89#define ANYNET2G_RSP_OK "OK"
90#define ANYNET2G_RSP_ERROR "ERROR"
91#define ANYNET2G_RSP_READY_FOR_SEND ">"
92#define ANYNET2G_RSP_SEND_OK "SEND OK"
93#define ANYNET2G_RSP_SEND_FAIL "SEND FAIL"
94
100#define ANYNET2G_RX_DRV_BUFFER_SIZE 256
101#define ANYNET2G_TX_DRV_BUFFER_SIZE 256
102
103 // anynet2g_set
104
119#define ANYNET2G_MAP_MIKROBUS( cfg, mikrobus ) \
120 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
121 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
122 cfg.slp = MIKROBUS( mikrobus, MIKROBUS_RST ); \
123 cfg.dsr = MIKROBUS( mikrobus, MIKROBUS_CS ); \
124 cfg.dtr = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
125 cfg.iot = MIKROBUS( mikrobus, MIKROBUS_INT )
126
127 // anynet2g_map
128 // anynet2g
129
134typedef struct
135{
136 // Output pins
137 digital_out_t slp;
138 digital_out_t dtr;
139 digital_out_t iot;
141 // Input pins
142 digital_in_t dsr;
144 // Modules
145 uart_t uart;
147 // Buffers
148 uint8_t uart_rx_buffer[ ANYNET2G_RX_DRV_BUFFER_SIZE ];
149 uint8_t uart_tx_buffer[ ANYNET2G_TX_DRV_BUFFER_SIZE ];
151} anynet2g_t;
152
157typedef struct
158{
159 // Communication gpio pins
160 pin_name_t rx_pin;
161 pin_name_t tx_pin;
163 // Additional gpio pins
164 pin_name_t slp;
165 pin_name_t dtr;
166 pin_name_t iot;
167 pin_name_t dsr;
169 // Static variable
170 uint32_t baud_rate;
172 uart_data_bits_t data_bit;
173 uart_parity_t parity_bit;
174 uart_stop_bits_t stop_bit;
177
192
209
224
237err_t anynet2g_generic_write ( anynet2g_t *ctx, uint8_t *data_in, uint16_t len );
238
251err_t anynet2g_generic_read ( anynet2g_t *ctx, uint8_t *data_out, uint16_t len );
252
262void anynet2g_set_slp_pin ( anynet2g_t *ctx, uint8_t state );
263
273void anynet2g_set_dtr_pin ( anynet2g_t *ctx, uint8_t state );
274
284void anynet2g_set_iot_pin ( anynet2g_t *ctx, uint8_t state );
285
295
305void anynet2g_send_cmd ( anynet2g_t *ctx, uint8_t *cmd );
306
317void anynet2g_send_cmd_with_par ( anynet2g_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
318
328void anynet2g_send_cmd_check ( anynet2g_t *ctx, uint8_t *at_cmd_buf );
329
339void anynet2g_send_cmd_par_check ( anynet2g_t *ctx, uint8_t *at_cmd_buf );
340
341#ifdef __cplusplus
342}
343#endif
344#endif // ANYNET2G_H
345
346 // anynet2g
347
348// ------------------------------------------------------------------------ END
anynet2g_return_value_t
AnyNet 2G Click return value data.
Definition anynet2g.h:183
@ ANYNET2G_ERROR
Definition anynet2g.h:185
@ ANYNET2G_ERROR_SEND
Definition anynet2g.h:188
@ ANYNET2G_ERROR_UNKNOWN
Definition anynet2g.h:189
@ ANYNET2G_ERROR_CMD
Definition anynet2g.h:187
@ ANYNET2G_OK
Definition anynet2g.h:184
@ ANYNET2G_ERROR_TIMEOUT
Definition anynet2g.h:186
#define ANYNET2G_TX_DRV_BUFFER_SIZE
Definition anynet2g.h:101
#define ANYNET2G_RX_DRV_BUFFER_SIZE
AnyNet 2G driver buffer size.
Definition anynet2g.h:100
void anynet2g_send_cmd_with_par(anynet2g_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
void anynet2g_cfg_setup(anynet2g_cfg_t *cfg)
AnyNet 2G configuration object setup function.
void anynet2g_send_cmd_par_check(anynet2g_t *ctx, uint8_t *at_cmd_buf)
Check the command parameters.
err_t anynet2g_generic_write(anynet2g_t *ctx, uint8_t *data_in, uint16_t len)
AnyNet 2G data writing function.
err_t anynet2g_generic_read(anynet2g_t *ctx, uint8_t *data_out, uint16_t len)
AnyNet 2G data reading function.
void anynet2g_set_slp_pin(anynet2g_t *ctx, uint8_t state)
AnyNet 2G set slp pin function.
void anynet2g_send_cmd_check(anynet2g_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.
void anynet2g_send_cmd(anynet2g_t *ctx, uint8_t *cmd)
Send command function.
void anynet2g_set_iot_pin(anynet2g_t *ctx, uint8_t state)
AnyNet 2G set iot pin function.
err_t anynet2g_init(anynet2g_t *ctx, anynet2g_cfg_t *cfg)
AnyNet 2G initialization function.
void anynet2g_set_dtr_pin(anynet2g_t *ctx, uint8_t state)
AnyNet 2G set dtr pin function.
uint8_t anynet2g_get_dsr_pin(anynet2g_t *ctx)
AnyNet 2G get dsr pin function.
AnyNet 2G Click configuration object.
Definition anynet2g.h:158
pin_name_t dtr
Definition anynet2g.h:165
uint32_t baud_rate
Definition anynet2g.h:170
pin_name_t iot
Definition anynet2g.h:166
pin_name_t slp
Definition anynet2g.h:164
bool uart_blocking
Definition anynet2g.h:171
uart_data_bits_t data_bit
Definition anynet2g.h:172
pin_name_t tx_pin
Definition anynet2g.h:161
pin_name_t rx_pin
Definition anynet2g.h:160
uart_stop_bits_t stop_bit
Definition anynet2g.h:174
pin_name_t dsr
Definition anynet2g.h:167
uart_parity_t parity_bit
Definition anynet2g.h:173
AnyNet 2G Click context object.
Definition anynet2g.h:135
digital_out_t slp
Definition anynet2g.h:137
uart_t uart
Definition anynet2g.h:145
digital_out_t iot
Definition anynet2g.h:139
digital_out_t dtr
Definition anynet2g.h:138
digital_in_t dsr
Definition anynet2g.h:142