Skip to content

sensor: icm45686: Add I2C-bus support #88681

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

Merged
merged 4 commits into from
Apr 23, 2025

Conversation

ubieda
Copy link
Member

@ubieda ubieda commented Apr 15, 2025

Description

This PR adds I2C bus support to ICM45686 driver, making it compatible with all existing driver functionality:

  • Read/Decode.
  • Trigger Support.
  • Streaming Mode.

Testing

  • Run Shell sample on FRDM MCXN947 with Streaming mode enabled and validate sensor interaction:

  • Build command:

west build -b frdm_mcxn947/mcxn947/cpu0 samples/subsys/shell/shell_module -- -DCONFIG_SENSOR=y -DCONFIG_SENSOR_SHELL=y -DCONFIG_ICM45686_STREAM=y -DCONFIG_SENSOR_SHELL_STREAM=y
  • Overlay (boards/frdm_mcxn947_mcxn947_cpu0.overlay):
#include <zephyr/dt-bindings/sensor/icm45686.h>

&flexcomm2_lpi2c2 {
	status = "okay";

	icm45686: icm45686@68 {
		compatible = "invensense,icm45686";
		reg = <0x68>;
		int-gpios = <&gpio0 29 GPIO_ACTIVE_HIGH>;

		accel-pwr-mode = <ICM45686_DT_ACCEL_LN>;
		accel-fs = <ICM45686_DT_ACCEL_FS_2>;
		accel-odr = <ICM45686_DT_ACCEL_ODR_25>;
		accel-lpf = <ICM45686_DT_ACCEL_LPF_BW_1_32>;
		
		gyro-pwr-mode = <ICM45686_DT_GYRO_LN>;
		gyro-fs = <ICM45686_DT_GYRO_FS_4000>;
		gyro-odr = <ICM45686_DT_GYRO_ODR_25>;
		gyro-lpf = <ICM45686_DT_GYRO_LPF_BW_1_32>;

		fifo-watermark = <25>;
	};
};
  • Console output:
# Read/Decode validation
uart:~$ sensor get icm45686@68 
channel type=0(accel_x) index=0 shift=5 num_samples=1 value=55430013257ns (0.073022)
channel type=1(accel_y) index=0 shift=5 num_samples=1 value=55430013257ns (-0.195126)
channel type=2(accel_z) index=0 shift=5 num_samples=1 value=55430013257ns (9.810240)
channel type=3(accel_xyz) index=0 shift=5 num_samples=1 value=55430013257ns, (0.073022, -0.195126, 9.810240)
channel type=4(gyro_x) index=0 shift=12 num_samples=1 value=55430013257ns (0.000000)
channel type=5(gyro_y) index=0 shift=12 num_samples=1 value=55430013257ns (0.000000)
channel type=6(gyro_z) index=0 shift=12 num_samples=1 value=55430013257ns (0.000000)
channel type=7(gyro_xyz) index=0 shift=12 num_samples=1 value=55430013257ns, (0.000000, 0.000000, 0.000000)
channel type=12(die_temp) index=0 shift=9 num_samples=1 value=55430013257ns (25.000000)
uart:~$ 

