Skip to content
This repository was archived by the owner on Apr 16, 2021. It is now read-only.

Commit 19ddd21

Browse files
authored
Merge pull request #81 from arduino/beta
Backport patches from arduino/ArduinoCore-mbed
2 parents 1716fe5 + 92833a2 commit 19ddd21

File tree

293 files changed

+41663
-2098
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

293 files changed

+41663
-2098
lines changed

boards.txt

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ nano33ble.build.variant=ARDUINO_NANO33BLE
1919
nano33ble.build.mcu=cortex-m4
2020
nano33ble.build.extra_flags=
2121
nano33ble.build.architecture=cortex-m4
22+
nano33ble.build.fpu=fpv4-sp-d16
23+
nano33ble.build.float-abi=softfp
2224
nano33ble.build.board=ARDUINO_NANO33BLE
2325
nano33ble.build.ldscript=linker_script.ld
2426
nano33ble.compiler.mbed.arch.define=-DARDUINO_ARCH_NRF52840

cores/arduino/Arduino.h

+39-6
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,25 @@
1717
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818
*/
1919

20-
#ifndef Arduino_h
20+
#if !defined(Arduino_h) && !defined(ARDUINO_LIB_DISCOVERY_PHASE)
2121
#define Arduino_h
2222

2323
#if defined(__cplusplus)
2424
#if !defined(ARDUINO_AS_MBED_LIBRARY)
25-
#define PinMode MbedPinMode
25+
26+
#include "pinmode_arduino.h"
27+
2628
#ifdef F
2729
#define Arduino_F F
2830
#undef F
2931
#endif // F (mbed included after arduino.h)
3032
#define F Mbed_F
3133
#endif // !ARDUINO_AS_MBED_LIBRARY
32-
#include "mbed.h"
33-
#undef PinMode
34+
#include "mbed_config.h"
35+
#include "mbed/drivers/InterruptIn.h"
36+
#include "mbed/drivers/PwmOut.h"
37+
#include "mbed/drivers/AnalogIn.h"
38+
#include "mbed/drivers/DigitalInOut.h"
3439
#undef F
3540
#endif //__cplusplus
3641

@@ -80,16 +85,42 @@ void analogWriteResolution(int bits);
8085

8186
#include "pins_arduino.h"
8287

83-
/* Types used for the table below */
88+
#ifdef __cplusplus
89+
// Types used for the table below
8490
typedef struct _PinDescription
8591
{
8692
PinName name;
8793
mbed::InterruptIn* irq;
8894
mbed::PwmOut* pwm;
95+
mbed::DigitalInOut* gpio;
8996
} PinDescription ;
9097

91-
/* Pins table to be instantiated into variant.cpp */
98+
typedef struct _AnalogPinDescription
99+
{
100+
PinName name;
101+
mbed::AnalogIn* adc;
102+
} AnalogPinDescription ;
103+
104+
int PinNameToIndex(PinName P);
105+
106+
// Pins table to be instantiated into variant.cpp
92107
extern PinDescription g_APinDescription[];
108+
extern AnalogPinDescription g_AAnalogPinDescription[];
109+
110+
#ifdef ANALOG_CONFIG
111+
112+
typedef enum _AnalogReferenceMode AnalogReferenceMode;
113+
void analogReference(uint8_t mode);
114+
/* nRF specific function to change analog acquisition time */
115+
typedef enum _AnalogAcquisitionTime AnalogAcquisitionTime;
116+
void analogAcquisitionTime(uint8_t time);
117+
118+
/* Function to reconfigure already active ADC channels */
119+
void analogUpdate();
120+
extern bool isAdcConfigChanged;
121+
extern analogin_config_t adcCurrentConfig;
122+
123+
#endif
93124

94125
#include "Serial.h"
95126
#if defined(SERIAL_CDC)
@@ -105,6 +136,8 @@ extern PinDescription g_APinDescription[];
105136
#endif
106137

107138
#include "overloads.h"
139+
#endif
140+
108141
#include "macros.h"
109142

110143
#endif

cores/arduino/Interrupts.cpp

+30-33
Original file line numberDiff line numberDiff line change
@@ -18,55 +18,44 @@
1818

1919
#include "Arduino.h"
2020

