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 
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 ESP8684_CMD_AT "AT"
74 #define ESP8684_CMD_RST "AT+RST"
75 #define ESP8684_CMD_GMR "AT+GMR"
76 #define ESP8684_CMD_CWINIT "AT+CWINIT"
77 #define ESP8684_CMD_CWMODE "AT+CWMODE"
78 #define ESP8684_CMD_CWJAP "AT+CWJAP"
79 #define ESP8684_CMD_CWLAP "AT+CWLAP"
80 #define ESP8684_CMD_CWAP "AT+CWQAP"
81 #define ESP8684_CMD_CWSAP "AT+CWSAP"
82 #define ESP8684_CMD_CWLIF "AT+CWLIF"
83 #define ESP8684_CMD_CIPSTATE "AT+CIPSTATE"
84 #define ESP8684_CMD_CIPSTART "AT+CIPSTART"
85 #define ESP8684_CMD_CIPMODE "AT+CIPMODE"
86 #define ESP8684_CMD_CIPSEND "AT+CIPSEND"
87 #define ESP8684_CMD_CIPCLOSE "AT+CIPCLOSE"
88 #define ESP8684_CMD_CIFSR "AT+CIFSR"
89 #define ESP8684_CMD_CIPMUX "AT+CIPMUX"
90 #define ESP8684_CMD_CIPSERVER "AT+CIPSERVER"
91 #define ESP8684_CMD_CIPSTO "AT+CIPSTO"
92 #define ESP8684_CMD_CIPRECVMODE "AT+CIPRECVMODE"
93 
98 #define ESP8684_RSP_RECEIVE "+IPD"
99 #define ESP8684_READY_FOR_SEND ">"
100 #define ESP8684_RSP_OK "OK"
101 #define ESP8684_RSP_SEND_OK "SEND OK"
102 #define ESP8684_RSP_ERROR "ERROR"
103 #define ESP8684_RSP_READY "ready"
104 
109 #define ESP8684_PIN_STATE_HIGH 0x01
110 #define ESP8684_PIN_STATE_LOW 0x00
111 
112 
118 #define ESP8684_TX_DRV_BUFFER_SIZE 100
119 #define ESP8684_RX_DRV_BUFFER_SIZE 300
120  // esp8684_cmd
122 
137 #define ESP8684_MAP_MIKROBUS( cfg, mikrobus ) \
138  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
139  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
140  cfg.bt = MIKROBUS( mikrobus, MIKROBUS_AN ); \
141  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
142  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
143  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
144  // esp8684_map // esp8684
147 
152 typedef struct
153 {
154  // Output pins
155  digital_out_t bt;
156  digital_out_t rst;
157  digital_out_t rts;
159  // Input pins
160  digital_in_t cts;
162  // Modules
163  uart_t uart;
165  // Buffers
166  uint8_t uart_rx_buffer[ ESP8684_RX_DRV_BUFFER_SIZE ];
167  uint8_t uart_tx_buffer[ ESP8684_TX_DRV_BUFFER_SIZE ];
169 } esp8684_t;
170 
175 typedef struct
176 {
177  // Communication gpio pins
178  pin_name_t rx_pin;
179  pin_name_t tx_pin;
181  // Additional gpio pins
182  pin_name_t bt;
183  pin_name_t rst;
184  pin_name_t rts;
185  pin_name_t cts;
187  // Static variable
188  uint32_t baud_rate;
190  uart_data_bits_t data_bit;
191  uart_parity_t parity_bit;
192  uart_stop_bits_t stop_bit;
194 } esp8684_cfg_t;
195 
200 typedef enum
201 {
205  ESP8684_TIMEOUT = -3
206 
208 
225 
239 err_t esp8684_init ( esp8684_t *ctx, esp8684_cfg_t *cfg );
240 
252 
265 err_t esp8684_generic_write ( esp8684_t *ctx, uint8_t *data_in, uint16_t len );
266 
279 err_t esp8684_generic_read ( esp8684_t *ctx, uint8_t *data_out, uint16_t len );
280 
290 void esp8684_set_rst_pin ( esp8684_t *ctx, uint8_t pin_state );
291 
301 void esp8684_set_bt_pin ( esp8684_t *ctx, uint8_t pin_state );
302 
312 void esp8684_set_rts_pin ( esp8684_t *ctx, uint8_t pin_state );
313 
324 
335 void esp8684_send_cmd ( esp8684_t *ctx, uint8_t *cmd, uint8_t *args );
336 
346 void esp8684_send_query_cmd ( esp8684_t *ctx, uint8_t *cmd );
347 
357 void esp8684_send_test_cmd ( esp8684_t *ctx, uint8_t *cmd );
358 
370 void esp8684_connect_to_network ( esp8684_t* ctx, uint8_t *ssid, uint8_t *password );
371 
384 void esp8684_connect_for_trans ( esp8684_t* ctx, uint8_t *type, uint8_t *link_id, uint8_t *remote_host, uint8_t *remote_port );
385 
386 #ifdef __cplusplus
387 }
388 #endif
389 #endif // ESP8684_H
390  // esp8684
392 
393 // ------------------------------------------------------------------------ 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:155
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:183
ESP8684_TX_DRV_BUFFER_SIZE
#define ESP8684_TX_DRV_BUFFER_SIZE
ESP8684 driver buffer size.
Definition: esp8684.h:118
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:160
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:157
ESP8684_RX_DRV_BUFFER_SIZE
#define ESP8684_RX_DRV_BUFFER_SIZE
Definition: esp8684.h:119
esp8684_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: esp8684.h:191
esp8684_cfg_t::rts
pin_name_t rts
Definition: esp8684.h:184
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:156
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:190
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:153
ESP8684_ERROR
@ ESP8684_ERROR
Definition: esp8684.h:203
esp8684_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: esp8684.h:192
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:179
ESP8684_OVERFLOW
@ ESP8684_OVERFLOW
Definition: esp8684.h:204
esp8684_t::uart
uart_t uart
Definition: esp8684.h:163
esp8684_cfg_t::uart_blocking
bool uart_blocking
Definition: esp8684.h:189
esp8684_cfg_t::baud_rate
uint32_t baud_rate
Definition: esp8684.h:188
esp8684_return_value_t
esp8684_return_value_t
ESP8684 Click return value data.
Definition: esp8684.h:201
ESP8684_OK
@ ESP8684_OK
Definition: esp8684.h:202
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:178
esp8684_cfg_t
ESP8684 Click configuration object.
Definition: esp8684.h:176
ESP8684_TIMEOUT
@ ESP8684_TIMEOUT
Definition: esp8684.h:205
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:182
esp8684_cfg_t::cts
pin_name_t cts
Definition: esp8684.h:185