From ba3cdf74b5d6acf37ff1bc2109d99fcd98e2d55e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 8 Jan 2018 18:12:21 +1100 Subject: [PATCH] HAL_Chibios: optional ADC debugging this debugging capability is very useful on board bringup. It outputs the first 6 analog channels as an AP_ADC MAVLink message --- libraries/AP_HAL_ChibiOS/AnalogIn.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libraries/AP_HAL_ChibiOS/AnalogIn.cpp b/libraries/AP_HAL_ChibiOS/AnalogIn.cpp index 11a1ad0f75..d4d29f8bfb 100644 --- a/libraries/AP_HAL_ChibiOS/AnalogIn.cpp +++ b/libraries/AP_HAL_ChibiOS/AnalogIn.cpp @@ -23,6 +23,13 @@ extern AP_IOMCU iomcu; #endif +#ifndef CHIBIOS_ADC_MAVLINK_DEBUG +// this allows the first 6 analog channels to be reported by mavlink for debugging purposes +#define CHIBIOS_ADC_MAVLINK_DEBUG 0 +#endif + +#include + #define ANLOGIN_DEBUGGING 0 // base voltage scaling for 12 bit 3.3V ADC @@ -274,6 +281,18 @@ void AnalogIn::_timer_tick(void) // now handle special inputs from IOMCU _servorail_voltage = iomcu.get_vservo(); #endif + +#if CHIBIOS_ADC_MAVLINK_DEBUG + static uint8_t count; + if (AP_HAL::millis() > 5000 && count++ == 10) { + count = 0; + uint16_t adc[6] {}; + for (uint8_t i=0; i < ADC_GRP1_NUM_CHANNELS; i++) { + adc[i] = buf_adc[i]; + } + mavlink_msg_ap_adc_send(MAVLINK_COMM_0, adc[0], adc[1], adc[2], adc[3], adc[4], adc[5]); + } +#endif } AP_HAL::AnalogSource* AnalogIn::channel(int16_t pin)