diff --git a/libraries/AP_IOMCU/iofirmware/rc.cpp b/libraries/AP_IOMCU/iofirmware/rc.cpp index 8bde774f1b..4cee86c774 100644 --- a/libraries/AP_IOMCU/iofirmware/rc.cpp +++ b/libraries/AP_IOMCU/iofirmware/rc.cpp @@ -61,6 +61,12 @@ static const SerialConfig dsm_cfg = { nullptr, // ctx }; +static enum { + RC_SEARCHING, + RC_DSM_PORT, + RC_SBUS_PORT +} rc_state; + /* init rcin on DSM USART1 */ @@ -95,16 +101,25 @@ void AP_IOMCU_FW::rcin_serial_update(void) uint8_t b[16]; uint32_t n; uint32_t now = AP_HAL::millis(); + auto &rc = AP::RC(); + + if (rc.should_search(now)) { + rc_state = RC_SEARCHING; + } // read from DSM port - if ((n = chnReadTimeout(&SD1, b, sizeof(b), TIME_IMMEDIATE)) > 0) { + if ((rc_state == RC_SEARCHING || rc_state == RC_DSM_PORT) && + (n = chnReadTimeout(&SD1, b, sizeof(b), TIME_IMMEDIATE)) > 0) { n = MIN(n, sizeof(b)); // don't mix two 115200 uarts if (sd3_config == 0) { rc_stats.num_dsm_bytes += n; for (uint8_t i=0; i 0) { + if ((rc_state == RC_SEARCHING || rc_state == RC_SBUS_PORT) && + (n = chnReadTimeout(&SD3, b, sizeof(b), TIME_IMMEDIATE)) > 0) { eventflags_t flags; if (sd3_config == 0 && ((flags = chEvtGetAndClearFlags(&sd3_listener)) & SD_PARITY_ERROR)) { rc_stats.sbus_error = flags; @@ -121,8 +137,11 @@ void AP_IOMCU_FW::rcin_serial_update(void) n = MIN(n, sizeof(b)); rc_stats.num_sbus_bytes += n; for (uint8_t i=0; i 2000 && (sd3_config==1 || !sbus_out_enabled)) { + if (rc_state == RC_SEARCHING && + now - rc_stats.last_good_ms > 2000 && (sd3_config==1 || !sbus_out_enabled)) { rc_stats.last_good_ms = now; sd3_config ^= 1; sdStop(&SD3);