Add legacy ESP32 compatibility fixes
This commit is contained in:
14
include/ArduinoEsp32Compat.h
Normal file
14
include/ArduinoEsp32Compat.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Arduino-ESP32 1.0.6 does not define these version macros, but some newer
|
||||||
|
// libraries use them to select legacy-compatible code paths.
|
||||||
|
#ifndef ESP_ARDUINO_VERSION
|
||||||
|
#define EGGDUINO_LEGACY_ARDUINO_ESP32 1
|
||||||
|
#define ESP_ARDUINO_VERSION 0
|
||||||
|
#else
|
||||||
|
#define EGGDUINO_LEGACY_ARDUINO_ESP32 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef ESP_ARDUINO_VERSION_VAL
|
||||||
|
#define ESP_ARDUINO_VERSION_VAL(major, minor, patch) (((major) * 10000) + ((minor) * 100) + (patch))
|
||||||
|
#endif
|
||||||
@@ -29,7 +29,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Button(byte p, ActionCb a): debounce(0), state(1), lastState(1), action(a), pin(p) {
|
Button(byte p, ActionCb a): debounce(0), state(1), lastState(1), pin(p), action(a) {
|
||||||
pinMode(pin, INPUT_PULLUP);
|
pinMode(pin, INPUT_PULLUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,4 +56,3 @@ public:
|
|||||||
}; //button
|
}; //button
|
||||||
|
|
||||||
#endif //__BUTTON_H__
|
#endif //__BUTTON_H__
|
||||||
|
|
||||||
|
|||||||
@@ -12,28 +12,57 @@
|
|||||||
platform = platformio/espressif32
|
platform = platformio/espressif32
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
extra_scripts = pre:scripts/patch_legacy_esp32_libs.py
|
||||||
|
build_flags =
|
||||||
|
-include $PROJECT_INCLUDE_DIR/ArduinoEsp32Compat.h
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
upload_speed = 576000
|
upload_speed = 576000
|
||||||
upload_port = /dev/ttyUSB*
|
upload_port = /dev/ttyUSB*
|
||||||
|
; FastAccelStepper 0.33+ requires newer ESP-IDF headers than the
|
||||||
|
; espressif32 3.4.0 / Arduino 1.0.6 toolchain provides.
|
||||||
lib_deps =
|
lib_deps =
|
||||||
arminjo/ServoEasing
|
arminjo/ServoEasing
|
||||||
madhephaestus/ESP32Servo@^3.0.6
|
madhephaestus/ESP32Servo@^3.0.6
|
||||||
bblanchon/ArduinoJson@^6.21.5
|
bblanchon/ArduinoJson@^6.21.5
|
||||||
gin66/FastAccelStepper@^0.33.13
|
gin66/FastAccelStepper@0.30.15
|
||||||
h2zero/NimBLE-Arduino@^2.3.6
|
h2zero/NimBLE-Arduino@2.2.3
|
||||||
links2004/WebSockets@^2.6.1
|
links2004/WebSockets@2.6.1
|
||||||
|
|
||||||
|
[env:uno_windows]
|
||||||
|
platform = platformio/espressif32
|
||||||
|
board = esp32dev
|
||||||
|
framework = arduino
|
||||||
|
extra_scripts = pre:scripts/patch_legacy_esp32_libs.py
|
||||||
|
build_flags =
|
||||||
|
-include $PROJECT_INCLUDE_DIR/ArduinoEsp32Compat.h
|
||||||
|
monitor_speed = 115200
|
||||||
|
monitor_port = COM*
|
||||||
|
#upload_speed = 576000
|
||||||
|
upload_port = COM8
|
||||||
|
; Keep this aligned with [env:uno] for Arduino-ESP32 1.0.6 compatibility.
|
||||||
|
lib_deps =
|
||||||
|
arminjo/ServoEasing
|
||||||
|
madhephaestus/ESP32Servo@^3.0.6
|
||||||
|
bblanchon/ArduinoJson@^6.21.5
|
||||||
|
gin66/FastAccelStepper@0.30.15
|
||||||
|
h2zero/NimBLE-Arduino@2.2.3
|
||||||
|
links2004/WebSockets@2.6.1
|
||||||
|
|
||||||
[env:uno_macos]
|
[env:uno_macos]
|
||||||
platform = platformio/espressif32
|
platform = platformio/espressif32
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
extra_scripts = pre:scripts/patch_legacy_esp32_libs.py
|
||||||
|
build_flags =
|
||||||
|
-include $PROJECT_INCLUDE_DIR/ArduinoEsp32Compat.h
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
monitor_port = /dev/cu.usb*
|
monitor_port = /dev/cu.usb*
|
||||||
upload_port = /dev/cu.usb*
|
upload_port = /dev/cu.usb*
|
||||||
|
; Keep this aligned with [env:uno] for Arduino-ESP32 1.0.6 compatibility.
|
||||||
lib_deps =
|
lib_deps =
|
||||||
arminjo/ServoEasing
|
arminjo/ServoEasing
|
||||||
madhephaestus/ESP32Servo@^3.0.6
|
madhephaestus/ESP32Servo@^3.0.6
|
||||||
bblanchon/ArduinoJson@^6.21.5
|
bblanchon/ArduinoJson@^6.21.5
|
||||||
gin66/FastAccelStepper@^0.33.13
|
gin66/FastAccelStepper@0.30.15
|
||||||
h2zero/NimBLE-Arduino@^2.3.6
|
h2zero/NimBLE-Arduino@2.2.3
|
||||||
links2004/WebSockets@^2.6.1
|
links2004/WebSockets@2.6.1
|
||||||
|
|||||||
98
scripts/patch_legacy_esp32_libs.py
Normal file
98
scripts/patch_legacy_esp32_libs.py
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
Import("env")
|
||||||
|
|
||||||
|
|
||||||
|
def patch_nimble_address() -> None:
|
||||||
|
libdeps_dir = Path(env.subst("$PROJECT_LIBDEPS_DIR"))
|
||||||
|
env_name = env.subst("$PIOENV")
|
||||||
|
source_path = libdeps_dir / env_name / "NimBLE-Arduino" / "src" / "NimBLEAddress.cpp"
|
||||||
|
|
||||||
|
if not source_path.exists():
|
||||||
|
return
|
||||||
|
|
||||||
|
original = source_path.read_text(encoding="utf-8")
|
||||||
|
updated = original
|
||||||
|
|
||||||
|
include_old = '# include <algorithm>\n'
|
||||||
|
include_new = '# include <algorithm>\n# include <cstdlib>\n'
|
||||||
|
if include_old in updated and "# include <cstdlib>\n" not in updated:
|
||||||
|
updated = updated.replace(include_old, include_new, 1)
|
||||||
|
|
||||||
|
call_old = " uint64_t address = std::stoull(mac, nullptr, 16);"
|
||||||
|
call_new = " uint64_t address = strtoull(mac.c_str(), nullptr, 16);"
|
||||||
|
updated = updated.replace(call_old, call_new, 1)
|
||||||
|
|
||||||
|
if updated != original:
|
||||||
|
source_path.write_text(updated, encoding="utf-8")
|
||||||
|
print("Patched NimBLE-Arduino for legacy ESP32 toolchain compatibility")
|
||||||
|
|
||||||
|
|
||||||
|
def patch_nimble_device() -> None:
|
||||||
|
libdeps_dir = Path(env.subst("$PROJECT_LIBDEPS_DIR"))
|
||||||
|
env_name = env.subst("$PIOENV")
|
||||||
|
source_path = libdeps_dir / env_name / "NimBLE-Arduino" / "src" / "NimBLEDevice.cpp"
|
||||||
|
|
||||||
|
if not source_path.exists():
|
||||||
|
return
|
||||||
|
|
||||||
|
original = source_path.read_text(encoding="utf-8")
|
||||||
|
updated = original
|
||||||
|
|
||||||
|
updated = updated.replace(
|
||||||
|
" ble_sm_io pkey{.action = BLE_SM_IOACT_INPUT, .passkey = passkey};\n",
|
||||||
|
" ble_sm_io pkey{};\n"
|
||||||
|
" pkey.action = BLE_SM_IOACT_INPUT;\n"
|
||||||
|
" pkey.passkey = passkey;\n",
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
updated = updated.replace(
|
||||||
|
" ble_sm_io pkey{.action = BLE_SM_IOACT_NUMCMP, .numcmp_accept = accept};\n",
|
||||||
|
" ble_sm_io pkey{};\n"
|
||||||
|
" pkey.action = BLE_SM_IOACT_NUMCMP;\n"
|
||||||
|
" pkey.numcmp_accept = accept;\n",
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
|
||||||
|
if updated != original:
|
||||||
|
source_path.write_text(updated, encoding="utf-8")
|
||||||
|
print("Patched NimBLEDevice.cpp for legacy ESP32 toolchain compatibility")
|
||||||
|
|
||||||
|
|
||||||
|
def patch_websockets_client() -> None:
|
||||||
|
libdeps_dir = Path(env.subst("$PROJECT_LIBDEPS_DIR"))
|
||||||
|
env_name = env.subst("$PIOENV")
|
||||||
|
source_path = libdeps_dir / env_name / "WebSockets" / "src" / "WebSocketsClient.cpp"
|
||||||
|
|
||||||
|
if not source_path.exists():
|
||||||
|
return
|
||||||
|
|
||||||
|
original = source_path.read_text(encoding="utf-8")
|
||||||
|
updated = original
|
||||||
|
|
||||||
|
old = (
|
||||||
|
"#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4)\n"
|
||||||
|
" _client.ssl->setCACertBundle(_CA_bundle, _CA_bundle_size);\n"
|
||||||
|
"#else\n"
|
||||||
|
" _client.ssl->setCACertBundle(_CA_bundle);\n"
|
||||||
|
"#endif\n"
|
||||||
|
)
|
||||||
|
new = (
|
||||||
|
"#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 4)\n"
|
||||||
|
" _client.ssl->setCACertBundle(_CA_bundle, _CA_bundle_size);\n"
|
||||||
|
"#else\n"
|
||||||
|
" // Arduino-ESP32 1.x has no CA bundle API; the project only uses\n"
|
||||||
|
" // WebSocketsServer, so keep the client path buildable with insecure TLS.\n"
|
||||||
|
" _client.ssl->setInsecure();\n"
|
||||||
|
"#endif\n"
|
||||||
|
)
|
||||||
|
updated = updated.replace(old, new, 1)
|
||||||
|
|
||||||
|
if updated != original:
|
||||||
|
source_path.write_text(updated, encoding="utf-8")
|
||||||
|
print("Patched WebSocketsClient.cpp for legacy ESP32 toolchain compatibility")
|
||||||
|
|
||||||
|
|
||||||
|
patch_nimble_address()
|
||||||
|
patch_nimble_device()
|
||||||
|
patch_websockets_client()
|
||||||
@@ -144,9 +144,7 @@ void setPen()
|
|||||||
{
|
{
|
||||||
Log(__FUNCTION__);
|
Log(__FUNCTION__);
|
||||||
int cmd;
|
int cmd;
|
||||||
int value;
|
|
||||||
char *arg;
|
char *arg;
|
||||||
char cstrMsg[20];
|
|
||||||
|
|
||||||
// moveToDestination();
|
// moveToDestination();
|
||||||
|
|
||||||
@@ -172,7 +170,7 @@ void setPen()
|
|||||||
val = nextCommandArg();
|
val = nextCommandArg();
|
||||||
if (val != NULL)
|
if (val != NULL)
|
||||||
{
|
{
|
||||||
value = atoi(val);
|
(void)atoi(val);
|
||||||
sendAck();
|
sendAck();
|
||||||
// delay(value);
|
// delay(value);
|
||||||
}
|
}
|
||||||
@@ -189,8 +187,7 @@ void setPen()
|
|||||||
void togglePen()
|
void togglePen()
|
||||||
{
|
{
|
||||||
Log(__FUNCTION__);
|
Log(__FUNCTION__);
|
||||||
char *arg;
|
(void)nextCommandArg();
|
||||||
arg = nextCommandArg();
|
|
||||||
|
|
||||||
doTogglePen();
|
doTogglePen();
|
||||||
sendAck();
|
sendAck();
|
||||||
|
|||||||
11
src/esp_timer_compat.c
Normal file
11
src/esp_timer_compat.c
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include <ArduinoEsp32Compat.h>
|
||||||
|
|
||||||
|
#if defined(ESP32) && EGGDUINO_LEGACY_ARDUINO_ESP32
|
||||||
|
#include <esp_timer.h>
|
||||||
|
|
||||||
|
int esp_timer_is_active(esp_timer_handle_t timer)
|
||||||
|
{
|
||||||
|
(void)timer;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user