From 26b6c021d9ca639e0a6da6edc80e13e3dc501dfb Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 14 Apr 2021 17:14:52 +0200 Subject: [PATCH] Restore functionality as mbed library ``` mkdir test && cd test mbed new . mbed add https://github.com/arduino/ArduinoCore-API mbed add https://github.com/arduino/ArduinoCore-mbed cat <> main.cpp DigitalOut led(PA_1); int main() { pinMode(PA_0, OUTPUT); while (1) { digitalWrite(PA_0, HIGH); delay(100); digitalWrite(PA_0, LOW); delay(100); } } EOT mbed compile -m TARGET -t GCC_ARM ``` --- .mbedignore | 9 ++- cores/arduino/Arduino.h | 3 - .../arduino/as_mbed_library/pinmode_arduino.h | 71 +++++++++++++++++++ cores/arduino/as_mbed_library/pins_arduino.h | 2 + cores/arduino/as_mbed_library/variant.cpp | 16 +++++ cores/arduino/mbed.h | 10 +-- cores/arduino/pinDefinitions.h | 4 ++ libraries/KernelDebug/src/KernelDebug.cpp | 1 + libraries/KernelDebug/src/KernelDebug.h | 3 +- 9 files changed, 102 insertions(+), 17 deletions(-) create mode 100644 cores/arduino/as_mbed_library/pinmode_arduino.h create mode 100644 cores/arduino/as_mbed_library/pins_arduino.h create mode 100644 cores/arduino/as_mbed_library/variant.cpp diff --git a/.mbedignore b/.mbedignore index cee0a2eb5..9d980ea3a 100644 --- a/.mbedignore +++ b/.mbedignore @@ -2,8 +2,7 @@ cores/arduino/mbed/* cores/arduino/api/Stream.h cores/arduino/api/deprecated/Stream.h cores/arduino/main.cpp -variants/*mbed_config.h -variants/E* -variants/M* -libraries/micro* -libraries/WiFi* +libraries/openamp* +cores/arduino/USB/* +variants/* +libraries/* diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index debbcf459..38cc70664 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -23,10 +23,7 @@ #if !defined(Arduino_h) && !defined(ARDUINO_LIB_DISCOVERY_PHASE) #define Arduino_h -#if !defined(ARDUINO_AS_MBED_LIBRARY) #include "pinmode_arduino.h" -#endif - #include "api/ArduinoAPI.h" #if defined(__cplusplus) diff --git a/cores/arduino/as_mbed_library/pinmode_arduino.h b/cores/arduino/as_mbed_library/pinmode_arduino.h new file mode 100644 index 000000000..19bcec803 --- /dev/null +++ b/cores/arduino/as_mbed_library/pinmode_arduino.h @@ -0,0 +1,71 @@ +#pragma once + +/* Define mock symbols to nullify PinMode definitions */ +#define PullNone TempPullNone +#define PullUp TempPullUp +#define PullDown TempPullDown +#define OpenDrainPullUp TempOpenDrainPullUp +#define OpenDrainNoPull TempOpenDrainNoPull +#define OpenDrainPullDown TempOpenDrainPullDown +#define PushPullNoPull TempPushPullNoPull +#define PushPullPullUp TempPushPullPullUp +#define PushPullPullDown TempPushPullPullDown +#define OpenDrain TempOpenDrain +#define PullDefault TempPullDefault + +#define INPUT TempINPUT +#define OUTPUT TempOUTPUT +#define INPUT_PULLUP TempINPUT_PULLUP +#define INPUT_PULLDOWN TempINPUT_PULLDOWN + +/* Rename symbol PinMode into MbedPinMode for all the file PinNamesTypes.h + * Functions using PinMode should be redeclared with the correct PinMode symbol */ +#define PinMode MbedPinMode +#include "PeripheralNames.h" +#include "PinNamesTypes.h" +#undef PinMode + +/* Rename symbol PinMode into ArduinoPinMode for all the file Common.h + * Functions using PinMode should be redeclared with the correct PinMode symbol */ +#define PinMode ArduinoPinMode +#include "api/Common.h" +#undef PinMode + +#undef PullNone +#undef PullUp +#undef PullDown +#undef OpenDrainPullUp +#undef OpenDrainNoPull +#undef OpenDrainPullDown +#undef PushPullNoPull +#undef PushPullPullUp +#undef PushPullPullDown +#undef OpenDrain +#undef PullDefault + +#undef INPUT +#undef OUTPUT +#undef INPUT_PULLUP +#undef INPUT_PULLDOWN + +/* Define the PinName symbol to be used in all the contexts */ +typedef enum { + PullNone = TempPullNone, + PullUp = TempPullUp, + PullDown = TempPullDown, + OpenDrainPullUp = TempOpenDrainPullUp, + OpenDrainNoPull = TempOpenDrainNoPull, + OpenDrainPullDown = TempOpenDrainPullDown, + PushPullNoPull = TempPushPullNoPull, + PushPullPullUp = TempPushPullPullUp, + PushPullPullDown = TempPushPullPullDown, + OpenDrain = TempOpenDrain, + PullDefault = TempPullDefault, + INPUT = TempINPUT, + OUTPUT = TempOUTPUT, + INPUT_PULLUP = TempINPUT_PULLUP, + INPUT_PULLDOWN = TempINPUT_PULLDOWN +} PinMode; + +/* Redeclare Common.h functions with the updated PinMode */ +void pinMode(pin_size_t pinNumber, PinMode pinMode); \ No newline at end of file diff --git a/cores/arduino/as_mbed_library/pins_arduino.h b/cores/arduino/as_mbed_library/pins_arduino.h new file mode 100644 index 000000000..e53349050 --- /dev/null +++ b/cores/arduino/as_mbed_library/pins_arduino.h @@ -0,0 +1,2 @@ +#define PINS_COUNT 255 +#define NUM_ANALOG_INPUTS 4 \ No newline at end of file diff --git a/cores/arduino/as_mbed_library/variant.cpp b/cores/arduino/as_mbed_library/variant.cpp new file mode 100644 index 000000000..b771fc1ca --- /dev/null +++ b/cores/arduino/as_mbed_library/variant.cpp @@ -0,0 +1,16 @@ +#ifdef ARDUINO_AS_MBED_LIBRARY + +#include "Arduino.h" +#include "pinDefinitions.h" + +// generic variant + +PinDescription g_APinDescription[PINS_COUNT]; + +void initVariant() { + for (int i = 0; i #include #include +#include "Arduino.h" #include "KernelDebug.h" // Put armv7-m module into handler mode before including its header and source code. diff --git a/libraries/KernelDebug/src/KernelDebug.h b/libraries/KernelDebug/src/KernelDebug.h index 014ae1df8..1e27dde5d 100644 --- a/libraries/KernelDebug/src/KernelDebug.h +++ b/libraries/KernelDebug/src/KernelDebug.h @@ -30,9 +30,8 @@ */ #pragma once -#include #include - +#include namespace arduino {