21-
#ifdef digitalPinToInterruptObj
22-
static mbed::InterruptIn* PinNameToInterruptObj(PinName P) {
23-
// reverse search for pinName in g_APinDescription[P].name fields
24-
for (pin_size_t i=0; i < PINS_COUNT; i++) {
25-
if (g_APinDescription[i].name == P) {
26-
return g_APinDescription[i].irq;
27-
}
28-
}
29-
return NULL;
30-
}
31-
#endif
32-
3321
void detachInterrupt(PinName interruptNum) {
34-
#ifdef digitalPinToInterruptObj
35-
if (PinNameToInterruptObj(interruptNum) != NULL) {
36-
delete PinNameToInterruptObj(interruptNum);
22+
pin_size_t idx = PinNameToIndex(interruptNum);
23+
if (idx != NOT_A_PIN) {
24+
detachInterrupt(idx);
3725
}
38-
#endif
3926
}
4027

4128
void detachInterrupt(pin_size_t interruptNum) {
42-
#ifdef digitalPinToInterruptObj
43-
if (digitalPinToInterruptObj(interruptNum) != NULL) {
29+
if ((interruptNum < PINS_COUNT) && (digitalPinToInterruptObj(interruptNum) != NULL)) {
4430
delete digitalPinToInterruptObj(interruptNum);
4531
}
46-
#endif
4732
}
4833

4934
void attachInterruptParam(PinName interruptNum, voidFuncPtrParam func, PinStatus mode, void* param) {
50-
detachInterrupt(interruptNum);
51-
mbed::InterruptIn* irq = new mbed::InterruptIn(interruptNum);
52-
if (mode == CHANGE) {
53-
irq->rise(mbed::callback(func, param));
54-
irq->fall(mbed::callback(func, param));
55-
} else if (mode == FALLING) {
56-
irq->fall(mbed::callback(func, param));
35+
pin_size_t idx = PinNameToIndex(interruptNum);
36+
if (idx != NOT_A_PIN) {
37+
attachInterruptParam(PinNameToIndex(interruptNum), func, mode, param);
5738
} else {
58-
irq->rise(mbed::callback(func, param));
39+
mbed::InterruptIn* irq = new mbed::InterruptIn(interruptNum);
40+
if (mode == CHANGE) {
41+
irq->rise(mbed::callback(func, param));
42+
irq->fall(mbed::callback(func, param));
43+
} else if (mode == FALLING) {
44+
irq->fall(mbed::callback(func, param));
45+
} else {
46+
irq->rise(mbed::callback(func, param));
47+
}
5948
}
60-
#ifdef digitalPinToInterruptObj
61-
digitalPinToInterruptObj(interruptNum) = irq;
62-
#endif
6349
}
6450

6551
void attachInterrupt(PinName interruptNum, voidFuncPtr func, PinStatus mode) {
6652
attachInterruptParam(interruptNum, (voidFuncPtrParam)func, mode, NULL);
6753
}
6854

6955
void attachInterruptParam(pin_size_t interruptNum, voidFuncPtrParam func, PinStatus mode, void* param) {
56+
if (interruptNum >= PINS_COUNT) {
57+
return;
58+
}
7059
detachInterrupt(interruptNum);
7160
mbed::InterruptIn* irq = new mbed::InterruptIn(digitalPinToPinName(interruptNum));
7261
if (mode == CHANGE) {
@@ -77,11 +66,19 @@ void attachInterruptParam(pin_size_t interruptNum, voidFuncPtrParam func, PinSta
7766
} else {
7867
irq->rise(mbed::callback(func, param));
7968
}
80-
#ifdef digitalPinToInterruptObj
8169
digitalPinToInterruptObj(interruptNum) = irq;
82-
#endif
70+
// Give a default pullup for the pin, since calling InterruptIn with PinMode is impossible
71+
if (digitalPinToGpio(interruptNum) == NULL) {
72+
if (mode == FALLING) {
73+
pinMode(interruptNum, INPUT_PULLUP);
74+
} else if (mode == RISING) {
75+
pinMode(interruptNum, INPUT_PULLDOWN);
76+
} else {
77+
pinMode(interruptNum, INPUT);
78+
}
79+
}
8380
}
8481

8582
void attachInterrupt(pin_size_t interruptNum, voidFuncPtr func, PinStatus mode) {
8683
attachInterruptParam(interruptNum, (voidFuncPtrParam)func, mode, NULL);
87-
}
84+
}

cores/arduino/Serial.h

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "api/RingBuffer.h"
2424
#include "Arduino.h"
25+
#include "drivers/RawSerial.h"
2526

2627
#ifdef __cplusplus
2728

cores/arduino/Tone.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Arduino.h"
2+
#include "mbed.h"
23

34
class Tone {
45
mbed::DigitalOut *pin;

cores/arduino/USB/PluggableUSBDevice.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
*/
1717

1818
#include "Arduino.h"
19+
20+
#if defined(DEVICE_USBDEVICE) && defined(SERIAL_CDC)
21+
1922
#include "stdint.h"
2023
#include "PluggableUSBDevice.h"
2124
#include "EndpointResolver.h"
@@ -289,3 +292,5 @@ arduino::PluggableUSBDevice& PluggableUSBD()
289292
static arduino::PluggableUSBDevice obj(BOARD_VENDORID, BOARD_PRODUCTID);
290293
return obj;
291294
}
295+
296+
#endif

cores/arduino/USB/PluggableUSBSerial.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "Arduino.h"
2222
#include "USBCDC.h"
2323
#include "platform/Stream.h"
24+
#include "mbed/rtos/rtos.h"
2425
#include "Callback.h"
2526

2627
/**

cores/arduino/USB/USBCDC.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
* limitations under the License.
1616
*/
1717

18+
19+
#include "Arduino.h"
20+
#include "PeripheralPins.h"
21+
22+
#if DEVICE_USBDEVICE && defined(SERIAL_CDC)
23+
1824
#include "stdint.h"
1925
#include "USBCDC.h"
2026
#include "EndpointResolver.h"
@@ -611,3 +617,5 @@ const uint8_t *USBCDC::configuration_desc(uint8_t index)
611617
return NULL;
612618
}
613619
}
620+
621+
#endif

cores/arduino/USB/USBSerial.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@
1515
* limitations under the License.
1616
*/
1717

18+
#include "Arduino.h"
19+
20+
#if DEVICE_USBDEVICE && defined(SERIAL_CDC)
21+
1822
#include "stdint.h"
1923
#include "PluggableUSBSerial.h"
2024
#include "usb_phy_api.h"
25+
#include "mbed.h"
2126

2227
using namespace arduino;
2328

@@ -113,4 +118,6 @@ bool USBSerial::connected()
113118
return _terminal_connected;
114119
}
115120

