Skip to content

Commit 0d48d4c

Browse files
committed
Improve compatibility with existing libraries
1 parent 8514d85 commit 0d48d4c

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

cores/arduino/Arduino.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111

1212

1313
#if defined(__cplusplus)
14+
15+
using namespace arduino;
16+
1417
#include "usb/SerialUSB.h"
1518
#include "pwm.h"
1619
#include "Serial.h"
1720
#endif
1821

19-
2022
#if defined(__cplusplus)
2123

2224
#undef F
@@ -171,6 +173,14 @@ extern sciTable_t SciTable[];
171173
#define digitalPinToPwmPin(P) (g_APinDescription[P].PWMChannel)
172174
#define digitalPinToPwmObj(P) (pwmTable[digitalPinToPwmPin(P)].pwm)
173175

176+
#define IOPORT_PRV_PORT_ADDRESS(port_number) ((uint32_t) (R_PORT1 - R_PORT0) * (port_number) + R_PORT0)
177+
178+
#define digitalPinToPort(P) (digitalPinToBspPin(P) >> 8)
179+
#define digitalPinToBitMask(P) (1 << (digitalPinToBspPin(P) & 0xFF))
180+
#define portOutputRegister(port) &(((R_PORT0_Type *)IOPORT_PRV_PORT_ADDRESS(port))->PODR)
181+
#define portInputRegister(port) &(((R_PORT0_Type *)IOPORT_PRV_PORT_ADDRESS(port))->PIDR)
182+
#define portModeRegister(port) &(((R_PORT0_Type *)IOPORT_PRV_PORT_ADDRESS(port))->PDR)
183+
174184
void pinPeripheral(bsp_io_port_pin_t bspPin, uint32_t bspPeripheral);
175185
#if defined(__cplusplus)
176186
void pinPeripheral(uint32_t pinNumber, uint32_t bspPeripheral);

libraries/SPI/SPI.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#include "SPI.h"
1515

16+
using namespace arduino;
17+
1618
extern const spi_extended_cfg_t g_spi0_ext_cfg;
1719
extern const spi_extended_cfg_t g_spi1_ext_cfg;
1820
extern const sci_spi_extended_cfg_t g_spi2_cfg_extend;

libraries/SPI/SPI.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
//extern const spi_extended_cfg_t g_spi0_ext_cfg;
2424
//extern const sci_spi_extended_cfg_t g_spi1_cfg_extend;
2525

26-
class ArduinoSPI : public arduino::SPIClass
26+
namespace arduino {
27+
28+
class ArduinoSPI : public SPIClass
2729
{
2830
public:
2931
ArduinoSPI(spi_ctrl_t *g_spi_ctrl
@@ -79,14 +81,16 @@ class ArduinoSPI : public arduino::SPIClass
7981
bool _is_sci;
8082
};
8183

84+
}
85+
8286
#if SPI_HOWMANY > 0
83-
extern ArduinoSPI SPI;
87+
extern arduino::ArduinoSPI SPI;
8488
#endif
8589
#if SPI_HOWMANY > 1
8690
#ifdef SPI1
8791
#undef SPI1
8892
#endif
89-
extern ArduinoSPI SPI1;
93+
extern arduino::ArduinoSPI SPI1;
9094
#endif
9195

9296
#endif

0 commit comments

Comments
 (0)