Browse Source

🐛 STM32 ADC followup (#22798)

Tanguy Pruvot 3 years ago
parent
commit
10fda222ea
No account linked to committer's email address
2 changed files with 5 additions and 5 deletions
  1. 4
    4
      Marlin/src/HAL/LPC1768/HAL.h
  2. 1
    1
      Marlin/src/HAL/STM32F1/HAL.cpp

+ 4
- 4
Marlin/src/HAL/LPC1768/HAL.h View File

156
 
156
 
157
 using FilteredADC = LPC176x::ADC<ADC_LOWPASS_K_VALUE, ADC_MEDIAN_FILTER_SIZE>;
157
 using FilteredADC = LPC176x::ADC<ADC_LOWPASS_K_VALUE, ADC_MEDIAN_FILTER_SIZE>;
158
 extern uint32_t HAL_adc_reading;
158
 extern uint32_t HAL_adc_reading;
159
-[[gnu::always_inline]] inline void HAL_start_adc(const pin_t pin) {
159
+[[gnu::always_inline]] inline void HAL_adc_start_conversion(const pin_t pin) {
160
   HAL_adc_reading = FilteredADC::read(pin) >> (16 - HAL_ADC_RESOLUTION); // returns 16bit value, reduce to required bits
160
   HAL_adc_reading = FilteredADC::read(pin) >> (16 - HAL_ADC_RESOLUTION); // returns 16bit value, reduce to required bits
161
 }
161
 }
162
-[[gnu::always_inline]] inline uint16_t HAL_read_adc() {
162
+[[gnu::always_inline]] inline uint16_t HAL_adc_get_result() {
163
   return HAL_adc_reading;
163
   return HAL_adc_reading;
164
 }
164
 }
165
 
165
 
166
 #define HAL_adc_init()
166
 #define HAL_adc_init()
167
 #define HAL_ANALOG_SELECT(pin) FilteredADC::enable_channel(pin)
167
 #define HAL_ANALOG_SELECT(pin) FilteredADC::enable_channel(pin)
168
-#define HAL_START_ADC(pin)     HAL_start_adc(pin)
169
-#define HAL_READ_ADC()         HAL_read_adc()
168
+#define HAL_START_ADC(pin)     HAL_adc_start_conversion(pin)
169
+#define HAL_READ_ADC()         HAL_adc_get_result()
170
 #define HAL_ADC_READY()        (true)
170
 #define HAL_ADC_READY()        (true)
171
 
171
 
172
 // Test whether the pin is valid
172
 // Test whether the pin is valid

+ 1
- 1
Marlin/src/HAL/STM32F1/HAL.cpp View File

437
       case POWER_MONITOR_VOLTAGE_PIN: pin_index = POWERMON_VOLTS; break;
437
       case POWER_MONITOR_VOLTAGE_PIN: pin_index = POWERMON_VOLTS; break;
438
     #endif
438
     #endif
439
   }
439
   }
440
-  HAL_adc_result = (HAL_adc_results[(int)pin_index] >> 2) & 0x3FF; // shift to get 10 bits only.
440
+  HAL_adc_result = HAL_adc_results[(int)pin_index] >> (12 - HAL_ADC_RESOLUTION); // shift out unused bits
441
 }
441
 }
442
 
442
 
443
 uint16_t HAL_adc_get_result() { return HAL_adc_result; }
443
 uint16_t HAL_adc_get_result() { return HAL_adc_result; }

Loading…
Cancel
Save