Skip to content

chore(v16): add support for more IMU hardware#7482

Open
helloradiosky wants to merge 5 commits into
EdgeTX:mainfrom
helloradiosky:hrs_v16_gyro
Open

chore(v16): add support for more IMU hardware#7482
helloradiosky wants to merge 5 commits into
EdgeTX:mainfrom
helloradiosky:hrs_v16_gyro

Conversation

@helloradiosky

@helloradiosky helloradiosky commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

The gyroscope of V16 has been enhanced with multi-chip dynamic loading functionality
The future should support more devices

Summary by CodeRabbit

  • New Features
    • Added support for ICM42627 and SC7U22 IMU sensors on V16 builds.
    • Improved IMU auto-detection on V16 by probing I2C addresses for all enabled IMU drivers.
  • Hardware Configuration
    • Updated V16 IMU setup to use I2C bus 1 and removed the forced I2C address override.
  • Bug Fixes
    • Improved ICM42627 power-up and initialization timing for more reliable device startup.
  • Refactor
    • Reworked IMU startup to build a compile-time candidate list of enabled drivers and initialize using detected results.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds V16 IMU build wiring, updates IMU bus selection, and revises ICM42627 initialization timing and register sequencing.

Changes

Horus V16 IMU wiring and initialization

Layer / File(s) Summary
Build flags and IMU selection
radio/src/drivers/icm42627.h, radio/src/targets/horus/CMakeLists.txt, radio/src/targets/horus/hal.h, radio/src/targets/horus/board.cpp
icm42627.h adds the ICM42627 I2C base address constant. CMakeLists.txt enables ICM42627 and SC7U22 IMU macros for X10 V16 and adds sc7u22.cpp. hal.h selects I2C_Bus_1 for RADIO_V16 without defining IMU_I2C_ADDRESS. board.cpp updates IMU gating and conditional header inclusion to match the enabled driver macros.
ICM42627 init timing and register writes
radio/src/drivers/icm42627.cpp
gyro42627Init() increases readiness timing, replaces the initial ack check with a retry-based wait, inserts a bank 1 GYRO_STATIC2 write while the sensors are off, and reorders power-on delays around the updated settle and startup timings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • EdgeTX/edgetx#7232: Introduces the earlier Horus V16 IMU wiring that this PR extends with SC7U22 support and revised ICM42627 initialization.

Suggested labels

hardware support, enhancement ✨

Suggested reviewers

  • pfeerick
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is too sparse and does not follow the required template sections. Add the template sections, including Fixes # and a 'Summary of changes' section with concrete details of the IMU hardware and init updates.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: broader IMU hardware support on V16.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@radio/src/drivers/icm42627.cpp`:
- Around line 95-97: The reset command write failure in the if statement
checking write_cmd(ICM42627_DEVICE_CONFIG_REG, ICM42627_RESET) is currently only
logging a trace message and continuing execution, which leaves the sensor in a
partially configured state. Instead of just logging the error with TRACE, the
function gyro42627Init() should return a failure status immediately when
write_cmd returns a value less than 0, ensuring that a failed reset is treated
as a fatal error that prevents the initialization from succeeding.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 69dca07d-df01-4e69-9876-7b5e910f91fa

📥 Commits

Reviewing files that changed from the base of the PR and between 0f5bc9b and ff928de.

📒 Files selected for processing (5)
  • radio/src/drivers/icm42627.cpp
  • radio/src/drivers/icm42627.h
  • radio/src/targets/horus/CMakeLists.txt
  • radio/src/targets/horus/board.cpp
  • radio/src/targets/horus/hal.h

Comment thread radio/src/drivers/icm42627.cpp
@richardclli

Copy link
Copy Markdown
Member

Is this duplicated #7232?

@helloradiosky

Copy link
Copy Markdown
Contributor Author

Is this duplicated #7232?

Well, some modifications were made to make it compatible with more gyroscope models

@pfeerick

pfeerick commented Jun 23, 2026

Copy link
Copy Markdown
Member

The problem is that it is a duplicate of #7232, while also extending it ... i.e. if I merge #7232 first (which I was intending to do before I saw Richard's mention of this PR), there would most likely be conflicts for merging this one (spoiler, there were). Because the intention was to enhance on #7232, I'll still merge that first and then update this so it can be merged after.

