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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
59 #define IOTEXPRESSLINK2_CMD_AT "AT"
60 #define IOTEXPRESSLINK2_CMD_CONNECT "AT+CONNECT"
61 #define IOTEXPRESSLINK2_CMD_CONNECT_CHECK "AT+CONNECT?"
62 #define IOTEXPRESSLINK2_CMD_DISCONNECT "AT+DISCONNECT"
63 #define IOTEXPRESSLINK2_CMD_SLEEP "AT+SLEEP"
64 #define IOTEXPRESSLINK2_CMD_CONFMODE "AT+CONFMODE"
65 #define IOTEXPRESSLINK2_CMD_RESET "AT+RESET"
66 #define IOTEXPRESSLINK2_CMD_FACTORY_RESET "AT+FACTORY_RESET"
67 #define IOTEXPRESSLINK2_CMD_SEND "AT+SEND"
68 #define IOTEXPRESSLINK2_CMD_GET "AT+GET"
69 #define IOTEXPRESSLINK2_CMD_SUBSCRIBE "AT+SUBSCRIBE"
70 #define IOTEXPRESSLINK2_CMD_UNSUBSCRIBE "AT+UNSUBSCRIBE"
71 #define IOTEXPRESSLINK2_CMD_CONF "AT+CONF"
72 #define IOTEXPRESSLINK2_CMD_CONF_CHECK "AT+CONF?"
73 #define IOTEXPRESSLINK2_CMD_EVENT "AT+EVENT?"
74 #define IOTEXPRESSLINK2_CMD_TIME "AT+TIME"
75 #define IOTEXPRESSLINK2_CMD_WHERE "AT+WHERE"
76 #define IOTEXPRESSLINK2_CMD_SEPARATOR " "
77 #define IOTEXPRESSLINK2_CMD_SIGN_EQUAL "="
78 
83 #define IOTEXPRESSLINK2_CONF_KEY_ABOUT "About"
84 #define IOTEXPRESSLINK2_CONF_KEY_VERSION "Version"
85 #define IOTEXPRESSLINK2_CONF_KEY_TECH_SPEC "TechSpec"
86 #define IOTEXPRESSLINK2_CONF_KEY_THING_NAME "ThingName"
87 #define IOTEXPRESSLINK2_CONF_KEY_CERTIFICATE "Certificate"
88 #define IOTEXPRESSLINK2_CONF_KEY_CERTIFICATE_PEM "Certificate pem"
89 #define IOTEXPRESSLINK2_CONF_KEY_CUSTOM_NAME "CustomName"
90 #define IOTEXPRESSLINK2_CONF_KEY_ENDPOINT "Endpoint"
91 #define IOTEXPRESSLINK2_CONF_KEY_ROOT_CA "RootCA"
92 #define IOTEXPRESSLINK2_CONF_KEY_DEFENDER "Defender"
93 #define IOTEXPRESSLINK2_CONF_KEY_HOTA_CERTIFICATE "HOTAcertificate"
94 #define IOTEXPRESSLINK2_CONF_KEY_OTA_CERTIFICATE "OTAcertificate"
95 #define IOTEXPRESSLINK2_CONF_KEY_APN "APN"
96 #define IOTEXPRESSLINK2_CONF_KEY_QOS "QOS"
97 #define IOTEXPRESSLINK2_CONF_KEY_TOPIC "Topic"
98 
103 #define IOTEXPRESSLINK2_RSP_OK "OK"
104 #define IOTEXPRESSLINK2_RSP_ERR "ERR"
105 
110 #define IOTEXPRESSLINK2_EVENT_TIMEOUT 10000ul
111 #define IOTEXPRESSLINK2_CONNECT_TIMEOUT 1000000ul
112 #define IOTEXPRESSLINK2_NORMAL_TIMEOUT 5000ul
113 
118 #define IOTEXPRESSLINK2_POWER_ON_DELAY 15
119 #define IOTEXPRESSLINK2_EMERGENCY_SD_DELAY 25
120 #define IOTEXPRESSLINK2_EMERGENCY_SD_RETRY 5
121 
127 #define IOTEXPRESSLINK2_TX_DRV_BUFFER_SIZE 200
128 #define IOTEXPRESSLINK2_RX_DRV_BUFFER_SIZE 900
129  // iotexpresslink2_cmd
131 
146 #define IOTEXPRESSLINK2_MAP_MIKROBUS( cfg, mikrobus ) \
147  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
148  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
149  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
150  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
151  cfg.wake = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
152  cfg.event = MIKROBUS( mikrobus, MIKROBUS_INT );
153  // iotexpresslink2_map // iotexpresslink2
156 
161 typedef struct
162 {
163  // Output pins
164  digital_out_t pwr;
165  digital_out_t rst;
167  // Input pins
168  digital_in_t wake;
169  digital_in_t event;
171  // Modules
172  uart_t uart;
174  // Buffers
175  uint8_t uart_rx_buffer[ IOTEXPRESSLINK2_RX_DRV_BUFFER_SIZE ];
176  uint8_t uart_tx_buffer[ IOTEXPRESSLINK2_TX_DRV_BUFFER_SIZE ];
179 
184 typedef struct
185 {
186  // Communication gpio pins
187  pin_name_t rx_pin;
188  pin_name_t tx_pin;
190  // Additional gpio pins
191  pin_name_t pwr;
192  pin_name_t rst;
193  pin_name_t wake;
194  pin_name_t event;
196  // Static variable
197  uint32_t baud_rate;
199  uart_data_bits_t data_bit;
200  uart_parity_t parity_bit;
201  uart_stop_bits_t stop_bit;
204 
209 typedef enum
210 {
215 
217 
234 
249 
262 err_t iotexpresslink2_generic_write ( iotexpresslink2_t *ctx, uint8_t *data_in, uint16_t len );
263 
276 err_t iotexpresslink2_generic_read ( iotexpresslink2_t *ctx, uint8_t *data_out, uint16_t len );
277 
287 void iotexpresslink2_send_cmd ( iotexpresslink2_t *ctx, uint8_t *cmd );
288 
298 void iotexpresslink2_set_pwr_pin ( iotexpresslink2_t *ctx, uint8_t state );
299 
309 void iotexpresslink2_set_rst_pin ( iotexpresslink2_t *ctx, uint8_t state );
310 
320 
330 
340 
350 
351 #ifdef __cplusplus
352 }
353 #endif
354 #endif // IOTEXPRESSLINK2_H
355  // iotexpresslink2
357 
358 // ------------------------------------------------------------------------ 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:194
iotexpresslink2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: iotexpresslink2.h:200
iotexpresslink2_cfg_t::pwr
pin_name_t pwr
Definition: iotexpresslink2.h:191
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:197
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:211
iotexpresslink2_t::event
digital_in_t event
Definition: iotexpresslink2.h:169
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:185
IOTEXPRESSLINK2_RX_DRV_BUFFER_SIZE
#define IOTEXPRESSLINK2_RX_DRV_BUFFER_SIZE
Definition: iotexpresslink2.h:128
iotexpresslink2_t::wake
digital_in_t wake
Definition: iotexpresslink2.h:168
iotexpresslink2_return_value_t
iotexpresslink2_return_value_t
IoT ExpressLink 2 Click return value data.
Definition: iotexpresslink2.h:210
IOTEXPRESSLINK2_ERROR_CMD
@ IOTEXPRESSLINK2_ERROR_CMD
Definition: iotexpresslink2.h:214
iotexpresslink2_cfg_t::tx_pin
pin_name_t tx_pin
Definition: iotexpresslink2.h:188
IOTEXPRESSLINK2_TX_DRV_BUFFER_SIZE
#define IOTEXPRESSLINK2_TX_DRV_BUFFER_SIZE
IoT ExpressLink 2 driver buffer size.
Definition: iotexpresslink2.h:127
iotexpresslink2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: iotexpresslink2.h:187
iotexpresslink2_t
IoT ExpressLink 2 Click context object.
Definition: iotexpresslink2.h:162
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:199
iotexpresslink2_cfg_t::wake
pin_name_t wake
Definition: iotexpresslink2.h:193
IOTEXPRESSLINK2_ERROR_TIMEOUT
@ IOTEXPRESSLINK2_ERROR_TIMEOUT
Definition: iotexpresslink2.h:213
iotexpresslink2_t::pwr
digital_out_t pwr
Definition: iotexpresslink2.h:164
iotexpresslink2_cfg_t::rst
pin_name_t rst
Definition: iotexpresslink2.h:192
iotexpresslink2_t::uart
uart_t uart
Definition: iotexpresslink2.h:172
IOTEXPRESSLINK2_ERROR
@ IOTEXPRESSLINK2_ERROR
Definition: iotexpresslink2.h:212
iotexpresslink2_t::rst
digital_out_t rst
Definition: iotexpresslink2.h:165
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:201
iotexpresslink2_cfg_t::uart_blocking
bool uart_blocking
Definition: iotexpresslink2.h:198