From 34c9e8e21d2afa42a824d63c2dfacb149c20e93b Mon Sep 17 00:00:00 2001 From: Perc Student Workshop Date: Tue, 5 May 2026 15:44:40 -0400 Subject: [PATCH 1/6] Add CMakeLists.txt to repository for cmake integration --- CMakeLists.txt | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..d35dce69 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,54 @@ +cmake_minimum_required(VERSION 4.0.0) + +project("Arduino Core API" + LANGUAGES CXX C ASM + VERSION 1.5.2.1 + DESCRIPTION "Forked Arduino core API from v1.5.2" +) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_C_STANDARD 11) + +set(ARDUINO_CORE_API "arduino-core-api") + +add_library(${ARDUINO_CORE_API} INTERFACE) +target_sources(${ARDUINO_CORE_API} + INTERFACE + api/CanMsg.cpp + api/CanMsgRingbuffer.cpp + api/Common.cpp + api/IPAddress.cpp + api/PluggableUSB.cpp + api/Print.cpp + api/Stream.cpp + api/String.cpp + INTERFACE FILE_SET arduino_core_headers TYPE HEADERS + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} + FILES + api/ArduinoAPI.h + api/Binary.h + api/CanMsg.h + api/CanMsgRingbuffer.h + api/Client.h + api/Common.h + api/Compat.h + api/DMAPool.h + api/HardwareCAN.h + api/HardwareI2C.h + api/HardwareSerial.h + api/HardwareSPI.h + api/Interrupts.h + api/IPAddress.h + api/itoa.h + api/PluggableUSB.h + api/Print.h + api/Printable.h + api/RingBuffer.h + api/Server.h + api/Stream.h + api/String.h + api/Udp.h + api/USBAPI.h + api/WCharacter.h +) + +add_library(ARDUINO::CORE_API ALIAS ${ARDUINO_CORE_API}) \ No newline at end of file From dc32cb435e14ed479eeb29ad3c0f61dea7de91e7 Mon Sep 17 00:00:00 2001 From: Perc Student Workshop Date: Tue, 5 May 2026 15:46:35 -0400 Subject: [PATCH 2/6] Change PinMode enum to better reflect pin modes in the RP2040. --- api/Common.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/api/Common.h b/api/Common.h index 9b28f40a..33fb14a6 100644 --- a/api/Common.h +++ b/api/Common.h @@ -36,11 +36,19 @@ typedef enum { } PinStatus; typedef enum { - INPUT = 0x0, - OUTPUT = 0x1, - INPUT_PULLUP = 0x2, - INPUT_PULLDOWN = 0x3, - OUTPUT_OPENDRAIN = 0x4, + // Normal Arduino API pin modes. + INPUT = 0x1, + INPUT_SCHMITT = 0x2, + INPUT_PULLUP = 0x3, + INPUT_SCHMITT_PULLUP = 0x5, + INPUT_PULLDOWN = 0x4, + INPUT_SCHMITT_PULLDOWN = 0x6, + // Drive strength modes added for Pico RP2040/RP2040 + OUTPUT = 0x7, + OUTPUT_2mA = 0x8, + OUTPUT_4mA = 0x9, + OUTPUT_8mA = 0xA, + OUTPUT_12mA = 0xB } PinMode; typedef enum { From ce13f492d7e10815c74d0f27053f4fdb809066cb Mon Sep 17 00:00:00 2001 From: Perc Student Workshop Date: Tue, 5 May 2026 15:48:10 -0400 Subject: [PATCH 3/6] Change return types of millis and micros to standard int types : uint32_t and uint64_t for better integration with Pico-SDK. --- api/Common.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/Common.h b/api/Common.h index 33fb14a6..b3d2bd85 100644 --- a/api/Common.h +++ b/api/Common.h @@ -127,8 +127,8 @@ int analogRead(pin_size_t pinNumber); void analogReference(uint8_t mode); void analogWrite(pin_size_t pinNumber, int value); -unsigned long millis(void); -unsigned long micros(void); +uint32_t millis(void); +uint64_t micros(void); void delay(unsigned long); void delayMicroseconds(unsigned int us); unsigned long pulseIn(pin_size_t pin, uint8_t state, unsigned long timeout); From 1ccd2e9bc949013474189f7e65f13a47d0b3d372 Mon Sep 17 00:00:00 2001 From: Perc Student Workshop Date: Tue, 5 May 2026 15:49:35 -0400 Subject: [PATCH 4/6] Change return types of pulseIn and pulseInLong to standard int types : uint64_t for better integration with Pico-SDK. --- api/Common.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/Common.h b/api/Common.h index b3d2bd85..1b1f7ae9 100644 --- a/api/Common.h +++ b/api/Common.h @@ -131,8 +131,8 @@ uint32_t millis(void); uint64_t micros(void); void delay(unsigned long); void delayMicroseconds(unsigned int us); -unsigned long pulseIn(pin_size_t pin, uint8_t state, unsigned long timeout); -unsigned long pulseInLong(pin_size_t pin, uint8_t state, unsigned long timeout); +uint64_t pulseIn(pin_size_t pin, uint8_t state, unsigned long timeout); +uint64_t pulseInLong(pin_size_t pin, uint8_t state, unsigned long timeout); void shiftOut(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder, uint8_t val); uint8_t shiftIn(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder); From 199a6654a2eb0fa4c39ec5470e25fe690b3bfed2 Mon Sep 17 00:00:00 2001 From: Perc Student Workshop Date: Tue, 5 May 2026 16:04:40 -0400 Subject: [PATCH 5/6] Added noreturn attribute to main() prototype function --- api/Common.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/Common.h b/api/Common.h index 1b1f7ae9..80629bca 100644 --- a/api/Common.h +++ b/api/Common.h @@ -111,7 +111,7 @@ void initVariant(void); #ifndef HOST int atexit(void (*func)()) __attribute__((weak)); #endif -int main() __attribute__((weak)); +[[noreturn]] int main() __attribute__((weak)); #ifdef EXTENDED_PIN_MODE // Platforms who want to declare more than 256 pins need to define EXTENDED_PIN_MODE globally @@ -183,8 +183,8 @@ uint16_t makeWord(byte h, byte l); #define word(...) makeWord(__VA_ARGS__) -unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); -unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); +uint64_t pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); +uint64_t pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); void noTone(uint8_t _pin); From e7cd5846747364a9370fcc8d61ae3f43fcd5c8d8 Mon Sep 17 00:00:00 2001 From: Perc Student Workshop Date: Fri, 8 May 2026 16:48:58 -0400 Subject: [PATCH 6/6] change code formatting. --- api/Interrupts.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/api/Interrupts.h b/api/Interrupts.h index c3e37ade..02e463c1 100644 --- a/api/Interrupts.h +++ b/api/Interrupts.h @@ -31,13 +31,15 @@ namespace arduino { template using voidTemplateFuncPtrParam = void (*)(T param); -template struct __container__ { +template +struct __container__ { void* param; voidTemplateFuncPtrParam function; }; // C++ only overloaded version of attachInterrupt function -template void attachInterrupt(pin_size_t interruptNum, voidTemplateFuncPtrParam userFunc, PinStatus mode, T& param) { +template +void attachInterrupt(pin_size_t interruptNum, voidTemplateFuncPtrParam userFunc, PinStatus mode, T& param) { struct __container__ *cont = new __container__(); cont->param = ¶m; @@ -54,7 +56,8 @@ template void attachInterrupt(pin_size_t interruptNum, voidTemplateF attachInterruptParam(interruptNum, f, mode, cont); } -template void attachInterrupt(pin_size_t interruptNum, voidTemplateFuncPtrParam userFunc, PinStatus mode, T* param) { +template +void attachInterrupt(pin_size_t interruptNum, voidTemplateFuncPtrParam userFunc, PinStatus mode, T* param) { attachInterruptParam(interruptNum, (voidFuncPtrParam)userFunc, mode, (void*)param); }