AP_HAL: UARTDriver: Add new flow control option "FLOW_CONTROL_RTS_DE" for RS485 driver enable.

This commit is contained in:
Iampete1 2024-04-10 19:46:03 +01:00 committed by Andrew Tridgell
parent 0956b4f65d
commit d340f37678
2 changed files with 21 additions and 0 deletions

View File

@ -165,6 +165,20 @@ uint64_t AP_HAL::UARTDriver::receive_time_constraint_us(uint16_t nbytes)
return AP_HAL::micros64();
}
// Helper to check if flow control is enabled given the passed setting
bool AP_HAL::UARTDriver::flow_control_enabled(enum flow_control flow_control_setting) const
{
switch(flow_control_setting) {
case FLOW_CONTROL_ENABLE:
case FLOW_CONTROL_AUTO:
return true;
case FLOW_CONTROL_DISABLE:
case FLOW_CONTROL_RTS_DE:
break;
}
return false;
}
#if HAL_UART_STATS_ENABLED
// Take cumulative bytes and return the change since last call
uint32_t AP_HAL::UARTDriver::StatsTracker::ByteTracker::update(uint32_t bytes)

View File

@ -103,10 +103,14 @@ public:
FLOW_CONTROL_DISABLE=0,
FLOW_CONTROL_ENABLE=1,
FLOW_CONTROL_AUTO=2,
FLOW_CONTROL_RTS_DE=3, // RTS pin is used as a driver enable (used in RS-485)
};
virtual void set_flow_control(enum flow_control flow_control_setting) {};
virtual enum flow_control get_flow_control(void) { return FLOW_CONTROL_DISABLE; }
// Return true if flow control is currently enabled
bool flow_control_enabled() { return flow_control_enabled(get_flow_control()); }
virtual void configure_parity(uint8_t v){};
virtual void set_stop_bits(int n){};
@ -240,6 +244,9 @@ protected:
// discard incoming data on the port
virtual bool _discard_input(void) = 0;
// Helper to check if flow control is enabled given the passed setting
bool flow_control_enabled(enum flow_control flow_control_setting) const;
#if HAL_UART_STATS_ENABLED
// Getters for cumulative tx and rx counts
virtual uint32_t get_total_tx_bytes() const { return 0; }