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 "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 IOTEXPRESSLINK2_CMD_AT "AT"
70 #define IOTEXPRESSLINK2_CMD_CONNECT "AT+CONNECT"
71 #define IOTEXPRESSLINK2_CMD_CONNECT_CHECK "AT+CONNECT?"
72 #define IOTEXPRESSLINK2_CMD_DISCONNECT "AT+DISCONNECT"
73 #define IOTEXPRESSLINK2_CMD_SLEEP "AT+SLEEP"
74 #define IOTEXPRESSLINK2_CMD_CONFMODE "AT+CONFMODE"
75 #define IOTEXPRESSLINK2_CMD_RESET "AT+RESET"
76 #define IOTEXPRESSLINK2_CMD_FACTORY_RESET "AT+FACTORY_RESET"
77 #define IOTEXPRESSLINK2_CMD_SEND "AT+SEND"
78 #define IOTEXPRESSLINK2_CMD_GET "AT+GET"
79 #define IOTEXPRESSLINK2_CMD_SUBSCRIBE "AT+SUBSCRIBE"
80 #define IOTEXPRESSLINK2_CMD_UNSUBSCRIBE "AT+UNSUBSCRIBE"
81 #define IOTEXPRESSLINK2_CMD_CONF "AT+CONF"
82 #define IOTEXPRESSLINK2_CMD_CONF_CHECK "AT+CONF?"
83 #define IOTEXPRESSLINK2_CMD_EVENT "AT+EVENT?"
84 #define IOTEXPRESSLINK2_CMD_TIME "AT+TIME"
85 #define IOTEXPRESSLINK2_CMD_WHERE "AT+WHERE"
86 #define IOTEXPRESSLINK2_CMD_SEPARATOR " "
87 #define IOTEXPRESSLINK2_CMD_SIGN_EQUAL "="
88 
93 #define IOTEXPRESSLINK2_CONF_KEY_ABOUT "About"
94 #define IOTEXPRESSLINK2_CONF_KEY_VERSION "Version"
95 #define IOTEXPRESSLINK2_CONF_KEY_TECH_SPEC "TechSpec"
96 #define IOTEXPRESSLINK2_CONF_KEY_THING_NAME "ThingName"
97 #define IOTEXPRESSLINK2_CONF_KEY_CERTIFICATE "Certificate"
98 #define IOTEXPRESSLINK2_CONF_KEY_CERTIFICATE_PEM "Certificate pem"
99 #define IOTEXPRESSLINK2_CONF_KEY_CUSTOM_NAME "CustomName"
100 #define IOTEXPRESSLINK2_CONF_KEY_ENDPOINT "Endpoint"
101 #define IOTEXPRESSLINK2_CONF_KEY_ROOT_CA "RootCA"
102 #define IOTEXPRESSLINK2_CONF_KEY_DEFENDER "Defender"
103 #define IOTEXPRESSLINK2_CONF_KEY_HOTA_CERTIFICATE "HOTAcertificate"
104 #define IOTEXPRESSLINK2_CONF_KEY_OTA_CERTIFICATE "OTAcertificate"
105 #define IOTEXPRESSLINK2_CONF_KEY_APN "APN"
106 #define IOTEXPRESSLINK2_CONF_KEY_QOS "QOS"
107 #define IOTEXPRESSLINK2_CONF_KEY_TOPIC "Topic"
108 
113 #define IOTEXPRESSLINK2_RSP_OK "OK"
114 #define IOTEXPRESSLINK2_RSP_ERR "ERR"
115 
120 #define IOTEXPRESSLINK2_EVENT_TIMEOUT 10000ul
121 #define IOTEXPRESSLINK2_CONNECT_TIMEOUT 1000000ul
122 #define IOTEXPRESSLINK2_NORMAL_TIMEOUT 5000ul
123 
128 #define IOTEXPRESSLINK2_POWER_ON_DELAY 15
129 #define IOTEXPRESSLINK2_EMERGENCY_SD_DELAY 25
130 #define IOTEXPRESSLINK2_EMERGENCY_SD_RETRY 5
131 
137 #define IOTEXPRESSLINK2_TX_DRV_BUFFER_SIZE 200
138 #define IOTEXPRESSLINK2_RX_DRV_BUFFER_SIZE 900
139  // iotexpresslink2_cmd
141 
156 #define IOTEXPRESSLINK2_MAP_MIKROBUS( cfg, mikrobus ) \
157  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
158  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
159  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
160  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
161  cfg.wake = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
162  cfg.event = MIKROBUS( mikrobus, MIKROBUS_INT );
163  // iotexpresslink2_map // iotexpresslink2
166 
171 typedef struct
172 {
173  // Output pins
174  digital_out_t pwr;
175  digital_out_t rst;
177  // Input pins
178  digital_in_t wake;
179  digital_in_t event;
181  // Modules
182  uart_t uart;
184  // Buffers
185  uint8_t uart_rx_buffer[ IOTEXPRESSLINK2_RX_DRV_BUFFER_SIZE ];
186  uint8_t uart_tx_buffer[ IOTEXPRESSLINK2_TX_DRV_BUFFER_SIZE ];
189 
194 typedef struct
195 {
196  // Communication gpio pins
197  pin_name_t rx_pin;
198  pin_name_t tx_pin;
200  // Additional gpio pins
201  pin_name_t pwr;
202  pin_name_t rst;
203  pin_name_t wake;
204  pin_name_t event;
206  // Static variable
207  uint32_t baud_rate;
209  uart_data_bits_t data_bit;
210  uart_parity_t parity_bit;
211  uart_stop_bits_t stop_bit;
214 
219 typedef enum
220 {
225 
227 
244 
259 
272 err_t iotexpresslink2_generic_write ( iotexpresslink2_t *ctx, uint8_t *data_in, uint16_t len );
273 
286 err_t iotexpresslink2_generic_read ( iotexpresslink2_t *ctx, uint8_t *data_out, uint16_t len );
287 
297 void iotexpresslink2_send_cmd ( iotexpresslink2_t *ctx, uint8_t *cmd );
298 
308 void iotexpresslink2_set_pwr_pin ( iotexpresslink2_t *ctx, uint8_t state );
309 
319 void iotexpresslink2_set_rst_pin ( iotexpresslink2_t *ctx, uint8_t state );
320 
330 
340 
350 
360 
361 #ifdef __cplusplus
362 }
363 #endif
364 #endif // IOTEXPRESSLINK2_H
365  // iotexpresslink2
367 
368 // ------------------------------------------------------------------------ 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:204
iotexpresslink2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: iotexpresslink2.h:210
iotexpresslink2_cfg_t::pwr
pin_name_t pwr
Definition: iotexpresslink2.h:201
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:207
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:221
iotexpresslink2_t::event
digital_in_t event
Definition: iotexpresslink2.h:179
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:195
IOTEXPRESSLINK2_RX_DRV_BUFFER_SIZE
#define IOTEXPRESSLINK2_RX_DRV_BUFFER_SIZE
Definition: iotexpresslink2.h:138
iotexpresslink2_t::wake
digital_in_t wake
Definition: iotexpresslink2.h:178
iotexpresslink2_return_value_t
iotexpresslink2_return_value_t
IoT ExpressLink 2 Click return value data.
Definition: iotexpresslink2.h:220
IOTEXPRESSLINK2_ERROR_CMD
@ IOTEXPRESSLINK2_ERROR_CMD
Definition: iotexpresslink2.h:224
iotexpresslink2_cfg_t::tx_pin
pin_name_t tx_pin
Definition: iotexpresslink2.h:198
IOTEXPRESSLINK2_TX_DRV_BUFFER_SIZE
#define IOTEXPRESSLINK2_TX_DRV_BUFFER_SIZE
IoT ExpressLink 2 driver buffer size.
Definition: iotexpresslink2.h:137
iotexpresslink2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: iotexpresslink2.h:197
iotexpresslink2_t
IoT ExpressLink 2 Click context object.
Definition: iotexpresslink2.h:172
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:209
iotexpresslink2_cfg_t::wake
pin_name_t wake
Definition: iotexpresslink2.h:203
IOTEXPRESSLINK2_ERROR_TIMEOUT
@ IOTEXPRESSLINK2_ERROR_TIMEOUT
Definition: iotexpresslink2.h:223
iotexpresslink2_t::pwr
digital_out_t pwr
Definition: iotexpresslink2.h:174
iotexpresslink2_cfg_t::rst
pin_name_t rst
Definition: iotexpresslink2.h:202
iotexpresslink2_t::uart
uart_t uart
Definition: iotexpresslink2.h:182
IOTEXPRESSLINK2_ERROR
@ IOTEXPRESSLINK2_ERROR
Definition: iotexpresslink2.h:222
iotexpresslink2_t::rst
digital_out_t rst
Definition: iotexpresslink2.h:175
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:211
iotexpresslink2_cfg_t::uart_blocking
bool uart_blocking
Definition: iotexpresslink2.h:208