From bc74c21599cd579472776596d2fdb207eec4a07e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Wed, 24 May 2023 13:02:33 +0200 Subject: [PATCH] [realtek-ambz2] Enable compilation of Arduino core --- builder/frameworks/arduino.py | 1 - builder/utils/config.py | 16 ++++++++++++---- .../arduino/libraries/common/mDNS/LwIPmDNS.cpp | 8 ++++++++ cores/common/arduino/src/Arduino.h | 1 + cores/common/base/config/lwipopts.h | 3 +++ cores/realtek-amb/arduino/src/main.cpp | 5 +---- cores/realtek-amb/arduino/src/wiring_pulse.c | 4 ++-- cores/realtek-amb/base/sdk_private.h | 5 +++++ cores/realtek-ambz2/base/config/platform_conf.h | 3 +++ 9 files changed, 35 insertions(+), 11 deletions(-) diff --git a/builder/frameworks/arduino.py b/builder/frameworks/arduino.py index d2e0d40..1281079 100644 --- a/builder/frameworks/arduino.py +++ b/builder/frameworks/arduino.py @@ -73,7 +73,6 @@ queue.AppendPublic( ("ARDUINO_SDK", 1), ], LINKFLAGS=[ - "--specs=nosys.specs", "-Wl,--as-needed", "-Wl,--build-id=none", "-Wl,--cref", diff --git a/builder/utils/config.py b/builder/utils/config.py index 8a49589..8ebf701 100644 --- a/builder/utils/config.py +++ b/builder/utils/config.py @@ -20,13 +20,21 @@ def env_load_defines(env: Environment, path: str): line = line[7:].strip() line = line.split(None, 2) if len(line) == 1: - env.Append(CPPDEFINES=[(line[0], 1)]) - config[line[0]] = 1 + key, value = line[0], 1 elif len(line) == 2: - env.Append(CPPDEFINES=[(line[0], line[1])]) - config[line[0]] = line[1] + key, value = line[0], line[1] else: raise ValueError(f"Unknown directive: {line}") + for tpl in env["CPPDEFINES"]: + if isinstance(tpl, tuple): + k = tpl[0] + else: + k = tpl + if k == key: + env["CPPDEFINES"].remove(tpl) + break + env.Append(CPPDEFINES=[(key, value)]) + config[key] = value env.Append( CONFIG=config, ) diff --git a/cores/common/arduino/libraries/common/mDNS/LwIPmDNS.cpp b/cores/common/arduino/libraries/common/mDNS/LwIPmDNS.cpp index 40c16ca..f69eb04 100644 --- a/cores/common/arduino/libraries/common/mDNS/LwIPmDNS.cpp +++ b/cores/common/arduino/libraries/common/mDNS/LwIPmDNS.cpp @@ -13,6 +13,8 @@ extern "C" { #include } +#if LWIP_MDNS_RESPONDER + static std::vector services_name; static std::vector services; static std::vector protos; @@ -81,7 +83,11 @@ static bool enableMDNS(struct netif *netif) { err_t ret = mdns_resp_add_netif(netif, hostName, 255); if (ret == ERR_OK) { LT_DM(MDNS, "mDNS started on netif %u, announcing it to network", netif->num); +#if LWIP_VERSION_SIMPLE >= 20100 mdns_resp_announce(netif); +#else +#warning "lwIP version older than 2.1.0, mdns_resp_announce() unavailable" +#endif return true; } else { LT_DM(MDNS, "Cannot start mDNS on netif %u; ret=%d, errno=%d", netif->num, ret, errno); @@ -188,3 +194,5 @@ bool mDNS::addServiceTxtImpl(const char *service, uint8_t proto, const char *ite MDNSResponder MDNS; #endif + +#endif diff --git a/cores/common/arduino/src/Arduino.h b/cores/common/arduino/src/Arduino.h index 7e3e184..cdda136 100644 --- a/cores/common/arduino/src/Arduino.h +++ b/cores/common/arduino/src/Arduino.h @@ -25,6 +25,7 @@ using std::min; #include #ifdef __cplusplus #include +using namespace arduino; #endif // Include family-specific code diff --git a/cores/common/base/config/lwipopts.h b/cores/common/base/config/lwipopts.h index 833df85..2557d02 100644 --- a/cores/common/base/config/lwipopts.h +++ b/cores/common/base/config/lwipopts.h @@ -33,6 +33,9 @@ // clang-format on #endif +// lwIP version as a decimal number, with 2 digits for each part (major, minor, patch) +#define LWIP_VERSION_SIMPLE (LWIP_VERSION_MAJOR * 10000 + LWIP_VERSION_MINOR * 100 + LWIP_VERSION_REVISION) + // remove family-defined debugging options (use lwIP defaults, or user-defined) #undef ETHARP_DEBUG #undef NETIF_DEBUG diff --git a/cores/realtek-amb/arduino/src/main.cpp b/cores/realtek-amb/arduino/src/main.cpp index 9587dc7..7db967f 100644 --- a/cores/realtek-amb/arduino/src/main.cpp +++ b/cores/realtek-amb/arduino/src/main.cpp @@ -5,12 +5,9 @@ extern "C" { -#include -#include - osThreadId main_tid = 0; -#if LT_AUTO_DOWNLOAD_REBOOT && defined(PIN_SERIAL2_RX) && defined(PIN_SERIAL2_TX) +#if LT_AUTO_DOWNLOAD_REBOOT && LT_ARD_HAS_SERIAL && defined(PIN_SERIAL2_RX) && defined(PIN_SERIAL2_TX) void lt_init_arduino() { // initialize auto-download-reboot parser Serial2.begin(115200); diff --git a/cores/realtek-amb/arduino/src/wiring_pulse.c b/cores/realtek-amb/arduino/src/wiring_pulse.c index 85161e6..83aeed9 100644 --- a/cores/realtek-amb/arduino/src/wiring_pulse.c +++ b/cores/realtek-amb/arduino/src/wiring_pulse.c @@ -31,14 +31,14 @@ extern unsigned long pulseIn(uint8_t pinNumber, uint8_t state, unsigned long tim // digitalRead() instead yields much coarser resolution. PinInfo *pin = pinInfo(pinNumber); if (pin == NULL) - return; + return 0; uint32_t index = pinIndex(pin); gpio_t *pGpio_t; uint32_t start_ticks, cur_ticks; - if (pin < 0 || pin > PINS_COUNT || (pin->gpio == NC)) + if (pin->gpio == NC) return 0; /* Handle */ diff --git a/cores/realtek-amb/base/sdk_private.h b/cores/realtek-amb/base/sdk_private.h index aaf51af..d3bbf01 100644 --- a/cores/realtek-amb/base/sdk_private.h +++ b/cores/realtek-amb/base/sdk_private.h @@ -14,6 +14,7 @@ extern "C" { // remove log_printf() if included before sdk_private.h #undef log_printf +// CMSIS & Realtek APIs #if LT_RTL8710B #include #include @@ -25,6 +26,9 @@ extern "C" { #include #endif +#include + +// mbed APIs #include #undef MBED_GPIO_API_H // ..no comment #include @@ -48,6 +52,7 @@ extern "C" { #include #include +// other SDK APIs #if __has_include() #include #endif diff --git a/cores/realtek-ambz2/base/config/platform_conf.h b/cores/realtek-ambz2/base/config/platform_conf.h index 4b5d67d..fbf831f 100644 --- a/cores/realtek-ambz2/base/config/platform_conf.h +++ b/cores/realtek-ambz2/base/config/platform_conf.h @@ -17,3 +17,6 @@ #define DBG_SCE_ERR(...) #define DBG_SCE_WARN(...) #define DBG_SCE_INFO(...) + +// ...? +#define CONFIG_ADC_EN