Fix the analog driver for STM32-like MCUs when using a converter #21223
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The
pinToMux()
code for STM32-like chips (also used by GD32 and WB32, which have a similar GPIO implementation) used the regular QMK pin name defines likeA0
,A1
,E15
. However, when a converter is used, those pin name defines actually refer to the pins of the source MCU (e.g., ATmega32U4), therefore theanalog.c
code did not compile.Use raw ChibiOS pin names like
PAL_LINE(GPIOA, 0)
to refer to the pins in theanalog.c
code. In the normal case the pin name defines likeA0
would expand to those ChibiOS names anyway, but when a converter is used, the ChibiOS pin names continue to refer to the same pins of the target MCU, which is whatpinToMux()
requires.This change was originally suggested in #19453 (comment), and the RP2040 part of the change was included in that PR, therefore analog support for RP2040-based converters may work already, but any STM32-based converters need this change.
The change is just a mechanical transformation of the existing code:
One remaining problem is how to enable the ADC support in ChibiOS. Should the board files used for converters (
BONSAI_C4
,STEMCELL
,QMK_PROTON_C
) just enable the ADC support by default, or should that support be somehow limited to the converter use case? Currently theQMK_BLOK
andQMK_PM2040
boards enable ADC by default.TODO:
HAL_USE_ADC
andSTM32_ADC_USE_ADCn
options for various converters.Types of Changes
Issues Fixed or Closed by This PR
qmk compile -kb handwired/onekey/promicro -km adc -e CONVERT_TO=bonsai_c4
should work out of the box, like theCONVERT_TO=rp2040_ce
case works now.Checklist