Skip to content

Commit d887d06

Browse files
honnetsandeepmistry
authored andcommitted
Custom I2C/SPI/UART pins for generic variants (sandeepmistry#221)
* UART: Add setPins(...) for generic boards (nRF51 and nRF52). * SPI: Add setPins(...) for generic boards (nRF51 and nRF52). * Wire (I2C/TWI): Add setPins(...) for generic boards (nRF51 and nRF52).
1 parent 10fd652 commit d887d06

File tree

7 files changed

+52
-1
lines changed

7 files changed

+52
-1
lines changed

cores/nRF5/Uart.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ Uart::Uart(NRF_UART_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _pi
4141
uc_hwFlow = 1;
4242
}
4343

44+
#ifdef ARDUINO_GENERIC
45+
void Uart::setPins(uint8_t _pinRX, uint8_t _pinTX)
46+
{
47+
uc_pinRX = g_ADigitalPinMap[_pinRX];
48+
uc_pinTX = g_ADigitalPinMap[_pinTX];
49+
}
50+
51+
void Uart::setPins(uint8_t _pinRX, uint8_t _pinTX, uint8_t _pinCTS, uint8_t _pinRTS)
52+
{
53+
uc_pinRX = g_ADigitalPinMap[_pinRX];
54+
uc_pinTX = g_ADigitalPinMap[_pinTX];
55+
uc_pinCTS = g_ADigitalPinMap[_pinCTS];
56+
uc_pinRTS = g_ADigitalPinMap[_pinRTS];
57+
}
58+
#endif // ARDUINO_GENERIC
59+
4460
void Uart::begin(unsigned long baudrate)
4561
{
4662
begin(baudrate, (uint8_t)SERIAL_8N1);

cores/nRF5/Uart.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class Uart : public HardwareSerial
3131
public:
3232
Uart(NRF_UART_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _pinTX);
3333
Uart(NRF_UART_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _pinTX, uint8_t _pinCTS, uint8_t _pinRTS );
34+
#ifdef ARDUINO_GENERIC
35+
void setPins(uint8_t _pinRX, uint8_t _pinTX);
36+
void setPins(uint8_t _pinRX, uint8_t _pinTX, uint8_t _pinCTS, uint8_t _pinRTS);
37+
#endif // ARDUINO_GENERIC
3438
void begin(unsigned long baudRate);
3539
void begin(unsigned long baudrate, uint16_t config);
3640
void end();

libraries/SPI/SPI.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ SPIClass::SPIClass(NRF_SPI_Type *p_spi, uint8_t uc_pinMISO, uint8_t uc_pinSCK, u
4444
_bitOrder = SPI_CONFIG_ORDER_MsbFirst;
4545
}
4646

47+
#ifdef ARDUINO_GENERIC
48+
void SPIClass::setPins(uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI)
49+
{
50+
_uc_pinMiso = g_ADigitalPinMap[uc_pinMISO];
51+
_uc_pinSCK = g_ADigitalPinMap[uc_pinSCK];
52+
_uc_pinMosi = g_ADigitalPinMap[uc_pinMOSI];
53+
}
54+
#endif // ARDUINO_GENERIC
55+
4756
void SPIClass::begin()
4857
{
4958
init();

libraries/SPI/SPI.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ class SPIClass {
100100
void attachInterrupt();
101101
void detachInterrupt();
102102

103+
#ifdef ARDUINO_GENERIC
104+
void setPins(uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI);
105+
#endif // ARDUINO_GENERIC
103106
void begin();
104107
void end();
105108

@@ -152,4 +155,4 @@ extern SPIClass SPI1;
152155
#define SPI_CLOCK_DIV128 128
153156
#endif
154157

155-
#endif
158+
#endif

libraries/Wire/Wire.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class TwoWire : public Stream
3939
#else
4040
TwoWire(NRF_TWI_Type * p_twi, uint8_t pinSDA, uint8_t pinSCL);
4141
#endif
42+
#ifdef ARDUINO_GENERIC
43+
void setPins(uint8_t pinSDA, uint8_t pinSCL);
44+
#endif // ARDUINO_GENERIC
4245
void begin();
4346
#ifdef NRF52
4447
void begin(uint8_t);

libraries/Wire/Wire_nRF51.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ TwoWire::TwoWire(NRF_TWI_Type * p_twi, uint8_t pinSDA, uint8_t pinSCL)
3939
this->suspended = false;
4040
}
4141

42+
#ifdef ARDUINO_GENERIC
43+
void TwoWire::setPins(uint8_t pinSDA, uint8_t pinSCL)
44+
{
45+
this->_uc_pinSDA = g_ADigitalPinMap[pinSDA];
46+
this->_uc_pinSCL = g_ADigitalPinMap[pinSCL];
47+
}
48+
#endif // ARDUINO_GENERIC
49+
4250
void TwoWire::begin(void) {
4351
//Master Mode
4452
master = true;

libraries/Wire/Wire_nRF52.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ TwoWire::TwoWire(NRF_TWIM_Type * p_twim, NRF_TWIS_Type * p_twis, IRQn_Type IRQn,
3939
transmissionBegun = false;
4040
}
4141

42+
#ifdef ARDUINO_GENERIC
43+
void TwoWire::setPins(uint8_t pinSDA, uint8_t pinSCL)
44+
{
45+
this->_uc_pinSDA = g_ADigitalPinMap[pinSDA];
46+
this->_uc_pinSCL = g_ADigitalPinMap[pinSCL];
47+
}
48+
#endif // ARDUINO_GENERIC
49+
4250
void TwoWire::begin(void) {
4351
//Master Mode
4452
master = true;

0 commit comments

Comments
 (0)