Skip to content

adding icm42670p driver - #201

Open
r-u-t-r-A wants to merge 1 commit into
rtlopez:masterfrom
r-u-t-r-A:adding-icm42670p-imu-support
Open

adding icm42670p driver#201
r-u-t-r-A wants to merge 1 commit into
rtlopez:masterfrom
r-u-t-r-A:adding-icm42670p-imu-support

Conversation

@r-u-t-r-A

@r-u-t-r-A r-u-t-r-A commented Feb 24, 2026

Copy link
Copy Markdown

Hi, ive created a driver for icm42670p since all MPU IMUs are end of life products, code compiles, tested on esp32s3 with gyro connected over i2c

Summary by CodeRabbit

Release Notes

  • New Features
    • Added support for ICM-42670-P gyroscope sensor with automatic device detection across I2C and SPI interfaces.

Review Change Stack

@rtlopez

rtlopez commented Feb 24, 2026

Copy link
Copy Markdown
Owner

Looks promising, can you prepare any sort of demo? I mean YT video for example and cli status command result. Thanks.

@r-u-t-r-A

Copy link
Copy Markdown
Author

i will post it as fast as i can

@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR adds support for the ICM-42670-P gyro sensor to the ESP-FC flight controller firmware. A new device type enum is defined, a complete device driver class is implemented with register initialization and fast sensor reads, and the device is integrated into the hardware auto-detection system for both SPI and I2C buses.

Changes

ICM-42670-P Gyro Device Support

Layer / File(s) Summary
Device type enumeration
lib/Espfc/src/Device/GyroDevice.h
GyroDeviceType enum gains GYRO_ICM42670P = 9 before GYRO_MAX, extending the recognized device set.
ICM-42670-P device implementation
lib/Espfc/src/Device/GyroICM42760P.h
GyroICM42670P class initializes the sensor via soft reset and power/config writes, validates presence via WHO_AM_I, performs fast 6-byte gyro and accel reads into VectorInt16, and exposes fixed-rate (1600 Hz) and stubbed DLPF/rate configuration methods.
Hardware detection and wiring
lib/Espfc/src/Hardware.cpp
Include header, declare static device instance, and extend SPI and I2C gyro detection sequences to attempt icm42670p after existing candidates.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'adding icm42670p driver' directly and clearly describes the main change—adding support for a new IMU device driver, which is reflected across all modified files.
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
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch adding-icm42670p-imu-support

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

@rtlopez

rtlopez commented May 18, 2026

Copy link
Copy Markdown
Owner

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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: 2

🧹 Nitpick comments (1)
lib/Espfc/src/Device/GyroICM42760P.h (1)

51-64: 💤 Low value

Consider verifying bus write success during initialization.

The initialization writes to multiple registers but doesn't check return values from writeByte. If a write fails (e.g., due to bus error), the device may not be properly configured, yet begin() will return success. Consider checking at least the critical power management write.

🤖 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 `@lib/Espfc/src/Device/GyroICM42760P.h` around lines 51 - 64, The init sequence
calls _bus->writeByte repeatedly (e.g., for ICM42670P_REG_DEVICE_CONFIG,
ICM42670P_REG_PWR_MGMT0, ICM42670P_REG_GYRO_CONFIG0,
ICM42670P_REG_ACCEL_CONFIG0) but ignores return values; update begin() to check
the boolean/return result of at least the critical power management write
(_bus->writeByte(_addr, ICM42670P_REG_PWR_MGMT0, ICM42670P_PWR_LN_MODE)) and
fail early if it indicates an error (log or set an error state and return false
from begin()), and optionally propagate similar checks for the other writes
(retry or abort) so device initialization cannot report success when bus writes
fail.
🤖 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 `@lib/Espfc/src/Device/GyroICM42760P.h`:
- Around line 1-2: The header file is misnamed GyroICM42760P.h but the device
and symbols use ICM42670P; rename the file to GyroICM42670P.h to match the
include guard/class naming and ensure consistency, then update any includes that
reference the old name (notably the include in Hardware.cpp) to the new filename
GyroICM42670P.h so compilation and symbol resolution remain correct.

