From 7a976925d27137aac7e9d431ec73316bb8adc09e Mon Sep 17 00:00:00 2001 From: "Guilherme S. Salustiano" Date: Wed, 1 Nov 2023 17:11:40 +0100 Subject: [PATCH] boards: thingy52: add missing mpu9250 support The Thingy:52 has a mpu9250, a 9 axis motion sensor, on the I2C bus. Add the necessary description on devicetree and config the mpu_pwr regulator. Signed-off-by: Guilherme S. Salustiano --- boards/arm/thingy52_nrf52832/board.c | 30 +++++++++++++++++-- .../thingy52_nrf52832/thingy52_nrf52832.dts | 13 ++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/boards/arm/thingy52_nrf52832/board.c b/boards/arm/thingy52_nrf52832/board.c index a6a3fec782e592c..ca7b1725d934403 100644 --- a/boards/arm/thingy52_nrf52832/board.c +++ b/boards/arm/thingy52_nrf52832/board.c @@ -11,7 +11,7 @@ static const struct gpio_dt_spec ccs_gpio = GPIO_DT_SPEC_GET(DT_NODELABEL(ccs_pwr), enable_gpios); -static int pwr_ctrl_init(void) +static int ccs_pwr_ctrl_init(void) { int ret; @@ -24,7 +24,28 @@ static int pwr_ctrl_init(void) return ret; } - k_sleep(K_MSEC(1)); /* Wait for the rail to come up and stabilize */ + k_sleep(K_MSEC(100)); /* Wait for the rail to come up and stabilize */ + + return 0; +} + +static const struct gpio_dt_spec mpu_gpio = + GPIO_DT_SPEC_GET(DT_NODELABEL(mpu_pwr), enable_gpios); + +static int mpu_pwr_ctrl_init(void) +{ + int ret; + + if (!gpio_is_ready_dt(&imu_gpio)) { + return -ENODEV; + } + + ret = gpio_pin_configure_dt(&imu_gpio, GPIO_OUTPUT_HIGH); + if (ret < 0) { + return ret; + } + + k_sleep(K_MSEC(100)); /* Wait for the rail to come up and stabilize */ return 0; } @@ -34,5 +55,8 @@ static int pwr_ctrl_init(void) #error BOARD_CCS_VDD_PWR_CTRL_INIT_PRIORITY must be lower than SENSOR_INIT_PRIORITY #endif -SYS_INIT(pwr_ctrl_init, POST_KERNEL, +SYS_INIT(ccs_pwr_ctrl_init, POST_KERNEL, + CONFIG_BOARD_CCS_VDD_PWR_CTRL_INIT_PRIORITY); + +SYS_INIT(imu_pwr_ctrl_init, POST_KERNEL, CONFIG_BOARD_CCS_VDD_PWR_CTRL_INIT_PRIORITY); diff --git a/boards/arm/thingy52_nrf52832/thingy52_nrf52832.dts b/boards/arm/thingy52_nrf52832/thingy52_nrf52832.dts index dea1e43fad510be..22d7efdeb1136b9 100644 --- a/boards/arm/thingy52_nrf52832/thingy52_nrf52832.dts +++ b/boards/arm/thingy52_nrf52832/thingy52_nrf52832.dts @@ -171,6 +171,19 @@ reset-gpios = <&sx1509b 11 GPIO_ACTIVE_LOW>; wake-gpios = <&sx1509b 12 GPIO_ACTIVE_LOW>; }; + + mpu9250: mpu9250@68 { + compatible = "invensense,mpu9250"; + reg = <0x68>; + vin-supply = <&mpu_pwr>; + status = "okay"; + irq-gpios = <&gpio0 06 GPIO_ACTIVE_HIGH>; + gyro-sr-div = <10>; + gyro-dlpf = <5>; + gyro-fs = <250>; + accel-fs = <2>; + accel-dlpf="5.05"; + }; }; &i2c1 {