wifi9 2.0.0.0
wifi9.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 WIFI9_H
36#define WIFI9_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
57// -------------------------------------------------------------- PUBLIC MACROS
67#define WIFI9_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
70 cfg.adr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
71 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
72 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.mcr = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
74 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
81#define WIFI9_OK 0
82#define WIFI9_ERROR -1
83#define WIFI9_ERROR_TIMEOUT -2
90#define WIFI9_MODULE_POWER_ON 1
91#define WIFI9_MODULE_POWER_OFF 0
98#define WIFI9_SELECT_CMD_UART 0
99#define WIFI9_SELECT_BIN_UART 1
106#define WIFI9_CMD_GET_SYSTEM_FIRMWARE "get system firmware"
107#define WIFI9_CMD_GET_SYSTEM_MAC_ADDR "get system macaddr"
108#define WIFI9_CMD_GET_SYSTEM_SERIAL_NUM "get system serialnum"
109#define WIFI9_CMD_GET_SYSTEM_RADIO_VER "get system radio_ver"
110#define WIFI9_CMD_GET_SYSTEM_BOOTL_VER "get system bootl_ver"
111#define WIFI9_CMD_GET_SYSTEM_HW_REV "get system hwrev"
112#define WIFI9_CMD_GET_WLAN_STATE "get wlan state"
113#define WIFI9_CMD_GET_WLAN_STATE_STA "get wlan state sta"
114#define WIFI9_CMD_SET_WLAN_STATE "set wlan state"
115#define WIFI9_CMD_SET_WLAN_STATE_STA_ON "set wlan state sta on"
116#define WIFI9_CMD_SET_WLAN_CFG "set wlan cfg"
117#define WIFI9_CMD_SET_WLAN_CFG_STA "set wlan cfg sta"
118#define WIFI9_CMD_SET_NETCAT_STATE "set netcat state"
119#define WIFI9_CMD_SET_NETCAT_STATE_OFF "set netcat state off"
120#define WIFI9_CMD_SET_NETCAT_STATE_ON "set netcat state on"
121#define WIFI9_CMD_SET_NETCAT_CFG "set netcat cfg"
122#define WIFI9_CMD_SET_NETCAT_CFG_SERVER "set netcat cfg server"
123#define WIFI9_CMD_SET_NETCAT_AUTH "set netcat auth"
124#define WIFI9_CMD_SET_NETCAT_AUTH_OFF "set netcat auth off"
125#define WIFI9_CMD_GET_NET_CFG "get net cfg"
126#define WIFI9_CMD_GET_NET_CFG_STA "get net cfg sta"
133#define WIFI9_DRV_TX_BUFFER_SIZE 300
134#define WIFI9_DRV_RX_BUFFER_SIZE 500
137 // End group macro
138// --------------------------------------------------------------- PUBLIC TYPES
146typedef struct
147{
148 // Output pins
149 digital_out_t adr;
150 digital_out_t rst;
151 digital_out_t rts;
152
153 // Input pins
154 digital_in_t mcr;
155 digital_in_t cts;
156
157 // Modules
158 uart_t uart;
159
160 uint8_t uart_rx_buffer[ WIFI9_DRV_RX_BUFFER_SIZE ];
161 uint8_t uart_tx_buffer[ WIFI9_DRV_TX_BUFFER_SIZE ];
162
163} wifi9_t;
164
168typedef struct
169{
170 // Communication gpio pins
171 pin_name_t rx_pin;
172 pin_name_t tx_pin;
173
174 // Additional gpio pins
175 pin_name_t adr;
176 pin_name_t rst;
177 pin_name_t rts;
178 pin_name_t mcr;
179 pin_name_t cts;
180
181 // static variable
182 uint32_t baud_rate; // Clock speed.
184 uart_data_bits_t data_bit; // Data bits.
185 uart_parity_t parity_bit; // Parity bit.
186 uart_stop_bits_t stop_bit; // Stop bits.
187
189
190 // End types group
191// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
192
198#ifdef __cplusplus
199extern "C"{
200#endif
201
211
219err_t wifi9_init ( wifi9_t *ctx, wifi9_cfg_t *cfg );
220
226
232void wifi9_set_rst_pin ( wifi9_t *ctx, uint8_t state );
233
239void wifi9_set_rts_pin ( wifi9_t *ctx, uint8_t state );
240
246void wifi9_select_uart ( wifi9_t *ctx, uint8_t uart_select );
247
253uint8_t wifi9_get_mcr_pin ( wifi9_t *ctx );
254
260uint8_t wifi9_get_cts_pin ( wifi9_t *ctx );
261
268void wifi9_generic_write ( wifi9_t *ctx, uint8_t *data_buf, uint16_t len );
269
277int32_t wifi9_generic_read ( wifi9_t *ctx, uint8_t *data_buf, uint16_t max_len );
278
285void wifi9_send_command ( wifi9_t *ctx, uint8_t *command );
286
287#ifdef __cplusplus
288}
289#endif
290#endif // _WIFI9_H_
291
292 // End public_function group
294
295// ------------------------------------------------------------------------- END
#define WIFI9_DRV_TX_BUFFER_SIZE
Definition wifi9.h:133
#define WIFI9_DRV_RX_BUFFER_SIZE
Definition wifi9.h:134
uint8_t wifi9_get_mcr_pin(wifi9_t *ctx)
Get MCR pin state.
void wifi9_generic_write(wifi9_t *ctx, uint8_t *data_buf, uint16_t len)
Generic write function.
int32_t wifi9_generic_read(wifi9_t *ctx, uint8_t *data_buf, uint16_t max_len)
Generic read function.
void wifi9_send_command(wifi9_t *ctx, uint8_t *command)
Send Command function.
void wifi9_select_uart(wifi9_t *ctx, uint8_t uart_select)
Switch to a command or binary uart.
uint8_t wifi9_get_cts_pin(wifi9_t *ctx)
Get CTS pin state.
void wifi9_reset_device(wifi9_t *ctx)
Module reset.
void wifi9_set_rst_pin(wifi9_t *ctx, uint8_t state)
Set RST pin state.
void wifi9_set_rts_pin(wifi9_t *ctx, uint8_t state)
Set RTS pin state.
err_t wifi9_init(wifi9_t *ctx, wifi9_cfg_t *cfg)
Initialization function.
void wifi9_cfg_setup(wifi9_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition wifi9.h:169
pin_name_t rts
Definition wifi9.h:177
uint32_t baud_rate
Definition wifi9.h:182
pin_name_t mcr
Definition wifi9.h:178
pin_name_t adr
Definition wifi9.h:175
pin_name_t cts
Definition wifi9.h:179
bool uart_blocking
Definition wifi9.h:183
uart_data_bits_t data_bit
Definition wifi9.h:184
pin_name_t tx_pin
Definition wifi9.h:172
pin_name_t rx_pin
Definition wifi9.h:171
uart_stop_bits_t stop_bit
Definition wifi9.h:186
uart_parity_t parity_bit
Definition wifi9.h:185
pin_name_t rst
Definition wifi9.h:176
Click ctx object definition.
Definition wifi9.h:147
digital_in_t mcr
Definition wifi9.h:154
digital_out_t rts
Definition wifi9.h:151
digital_out_t adr
Definition wifi9.h:149
uart_t uart
Definition wifi9.h:158
digital_in_t cts
Definition wifi9.h:155
digital_out_t rst
Definition wifi9.h:150