diff --git a/cores/nRF5/HardwareSerial.h b/cores/nRF5/HardwareSerial.h index b3597e64..50bb338a 100644 --- a/cores/nRF5/HardwareSerial.h +++ b/cores/nRF5/HardwareSerial.h @@ -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 diff --git a/cores/nRF5/Uart.cpp b/cores/nRF5/Uart.cpp index 289391c4..e96959ed 100644 --- a/cores/nRF5/Uart.cpp +++ b/cores/nRF5/Uart.cpp @@ -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 + diff --git a/cores/nRF5/Uart.h b/cores/nRF5/Uart.h index d889aa25..a0003411 100644 --- a/cores/nRF5/Uart.h +++ b/cores/nRF5/Uart.h @@ -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 diff --git a/keywords.txt b/keywords.txt index c0c9e870..bf24cb91 100644 --- a/keywords.txt +++ b/keywords.txt @@ -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 diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/image_upload/image_upload.ino b/libraries/Bluefruit52Lib/examples/Peripheral/image_upload/image_upload.ino index 99220d4e..2a62056f 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/image_upload/image_upload.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/image_upload/image_upload.ino @@ -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"); diff --git a/variants/circuitplayground_nrf52840/variant.h b/variants/circuitplayground_nrf52840/variant.h index f85d41ee..be0fd64e 100644 --- a/variants/circuitplayground_nrf52840/variant.h +++ b/variants/circuitplayground_nrf52840/variant.h @@ -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 diff --git a/variants/clue_nrf52840/variant.h b/variants/clue_nrf52840/variant.h index a64710b6..a6fe740f 100644 --- a/variants/clue_nrf52840/variant.h +++ b/variants/clue_nrf52840/variant.h @@ -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 diff --git a/variants/feather_nrf52832/variant.h b/variants/feather_nrf52832/variant.h index 25c9a6c5..24b16b73 100644 --- a/variants/feather_nrf52832/variant.h +++ b/variants/feather_nrf52832/variant.h @@ -87,7 +87,6 @@ static const uint8_t AREF = PIN_AREF; /* * Serial interfaces */ -// Serial #define PIN_SERIAL_RX (8) #define PIN_SERIAL_TX (6) diff --git a/variants/feather_nrf52840_express/variant.h b/variants/feather_nrf52840_express/variant.h index 9cd3b64f..ea47c4ea 100644 --- a/variants/feather_nrf52840_express/variant.h +++ b/variants/feather_nrf52840_express/variant.h @@ -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 diff --git a/variants/itsybitsy_nrf52840_express/variant.h b/variants/itsybitsy_nrf52840_express/variant.h index 56c90b32..f86f5259 100644 --- a/variants/itsybitsy_nrf52840_express/variant.h +++ b/variants/itsybitsy_nrf52840_express/variant.h @@ -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 diff --git a/variants/metro_nrf52840_express/variant.h b/variants/metro_nrf52840_express/variant.h index 9fdf407a..2a602f3b 100644 --- a/variants/metro_nrf52840_express/variant.h +++ b/variants/metro_nrf52840_express/variant.h @@ -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 diff --git a/variants/particle_xenon/variant.h b/variants/particle_xenon/variant.h index 2c3d5068..ae273eeb 100644 --- a/variants/particle_xenon/variant.h +++ b/variants/particle_xenon/variant.h @@ -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 diff --git a/variants/pca10056/variant.h b/variants/pca10056/variant.h index b8802995..0dd13c0a 100644 --- a/variants/pca10056/variant.h +++ b/variants/pca10056/variant.h @@ -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) diff --git a/variants/raytac_mdbt50q_rx/variant.h b/variants/raytac_mdbt50q_rx/variant.h index 097f83e0..0ee7fd1b 100644 --- a/variants/raytac_mdbt50q_rx/variant.h +++ b/variants/raytac_mdbt50q_rx/variant.h @@ -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