From bd1f69fb76e67f543ba0081e3fdef28c3cb3da1a Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Thu, 21 May 2020 12:22:46 -0700 Subject: [PATCH] stm32_common:board_hw_rev_ver Support 16 Bit ADC --- .../stm/stm32_common/board_hw_info/board_hw_rev_ver.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/platforms/nuttx/src/px4/stm/stm32_common/board_hw_info/board_hw_rev_ver.c b/platforms/nuttx/src/px4/stm/stm32_common/board_hw_info/board_hw_rev_ver.c index 7dd0e76815..e6ed57e471 100644 --- a/platforms/nuttx/src/px4/stm/stm32_common/board_hw_info/board_hw_rev_ver.c +++ b/platforms/nuttx/src/px4/stm/stm32_common/board_hw_info/board_hw_rev_ver.c @@ -79,6 +79,14 @@ static char hw_info[] = HW_INFO_INIT; static int dn_to_ordinal(uint16_t dn) { + /* Table is scaled for 12, so if ADC is in 16 bit mode + * scale the result + */ + + if (px4_arch_adc_dn_fullcount() > (1 << 12)) { + + dn /= (px4_arch_adc_dn_fullcount() / (1 << 12)); + } const struct { uint16_t low; // High(n-1) + 1 @@ -204,6 +212,7 @@ static int read_id_dn(int *id, uint32_t gpio_drive, uint32_t gpio_sense, int adc if (px4_arch_adc_init(HW_REV_VER_ADC_BASE) == OK) { /* Read the value */ + for (unsigned av = 0; av < samples; av++) { dn = px4_arch_adc_sample(HW_REV_VER_ADC_BASE, adc_channel);