Skip to content

Commit f8e8a7b

Browse files
authored
Updating LoRa board pins and UART hw flow. (#499)
* Added missing SERIAL2 and LoRa module GIO pins. * Added support for enabling UART CTS and RTS pins.
1 parent 5a0d67f commit f8e8a7b

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

cores/rp2040/SerialUART.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,39 @@ bool SerialUART::setTX(pin_size_t pin) {
6565
return false;
6666
}
6767

68+
bool SerialUART::setRTS(pin_size_t pin) {
69+
constexpr uint32_t valid[2] = { __bitset({3, 15, 19}) /* UART0 */,
70+
__bitset({7, 11, 23, 27}) /* UART1 */
71+
};
72+
if ((!_running) && ((1 << pin) & valid[uart_get_index(_uart)])) {
73+
_rts = pin;
74+
return true;
75+
}
76+
77+
if (_running) {
78+
panic("FATAL: Attempting to set Serial%d.RTS while running", uart_get_index(_uart) + 1);
79+
} else {
80+
panic("FATAL: Attempting to set Serial%d.RTS to illegal pin %d", uart_get_index(_uart) + 1, pin);
81+
}
82+
return false;
83+
}
84+
85+
bool SerialUART::setCTS(pin_size_t pin) {
86+
constexpr uint32_t valid[2] = { __bitset({2, 14, 18}) /* UART0 */,
87+
__bitset({6, 10, 22, 26}) /* UART1 */
88+
};
89+
if ((!_running) && ((1 << pin) & valid[uart_get_index(_uart)])) {
90+
_cts = pin;
91+
return true;
92+
}
93+
94+
if (_running) {
95+
panic("FATAL: Attempting to set Serial%d.CTS while running", uart_get_index(_uart) + 1);
96+
} else {
97+
panic("FATAL: Attempting to set Serial%d.CTS to illegal pin %d", uart_get_index(_uart) + 1, pin);
98+
}
99+
return false;
100+
}
68101
bool SerialUART::setPollingMode(bool mode) {
69102
if (_running) {
70103
return false;
@@ -85,6 +118,8 @@ SerialUART::SerialUART(uart_inst_t *uart, pin_size_t tx, pin_size_t rx) {
85118
_uart = uart;
86119
_tx = tx;
87120
_rx = rx;
121+
_rts = UART_PIN_NOT_DEFINED;
122+
_cts = UART_PIN_NOT_DEFINED;
88123
mutex_init(&_mutex);
89124
}
90125

@@ -133,6 +168,13 @@ void SerialUART::begin(unsigned long baud, uint16_t config) {
133168
uart_set_format(_uart, bits, stop, parity);
134169
gpio_set_function(_tx, GPIO_FUNC_UART);
135170
gpio_set_function(_rx, GPIO_FUNC_UART);
171+
if (_rts != UART_PIN_NOT_DEFINED) {
172+
gpio_set_function(_rts, GPIO_FUNC_UART);
173+
}
174+
if (_cts != UART_PIN_NOT_DEFINED) {
175+
gpio_set_function(_cts, GPIO_FUNC_UART);
176+
}
177+
uart_set_hw_flow(_uart, _rts != UART_PIN_NOT_DEFINED, _cts != UART_PIN_NOT_DEFINED);
136178
_writer = 0;
137179
_reader = 0;
138180

cores/rp2040/SerialUART.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@
2828

2929
extern "C" typedef struct uart_inst uart_inst_t;
3030

31+
#define UART_PIN_NOT_DEFINED (255u)
3132
class SerialUART : public HardwareSerial {
3233
public:
3334
SerialUART(uart_inst_t *uart, pin_size_t tx, pin_size_t rx);
3435

3536
// Select the pinout. Call before .begin()
3637
bool setRX(pin_size_t pin);
3738
bool setTX(pin_size_t pin);
39+
bool setRTS(pin_size_t pin);
40+
bool setCTS(pin_size_t pin);
3841
bool setPinout(pin_size_t tx, pin_size_t rx) {
3942
bool ret = setRX(rx);
4043
ret &= setTX(tx);
@@ -66,6 +69,7 @@ class SerialUART : public HardwareSerial {
6669
bool _running = false;
6770
uart_inst_t *_uart;
6871
pin_size_t _tx, _rx;
72+
pin_size_t _rts, _cts;
6973
int _baud;
7074
mutex_t _mutex;
7175
bool _polling = false;

docs/pins.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Serial1 (UART0), Serial2 (UART1)
2626
2727
::setRX(pin)
2828
::setTX(pin)
29+
::setRTS(pin)
30+
::setCTS(pin)
2931
3032
SPI (SPI0), SPI1 (SPI1)
3133
-----------------------
@@ -58,4 +60,3 @@ it use a non-default pinout with a simple call
5860
SPI.setCS(5);
5961
SD.begin(5);
6062
}
61-

variants/challenger_2040_lora/pins_arduino.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
#define PIN_SPI1_MOSI (11u)
2525
#define PIN_SPI1_SCK (10u)
2626
#define PIN_SPI1_SS (9u)
27+
#define RFM95W_SS (9u)
28+
#define RFM95W_DIO0 (14u)
29+
#define RFM95W_DIO1 (15u)
30+
#define RFM95W_DIO2 (18u)
31+
#define RFM95W_RST (13u)
32+
#define RFM95W_SPI SPI1
2733

2834
// Wire
2935
#define PIN_WIRE0_SDA (0u)
@@ -32,6 +38,8 @@
3238
// Not pinned out
3339
#define PIN_WIRE1_SDA (31u)
3440
#define PIN_WIRE1_SCL (31u)
41+
#define PIN_SERIAL2_RX (31u)
42+
#define PIN_SERIAL2_TX (31u)
3543

3644
#define SERIAL_HOWMANY (1u)
3745
#define SPI_HOWMANY (2u)

0 commit comments

Comments
 (0)