g2c 2.1.0.0
g2c.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 G2C_H
29#define G2C_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 G2C_CMD_AT "AT" // Communication test
74#define G2C_CMD_GMR "AT+GMR" // Firmware version
75#define G2C_CMD_ATE1 "ATE1" // Enable echo
76#define G2C_CMD_ATE0 "ATE0" // Disable echo
77#define G2C_CMD_RST "AT+RST" // Reset device
78#define G2C_CMD_CRST "AT+CRST" // Connector module reset
79#define G2C_CMD_CEN "AT+CEN" // Enable connector module
80#define G2C_CMD_GPEN "AT+GPEN" // Enable GPIO outputs
81#define G2C_CMD_W "AT+W" // Store configuration
82#define G2C_CMD_R "AT+R" // Restore configuration
83#define G2C_CMD_NWP "AT+NWP" // Network parameters
84#define G2C_CMD_NWCR "AT+NWCR" // Network credentials
85#define G2C_CMD_NWC "AT+NWC" // Connect to network
86#define G2C_CMD_BRCR "AT+BRCR" // Broker credentials
87#define G2C_CMD_BRC "AT+BRC" // Connect to broker
88#define G2C_CMD_ASTA "AT+ASTA" // Actuator status
89#define G2C_CMD_DSET "AT+DSET" // Data set
90#define G2C_CMD_PUB "AT+PUB" // Publish data
91
96#define G2C_RSP_OK "OK"
97#define G2C_RSP_ERROR "ERROR"
98#define G2C_RSP_ERR "+ERR"
99#define G2C_RSP_ACT "+ACT"
100
106#define G2C_TX_DRV_BUFFER_SIZE 300
107#define G2C_RX_DRV_BUFFER_SIZE 300
108
109 // g2c_cmd
110
125#define G2C_MAP_MIKROBUS( cfg, mikrobus ) \
126 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
127 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
128 cfg.gp0 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
129 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
130 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
131 cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
132 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
133
134 // g2c_map
135 // g2c
136
141typedef struct
142{
143 // Output pins
144 digital_out_t rst;
145 digital_out_t cts;
147 // Input pins
148 digital_in_t gp0;
149 digital_in_t gp1;
150 digital_in_t rts;
152 // Modules
153 uart_t uart;
155 // Buffers
156 uint8_t uart_rx_buffer[ G2C_RX_DRV_BUFFER_SIZE ];
157 uint8_t uart_tx_buffer[ G2C_TX_DRV_BUFFER_SIZE ];
159} g2c_t;
160
165typedef struct
166{
167 // Communication gpio pins
168 pin_name_t rx_pin;
169 pin_name_t tx_pin;
171 // Additional gpio pins
172 pin_name_t gp0;
173 pin_name_t rst;
174 pin_name_t cts;
175 pin_name_t gp1;
176 pin_name_t rts;
178 // Static variable
179 uint32_t baud_rate;
181 uart_data_bits_t data_bit;
182 uart_parity_t parity_bit;
183 uart_stop_bits_t stop_bit;
185} g2c_cfg_t;
186
200
217
231err_t g2c_init ( g2c_t *ctx, g2c_cfg_t *cfg );
232
245err_t g2c_generic_write ( g2c_t *ctx, uint8_t *data_in, uint16_t len );
246
259err_t g2c_generic_read ( g2c_t *ctx, uint8_t *data_out, uint16_t len );
260
270void g2c_set_cts_pin ( g2c_t *ctx, uint8_t state );
271
281void g2c_set_rst_pin ( g2c_t *ctx, uint8_t state );
282
291uint8_t g2c_get_gp0_pin ( g2c_t *ctx );
292
301uint8_t g2c_get_gp1_pin ( g2c_t *ctx );
302
311uint8_t g2c_get_rts_pin ( g2c_t *ctx );
312
322
332void g2c_send_cmd ( g2c_t *ctx, uint8_t *cmd );
333
344void g2c_send_cmd_with_par ( g2c_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
345
355void g2c_send_cmd_check ( g2c_t *ctx, uint8_t *at_cmd_buf );
356
366void g2c_send_cmd_par_check ( g2c_t *ctx, uint8_t *at_cmd_buf );
367
378void g2c_set_net_creds ( g2c_t *ctx, uint8_t *wifi_ssid, uint8_t *wifi_pass );
379
390void g2c_set_broker_creds ( g2c_t *ctx, uint8_t *dev_key, uint8_t *password );
391
392#ifdef __cplusplus
393}
394#endif
395#endif // G2C_H
396
397 // g2c
398
399// ------------------------------------------------------------------------ END
g2c_return_value_t
G2C Click return value data.
Definition g2c.h:192
@ G2C_OK
Definition g2c.h:193
@ G2C_ERROR_CMD
Definition g2c.h:196
@ G2C_ERROR_UNKNOWN
Definition g2c.h:197
@ G2C_ERROR
Definition g2c.h:194
@ G2C_ERROR_TIMEOUT
Definition g2c.h:195
#define G2C_TX_DRV_BUFFER_SIZE
G2C driver buffer size.
Definition g2c.h:106
#define G2C_RX_DRV_BUFFER_SIZE
Definition g2c.h:107
void g2c_send_cmd(g2c_t *ctx, uint8_t *cmd)
G2C send command function.
void g2c_send_cmd_with_par(g2c_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
G2C send command function with parameter.
uint8_t g2c_get_rts_pin(g2c_t *ctx)
G2C get rts pin function.
void g2c_set_cts_pin(g2c_t *ctx, uint8_t state)
G2C set cts pin function.
uint8_t g2c_get_gp0_pin(g2c_t *ctx)
G2C get gp0 pin function.
void g2c_set_broker_creds(g2c_t *ctx, uint8_t *dev_key, uint8_t *password)
G2C set broker credentials.
uint8_t g2c_get_gp1_pin(g2c_t *ctx)
G2C get gp1 pin function.
void g2c_set_rst_pin(g2c_t *ctx, uint8_t state)
G2C set rst pin function.
err_t g2c_generic_read(g2c_t *ctx, uint8_t *data_out, uint16_t len)
G2C data reading function.
void g2c_send_cmd_par_check(g2c_t *ctx, uint8_t *at_cmd_buf)
G2C check the command parameters.
err_t g2c_init(g2c_t *ctx, g2c_cfg_t *cfg)
G2C initialization function.
void g2c_send_cmd_check(g2c_t *ctx, uint8_t *at_cmd_buf)
G2C check the sent command.
err_t g2c_generic_write(g2c_t *ctx, uint8_t *data_in, uint16_t len)
G2C data writing function.
void g2c_reset_device(g2c_t *ctx)
G2C reset device function.
void g2c_cfg_setup(g2c_cfg_t *cfg)
G2C configuration object setup function.
void g2c_set_net_creds(g2c_t *ctx, uint8_t *wifi_ssid, uint8_t *wifi_pass)
G2C set network credentials.
G2C Click configuration object.
Definition g2c.h:166
pin_name_t rts
Definition g2c.h:176
uint32_t baud_rate
Definition g2c.h:179
pin_name_t gp0
Definition g2c.h:172
pin_name_t cts
Definition g2c.h:174
bool uart_blocking
Definition g2c.h:180
uart_data_bits_t data_bit
Definition g2c.h:181
pin_name_t tx_pin
Definition g2c.h:169
pin_name_t rx_pin
Definition g2c.h:168
uart_stop_bits_t stop_bit
Definition g2c.h:183
pin_name_t gp1
Definition g2c.h:175
uart_parity_t parity_bit
Definition g2c.h:182
pin_name_t rst
Definition g2c.h:173
G2C Click context object.
Definition g2c.h:142
digital_in_t gp1
Definition g2c.h:149
uart_t uart
Definition g2c.h:153
digital_in_t gp0
Definition g2c.h:148
digital_in_t rts
Definition g2c.h:150
digital_out_t rst
Definition g2c.h:144
digital_out_t cts
Definition g2c.h:145