Skip to content

Commit 0757478

Browse files
authored
Merge pull request #430 from adafruit/develop
follow up to #315
2 parents b6bd051 + a00eb4f commit 0757478

File tree

14 files changed

+78
-76
lines changed

14 files changed

+78
-76
lines changed

cores/nRF5/HardwareSerial.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@
4949
#ifdef NRF52832_XXAA
5050
#define SERIAL_8N1 (UARTE_CONFIG_PARITY_Excluded << UARTE_CONFIG_PARITY_Pos)
5151
#define SERIAL_8E1 (UARTE_CONFIG_PARITY_Included << UARTE_CONFIG_PARITY_Pos)
52-
#elif NRF52840_XXAA
52+
#elif defined(NRF52840_XXAA)
5353
#define SERIAL_8N1 ((UARTE_CONFIG_STOP_One << UARTE_CONFIG_STOP_Pos) | (UARTE_CONFIG_PARITY_Excluded << UARTE_CONFIG_PARITY_Pos))
5454
#define SERIAL_8N2 ((UARTE_CONFIG_STOP_Two << UARTE_CONFIG_STOP_Pos) | (UARTE_CONFIG_PARITY_Excluded << UARTE_CONFIG_PARITY_Pos))
5555
#define SERIAL_8E1 ((UARTE_CONFIG_STOP_One << UARTE_CONFIG_STOP_Pos) | (UARTE_CONFIG_PARITY_Included << UARTE_CONFIG_PARITY_Pos))
5656
#define SERIAL_8E2 ((UARTE_CONFIG_STOP_Two << UARTE_CONFIG_STOP_Pos) | (UARTE_CONFIG_PARITY_Included << UARTE_CONFIG_PARITY_Pos))
57+
#else
58+
#error Unsupported MCU
5759
#endif
5860

5961
class HardwareSerial : public Stream
@@ -75,4 +77,9 @@ class HardwareSerial : public Stream
7577
extern void serialEventRun(void) __attribute__((weak));
7678
extern void serialEvent() __attribute__((weak));
7779

80+
#ifndef NRF52832_XXAA // 832 only has 1 UART for Serial
81+
extern void serialEvent1() __attribute__((weak));
82+
extern void serialEvent2() __attribute__((weak));
83+
#endif
84+
7885
#endif

cores/nRF5/Uart.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
void serialEventRun(void)
2626
{
2727
if (serialEvent && Serial.available() ) serialEvent();
28+
29+
#if defined(PIN_SERIAL1_RX) && defined(PIN_SERIAL1_TX)
30+
if (serialEvent1 && Serial1.available() ) serialEvent1();
31+
#endif
32+
33+
#if defined(PIN_SERIAL2_RX) && defined(PIN_SERIAL2_TX)
34+
if (serialEvent2 && Serial2.available() ) serialEvent2();
35+
#endif
2836
}
2937

3038
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)
6169

6270
void Uart::begin(unsigned long baudrate)
6371
{
64-
begin(baudrate, (uint8_t)SERIAL_8N1);
72+
begin(baudrate, (uint16_t)SERIAL_8N1);
6573
}
6674

6775
void Uart::begin(unsigned long baudrate, uint16_t config)
@@ -232,10 +240,11 @@ size_t Uart::write(const uint8_t *buffer, size_t size)
232240
return sent;
233241
}
234242

235-
Uart SERIAL_PORT_HARDWARE( NRF_UARTE0, UARTE0_UART0_IRQn, PIN_SERIAL_RX, PIN_SERIAL_TX );
236-
237-
#ifdef SERIAL_PORT_HARDWARE1
238-
Uart SERIAL_PORT_HARDWARE1( NRF_UARTE1, UARTE1_IRQn, PIN_SERIAL2_RX, PIN_SERIAL2_TX );
243+
//------------- Serial1 (or Serial in case of nRF52832) -------------//
244+
#ifdef NRF52832_XXAA
245+
Uart Serial( NRF_UARTE0, UARTE0_UART0_IRQn, PIN_SERIAL_RX, PIN_SERIAL_TX );
246+
#else
247+
Uart Serial1( NRF_UARTE0, UARTE0_UART0_IRQn, PIN_SERIAL1_RX, PIN_SERIAL1_TX );
239248
#endif
240249

241250
extern "C"
@@ -244,11 +253,18 @@ extern "C"
244253
{
245254
SERIAL_PORT_HARDWARE.IrqHandler();
246255
}
256+
}
247257

248-
#ifdef SERIAL_PORT_HARDWARE1
258+
//------------- Serial2 -------------//
259+
#if defined(PIN_SERIAL2_RX) && defined(PIN_SERIAL2_TX)
260+
Uart Serial2( NRF_UARTE1, UARTE1_IRQn, PIN_SERIAL2_RX, PIN_SERIAL2_TX );
261+
262+
extern "C"
263+
{
249264
void UARTE1_IRQHandler()
250265
{
251-
SERIAL_PORT_HARDWARE1.IrqHandler();
266+
Serial2.IrqHandler();
252267
}
253-
#endif
254268
}
269+
#endif
270+

