From 5d8ca7c9445dac3d8bb52eafd9c45826e9c3387b Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 19 Sep 2021 05:16:29 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20STM32=20ADC=20followup=20(#22798?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/HAL/LPC1768/HAL.h | 8 ++++---- Marlin/src/HAL/STM32F1/HAL.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Marlin/src/HAL/LPC1768/HAL.h b/Marlin/src/HAL/LPC1768/HAL.h index ca4e2decab..f241249804 100644 --- a/Marlin/src/HAL/LPC1768/HAL.h +++ b/Marlin/src/HAL/LPC1768/HAL.h @@ -156,17 +156,17 @@ int freeMemory(); using FilteredADC = LPC176x::ADC; extern uint32_t HAL_adc_reading; -[[gnu::always_inline]] inline void HAL_start_adc(const pin_t pin) { +[[gnu::always_inline]] inline void HAL_adc_start_conversion(const pin_t pin) { HAL_adc_reading = FilteredADC::read(pin) >> (16 - HAL_ADC_RESOLUTION); // returns 16bit value, reduce to required bits } -[[gnu::always_inline]] inline uint16_t HAL_read_adc() { +[[gnu::always_inline]] inline uint16_t HAL_adc_get_result() { return HAL_adc_reading; } #define HAL_adc_init() #define HAL_ANALOG_SELECT(pin) FilteredADC::enable_channel(pin) -#define HAL_START_ADC(pin) HAL_start_adc(pin) -#define HAL_READ_ADC() HAL_read_adc() +#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin) +#define HAL_READ_ADC() HAL_adc_get_result() #define HAL_ADC_READY() (true) // Test whether the pin is valid diff --git a/Marlin/src/HAL/STM32F1/HAL.cpp b/Marlin/src/HAL/STM32F1/HAL.cpp index 73014945a1..df1ba33d4a 100644 --- a/Marlin/src/HAL/STM32F1/HAL.cpp +++ b/Marlin/src/HAL/STM32F1/HAL.cpp @@ -437,7 +437,7 @@ void HAL_adc_start_conversion(const uint8_t adc_pin) { case POWER_MONITOR_VOLTAGE_PIN: pin_index = POWERMON_VOLTS; break; #endif } - HAL_adc_result = (HAL_adc_results[(int)pin_index] >> 2) & 0x3FF; // shift to get 10 bits only. + HAL_adc_result = HAL_adc_results[(int)pin_index] >> (12 - HAL_ADC_RESOLUTION); // shift out unused bits } uint16_t HAL_adc_get_result() { return HAL_adc_result; }