From 4ed0b03f35441b1ad568d7edd73d2f3d6c5f3aa5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 8 Jul 2021 16:35:58 +1000 Subject: [PATCH] HAL_ChibiOS: implement set_RTS/CTS_pin methods --- libraries/AP_HAL_ChibiOS/UARTDriver.cpp | 38 +++++++++++++++++++++++++ libraries/AP_HAL_ChibiOS/UARTDriver.h | 7 +++++ 2 files changed, 45 insertions(+) diff --git a/libraries/AP_HAL_ChibiOS/UARTDriver.cpp b/libraries/AP_HAL_ChibiOS/UARTDriver.cpp index a7141908a8..1446eab5d6 100644 --- a/libraries/AP_HAL_ChibiOS/UARTDriver.cpp +++ b/libraries/AP_HAL_ChibiOS/UARTDriver.cpp @@ -1699,6 +1699,44 @@ void UARTDriver::uart_info(ExpandingString &str) _last_stats_ms = now_ms; } +/* + software control of the CTS pin if available. Return false if + not available +*/ +bool UARTDriver::set_CTS_pin(bool high) +{ + if (_flow_control != FLOW_CONTROL_DISABLE) { + // CTS pin is being used + return false; + } + if (sdef.cts_line == 0) { + // we don't have a CTS pin on this UART + return false; + } + palSetLineMode(sdef.cts_line, 1); + palWriteLine(sdef.cts_line, high?1:0); + return true; +} + +/* + software control of the RTS pin if available. Return false if + not available +*/ +bool UARTDriver::set_RTS_pin(bool high) +{ + if (_flow_control != FLOW_CONTROL_DISABLE) { + // RTS pin is being used + return false; + } + if (sdef.rts_line == 0) { + // we don't have a RTS pin on this UART + return false; + } + palSetLineMode(sdef.rts_line, 1); + palWriteLine(sdef.rts_line, high?1:0); + return true; +} + #if HAL_USE_SERIAL_USB == TRUE /* initialise the USB bus, called from both UARTDriver and stdio for startup debug diff --git a/libraries/AP_HAL_ChibiOS/UARTDriver.h b/libraries/AP_HAL_ChibiOS/UARTDriver.h index 0124a98530..37e2924962 100644 --- a/libraries/AP_HAL_ChibiOS/UARTDriver.h +++ b/libraries/AP_HAL_ChibiOS/UARTDriver.h @@ -107,6 +107,13 @@ public: void configure_parity(uint8_t v) override; void set_stop_bits(int n) override; + /* + software control of the CTS/RTS pins if available. Return false if + not available + */ + bool set_RTS_pin(bool high) override; + bool set_CTS_pin(bool high) override; + /* return timestamp estimate in microseconds for when the start of a nbytes packet arrived on the uart. This should be treated as a