wifi11  2.0.0.0
wifi11.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 WIFI11_H
36 #define WIFI11_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define WIFI11_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_INT ); \
57  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
58 
64 #define WIFI11_RETVAL uint8_t
65 
66 #define WIFI11_OK 0x00
67 #define WIFI11_INIT_ERROR 0xFF
68 
74 #define WIFI11_CMD_AT "AT" // Test AT command ready
75 #define WIFI11_CMD_ATS "ATS?" // List all AT command
76 #define WIFI11_CMD_ATSR "ATSR" // Restart module
77 #define WIFI11_CMD_ATSV "ATSV" // Query version info
78 #define WIFI11_CMD_ATSP "ATSP" // Set power saving mode
79 #define WIFI11_CMD_ATSE "ATSE" // Set AT command echo mode
80 #define WIFI11_CMD_ATSY "ATSY" // Factory Reset
81 #define WIFI11_CMD_ATSU "ATSU" // UART configuration
82 #define WIFI11_CMD_ATSW "ATSW" // Start Webserver
83 #define WIFI11_CMD_ATSO "ATSO" // OTA upgrade
84 #define WIFI11_CMD_ATSC "ATSC" // Choose Activated Image
85 #define WIFI11_CMD_ATSG "ATSG" // GPIO control
86 
92 #define WIFI11_CMD_ATPW "ATPW" // Set WiFi mode
93 #define WIFI11_CMD_ATPN "ATPN" // Connect to AP (STA mode)
94 #define WIFI11_CMD_ATWD "ATWD" // Disconnect from AP
95 #define WIFI11_CMD_ATWS "ATWS" // Scan AP
96 #define WIFI11_CMD_ATPA "ATPA" // Set AP mode
97 #define WIFI11_CMD_ATW "ATW?" // Wifi information
98 #define WIFI11_CMD_ATPH "ATPH" // Set DHCP mode
99 #define WIFI11_CMD_ATPE "ATPE" // Set static IP for STA
100 #define WIFI11_CMD_ATPF "ATPF" // Set static IP for AP, and DHCP rule
101 #define WIFI11_CMD_ATPG "ATPG" // Set Auto connect
102 #define WIFI11_CMD_ATPM "ATPM" // Set MAC address
103 #define WIFI11_CMD_ATWQ "ATWQ" // Start simple config
104 
110 #define WIFI11_CMD_ATP0 "ATP0" // Get LWIP errno
111 #define WIFI11_CMD_ATPS "ATPS" // Create TCP/UDP Server
112 #define WIFI11_CMD_ATPC "ATPC" // Create TCP/UDP Client
113 #define WIFI11_CMD_ATPD "ATPD" // Close TCP or UDP connection
114 #define WIFI11_CMD_ATPT "ATPT" // Send data
115 #define WIFI11_CMD_ATPR "ATPR" // Receive data
116 #define WIFI11_CMD_ATPK "ATPK" // Set auto receive data mode
117 #define WIFI11_CMD_ATPI "ATPI" // Check network connection status
118 #define WIFI11_CMD_ATPP "ATPP" // PING Command
119 #define WIFI11_CMD_ATPU "ATPU" // Set transparent transmission mode
120 #define WIFI11_CMD_ATPL "ATPL" // Save translink and enable autolink
121 
127 #define WIFI11_TCP_MODE 0
128 #define WIFI11_UDP_MODE 1
129 
135 #define DRV_RX_BUFFER_SIZE 500
136 #define DRV_TX_BUFFER_SIZE 500
137  // End group macro
140 // --------------------------------------------------------------- PUBLIC TYPES
148 typedef struct
149 {
150  // Output pins
151 
152  digital_out_t en;
153  digital_out_t cs;
154  digital_out_t gp1;
155 
156  // Modules
157 
158  uart_t uart;
159 
160  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
161  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
162 
163 } wifi11_t;
164 
168 typedef struct
169 {
170  // Communication gpio pins
171 
172  pin_name_t rx_pin;
173  pin_name_t tx_pin;
174 
175  // Additional gpio pins
176 
177  pin_name_t en;
178  pin_name_t cs;
179  pin_name_t gp1;
180 
181  // static variable
182 
183  uint32_t baud_rate; // Clock speed.
185  uart_data_bits_t data_bit; // Data bits.
186  uart_parity_t parity_bit; // Parity bit.
187  uart_stop_bits_t stop_bit; // Stop bits.
188 
189 } wifi11_cfg_t;
190  // End types group
192 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
193 
199 #ifdef __cplusplus
200 extern "C"{
201 #endif
202 
212 
222 
231 void wifi11_generic_write ( wifi11_t *ctx, char *data_buf, uint16_t len );
232 
243 int32_t wifi11_generic_read ( wifi11_t *ctx, char *data_buf, uint16_t max_len );
244 
254 
264 void wifi11_send_cmd ( wifi11_t *ctx, char *cmd );
265 
276 void wifi11_send_cmd_with_parameter ( wifi11_t *ctx, char *at_cmd_buf, char *param_buf );
277 
288 void wifi11_connect_to_ap ( wifi11_t *ctx, char *ssid, char *password );
289 
300 void wifi11_create_tcp_udp_server ( wifi11_t *ctx, uint8_t mode, uint16_t port );
301 
302 #ifdef __cplusplus
303 }
304 #endif
305 #endif // _WIFI11_H_
306  // End public_function group
309 
310 // ------------------------------------------------------------------------- END
wifi11_cfg_t::tx_pin
pin_name_t tx_pin
Definition: wifi11.h:173
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: wifi11.h:135
wifi11_generic_write
void wifi11_generic_write(wifi11_t *ctx, char *data_buf, uint16_t len)
Generic write function.
wifi11_send_cmd
void wifi11_send_cmd(wifi11_t *ctx, char *cmd)
Send command function.
wifi11_cfg_t::en
pin_name_t en
Definition: wifi11.h:177
wifi11_cfg_t::baud_rate
uint32_t baud_rate
Definition: wifi11.h:183
wifi11_init
WIFI11_RETVAL wifi11_init(wifi11_t *ctx, wifi11_cfg_t *cfg)
Initialization function.
wifi11_cfg_t
Click configuration structure definition.
Definition: wifi11.h:169
wifi11_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: wifi11.h:187
wifi11_t::cs
digital_out_t cs
Definition: wifi11.h:153
wifi11_connect_to_ap
void wifi11_connect_to_ap(wifi11_t *ctx, char *ssid, char *password)
Connect to AP function.
wifi11_t::en
digital_out_t en
Definition: wifi11.h:152
wifi11_cfg_setup
void wifi11_cfg_setup(wifi11_cfg_t *cfg)
Config Object Initialization function.
wifi11_cfg_t::cs
pin_name_t cs
Definition: wifi11.h:178
WIFI11_RETVAL
#define WIFI11_RETVAL
Definition: wifi11.h:64
wifi11_reset_device
void wifi11_reset_device(wifi11_t *ctx)
Device reset function.
wifi11_cfg_t::gp1
pin_name_t gp1
Definition: wifi11.h:179
wifi11_t
Click ctx object definition.
Definition: wifi11.h:149
wifi11_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: wifi11.h:185
wifi11_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: wifi11.h:186
wifi11_t::uart
uart_t uart
Definition: wifi11.h:158
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: wifi11.h:136
wifi11_create_tcp_udp_server
void wifi11_create_tcp_udp_server(wifi11_t *ctx, uint8_t mode, uint16_t port)
Create TCP/UDP server function.
wifi11_cfg_t::uart_blocking
bool uart_blocking
Definition: wifi11.h:184
wifi11_cfg_t::rx_pin
pin_name_t rx_pin
Definition: wifi11.h:172
wifi11_generic_read
int32_t wifi11_generic_read(wifi11_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
wifi11_send_cmd_with_parameter
void wifi11_send_cmd_with_parameter(wifi11_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
wifi11_t::gp1
digital_out_t gp1
Definition: wifi11.h:154