@pfeerick pfeerick changed the title Hrs v16 gyro chore(v16): add support for more IMU hardware Jun 23, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
radio/src/targets/horus/CMakeLists.txt (1)

119-120: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Align SC7U22 source gating with macro gating.

Line 119-120 enables IMU_SC7U22 under PCBREV conditions, while Line 301-303 compiles drivers/sc7u22.cpp under FLAVOUR conditions. Keeping these predicates identical avoids config drift between symbol usage and source inclusion.

Suggested diff
-if(FLAVOUR STREQUAL v16)
+if(PCB STREQUAL X10 AND PCBREV STREQUAL V16)
   target_sources(board PRIVATE drivers/sc7u22.cpp)
 endif()

Also applies to: 301-303

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@radio/src/targets/horus/CMakeLists.txt` around lines 119 - 120, The SC7U22
macro definition and source file compilation are gated by different CMake
conditions, creating a mismatch between symbol definition and actual source
inclusion. The add_definitions(-DIMU_SC7U22) uses PCBREV conditions (line
119-120), while the drivers/sc7u22.cpp compilation uses FLAVOUR conditions
(around line 301-303). Update the conditional check for compiling
drivers/sc7u22.cpp to use the same PCBREV condition as the macro definition to
ensure consistency between when the symbol is defined and when the source is
actually compiled.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@radio/src/targets/horus/CMakeLists.txt`:
- Around line 119-120: The SC7U22 macro definition and source file compilation
are gated by different CMake conditions, creating a mismatch between symbol
definition and actual source inclusion. The add_definitions(-DIMU_SC7U22) uses
PCBREV conditions (line 119-120), while the drivers/sc7u22.cpp compilation uses
FLAVOUR conditions (around line 301-303). Update the conditional check for
compiling drivers/sc7u22.cpp to use the same PCBREV condition as the macro
definition to ensure consistency between when the symbol is defined and when the
source is actually compiled.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ef937371-3c40-42dd-99ca-e65522192f7d

📥 Commits

Reviewing files that changed from the base of the PR and between ff928de and 627ae5f.

📒 Files selected for processing (4)
  • radio/src/drivers/icm42627.h
  • radio/src/targets/horus/CMakeLists.txt
  • radio/src/targets/horus/board.cpp
  • radio/src/targets/horus/hal.h
✅ Files skipped from review due to trivial changes (1)
  • radio/src/drivers/icm42627.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • radio/src/targets/horus/board.cpp

…pecific

Replace the RADIO_V16-gated multi-chip candidate table and HAS_IMU
check with a single table driven by IMU_xxx chip defines
(IMU_ICM42627, IMU_SC7U22, IMU_LSM6DS33), with a fallback for boards
that only set the legacy IMU_I2C_ADDRESS (PCBX12S). Lays groundwork
for unifying rm-h750/taranis/pa01/st16 onto the same pattern.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@radio/src/targets/horus/board.cpp`:
- Around line 56-57: The IMU feature guard in board.cpp is too permissive for
IMU_LSM6DS33, allowing that path to compile without an IMU_I2C_ADDRESS even
though the later IMU setup still depends on it. Update the conditional checks
around the IMU support block and the IMU_I2C_ADDRESS usage so that IMU_LSM6DS33
only enables the relevant code when an I2C address is present, keeping the guard
consistent across the definitions near the board feature macros and the IMU
initialization logic in the Horus board target.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 005c105a-3ce8-4f2a-a0ee-f745c2cb0ac5

📥 Commits

Reviewing files that changed from the base of the PR and between 627ae5f and 9a3caae.

📒 Files selected for processing (1)
  • radio/src/targets/horus/board.cpp

Comment thread radio/src/targets/horus/board.cpp
pfeerick and others added 2 commits June 24, 2026 22:50
…MU drivers

drivers/sc7u22.cpp had no internal guard, so gating it on FLAVOUR
STREQUAL v16 was redundant and inconsistent with lsm6ds.cpp and
icm42627.cpp, which are always compiled and rely on --gc-sections to
drop unused code when their IMU_xxx define isn't set.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Configure the gyro/accel signal path while powered off per datasheet
section 12.6, then power on last with the required 200us/45ms timing
windows. Also retry the initial I2C device-ready probe instead of a
single quick check, since the chip can take longer than that to start
acknowledging after power-up.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@pfeerick

Copy link
Copy Markdown
Member

@helloradiosky @gismo2004 Would you be so kind as to test the latest state of this PR on the V16. I think I finally pinned down the intermittent ICM42627 detection to the chip sometimes not responding as soon as we expect it to on power on (and fixed up a few initialisation order inconsistencies while at it)... once it starts responding... all is good. @philmoz If you want to check also, this should hopefully work for your V16 now also... mine is consistently working now, rather than still being somewhat intermittent in detecting the IMU.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@radio/src/drivers/icm42627.cpp`:
- Around line 120-123: The GYRO_STATIC2 failure path in icm42627::init leaves
the device in bank 1 because it returns immediately after the write_cmd call, so
update this error branch to switch the register bank back to 0 before returning.
Make the fix in the same init sequence that selects bank 1 earlier, ensuring any
transient failure still restores the default bank state for later retries and
subsequent register access.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9edd107e-fdaf-48a9-853f-4d8573ea1689

