Remove quirks.h, patch libs instead

This commit is contained in:
Mikhael Skvortsov 2025-03-27 21:11:20 +03:00
parent da7a9cb9ab
commit ad81ecc034
5 changed files with 53 additions and 24 deletions

View File

@ -38,7 +38,6 @@ build_flags =
-DLIBPAX_BLE -DLIBPAX_BLE
-DHAS_UDP_MULTICAST=1 -DHAS_UDP_MULTICAST=1
;-DDEBUG_HEAP ;-DDEBUG_HEAP
-include src/platform/esp32/quirks.h
lib_deps = lib_deps =
${arduino_base.lib_deps} ${arduino_base.lib_deps}

View File

@ -83,13 +83,6 @@ if platform.name == "espressif32":
# For newer ESP32 targets, using newlib nano works better. # For newer ESP32 targets, using newlib nano works better.
env.Append(LINKFLAGS=["--specs=nano.specs", "-u", "_printf_float"]) env.Append(LINKFLAGS=["--specs=nano.specs", "-u", "_printf_float"])
# XXX
for lb in env.GetLibBuilders():
if lb.name == "NonBlockingRTTTL":
lb.env.Append(CPPDEFINES=[("QUIRK_RTTTL", 1)])
elif lb.name == "LovyanGFX":
lb.env.Append(CPPDEFINES=[("QUIRK_LOVYAN", 1)])
if platform.name == "nordicnrf52": if platform.name == "nordicnrf52":
env.AddPostAction("$BUILD_DIR/${PROGNAME}.hex", env.AddPostAction("$BUILD_DIR/${PROGNAME}.hex",
env.VerboseAction(f"\"{sys.executable}\" ./bin/uf2conv.py $BUILD_DIR/firmware.hex -c -f 0xADA52840 -o $BUILD_DIR/firmware.uf2", env.VerboseAction(f"\"{sys.executable}\" ./bin/uf2conv.py $BUILD_DIR/firmware.hex -c -f 0xADA52840 -o $BUILD_DIR/firmware.uf2",
@ -140,3 +133,29 @@ for lb in env.GetLibBuilders():
if lb.name == "meshtastic-device-ui": if lb.name == "meshtastic-device-ui":
lb.env.Append(CPPDEFINES=[("APP_VERSION", verObj["long"])]) lb.env.Append(CPPDEFINES=[("APP_VERSION", verObj["long"])])
break break
############################# Libraries Patching #############################
env.Execute("$PYTHONEXE -m pip install patch")
import pathlib
import glob
import os
import patch
libsToPatch = {}
for entry in glob.glob("patches/*.patch"):
p = pathlib.Path(entry).stem
libsToPatch[p] = entry
for lb in env.GetLibBuilders():
if lb.name in libsToPatch:
marker_path = os.path.join(pathlib.Path(lb.src_dir), ".patched")
if not os.path.exists(marker_path):
patch_path = libsToPatch[lb.name]
ps = patch.fromfile(patch_path)
if not ps.apply(0, lb.src_dir):
print(f"Failed to apply patch {patch_path}")
exit(1)
print(f"Patched {lb.name}")
open(marker_path, "w").close()

View File

@ -0,0 +1,15 @@
diff --git a/NonBlockingRtttl.cpp b/NonBlockingRtttl.cpp
index 76dea43..ba8c4e5 100644
--- a/NonBlockingRtttl.cpp
+++ b/NonBlockingRtttl.cpp
@@ -69,8 +69,8 @@ void begin(byte iPin, const char * iSongBuffer)
//init values
pin = iPin;
#if defined(ESP32)
- ledcSetup(0, 1000, 10); // resolution always seems to be 10bit, no matter what is given
- ledcAttachPin(pin, 0);
+ // resolution always seems to be 10bit, no matter what is given
+ ledcAttachChannel(pin, 1000, 10, 0);
#endif
buffer = iSongBuffer;
bufferIndex = 0;

12
patches/SdFat.patch Normal file
View File

@ -0,0 +1,12 @@
diff --git a/iostream/ostream.h b/iostream/ostream.h
index e313ccf..9ac8c24 100644
--- a/iostream/ostream.h
+++ b/iostream/ostream.h
@@ -290,6 +290,7 @@ class ostream : public virtual ios {
void putNum(int64_t n);
void putNum(uint32_t n) { putNum(n, false); }
void putNum(uint64_t n) { putNum(n, false); }
+ void putNum(uintptr_t n) { putNum(n, false); }
void putPgm(const char *str);
void putStr(const char *str);

View File

@ -1,16 +0,0 @@
#if QUIRK_RTTTL
#define ledcSetup(ch, freq, res) \
uint32_t __freq = freq; \
uint8_t __res = res; \
do { \
} while (0)
#define ledcAttachPin(pin, ch) ledcAttachChannel(pin, __freq, __res, ch)
#endif
#if QUIRK_LOVYAN && (CHATTER_2 || M5STACK)
#include "rom/ets_sys.h"
#include <stdbool.h>
#undef bool
#undef true
#undef false
#endif