diff --git a/bsp/stm32/stm32l431-BearPi/board/Kconfig b/bsp/stm32/stm32l431-BearPi/board/Kconfig index 3db4cc62c5..8043ca769c 100644 --- a/bsp/stm32/stm32l431-BearPi/board/Kconfig +++ b/bsp/stm32/stm32l431-BearPi/board/Kconfig @@ -182,6 +182,14 @@ menu "Onboard Peripheral Drivers" imply RTDUINO_USING_WIRE imply RTDUINO_USING_SPI default n + + config BSP_USING_MPU6050 + bool "Enable MPU6050 to read accel data" + select BSP_USING_I2C + select BSP_USING_I2C1 + select PKG_USING_MPU6XXX + default n + endmenu endmenu diff --git a/bsp/stm32/stm32l431-BearPi/board/SConscript b/bsp/stm32/stm32l431-BearPi/board/SConscript index 0abd516819..2c0c4321fc 100644 --- a/bsp/stm32/stm32l431-BearPi/board/SConscript +++ b/bsp/stm32/stm32l431-BearPi/board/SConscript @@ -15,6 +15,9 @@ CubeMX_Config/Src/stm32l4xx_hal_msp.c if GetDepend('BSP_USING_SPI_LCD'): src += ['ports/lcd/drv_lcd.c'] +if GetDepend('BSP_USING_MPU6050'): + src += ['ports/mpu6050_meas.c'] + path = [cwd] path += [cwd + '/CubeMX_Config/Inc'] path += [cwd + '/ports/lcd'] diff --git a/bsp/stm32/stm32l431-BearPi/board/ports/mpu6050_meas.c b/bsp/stm32/stm32l431-BearPi/board/ports/mpu6050_meas.c new file mode 100644 index 0000000000..2e6f855958 --- /dev/null +++ b/bsp/stm32/stm32l431-BearPi/board/ports/mpu6050_meas.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2006-2023, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2023-09-19 liYony first version + */ + +#include +#include "mpu6xxx.h" + +#define DBG_TAG "mpu6050" +#define DBG_LVL DBG_LOG +#include + +#define MPU6050_DEVICE_NAME "i2c1" + +static void mpu6050_accel_entry(void *parameter) +{ + struct mpu6xxx_device *dev; + struct mpu6xxx_3axes accel; + + /* Initialize mpu6050, The parameter is RT_NULL, means auto probing for i2c*/ + dev = mpu6xxx_init(MPU6050_DEVICE_NAME, RT_NULL); + + if (dev == RT_NULL) + { + LOG_E("mpu6050 init failed."); + return; + } + LOG_I("mpu6050 init succeed."); + + while(1) + { + mpu6xxx_get_accel(dev, &accel); + + LOG_D("accel.x = %3d, accel.y = %3d, accel.z = %3d", accel.x, accel.y, accel.z); + + rt_thread_mdelay(1000); + } +} + +static int rt_hw_mpu6050_init() +{ + rt_thread_t tid_mpu; + + tid_mpu = rt_thread_create("mpu_accel", mpu6050_accel_entry, RT_NULL, 1024, 10, 10); + if (tid_mpu == RT_NULL) + { + return -RT_ERROR; + } + + rt_thread_startup(tid_mpu); + + return RT_EOK; +} + +INIT_APP_EXPORT(rt_hw_mpu6050_init);