Skip to content

Commit 22139df

Browse files
authored
Enable interrupt-mode for lwIP_ESPHost (#2036)
1 parent 9c94bab commit 22139df

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

libraries/lwIP_ESPHost/src/ESPHost.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
*/
2020

2121
#include "ESPHost.h"
22-
#include "CEspControl.h"
22+
#include <CEspControl.h>
23+
#include <LwipEthernet.h>
2324

2425
ESPHost::ESPHost(int8_t cs, arduino::SPIClass &spi, int8_t intrpin) {
2526
(void) cs;
@@ -42,8 +43,10 @@ void ESPHost::end() {
4243
}
4344

4445
uint16_t ESPHost::sendFrame(const uint8_t *data, uint16_t datalen) {
46+
ethernet_arch_lwip_gpio_mask();
4547
int res = CEspControl::getInstance().sendBuffer(apMode ? ESP_AP_IF : ESP_STA_IF, 0, (uint8_t*) data, datalen);
4648
CEspControl::getInstance().communicateWithEsp();
49+
ethernet_arch_lwip_gpio_unmask();
4750
return (res == ESP_CONTROL_OK) ? datalen : 0;
4851
}
4952

libraries/lwIP_ESPHost/src/ESPHost.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ESPHost {
4444
}
4545

4646
bool interruptIsPossible() {
47-
return false;
47+
return true;
4848
}
4949

5050
PinStatus interruptMode() {

libraries/lwIP_ESPHost/src/lwIP_ESPHost.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,18 @@
2323

2424
#define MAX_SOFTAP_CONNECTION_DEF 5
2525

26+
#if defined(SPIWIFI_ACK) // Arduino Nano RP2040 Connect
27+
#define ESPHOST_DATA_READY SPIWIFI_ACK
28+
#endif
29+
2630
bool ESPHostLwIP::wifiHwInitialized = false;
2731
ESPHostLwIP* ESPHostLwIP::instance = nullptr;
2832

33+
ESPHostLwIP::ESPHostLwIP() :
34+
LwipIntfDev<ESPHost>(SS, SPI, ESPHOST_DATA_READY) {
35+
36+
}
37+
2938
void ESPHostLwIP::setSTA() {
3039
apMode = false;
3140
}
@@ -122,7 +131,7 @@ bool ESPHostLwIP::begin() {
122131
if (!initHW()) {
123132
return false;
124133
}
125-
ethernet_arch_lwip_begin();
134+
ethernet_arch_lwip_gpio_mask();
126135
if (!apMode) {
127136
CEspControl::getInstance().setWifiMode(WIFI_MODE_STA);
128137
if (CEspControl::getInstance().connectAccessPoint(ap) != ESP_CONTROL_OK) {
@@ -148,18 +157,18 @@ bool ESPHostLwIP::begin() {
148157
}
149158
CEspControl::getInstance().getSoftAccessPointConfig(softAP);
150159
}
151-
ethernet_arch_lwip_end();
160+
ethernet_arch_lwip_gpio_unmask();
152161
uint8_t mac[6];
153162
if (!LwipIntfDev<ESPHost>::begin(macAddress(apMode, mac))) {
154-
ethernet_arch_lwip_begin();
163+
ethernet_arch_lwip_gpio_mask();
155164
if (apMode) {
156165
CEspControl::getInstance().stopSoftAccessPoint();
157166
wifiStatus = WL_AP_FAILED;
158167
} else {
159168
CEspControl::getInstance().disconnectAccessPoint();
160169
wifiStatus = WL_CONNECT_FAILED;
161170
}
162-
ethernet_arch_lwip_end();
171+
ethernet_arch_lwip_gpio_unmask();
163172
return false;
164173
}
165174
if (apMode) {
@@ -206,11 +215,11 @@ uint8_t* ESPHostLwIP::macAddress(bool apMode, uint8_t *mac) {
206215
}
207216
WifiMac_t MAC;
208217
MAC.mode = apMode ? WIFI_MODE_AP : WIFI_MODE_STA;
209-
ethernet_arch_lwip_begin();
218+
ethernet_arch_lwip_gpio_mask();
210219
if (CEspControl::getInstance().getWifiMacAddress(MAC) == ESP_CONTROL_OK) {
211220
CNetUtilities::macStr2macArray(mac, MAC.mac);
212221
}
213-
ethernet_arch_lwip_end();
222+
ethernet_arch_lwip_gpio_unmask();
214223
return mac;
215224
}
216225

@@ -227,9 +236,9 @@ int32_t ESPHostLwIP::RSSI() {
227236
if (!joined) {
228237
return 0;
229238
}
230-
ethernet_arch_lwip_begin();
239+
ethernet_arch_lwip_gpio_mask();
231240
CEspControl::getInstance().getAccessPointConfig(ap);
232-
ethernet_arch_lwip_end();
241+
ethernet_arch_lwip_gpio_unmask();
233242
return ap.rssi;
234243
}
235244

@@ -264,9 +273,9 @@ int8_t ESPHostLwIP::scanNetworks(bool async) {
264273
if (!initHW()) {
265274
return -1;
266275
}
267-
ethernet_arch_lwip_begin();
276+
ethernet_arch_lwip_gpio_mask();
268277
int res = CEspControl::getInstance().getAccessPointScanList(accessPoints);
269-
ethernet_arch_lwip_end();
278+
ethernet_arch_lwip_gpio_unmask();
270279
wifiStatus = WL_SCAN_COMPLETED;
271280
if (res != ESP_CONTROL_OK) {
272281
return -1;
@@ -321,9 +330,9 @@ void ESPHostLwIP::lowPowerMode() {
321330
if (!initHW()) {
322331
return;
323332
}
324-
ethernet_arch_lwip_begin();
333+
ethernet_arch_lwip_gpio_mask();
325334
CEspControl::getInstance().setPowerSaveMode(1);
326-
ethernet_arch_lwip_end();
335+
ethernet_arch_lwip_gpio_unmask();
327336
}
328337

329338
void ESPHostLwIP::noLowPowerMode() {

libraries/lwIP_ESPHost/src/lwIP_ESPHost.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
class ESPHostLwIP : public LwipIntfDev<ESPHost> {
2828
public:
2929

30+
ESPHostLwIP();
31+
3032
void setSTA();
3133
void setAP();
3234

0 commit comments

Comments
 (0)