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 "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 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define WIFI9_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
65  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
66  cfg.adr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
67  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
68  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.mcr = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
70  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
71 
77 #define WIFI9_OK 0
78 #define WIFI9_ERROR -1
79 #define WIFI9_ERROR_TIMEOUT -2
80 
86 #define WIFI9_MODULE_POWER_ON 1
87 #define WIFI9_MODULE_POWER_OFF 0
88 
94 #define WIFI9_SELECT_CMD_UART 0
95 #define WIFI9_SELECT_BIN_UART 1
96 
102 #define WIFI9_CMD_GET_SYSTEM_FIRMWARE "get system firmware"
103 #define WIFI9_CMD_GET_SYSTEM_MAC_ADDR "get system macaddr"
104 #define WIFI9_CMD_GET_SYSTEM_SERIAL_NUM "get system serialnum"
105 #define WIFI9_CMD_GET_SYSTEM_RADIO_VER "get system radio_ver"
106 #define WIFI9_CMD_GET_SYSTEM_BOOTL_VER "get system bootl_ver"
107 #define WIFI9_CMD_GET_SYSTEM_HW_REV "get system hwrev"
108 #define WIFI9_CMD_GET_WLAN_STATE "get wlan state"
109 #define WIFI9_CMD_GET_WLAN_STATE_STA "get wlan state sta"
110 #define WIFI9_CMD_SET_WLAN_STATE "set wlan state"
111 #define WIFI9_CMD_SET_WLAN_STATE_STA_ON "set wlan state sta on"
112 #define WIFI9_CMD_SET_WLAN_CFG "set wlan cfg"
113 #define WIFI9_CMD_SET_WLAN_CFG_STA "set wlan cfg sta"
114 #define WIFI9_CMD_SET_NETCAT_STATE "set netcat state"
115 #define WIFI9_CMD_SET_NETCAT_STATE_OFF "set netcat state off"
116 #define WIFI9_CMD_SET_NETCAT_STATE_ON "set netcat state on"
117 #define WIFI9_CMD_SET_NETCAT_CFG "set netcat cfg"
118 #define WIFI9_CMD_SET_NETCAT_CFG_SERVER "set netcat cfg server"
119 #define WIFI9_CMD_SET_NETCAT_AUTH "set netcat auth"
120 #define WIFI9_CMD_SET_NETCAT_AUTH_OFF "set netcat auth off"
121 #define WIFI9_CMD_GET_NET_CFG "get net cfg"
122 #define WIFI9_CMD_GET_NET_CFG_STA "get net cfg sta"
123 
129 #define WIFI9_DRV_TX_BUFFER_SIZE 300
130 #define WIFI9_DRV_RX_BUFFER_SIZE 500
131  // End group macro
134 // --------------------------------------------------------------- PUBLIC TYPES
142 typedef struct
143 {
144  // Output pins
145  digital_out_t adr;
146  digital_out_t rst;
147  digital_out_t rts;
148 
149  // Input pins
150  digital_in_t mcr;
151  digital_in_t cts;
152 
153  // Modules
154  uart_t uart;
155 
156  uint8_t uart_rx_buffer[ WIFI9_DRV_RX_BUFFER_SIZE ];
157  uint8_t uart_tx_buffer[ WIFI9_DRV_TX_BUFFER_SIZE ];
158 
159 } wifi9_t;
160 
164 typedef struct
165 {
166  // Communication gpio pins
167  pin_name_t rx_pin;
168  pin_name_t tx_pin;
169 
170  // Additional gpio pins
171  pin_name_t adr;
172  pin_name_t rst;
173  pin_name_t rts;
174  pin_name_t mcr;
175  pin_name_t cts;
176 
177  // static variable
178  uint32_t baud_rate; // Clock speed.
180  uart_data_bits_t data_bit; // Data bits.
181  uart_parity_t parity_bit; // Parity bit.
182  uart_stop_bits_t stop_bit; // Stop bits.
183 
184 } wifi9_cfg_t;
185  // End types group
187 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
188 
194 #ifdef __cplusplus
195 extern "C"{
196 #endif
197 
207 
215 err_t wifi9_init ( wifi9_t *ctx, wifi9_cfg_t *cfg );
216 
222 
228 void wifi9_set_rst_pin ( wifi9_t *ctx, uint8_t state );
229 
235 void wifi9_set_rts_pin ( wifi9_t *ctx, uint8_t state );
236 
242 void wifi9_select_uart ( wifi9_t *ctx, uint8_t uart_select );
243 
249 uint8_t wifi9_get_mcr_pin ( wifi9_t *ctx );
250 
256 uint8_t wifi9_get_cts_pin ( wifi9_t *ctx );
257 
264 void wifi9_generic_write ( wifi9_t *ctx, uint8_t *data_buf, uint16_t len );
265 
273 int32_t wifi9_generic_read ( wifi9_t *ctx, uint8_t *data_buf, uint16_t max_len );
274 
281 void wifi9_send_command ( wifi9_t *ctx, uint8_t *command );
282 
283 #ifdef __cplusplus
284 }
285 #endif
286 #endif // _WIFI9_H_
287  // End public_function group
290 
291 // ------------------------------------------------------------------------- END
WIFI9_DRV_TX_BUFFER_SIZE
#define WIFI9_DRV_TX_BUFFER_SIZE
Definition: wifi9.h:129
wifi9_t::mcr
digital_in_t mcr
Definition: wifi9.h:150
wifi9_t
Click ctx object definition.
Definition: wifi9.h:143
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:173
wifi9_cfg_t
Click configuration structure definition.
Definition: wifi9.h:165
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:172
wifi9_t::uart
uart_t uart
Definition: wifi9.h:154
wifi9_cfg_t::uart_blocking
bool uart_blocking
Definition: wifi9.h:179
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:151
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:167
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:171
wifi9_cfg_t::tx_pin
pin_name_t tx_pin
Definition: wifi9.h:168
wifi9_t::rts
digital_out_t rts
Definition: wifi9.h:147
wifi9_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: wifi9.h:180
wifi9_cfg_t::mcr
pin_name_t mcr
Definition: wifi9.h:174
wifi9_cfg_t::cts
pin_name_t cts
Definition: wifi9.h:175
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:130
wifi9_cfg_t::baud_rate
uint32_t baud_rate
Definition: wifi9.h:178
wifi9_t::rst
digital_out_t rst
Definition: wifi9.h:146
wifi9_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: wifi9.h:182
wifi9_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: wifi9.h:181
wifi9_t::adr
digital_out_t adr
Definition: wifi9.h:145