summaryrefslogtreecommitdiffstats
path: root/platforms
diff options
context:
space:
mode:
authorSergey Vlasov <sigprof@gmail.com>2023-01-25 04:47:55 +0300
committerGitHub <noreply@github.com>2023-01-25 01:47:55 +0000
commit81ca83296f3a9d9101ea9d88830cfcf427e8d944 (patch)
tree2f3378cdee788a21f10f1bb6b70b09e8dfaf399c /platforms
parent0edf478a5335b5c8fac29a0b77428f0dcbf43316 (diff)
analog.c: Fix `pinToMux()` for STM32F0xx (#19658)
The `adc_read()` code for STM32F0xx expects to get the 0-based channel number in `mux.input`, but the `pinToMux()` code for STM32F0xx was attempting to pass the CHSELR bit mask in that field, which resulted in selecting a wrong channel, therefore `analogReadPin()` did not work properly for the STM32F0xx chips. Fix `pinToMux()` to put the channel number in that field (this matches the behavior for other supported chips and also allows selection of channels 16...18, which can be used to access the builtin temperature, reference voltage and VBAT sensors).
Diffstat (limited to 'platforms')
-rw-r--r--platforms/chibios/drivers/analog.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/platforms/chibios/drivers/analog.c b/platforms/chibios/drivers/analog.c
index a8ce21bb6d..bf84ce8f76 100644
--- a/platforms/chibios/drivers/analog.c
+++ b/platforms/chibios/drivers/analog.c
@@ -138,22 +138,22 @@ static ADCConversionGroup adcConversionGroup = {
__attribute__((weak)) adc_mux pinToMux(pin_t pin) {
switch (pin) {
#if defined(STM32F0XX)
- case A0: return TO_MUX( ADC_CHSELR_CHSEL0, 0 );
- case A1: return TO_MUX( ADC_CHSELR_CHSEL1, 0 );
- case A2: return TO_MUX( ADC_CHSELR_CHSEL2, 0 );
- case A3: return TO_MUX( ADC_CHSELR_CHSEL3, 0 );
- case A4: return TO_MUX( ADC_CHSELR_CHSEL4, 0 );
- case A5: return TO_MUX( ADC_CHSELR_CHSEL5, 0 );
- case A6: return TO_MUX( ADC_CHSELR_CHSEL6, 0 );
- case A7: return TO_MUX( ADC_CHSELR_CHSEL7, 0 );
- case B0: return TO_MUX( ADC_CHSELR_CHSEL8, 0 );
- case B1: return TO_MUX( ADC_CHSELR_CHSEL9, 0 );
- case C0: return TO_MUX( ADC_CHSELR_CHSEL10, 0 );
- case C1: return TO_MUX( ADC_CHSELR_CHSEL11, 0 );
- case C2: return TO_MUX( ADC_CHSELR_CHSEL12, 0 );
- case C3: return TO_MUX( ADC_CHSELR_CHSEL13, 0 );
- case C4: return TO_MUX( ADC_CHSELR_CHSEL14, 0 );
- case C5: return TO_MUX( ADC_CHSELR_CHSEL15, 0 );
+ case A0: return TO_MUX( 0, 0 );
+ case A1: return TO_MUX( 1, 0 );
+ case A2: return TO_MUX( 2, 0 );
+ case A3: return TO_MUX( 3, 0 );
+ case A4: return TO_MUX( 4, 0 );
+ case A5: return TO_MUX( 5, 0 );
+ case A6: return TO_MUX( 6, 0 );
+ case A7: return TO_MUX( 7, 0 );
+ case B0: return TO_MUX( 8, 0 );
+ case B1: return TO_MUX( 9, 0 );
+ case C0: return TO_MUX( 10, 0 );
+ case C1: return TO_MUX( 11, 0 );
+ case C2: return TO_MUX( 12, 0 );
+ case C3: return TO_MUX( 13, 0 );
+ case C4: return TO_MUX( 14, 0 );
+ case C5: return TO_MUX( 15, 0 );
#elif defined(STM32F3XX)
case A0: return TO_MUX( ADC_CHANNEL_IN1, 0 );
case A1: return TO_MUX( ADC_CHANNEL_IN2, 0 );