Skip to content

Conversation

@liyouluo
Copy link
Contributor

@liyouluo liyouluo commented Aug 24, 2025

Hi. Please check.

This configures the I2C interface on the board for use with an external magnetometer.

The target board has an I2C pad.

Thank you.

image

Summary by CodeRabbit

  • New Features
    • Magnetometer support enabled by default for BETAFPV F405 and F405 ELRS targets, including QMC5883 and IST8310 compatibility.
    • I2C1 pins are preconfigured to PB8 (SCL) and PB9 (SDA) to simplify sensor wiring and setup.
    • Magnetometer functionality remains optional and can be disabled via existing configuration options.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 24, 2025

Walkthrough

Adds three preprocessor macros — I2C1_SCL_PIN = PB8, I2C1_SDA_PIN = PB9, and MAG_I2C_INSTANCE = I2CDEV_1 — to two board config headers: configs/BETAFPVF405/config.h and configs/BETAFPVF405_ELRS/config.h. No runtime logic or control-flow changes.

Changes

Cohort / File(s) Summary
BETAFPVF405 config updates
configs/BETAFPVF405/config.h
Added #define I2C1_SCL_PIN PB8, #define I2C1_SDA_PIN PB9, and #define MAG_I2C_INSTANCE I2CDEV_1.
BETAFPVF405_ELRS config updates
configs/BETAFPVF405_ELRS/config.h
Added #define I2C1_SCL_PIN PB8, #define I2C1_SDA_PIN PB9, and #define MAG_I2C_INSTANCE I2CDEV_1.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • ot0tot
  • haslinghuis
  • osirisinferi
  • blckmn

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8a51d6d and dc00fed.

