Skip to content

Commit 26b6c02

Browse files
committed
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 <<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 ```
1 parent bd529a0 commit 26b6c02

File tree

9 files changed

+102
-17
lines changed

9 files changed

+102
-17
lines changed

.mbedignore

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ cores/arduino/mbed/*
22
cores/arduino/api/Stream.h
33
cores/arduino/api/deprecated/Stream.h
44
cores/arduino/main.cpp
5-
variants/*mbed_config.h
6-
variants/E*
7-
variants/M*
8-
libraries/micro*
9-
libraries/WiFi*
5+
libraries/openamp*
6+
cores/arduino/USB/*
7+
variants/*
8+
libraries/*

cores/arduino/Arduino.h

-3
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
#if !defined(Arduino_h) && !defined(ARDUINO_LIB_DISCOVERY_PHASE)
2424
#define Arduino_h
2525

26-
#if !defined(ARDUINO_AS_MBED_LIBRARY)
2726
#include "pinmode_arduino.h"
28-
#endif
29-
3027
#include "api/ArduinoAPI.h"
3128

3229
#if defined(__cplusplus)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#pragma once
2+
3+
/* Define mock symbols to nullify PinMode definitions */
4+
#define PullNone TempPullNone
5+
#define PullUp TempPullUp
6+
#define PullDown TempPullDown
7+
#define OpenDrainPullUp TempOpenDrainPullUp
8+
#define OpenDrainNoPull TempOpenDrainNoPull
9+
#define OpenDrainPullDown TempOpenDrainPullDown
10+
#define PushPullNoPull TempPushPullNoPull
11+
#define PushPullPullUp TempPushPullPullUp
12+
#define PushPullPullDown TempPushPullPullDown
13+
#define OpenDrain TempOpenDrain
14+
#define PullDefault TempPullDefault
15+
16+
#define INPUT TempINPUT
17+
#define OUTPUT TempOUTPUT
18+
#define INPUT_PULLUP TempINPUT_PULLUP
19+
#define INPUT_PULLDOWN TempINPUT_PULLDOWN
20+
21+
/* Rename symbol PinMode into MbedPinMode for all the file PinNamesTypes.h
22+
* Functions using PinMode should be redeclared with the correct PinMode symbol */
23+
#define PinMode MbedPinMode
24+
#include "PeripheralNames.h"
25+
#include "PinNamesTypes.h"
26+
#undef PinMode
27+
28+
/* Rename symbol PinMode into ArduinoPinMode for all the file Common.h
29+
* Functions using PinMode should be redeclared with the correct PinMode symbol */
30+
#define PinMode ArduinoPinMode
31+
#include "api/Common.h"
32+
#undef PinMode
33+
34+
#undef PullNone
35+
#undef PullUp
36+
#undef PullDown
37+
#undef OpenDrainPullUp
38+
#undef OpenDrainNoPull
39+
#undef OpenDrainPullDown
40+
#undef PushPullNoPull
41+
#undef PushPullPullUp
42+
#undef PushPullPullDown
43+
#undef OpenDrain
44+
#undef PullDefault
45+
46+
#undef INPUT
47+
#undef OUTPUT
48+
#undef INPUT_PULLUP
49+
#undef INPUT_PULLDOWN
50+
51+
/* Define the PinName symbol to be used in all the contexts */
52+
typedef enum {
53+
PullNone = TempPullNone,
54+
PullUp = TempPullUp,
55+
PullDown = TempPullDown,
56+
OpenDrainPullUp = TempOpenDrainPullUp,
57+
OpenDrainNoPull = TempOpenDrainNoPull,
58+
OpenDrainPullDown = TempOpenDrainPullDown,
59+
PushPullNoPull = TempPushPullNoPull,
60+
PushPullPullUp = TempPushPullPullUp,
61+
PushPullPullDown = TempPushPullPullDown,
62+
OpenDrain = TempOpenDrain,
63+
PullDefault = TempPullDefault,
64+
INPUT = TempINPUT,
65+
OUTPUT = TempOUTPUT,
66+
INPUT_PULLUP = TempINPUT_PULLUP,
67+
INPUT_PULLDOWN = TempINPUT_PULLDOWN
68+
} PinMode;
69+
70+
/* Redeclare Common.h functions with the updated PinMode */
71+
void pinMode(pin_size_t pinNumber, PinMode pinMode);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define PINS_COUNT 255
2+
#define NUM_ANALOG_INPUTS 4
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifdef ARDUINO_AS_MBED_LIBRARY
2+
3+
#include "Arduino.h"
4+
#include "pinDefinitions.h"
5+
6+
// generic variant
7+
8+
PinDescription g_APinDescription[PINS_COUNT];
9+
10+
void initVariant() {
11+
for (int i = 0; i<PINS_COUNT; i++) {
12+
g_APinDescription[i].name = (PinName)i;
13+
}
14+
}
15+
16+
#endif

cores/arduino/mbed.h

+3-7
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@
55

66
#if defined(__cplusplus)
77
#if !defined(ARDUINO_AS_MBED_LIBRARY)
8-
#ifdef F
9-
#define Arduino_F F
10-
#undef F
11-
#endif // F (mbed included after arduino.h)
12-
#define F Mbed_F
13-
#endif // !ARDUINO_AS_MBED_LIBRARY
148
#include "mbed/mbed.h"
15-
#undef F
9+
#else
10+
#include_next "mbed.h"
11+
#endif // !ARDUINO_AS_MBED_LIBRARY
1612
#endif //__cplusplus
1713

1814
#endif //_MBED_WRAP_H_

cores/arduino/pinDefinitions.h

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#ifdef USE_ARDUINO_PINOUT
2+
13
#include "drivers/InterruptIn.h"
24
#include "drivers/PwmOut.h"
35
#include "drivers/AnalogIn.h"
@@ -35,3 +37,5 @@ inline PinName digitalPinToPinName(pin_size_t P) {
3537
#endif
3638

3739
int PinNameToIndex(PinName P);
40+
41+
#endif

libraries/KernelDebug/src/KernelDebug.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <MRI.h>
1818
#include <cmsis_os2.h>
1919
#include <rtx_os.h>
20+
#include "Arduino.h"
2021
#include "KernelDebug.h"
2122

2223
// Put armv7-m module into handler mode before including its header and source code.

libraries/KernelDebug/src/KernelDebug.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030
*/
3131
#pragma once
3232

33-
#include <mbed.h>
3433
#include <pinDefinitions.h>
35-
34+
#include <mbed.h>
3635

3736
namespace arduino {
3837

0 commit comments

Comments
 (0)