Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the analog driver for STM32-like MCUs when using a converter #21223

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

sigprof
Copy link
Contributor

@sigprof sigprof commented Jun 12, 2023

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 like A0, 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 the analog.c code did not compile.

Use raw ChibiOS pin names like PAL_LINE(GPIOA, 0) to refer to the pins in the analog.c code. In the normal case the pin name defines like A0 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 what pinToMux() 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:

s/case \([A-Z]\)\([0-9]\+\):/case PAL_LINE(GPIO\1, \2):/

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 the QMK_BLOK and QMK_PM2040 boards enable ADC by default.

TODO:

  • Figure out how to handle the HAL_USE_ADC and STM32_ADC_USE_ADCn options for various converters.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Issues Fixed or Closed by This PR

  • Things like qmk compile -kb handwired/onekey/promicro -km adc -e CONVERT_TO=bonsai_c4 should work out of the box, like the CONVERT_TO=rp2040_ce case works now.

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

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 like `A0`, `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 the `analog.c` code did not compile.

Use raw ChibiOS pin names like `PAL_LINE(GPIOA, 0)` to refer to the pins
in the `analog.c` code.  In the normal case the pin name defines like
`A0` 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 what `pinToMux()` requires.
@github-actions github-actions bot added the core label Jun 12, 2023
@drashna drashna requested a review from a team June 13, 2023 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants