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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
59 #define G2C3G_CMD_AT "AT" // Communication test
60 #define G2C3G_CMD_GMR "AT+GMR" // Firmware version
61 #define G2C3G_CMD_ATE1 "ATE1" // Enable echo
62 #define G2C3G_CMD_ATE0 "ATE0" // Disable echo
63 #define G2C3G_CMD_GMSTA "AT+GMSTA" // LED status
64 #define G2C3G_CMD_RST "AT+RST" // Reset device
65 #define G2C3G_CMD_CRST "AT+CRST" // Connector module reset
66 #define G2C3G_CMD_CEN "AT+CEN" // Enable connector module
67 #define G2C3G_CMD_GPEN "AT+GPEN" // Enable GPIO outputs
68 #define G2C3G_CMD_W "AT+W" // Store configuration
69 #define G2C3G_CMD_R "AT+R" // Restore configuration
70 #define G2C3G_CMD_NWCR "AT+NWCR" // Network credentials
71 #define G2C3G_CMD_NWC "AT+NWC" // Connect to network
72 #define G2C3G_CMD_BRCR "AT+BRCR" // Broker credentials
73 #define G2C3G_CMD_BRC "AT+BRC" // Connect to broker
74 #define G2C3G_CMD_LRSP "AT+LRSP" // Long response
75 #define G2C3G_CMD_DSET "AT+DSET" // Data set
76 #define G2C3G_CMD_PUB "AT+PUB" // Publish data
77 
82 #define G2C3G_RSP_OK "OK"
83 #define G2C3G_RSP_ERROR "ERROR"
84 #define G2C3G_RSP_DEVICE_READY "DEVICE READY"
85 #define G2C3G_RSP_ERR "+ERR"
86 #define G2C3G_RSP_ACT "+ACT"
87 #define G2C3G_RSP_G2C3G "+G2C3G"
88 #define G2C3G_RSP_G2C3G_RSP "+G2C3G_RSP"
89 
95 #define G2C3G_TX_DRV_BUFFER_SIZE 300
96 #define G2C3G_RX_DRV_BUFFER_SIZE 300
97  // g2c3g_cmd
99 
114 #define G2C3G_MAP_MIKROBUS( cfg, mikrobus ) \
115  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
116  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
117  cfg.gp0 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
118  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
119  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
120  cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
121  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
122  // g2c3g_map // g2c3g
125 
130 typedef struct
131 {
132  // Output pins
133  digital_out_t rst;
134  digital_out_t cts;
136  // Input pins
137  digital_in_t gp0;
138  digital_in_t gp1;
139  digital_in_t rts;
141  // Modules
142  uart_t uart;
144  // Buffers
145  uint8_t uart_rx_buffer[ G2C3G_RX_DRV_BUFFER_SIZE ];
146  uint8_t uart_tx_buffer[ G2C3G_TX_DRV_BUFFER_SIZE ];
148 } g2c3g_t;
149 
154 typedef struct
155 {
156  // Communication gpio pins
157  pin_name_t rx_pin;
158  pin_name_t tx_pin;
160  // Additional gpio pins
161  pin_name_t gp0;
162  pin_name_t rst;
163  pin_name_t cts;
164  pin_name_t gp1;
165  pin_name_t rts;
167  // Static variable
168  uint32_t baud_rate;
170  uart_data_bits_t data_bit;
171  uart_parity_t parity_bit;
172  uart_stop_bits_t stop_bit;
174 } g2c3g_cfg_t;
175 
180 typedef enum
181 {
182  G2C3G_OK = 0,
187 
189 
206 
220 err_t g2c3g_init ( g2c3g_t *ctx, g2c3g_cfg_t *cfg );
221 
234 err_t g2c3g_generic_write ( g2c3g_t *ctx, uint8_t *data_in, uint16_t len );
235 
248 err_t g2c3g_generic_read ( g2c3g_t *ctx, uint8_t *data_out, uint16_t len );
249 
259 void g2c3g_set_cts_pin ( g2c3g_t *ctx, uint8_t state );
260 
270 void g2c3g_set_rst_pin ( g2c3g_t *ctx, uint8_t state );
271 
280 uint8_t g2c3g_get_gp0_pin ( g2c3g_t *ctx );
281 
290 uint8_t g2c3g_get_gp1_pin ( g2c3g_t *ctx );
291 
300 uint8_t g2c3g_get_rts_pin ( g2c3g_t *ctx );
301 
311 
321 void g2c3g_send_cmd ( g2c3g_t *ctx, uint8_t *cmd );
322 
333 void g2c3g_send_cmd_with_par ( g2c3g_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
334 
344 void g2c3g_send_cmd_check ( g2c3g_t *ctx, uint8_t *at_cmd_buf );
345 
355 void g2c3g_send_cmd_par_check ( g2c3g_t *ctx, uint8_t *at_cmd_buf );
356 
368 void g2c3g_set_net_creds ( g2c3g_t *ctx, uint8_t *sim_apn, uint8_t *username, uint8_t *password );
369 
380 void g2c3g_set_broker_creds ( g2c3g_t *ctx, uint8_t *dev_key, uint8_t *password );
381 
382 #ifdef __cplusplus
383 }
384 #endif
385 #endif // G2C3G_H
386  // g2c3g
388 
389 // ------------------------------------------------------------------------ END
G2C3G_ERROR_UNKNOWN
@ G2C3G_ERROR_UNKNOWN
Definition: g2c3g.h:186
g2c3g_t
G2C 3G Click context object.
Definition: g2c3g.h:131
g2c3g_cfg_t
G2C 3G Click configuration object.
Definition: g2c3g.h:155
g2c3g_send_cmd
void g2c3g_send_cmd(g2c3g_t *ctx, uint8_t *cmd)
G2C 3G send command function.
g2c3g_set_rst_pin
void g2c3g_set_rst_pin(g2c3g_t *ctx, uint8_t state)
G2C 3G set rst pin function.
g2c3g_cfg_t::rx_pin
pin_name_t rx_pin
Definition: g2c3g.h:157
g2c3g_generic_write
err_t g2c3g_generic_write(g2c3g_t *ctx, uint8_t *data_in, uint16_t len)
G2C 3G data writing function.
g2c3g_cfg_t::uart_blocking
bool uart_blocking
Definition: g2c3g.h:169
g2c3g_t::gp0
digital_in_t gp0
Definition: g2c3g.h:137
g2c3g_cfg_t::baud_rate
uint32_t baud_rate
Definition: g2c3g.h:168
g2c3g_cfg_t::rts
pin_name_t rts
Definition: g2c3g.h:165
g2c3g_cfg_t::tx_pin
pin_name_t tx_pin
Definition: g2c3g.h:158
g2c3g_get_gp1_pin
uint8_t g2c3g_get_gp1_pin(g2c3g_t *ctx)
G2C 3G get gp1 pin function.
g2c3g_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: g2c3g.h:171
g2c3g_set_broker_creds
void g2c3g_set_broker_creds(g2c3g_t *ctx, uint8_t *dev_key, uint8_t *password)
G2C 3G set broker credentials.
g2c3g_t::cts
digital_out_t cts
Definition: g2c3g.h:134
g2c3g_get_rts_pin
uint8_t g2c3g_get_rts_pin(g2c3g_t *ctx)
G2C 3G get rts pin function.
g2c3g_t::gp1
digital_in_t gp1
Definition: g2c3g.h:138
g2c3g_t::uart
uart_t uart
Definition: g2c3g.h:142
G2C3G_TX_DRV_BUFFER_SIZE
#define G2C3G_TX_DRV_BUFFER_SIZE
G2C 3G driver buffer size.
Definition: g2c3g.h:95
g2c3g_t::rts
digital_in_t rts
Definition: g2c3g.h:139
g2c3g_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: g2c3g.h:170
g2c3g_send_cmd_par_check
void g2c3g_send_cmd_par_check(g2c3g_t *ctx, uint8_t *at_cmd_buf)
G2C 3G check the command parameters.
g2c3g_cfg_setup
void g2c3g_cfg_setup(g2c3g_cfg_t *cfg)
G2C 3G configuration object setup function.
g2c3g_cfg_t::cts
pin_name_t cts
Definition: g2c3g.h:163
g2c3g_init
err_t g2c3g_init(g2c3g_t *ctx, g2c3g_cfg_t *cfg)
G2C 3G initialization function.
g2c3g_t::rst
digital_out_t rst
Definition: g2c3g.h:133
G2C3G_ERROR
@ G2C3G_ERROR
Definition: g2c3g.h:183
G2C3G_RX_DRV_BUFFER_SIZE
#define G2C3G_RX_DRV_BUFFER_SIZE
Definition: g2c3g.h:96
g2c3g_send_cmd_check
void g2c3g_send_cmd_check(g2c3g_t *ctx, uint8_t *at_cmd_buf)
G2C 3G check the sent command.
g2c3g_set_net_creds
void g2c3g_set_net_creds(g2c3g_t *ctx, uint8_t *sim_apn, uint8_t *username, uint8_t *password)
G2C 3G set network credentials.
g2c3g_cfg_t::gp0
pin_name_t gp0
Definition: g2c3g.h:161
g2c3g_return_value_t
g2c3g_return_value_t
G2C 3G Click return value data.
Definition: g2c3g.h:181
g2c3g_cfg_t::gp1
pin_name_t gp1
Definition: g2c3g.h:164
G2C3G_ERROR_CMD
@ G2C3G_ERROR_CMD
Definition: g2c3g.h:185
g2c3g_reset_device
void g2c3g_reset_device(g2c3g_t *ctx)
G2C 3G reset device function.
g2c3g_set_cts_pin
void g2c3g_set_cts_pin(g2c3g_t *ctx, uint8_t state)
G2C 3G set cts pin function.
G2C3G_OK
@ G2C3G_OK
Definition: g2c3g.h:182
g2c3g_get_gp0_pin
uint8_t g2c3g_get_gp0_pin(g2c3g_t *ctx)
G2C 3G get gp0 pin function.
g2c3g_cfg_t::rst
pin_name_t rst
Definition: g2c3g.h:162
G2C3G_ERROR_TIMEOUT
@ G2C3G_ERROR_TIMEOUT
Definition: g2c3g.h:184
g2c3g_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: g2c3g.h:172
g2c3g_generic_read
err_t g2c3g_generic_read(g2c3g_t *ctx, uint8_t *data_out, uint16_t len)
G2C 3G data reading function.
g2c3g_send_cmd_with_par
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.