# Streaming validation
uart:~$ sensor stream icm45686@68 on fifo_wm incl
Disabling existing stream
Enabling stream...
Trigger (10 / fifo_wm) detected
channel type=3(accel_xyz) index=0 shift=9 num_samples=25 value=95403523897ns, (0.076470, -0.191008, 9.810528)
channel type=7(gyro_xyz) index=0 shift=12 num_samples=25 value=95403523897ns, (0.000429, -0.000871, -0.000247)
channel type=12(die_temp) index=0 shift=9 num_samples=25 value=95403523897ns (24.946859)
Trigger (10 / fifo_wm) detected
channel type=3(accel_xyz) index=0 shift=9 num_samples=25 value=96401679064ns, (0.075368, -0.188806, 9.809762)
channel type=7(gyro_xyz) index=0 shift=12 num_samples=25 value=96401679064ns, (0.000471, -0.000669, -0.000291)
channel type=12(die_temp) index=0 shift=9 num_samples=25 value=96401679064ns (24.956521)
Trigger (10 / fifo_wm) detected
channel type=3(accel_xyz) index=0 shift=9 num_samples=25 value=97399794957ns, (0.086477, -0.190529, 9.809618)
channel type=7(gyro_xyz) index=0 shift=12 num_samples=25 value=97399794957ns, (0.000051, -0.002565, -0.000268)
channel type=12(die_temp) index=0 shift=9 num_samples=25 value=97399794957ns (24.934782)
Trigger (10 / fifo_wm) detected
channel type=3(accel_xyz) index=0 shift=9 num_samples=25 value=98397860331ns, (0.093324, -0.190673, 9.809570)
channel type=7(gyro_xyz) index=0 shift=12 num_samples=25 value=98397860331ns, (0.000286, -0.000797, -0.000226)
channel type=12(die_temp) index=0 shift=9 num_samples=25 value=98397860331ns (24.913042)
Trigger (10 / fifo_wm) detected
channel type=3(accel_xyz) index=0 shift=9 num_samples=25 value=99395940484ns, (0.093324, -0.191487, 9.808948)
channel type=7(gyro_xyz) index=0 shift=12 num_samples=25 value=99395940484ns, (0.000343, -0.000722, -0.000238)
channel type=12(die_temp) index=0 shift=9 num_samples=25 value=99395940484ns (24.934782)
Trigger (10 / fifo_wm) detected
channel type=3(accel_xyz) index=0 shift=9 num_samples=25 value=100394029104ns, (0.093516, -0.191487, 9.808756)
channel type=7(gyro_xyz) index=0 shift=12 num_samples=25 value=100394029104ns, (0.000333, -0.000791, -0.000242)
channel type=12(die_temp) index=0 shift=9 num_samples=25 value=100394029104ns (24.968598)
Trigger (10 / fifo_wm) detected
channel type=3(accel_xyz) index=0 shift=9 num_samples=25 value=101392128157ns, (0.092080, -0.191679, 9.811725)
channel type=7(gyro_xyz) index=0 shift=12 num_samples=25 value=101392128157ns, (0.000482, 0.000495, -0.000291)
channel type=12(die_temp) index=0 shift=9 num_samples=25 value=101392128157ns (24.958936)
Trigger (10 / fifo_wm) detected
channel type=3(accel_xyz) index=0 shift=9 num_samples=25 value=102390202224ns, (0.076278, -0.189620, 9.808947)
channel type=7(gyro_xyz) index=0 shift=12 num_samples=25 value=102390202224ns, (0.000137, -0.000169, -0.000322)
channel type=12(die_temp) index=0 shift=9 num_samples=25 value=102390202224ns (24.903381)
Trigger (10 / fifo_wm) detected
channel type=3(accel_xyz) index=0 shift=9 num_samples=25 value=103388262137ns, (0.076470, -0.190865, 9.810240)
channel type=7(gyro_xyz) index=0 shift=12 num_samples=25 value=103388262137ns, (0.000307, -0.000827, -0.000280)
channel type=12(die_temp) index=0 shift=9 num_samples=25 value=103388262137ns (24.929950)
Trigger (10 / fifo_wm) detected
channel type=3(accel_xyz) index=0 shift=9 num_samples=25 value=104386362624ns, (0.076422, -0.191247, 9.809857)
channel type=7(gyro_xyz) index=0 shift=12 num_samples=25 value=104386362624ns, (0.000322, -0.000684, -0.000188)
channel type=12(die_temp) index=0 shift=9 num_samples=25 value=104386362624ns (24.913042)
uart:~$ sensor stream icm45686@68 off
Disabling existing stream
[00:09:54.434,000] <wrn> ICM45686_STREAM: Callback triggered with no streaming submission - Disabling interrupts
uart:~$ 
  • Scope capture of I2C bus with Streaming mode enabled. Interrupts every 1 sec (Watermark at 25, 25 HZ ODR):
    image

