From 7e897c16c02ba09f986162c02e8870a75003036a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 5 May 2018 18:54:12 +1000 Subject: [PATCH] HAL_ChibiOS: maintain rcout state beyond BRD_PWM_COUNT allow channels beyond BRD_PWM_COUNT to be sent over SBUS or DShot distribution --- libraries/AP_HAL_ChibiOS/RCOutput.cpp | 36 ++++++++++++++------------- libraries/AP_HAL_ChibiOS/RCOutput.h | 16 +++++++----- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/RCOutput.cpp b/libraries/AP_HAL_ChibiOS/RCOutput.cpp index 5625a58a12..db49169284 100644 --- a/libraries/AP_HAL_ChibiOS/RCOutput.cpp +++ b/libraries/AP_HAL_ChibiOS/RCOutput.cpp @@ -59,7 +59,7 @@ void RCOutput::init() group.chan[j] = CHAN_DISABLED; } if (group.chan[j] != CHAN_DISABLED) { - total_channels = MAX(total_channels, group.chan[j]+1); + num_fmu_channels = MAX(num_fmu_channels, group.chan[j]+1); group.ch_mask |= (1U<= total_channels) { + if (chan >= max_channels) { return 0; } #if HAL_WITH_IO_MCU @@ -260,7 +259,7 @@ uint16_t RCOutput::get_freq(uint8_t chan) void RCOutput::enable_ch(uint8_t chan) { - if (chan >= total_channels) { + if (chan >= max_channels) { return; } if (chan < chan_offset) { @@ -280,7 +279,7 @@ void RCOutput::enable_ch(uint8_t chan) void RCOutput::disable_ch(uint8_t chan) { - if (chan >= total_channels) { + if (chan >= max_channels) { return; } if (chan < chan_offset) { @@ -301,7 +300,7 @@ void RCOutput::disable_ch(uint8_t chan) void RCOutput::write(uint8_t chan, uint16_t period_us) { - if (chan >= total_channels) { + if (chan >= max_channels) { return; } last_sent[chan] = period_us; @@ -330,9 +329,12 @@ void RCOutput::write(uint8_t chan, uint16_t period_us) chan -= chan_offset; period[chan] = period_us; - num_channels = MAX(chan+1, num_channels); - if (!corked) { - push_local(); + + if (chan < num_fmu_channels) { + active_fmu_channels = MAX(chan+1, active_fmu_channels); + if (!corked) { + push_local(); + } } } @@ -341,10 +343,10 @@ void RCOutput::write(uint8_t chan, uint16_t period_us) */ void RCOutput::push_local(void) { - if (num_channels == 0) { + if (active_fmu_channels == 0) { return; } - uint16_t outmask = (1U<= total_channels) { + if (chan >= max_channels) { return 0; } #if HAL_WITH_IO_MCU @@ -434,8 +436,8 @@ uint16_t RCOutput::read(uint8_t chan) void RCOutput::read(uint16_t* period_us, uint8_t len) { - if (len > total_channels) { - len = total_channels; + if (len > max_channels) { + len = max_channels; } #if HAL_WITH_IO_MCU for (uint8_t i=0; i= total_channels) { + if (chan >= max_channels) { return 0; } return last_sent[chan]; @@ -461,8 +463,8 @@ uint16_t RCOutput::read_last_sent(uint8_t chan) void RCOutput::read_last_sent(uint16_t* period_us, uint8_t len) { - if (len > total_channels) { - len = total_channels; + if (len > max_channels) { + len = max_channels; } for (uint8_t i=0; i