Sitelet https://github.com/betaflight/betaflight/pull/14962
Skip to content

Move GPIO_TypeDef and IO_GPIO out of common drivers into platform-specific headers to decouple IO implementation from hardware details - #14962

Merged
haslinghuis merged 3 commits into
betaflight:masterfrom
blckmn:io-gpio-move-to-platform
Mar 3, 2026
Merged

haslinghuis merged 3 commits into
betaflight:masterfrom
blckmn:io-gpio-move-to-platform

Conversation

@blckmn

@blckmn blckmn commented Mar 2, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Refactor
    • Reorganized I/O layer to move low-level GPIO access into platform-level implementations and decouple drivers from direct hardware access. Public I/O surface simplified and internal types adjusted. No user-visible behavioral changes; existing features remain unchanged.

…cific headers to decouple IO implementation from hardware details
@blckmn blckmn self-assigned this Mar 2, 2026
@github-actions

github-actions Bot commented Mar 2, 2026

Copy link
Copy Markdown

Do you want to test this code? You can flash it directly from the Betaflight App:

  • Simply put #14962 (this pull request number) in the Select commit field in the Firmware Flasher tab (you need to Enable expert mode, Show release candidates and Development).

WARNING: It may be unstable. Use only for testing!

@coderabbitai

coderabbitai Bot commented Mar 2, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f83df0a and 21bf937.

📒 Files selected for processing (1)
  • src/platform/STM32/pwm_output_dshot_hal.c
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/platform/STM32/pwm_output_dshot_hal.c

Walkthrough

Refactors IO/GPIO handling by removing driver-level GPIO accessors, changing ioRec->gpio to void*, moving IO_GPIO and platform-specific EXTI helpers into platform/common/stm32 io_impl.*, and updating includes across drivers and platform files to use the new platform io_impl headers. No public API additions beyond platform-level accessors.

Changes

Cohort / File(s) Summary
Driver include removals
src/main/drivers/accgyro/accgyro_spi_bmi160.c, src/main/drivers/accgyro/accgyro_spi_bmi270.c, src/main/drivers/accgyro/accgyro_spi_lsm6dso.c, src/main/drivers/accgyro/accgyro_spi_lsm6dso_init.c, src/main/drivers/light_led.c, src/main/drivers/rx/rx_a7105.c, src/main/drivers/rx/rx_cyrf6936.c, src/main/drivers/rx/rx_nrf24l01.c, src/main/drivers/rx/rx_spi.c, src/main/drivers/rx/rx_sx127x.c, src/main/drivers/rx/rx_sx1280.c, src/main/rx/spektrum.c
Removed drivers/io_impl.h includes from driver sources to decouple drivers from platform-specific IO implementation.
Core drivers IO refactor
src/main/drivers/io.c, src/main/drivers/io.h, src/main/drivers/io_impl.h
Removed driver-level IO_GPIO() declaration/definition; changed io_impl.h API/typedefs (removed ioDef_t, switched ioRec_s.gpio from GPIO_TypeDef* to void*, removed several IO accessor prototypes/macros, added IO_Rec() declaration).
Platform include additions
src/platform/STM32/dshot_bitbang.c, src/platform/STM32/exti.c, src/platform/STM32/io_stm32.c, src/platform/STM32/pwm_output_dshot_hal.c, src/platform/AT32/dshot_bitbang.c, src/platform/AT32/io_at32.c, src/platform/APM32/dshot_bitbang.c, src/platform/APM32/eint_apm32.c, src/platform/APM32/io_apm32.c, src/platform/common/stm32/debug_pin.c
Added platform/io_impl.h includes in multiple platform-specific implementation files so platform-level IO accessors are available where needed.
New/updated platform IO impl
src/platform/common/stm32/platform/io_impl.h, src/platform/common/stm32/io_impl.c
Introduced platform/common/stm32 io_impl.h declaring IO_GPIO() and conditional EXTI helpers; implemented IO_GPIO() in io_impl.c to resolve ioRec->gpio (converting void* storage to GPIO_TypeDef*).
Platform GPIO typedef removals
src/platform/PICO/include/platform/platform.h, src/platform/SIMULATOR/target/SITL/target.h, src/test/unit/platform.h
Removed platform-local GPIO_TypeDef typedefs/definitions from several platform headers (register map / test typedefs removed).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • KarateBrot
  • sugaarK
  • haslinghuis
  • ledvinap
🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request has no description provided by the author, violating the repository's template expectations which require explanation of changes and adherence to submission guidelines. Add a comprehensive pull request description explaining the motivation, implementation approach, testing performed, and any breaking changes or migration notes for affected code.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and clearly summarizes the main objective of the changeset—moving GPIO_TypeDef and IO_GPIO from common drivers into platform-specific headers to decouple implementation from hardware.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@haslinghuis haslinghuis moved this to Refactoring in 2026.6.0 Mar 2, 2026
@haslinghuis haslinghuis added this to the 2026.6 milestone Mar 2, 2026

@SupaflyFPV SupaflyFPV left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent and execution are solid. The main practical risk is the SITL build — if that still compiles and the simulated IO path works, the rest of this is a straightforward and beneficial cleanup.

Comment thread src/platform/STM32/pwm_output_dshot_hal.c
Comment thread src/platform/SIMULATOR/target/SITL/target.h
Comment thread src/test/unit/platform.h
Comment thread src/main/drivers/io_impl.h
Comment thread src/main/drivers/io_impl.h
Removed unnecessary include for 'drivers/io_impl.h'.
@haslinghuis
haslinghuis merged commit b494f6c into betaflight:master Mar 3, 2026
34 checks passed
@github-project-automation github-project-automation Bot moved this from Refactoring to Done in 2026.6.0 Mar 3, 2026
@blckmn
blckmn deleted the io-gpio-move-to-platform branch March 25, 2026 20:15
x4FF3 pushed a commit to openwch/betaflight that referenced this pull request Apr 7, 2026
…cific headers to decouple IO implementation from hardware details (betaflight#14962)

* Move GPIO_TypeDef and IO_GPIO out of common drivers into platform-specific headers to decouple IO implementation from hardware details

* Platform headers to be located in platform/

* Remove redundant include for io_impl.h

Removed unnecessary include for 'drivers/io_impl.h'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants