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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_uart.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define WIFI11_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
64  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
65  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_INT ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
68 
74 #define WIFI11_RETVAL uint8_t
75 
76 #define WIFI11_OK 0x00
77 #define WIFI11_INIT_ERROR 0xFF
78 
84 #define WIFI11_CMD_AT "AT" // Test AT command ready
85 #define WIFI11_CMD_ATS "ATS?" // List all AT command
86 #define WIFI11_CMD_ATSR "ATSR" // Restart module
87 #define WIFI11_CMD_ATSV "ATSV" // Query version info
88 #define WIFI11_CMD_ATSP "ATSP" // Set power saving mode
89 #define WIFI11_CMD_ATSE "ATSE" // Set AT command echo mode
90 #define WIFI11_CMD_ATSY "ATSY" // Factory Reset
91 #define WIFI11_CMD_ATSU "ATSU" // UART configuration
92 #define WIFI11_CMD_ATSW "ATSW" // Start Webserver
93 #define WIFI11_CMD_ATSO "ATSO" // OTA upgrade
94 #define WIFI11_CMD_ATSC "ATSC" // Choose Activated Image
95 #define WIFI11_CMD_ATSG "ATSG" // GPIO control
96 
102 #define WIFI11_CMD_ATPW "ATPW" // Set WiFi mode
103 #define WIFI11_CMD_ATPN "ATPN" // Connect to AP (STA mode)
104 #define WIFI11_CMD_ATWD "ATWD" // Disconnect from AP
105 #define WIFI11_CMD_ATWS "ATWS" // Scan AP
106 #define WIFI11_CMD_ATPA "ATPA" // Set AP mode
107 #define WIFI11_CMD_ATW "ATW?" // Wifi information
108 #define WIFI11_CMD_ATPH "ATPH" // Set DHCP mode
109 #define WIFI11_CMD_ATPE "ATPE" // Set static IP for STA
110 #define WIFI11_CMD_ATPF "ATPF" // Set static IP for AP, and DHCP rule
111 #define WIFI11_CMD_ATPG "ATPG" // Set Auto connect
112 #define WIFI11_CMD_ATPM "ATPM" // Set MAC address
113 #define WIFI11_CMD_ATWQ "ATWQ" // Start simple config
114 
120 #define WIFI11_CMD_ATP0 "ATP0" // Get LWIP errno
121 #define WIFI11_CMD_ATPS "ATPS" // Create TCP/UDP Server
122 #define WIFI11_CMD_ATPC "ATPC" // Create TCP/UDP Client
123 #define WIFI11_CMD_ATPD "ATPD" // Close TCP or UDP connection
124 #define WIFI11_CMD_ATPT "ATPT" // Send data
125 #define WIFI11_CMD_ATPR "ATPR" // Receive data
126 #define WIFI11_CMD_ATPK "ATPK" // Set auto receive data mode
127 #define WIFI11_CMD_ATPI "ATPI" // Check network connection status
128 #define WIFI11_CMD_ATPP "ATPP" // PING Command
129 #define WIFI11_CMD_ATPU "ATPU" // Set transparent transmission mode
130 #define WIFI11_CMD_ATPL "ATPL" // Save translink and enable autolink
131 
137 #define WIFI11_TCP_MODE 0
138 #define WIFI11_UDP_MODE 1
139 
145 #define DRV_RX_BUFFER_SIZE 500
146 #define DRV_TX_BUFFER_SIZE 500
147  // End group macro
150 // --------------------------------------------------------------- PUBLIC TYPES
158 typedef struct
159 {
160  // Output pins
161 
162  digital_out_t en;
163  digital_out_t cs;
164  digital_out_t gp1;
165 
166  // Modules
167 
168  uart_t uart;
169 
170  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
171  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
172 
173 } wifi11_t;
174 
178 typedef struct
179 {
180  // Communication gpio pins
181 
182  pin_name_t rx_pin;
183  pin_name_t tx_pin;
184 
185  // Additional gpio pins
186 
187  pin_name_t en;
188  pin_name_t cs;
189  pin_name_t gp1;
190 
191  // static variable
192 
193  uint32_t baud_rate; // Clock speed.
195  uart_data_bits_t data_bit; // Data bits.
196  uart_parity_t parity_bit; // Parity bit.
197  uart_stop_bits_t stop_bit; // Stop bits.
198 
199 } wifi11_cfg_t;
200  // End types group
202 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
203 
209 #ifdef __cplusplus
210 extern "C"{
211 #endif
212 
222 
232 
241 void wifi11_generic_write ( wifi11_t *ctx, char *data_buf, uint16_t len );
242 
253 int32_t wifi11_generic_read ( wifi11_t *ctx, char *data_buf, uint16_t max_len );
254 
264 
274 void wifi11_send_cmd ( wifi11_t *ctx, char *cmd );
275 
286 void wifi11_send_cmd_with_parameter ( wifi11_t *ctx, char *at_cmd_buf, char *param_buf );
287 
298 void wifi11_connect_to_ap ( wifi11_t *ctx, char *ssid, char *password );
299 
310 void wifi11_create_tcp_udp_server ( wifi11_t *ctx, uint8_t mode, uint16_t port );
311 
312 #ifdef __cplusplus
313 }
314 #endif
315 #endif // _WIFI11_H_
316  // End public_function group
319 
320 // ------------------------------------------------------------------------- END
wifi11_cfg_t::tx_pin
pin_name_t tx_pin
Definition: wifi11.h:183
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: wifi11.h:145
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:187
wifi11_cfg_t::baud_rate
uint32_t baud_rate
Definition: wifi11.h:193
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:179
wifi11_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: wifi11.h:197
wifi11_t::cs
digital_out_t cs
Definition: wifi11.h:163
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:162
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:188
WIFI11_RETVAL
#define WIFI11_RETVAL
Definition: wifi11.h:74
wifi11_reset_device
void wifi11_reset_device(wifi11_t *ctx)
Device reset function.
wifi11_cfg_t::gp1
pin_name_t gp1
Definition: wifi11.h:189
wifi11_t
Click ctx object definition.
Definition: wifi11.h:159
wifi11_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: wifi11.h:195
wifi11_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: wifi11.h:196
wifi11_t::uart
uart_t uart
Definition: wifi11.h:168
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: wifi11.h:146
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:194
wifi11_cfg_t::rx_pin
pin_name_t rx_pin
Definition: wifi11.h:182
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:164