cores/nRF5/Uart.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,21 @@ class Uart : public HardwareSerial
8989
//
9090
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
9191
// pins are NOT connected to anything by default.
92-
#ifdef NRF52840_XXAA
92+
#ifdef NRF52832_XXAA
93+
#define SERIAL_PORT_MONITOR Serial
94+
#define SERIAL_PORT_HARDWARE Serial
95+
96+
#else
9397
#define SERIAL_PORT_MONITOR Serial
9498
#define SERIAL_PORT_USBVIRTUAL Serial
9599

96100
#define SERIAL_PORT_HARDWARE Serial1
97101
#define SERIAL_PORT_HARDWARE_OPEN Serial1
98102

99-
#ifdef HAVE_HWSERIAL2
100-
#define SERIAL_PORT_HARDWARE1 Serial2
101-
#define SERIAL_PORT_HARDWARE_OPEN1 Serial2
102-
#endif
103-
#else
104-
#define SERIAL_PORT_MONITOR Serial
105-
#define SERIAL_PORT_HARDWARE Serial
106103
#endif
107104

108105
extern Uart SERIAL_PORT_HARDWARE;
109106

110-
#ifdef SERIAL_PORT_HARDWARE1
111-
extern Uart SERIAL_PORT_HARDWARE1;
107+
#if defined(PIN_SERIAL2_RX) && defined(PIN_SERIAL2_TX)
108+
extern Uart Serial2;
112109
#endif

keywords.txt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ writeChannel KEYWORD2
9696
# Constants (LITERAL1)
9797
#######################################
9898
INPUT_PULLDOWN LITERAL1
99+
INPUT_PULLUP LITERAL1
100+
INPUT_PULLUP_SENSE LITERAL1
101+
INPUT_PULLDOWN_SENSE LITERAL1
99102

100103
PIN_A0 LITERAL1
101104
PIN_A1 LITERAL1
@@ -107,17 +110,5 @@ PIN_A6 LITERAL1
107110
PIN_A7 LITERAL1
108111

109112
PIN_AREF LITERAL1
110-
PIN_NFC1 LITERAL1
111-
PIN_NFC2 LITERAL1
112-
113-
PIN_SERIAL_RX LITERAL1
114-
PIN_SERIAL_TX LITERAL1
115-
116-
PIN_SPI_MISO LITERAL1
117-
PIN_SPI_MOSI LITERAL1
118-
PIN_SPI_SCK LITERAL1
119-
120-
PIN_WIRE_SDA LITERAL1
121-
PIN_WIRE_SCL LITERAL1
122113

123114
ISR_DEFERRED LITERAL1

libraries/Bluefruit52Lib/examples/Peripheral/image_upload/image_upload.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ void connect_callback(uint16_t conn_handle)
313313
// Then schedule negotiation after a few seconds, we should not
314314
// negotiate here since it increases chance to conflict with other
315315
// on-going negotiation from central after connection
316-
negoTimer.setID((void*) conn_handle);
316+
negoTimer.setID((void*) ((uint32_t)conn_handle));
317317
negoTimer.start();
318318

319319
tft.println("Connected");

variants/circuitplayground_nrf52840/variant.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ static const uint8_t A9 = PIN_A9 ;
9191
/*
9292
* Serial interfaces
9393
*/
94-
// Serial
95-
#define PIN_SERIAL_RX (0)
96-
#define PIN_SERIAL_TX (1)
94+
#define PIN_SERIAL1_RX (0)
95+
#define PIN_SERIAL1_TX (1)
9796

9897
/*
9998
* SPI Interfaces

variants/clue_nrf52840/variant.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ static const uint8_t A7 = PIN_A7 ;
8585
/*
8686
* Serial interfaces
8787
*/
88-
// Serial
89-
#define PIN_SERIAL_RX (0)
90-
#define PIN_SERIAL_TX (1)
88+
#define PIN_SERIAL1_RX (0)
89+
#define PIN_SERIAL1_TX (1)
9190

9291
/*
9392
* SPI Interfaces

variants/feather_nrf52832/variant.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ static const uint8_t AREF = PIN_AREF;
8787
/*
8888
* Serial interfaces
8989
*/
90-
// Serial
9190
#define PIN_SERIAL_RX (8)
9291
#define PIN_SERIAL_TX (6)
9392

variants/feather_nrf52840_express/variant.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,8 @@ static const uint8_t AREF = PIN_AREF;
9393
/*
9494
* Serial interfaces
9595
*/
96-
// Serial
97-
#define PIN_SERIAL_RX (1)
98-
#define PIN_SERIAL_TX (0)
96+
#define PIN_SERIAL1_RX (1)
97+
#define PIN_SERIAL1_TX (0)
9998

10099
/*
101100
* SPI Interfaces

variants/itsybitsy_nrf52840_express/variant.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@ static const uint8_t A6 = PIN_A6 ;
8989
/*
9090
* Serial interfaces
9191
*/
92-
// Serial
93-
#define PIN_SERIAL_RX (0)
94-
#define PIN_SERIAL_TX (1)
92+
#define PIN_SERIAL1_RX (0)
93+
#define PIN_SERIAL1_TX (1)
9594

9695
/*
9796
* SPI Interfaces

0 commit comments

Comments
 (0)