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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_uart.h"
48 
69 #define LTEIOT4_CMD_AT "AT"
70 #define LTEIOT4_CMD_MODULE_VERSION "AT+CGMM"
71 #define LTEIOT4_CMD_FW_VERSION "AT+CGMR"
72 #define LTEIOT4_CMD_FLIGHT_MODE "AT+CFUN=4"
73 #define LTEIOT4_CMD_NBIOT_MODE "AT%XSYSTEMMODE=0,1,0,0"
74 #define LTEIOT4_CMD_ENABLE_NET_SMS "AT+CIND=1,0,1"
75 #define LTEIOT4_CMD_FULL_FUNCTION "AT+CFUN=1"
76 #define LTEIOT4_CMD_AUTO_NET_SRC "AT+COPS=0"
77 #define LTEIOT4_CMD_SEARCH_NET "AT+CEREG=2"
78 #define LTEIOT4_CMD_SIM_TEST "AT+CIMI"
79 #define LTEIOT4_CMD_CHECK_CONNECTION "AT+CGATT?"
80 #define LTEIOT4_CMD_CHECK_REGISTARTION "AT+CEREG?"
81 #define LTEIOT4_CMD_SIGNAL_QUALITY "AT+CESQ"
82 #define LTEIOT4_CMD_SET_DUMMY_CLOCK "AT+CCLK=\"20/12/31,23:59:39+01\""
83 #define LTEIOT4_CMD_CHECK_TEMPERATURE "AT%XTEMP?"
84 #define LTEIOT4_CMD_CHECK_CLOCK "AT+CCLK?"
85 
91 #define DRV_BUFFER_SIZE 500
92  // lteiot4_set
94 
109 #define LTEIOT4_MAP_MIKROBUS( cfg, mikrobus ) \
110  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
111  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
112  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
113 
114  // lteiot4_map // lteiot4
116 
121 typedef struct
122 {
123  // Output pins
124  digital_out_t rst;
126  // Modules
127  uart_t uart;
129  // Buffers
130  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
131  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
133 } lteiot4_t;
134 
139 typedef struct
140 {
141  // Communication gpio pins
142  pin_name_t rx_pin;
143  pin_name_t tx_pin;
145  // Additional gpio pins
146  pin_name_t rst;
148  // Static variable
149 
150  uint32_t baud_rate;
152  uart_data_bits_t data_bit;
153  uart_parity_t parity_bit;
154  uart_stop_bits_t stop_bit;
156 } lteiot4_cfg_t;
157 
174 
189 err_t lteiot4_init ( lteiot4_t *ctx, lteiot4_cfg_t *cfg );
190 
205 
219 err_t lteiot4_generic_write ( lteiot4_t *ctx, char *data_buf, uint16_t len );
220 
234 err_t lteiot4_generic_read ( lteiot4_t *ctx, char *data_buf, uint16_t max_len );
235 
246 void lteiot4_set_rst ( lteiot4_t *ctx, uint8_t state );
247 
259 void lteiot4_send_cmd ( lteiot4_t *ctx, char *cmd );
260 
272 void lteiot4_set_sim_apn ( lteiot4_t *ctx, char *sim_apn );
273 
274 #ifdef __cplusplus
275 }
276 #endif
277 #endif // LTEIOT4_H
278  // lteiot4
280 
281 // ------------------------------------------------------------------------ END
lteiot4_cfg_t::rst
pin_name_t rst
Definition: lteiot4.h:146
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:152
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:154
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:153
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:151
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
LTE IoT 4 driver buffer size.
Definition: lteiot4.h:91
lteiot4_t::uart
uart_t uart
Definition: lteiot4.h:127
lteiot4_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lteiot4.h:142
lteiot4_t
LTE IoT 4 Click context object.
Definition: lteiot4.h:122
lteiot4_cfg_t
LTE IoT 4 Click configuration object.
Definition: lteiot4.h:140
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:150
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:143
lteiot4_t::rst
digital_out_t rst
Definition: lteiot4.h:124