Skip to content

Commit

Permalink
Restore functionality as mbed library
Browse files Browse the repository at this point in the history
```
mkdir test && cd test
mbed new .
mbed add https://github.com/arduino/ArduinoCore-API
mbed add https://github.com/arduino/ArduinoCore-mbed
cat <<EOT >> 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
```
  • Loading branch information
facchinm committed Apr 14, 2021
1 parent bd529a0 commit 26b6c02
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 17 deletions.
9 changes: 4 additions & 5 deletions .mbedignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
3 changes: 0 additions & 3 deletions cores/arduino/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
71 changes: 71 additions & 0 deletions cores/arduino/as_mbed_library/pinmode_arduino.h
Original file line number Diff line number Diff line change
@@ -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);
2 changes: 2 additions & 0 deletions cores/arduino/as_mbed_library/pins_arduino.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define PINS_COUNT 255
#define NUM_ANALOG_INPUTS 4
16 changes: 16 additions & 0 deletions cores/arduino/as_mbed_library/variant.cpp
Original file line number Diff line number Diff line change
@@ -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<PINS_COUNT; i++) {
g_APinDescription[i].name = (PinName)i;
}
}

#endif
10 changes: 3 additions & 7 deletions cores/arduino/mbed.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@

#if defined(__cplusplus)
#if !defined(ARDUINO_AS_MBED_LIBRARY)
#ifdef F
#define Arduino_F F
#undef F
#endif // F (mbed included after arduino.h)
#define F Mbed_F
#endif // !ARDUINO_AS_MBED_LIBRARY
#include "mbed/mbed.h"
#undef F
#else
#include_next "mbed.h"
#endif // !ARDUINO_AS_MBED_LIBRARY
#endif //__cplusplus

#endif //_MBED_WRAP_H_
4 changes: 4 additions & 0 deletions cores/arduino/pinDefinitions.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef USE_ARDUINO_PINOUT

#include "drivers/InterruptIn.h"
#include "drivers/PwmOut.h"
#include "drivers/AnalogIn.h"
Expand Down Expand Up @@ -35,3 +37,5 @@ inline PinName digitalPinToPinName(pin_size_t P) {
#endif

int PinNameToIndex(PinName P);

#endif
1 change: 1 addition & 0 deletions libraries/KernelDebug/src/KernelDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <MRI.h>
#include <cmsis_os2.h>
#include <rtx_os.h>
#include "Arduino.h"
#include "KernelDebug.h"

// Put armv7-m module into handler mode before including its header and source code.
Expand Down
3 changes: 1 addition & 2 deletions libraries/KernelDebug/src/KernelDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
*/
#pragma once

#include <mbed.h>
#include <pinDefinitions.h>

#include <mbed.h>

namespace arduino {

Expand Down

0 comments on commit 26b6c02

Please sign in to comment.