This repository was archived by the owner on Feb 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathWebServer_ESP32_SC_W5500.hpp
210 lines (148 loc) · 5.73 KB
/
WebServer_ESP32_SC_W5500.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/****************************************************************************************************************************
WebServer_ESP32_SC_W5500.h
For Ethernet shields using ESP32_SC_W5500 (ESP32_S2/S3/C3 + LwIP W5500)
WebServer_ESP32_SC_W5500 is a library for the ESP32_S2/S3/C3 with LwIP Ethernet W5500
Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases
Built by Khoi Hoang https://github.com/khoih-prog/WebServer_ESP32_SC_W5500
Licensed under GPLv3 license
Version: 1.2.1
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 13/12/2022 Initial coding for ESP32_S3_W5500 (ESP32_S3 + W5500)
1.0.1 K Hoang 14/12/2022 Using SPI_DMA_CH_AUTO instead of manually selected
1.1.0 K Hoang 19/12/2022 Add support to ESP32_S2_W5500 (ESP32_S2 + W5500)
1.2.0 K Hoang 20/12/2022 Add support to ESP32_C3_W5500 (ESP32_C3 + W5500)
1.2.1 K Hoang 22/12/2022 Remove unused variable to avoid compiler warning and error
*****************************************************************************************************************************/
#pragma once
#ifndef WEBSERVER_ESP32_SC_W5500_HPP
#define WEBSERVER_ESP32_SC_W5500_HPP
/////////////////////////////////////////////////////////////
#if ( ARDUINO_ESP32S2_DEV || ARDUINO_FEATHERS2 || ARDUINO_ESP32S2_THING_PLUS || ARDUINO_MICROS2 || \
ARDUINO_METRO_ESP32S2 || ARDUINO_MAGTAG29_ESP32S2 || ARDUINO_FUNHOUSE_ESP32S2 || \
ARDUINO_ADAFRUIT_FEATHER_ESP32S2_NOPSRAM )
#if (_ETHERNET_WEBSERVER_LOGLEVEL_ > 3)
#warning Using ESP32_S2. To follow library instructions to install esp32-s2 core and WebServer Patch
#warning You have to select HUGE APP or 1.9-2.0 MB APP to be able to run Config Portal. Must use PSRAM
#endif
#define USING_ESP32_S2 true
#ifndef SHIELD_TYPE
#define SHIELD_TYPE "ESP32_S2_W5500"
#endif
#elif ( ARDUINO_ESP32C3_DEV )
#if (_ETHERNET_WEBSERVER_LOGLEVEL_ > 3)
#if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 2) )
#warning Using ESP32_C3 using core v2.0.0+. Either LittleFS, SPIFFS or EEPROM OK.
#else
#warning Using ESP32_C3 using core v1.0.6-. To follow library instructions to install esp32-c3 core. Only SPIFFS and EEPROM OK.
#endif
#warning You have to select Flash size 2MB and Minimal APP (1.3MB + 700KB) for some boards
#endif
#define USING_ESP32_C3 true
#ifndef SHIELD_TYPE
#define SHIELD_TYPE "ESP32_C3_W5500"
#endif
//#error ESP32_C3 not supported yet
#elif ( defined(ARDUINO_ESP32S3_DEV) || defined(ARDUINO_ESP32_S3_BOX) || defined(ARDUINO_TINYS3) || \
defined(ARDUINO_PROS3) || defined(ARDUINO_FEATHERS3) )
#if (_ETHERNET_WEBSERVER_LOGLEVEL_ > 3)
#warning Using ESP32_S3. To install esp32-s3-support branch if using core v2.0.2-
#endif
#define USING_ESP32_S3 true
#ifndef SHIELD_TYPE
#define SHIELD_TYPE "ESP32_S3_W5500"
#endif
#else
#error This code is intended to run on the ESP32_S2/3, ESP32_C3 platform! Please check your Tools->Board setting.
#endif
#define BOARD_NAME ARDUINO_BOARD
//////////////////////////////////////////////////////////////
//#define CONFIG_ETH_SPI_ETHERNET_W5500 true
//////////////////////////////////////////////////////////////
#include <WiFi.h>
#include <WebServer.h> // Introduce corresponding libraries
#include <hal/spi_types.h>
//////////////////////////////////////////////////////////////
#if USING_ESP32_S3
#if !defined(ETH_SPI_HOST)
// Using SPI2 for ESP32_SC, but name is SPI3_HOST
#define ETH_SPI_HOST SPI3_HOST
#endif
#if !defined(SPI_CLOCK_MHZ)
// Using 25MHz for W5500, 14MHz for W5100
#define SPI_CLOCK_MHZ 25
#endif
#if !defined(INT_GPIO)
#define INT_GPIO 4
#endif
#if !defined(MISO_GPIO)
#define MISO_GPIO 13
#endif
#if !defined(MOSI_GPIO)
#define MOSI_GPIO 11
#endif
#if !defined(SCK_GPIO)
#define SCK_GPIO 12
#endif
#if !defined(CS_GPIO)
#define CS_GPIO 10
#endif
//////////////////////////////////////////////////////////////
#elif USING_ESP32_S2
#if !defined(ETH_SPI_HOST)
// Using SPI1 for ESP32_SC, but name is SPI2_HOST
#define ETH_SPI_HOST SPI3_HOST
#endif
#if !defined(SPI_CLOCK_MHZ)
// Using 25MHz for W5500, 14MHz for W5100
#define SPI_CLOCK_MHZ 25
#endif
#if !defined(INT_GPIO)
#define INT_GPIO 4
#endif
#if !defined(MISO_GPIO)
#define MISO_GPIO 37
#endif
#if !defined(MOSI_GPIO)
#define MOSI_GPIO 35
#endif
#if !defined(SCK_GPIO)
#define SCK_GPIO 36
#endif
#if !defined(CS_GPIO)
#define CS_GPIO 34
#endif
//////////////////////////////////////////////////////////////
#elif USING_ESP32_C3
#if !defined(ETH_SPI_HOST)
// Using SPI2 for ESP32_SC, but name is SPI3_HOST
#define ETH_SPI_HOST SPI2_HOST
#endif
#if !defined(SPI_CLOCK_MHZ)
// Using 25MHz for W5500, 14MHz for W5100
#define SPI_CLOCK_MHZ 25
#endif
#if !defined(INT_GPIO)
#define INT_GPIO 10
#endif
#if !defined(MISO_GPIO)
#define MISO_GPIO 5
#endif
#if !defined(MOSI_GPIO)
#define MOSI_GPIO 6
#endif
#if !defined(SCK_GPIO)
#define SCK_GPIO 4
#endif
#if !defined(CS_GPIO)
#define CS_GPIO 7
#endif
#endif
//////////////////////////////////////////////////////////////
extern bool ESP32_W5500_eth_connected;
extern void ESP32_W5500_onEvent();
extern void ESP32_W5500_waitForConnect();
extern bool ESP32_W5500_isConnected();
extern void ESP32_W5500_event(WiFiEvent_t event);
//////////////////////////////////////////////////////////////
#endif // WEBSERVER_ESP32_SC_W5500_HPP