lpwifi 2.0.0.0
lpwifi.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef LPWIFI_H
29#define LPWIFI_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_uart.h"
52
73#define LPWIFI_CMD_AT "AT"
74#define LPWIFI_CMD_ATZ "ATZ"
75#define LPWIFI_CMD_ATE "ATE"
76#define LPWIFI_CMD_ATF "ATF"
77
82#define LPWIFI_CMD_WFMODE "AT+WFMODE"
83#define LPWIFI_CMD_WFJAPA "AT+WFJAPA"
84
89#define LPWIFI_CMD_TRTS "AT+TRTS"
90#define LPWIFI_CMD_TRUSE "AT+TRUSE"
91
96#define LPWIFI_CMD_PWMINIT "AT+PWMINIT"
97#define LPWIFI_CMD_PWMSTART "AT+PWMSTART"
98#define LPWIFI_CMD_PWMSTOP "AT+PWMSTOP"
99
104#define LPWIFI_CMD_I2CINIT "AT+I2CINIT"
105#define LPWIFI_CMD_I2CREAD "AT+I2CREAD"
106#define LPWIFI_CMD_I2CWRITE "AT+I2CWRITE"
107
108 // lpwifi_reg
109
124#define LPWIFI_MODE_STA 0
125#define LPWIFI_MODE_SOFT_AP 1
126
132#define DRV_BUFFER_SIZE 400
133
134 // lpwifi_set
135
150#define LPWIFI_MAP_MIKROBUS( cfg, mikrobus ) \
151 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
152 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
153 cfg.wkp = MIKROBUS( mikrobus, MIKROBUS_RST ); \
154 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
155 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
156
157 // lpwifi_map
158 // lpwifi
159
164typedef struct
165{
166 // Output pins
167
168 digital_out_t wkp;
169 digital_out_t cs;
171 // Input pins
172
173 digital_in_t int_pin;
175 // Modules
176
177 uart_t uart;
179 // Buffers
180
181 char uart_rx_buffer[ DRV_BUFFER_SIZE ];
182 char uart_tx_buffer[ DRV_BUFFER_SIZE ];
184} lpwifi_t;
185
190typedef struct
191{
192 // Communication gpio pins
193
194 pin_name_t rx_pin;
195 pin_name_t tx_pin;
197 // Additional gpio pins
198
199 pin_name_t wkp;
200 pin_name_t int_pin;
201 pin_name_t cs;
203 // Static variable
204
205 uint32_t baud_rate;
207 uart_data_bits_t data_bit;
208 uart_parity_t parity_bit;
209 uart_stop_bits_t stop_bit;
212
217typedef enum
218{
220 LPWIFI_ERROR = -1
221
223
240
255err_t lpwifi_init ( lpwifi_t *ctx, lpwifi_cfg_t *cfg );
256
268
282err_t lpwifi_generic_write ( lpwifi_t *ctx, char *data_buf, uint16_t len );
283
297err_t lpwifi_generic_read ( lpwifi_t *ctx, char *data_buf, uint16_t max_len );
298
308
318void lpwifi_send_cmd ( lpwifi_t *ctx, char *cmd );
319
330void lpwifi_send_cmd_with_parameter ( lpwifi_t *ctx, char *at_cmd_buf, char *param_buf );
331
341void lpwifi_send_cmd_check ( lpwifi_t *ctx, char *at_cmd_buf );
342
353void lpwifi_connect_to_ap ( lpwifi_t *ctx, char *ssid, char *password );
354
364void lpwifi_set_wifi_mode ( lpwifi_t *ctx, uint8_t mode );
365
375void lpwifi_create_tcp_server ( lpwifi_t *ctx, uint16_t port );
376
386void lpwifi_create_udp_socket ( lpwifi_t *ctx, uint16_t port );
387
388#ifdef __cplusplus
389}
390#endif
391#endif // LPWIFI_H
392
393 // lpwifi
394
395// ------------------------------------------------------------------------ END
#define DRV_BUFFER_SIZE
LP WiFi driver buffer size.
Definition lpwifi.h:132
err_t lpwifi_generic_write(lpwifi_t *ctx, char *data_buf, uint16_t len)
LP WiFi data writing function.
void lpwifi_send_cmd(lpwifi_t *ctx, char *cmd)
Send command function.
void lpwifi_set_wifi_mode(lpwifi_t *ctx, uint8_t mode)
Set WiFi mode function.
void lpwifi_factory_reset_device(lpwifi_t *ctx)
Device factory reset function.
void lpwifi_create_udp_socket(lpwifi_t *ctx, uint16_t port)
Create UDP socket function.
void lpwifi_cfg_setup(lpwifi_cfg_t *cfg)
LP WiFi configuration object setup function.
err_t lpwifi_generic_read(lpwifi_t *ctx, char *data_buf, uint16_t max_len)
LP WiFi data reading function.
void lpwifi_send_cmd_with_parameter(lpwifi_t *ctx, char *at_cmd_buf, char *param_buf)
Send command function with parameter.
void lpwifi_create_tcp_server(lpwifi_t *ctx, uint16_t port)
Create TCP server function.
void lpwifi_send_cmd_check(lpwifi_t *ctx, char *at_cmd_buf)
Send command to check commands current value.
void lpwifi_default_cfg(lpwifi_t *ctx)
LP WiFi default configuration function.
err_t lpwifi_init(lpwifi_t *ctx, lpwifi_cfg_t *cfg)
LP WiFi initialization function.
void lpwifi_connect_to_ap(lpwifi_t *ctx, char *ssid, char *password)
Connect to AP function.
lpwifi_return_value_t
LP WiFi Click return value data.
Definition lpwifi.h:218
@ LPWIFI_OK
Definition lpwifi.h:219
@ LPWIFI_ERROR
Definition lpwifi.h:220
LP WiFi Click configuration object.
Definition lpwifi.h:191
uint32_t baud_rate
Definition lpwifi.h:205
pin_name_t wkp
Definition lpwifi.h:199
bool uart_blocking
Definition lpwifi.h:206
uart_data_bits_t data_bit
Definition lpwifi.h:207
pin_name_t tx_pin
Definition lpwifi.h:195
pin_name_t rx_pin
Definition lpwifi.h:194
uart_stop_bits_t stop_bit
Definition lpwifi.h:209
pin_name_t int_pin
Definition lpwifi.h:200
uart_parity_t parity_bit
Definition lpwifi.h:208
pin_name_t cs
Definition lpwifi.h:201
LP WiFi Click context object.
Definition lpwifi.h:165
digital_out_t cs
Definition lpwifi.h:169
uart_t uart
Definition lpwifi.h:177
digital_in_t int_pin
Definition lpwifi.h:173
digital_out_t wkp
Definition lpwifi.h:168