Commit d887d064 authored by Cédric / Drix's avatar Cédric / Drix Committed by Sandeep Mistry

Custom I2C/SPI/UART pins for generic variants (#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).
parent 10fd652d
...@@ -41,6 +41,22 @@ Uart::Uart(NRF_UART_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _pi ...@@ -41,6 +41,22 @@ Uart::Uart(NRF_UART_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _pi
uc_hwFlow = 1; uc_hwFlow = 1;
} }
#ifdef ARDUINO_GENERIC
void Uart::setPins(uint8_t _pinRX, uint8_t _pinTX)
{
uc_pinRX = g_ADigitalPinMap[_pinRX];
uc_pinTX = g_ADigitalPinMap[_pinTX];
}
void Uart::setPins(uint8_t _pinRX, uint8_t _pinTX, uint8_t _pinCTS, uint8_t _pinRTS)
{
uc_pinRX = g_ADigitalPinMap[_pinRX];
uc_pinTX = g_ADigitalPinMap[_pinTX];
uc_pinCTS = g_ADigitalPinMap[_pinCTS];
uc_pinRTS = g_ADigitalPinMap[_pinRTS];
}
#endif // ARDUINO_GENERIC
void Uart::begin(unsigned long baudrate) void Uart::begin(unsigned long baudrate)
{ {
begin(baudrate, (uint8_t)SERIAL_8N1); begin(baudrate, (uint8_t)SERIAL_8N1);
......
...@@ -31,6 +31,10 @@ class Uart : public HardwareSerial ...@@ -31,6 +31,10 @@ class Uart : public HardwareSerial
public: public:
Uart(NRF_UART_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _pinTX); Uart(NRF_UART_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _pinTX);
Uart(NRF_UART_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _pinTX, uint8_t _pinCTS, uint8_t _pinRTS ); Uart(NRF_UART_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _pinTX, uint8_t _pinCTS, uint8_t _pinRTS );
#ifdef ARDUINO_GENERIC
void setPins(uint8_t _pinRX, uint8_t _pinTX);
void setPins(uint8_t _pinRX, uint8_t _pinTX, uint8_t _pinCTS, uint8_t _pinRTS);
#endif // ARDUINO_GENERIC
void begin(unsigned long baudRate); void begin(unsigned long baudRate);
void begin(unsigned long baudrate, uint16_t config); void begin(unsigned long baudrate, uint16_t config);
void end(); void end();
......
...@@ -44,6 +44,15 @@ SPIClass::SPIClass(NRF_SPI_Type *p_spi, uint8_t uc_pinMISO, uint8_t uc_pinSCK, u ...@@ -44,6 +44,15 @@ SPIClass::SPIClass(NRF_SPI_Type *p_spi, uint8_t uc_pinMISO, uint8_t uc_pinSCK, u
_bitOrder = SPI_CONFIG_ORDER_MsbFirst; _bitOrder = SPI_CONFIG_ORDER_MsbFirst;
} }
#ifdef ARDUINO_GENERIC
void SPIClass::setPins(uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI)
{
_uc_pinMiso = g_ADigitalPinMap[uc_pinMISO];
_uc_pinSCK = g_ADigitalPinMap[uc_pinSCK];
_uc_pinMosi = g_ADigitalPinMap[uc_pinMOSI];
}
#endif // ARDUINO_GENERIC
void SPIClass::begin() void SPIClass::begin()
{ {
init(); init();
......
...@@ -100,6 +100,9 @@ class SPIClass { ...@@ -100,6 +100,9 @@ class SPIClass {
void attachInterrupt(); void attachInterrupt();
void detachInterrupt(); void detachInterrupt();
#ifdef ARDUINO_GENERIC
void setPins(uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI);
#endif // ARDUINO_GENERIC
void begin(); void begin();
void end(); void end();
...@@ -152,4 +155,4 @@ extern SPIClass SPI1; ...@@ -152,4 +155,4 @@ extern SPIClass SPI1;
#define SPI_CLOCK_DIV128 128 #define SPI_CLOCK_DIV128 128
#endif #endif
#endif #endif
\ No newline at end of file
...@@ -39,6 +39,9 @@ class TwoWire : public Stream ...@@ -39,6 +39,9 @@ class TwoWire : public Stream
#else #else
TwoWire(NRF_TWI_Type * p_twi, uint8_t pinSDA, uint8_t pinSCL); TwoWire(NRF_TWI_Type * p_twi, uint8_t pinSDA, uint8_t pinSCL);
#endif #endif
#ifdef ARDUINO_GENERIC
void setPins(uint8_t pinSDA, uint8_t pinSCL);
#endif // ARDUINO_GENERIC
void begin(); void begin();
#ifdef NRF52 #ifdef NRF52
void begin(uint8_t); void begin(uint8_t);
......
...@@ -39,6 +39,14 @@ TwoWire::TwoWire(NRF_TWI_Type * p_twi, uint8_t pinSDA, uint8_t pinSCL) ...@@ -39,6 +39,14 @@ TwoWire::TwoWire(NRF_TWI_Type * p_twi, uint8_t pinSDA, uint8_t pinSCL)
this->suspended = false; this->suspended = false;
} }
#ifdef ARDUINO_GENERIC
void TwoWire::setPins(uint8_t pinSDA, uint8_t pinSCL)
{
this->_uc_pinSDA = g_ADigitalPinMap[pinSDA];
this->_uc_pinSCL = g_ADigitalPinMap[pinSCL];
}
#endif // ARDUINO_GENERIC
void TwoWire::begin(void) { void TwoWire::begin(void) {
//Master Mode //Master Mode
master = true; master = true;
......
...@@ -39,6 +39,14 @@ TwoWire::TwoWire(NRF_TWIM_Type * p_twim, NRF_TWIS_Type * p_twis, IRQn_Type IRQn, ...@@ -39,6 +39,14 @@ TwoWire::TwoWire(NRF_TWIM_Type * p_twim, NRF_TWIS_Type * p_twis, IRQn_Type IRQn,
transmissionBegun = false; transmissionBegun = false;
} }
#ifdef ARDUINO_GENERIC
void TwoWire::setPins(uint8_t pinSDA, uint8_t pinSCL)
{
this->_uc_pinSDA = g_ADigitalPinMap[pinSDA];
this->_uc_pinSCL = g_ADigitalPinMap[pinSCL];
}
#endif // ARDUINO_GENERIC
void TwoWire::begin(void) { void TwoWire::begin(void) {
//Master Mode //Master Mode
master = true; master = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment