Merge pull request #430 from adafruit/develop

follow up to #315
This commit is contained in:
Ha Thach authored and GitHub committed 2020-02-01 01:42:18 +07:00
commit 0757478e65
14 files changed
+76 -74

No files matched your search

+8 -1
View File
@@ -49,11 +49,13 @@
#ifdef NRF52832_XXAA
#define SERIAL_8N1 (UARTE_CONFIG_PARITY_Excluded << UARTE_CONFIG_PARITY_Pos)
#define SERIAL_8E1 (UARTE_CONFIG_PARITY_Included << UARTE_CONFIG_PARITY_Pos)
#elif NRF52840_XXAA
#elif defined(NRF52840_XXAA)
#define SERIAL_8N1 ((UARTE_CONFIG_STOP_One << UARTE_CONFIG_STOP_Pos) | (UARTE_CONFIG_PARITY_Excluded << UARTE_CONFIG_PARITY_Pos))
#define SERIAL_8N2 ((UARTE_CONFIG_STOP_Two << UARTE_CONFIG_STOP_Pos) | (UARTE_CONFIG_PARITY_Excluded << UARTE_CONFIG_PARITY_Pos))
#define SERIAL_8E1 ((UARTE_CONFIG_STOP_One << UARTE_CONFIG_STOP_Pos) | (UARTE_CONFIG_PARITY_Included << UARTE_CONFIG_PARITY_Pos))
#define SERIAL_8E2 ((UARTE_CONFIG_STOP_Two << UARTE_CONFIG_STOP_Pos) | (UARTE_CONFIG_PARITY_Included << UARTE_CONFIG_PARITY_Pos))
#else
#error Unsupported MCU
#endif
class HardwareSerial : public Stream
@@ -75,4 +77,9 @@ class HardwareSerial : public Stream
extern void serialEventRun(void) __attribute__((weak));
extern void serialEvent() __attribute__((weak));
#ifndef NRF52832_XXAA // 832 only has 1 UART for Serial
extern void serialEvent1() __attribute__((weak));
extern void serialEvent2() __attribute__((weak));
#endif
#endif
+24 -8
View File
@@ -25,6 +25,14 @@
void serialEventRun(void)
{
if (serialEvent && Serial.available() ) serialEvent();
#if defined(PIN_SERIAL1_RX) && defined(PIN_SERIAL1_TX)
if (serialEvent1 && Serial1.available() ) serialEvent1();
#endif
#if defined(PIN_SERIAL2_RX) && defined(PIN_SERIAL2_TX)
if (serialEvent2 && Serial2.available() ) serialEvent2();
#endif
}
Uart::Uart(NRF_UARTE_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _pinTX)
@@ -61,7 +69,7 @@ void Uart::setPins(uint8_t pin_rx, uint8_t pin_tx)
void Uart::begin(unsigned long baudrate)
{
begin(baudrate, (uint8_t)SERIAL_8N1);
begin(baudrate, (uint16_t)SERIAL_8N1);
}
void Uart::begin(unsigned long baudrate, uint16_t config)
@@ -232,10 +240,11 @@ size_t Uart::write(const uint8_t *buffer, size_t size)
return sent;
}
Uart SERIAL_PORT_HARDWARE( NRF_UARTE0, UARTE0_UART0_IRQn, PIN_SERIAL_RX, PIN_SERIAL_TX );
#ifdef SERIAL_PORT_HARDWARE1
Uart SERIAL_PORT_HARDWARE1( NRF_UARTE1, UARTE1_IRQn, PIN_SERIAL2_RX, PIN_SERIAL2_TX );
//------------- Serial1 (or Serial in case of nRF52832) -------------//
#ifdef NRF52832_XXAA
Uart Serial( NRF_UARTE0, UARTE0_UART0_IRQn, PIN_SERIAL_RX, PIN_SERIAL_TX );
#else
Uart Serial1( NRF_UARTE0, UARTE0_UART0_IRQn, PIN_SERIAL1_RX, PIN_SERIAL1_TX );
#endif
extern "C"
@@ -244,11 +253,18 @@ extern "C"
{
SERIAL_PORT_HARDWARE.IrqHandler();
}
}
#ifdef SERIAL_PORT_HARDWARE1
//------------- Serial2 -------------//
#if defined(PIN_SERIAL2_RX) && defined(PIN_SERIAL2_TX)
Uart Serial2( NRF_UARTE1, UARTE1_IRQn, PIN_SERIAL2_RX, PIN_SERIAL2_TX );
extern "C"
{
void UARTE1_IRQHandler()
{
SERIAL_PORT_HARDWARE1.IrqHandler();
Serial2.IrqHandler();
}
#endif
}
#endif
+7 -10
View File
@@ -89,24 +89,21 @@ class Uart : public HardwareSerial
//
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
// pins are NOT connected to anything by default.
#ifdef NRF52840_XXAA
#ifdef NRF52832_XXAA
#define SERIAL_PORT_MONITOR Serial
#define SERIAL_PORT_HARDWARE Serial
#else
#define SERIAL_PORT_MONITOR Serial
#define SERIAL_PORT_USBVIRTUAL Serial
#define SERIAL_PORT_HARDWARE Serial1
#define SERIAL_PORT_HARDWARE_OPEN Serial1
#ifdef HAVE_HWSERIAL2
#define SERIAL_PORT_HARDWARE1 Serial2
#define SERIAL_PORT_HARDWARE_OPEN1 Serial2
#endif
#else
#define SERIAL_PORT_MONITOR Serial
#define SERIAL_PORT_HARDWARE Serial
#endif
extern Uart SERIAL_PORT_HARDWARE;
#ifdef SERIAL_PORT_HARDWARE1
extern Uart SERIAL_PORT_HARDWARE1;
#if defined(PIN_SERIAL2_RX) && defined(PIN_SERIAL2_TX)
extern Uart Serial2;
#endif
+3 -12
View File
@@ -96,6 +96,9 @@ writeChannel KEYWORD2
# Constants (LITERAL1)
#######################################
INPUT_PULLDOWN LITERAL1
INPUT_PULLUP LITERAL1
INPUT_PULLUP_SENSE LITERAL1
INPUT_PULLDOWN_SENSE LITERAL1
PIN_A0 LITERAL1
PIN_A1 LITERAL1
@@ -107,17 +110,5 @@ PIN_A6 LITERAL1
PIN_A7 LITERAL1
PIN_AREF LITERAL1
PIN_NFC1 LITERAL1
PIN_NFC2 LITERAL1
PIN_SERIAL_RX LITERAL1
PIN_SERIAL_TX LITERAL1
PIN_SPI_MISO LITERAL1
PIN_SPI_MOSI LITERAL1
PIN_SPI_SCK LITERAL1
PIN_WIRE_SDA LITERAL1
PIN_WIRE_SCL LITERAL1
ISR_DEFERRED LITERAL1
@@ -313,7 +313,7 @@ void connect_callback(uint16_t conn_handle)
// Then schedule negotiation after a few seconds, we should not
// negotiate here since it increases chance to conflict with other
// on-going negotiation from central after connection
negoTimer.setID((void*) conn_handle);
negoTimer.setID((void*) ((uint32_t)conn_handle));
negoTimer.start();
tft.println("Connected");
@@ -91,9 +91,8 @@ static const uint8_t A9 = PIN_A9 ;
/*
* Serial interfaces
*/
// Serial
#define PIN_SERIAL_RX (0)
#define PIN_SERIAL_TX (1)
#define PIN_SERIAL1_RX (0)
#define PIN_SERIAL1_TX (1)
/*
* SPI Interfaces
+2 -3
View File
@@ -85,9 +85,8 @@ static const uint8_t A7 = PIN_A7 ;
/*
* Serial interfaces
*/
// Serial
#define PIN_SERIAL_RX (0)
#define PIN_SERIAL_TX (1)
#define PIN_SERIAL1_RX (0)
#define PIN_SERIAL1_TX (1)
/*
* SPI Interfaces
-1
View File
@@ -87,7 +87,6 @@ static const uint8_t AREF = PIN_AREF;
/*
* Serial interfaces
*/
// Serial
#define PIN_SERIAL_RX (8)
#define PIN_SERIAL_TX (6)
+2 -3
View File
@@ -93,9 +93,8 @@ static const uint8_t AREF = PIN_AREF;
/*
* Serial interfaces
*/
// Serial
#define PIN_SERIAL_RX (1)
#define PIN_SERIAL_TX (0)
#define PIN_SERIAL1_RX (1)
#define PIN_SERIAL1_TX (0)
/*
* SPI Interfaces
@@ -89,9 +89,8 @@ static const uint8_t A6 = PIN_A6 ;
/*
* Serial interfaces
*/
// Serial
#define PIN_SERIAL_RX (0)
#define PIN_SERIAL_TX (1)
#define PIN_SERIAL1_RX (0)
#define PIN_SERIAL1_TX (1)
/*
* SPI Interfaces
+2 -3
View File
@@ -94,9 +94,8 @@ static const uint8_t AREF = PIN_AREF;
/*
* Serial interfaces
*/
// Serial
#define PIN_SERIAL_RX (1)
#define PIN_SERIAL_TX (0)
#define PIN_SERIAL1_RX (1)
#define PIN_SERIAL1_TX (0)
/*
* SPI Interfaces
+17 -21
View File
@@ -91,23 +91,23 @@ static const uint8_t D19 = PIN_D4;
static const uint8_t D20 = PIN_D5;
// LEDs
#define LEDS_NUMBER 1
#define LED_PRIMARY_PIN _PINNUM(1, 12)
#define LED_STATE_ON 1
#define LED_PRIMARY_IDX 0
#define LED_RGB_RED_IDX 1
#define LED_RGB_GREEN_IDX 2
#define LED_RGB_BLUE_IDX 3
#define LEDS_NUMBER 1
#define LED_PRIMARY_PIN _PINNUM(1, 12)
#define LED_STATE_ON 1
#define LED_PRIMARY_IDX 0
#define LED_RGB_RED_IDX 1
#define LED_RGB_GREEN_IDX 2
#define LED_RGB_BLUE_IDX 3
#define LED_RGB_RED_PIN _PINNUM(0, 13)
#define LED_RGB_GREEN_PIN _PINNUM(0, 14)
#define LED_RGB_BLUE_PIN _PINNUM(0, 15)
#define BOARD_RGB_BRIGHTNESS 0x202020
#define LED_RGB_RED_PIN _PINNUM(0, 13)
#define LED_RGB_GREEN_PIN _PINNUM(0, 14)
#define LED_RGB_BLUE_PIN _PINNUM(0, 15)
#define BOARD_RGB_BRIGHTNESS 0x202020
static const uint8_t LED_BUILTIN = LED_PRIMARY_PIN;
static const uint8_t LED_RGB_RED = LED_RGB_RED_PIN;
static const uint8_t LED_RGB_GREEN = LED_RGB_GREEN_PIN;
static const uint8_t LED_RGB_BLUE = LED_RGB_BLUE_PIN;
static const uint8_t LED_BUILTIN = LED_PRIMARY_PIN;
static const uint8_t LED_RGB_RED = LED_RGB_RED_PIN;
static const uint8_t LED_RGB_GREEN = LED_RGB_GREEN_PIN;
static const uint8_t LED_RGB_BLUE = LED_RGB_BLUE_PIN;
// Buttons
#define BUTTONS_NUMBER 2
@@ -146,12 +146,8 @@ static const uint8_t A5 = PIN_A5 ;
/*
* Serial interfaces
*/
// Serial
#define PIN_SERIAL_RX PIN_D9
#define PIN_SERIAL_TX PIN_D10
#define PIN_SERIAL2_RX PIN_D5
#define PIN_SERIAL2_TX PIN_D6
//#define HAVE_HWSERIAL2 true // TODO: implement UARTE in Uart.cpp
#define PIN_SERIAL1_RX PIN_D9
#define PIN_SERIAL1_TX PIN_D10
/*
* SPI Interfaces
+4 -3
View File
@@ -94,11 +94,12 @@ static const uint8_t AREF = PIN_AREF;
/*
* Serial interfaces
*/
#define HAVE_HWSERIAL2
#define PIN_SERIAL_RX (33)
#define PIN_SERIAL_TX (34)
// Arduino Header D0, D1
#define PIN_SERIAL1_RX (33) // P1.01
#define PIN_SERIAL1_TX (34) // P1.02
// Connected to Jlink CDC
#define PIN_SERIAL2_RX (8)
#define PIN_SERIAL2_TX (6)
+2 -2
View File
@@ -74,8 +74,8 @@ extern "C"
// Bad things happen if the serial pins aren't defined. Instead
// define them with an invalid pin number
// Serial
#define PIN_SERIAL_RX (3)
#define PIN_SERIAL_TX (3)
#define PIN_SERIAL1_RX (3)
#define PIN_SERIAL1_TX (3)
#ifdef __cplusplus