HAL_ChibiOS: fixed asserts in AnalogIn driver

when building with --enable-asserts on boards with ADC1 and ADC3
(eg. Holybro H7 based boards) we were triggering asserts on bad ADC
index. In order to preserve the asserts (which are good for catching
errors) we need to ifdef the relevant calls
This commit is contained in:
Andrew Tridgell 2023-05-05 15:07:06 +10:00
parent a43680e882
commit ce703cbed7
2 changed files with 64 additions and 44 deletions

View File

@ -403,9 +403,13 @@ void AnalogIn::init()
#else #else
static_assert(sizeof(uint16_t) == sizeof(adcsample_t), "adcsample_t must be uint16_t"); static_assert(sizeof(uint16_t) == sizeof(adcsample_t), "adcsample_t must be uint16_t");
#endif #endif
for (uint8_t i=0; i<HAL_NUM_ANALOG_INPUTS; i++) { setup_adc(0);
setup_adc(i); #if defined(HAL_ANALOG2_PINS)
} setup_adc(1);
#endif
#if defined(HAL_ANALOG3_PINS)
setup_adc(2);
#endif
} }
void AnalogIn::setup_adc(uint8_t index) void AnalogIn::setup_adc(uint8_t index)
@ -623,27 +627,10 @@ void AnalogIn::read_adc(uint8_t index, uint32_t *val)
} }
/* /*
called at 1kHz read the data from an ADC index
*/ */
void AnalogIn::_timer_tick(void) void AnalogIn::timer_tick_adc(uint8_t index)
{ {
// read adc at 100Hz
uint32_t now = AP_HAL::micros();
uint32_t delta_t = now - _last_run;
if (delta_t < 10000) {
return;
}
_last_run = now;
// update power status flags
update_power_flags();
#if HAL_WITH_IO_MCU
// handle special inputs from IOMCU
_rssi_voltage = iomcu.get_vrssi_adc_count() * (VOLTAGE_SCALING * HAL_IOMCU_VRSSI_SCALAR);
#endif
for (uint8_t index=0; index < HAL_NUM_ANALOG_INPUTS; index++) {
const uint8_t num_grp_channels = get_num_grp_channels(index); const uint8_t num_grp_channels = get_num_grp_channels(index);
uint32_t buf_adc[num_grp_channels]; uint32_t buf_adc[num_grp_channels];
@ -685,6 +672,38 @@ void AnalogIn::_timer_tick(void)
} }
} }
/*
called at 1kHz
*/
void AnalogIn::_timer_tick(void)
{
// read adc at 100Hz
uint32_t now = AP_HAL::micros();
uint32_t delta_t = now - _last_run;
if (delta_t < 10000) {
return;
}
_last_run = now;
// update power status flags
update_power_flags();
#if HAL_WITH_IO_MCU
// handle special inputs from IOMCU
_rssi_voltage = iomcu.get_vrssi_adc_count() * (VOLTAGE_SCALING * HAL_IOMCU_VRSSI_SCALAR);
#endif
/*
update each of our ADCs
*/
timer_tick_adc(0);
#if defined(HAL_ANALOG2_PINS)
timer_tick_adc(1);
#endif
#if defined(HAL_ANALOG3_PINS)
timer_tick_adc(2);
#endif
#if HAL_WITH_IO_MCU #if HAL_WITH_IO_MCU
_servorail_voltage = iomcu.get_vservo_adc_count() * (VOLTAGE_SCALING * HAL_IOMCU_VSERVO_SCALAR); _servorail_voltage = iomcu.get_vservo_adc_count() * (VOLTAGE_SCALING * HAL_IOMCU_VSERVO_SCALAR);
#endif #endif

View File

@ -73,6 +73,7 @@ public:
void init() override; void init() override;
AP_HAL::AnalogSource* channel(int16_t pin) override; AP_HAL::AnalogSource* channel(int16_t pin) override;
void _timer_tick(void); void _timer_tick(void);
void timer_tick_adc(uint8_t index);
float board_voltage(void) override { return _board_voltage; } float board_voltage(void) override { return _board_voltage; }
float servorail_voltage(void) override { return _servorail_voltage; } float servorail_voltage(void) override { return _servorail_voltage; }
uint16_t power_status_flags(void) override { return _power_flags; } uint16_t power_status_flags(void) override { return _power_flags; }