wifiesp  2.0.0.0
wifiesp.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef WIFIESP_H
36 #define WIFIESP_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 #include "log.h"
42 
43 
44 // -------------------------------------------------------------- PUBLIC MACROS
54 #define WIFIESP_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
56  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
57  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
58  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
59 
65 #define WIFIESP_DRV_RX_BUFFER_SIZE 610
66 #define WIFIESP_DRV_TX_BUFFER_SIZE 150
67 
73 #define WIFIESP_CHECK "AT"
74 #define WIFIESP_RESTORE "AT+RESTORE"
75 #define WIFIESP_RST "AT+RST"
76 #define WIFIESP_CHECK_FIRMWARE "AT+GMR"
77 #define WIFIESP_SET_MODE "AT+CWMODE"
78 #define WIFIESP_CONNECT "AT+CWJAP"
79 #define WIFIESP_LIST_AP "AT+CWLAP"
80 #define WIFIESP_QUIT_AP "AT+CWQAP"
81 #define WIFIESP_SET_AP_PARAMETERS "AT+CWSAP"
82 #define WIFIESP_JOIN_DEV_IP "AT+CWLIF"
83 #define WIFIESP_CONNESTION_STATUS "AT+CIPSTATUS"
84 #define WIFIESP_START "AT+CIPSTART"
85 #define WIFIESP_MODE "AT+CIPMODE"
86 #define WIFIESP_SEND "AT+CIPSEND"
87 #define WIFIESP_CLOSE "AT+CIPCLOSE"
88 #define WIFIESP_GET_IP "AT+CIFSR"
89 #define WIFIESP_SET_MULTIPLE_CONNECTION "AT+CIPMUX"
90 #define WIFIESP_SET_AS_SERVER "AT+CIPSERVER"
91 #define WIFIESP_CHECK_SERVER_TIMEOUT "AT+CIPSTO?"
92 #define WIFIESP_RECEIVE "+IPD"
93 
99 #define WIFIESP_RSP_OK "OK"
100 #define WIFIESP_RSP_READY_FOR_SEND ">"
101 #define WIFIESP_RSP_SEND_OK "SEND OK"
102 #define WIFIESP_RSP_ERROR "ERROR"
103 #define WIFIESP_RSP_CONNECT "CONNECT"
104  // End group macro
107 // --------------------------------------------------------------- PUBLIC TYPES
116 typedef struct
117 {
118  // Output pins
119  digital_out_t rst;
120  digital_out_t cs;
121 
122  // Modules
123  uart_t uart;
124 
125  char uart_rx_buffer[ WIFIESP_DRV_RX_BUFFER_SIZE ];
126  char uart_tx_buffer[ WIFIESP_DRV_TX_BUFFER_SIZE ];
127 
128 } wifiesp_t;
129 
133 typedef struct
134 {
135  // Communication gpio pins
136  pin_name_t rx_pin;
137  pin_name_t tx_pin;
138 
139  // Additional gpio pins
140  pin_name_t rst;
141  pin_name_t cs;
142 
143  // static variable
144  uint32_t baud_rate; // Clock speed.
146  uart_data_bits_t data_bit; // Data bits.
147  uart_parity_t parity_bit; // Parity bit.
148  uart_stop_bits_t stop_bit; // Stop bits.
149 
150 } wifiesp_cfg_t;
151 
156 typedef enum
157 {
163 
165  // End types group
167 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
168 
174 #ifdef __cplusplus
175 extern "C"{
176 #endif
177 
187 
195 err_t wifiesp_init ( wifiesp_t *ctx, wifiesp_cfg_t *cfg );
196 
205 
212 void wifiesp_generic_write ( wifiesp_t *ctx, char *data_buf, uint16_t len );
213 
221 int32_t wifiesp_generic_read ( wifiesp_t *ctx, char *data_buf, int32_t max_len );
222 
231 void wifiesp_send_cmd( wifiesp_t* ctx, uint8_t* cmd, uint8_t* args );
232 
233 #ifdef __cplusplus
234 }
235 #endif
236 #endif // _WIFIESP_H_
237  // End public_function group
240 
241 // ------------------------------------------------------------------------- END
WIFIESP_ERROR_CMD
@ WIFIESP_ERROR_CMD
Definition: wifiesp.h:161
wifiesp_cfg_setup
void wifiesp_cfg_setup(wifiesp_cfg_t *cfg)
Config Object Initialization function.
wifiesp_t
Click ctx object definition.
Definition: wifiesp.h:117
WIFIESP_DRV_RX_BUFFER_SIZE
#define WIFIESP_DRV_RX_BUFFER_SIZE
Definition: wifiesp.h:65
wifiesp_t::uart
uart_t uart
Definition: wifiesp.h:123
WIFIESP_ERROR
@ WIFIESP_ERROR
Definition: wifiesp.h:159
wifiesp_init
err_t wifiesp_init(wifiesp_t *ctx, wifiesp_cfg_t *cfg)
Initialization function.
wifiesp_return_value_t
wifiesp_return_value_t
WiFi ESP Click return value data.
Definition: wifiesp.h:157
WIFIESP_DRV_TX_BUFFER_SIZE
#define WIFIESP_DRV_TX_BUFFER_SIZE
Definition: wifiesp.h:66
wifiesp_cfg_t::tx_pin
pin_name_t tx_pin
Definition: wifiesp.h:137
WIFIESP_ERROR_UNKNOWN
@ WIFIESP_ERROR_UNKNOWN
Definition: wifiesp.h:162
wifiesp_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: wifiesp.h:148
WIFIESP_OK
@ WIFIESP_OK
Definition: wifiesp.h:158
wifiesp_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: wifiesp.h:147
WIFIESP_ERROR_TIMEOUT
@ WIFIESP_ERROR_TIMEOUT
Definition: wifiesp.h:160
wifiesp_cfg_t::rst
pin_name_t rst
Definition: wifiesp.h:140
wifiesp_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: wifiesp.h:146
wifiesp_cfg_t::rx_pin
pin_name_t rx_pin
Definition: wifiesp.h:136
wifiesp_default_cfg
void wifiesp_default_cfg(wifiesp_t *ctx)
Click Default Configuration function.
wifiesp_generic_read
int32_t wifiesp_generic_read(wifiesp_t *ctx, char *data_buf, int32_t max_len)
Generic read function.
wifiesp_t::rst
digital_out_t rst
Definition: wifiesp.h:119
wifiesp_cfg_t::baud_rate
uint32_t baud_rate
Definition: wifiesp.h:144
wifiesp_t::cs
digital_out_t cs
Definition: wifiesp.h:120
wifiesp_cfg_t::uart_blocking
bool uart_blocking
Definition: wifiesp.h:145
wifiesp_cfg_t
Click configuration structure definition.
Definition: wifiesp.h:134
wifiesp_send_cmd
void wifiesp_send_cmd(wifiesp_t *ctx, uint8_t *cmd, uint8_t *args)
Sends AT command to the module.
wifiesp_generic_write
void wifiesp_generic_write(wifiesp_t *ctx, char *data_buf, uint16_t len)
Generic write function.
wifiesp_cfg_t::cs
pin_name_t cs
Definition: wifiesp.h:141