afontaine-invn
afontaine-invn previously approved these changes Apr 17, 2025
teburd
teburd previously approved these changes Apr 17, 2025
@kartben kartben requested a review from Copilot April 18, 2025 10:32
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for I2C bus communication to the ICM45686 sensor driver while updating the SPI code paths to a unified flag (REG_READ_BIT) and enhancing the device tree bindings.

  • Added new I2C device tree bindings and updated SPI binding where applicable.
  • Modified driver code to add I2C-specific handling for read/write operations and conditionally check bus readiness.
  • Introduced an enum to distinguish between SPI and I2C bus types in driver initialization and runtime.

Reviewed Changes

Copilot reviewed 8 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
dts/bindings/sensor/invensense,icm45686-spi.yaml New SPI binding file with updated description and include directives.
dts/bindings/sensor/invensense,icm45686-i2c.yaml New I2C binding file mirroring SPI file with I2C-specific changes.
dts/bindings/sensor/invensense,icm45686-common.yaml Removed redundant description and simplified include directives.
drivers/sensor/tdk/icm45686/icm45686_stream.c Updated read flag usage and added I2C conditional handling in SQE setups.
drivers/sensor/tdk/icm45686/icm45686_reg.h Renamed SPI read flag to REG_READ_BIT to be used across bus types.
drivers/sensor/tdk/icm45686/icm45686_bus.h Updated bus read/write functions with I2C-specific SQE flag additions.
drivers/sensor/tdk/icm45686/icm45686.h Introduced an enum for bus type and added it to the data structure.
drivers/sensor/tdk/icm45686/icm45686.c Added bus type checks for device readiness and used conditional macros.
Files not reviewed (2)
  • drivers/sensor/tdk/icm45686/Kconfig: Language not supported
  • tests/drivers/build_all/sensor/i2c.dtsi: Language not supported
Comments suppressed due to low confidence (2)

drivers/sensor/tdk/icm45686/icm45686_bus.h:39

  • The variable 'data' is used without being defined in this function. Consider retrieving the driver data (e.g. via device_get_drvdata(dev)) before using data->rtio.type.
if (data->rtio.type == ICM45686_BUS_I2C) {

drivers/sensor/tdk/icm45686/icm45686_bus.h:79

  • The same issue occurs here: 'data' is not defined in the function. Ensure that the driver data pointer is obtained before referencing data->rtio.type in the write function.
if (data->rtio.type == ICM45686_BUS_I2C) {

MaureenHelm
MaureenHelm previously approved these changes Apr 21, 2025
@kartben
Copy link
Collaborator

kartben commented Apr 22, 2025

@ubieda please rebase

ubieda added 4 commits April 22, 2025 09:27
To split bus support into separate files. This patch does not introduce
any functionality, but rather precedes a patch introducing I2C bus
support.

Signed-off-by: Luis Ubieda <[email protected]>
So it's generic irrespective to the bus. Tested for I2C and SPI.

Signed-off-by: Luis Ubieda <[email protected]>
Validated for read/decode APIs, as well as Streaming mode (FIFO).

Signed-off-by: Luis Ubieda <[email protected]>
To validate build-time functionality.

Signed-off-by: Luis Ubieda <[email protected]>
@ubieda ubieda dismissed stale reviews from MaureenHelm, teburd, and afontaine-invn via 6a75d69 April 22, 2025 13:29
@ubieda ubieda force-pushed the feature-add-i2c-to-icm45686 branch from 92f063a to 6a75d69 Compare April 22, 2025 13:29
@ubieda
Copy link
Member Author

ubieda commented Apr 22, 2025

Rebased to resolve conflicts in tests/drivers/build_all/sensor/i2c.dtsi

@kartben kartben merged commit 150cd56 into zephyrproject-rtos:main Apr 23, 2025
24 checks passed
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.

5 participants