Skip to content

Restore compatibility as mbed library #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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