lteiot 2.0.0.0
lteiot.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef LTEIOT_H
36#define LTEIOT_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_uart.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define LTEIOT_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69 cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.ri = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
73 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
80#define LTEIOT_RETVAL uint8_t
81
82#define LTEIOT_OK 0x00
83#define LTEIOT_INIT_ERROR 0xFF
90#define LTEIOT_MODULE_POWER_ON 1
91#define LTEIOT_MODULE_POWER_OFF 0
98#define LTEIOT_CMD_AT "AT"
99#define LTEIOT_CMD_ATI "ATI"
100#define LTEIOT_CMD_CGMR "AT+CGMR"
101
102#define LTEIOT_CMD_CFUN "AT+CFUN"
103#define LTEIOT_CMD_CREG "AT+CREG"
104#define LTEIOT_CMD_CEREG "AT+CEREG"
105#define LTEIOT_CMD_CGDCONT "AT+CGDCONT"
106#define LTEIOT_CMD_CIMI "AT+CIMI"
107#define LTEIOT_CMD_CGATT "AT+CGATT"
108#define LTEIOT_CMD_CSQ "AT+CSQ"
109#define LTEIOT_CMD_CESQ "AT+CESQ"
110#define LTEIOT_CMD_COPS "AT+COPS"
117#define DRV_RX_BUFFER_SIZE 500
118#define DRV_TX_BUFFER_SIZE 100
121 // End group macro
122// --------------------------------------------------------------- PUBLIC TYPES
130typedef struct
131{
132 // Output pins
133
134 digital_out_t pwr;
135 digital_out_t rst;
136 digital_out_t rts;
137
138 // Input pins
139
140 digital_in_t ri;
141 digital_in_t cts;
142
143 // Modules
144
145 uart_t uart;
146
147 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
148 char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
149
150} lteiot_t;
151
155typedef struct
156{
157 // Communication gpio pins
158
159 pin_name_t rx_pin;
160 pin_name_t tx_pin;
161
162 // Additional gpio pins
163
164 pin_name_t pwr;
165 pin_name_t rst;
166 pin_name_t cts;
167 pin_name_t ri;
168 pin_name_t rts;
169
170 // static variable
171
172 uint32_t baud_rate; // Clock speed.
174 uart_data_bits_t data_bit; // Data bits.
175 uart_parity_t parity_bit; // Parity bit.
176 uart_stop_bits_t stop_bit; // Stop bits.
177
179
180 // End types group
181// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
182
188#ifdef __cplusplus
189extern "C"{
190#endif
191
202
217err_t lteiot_init ( lteiot_t *ctx, lteiot_cfg_t *cfg );
218
232err_t lteiot_generic_write ( lteiot_t *ctx, char *data_buf, uint16_t len );
233
247err_t lteiot_generic_read ( lteiot_t *ctx, char *data_buf, uint16_t max_len );
248
257
266void lteiot_set_rst ( lteiot_t *ctx, uint8_t state );
267
276void lteiot_set_rts ( lteiot_t *ctx, uint8_t state );
277
286uint8_t lteiot_get_cts ( lteiot_t *ctx );
287
297void lteiot_send_cmd ( lteiot_t *ctx, char *cmd );
298
309void lteiot_send_cmd_with_parameter ( lteiot_t *ctx, char *at_cmd_buf, char *param_buf );
310
320void lteiot_send_cmd_check ( lteiot_t *ctx, char *at_cmd_buf );
321
331void lteiot_send_cmd_parameter_check ( lteiot_t *ctx, char *at_cmd_buf );
332
342void lteiot_set_sim_apn ( lteiot_t *ctx, char *sim_apn );
343
354void lteiot_send_text_message ( lteiot_t *ctx, char *phone_number, char *message_context );
355
356#ifdef __cplusplus
357}
358#endif
359#endif // _LTEIOT_H_
360
361 // End public_function group
363
364// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition lteiot.h:117
#define DRV_TX_BUFFER_SIZE
Definition lteiot.h:118
void lteiot_set_sim_apn(lteiot_t *ctx, char *sim_apn)
Set sim card APN.
void lteiot_send_text_message(lteiot_t *ctx, char *phone_number, char *message_context)
LTE IoT send text message.
void lteiot_send_cmd_check(lteiot_t *ctx, char *at_cmd_buf)
Check the sent command.
err_t lteiot_init(lteiot_t *ctx, lteiot_cfg_t *cfg)
LTE IoT initialization function.
uint8_t lteiot_get_cts(lteiot_t *ctx)
CTS Pin Get function.
void lteiot_send_cmd_parameter_check(lteiot_t *ctx, char *at_cmd_buf)
Check the command parameters.
void lteiot_cfg_setup(lteiot_cfg_t *cfg)
LTE IoT configuration object setup function.
void lteiot_send_cmd_with_parameter(lteiot_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
err_t lteiot_generic_read(lteiot_t *ctx, char *data_buf, uint16_t max_len)
LTE IoT data reading function.
void lteiot_set_rts(lteiot_t *ctx, uint8_t state)
Sets state of the RTS pin.
void lteiot_send_cmd(lteiot_t *ctx, char *cmd)
Send command function.
void lteiot_power_on(lteiot_t *ctx)
LTE IoT module power on.
err_t lteiot_generic_write(lteiot_t *ctx, char *data_buf, uint16_t len)
LTE IoT data writing function.
void lteiot_set_rst(lteiot_t *ctx, uint8_t state)
Sets state of the RST pin.
Click configuration structure definition.
Definition lteiot.h:156
pin_name_t rts
Definition lteiot.h:168
uint32_t baud_rate
Definition lteiot.h:172
pin_name_t cts
Definition lteiot.h:166
bool uart_blocking
Definition lteiot.h:173
pin_name_t ri
Definition lteiot.h:167
uart_data_bits_t data_bit
Definition lteiot.h:174
pin_name_t tx_pin
Definition lteiot.h:160
pin_name_t pwr
Definition lteiot.h:164
pin_name_t rx_pin
Definition lteiot.h:159
uart_stop_bits_t stop_bit
Definition lteiot.h:176
uart_parity_t parity_bit
Definition lteiot.h:175
pin_name_t rst
Definition lteiot.h:165
Click ctx object definition.
Definition lteiot.h:131
digital_out_t pwr
Definition lteiot.h:134
digital_out_t rts
Definition lteiot.h:136
digital_in_t ri
Definition lteiot.h:140
uart_t uart
Definition lteiot.h:145
digital_in_t cts
Definition lteiot.h:141
digital_out_t rst
Definition lteiot.h:135