diff --git a/libraries/AP_HAL_ChibiOS/UARTDriver.cpp b/libraries/AP_HAL_ChibiOS/UARTDriver.cpp index 430e70a0bc..888f9a6671 100644 --- a/libraries/AP_HAL_ChibiOS/UARTDriver.cpp +++ b/libraries/AP_HAL_ChibiOS/UARTDriver.cpp @@ -564,6 +564,24 @@ uint32_t UARTDriver::txspace() return _writebuf.space(); } +bool UARTDriver::discard_input() +{ + if (lock_read_key != 0 || _uart_owner_thd != chThdGetSelfX()){ + return false; + } + if (!_initialised) { + return false; + } + + _readbuf.empty(); + + if (!_rts_is_active) { + update_rts_line(); + } + + return true; +} + int16_t UARTDriver::read() { if (lock_read_key != 0 || _uart_owner_thd != chThdGetSelfX()){ diff --git a/libraries/AP_HAL_ChibiOS/UARTDriver.h b/libraries/AP_HAL_ChibiOS/UARTDriver.h index 63832b051d..7ebf4d5d02 100644 --- a/libraries/AP_HAL_ChibiOS/UARTDriver.h +++ b/libraries/AP_HAL_ChibiOS/UARTDriver.h @@ -47,6 +47,8 @@ public: int16_t read_locked(uint32_t key) override; void _timer_tick(void) override; + bool discard_input() override; + size_t write(uint8_t c) override; size_t write(const uint8_t *buffer, size_t size) override;