esp8684  2.1.0.0
esp8684.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 ESP8684_H
29 #define ESP8684_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 ESP8684_CMD_AT "AT"
70 #define ESP8684_CMD_RST "AT+RST"
71 #define ESP8684_CMD_GMR "AT+GMR"
72 #define ESP8684_CMD_CWINIT "AT+CWINIT"
73 #define ESP8684_CMD_CWMODE "AT+CWMODE"
74 #define ESP8684_CMD_CWJAP "AT+CWJAP"
75 #define ESP8684_CMD_CWLAP "AT+CWLAP"
76 #define ESP8684_CMD_CWAP "AT+CWQAP"
77 #define ESP8684_CMD_CWSAP "AT+CWSAP"
78 #define ESP8684_CMD_CWLIF "AT+CWLIF"
79 #define ESP8684_CMD_CIPSTATE "AT+CIPSTATE"
80 #define ESP8684_CMD_CIPSTART "AT+CIPSTART"
81 #define ESP8684_CMD_CIPMODE "AT+CIPMODE"
82 #define ESP8684_CMD_CIPSEND "AT+CIPSEND"
83 #define ESP8684_CMD_CIPCLOSE "AT+CIPCLOSE"
84 #define ESP8684_CMD_CIFSR "AT+CIFSR"
85 #define ESP8684_CMD_CIPMUX "AT+CIPMUX"
86 #define ESP8684_CMD_CIPSERVER "AT+CIPSERVER"
87 #define ESP8684_CMD_CIPSTO "AT+CIPSTO"
88 #define ESP8684_CMD_CIPRECVMODE "AT+CIPRECVMODE"
89 
94 #define ESP8684_RSP_RECEIVE "+IPD"
95 #define ESP8684_READY_FOR_SEND ">"
96 #define ESP8684_RSP_OK "OK"
97 #define ESP8684_RSP_SEND_OK "SEND OK"
98 #define ESP8684_RSP_ERROR "ERROR"
99 #define ESP8684_RSP_READY "ready"
100 
105 #define ESP8684_PIN_STATE_HIGH 0x01
106 #define ESP8684_PIN_STATE_LOW 0x00
107 
108 
114 #define ESP8684_TX_DRV_BUFFER_SIZE 100
115 #define ESP8684_RX_DRV_BUFFER_SIZE 300
116  // esp8684_cmd
118 
133 #define ESP8684_MAP_MIKROBUS( cfg, mikrobus ) \
134  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
135  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
136  cfg.bt = MIKROBUS( mikrobus, MIKROBUS_AN ); \
137  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
138  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
139  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
140  // esp8684_map // esp8684
143 
148 typedef struct
149 {
150  // Output pins
151  digital_out_t bt;
152  digital_out_t rst;
153  digital_out_t rts;
155  // Input pins
156  digital_in_t cts;
158  // Modules
159  uart_t uart;
161  // Buffers
162  uint8_t uart_rx_buffer[ ESP8684_RX_DRV_BUFFER_SIZE ];
163  uint8_t uart_tx_buffer[ ESP8684_TX_DRV_BUFFER_SIZE ];
165 } esp8684_t;
166 
171 typedef struct
172 {
173  // Communication gpio pins
174  pin_name_t rx_pin;
175  pin_name_t tx_pin;
177  // Additional gpio pins
178  pin_name_t bt;
179  pin_name_t rst;
180  pin_name_t rts;
181  pin_name_t cts;
183  // Static variable
184  uint32_t baud_rate;
186  uart_data_bits_t data_bit;
187  uart_parity_t parity_bit;
188  uart_stop_bits_t stop_bit;
190 } esp8684_cfg_t;
191 
196 typedef enum
197 {
201  ESP8684_TIMEOUT = -3
202 
204 
221 
235 err_t esp8684_init ( esp8684_t *ctx, esp8684_cfg_t *cfg );
236 
248 
261 err_t esp8684_generic_write ( esp8684_t *ctx, uint8_t *data_in, uint16_t len );
262 
275 err_t esp8684_generic_read ( esp8684_t *ctx, uint8_t *data_out, uint16_t len );
276 
286 void esp8684_set_rst_pin ( esp8684_t *ctx, uint8_t pin_state );
287 
297 void esp8684_set_bt_pin ( esp8684_t *ctx, uint8_t pin_state );
298 
308 void esp8684_set_rts_pin ( esp8684_t *ctx, uint8_t pin_state );
309 
320 
331 void esp8684_send_cmd ( esp8684_t *ctx, uint8_t *cmd, uint8_t *args );
332 
342 void esp8684_send_query_cmd ( esp8684_t *ctx, uint8_t *cmd );
343 
353 void esp8684_send_test_cmd ( esp8684_t *ctx, uint8_t *cmd );
354 
366 void esp8684_connect_to_network ( esp8684_t* ctx, uint8_t *ssid, uint8_t *password );
367 
380 void esp8684_connect_for_trans ( esp8684_t* ctx, uint8_t *type, uint8_t *link_id, uint8_t *remote_host, uint8_t *remote_port );
381 
382 #ifdef __cplusplus
383 }
384 #endif
385 #endif // ESP8684_H
386  // esp8684
388 
389 // ------------------------------------------------------------------------ END
esp8684_send_test_cmd
void esp8684_send_test_cmd(esp8684_t *ctx, uint8_t *cmd)
ESP8684 test query command function.
esp8684_t::bt
digital_out_t bt
Definition: esp8684.h:151
esp8684_connect_for_trans
void esp8684_connect_for_trans(esp8684_t *ctx, uint8_t *type, uint8_t *link_id, uint8_t *remote_host, uint8_t *remote_port)
ESP8684 connect to remote host function.
esp8684_cfg_t::rst
pin_name_t rst
Definition: esp8684.h:179
ESP8684_TX_DRV_BUFFER_SIZE
#define ESP8684_TX_DRV_BUFFER_SIZE
ESP8684 driver buffer size.
Definition: esp8684.h:114
esp8684_init
err_t esp8684_init(esp8684_t *ctx, esp8684_cfg_t *cfg)
ESP8684 initialization function.
esp8684_set_bt_pin
void esp8684_set_bt_pin(esp8684_t *ctx, uint8_t pin_state)
ESP8684 set bt pin state function.
esp8684_t::cts
digital_in_t cts
Definition: esp8684.h:156
esp8684_cfg_setup
void esp8684_cfg_setup(esp8684_cfg_t *cfg)
ESP8684 configuration object setup function.
esp8684_t::rts
digital_out_t rts
Definition: esp8684.h:153
ESP8684_RX_DRV_BUFFER_SIZE
#define ESP8684_RX_DRV_BUFFER_SIZE
Definition: esp8684.h:115
esp8684_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: esp8684.h:187
esp8684_cfg_t::rts
pin_name_t rts
Definition: esp8684.h:180
esp8684_send_query_cmd
void esp8684_send_query_cmd(esp8684_t *ctx, uint8_t *cmd)
ESP8684 send query command function.
esp8684_set_rts_pin
void esp8684_set_rts_pin(esp8684_t *ctx, uint8_t pin_state)
ESP8684 set rts pin state function.
esp8684_generic_write
err_t esp8684_generic_write(esp8684_t *ctx, uint8_t *data_in, uint16_t len)
ESP8684 data writing function.
esp8684_t::rst
digital_out_t rst
Definition: esp8684.h:152
esp8684_send_cmd
void esp8684_send_cmd(esp8684_t *ctx, uint8_t *cmd, uint8_t *args)
ESP8684 send command with arguments function.
esp8684_default_cfg
void esp8684_default_cfg(esp8684_t *ctx)
ESP8684 default configuration function.
esp8684_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: esp8684.h:186
esp8684_connect_to_network
void esp8684_connect_to_network(esp8684_t *ctx, uint8_t *ssid, uint8_t *password)
ESP8684 connect to network function.
esp8684_t
ESP8684 Click context object.
Definition: esp8684.h:149
ESP8684_ERROR
@ ESP8684_ERROR
Definition: esp8684.h:199
esp8684_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: esp8684.h:188
esp8684_generic_read
err_t esp8684_generic_read(esp8684_t *ctx, uint8_t *data_out, uint16_t len)
ESP8684 data reading function.
esp8684_cfg_t::tx_pin
pin_name_t tx_pin
Definition: esp8684.h:175
ESP8684_OVERFLOW
@ ESP8684_OVERFLOW
Definition: esp8684.h:200
esp8684_t::uart
uart_t uart
Definition: esp8684.h:159
esp8684_cfg_t::uart_blocking
bool uart_blocking
Definition: esp8684.h:185
esp8684_cfg_t::baud_rate
uint32_t baud_rate
Definition: esp8684.h:184
esp8684_return_value_t
esp8684_return_value_t
ESP8684 Click return value data.
Definition: esp8684.h:197
ESP8684_OK
@ ESP8684_OK
Definition: esp8684.h:198
esp8684_set_rst_pin
void esp8684_set_rst_pin(esp8684_t *ctx, uint8_t pin_state)
ESP8684 set rst pin state function.
esp8684_cfg_t::rx_pin
pin_name_t rx_pin
Definition: esp8684.h:174
esp8684_cfg_t
ESP8684 Click configuration object.
Definition: esp8684.h:172
ESP8684_TIMEOUT
@ ESP8684_TIMEOUT
Definition: esp8684.h:201
esp8684_get_cts_pin
uint8_t esp8684_get_cts_pin(esp8684_t *ctx)
ESP8684 get cts pin state function.
esp8684_cfg_t::bt
pin_name_t bt
Definition: esp8684.h:178
esp8684_cfg_t::cts
pin_name_t cts
Definition: esp8684.h:181