In `@lib/Espfc/src/Hardware.cpp`:
- Line 9: Update the include in Hardware.cpp to reference the corrected header
name: replace the old include of "Device/GyroICM42760P.h" with the corrected
"Device/GyroICM42670P.h" so that the compilation uses the fixed GyroICM42670P.h
header (search for the include line containing GyroICM42760P and change the
filename to GyroICM42670P).

---

Nitpick comments:
In `@lib/Espfc/src/Device/GyroICM42760P.h`:
- Around line 51-64: The init sequence calls _bus->writeByte repeatedly (e.g.,
for ICM42670P_REG_DEVICE_CONFIG, ICM42670P_REG_PWR_MGMT0,
ICM42670P_REG_GYRO_CONFIG0, ICM42670P_REG_ACCEL_CONFIG0) but ignores return
values; update begin() to check the boolean/return result of at least the
critical power management write (_bus->writeByte(_addr, ICM42670P_REG_PWR_MGMT0,
ICM42670P_PWR_LN_MODE)) and fail early if it indicates an error (log or set an
error state and return false from begin()), and optionally propagate similar
checks for the other writes (retry or abort) so device initialization cannot
report success when bus writes fail.
🪄 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: edc4ce9b-6947-4055-afa7-91022df3b3dc

📥 Commits

Reviewing files that changed from the base of the PR and between d44487e and 385dc04.

📒 Files selected for processing (3)
  • lib/Espfc/src/Device/GyroDevice.h
  • lib/Espfc/src/Device/GyroICM42760P.h
  • lib/Espfc/src/Hardware.cpp

Comment on lines +1 to +2
#ifndef _ESPFC_DEVICE_GYRO_ICM42670P_H_
#define _ESPFC_DEVICE_GYRO_ICM42670P_H_

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Filename typo: GyroICM42760P.h should be GyroICM42670P.h.

The file is named GyroICM42760P.h but the device is ICM-42670-P (note: 42670, not 42760). The include guard and class name correctly use 42670P. Rename the file to GyroICM42670P.h for consistency, and update the include in Hardware.cpp accordingly.

🤖 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 `@lib/Espfc/src/Device/GyroICM42760P.h` around lines 1 - 2, The header file is
misnamed GyroICM42760P.h but the device and symbols use ICM42670P; rename the
file to GyroICM42670P.h to match the include guard/class naming and ensure
consistency, then update any includes that reference the old name (notably the
include in Hardware.cpp) to the new filename GyroICM42670P.h so compilation and
symbol resolution remain correct.

#include "Device/GyroLSM6DSO.h"
#include "Device/GyroICM20602.h"
#include "Device/GyroBMI160.h"
#include "Device/GyroICM42760P.h"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Update include path when filename is corrected.

This include path references the typo'd filename (GyroICM42760P.h). When the filename is corrected to GyroICM42670P.h, update this include accordingly.

🤖 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 `@lib/Espfc/src/Hardware.cpp` at line 9, Update the include in Hardware.cpp to
reference the corrected header name: replace the old include of
"Device/GyroICM42760P.h" with the corrected "Device/GyroICM42670P.h" so that the
compilation uses the fixed GyroICM42670P.h header (search for the include line
containing GyroICM42760P and change the filename to GyroICM42670P).

@rtlopez rtlopez left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hi @r-u-t-r-A To proceed I need all issues to be addressed, Also you need to rebase your changes. Thank you.

GYRO_ICM20602 = 7,
GYRO_BMI160 = 8,
GYRO_ICM42670P = 9,
GYRO_MAX

@rtlopez rtlopez May 20, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think You missed this place
https://github.com/r-u-t-r-A/esp-fc/blob/385dc0453495c6b8dc2090d9318657e02d0c9e71/lib/Espfc/src/Device/GyroDevice.cpp#L9

lib/Espfc/src/Device/GyroDevice.cpp:9

static const char* devChoices[] = { PSTR("AUTO"), PSTR("NONE"), PSTR("MPU6000"), PSTR("MPU6050"), PSTR("MPU6500"), PSTR("MPU9250"), PSTR("LSM6DSO"), PSTR("ICM20602"),PSTR("BMI160"), NULL };

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.

2 participants