116-
USBSerial SerialUSB(false);
121+
USBSerial SerialUSB(false);
122+
123+
#endif

cores/arduino/macros.h

+20-16
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,29 @@
2323
#pragma once
2424
#ifdef USE_ARDUINO_PINOUT
2525

26-
#define analogPinToPinName(P) (P < A0 ? g_APinDescription[P+A0].name : g_APinDescription[P].name)
27-
#define digitalPinToPinName(P) (g_APinDescription[P].name)
28-
#define digitalPinToInterrupt(P) (P)
29-
#define digitalPinToInterruptObj(P) (g_APinDescription[P].irq)
30-
#define digitalPinToPwmObj(P) (g_APinDescription[P].pwm)
26+
#define analogPinToPinName(P) (P >= PINS_COUNT ? NC : P < A0 ? g_APinDescription[P+A0].name : g_APinDescription[P].name)
27+
#define analogPinToAdcObj(P) (P < A0 ? g_AAnalogPinDescription[P].adc : g_AAnalogPinDescription[P-A0].adc)
28+
#define digitalPinToPinName(P) (P >= PINS_COUNT ? NC : g_APinDescription[P].name)
29+
#define digitalPinToInterruptObj(P) (g_APinDescription[P].irq)
30+
#define digitalPinToPwm(P) (g_APinDescription[P].pwm)
31+
#define digitalPinToGpio(P) (g_APinDescription[P].gpio)
32+
33+
// this is needed for backwards compatibility
34+
#define digitalPinToInterrupt(P) (P)
3135

3236
#else
3337

34-
#define analogPinToPinName(P) ((PinName)P)
35-
#define digitalPinToPinName(P) ((PinName)P)
36-
#define digitalPinToInterrupt(P) ((PinName)P)
38+
#define analogPinToPinName(P) ((PinName)P)
39+
#define digitalPinToPinName(P) ((PinName)P)
40+
#define digitalPinToInterrupt(P) ((PinName)P)
3741

3842
#endif
3943

40-
#define REDIRECT_STDOUT_TO(stream) namespace mbed { \
41-
FileHandle *mbed_override_console(int fd) { \
42-
return &stream; \
43-
} \
44-
FileHandle *mbed_target_override_console(int fd) { \
45-
return &stream; \
46-
} \
47-
}
44+
#define REDIRECT_STDOUT_TO(stream) namespace mbed { \
45+
FileHandle *mbed_override_console(int fd) { \
46+
return &stream; \
47+
} \
48+
FileHandle *mbed_target_override_console(int fd) { \
49+
return &stream; \
50+
} \
51+
}

cores/arduino/mbed.h

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef _MBED_WRAP_H_
2+
#define _MBED_WRAP_H_
3+
4+
#include "Arduino.h"
5+
6+
#if defined(__cplusplus)
7+
#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
14+
#include "mbed/mbed.h"
15+
#undef F
16+
#endif //__cplusplus
17+
18+
#endif //_MBED_WRAP_H_

0 commit comments

Comments
 (0)