Skip to content

Commit 43ded08

Browse files
committed
Restore functionality as mbed library
``` mkdir test && cd test mbed new test mbed add https://github.com/arduino/ArduinoCore-API mbed add https://github.com/arduino/ArduinoCore-mbed cat <<EOT >> main.cpp 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 43ded08

File tree

7 files changed

+100
-26
lines changed

7 files changed

+100
-26
lines changed

.mbedignore

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
cores/arduino/mbed.h
12
cores/arduino/mbed/*
23
cores/arduino/api/Stream.h
34
cores/arduino/api/deprecated/Stream.h
45
cores/arduino/main.cpp
5-
variants/*mbed_config.h
6-
variants/E*
7-
variants/M*
8-
libraries/micro*
9-
libraries/WiFi*
6+
cores/arduino/mbed/*
7+
cores/arduino/mbed*
8+
libraries/openamp*
9+
cores/arduino/USB/*
10+
variants/*
11+
libraries/*

cores/arduino/Arduino.h

Lines changed: 0 additions & 3 deletions
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)
Lines changed: 71 additions & 0 deletions
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);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define PINS_COUNT 255
2+
#define NUM_ANALOG_INPUTS 4
Lines changed: 16 additions & 0 deletions
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

Lines changed: 0 additions & 18 deletions
This file was deleted.

cores/arduino/pinDefinitions.h

Lines changed: 4 additions & 0 deletions
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

0 commit comments

Comments
 (0)