[bsp][stm32] BearPi 支持 MPU6050 模块

This commit is contained in:
liYony 2023-09-19 23:18:54 +08:00 committed by Meco Man
parent 35231eb116
commit 2ff1a1a4c9
3 changed files with 71 additions and 0 deletions

View File

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

View File

@ -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']

View File

@ -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 <rtthread.h>
#include "mpu6xxx.h"
#define DBG_TAG "mpu6050"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>
#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);