Skip to content

Commit 0987ac6

Browse files
committed
Main files of the driver to STM32
1 parent c95e7a2 commit 0987ac6

File tree

3 files changed

+1113
-0
lines changed

3 files changed

+1113
-0
lines changed

Inc/ESP8266.h

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#ifndef _ESP8266_H
2+
#define _ESP8266_H
3+
4+
#include "ESP8266Config.h"
5+
#include <stdlib.h>
6+
#include <stdio.h>
7+
#include <string.h>
8+
#include <stdarg.h>
9+
#include "stm32f4xx_hal.h"
10+
#include "dwt_stm32_delay.h"
11+
12+
13+
typedef enum{false = 0, true = 1}bool;
14+
15+
UART_HandleTypeDef _WIFI_USART;
16+
17+
//###################################################################################################
18+
typedef enum
19+
{
20+
WifiMode_Error = 0,
21+
WifiMode_Station = 1,
22+
WifiMode_SoftAp = 2,
23+
WifiMode_StationAndSoftAp = 3,
24+
}WifiMode_t;
25+
26+
typedef enum
27+
{
28+
WifiEncryptionType_Open = 0,
29+
WifiEncryptionType_WPA_PSK = 2,
30+
WifiEncryptionType_WPA2_PSK = 3,
31+
WifiEncryptionType_WPA_WPA2_PSK = 4,
32+
}WifiEncryptionType_t;
33+
typedef enum
34+
{
35+
WifiConnectionStatus_Error = 0,
36+
WifiConnectionStatus_GotIp = 2,
37+
WifiConnectionStatus_Connected = 3,
38+
WifiConnectionStatus_Disconnected = 4,
39+
WifiConnectionStatus_ConnectionFail = 5,
40+
}WifiConnectionStatus_t;
41+
42+
typedef struct
43+
{
44+
WifiConnectionStatus_t status;
45+
uint8_t LinkId;
46+
char Type[4];
47+
char RemoteIp[17];
48+
uint16_t RemotePort;
49+
uint16_t LocalPort;
50+
bool RunAsServer;
51+
}WifiConnection_t;
52+
//###################################################################################################
53+
typedef struct
54+
{
55+
//----------------Usart Paremeter
56+
uint8_t usartBuff;
57+
uint8_t RxBuffer[_WIFI_RX_SIZE];
58+
uint8_t TxBuffer[_WIFI_TX_SIZE];
59+
uint16_t RxIndex;
60+
bool RxIsData;
61+
//----------------General Parameter
62+
WifiMode_t Mode;
63+
char MyIP[16];
64+
char MyGateWay[16];
65+
//----------------Station Parameter
66+
char SSID_Connected[20];
67+
bool StationDhcp;
68+
char StationIp[16];
69+
//----------------SoftAp Parameter
70+
bool SoftApDhcp;
71+
char SoftApConnectedDevicesIp[6][16];
72+
char SoftApConnectedDevicesMac[6][18];
73+
//----------------TcpIp Parameter
74+
bool TcpIpMultiConnection;
75+
uint16_t TcpIpPingAnswer;
76+
WifiConnection_t TcpIpConnections[5];
77+
//----------------
78+
}Wifi_t;
79+
//###################################################################################################
80+
Wifi_t Wifi;
81+
//###################################################################################################
82+
void Wifi_RxClear(void);
83+
bool Wifi_SendString(char *data);
84+
bool Wifi_WaitForString(uint32_t TimeOut_ms,uint8_t *result,uint8_t CountOfParameter,...);
85+
void Wifi_RxCallBack(void);
86+
//###################################################################################################
87+
// Basic functions of ESP8266
88+
bool Wifi_Init(void);
89+
void Wifi_Enable(void);
90+
void Wifi_Disable(void);
91+
bool Wifi_Restart(void);
92+
bool Wifi_DeepSleep(uint16_t DelayMs);
93+
bool Wifi_FactoryReset(void);
94+
bool Wifi_Update(void);
95+
bool Wifi_SetRfPower(uint8_t Power_0_to_82);
96+
//###################################################################################################
97+
// Mode of the ESP8266: Station or SoftAP or both
98+
bool Wifi_SetMode(WifiMode_t WifiMode_);
99+
bool Wifi_GetMode(void);
100+
bool Wifi_GetMyIp(void);
101+
//###################################################################################################
102+
bool Wifi_Station_ConnectToAp(char *SSID,char *Pass,char *MAC);
103+
bool Wifi_Station_Disconnect(void);
104+
bool Wifi_Station_DhcpEnable(bool Enable);
105+
bool Wifi_Station_DhcpIsEnable(void);
106+
bool Wifi_Station_SetIp(char *IP,char *GateWay,char *NetMask);
107+
//###################################################################################################
108+
bool Wifi_SoftAp_Create(char *SSID,char *password,uint8_t channel,
109+
WifiEncryptionType_t WifiEncryptionType,uint8_t MaxConnections_1_to_4,
110+
bool HiddenSSID);
111+
bool Wifi_GetApConnection(void);
112+
bool Wifi_SoftAp_GetConnectedDevices(void);
113+
//###################################################################################################
114+
bool Wifi_TcpIp_GetConnectionStatus(void);
115+
bool Wifi_TcpIp_Ping(char *PingTo);
116+
bool Wifi_TcpIp_SetMultiConnection(bool EnableMultiConnections);
117+
bool Wifi_TcpIp_GetMultiConnection(void);
118+
bool Wifi_TcpIp_StartTcpConnection(uint8_t LinkId,char *RemoteIp,uint16_t RemotePort,
119+
uint16_t TimeOut_S);
120+
bool Wifi_TcpIp_StartUdpConnection(uint8_t LinkId,char *RemoteIp,uint16_t RemotePort,
121+
uint16_t LocalPort);
122+
bool Wifi_TcpIp_Close(uint8_t LinkId);
123+
bool Wifi_TcpIp_SetEnableTcpServer(uint16_t PortNumber);
124+
bool Wifi_TcpIp_SetDisableTcpServer(uint16_t PortNumber);
125+
bool Wifi_TcpIp_SendDataUdp(uint8_t LinkId,uint16_t dataLen,uint8_t *data);
126+
bool Wifi_TcpIp_SendDataTcp(uint8_t LinkId,uint16_t dataLen,uint8_t *data);
127+
128+
#endif
129+

Inc/ESP8266Config.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef _WIFICONFIG_H
2+
#define _WIFICONFIG_H
3+
4+
/*
5+
* You have to change the settings according to your settings for the project
6+
* the times of execution and the other things are necessary to work correctly
7+
* without a problem
8+
*/
9+
#define _WIFI_USART huart1
10+
#define _WIFI_RX_SIZE 512
11+
#define _WIFI_RX_FOR_DATA_SIZE 1024
12+
#define _WIFI_TX_SIZE 256
13+
#define _WIFI_TASK_SIZE 512
14+
#define _MAX_SEND_BYTES 2048
15+
// Buttons of the ESP8266 Module
16+
#define _BANK_WIFI_BUTTONS GPIOB
17+
#define _BUTTON_RST GPIO_PIN_11
18+
#define _BUTTON_ENABLE GPIO_PIN_6
19+
// The times are defined in ms
20+
#define _WIFI_WAIT_TIME_LOW 1000
21+
#define _WIFI_WAIT_TIME_MED 5000
22+
#define _WIFI_WAIT_TIME_HIGH 15000
23+
#define _WIFI_WAIT_TIME_VERYHIGH 25000
24+
25+
#endif

0 commit comments

Comments
 (0)