📒 Files selected for processing (1)
  • configs/BETAFPVF405_ELRS/config.h (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • configs/BETAFPVF405_ELRS/config.h
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or `` to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
configs/BETAFPVF405/config.h (1)

42-46: Avoid hiding driver macros behind USE_MAG; guard each macro independently

As written, if USE_MAG is defined upstream, the driver macros (USE_MAG_QMC5883, USE_MAG_IST8310) will be skipped entirely. That can silently omit needed drivers while still enabling the MAG feature. Prefer individually guarding each macro.

Apply this diff within this block:

-#ifndef USE_MAG
-#define USE_MAG
-#define USE_MAG_QMC5883
-#define USE_MAG_IST8310
-#endif
+#ifndef USE_MAG
+#define USE_MAG
+#endif
+#ifndef USE_MAG_QMC5883
+#define USE_MAG_QMC5883
+#endif
+#ifndef USE_MAG_IST8310
+#define USE_MAG_IST8310
+#endif

If the goal is to keep magnetometer support truly optional by default (no added flash unless explicitly requested), consider not defining USE_MAG or any driver here and only provide the I2C pin mapping; users can enable the feature at build time.

configs/BETAFPVF405_ELRS/config.h (1)

42-46: Guard MAG driver macros independently to avoid accidental omission

Same pattern here: wrapping drivers under a single #ifndef USE_MAG means pre-defining USE_MAG upstream would skip driver inclusion.

Apply this diff within this block:

-#ifndef USE_MAG
-#define USE_MAG
-#define USE_MAG_QMC5883
-#define USE_MAG_IST8310
-#endif
+#ifndef USE_MAG
+#define USE_MAG
+#endif
+#ifndef USE_MAG_QMC5883
+#define USE_MAG_QMC5883
+#endif
+#ifndef USE_MAG_IST8310
+#define USE_MAG_IST8310
+#endif

Optional: if “optional MAG” is intended (not compiled by default), omit USE_MAG and driver defines here and only keep I2C pins; enable via build flags when needed.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0a79266 and 0424a9f.

📒 Files selected for processing (2)
  • configs/BETAFPVF405/config.h (2 hunks)
  • configs/BETAFPVF405_ELRS/config.h (2 hunks)
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
Learnt from: haslinghuis
PR: betaflight/config#822
File: configs/AXISFLYINGH7MINI/config.h:29-37
Timestamp: 2025-06-23T18:43:31.746Z
Learning: In Betaflight configuration files, feature enablement macros like USE_MAG are build options that can be controlled at compile time, while hardware instance definitions like MAG_I2C_INSTANCE are predefined in board configurations to assist with hardware mapping when those features are enabled at build time.
📚 Learning: 2025-06-23T18:43:31.746Z
Learnt from: haslinghuis
PR: betaflight/config#822
File: configs/AXISFLYINGH7MINI/config.h:29-37
Timestamp: 2025-06-23T18:43:31.746Z
Learning: In Betaflight configuration files, feature enablement macros like USE_MAG are build options that can be controlled at compile time, while hardware instance definitions like MAG_I2C_INSTANCE are predefined in board configurations to assist with hardware mapping when those features are enabled at build time.

Applied to files:

  • configs/BETAFPVF405/config.h
  • configs/BETAFPVF405_ELRS/config.h
📚 Learning: 2025-08-21T11:11:19.213Z
Learnt from: haslinghuis
PR: betaflight/config#870
File: configs/ZEX_ATHENA_STD_PRO/config.h:54-55
Timestamp: 2025-08-21T11:11:19.213Z
Learning: For STM32H743 in Betaflight, UART4 can use PB8 (UART4_RX) and PB9 (UART4_TX) as confirmed in the official Betaflight codebase at src/platform/STM32/serial_uart_stm32h7xx.c. This contradicts some generic STM32 documentation that might not show all supported pin configurations used by Betaflight.

Applied to files:

  • configs/BETAFPVF405/config.h
  • configs/BETAFPVF405_ELRS/config.h
📚 Learning: 2025-08-21T11:11:19.213Z
Learnt from: haslinghuis
PR: betaflight/config#870
File: configs/ZEX_ATHENA_STD_PRO/config.h:54-55
Timestamp: 2025-08-21T11:11:19.213Z
Learning: For STM32H743 in Betaflight, UART4 can use PB8 (UART4_RX) and PB9 (UART4_TX) with GPIO_AF8_UART4, as confirmed in the official Betaflight codebase at src/platform/STM32/serial_uart_stm32h7xx.c. This is a valid pin mapping despite what some generic STM32 documentation might suggest.

Applied to files:

  • configs/BETAFPVF405/config.h
  • configs/BETAFPVF405_ELRS/config.h
📚 Learning: 2025-08-19T18:34:22.887Z
Learnt from: osirisinferi
PR: betaflight/config#872
File: configs/HGLRCH743/config.h:82-83
Timestamp: 2025-08-19T18:34:22.887Z
Learning: For STM32H743, both UART5_TX (PB6) and UART5_RX (PB5) use alternate function AF14, not AF8. The Port B alternate functions table in the STM32H743 datasheet confirms PB5 supports UART5_RX and PB6 supports UART5_TX, both using AF14.

Applied to files:

  • configs/BETAFPVF405/config.h
  • configs/BETAFPVF405_ELRS/config.h
📚 Learning: 2025-07-14T15:41:14.364Z
Learnt from: ot0tot
PR: betaflight/config#834
File: configs/RADIOLINKF405/config.h:79-88
Timestamp: 2025-07-14T15:41:14.364Z
Learning: In STM32F405 configurations, PB1 typically maps to TIM3_CH4 and PC9 typically maps to TIM8_CH4. These are different timers and do not share DMA resources, so there is no conflict when both pins are used simultaneously (e.g., PB1 for LED_STRIP and PC9 for MOTOR4).

Applied to files:

  • configs/BETAFPVF405/config.h
  • configs/BETAFPVF405_ELRS/config.h
📚 Learning: 2025-07-25T20:06:07.492Z
Learnt from: haslinghuis
PR: betaflight/config#719
File: configs/SPEDIXG473/config.h:29-38
Timestamp: 2025-07-25T20:06:07.492Z
Learning: BMP280 and DPS310 barometer drivers in Betaflight do not require USE_I2C to be explicitly defined in board configurations. Out of 264 boards using these drivers, 259 (98%) work without USE_I2C defined, indicating that the I2C dependency is handled automatically by the build system.

Applied to files:

  • configs/BETAFPVF405_ELRS/config.h
📚 Learning: 2025-07-25T20:06:07.492Z
Learnt from: haslinghuis
PR: betaflight/config#719
File: configs/SPEDIXG473/config.h:29-38
Timestamp: 2025-07-25T20:06:07.492Z
Learning: BMP280 and DPS310 barometer drivers in Betaflight do not require USE_I2C to be explicitly defined in board configurations. Many existing boards successfully use USE_BARO_BMP280 and USE_BARO_DPS310 without defining USE_I2C, indicating that the I2C dependency is handled automatically by the build system or these sensors support alternative communication methods.

Applied to files:

  • configs/BETAFPVF405_ELRS/config.h

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@ot0tot
Copy link
Contributor

ot0tot commented Aug 25, 2025

PB8 is already mapped to ESC_SERIAL and RX_PPM in the target. It cannot be used for those and I2C.
Additionally, PB8 should be removed from the timer pin map in the BETAFPVF405_ELRS target.

@osirisinferi
Copy link
Contributor

osirisinferi commented Aug 25, 2025

PB8 is already mapped to ESC_SERIAL and RX_PPM in the target. It cannot be used for those and I2C.

Wouldn't be the first that the I²C config (exclusively PB8 it seems) is shared with ESC_SERIAL and/or RX_PPM, see e.g. FLYWOOF405, FLYWOOF405PRO, FLYWOOF405S_AIO, FLYWOOF405NANO, HGLRCF405, OMNIBUSF4V6 and JHEF405PRO.

@haslinghuis
Copy link
Member

@osirisinferi guess these targets were submitted before our manufacturer guideline requirements kicked in - as we all learn in the progress to get the best possible hardware out.

@osirisinferi
Copy link
Contributor

@osirisinferi guess these targets were submitted before our manufacturer guideline requirements kicked in - as we all learn in the progress to get the best possible hardware out.

@haslinghuis Didn't mean to "point fingers", but thought maybe someone would like to fix these 🙂 Do you have schematics of the older boards?

@haslinghuis
Copy link
Member

No worrries, schematics were not required before the program.

@haslinghuis haslinghuis requested a review from ot0tot August 26, 2025 16:09
@haslinghuis haslinghuis merged commit 3bd1953 into betaflight:master Aug 26, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants