g2c3g 2.1.0.0
g2c3g.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 G2C3G_H
29#define G2C3G_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 G2C3G_CMD_AT "AT" // Communication test
74#define G2C3G_CMD_GMR "AT+GMR" // Firmware version
75#define G2C3G_CMD_ATE1 "ATE1" // Enable echo
76#define G2C3G_CMD_ATE0 "ATE0" // Disable echo
77#define G2C3G_CMD_GMSTA "AT+GMSTA" // LED status
78#define G2C3G_CMD_RST "AT+RST" // Reset device
79#define G2C3G_CMD_CRST "AT+CRST" // Connector module reset
80#define G2C3G_CMD_CEN "AT+CEN" // Enable connector module
81#define G2C3G_CMD_GPEN "AT+GPEN" // Enable GPIO outputs
82#define G2C3G_CMD_W "AT+W" // Store configuration
83#define G2C3G_CMD_R "AT+R" // Restore configuration
84#define G2C3G_CMD_NWCR "AT+NWCR" // Network credentials
85#define G2C3G_CMD_NWC "AT+NWC" // Connect to network
86#define G2C3G_CMD_BRCR "AT+BRCR" // Broker credentials
87#define G2C3G_CMD_BRC "AT+BRC" // Connect to broker
88#define G2C3G_CMD_LRSP "AT+LRSP" // Long response
89#define G2C3G_CMD_DSET "AT+DSET" // Data set
90#define G2C3G_CMD_PUB "AT+PUB" // Publish data
91
96#define G2C3G_RSP_OK "OK"
97#define G2C3G_RSP_ERROR "ERROR"
98#define G2C3G_RSP_DEVICE_READY "DEVICE READY"
99#define G2C3G_RSP_ERR "+ERR"
100#define G2C3G_RSP_ACT "+ACT"
101#define G2C3G_RSP_G2C3G "+G2C3G"
102#define G2C3G_RSP_G2C3G_RSP "+G2C3G_RSP"
103
109#define G2C3G_TX_DRV_BUFFER_SIZE 300
110#define G2C3G_RX_DRV_BUFFER_SIZE 300
111
112 // g2c3g_cmd
113
128#define G2C3G_MAP_MIKROBUS( cfg, mikrobus ) \
129 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
130 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
131 cfg.gp0 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
132 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
133 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
134 cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
135 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
136
137 // g2c3g_map
138 // g2c3g
139
144typedef struct
145{
146 // Output pins
147 digital_out_t rst;
148 digital_out_t cts;
150 // Input pins
151 digital_in_t gp0;
152 digital_in_t gp1;
153 digital_in_t rts;
155 // Modules
156 uart_t uart;
158 // Buffers
159 uint8_t uart_rx_buffer[ G2C3G_RX_DRV_BUFFER_SIZE ];
160 uint8_t uart_tx_buffer[ G2C3G_TX_DRV_BUFFER_SIZE ];
162} g2c3g_t;
163
168typedef struct
169{
170 // Communication gpio pins
171 pin_name_t rx_pin;
172 pin_name_t tx_pin;
174 // Additional gpio pins
175 pin_name_t gp0;
176 pin_name_t rst;
177 pin_name_t cts;
178 pin_name_t gp1;
179 pin_name_t rts;
181 // Static variable
182 uint32_t baud_rate;
184 uart_data_bits_t data_bit;
185 uart_parity_t parity_bit;
186 uart_stop_bits_t stop_bit;
189
203
220
234err_t g2c3g_init ( g2c3g_t *ctx, g2c3g_cfg_t *cfg );
235
248err_t g2c3g_generic_write ( g2c3g_t *ctx, uint8_t *data_in, uint16_t len );
249
262err_t g2c3g_generic_read ( g2c3g_t *ctx, uint8_t *data_out, uint16_t len );
263
273void g2c3g_set_cts_pin ( g2c3g_t *ctx, uint8_t state );
274
284void g2c3g_set_rst_pin ( g2c3g_t *ctx, uint8_t state );
285
294uint8_t g2c3g_get_gp0_pin ( g2c3g_t *ctx );
295
304uint8_t g2c3g_get_gp1_pin ( g2c3g_t *ctx );
305
314uint8_t g2c3g_get_rts_pin ( g2c3g_t *ctx );
315
325
335void g2c3g_send_cmd ( g2c3g_t *ctx, uint8_t *cmd );
336
347void g2c3g_send_cmd_with_par ( g2c3g_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
348
358void g2c3g_send_cmd_check ( g2c3g_t *ctx, uint8_t *at_cmd_buf );
359
369void g2c3g_send_cmd_par_check ( g2c3g_t *ctx, uint8_t *at_cmd_buf );
370
382void g2c3g_set_net_creds ( g2c3g_t *ctx, uint8_t *sim_apn, uint8_t *username, uint8_t *password );
383
394void g2c3g_set_broker_creds ( g2c3g_t *ctx, uint8_t *dev_key, uint8_t *password );
395
396#ifdef __cplusplus
397}
398#endif
399#endif // G2C3G_H
400
401 // g2c3g
402
403// ------------------------------------------------------------------------ END
g2c3g_return_value_t
G2C 3G Click return value data.
Definition g2c3g.h:195
@ G2C3G_ERROR_UNKNOWN
Definition g2c3g.h:200
@ G2C3G_ERROR_TIMEOUT
Definition g2c3g.h:198
@ G2C3G_ERROR
Definition g2c3g.h:197
@ G2C3G_ERROR_CMD
Definition g2c3g.h:199
@ G2C3G_OK
Definition g2c3g.h:196
#define G2C3G_RX_DRV_BUFFER_SIZE
Definition g2c3g.h:110
#define G2C3G_TX_DRV_BUFFER_SIZE
G2C 3G driver buffer size.
Definition g2c3g.h:109
void g2c3g_set_rst_pin(g2c3g_t *ctx, uint8_t state)
G2C 3G set rst pin function.
uint8_t g2c3g_get_rts_pin(g2c3g_t *ctx)
G2C 3G get rts pin function.
void g2c3g_send_cmd_par_check(g2c3g_t *ctx, uint8_t *at_cmd_buf)
G2C 3G check the command parameters.
void g2c3g_send_cmd_check(g2c3g_t *ctx, uint8_t *at_cmd_buf)
G2C 3G check the sent command.
void g2c3g_set_net_creds(g2c3g_t *ctx, uint8_t *sim_apn, uint8_t *username, uint8_t *password)
G2C 3G set network credentials.
void g2c3g_set_broker_creds(g2c3g_t *ctx, uint8_t *dev_key, uint8_t *password)
G2C 3G set broker credentials.
err_t g2c3g_generic_read(g2c3g_t *ctx, uint8_t *data_out, uint16_t len)
G2C 3G data reading function.
err_t g2c3g_init(g2c3g_t *ctx, g2c3g_cfg_t *cfg)
G2C 3G initialization function.
void g2c3g_send_cmd_with_par(g2c3g_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
G2C 3G send command function with parameter.
void g2c3g_set_cts_pin(g2c3g_t *ctx, uint8_t state)
G2C 3G set cts pin function.
uint8_t g2c3g_get_gp1_pin(g2c3g_t *ctx)
G2C 3G get gp1 pin function.
void g2c3g_send_cmd(g2c3g_t *ctx, uint8_t *cmd)
G2C 3G send command function.
uint8_t g2c3g_get_gp0_pin(g2c3g_t *ctx)
G2C 3G get gp0 pin function.
void g2c3g_cfg_setup(g2c3g_cfg_t *cfg)
G2C 3G configuration object setup function.
err_t g2c3g_generic_write(g2c3g_t *ctx, uint8_t *data_in, uint16_t len)
G2C 3G data writing function.
void g2c3g_reset_device(g2c3g_t *ctx)
G2C 3G reset device function.
G2C 3G Click configuration object.
Definition g2c3g.h:169
pin_name_t rts
Definition g2c3g.h:179
uint32_t baud_rate
Definition g2c3g.h:182
pin_name_t gp0
Definition g2c3g.h:175
pin_name_t cts
Definition g2c3g.h:177
bool uart_blocking
Definition g2c3g.h:183
uart_data_bits_t data_bit
Definition g2c3g.h:184
pin_name_t tx_pin
Definition g2c3g.h:172
pin_name_t rx_pin
Definition g2c3g.h:171
uart_stop_bits_t stop_bit
Definition g2c3g.h:186
pin_name_t gp1
Definition g2c3g.h:178
uart_parity_t parity_bit
Definition g2c3g.h:185
pin_name_t rst
Definition g2c3g.h:176
G2C 3G Click context object.
Definition g2c3g.h:145
digital_in_t gp1
Definition g2c3g.h:152
uart_t uart
Definition g2c3g.h:156
digital_in_t gp0
Definition g2c3g.h:151
digital_in_t rts
Definition g2c3g.h:153
digital_out_t rst
Definition g2c3g.h:147
digital_out_t cts
Definition g2c3g.h:148