📥 Commits

Reviewing files that changed from the base of the PR and between ff146a2 and 768a7bd.

📒 Files selected for processing (1)
  • radio/src/drivers/icm42627.cpp

Comment thread radio/src/drivers/icm42627.cpp
@helloradiosky

Copy link
Copy Markdown
Contributor Author

@helloradiosky @gismo2004 Would you be so kind as to test the latest state of this PR on the V16. I think I finally pinned down the intermittent ICM42627 detection to the chip sometimes not responding as soon as we expect it to on power on (and fixed up a few initialisation order inconsistencies while at it)... once it starts responding... all is good. @philmoz If you want to check also, this should hopefully work for your V16 now also... mine is consistently working now, rather than still being somewhat intermittent in detecting the IMU.

Alright, I'll test it right away

@philmoz

philmoz commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

@philmoz If you want to check also, this should hopefully work for your V16 now also

Tested one of the V16 radios and it now works - thanks.

@gismo2004

Copy link
Copy Markdown
Contributor

@pfeerick It also works for me, but it worked before too :-). Thanks for taking a look at it and fixing it properly! BTW, where did you get the docs from?

@pfeerick

Copy link
Copy Markdown
Member

Thanks @philmoz ! :) Fantastic!

@gismo2004 Excellent! Yeah, it worked for me for a short while after resetting the IMU a few times, for several reboots, and then stopped again. HRS sent through the datasheets they had ;)

@helloradiosky

Copy link
Copy Markdown
Contributor Author

@helloradiosky @gismo2004 Would you be so kind as to test the latest state of this PR on the V16. I think I finally pinned down the intermittent ICM42627 detection to the chip sometimes not responding as soon as we expect it to on power on (and fixed up a few initialisation order inconsistencies while at it)... once it starts responding... all is good. @philmoz If you want to check also, this should hopefully work for your V16 now also... mine is consistently working now, rather than still being somewhat intermittent in detecting the IMU.

@pfeerick I have repeatedly tested it, and it is working perfectly. Thank you

@helloradiosky

Copy link
Copy Markdown
Contributor Author

Thanks @philmoz ! :) Fantastic!

@gismo2004 Excellent! Yeah, it worked for me for a short while after resetting the IMU a few times, for several reboots, and then stopped again. HRS sent through the datasheets they had ;)

@pfeerick Sorry, if there are still unstable issues, I think it might be a problem with the gyro hardware on your machine. Please keep an eye on it. If it's indeed unstable, I'll arrange for another prototype for you to test

If the GYRO_STATIC2 write fails during ICM42627 init, the function
returned early while still in bank 1, leaving WHO_AM_I/DEVICE_CONFIG
(bank 0 registers) unreadable on any subsequent init retry or
candidate probe.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@pfeerick pfeerick added bug 🪲 Something isn't working house keeping 🧹 Cleanup of code and house keeping labels Jul 3, 2026
@pfeerick pfeerick added this to the 2.12.3 milestone Jul 3, 2026
@pfeerick pfeerick added the backport/2.12 To be backported to a 2.12 release also. label Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/2.12 To be backported to a 2.12 release also. bug 🪲 Something isn't working house keeping 🧹 Cleanup of code and house keeping

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants