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_RETVAL uint8_t
66 
67 #define WIFIESP_OK 0x00
68 #define WIFIESP_INIT_ERROR 0xFF
69 
75 #define DRV_RX_BUFFER_SIZE 610
76 #define DRV_TX_BUFFER_SIZE 150
77 
83 #define WIFIESP_CHECK "AT"
84 #define WIFIESP_RST "AT+RST"
85 #define WIFIESP_CHECK_FIRMWARE "AT+GMR"
86 #define WIFIESP_SET_MODE "AT+CWMODE"
87 #define WIFIESP_CONNECT "AT+CWJAP"
88 #define WIFIESP_LIST_AP "AT+CWLAP"
89 #define WIFIESP_QUIT_AP "AT+CWQAP"
90 #define WIFIESP_SET_AP_PARAMETERS "AT+CWSAP"
91 #define WIFIESP_JOIN_DEV_IP "AT+CWLIF"
92 #define WIFIESP_CONNESTION_STATUS "AT+CIPSTATUS"
93 #define WIFIESP_START "AT+CIPSTART"
94 #define WIFIESP_MODE "AT+CIPMODE"
95 #define WIFIESP_SEND "AT+CIPSEND"
96 #define WIFIESP_CLOSE "AT+CIPCLOSE"
97 #define WIFIESP_GET_IP "AT+CIFSR"
98 #define WIFIESP_SET_MULTIPLE_CONNECTION "AT+CIPMUX"
99 #define WIFIESP_SET_AS_SERVER "AT+CIPSERVER"
100 #define WIFIESP_CHECK_SERVER_TIMEOUT "AT+CIPSTO?"
101 #define WIFIESP_RECEIVE "+IPD"
102  // End group macro
106 // --------------------------------------------------------------- PUBLIC TYPES
115 typedef struct
116 {
117  // Output pins
118 
119  digital_out_t rst;
120  digital_out_t cs;
121 
122  // Modules
123 
124  uart_t uart;
125 
126  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
127  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
128 
129 } wifiesp_t;
130 
134 typedef struct
135 {
136  // Communication gpio pins
137 
138  pin_name_t rx_pin;
139  pin_name_t tx_pin;
140 
141  // Additional gpio pins
142 
143  pin_name_t rst;
144  pin_name_t cs;
145 
146  // static variable
147 
148  uint32_t baud_rate; // Clock speed.
150  uart_data_bits_t data_bit; // Data bits.
151  uart_parity_t parity_bit; // Parity bit.
152  uart_stop_bits_t stop_bit; // Stop bits.
153 
154 } wifiesp_cfg_t;
155 
159 typedef uint8_t wifiesp_error_t;
160  // End types group
162 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
163 
169 #ifdef __cplusplus
170 extern "C"{
171 #endif
172 
181 void wifiesp_cfg_setup ( wifiesp_cfg_t *cfg );
182 
191 
199 void wifiesp_default_cfg ( wifiesp_t *ctx );
200 
207 void wifiesp_generic_write ( wifiesp_t *ctx, char *data_buf, uint16_t len );
208 
216 int32_t wifiesp_generic_read ( wifiesp_t *ctx, char *data_buf, int32_t max_len );
217 
226 void wifiesp_send_cmd( wifiesp_t* ctx, uint8_t* cmd, uint8_t* args );
227 
228 #ifdef __cplusplus
229 }
230 #endif
231 #endif // _WIFIESP_H_
232  // End public_function group
235 
236 // ------------------------------------------------------------------------- END
wifiesp_cfg_setup
void wifiesp_cfg_setup(wifiesp_cfg_t *cfg)
Config Object Initialization function.
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: wifiesp.h:75
wifiesp_init
WIFIESP_RETVAL wifiesp_init(wifiesp_t *ctx, wifiesp_cfg_t *cfg)
Initialization function.
wifiesp_t
Click ctx object definition.
Definition: wifiesp.h:115
wifiesp_t::uart
uart_t uart
Definition: wifiesp.h:124
wifiesp_cfg_t::tx_pin
pin_name_t tx_pin
Definition: wifiesp.h:139
wifiesp_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: wifiesp.h:152
wifiesp_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: wifiesp.h:151
wifiesp_cfg_t::rst
pin_name_t rst
Definition: wifiesp.h:143
wifiesp_error_t
uint8_t wifiesp_error_t
Error type.
Definition: wifiesp.h:159
wifiesp_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: wifiesp.h:150
wifiesp_cfg_t::rx_pin
pin_name_t rx_pin
Definition: wifiesp.h:138
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:148
wifiesp_t::cs
digital_out_t cs
Definition: wifiesp.h:120
wifiesp_cfg_t::uart_blocking
bool uart_blocking
Definition: wifiesp.h:149
wifiesp_cfg_t
Click configuration structure definition.
Definition: wifiesp.h:134
WIFIESP_RETVAL
#define WIFIESP_RETVAL
Definition: wifiesp.h:65
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: wifiesp.h:76
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:144