iotexpresslink2  2.1.0.0
iotexpresslink2.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 IOTEXPRESSLINK2_H
29 #define IOTEXPRESSLINK2_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 IOTEXPRESSLINK2_CMD_AT "AT"
74 #define IOTEXPRESSLINK2_CMD_CONNECT "AT+CONNECT"
75 #define IOTEXPRESSLINK2_CMD_CONNECT_CHECK "AT+CONNECT?"
76 #define IOTEXPRESSLINK2_CMD_DISCONNECT "AT+DISCONNECT"
77 #define IOTEXPRESSLINK2_CMD_SLEEP "AT+SLEEP"
78 #define IOTEXPRESSLINK2_CMD_CONFMODE "AT+CONFMODE"
79 #define IOTEXPRESSLINK2_CMD_RESET "AT+RESET"
80 #define IOTEXPRESSLINK2_CMD_FACTORY_RESET "AT+FACTORY_RESET"
81 #define IOTEXPRESSLINK2_CMD_SEND "AT+SEND"
82 #define IOTEXPRESSLINK2_CMD_GET "AT+GET"
83 #define IOTEXPRESSLINK2_CMD_SUBSCRIBE "AT+SUBSCRIBE"
84 #define IOTEXPRESSLINK2_CMD_UNSUBSCRIBE "AT+UNSUBSCRIBE"
85 #define IOTEXPRESSLINK2_CMD_CONF "AT+CONF"
86 #define IOTEXPRESSLINK2_CMD_CONF_CHECK "AT+CONF?"
87 #define IOTEXPRESSLINK2_CMD_EVENT "AT+EVENT?"
88 #define IOTEXPRESSLINK2_CMD_TIME "AT+TIME"
89 #define IOTEXPRESSLINK2_CMD_WHERE "AT+WHERE"
90 #define IOTEXPRESSLINK2_CMD_SEPARATOR " "
91 #define IOTEXPRESSLINK2_CMD_SIGN_EQUAL "="
92 
97 #define IOTEXPRESSLINK2_CONF_KEY_ABOUT "About"
98 #define IOTEXPRESSLINK2_CONF_KEY_VERSION "Version"
99 #define IOTEXPRESSLINK2_CONF_KEY_TECH_SPEC "TechSpec"
100 #define IOTEXPRESSLINK2_CONF_KEY_THING_NAME "ThingName"
101 #define IOTEXPRESSLINK2_CONF_KEY_CERTIFICATE "Certificate"
102 #define IOTEXPRESSLINK2_CONF_KEY_CERTIFICATE_PEM "Certificate pem"
103 #define IOTEXPRESSLINK2_CONF_KEY_CUSTOM_NAME "CustomName"
104 #define IOTEXPRESSLINK2_CONF_KEY_ENDPOINT "Endpoint"
105 #define IOTEXPRESSLINK2_CONF_KEY_ROOT_CA "RootCA"
106 #define IOTEXPRESSLINK2_CONF_KEY_DEFENDER "Defender"
107 #define IOTEXPRESSLINK2_CONF_KEY_HOTA_CERTIFICATE "HOTAcertificate"
108 #define IOTEXPRESSLINK2_CONF_KEY_OTA_CERTIFICATE "OTAcertificate"
109 #define IOTEXPRESSLINK2_CONF_KEY_APN "APN"
110 #define IOTEXPRESSLINK2_CONF_KEY_QOS "QOS"
111 #define IOTEXPRESSLINK2_CONF_KEY_TOPIC "Topic"
112 
117 #define IOTEXPRESSLINK2_RSP_OK "OK"
118 #define IOTEXPRESSLINK2_RSP_ERR "ERR"
119 
124 #define IOTEXPRESSLINK2_EVENT_TIMEOUT 10000ul
125 #define IOTEXPRESSLINK2_CONNECT_TIMEOUT 1000000ul
126 #define IOTEXPRESSLINK2_NORMAL_TIMEOUT 5000ul
127 
132 #define IOTEXPRESSLINK2_POWER_ON_DELAY 15
133 #define IOTEXPRESSLINK2_EMERGENCY_SD_DELAY 25
134 #define IOTEXPRESSLINK2_EMERGENCY_SD_RETRY 5
135 
141 #define IOTEXPRESSLINK2_TX_DRV_BUFFER_SIZE 200
142 #define IOTEXPRESSLINK2_RX_DRV_BUFFER_SIZE 900
143  // iotexpresslink2_cmd
145 
160 #define IOTEXPRESSLINK2_MAP_MIKROBUS( cfg, mikrobus ) \
161  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
162  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
163  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
164  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
165  cfg.wake = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
166  cfg.event = MIKROBUS( mikrobus, MIKROBUS_INT );
167  // iotexpresslink2_map // iotexpresslink2
170 
175 typedef struct
176 {
177  // Output pins
178  digital_out_t pwr;
179  digital_out_t rst;
181  // Input pins
182  digital_in_t wake;
183  digital_in_t event;
185  // Modules
186  uart_t uart;
188  // Buffers
189  uint8_t uart_rx_buffer[ IOTEXPRESSLINK2_RX_DRV_BUFFER_SIZE ];
190  uint8_t uart_tx_buffer[ IOTEXPRESSLINK2_TX_DRV_BUFFER_SIZE ];
193 
198 typedef struct
199 {
200  // Communication gpio pins
201  pin_name_t rx_pin;
202  pin_name_t tx_pin;
204  // Additional gpio pins
205  pin_name_t pwr;
206  pin_name_t rst;
207  pin_name_t wake;
208  pin_name_t event;
210  // Static variable
211  uint32_t baud_rate;
213  uart_data_bits_t data_bit;
214  uart_parity_t parity_bit;
215  uart_stop_bits_t stop_bit;
218 
223 typedef enum
224 {
229 
231 
248 
263 
276 err_t iotexpresslink2_generic_write ( iotexpresslink2_t *ctx, uint8_t *data_in, uint16_t len );
277 
290 err_t iotexpresslink2_generic_read ( iotexpresslink2_t *ctx, uint8_t *data_out, uint16_t len );
291 
301 void iotexpresslink2_send_cmd ( iotexpresslink2_t *ctx, uint8_t *cmd );
302 
312 void iotexpresslink2_set_pwr_pin ( iotexpresslink2_t *ctx, uint8_t state );
313 
323 void iotexpresslink2_set_rst_pin ( iotexpresslink2_t *ctx, uint8_t state );
324 
334 
344 
354 
364 
365 #ifdef __cplusplus
366 }
367 #endif
368 #endif // IOTEXPRESSLINK2_H
369  // iotexpresslink2
371 
372 // ------------------------------------------------------------------------ END
iotexpresslink2_send_cmd
void iotexpresslink2_send_cmd(iotexpresslink2_t *ctx, uint8_t *cmd)
IoT ExpressLink 2 send cmd function.
iotexpresslink2_cfg_setup
void iotexpresslink2_cfg_setup(iotexpresslink2_cfg_t *cfg)
IoT ExpressLink 2 configuration object setup function.
iotexpresslink2_cfg_t::event
pin_name_t event
Definition: iotexpresslink2.h:208
iotexpresslink2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: iotexpresslink2.h:214
iotexpresslink2_cfg_t::pwr
pin_name_t pwr
Definition: iotexpresslink2.h:205
iotexpresslink2_init
err_t iotexpresslink2_init(iotexpresslink2_t *ctx, iotexpresslink2_cfg_t *cfg)
IoT ExpressLink 2 initialization function.
iotexpresslink2_get_event_pin
uint8_t iotexpresslink2_get_event_pin(iotexpresslink2_t *ctx)
IoT ExpressLink 2 get event pin function.
iotexpresslink2_cfg_t::baud_rate
uint32_t baud_rate
Definition: iotexpresslink2.h:211
iotexpresslink2_generic_read
err_t iotexpresslink2_generic_read(iotexpresslink2_t *ctx, uint8_t *data_out, uint16_t len)
IoT ExpressLink 2 data reading function.
IOTEXPRESSLINK2_OK
@ IOTEXPRESSLINK2_OK
Definition: iotexpresslink2.h:225
iotexpresslink2_t::event
digital_in_t event
Definition: iotexpresslink2.h:183
iotexpresslink2_reset_device
void iotexpresslink2_reset_device(iotexpresslink2_t *ctx)
IoT ExpressLink 2 reset device function.
iotexpresslink2_power_on
void iotexpresslink2_power_on(iotexpresslink2_t *ctx)
IoT ExpressLink 2 power on function.
iotexpresslink2_cfg_t
IoT ExpressLink 2 Click configuration object.
Definition: iotexpresslink2.h:199
IOTEXPRESSLINK2_RX_DRV_BUFFER_SIZE
#define IOTEXPRESSLINK2_RX_DRV_BUFFER_SIZE
Definition: iotexpresslink2.h:142
iotexpresslink2_t::wake
digital_in_t wake
Definition: iotexpresslink2.h:182
iotexpresslink2_return_value_t
iotexpresslink2_return_value_t
IoT ExpressLink 2 Click return value data.
Definition: iotexpresslink2.h:224
IOTEXPRESSLINK2_ERROR_CMD
@ IOTEXPRESSLINK2_ERROR_CMD
Definition: iotexpresslink2.h:228
iotexpresslink2_cfg_t::tx_pin
pin_name_t tx_pin
Definition: iotexpresslink2.h:202
IOTEXPRESSLINK2_TX_DRV_BUFFER_SIZE
#define IOTEXPRESSLINK2_TX_DRV_BUFFER_SIZE
IoT ExpressLink 2 driver buffer size.
Definition: iotexpresslink2.h:141
iotexpresslink2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: iotexpresslink2.h:201
iotexpresslink2_t
IoT ExpressLink 2 Click context object.
Definition: iotexpresslink2.h:176
iotexpresslink2_set_rst_pin
void iotexpresslink2_set_rst_pin(iotexpresslink2_t *ctx, uint8_t state)
IoT ExpressLink 2 set rst pin function.
iotexpresslink2_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: iotexpresslink2.h:213
iotexpresslink2_cfg_t::wake
pin_name_t wake
Definition: iotexpresslink2.h:207
IOTEXPRESSLINK2_ERROR_TIMEOUT
@ IOTEXPRESSLINK2_ERROR_TIMEOUT
Definition: iotexpresslink2.h:227
iotexpresslink2_t::pwr
digital_out_t pwr
Definition: iotexpresslink2.h:178
iotexpresslink2_cfg_t::rst
pin_name_t rst
Definition: iotexpresslink2.h:206
iotexpresslink2_t::uart
uart_t uart
Definition: iotexpresslink2.h:186
IOTEXPRESSLINK2_ERROR
@ IOTEXPRESSLINK2_ERROR
Definition: iotexpresslink2.h:226
iotexpresslink2_t::rst
digital_out_t rst
Definition: iotexpresslink2.h:179
iotexpresslink2_generic_write
err_t iotexpresslink2_generic_write(iotexpresslink2_t *ctx, uint8_t *data_in, uint16_t len)
IoT ExpressLink 2 data writing function.
iotexpresslink2_get_wake_pin
uint8_t iotexpresslink2_get_wake_pin(iotexpresslink2_t *ctx)
IoT ExpressLink 2 get wake pin function.
iotexpresslink2_set_pwr_pin
void iotexpresslink2_set_pwr_pin(iotexpresslink2_t *ctx, uint8_t state)
IoT ExpressLink 2 set pwr pin function.
iotexpresslink2_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: iotexpresslink2.h:215
iotexpresslink2_cfg_t::uart_blocking
bool uart_blocking
Definition: iotexpresslink2.h:212