lteiot4  2.0.0.0
lteiot4.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 LTEIOT4_H
29 #define LTEIOT4_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 LTEIOT4_CMD_AT "AT"
60 #define LTEIOT4_CMD_MODULE_VERSION "AT+CGMM"
61 #define LTEIOT4_CMD_FW_VERSION "AT+CGMR"
62 #define LTEIOT4_CMD_FLIGHT_MODE "AT+CFUN=4"
63 #define LTEIOT4_CMD_NBIOT_MODE "AT%XSYSTEMMODE=0,1,0,0"
64 #define LTEIOT4_CMD_ENABLE_NET_SMS "AT+CIND=1,0,1"
65 #define LTEIOT4_CMD_FULL_FUNCTION "AT+CFUN=1"
66 #define LTEIOT4_CMD_AUTO_NET_SRC "AT+COPS=0"
67 #define LTEIOT4_CMD_SEARCH_NET "AT+CEREG=2"
68 #define LTEIOT4_CMD_SIM_TEST "AT+CIMI"
69 #define LTEIOT4_CMD_CHECK_CONNECTION "AT+CGATT?"
70 #define LTEIOT4_CMD_CHECK_REGISTARTION "AT+CEREG?"
71 #define LTEIOT4_CMD_SIGNAL_QUALITY "AT+CESQ"
72 #define LTEIOT4_CMD_SET_DUMMY_CLOCK "AT+CCLK=\"20/12/31,23:59:39+01\""
73 #define LTEIOT4_CMD_CHECK_TEMPERATURE "AT%XTEMP?"
74 #define LTEIOT4_CMD_CHECK_CLOCK "AT+CCLK?"
75 
81 #define DRV_BUFFER_SIZE 500
82  // lteiot4_set
84 
99 #define LTEIOT4_MAP_MIKROBUS( cfg, mikrobus ) \
100  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
101  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
102  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
103 
104  // lteiot4_map // lteiot4
106 
111 typedef struct
112 {
113  // Output pins
114  digital_out_t rst;
116  // Modules
117  uart_t uart;
119  // Buffers
120  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
121  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
123 } lteiot4_t;
124 
129 typedef struct
130 {
131  // Communication gpio pins
132  pin_name_t rx_pin;
133  pin_name_t tx_pin;
135  // Additional gpio pins
136  pin_name_t rst;
138  // Static variable
139 
140  uint32_t baud_rate;
141  bool uart_blocking;
142  uart_data_bits_t data_bit;
143  uart_parity_t parity_bit;
144  uart_stop_bits_t stop_bit;
146 } lteiot4_cfg_t;
147 
163 void lteiot4_cfg_setup ( lteiot4_cfg_t *cfg );
164 
179 err_t lteiot4_init ( lteiot4_t *ctx, lteiot4_cfg_t *cfg );
180 
194 err_t lteiot4_default_cfg ( lteiot4_t *ctx );
195 
209 err_t lteiot4_generic_write ( lteiot4_t *ctx, char *data_buf, uint16_t len );
210 
224 err_t lteiot4_generic_read ( lteiot4_t *ctx, char *data_buf, uint16_t max_len );
225 
236 void lteiot4_set_rst ( lteiot4_t *ctx, uint8_t state );
237 
249 void lteiot4_send_cmd ( lteiot4_t *ctx, char *cmd );
250 
262 void lteiot4_set_sim_apn ( lteiot4_t *ctx, char *sim_apn );
263 
264 #ifdef __cplusplus
265 }
266 #endif
267 #endif // LTEIOT4_H
268  // lteiot4
270 
271 // ------------------------------------------------------------------------ END
lteiot4_cfg_setup
void lteiot4_cfg_setup(lteiot4_cfg_t *cfg)
LTE IoT 4 configuration object setup function.
lteiot4_generic_read
err_t lteiot4_generic_read(lteiot4_t *ctx, char *data_buf, uint16_t max_len)
LTE IoT 4 data reading function.
lteiot4_init
err_t lteiot4_init(lteiot4_t *ctx, lteiot4_cfg_t *cfg)
LTE IoT 4 initialization function.
lteiot4_set_sim_apn
void lteiot4_set_sim_apn(lteiot4_t *ctx, char *sim_apn)
Set sim card APN.
lteiot4_set_rst
void lteiot4_set_rst(lteiot4_t *ctx, uint8_t state)
Sets state of the rst pin setting.
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
LTE IoT 4 driver buffer size.
Definition: lteiot4.h:80
lteiot4_t
LTE IoT 4 Click context object.
Definition: lteiot4.h:110
lteiot4_cfg_t
LTE IoT 4 Click configuration object.
Definition: lteiot4.h:128
lteiot4_generic_write
err_t lteiot4_generic_write(lteiot4_t *ctx, char *data_buf, uint16_t len)
LTE IoT 4 data writing function.
lteiot4_default_cfg
err_t lteiot4_default_cfg(lteiot4_t *ctx)
LTE IoT 4 default configuration function.
lteiot4_send_cmd
void lteiot4_send_cmd(lteiot4_t *ctx, char *cmd)
Send command function.