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_RETVAL uint8_t
68 
69 #define WIFI9_OK 0x00
70 #define WIFI9_INIT_ERROR 0xFF
71 
77 #define WIFI9_MODULE_POWER_ON 1
78 #define WIFI9_MODULE_POWER_OFF 0
79 
85 #define WIFI9_SELECT_CMD_UART 0x00
86 #define WIFI9_SELECT_BIN_UART 0x01
87 
93 #define WIFI9_CMD_GET_SYSTEM_FIRMWARE "get system firmware"
94 #define WIFI9_CMD_GET_SYSTEM_MAC_ADDR "get system macaddr"
95 #define WIFI9_CMD_GET_SYSTEM_SERIAL_NUM "get system serialnum"
96 #define WIFI9_CMD_GET_SYSTEM_RADIO_VER "get system radio_ver"
97 #define WIFI9_CMD_GET_SYSTEM_BOOTL_VER "get system bootl_ver"
98 #define WIFI9_CMD_GET_SYSTEM_HW_REV "get system hwrev"
99 
100 #define WIFI9_CMD_GET_WLAN_STATE_STA "get wlan state sta"
101 #define WIFI9_CMD_SET_WLAN_STATE_STA_ON "set wlan state sta on"
102 #define WIFI9_CMD_SET_NETCAT_STATE_OFF "set netcat state off"
103 #define WIFI9_CMD_SET_NETCAT_STATE_ON "set netcat state on"
104 #define WIFI9_CMD_SET_NETCAT_CFG_SERVER "set netcat cfg server 1234"
105 #define WIFI9_CMD_SET_NETCAT_AUTH_OFF "set netcat auth off"
106 #define WIFI9_CMD_GET_NET_CFG_STA "get net cfg sta"
107 
108 #define WIFI9_CMD_SET_WLAN_CFG_STA "set wlan cfg sta net_username net_password 4"
109 
115 #define DRV_RX_BUFFER_SIZE 500
116  // End group macro
119 // --------------------------------------------------------------- PUBLIC TYPES
127 typedef struct
128 {
129  // Output pins
130 
131  digital_out_t adr;
132  digital_out_t rst;
133  digital_out_t rts;
134 
135  // Input pins
136 
137  digital_in_t mcr;
138  digital_in_t cts;
139 
140  // Modules
141 
142  uart_t uart;
143 
144  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
145  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
146 
147 } wifi9_t;
148 
152 typedef struct
153 {
154  // Communication gpio pins
155 
156  pin_name_t rx_pin;
157  pin_name_t tx_pin;
158 
159  // Additional gpio pins
160 
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 
169  uint32_t baud_rate; // Clock speed.
171  uart_data_bits_t data_bit; // Data bits.
172  uart_parity_t parity_bit; // Parity bit.
173  uart_stop_bits_t stop_bit; // Stop bits.
174 
175 } wifi9_cfg_t;
176 
180 // Actuator switch type
181 typedef uint8_t wifi9_actuator_sw_t;
182 
183 // Actuator counter type
184 typedef int16_t wifi9_actuator_cnt_t;
185 
186 // Actuator string type
187 typedef char wifi9_actuator_str_t;
188 
189 // Parser error type
190 typedef uint8_t wifi9_error_t;
191  // End types group
193 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
194 
200 #ifdef __cplusplus
201 extern "C"{
202 #endif
203 
212 void wifi9_cfg_setup ( wifi9_cfg_t *cfg );
213 
222 
227 void wifi9_module_power ( wifi9_t *ctx );
228 
235 void wifi9_generic_write ( wifi9_t *ctx, char *data_buf, uint16_t len );
236 
244 int32_t wifi9_generic_read ( wifi9_t *ctx, char *data_buf, uint16_t max_len );
245 
252 void wifi9_send_command ( wifi9_t *ctx, char *command );
253 
259 void wifi9_select_uart ( wifi9_t *ctx, uint8_t uart_select );
260 
261 #ifdef __cplusplus
262 }
263 #endif
264 #endif // _WIFI9_H_
265  // End public_function group
268 
269 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: wifi9.h:115
wifi9_t::mcr
digital_in_t mcr
Definition: wifi9.h:137
wifi9_t
Click ctx object definition.
Definition: wifi9.h:127
wifi9_cfg_t::rts
pin_name_t rts
Definition: wifi9.h:163
wifi9_cfg_t
Click configuration structure definition.
Definition: wifi9.h:152
wifi9_generic_read
int32_t wifi9_generic_read(wifi9_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
wifi9_init
WIFI9_RETVAL wifi9_init(wifi9_t *ctx, wifi9_cfg_t *cfg)
Initialization function.
wifi9_actuator_sw_t
uint8_t wifi9_actuator_sw_t
Error type.
Definition: wifi9.h:181
wifi9_cfg_t::rst
pin_name_t rst
Definition: wifi9.h:162
wifi9_t::uart
uart_t uart
Definition: wifi9.h:142
wifi9_cfg_t::uart_blocking
bool uart_blocking
Definition: wifi9.h:170
wifi9_actuator_cnt_t
int16_t wifi9_actuator_cnt_t
Definition: wifi9.h:184
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:138
wifi9_cfg_t::rx_pin
pin_name_t rx_pin
Definition: wifi9.h:156
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_RETVAL
#define WIFI9_RETVAL
Definition: wifi9.h:67
wifi9_module_power
void wifi9_module_power(wifi9_t *ctx)
Module power up.
wifi9_error_t
uint8_t wifi9_error_t
Definition: wifi9.h:190
wifi9_cfg_t::tx_pin
pin_name_t tx_pin
Definition: wifi9.h:157
wifi9_t::rts
digital_out_t rts
Definition: wifi9.h:133
wifi9_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: wifi9.h:171
wifi9_cfg_t::mcr
pin_name_t mcr
Definition: wifi9.h:164
wifi9_send_command
void wifi9_send_command(wifi9_t *ctx, char *command)
Send Command function.
wifi9_cfg_t::cts
pin_name_t cts
Definition: wifi9.h:165
wifi9_cfg_t::baud_rate
uint32_t baud_rate
Definition: wifi9.h:169
wifi9_t::rst
digital_out_t rst
Definition: wifi9.h:132
wifi9_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: wifi9.h:173
wifi9_generic_write
void wifi9_generic_write(wifi9_t *ctx, char *data_buf, uint16_t len)
Generic write function.
wifi9_actuator_str_t
char wifi9_actuator_str_t
Definition: wifi9.h:187
wifi9_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: wifi9.h:172
wifi9_t::adr
digital_out_t adr
Definition: wifi9.h:131