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 
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 LTEIOT4_CMD_AT "AT"
74 #define LTEIOT4_CMD_MODULE_VERSION "AT+CGMM"
75 #define LTEIOT4_CMD_FW_VERSION "AT+CGMR"
76 #define LTEIOT4_CMD_FLIGHT_MODE "AT+CFUN=4"
77 #define LTEIOT4_CMD_NBIOT_MODE "AT%XSYSTEMMODE=0,1,0,0"
78 #define LTEIOT4_CMD_ENABLE_NET_SMS "AT+CIND=1,0,1"
79 #define LTEIOT4_CMD_FULL_FUNCTION "AT+CFUN=1"
80 #define LTEIOT4_CMD_AUTO_NET_SRC "AT+COPS=0"
81 #define LTEIOT4_CMD_SEARCH_NET "AT+CEREG=2"
82 #define LTEIOT4_CMD_SIM_TEST "AT+CIMI"
83 #define LTEIOT4_CMD_CHECK_CONNECTION "AT+CGATT?"
84 #define LTEIOT4_CMD_CHECK_REGISTARTION "AT+CEREG?"
85 #define LTEIOT4_CMD_SIGNAL_QUALITY "AT+CESQ"
86 #define LTEIOT4_CMD_SET_DUMMY_CLOCK "AT+CCLK=\"20/12/31,23:59:39+01\""
87 #define LTEIOT4_CMD_CHECK_TEMPERATURE "AT%XTEMP?"
88 #define LTEIOT4_CMD_CHECK_CLOCK "AT+CCLK?"
89 
95 #define DRV_BUFFER_SIZE 500
96  // lteiot4_set
98 
113 #define LTEIOT4_MAP_MIKROBUS( cfg, mikrobus ) \
114  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
115  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
116  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
117 
118  // lteiot4_map // lteiot4
120 
125 typedef struct
126 {
127  // Output pins
128  digital_out_t rst;
130  // Modules
131  uart_t uart;
133  // Buffers
134  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
135  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
137 } lteiot4_t;
138 
143 typedef struct
144 {
145  // Communication gpio pins
146  pin_name_t rx_pin;
147  pin_name_t tx_pin;
149  // Additional gpio pins
150  pin_name_t rst;
152  // Static variable
153 
154  uint32_t baud_rate;
156  uart_data_bits_t data_bit;
157  uart_parity_t parity_bit;
158  uart_stop_bits_t stop_bit;
160 } lteiot4_cfg_t;
161 
178 
193 err_t lteiot4_init ( lteiot4_t *ctx, lteiot4_cfg_t *cfg );
194 
209 
223 err_t lteiot4_generic_write ( lteiot4_t *ctx, char *data_buf, uint16_t len );
224 
238 err_t lteiot4_generic_read ( lteiot4_t *ctx, char *data_buf, uint16_t max_len );
239 
250 void lteiot4_set_rst ( lteiot4_t *ctx, uint8_t state );
251 
263 void lteiot4_send_cmd ( lteiot4_t *ctx, char *cmd );
264 
276 void lteiot4_set_sim_apn ( lteiot4_t *ctx, char *sim_apn );
277 
278 #ifdef __cplusplus
279 }
280 #endif
281 #endif // LTEIOT4_H
282  // lteiot4
284 
285 // ------------------------------------------------------------------------ END
lteiot4_cfg_t::rst
pin_name_t rst
Definition: lteiot4.h:150
lteiot4_cfg_setup
void lteiot4_cfg_setup(lteiot4_cfg_t *cfg)
LTE IoT 4 configuration object setup function.
lteiot4_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lteiot4.h:156
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_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lteiot4.h:158
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_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lteiot4.h:157
lteiot4_set_rst
void lteiot4_set_rst(lteiot4_t *ctx, uint8_t state)
Sets state of the rst pin setting.
lteiot4_cfg_t::uart_blocking
bool uart_blocking
Definition: lteiot4.h:155
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
LTE IoT 4 driver buffer size.
Definition: lteiot4.h:95
lteiot4_t::uart
uart_t uart
Definition: lteiot4.h:131
lteiot4_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lteiot4.h:146
lteiot4_t
LTE IoT 4 Click context object.
Definition: lteiot4.h:126
lteiot4_cfg_t
LTE IoT 4 Click configuration object.
Definition: lteiot4.h:144
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_cfg_t::baud_rate
uint32_t baud_rate
Definition: lteiot4.h:154
lteiot4_send_cmd
void lteiot4_send_cmd(lteiot4_t *ctx, char *cmd)
Send command function.
lteiot4_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lteiot4.h:147
lteiot4_t::rst
digital_out_t rst
Definition: lteiot4.h:128