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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_uart.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define WIFI11_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70  cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_INT ); \
71  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
72 
78 #define WIFI11_RETVAL uint8_t
79 
80 #define WIFI11_OK 0x00
81 #define WIFI11_INIT_ERROR 0xFF
82 
88 #define WIFI11_CMD_AT "AT" // Test AT command ready
89 #define WIFI11_CMD_ATS "ATS?" // List all AT command
90 #define WIFI11_CMD_ATSR "ATSR" // Restart module
91 #define WIFI11_CMD_ATSV "ATSV" // Query version info
92 #define WIFI11_CMD_ATSP "ATSP" // Set power saving mode
93 #define WIFI11_CMD_ATSE "ATSE" // Set AT command echo mode
94 #define WIFI11_CMD_ATSY "ATSY" // Factory Reset
95 #define WIFI11_CMD_ATSU "ATSU" // UART configuration
96 #define WIFI11_CMD_ATSW "ATSW" // Start Webserver
97 #define WIFI11_CMD_ATSO "ATSO" // OTA upgrade
98 #define WIFI11_CMD_ATSC "ATSC" // Choose Activated Image
99 #define WIFI11_CMD_ATSG "ATSG" // GPIO control
100 
106 #define WIFI11_CMD_ATPW "ATPW" // Set WiFi mode
107 #define WIFI11_CMD_ATPN "ATPN" // Connect to AP (STA mode)
108 #define WIFI11_CMD_ATWD "ATWD" // Disconnect from AP
109 #define WIFI11_CMD_ATWS "ATWS" // Scan AP
110 #define WIFI11_CMD_ATPA "ATPA" // Set AP mode
111 #define WIFI11_CMD_ATW "ATW?" // Wifi information
112 #define WIFI11_CMD_ATPH "ATPH" // Set DHCP mode
113 #define WIFI11_CMD_ATPE "ATPE" // Set static IP for STA
114 #define WIFI11_CMD_ATPF "ATPF" // Set static IP for AP, and DHCP rule
115 #define WIFI11_CMD_ATPG "ATPG" // Set Auto connect
116 #define WIFI11_CMD_ATPM "ATPM" // Set MAC address
117 #define WIFI11_CMD_ATWQ "ATWQ" // Start simple config
118 
124 #define WIFI11_CMD_ATP0 "ATP0" // Get LWIP errno
125 #define WIFI11_CMD_ATPS "ATPS" // Create TCP/UDP Server
126 #define WIFI11_CMD_ATPC "ATPC" // Create TCP/UDP Client
127 #define WIFI11_CMD_ATPD "ATPD" // Close TCP or UDP connection
128 #define WIFI11_CMD_ATPT "ATPT" // Send data
129 #define WIFI11_CMD_ATPR "ATPR" // Receive data
130 #define WIFI11_CMD_ATPK "ATPK" // Set auto receive data mode
131 #define WIFI11_CMD_ATPI "ATPI" // Check network connection status
132 #define WIFI11_CMD_ATPP "ATPP" // PING Command
133 #define WIFI11_CMD_ATPU "ATPU" // Set transparent transmission mode
134 #define WIFI11_CMD_ATPL "ATPL" // Save translink and enable autolink
135 
141 #define WIFI11_TCP_MODE 0
142 #define WIFI11_UDP_MODE 1
143 
149 #define DRV_RX_BUFFER_SIZE 500
150 #define DRV_TX_BUFFER_SIZE 500
151  // End group macro
154 // --------------------------------------------------------------- PUBLIC TYPES
162 typedef struct
163 {
164  // Output pins
165 
166  digital_out_t en;
167  digital_out_t cs;
168  digital_out_t gp1;
169 
170  // Modules
171 
172  uart_t uart;
173 
174  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
175  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
176 
177 } wifi11_t;
178 
182 typedef struct
183 {
184  // Communication gpio pins
185 
186  pin_name_t rx_pin;
187  pin_name_t tx_pin;
188 
189  // Additional gpio pins
190 
191  pin_name_t en;
192  pin_name_t cs;
193  pin_name_t gp1;
194 
195  // static variable
196 
197  uint32_t baud_rate; // Clock speed.
199  uart_data_bits_t data_bit; // Data bits.
200  uart_parity_t parity_bit; // Parity bit.
201  uart_stop_bits_t stop_bit; // Stop bits.
202 
203 } wifi11_cfg_t;
204  // End types group
206 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
207 
213 #ifdef __cplusplus
214 extern "C"{
215 #endif
216 
226 
236 
245 void wifi11_generic_write ( wifi11_t *ctx, char *data_buf, uint16_t len );
246 
257 int32_t wifi11_generic_read ( wifi11_t *ctx, char *data_buf, uint16_t max_len );
258 
268 
278 void wifi11_send_cmd ( wifi11_t *ctx, char *cmd );
279 
290 void wifi11_send_cmd_with_parameter ( wifi11_t *ctx, char *at_cmd_buf, char *param_buf );
291 
302 void wifi11_connect_to_ap ( wifi11_t *ctx, char *ssid, char *password );
303 
314 void wifi11_create_tcp_udp_server ( wifi11_t *ctx, uint8_t mode, uint16_t port );
315 
316 #ifdef __cplusplus
317 }
318 #endif
319 #endif // _WIFI11_H_
320  // End public_function group
323 
324 // ------------------------------------------------------------------------- END
wifi11_cfg_t::tx_pin
pin_name_t tx_pin
Definition: wifi11.h:187
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: wifi11.h:149
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:191
wifi11_cfg_t::baud_rate
uint32_t baud_rate
Definition: wifi11.h:197
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:183
wifi11_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: wifi11.h:201
wifi11_t::cs
digital_out_t cs
Definition: wifi11.h:167
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:166
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:192
WIFI11_RETVAL
#define WIFI11_RETVAL
Definition: wifi11.h:78
wifi11_reset_device
void wifi11_reset_device(wifi11_t *ctx)
Device reset function.
wifi11_cfg_t::gp1
pin_name_t gp1
Definition: wifi11.h:193
wifi11_t
Click ctx object definition.
Definition: wifi11.h:163
wifi11_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: wifi11.h:199
wifi11_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: wifi11.h:200
wifi11_t::uart
uart_t uart
Definition: wifi11.h:172
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: wifi11.h:150
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:198
wifi11_cfg_t::rx_pin
pin_name_t rx_pin
Definition: wifi11.h:186
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:168