diff --git a/cores/nRF5/HardwareSerial.h b/cores/nRF5/HardwareSerial.h index b3597e64..6785bcbf 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 diff --git a/cores/nRF5/Uart.cpp b/cores/nRF5/Uart.cpp index 289391c4..13c691e1 100644 --- a/cores/nRF5/Uart.cpp +++ b/cores/nRF5/Uart.cpp @@ -61,7 +61,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,11 +232,8 @@ 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 ); -#endif +//------------- Serial1 (or Serial in case of nRF52832) -------------// +Uart SERIAL_PORT_HARDWARE( NRF_UARTE0, UARTE0_UART0_IRQn, PIN_SERIAL1_RX, PIN_SERIAL1_TX ); extern "C" { @@ -244,11 +241,18 @@ extern "C" { SERIAL_PORT_HARDWARE.IrqHandler(); } +} -#ifdef SERIAL_PORT_HARDWARE1 +//------------- Serial2 -------------// +#if SERIAL_INTERFACES_COUNT >= 2 +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..42bd8d86 100644 --- a/cores/nRF5/Uart.h +++ b/cores/nRF5/Uart.h @@ -95,11 +95,6 @@ class Uart : public HardwareSerial #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 @@ -107,6 +102,6 @@ class Uart : public HardwareSerial extern Uart SERIAL_PORT_HARDWARE; -#ifdef SERIAL_PORT_HARDWARE1 -extern Uart SERIAL_PORT_HARDWARE1; +#if SERIAL_INTERFACES_COUNT >= 2 +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..a4671740 100644 --- a/variants/circuitplayground_nrf52840/variant.h +++ b/variants/circuitplayground_nrf52840/variant.h @@ -91,9 +91,10 @@ static const uint8_t A9 = PIN_A9 ; /* * Serial interfaces */ -// Serial -#define PIN_SERIAL_RX (0) -#define PIN_SERIAL_TX (1) +#define SERIAL_INTERFACES_COUNT 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..128e23b1 100644 --- a/variants/clue_nrf52840/variant.h +++ b/variants/clue_nrf52840/variant.h @@ -85,9 +85,10 @@ static const uint8_t A7 = PIN_A7 ; /* * Serial interfaces */ -// Serial -#define PIN_SERIAL_RX (0) -#define PIN_SERIAL_TX (1) +#define SERIAL_INTERFACES_COUNT 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..f690605b 100644 --- a/variants/feather_nrf52832/variant.h +++ b/variants/feather_nrf52832/variant.h @@ -87,9 +87,10 @@ static const uint8_t AREF = PIN_AREF; /* * Serial interfaces */ -// Serial -#define PIN_SERIAL_RX (8) -#define PIN_SERIAL_TX (6) +#define SERIAL_INTERFACES_COUNT 1 + +#define PIN_SERIAL1_RX (8) +#define PIN_SERIAL1_TX (6) /* * SPI Interfaces diff --git a/variants/feather_nrf52840_express/variant.h b/variants/feather_nrf52840_express/variant.h index 9cd3b64f..9ede786a 100644 --- a/variants/feather_nrf52840_express/variant.h +++ b/variants/feather_nrf52840_express/variant.h @@ -93,9 +93,10 @@ static const uint8_t AREF = PIN_AREF; /* * Serial interfaces */ -// Serial -#define PIN_SERIAL_RX (1) -#define PIN_SERIAL_TX (0) +#define SERIAL_INTERFACES_COUNT 1 + +#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..77b6a125 100644 --- a/variants/itsybitsy_nrf52840_express/variant.h +++ b/variants/itsybitsy_nrf52840_express/variant.h @@ -89,9 +89,10 @@ static const uint8_t A6 = PIN_A6 ; /* * Serial interfaces */ -// Serial -#define PIN_SERIAL_RX (0) -#define PIN_SERIAL_TX (1) +#define SERIAL_INTERFACES_COUNT 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..d57c1ca7 100644 --- a/variants/metro_nrf52840_express/variant.h +++ b/variants/metro_nrf52840_express/variant.h @@ -94,9 +94,10 @@ static const uint8_t AREF = PIN_AREF; /* * Serial interfaces */ -// Serial -#define PIN_SERIAL_RX (1) -#define PIN_SERIAL_TX (0) +#define SERIAL_INTERFACES_COUNT 1 + +#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..ebef682d 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,10 @@ 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 SERIAL_INTERFACES_COUNT 1 + +#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..4c273c58 100644 --- a/variants/pca10056/variant.h +++ b/variants/pca10056/variant.h @@ -94,11 +94,13 @@ static const uint8_t AREF = PIN_AREF; /* * Serial interfaces */ -#define HAVE_HWSERIAL2 +#define SERIAL_INTERFACES_COUNT 2 -#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