c3gea 2.0.0.0
c3gea.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 C3GEA_H
29#define C3GEA_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 C3GEA_CMD_AT "AT"
74#define C3GEA_CMD_ATI "ATI"
75#define C3GEA_CMD_CFUN "AT+CFUN"
76#define C3GEA_CMD_CREG "AT+CREG"
77#define C3GEA_CMD_CGDCONT "AT+CGDCONT"
78#define C3GEA_CMD_CSQ "AT+CSQ"
79#define C3GEA_CMD_COPS "AT+COPS"
80#define C3GEA_CMD_CMGS "AT+CMGS"
81#define C3GEA_CMD_CMGF "AT+CMGF"
82#define C3GEA_CMD_QIACT "AT+QIACT"
83#define C3GEA_CMD_QIOPEN "AT+QIOPEN"
84#define C3GEA_CMD_QICLOSE "AT+QICLOSE"
85#define C3GEA_CMD_QISEND "AT+QISEND"
86#define C3GEA_CMD_QIRD "AT+QIRD"
87
92#define C3GEA_RSP_OK "OK"
93#define C3GEA_RSP_ERROR "ERROR"
94
100#define C3GEA_RX_DRV_BUFFER_SIZE 256
101#define C3GEA_TX_DRV_BUFFER_SIZE 256
102
103 // c3gea_set
104
119#define C3GEA_MAP_MIKROBUS( cfg, mikrobus ) \
120 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
121 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
122 cfg.sta = MIKROBUS( mikrobus, MIKROBUS_AN ); \
123 cfg.pwk = MIKROBUS( mikrobus, MIKROBUS_RST ); \
124 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
125 cfg.ring = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
126 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT )
127
128 // c3gea_map
129 // c3gea
130
135typedef struct
136{
137 // Output pins
138 digital_out_t pwk;
139 digital_out_t rts;
141 // Input pins
142 digital_in_t sta;
143 digital_in_t ring;
144 digital_in_t cts;
146 // Modules
147 uart_t uart;
149 // Buffers
150 char uart_rx_buffer[ C3GEA_RX_DRV_BUFFER_SIZE ];
151 char uart_tx_buffer[ C3GEA_TX_DRV_BUFFER_SIZE ];
153} c3gea_t;
154
159typedef struct
160{
161 // Communication gpio pins
162 pin_name_t rx_pin;
163 pin_name_t tx_pin;
165 // Additional gpio pins
166 pin_name_t sta;
167 pin_name_t pwk;
168 pin_name_t rts;
169 pin_name_t ring;
170 pin_name_t cts;
172 // Static variable
173 uint32_t baud_rate;
175 uart_data_bits_t data_bit;
176 uart_parity_t parity_bit;
177 uart_stop_bits_t stop_bit;
180
194
211
225err_t c3gea_init ( c3gea_t *ctx, c3gea_cfg_t *cfg );
226
239err_t c3gea_generic_write ( c3gea_t *ctx, uint8_t *data_in, uint16_t len );
240
253err_t c3gea_generic_read ( c3gea_t *ctx, uint8_t *data_out, uint16_t len );
254
264void c3gea_set_rts_pin ( c3gea_t *ctx, uint8_t state );
265
275void c3gea_set_pwk_pin ( c3gea_t *ctx, uint8_t state );
276
285uint8_t c3gea_get_cts_pin ( c3gea_t *ctx );
286
295uint8_t c3gea_get_sta_pin ( c3gea_t *ctx );
296
306
316void c3gea_send_cmd ( c3gea_t *ctx, uint8_t *cmd );
317
328void c3gea_send_cmd_with_par ( c3gea_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf );
329
339void c3gea_send_cmd_check ( c3gea_t *ctx, uint8_t *at_cmd_buf );
340
350void c3gea_send_cmd_par_check ( c3gea_t *ctx, uint8_t *at_cmd_buf );
351
361void c3gea_set_sim_apn ( c3gea_t *ctx, uint8_t *sim_apn );
362
373void c3gea_send_sms_text ( c3gea_t *ctx, uint8_t *phone_number, uint8_t *sms_text );
374
388err_t c3gea_send_sms_pdu ( c3gea_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text );
389
390#ifdef __cplusplus
391}
392#endif
393#endif // C3GEA_H
394
395 // c3gea
396
397// ------------------------------------------------------------------------ END
c3gea_return_value_t
3G-EA Click return value data.
Definition c3gea.h:186
@ C3GEA_OK
Definition c3gea.h:187
@ C3GEA_ERROR
Definition c3gea.h:188
@ C3GEA_ERROR_TIMEOUT
Definition c3gea.h:189
@ C3GEA_ERROR_UNKNOWN
Definition c3gea.h:191
@ C3GEA_ERROR_CMD
Definition c3gea.h:190
#define C3GEA_RX_DRV_BUFFER_SIZE
3G-EA driver buffer size.
Definition c3gea.h:100
#define C3GEA_TX_DRV_BUFFER_SIZE
Definition c3gea.h:101
void c3gea_set_rts_pin(c3gea_t *ctx, uint8_t state)
3G-EA set rts pin function.
err_t c3gea_init(c3gea_t *ctx, c3gea_cfg_t *cfg)
3G-EA initialization function.
void c3gea_cfg_setup(c3gea_cfg_t *cfg)
3G-EA configuration object setup function.
void c3gea_send_sms_text(c3gea_t *ctx, uint8_t *phone_number, uint8_t *sms_text)
3G-EA send SMS in text mode.
err_t c3gea_send_sms_pdu(c3gea_t *ctx, uint8_t *service_center_number, uint8_t *phone_number, uint8_t *sms_text)
3G-EA send SMS in PDU mode.
uint8_t c3gea_get_sta_pin(c3gea_t *ctx)
3G-EA get sta pin function.
void c3gea_send_cmd_par_check(c3gea_t *ctx, uint8_t *at_cmd_buf)
Check the command parameters.
void c3gea_set_pwk_pin(c3gea_t *ctx, uint8_t state)
3G-EA set pwk pin function.
void c3gea_send_cmd_check(c3gea_t *ctx, uint8_t *at_cmd_buf)
Check the sent command.
uint8_t c3gea_get_ring_pin(c3gea_t *ctx)
3G-EA get ring pin function.
void c3gea_send_cmd_with_par(c3gea_t *ctx, uint8_t *at_cmd_buf, uint8_t *param_buf)
Send command function with parameter.
uint8_t c3gea_get_cts_pin(c3gea_t *ctx)
3G-EA get cts pin function.
void c3gea_send_cmd(c3gea_t *ctx, uint8_t *cmd)
Send command function.
void c3gea_set_sim_apn(c3gea_t *ctx, uint8_t *sim_apn)
Set sim card APN.
err_t c3gea_generic_read(c3gea_t *ctx, uint8_t *data_out, uint16_t len)
3G-EA data reading function.
err_t c3gea_generic_write(c3gea_t *ctx, uint8_t *data_in, uint16_t len)
3G-EA data writing function.
3G-EA Click configuration object.
Definition c3gea.h:160
pin_name_t sta
Definition c3gea.h:166
pin_name_t rts
Definition c3gea.h:168
uint32_t baud_rate
Definition c3gea.h:173
pin_name_t pwk
Definition c3gea.h:167
pin_name_t cts
Definition c3gea.h:170
pin_name_t ring
Definition c3gea.h:169
bool uart_blocking
Definition c3gea.h:174
uart_data_bits_t data_bit
Definition c3gea.h:175
pin_name_t tx_pin
Definition c3gea.h:163
pin_name_t rx_pin
Definition c3gea.h:162
uart_stop_bits_t stop_bit
Definition c3gea.h:177
uart_parity_t parity_bit
Definition c3gea.h:176
3G-EA Click context object.
Definition c3gea.h:136
digital_in_t sta
Definition c3gea.h:142
digital_out_t rts
Definition c3gea.h:139
uart_t uart
Definition c3gea.h:147
digital_in_t cts
Definition c3gea.h:144
digital_out_t pwk
Definition c3gea.h:138
digital_in_t ring
Definition c3gea.h:143