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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define WIFI9_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
56  cfg.adr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
57  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
58  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
59  cfg.mcr = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
60  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
61 
67 #define WIFI9_OK 0
68 #define WIFI9_ERROR -1
69 #define WIFI9_ERROR_TIMEOUT -2
70 
76 #define WIFI9_MODULE_POWER_ON 1
77 #define WIFI9_MODULE_POWER_OFF 0
78 
84 #define WIFI9_SELECT_CMD_UART 0
85 #define WIFI9_SELECT_BIN_UART 1
86 
92 #define WIFI9_CMD_GET_SYSTEM_FIRMWARE "get system firmware"
93 #define WIFI9_CMD_GET_SYSTEM_MAC_ADDR "get system macaddr"
94 #define WIFI9_CMD_GET_SYSTEM_SERIAL_NUM "get system serialnum"
95 #define WIFI9_CMD_GET_SYSTEM_RADIO_VER "get system radio_ver"
96 #define WIFI9_CMD_GET_SYSTEM_BOOTL_VER "get system bootl_ver"
97 #define WIFI9_CMD_GET_SYSTEM_HW_REV "get system hwrev"
98 #define WIFI9_CMD_GET_WLAN_STATE "get wlan state"
99 #define WIFI9_CMD_GET_WLAN_STATE_STA "get wlan state sta"
100 #define WIFI9_CMD_SET_WLAN_STATE "set wlan state"
101 #define WIFI9_CMD_SET_WLAN_STATE_STA_ON "set wlan state sta on"
102 #define WIFI9_CMD_SET_WLAN_CFG "set wlan cfg"
103 #define WIFI9_CMD_SET_WLAN_CFG_STA "set wlan cfg sta"
104 #define WIFI9_CMD_SET_NETCAT_STATE "set netcat state"
105 #define WIFI9_CMD_SET_NETCAT_STATE_OFF "set netcat state off"
106 #define WIFI9_CMD_SET_NETCAT_STATE_ON "set netcat state on"
107 #define WIFI9_CMD_SET_NETCAT_CFG "set netcat cfg"
108 #define WIFI9_CMD_SET_NETCAT_CFG_SERVER "set netcat cfg server"
109 #define WIFI9_CMD_SET_NETCAT_AUTH "set netcat auth"
110 #define WIFI9_CMD_SET_NETCAT_AUTH_OFF "set netcat auth off"
111 #define WIFI9_CMD_GET_NET_CFG "get net cfg"
112 #define WIFI9_CMD_GET_NET_CFG_STA "get net cfg sta"
113 
119 #define WIFI9_DRV_TX_BUFFER_SIZE 300
120 #define WIFI9_DRV_RX_BUFFER_SIZE 500
121  // End group macro
124 // --------------------------------------------------------------- PUBLIC TYPES
132 typedef struct
133 {
134  // Output pins
135  digital_out_t adr;
136  digital_out_t rst;
137  digital_out_t rts;
138 
139  // Input pins
140  digital_in_t mcr;
141  digital_in_t cts;
142 
143  // Modules
144  uart_t uart;
145 
146  uint8_t uart_rx_buffer[ WIFI9_DRV_RX_BUFFER_SIZE ];
147  uint8_t uart_tx_buffer[ WIFI9_DRV_TX_BUFFER_SIZE ];
148 
149 } wifi9_t;
150 
154 typedef struct
155 {
156  // Communication gpio pins
157  pin_name_t rx_pin;
158  pin_name_t tx_pin;
159 
160  // Additional gpio pins
161  pin_name_t adr;
162  pin_name_t rst;
163  pin_name_t rts;
164  pin_name_t mcr;
165  pin_name_t cts;
166 
167  // static variable
168  uint32_t baud_rate; // Clock speed.
170  uart_data_bits_t data_bit; // Data bits.
171  uart_parity_t parity_bit; // Parity bit.
172  uart_stop_bits_t stop_bit; // Stop bits.
173 
174 } wifi9_cfg_t;
175  // End types group
177 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
178 
184 #ifdef __cplusplus
185 extern "C"{
186 #endif
187 
197 
205 err_t wifi9_init ( wifi9_t *ctx, wifi9_cfg_t *cfg );
206 
212 
218 void wifi9_set_rst_pin ( wifi9_t *ctx, uint8_t state );
219 
225 void wifi9_set_rts_pin ( wifi9_t *ctx, uint8_t state );
226 
232 void wifi9_select_uart ( wifi9_t *ctx, uint8_t uart_select );
233 
239 uint8_t wifi9_get_mcr_pin ( wifi9_t *ctx );
240 
246 uint8_t wifi9_get_cts_pin ( wifi9_t *ctx );
247 
254 void wifi9_generic_write ( wifi9_t *ctx, uint8_t *data_buf, uint16_t len );
255 
263 int32_t wifi9_generic_read ( wifi9_t *ctx, uint8_t *data_buf, uint16_t max_len );
264 
271 void wifi9_send_command ( wifi9_t *ctx, uint8_t *command );
272 
273 #ifdef __cplusplus
274 }
275 #endif
276 #endif // _WIFI9_H_
277  // End public_function group
280 
281 // ------------------------------------------------------------------------- END
WIFI9_DRV_TX_BUFFER_SIZE
#define WIFI9_DRV_TX_BUFFER_SIZE
Definition: wifi9.h:119
wifi9_t::mcr
digital_in_t mcr
Definition: wifi9.h:140
wifi9_t
Click ctx object definition.
Definition: wifi9.h:133
wifi9_get_mcr_pin
uint8_t wifi9_get_mcr_pin(wifi9_t *ctx)
Get MCR pin state.
wifi9_cfg_t::rts
pin_name_t rts
Definition: wifi9.h:163
wifi9_cfg_t
Click configuration structure definition.
Definition: wifi9.h:155
wifi9_set_rts_pin
void wifi9_set_rts_pin(wifi9_t *ctx, uint8_t state)
Set RTS pin state.
wifi9_reset_device
void wifi9_reset_device(wifi9_t *ctx)
Module reset.
wifi9_set_rst_pin
void wifi9_set_rst_pin(wifi9_t *ctx, uint8_t state)
Set RST pin state.
wifi9_send_command
void wifi9_send_command(wifi9_t *ctx, uint8_t *command)
Send Command function.
wifi9_init
err_t wifi9_init(wifi9_t *ctx, wifi9_cfg_t *cfg)
Initialization function.
wifi9_get_cts_pin
uint8_t wifi9_get_cts_pin(wifi9_t *ctx)
Get CTS pin state.
wifi9_cfg_t::rst
pin_name_t rst
Definition: wifi9.h:162
wifi9_t::uart
uart_t uart
Definition: wifi9.h:144
wifi9_cfg_t::uart_blocking
bool uart_blocking
Definition: wifi9.h:169
wifi9_cfg_setup
void wifi9_cfg_setup(wifi9_cfg_t *cfg)
Config Object Initialization function.
wifi9_t::cts
digital_in_t cts
Definition: wifi9.h:141
wifi9_generic_read
int32_t wifi9_generic_read(wifi9_t *ctx, uint8_t *data_buf, uint16_t max_len)
Generic read function.
wifi9_cfg_t::rx_pin
pin_name_t rx_pin
Definition: wifi9.h:157
wifi9_select_uart
void wifi9_select_uart(wifi9_t *ctx, uint8_t uart_select)
Switch to a command or binary uart.
wifi9_cfg_t::adr
pin_name_t adr
Definition: wifi9.h:161
wifi9_cfg_t::tx_pin
pin_name_t tx_pin
Definition: wifi9.h:158
wifi9_t::rts
digital_out_t rts
Definition: wifi9.h:137
wifi9_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: wifi9.h:170
wifi9_cfg_t::mcr
pin_name_t mcr
Definition: wifi9.h:164
wifi9_cfg_t::cts
pin_name_t cts
Definition: wifi9.h:165
wifi9_generic_write
void wifi9_generic_write(wifi9_t *ctx, uint8_t *data_buf, uint16_t len)
Generic write function.
WIFI9_DRV_RX_BUFFER_SIZE
#define WIFI9_DRV_RX_BUFFER_SIZE
Definition: wifi9.h:120
wifi9_cfg_t::baud_rate
uint32_t baud_rate
Definition: wifi9.h:168
wifi9_t::rst
digital_out_t rst
Definition: wifi9.h:136
wifi9_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: wifi9.h:172
wifi9_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: wifi9.h:171
wifi9_t::adr
digital_out_t adr
Definition: wifi9.h:135