cun
This commit is contained in:
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -3,6 +3,8 @@
|
||||
"board_config.h": "c",
|
||||
"board_jl701n_demo_cfg.h": "c",
|
||||
"colorful_lights.h": "c",
|
||||
"board_jl701n_anc_cfg.h": "c"
|
||||
"board_jl701n_anc_cfg.h": "c",
|
||||
"update_loader_download.h": "c",
|
||||
"iic_soft.h": "c"
|
||||
}
|
||||
}
|
||||
3
Makefile
3
Makefile
@ -245,6 +245,7 @@ INCLUDES := \
|
||||
-Iinclude_lib/media/aispeech/enc/include \
|
||||
-Icpu/br28/audio_hearing \
|
||||
-Iinclude_lib/media/cvp \
|
||||
-Iapps/earphone/xtell_Sensor \
|
||||
-I$(SYS_INC_DIR) \
|
||||
|
||||
|
||||
@ -609,6 +610,8 @@ c_SRC_FILES := \
|
||||
cpu/br28/uart_dev.c \
|
||||
cpu/br28/umidigi_chargestore.c \
|
||||
apps/common/colorful_lights/colorful_lights.c \
|
||||
apps/earphone/xtell_Sensor/LIS2DH12.c \
|
||||
apps/earphone/xtell_Sensor/main.c \
|
||||
|
||||
|
||||
# 需要编译的 .S 文件
|
||||
|
||||
@ -38,7 +38,7 @@ extern int gsensorlen;
|
||||
extern OS_MUTEX SENSOR_IIC_MUTEX;
|
||||
|
||||
|
||||
extern spinlock_t sensor_iic;
|
||||
// extern spinlock_t sensor_iic;
|
||||
extern u8 sensor_iic_init_status;
|
||||
|
||||
#define BUF_SIZE gsensorlen*3
|
||||
@ -201,7 +201,7 @@ void write_gsensor_data_handle(void)
|
||||
}
|
||||
u8 gravity_sensor_command(u8 w_chip_id, u8 register_address, u8 function_command)
|
||||
{
|
||||
spin_lock(&sensor_iic);
|
||||
// spin_lock(&sensor_iic);
|
||||
/* os_mutex_pend(&SENSOR_IIC_MUTEX,0); */
|
||||
u8 ret = 1;
|
||||
iic_start(gSensor_info->iic_hdl);
|
||||
@ -229,7 +229,7 @@ u8 gravity_sensor_command(u8 w_chip_id, u8 register_address, u8 function_command
|
||||
|
||||
__gcend:
|
||||
iic_stop(gSensor_info->iic_hdl);
|
||||
spin_unlock(&sensor_iic);
|
||||
// spin_unlock(&sensor_iic);
|
||||
/* os_mutex_post(&SENSOR_IIC_MUTEX); */
|
||||
return ret;
|
||||
}
|
||||
@ -237,7 +237,7 @@ __gcend:
|
||||
u8 _gravity_sensor_get_ndata(u8 r_chip_id, u8 register_address, u8 *buf, u8 data_len)
|
||||
{
|
||||
// printf("%s",__func__);
|
||||
spin_lock(&sensor_iic);
|
||||
// spin_lock(&sensor_iic);
|
||||
/* os_mutex_pend(&SENSOR_IIC_MUTEX,0); */
|
||||
u8 read_len = 0;
|
||||
|
||||
@ -277,7 +277,7 @@ __gdend:
|
||||
|
||||
iic_stop(gSensor_info->iic_hdl);
|
||||
delay(gSensor_info->iic_delay);
|
||||
spin_unlock(&sensor_iic);
|
||||
// spin_unlock(&sensor_iic);
|
||||
|
||||
/* os_mutex_post(&SENSOR_IIC_MUTEX); */
|
||||
return read_len;
|
||||
@ -292,7 +292,7 @@ int gravity_sensor_init(void *_data)
|
||||
|
||||
|
||||
if (sensor_iic_init_status == 0) {
|
||||
spin_lock_init(&sensor_iic);
|
||||
// spin_lock_init(&sensor_iic);
|
||||
sensor_iic_init_status = 1;
|
||||
}
|
||||
gSensor_info->init_flag = 0;
|
||||
|
||||
@ -312,6 +312,9 @@ void app_main()
|
||||
set_charge_event_flag(1);
|
||||
#endif
|
||||
|
||||
void xtell_main(void);
|
||||
xtell_main();
|
||||
|
||||
}
|
||||
|
||||
int __attribute__((weak)) eSystemConfirmStopStatus(void)
|
||||
|
||||
@ -29,9 +29,9 @@
|
||||
//*********************************************************************************//
|
||||
// IIC配置 //
|
||||
//*********************************************************************************//
|
||||
/*软件IIC设置*/
|
||||
#define TCFG_SW_I2C0_CLK_PORT IO_PORTG_07 //软件IIC CLK脚选择
|
||||
#define TCFG_SW_I2C0_DAT_PORT IO_PORTG_08 //软件IIC DAT脚选择
|
||||
/*软件IIC设置*/ //xtell
|
||||
#define TCFG_SW_I2C0_CLK_PORT IO_PORTA_05 //软件IIC CLK脚选择 XTELL
|
||||
#define TCFG_SW_I2C0_DAT_PORT IO_PORTA_06 //软件IIC DAT脚选择
|
||||
#define TCFG_SW_I2C0_DELAY_CNT 10 //IIC延时参数,影响通讯时钟频率
|
||||
|
||||
/*硬件IIC端口选择
|
||||
@ -48,9 +48,9 @@
|
||||
// 硬件SPI 配置 //
|
||||
//*********************************************************************************//
|
||||
#define TCFG_HW_SPI1_ENABLE 1
|
||||
#define TCFG_HW_SPI1_PORT_CLK IO_PORTC_04//IO_PORTA_00
|
||||
#define TCFG_HW_SPI1_PORT_CLK 0//IO_PORTC_04//IO_PORTA_00 xtellio
|
||||
#define TCFG_HW_SPI1_PORT_DO IO_PORTC_05//IO_PORTA_01
|
||||
#define TCFG_HW_SPI1_PORT_DI IO_PORTC_03//IO_PORTA_02
|
||||
#define TCFG_HW_SPI1_PORT_DI 0//IO_PORTC_03//IO_PORTA_02 xtellio
|
||||
#define TCFG_HW_SPI1_BAUD 2400000L
|
||||
#define TCFG_HW_SPI1_MODE SPI_MODE_BIDIR_1BIT
|
||||
#define TCFG_HW_SPI1_ROLE SPI_ROLE_MASTER
|
||||
@ -72,9 +72,9 @@
|
||||
#define TCFG_SD0_DET_IO IO_PORTB_03 //当检测方式为IO检测可用
|
||||
#define TCFG_SD0_DET_IO_LEVEL 0 //当检测方式为IO检测可用,0:低电平检测到卡。 1:高电平(外部电源)检测到卡。 2:高电平(SD卡电源)检测到卡。
|
||||
#define TCFG_SD0_CLK (3000000 * 4L) //SD卡时钟频率设置
|
||||
#define TCFG_SD0_PORT_CMD IO_PORTC_04
|
||||
#define TCFG_SD0_PORT_CMD NULL//IO_PORTC_04 //xtellio
|
||||
#define TCFG_SD0_PORT_CLK IO_PORTC_05
|
||||
#define TCFG_SD0_PORT_DA0 IO_PORTC_03
|
||||
#define TCFG_SD0_PORT_DA0 0//IO_PORTC_03 //xtellio
|
||||
#define TCFG_SD0_PORT_DA1 NO_CONFIG_PORT //当选择4线模式时要用
|
||||
#define TCFG_SD0_PORT_DA2 NO_CONFIG_PORT
|
||||
#define TCFG_SD0_PORT_DA3 NO_CONFIG_PORT
|
||||
@ -101,16 +101,16 @@
|
||||
|
||||
#define MULT_KEY_ENABLE 1//DISABLE //是否使能组合按键消息, 使能后需要配置组合按键映射表
|
||||
|
||||
#define TCFG_KEY_TONE_EN DISABLE // 按键提示音。
|
||||
#define TCFG_KEY_TONE_EN ENABLE//DISABLE xtell // 按键提示音。
|
||||
|
||||
//*********************************************************************************//
|
||||
// iokey 配置 //
|
||||
//*********************************************************************************//
|
||||
#define TCFG_IOKEY_ENABLE ENABLE_THIS_MOUDLE //是否使能IO按键
|
||||
#define TCFG_IOKEY_ENABLE DISABLE_THIS_MOUDLE//ENABLE_THIS_MOUDLE //是否使能IO按键 xtellio
|
||||
|
||||
#define TCFG_IOKEY_POWER_CONNECT_WAY ONE_PORT_TO_LOW //按键一端接低电平一端接IO
|
||||
|
||||
#define TCFG_IOKEY_POWER_ONE_PORT IO_PORTB_01 //IO按键端口
|
||||
#define TCFG_IOKEY_POWER_ONE_PORT NULL//IO_PORTG_05//IO_PORTB_01 //xtellio //IO按键端口
|
||||
|
||||
//*********************************************************************************//
|
||||
// adkey 配置 //
|
||||
@ -287,7 +287,7 @@
|
||||
|
||||
//RDEC2配置
|
||||
#define TCFG_RDEC2_ECODE1_PORT IO_PORTB_00
|
||||
#define TCFG_RDEC2_ECODE2_PORT IO_PORTB_01
|
||||
#define TCFG_RDEC2_ECODE2_PORT NULL//IO_PORTG_05 //IO_PORTB_01 xtellio
|
||||
#define TCFG_RDEC2_KEY0_VALUE 4
|
||||
#define TCFG_RDEC2_KEY1_VALUE 5
|
||||
|
||||
@ -295,9 +295,11 @@
|
||||
// Digital Hearing Aid(DHA)辅听耳机配置 //
|
||||
//*********************************************************************************//
|
||||
/*辅听功能使能*/
|
||||
// #define TCFG_AUDIO_HEARING_AID_ENABLE DISABLE_THIS_MOUDLE
|
||||
#define TCFG_AUDIO_HEARING_AID_ENABLE DISABLE_THIS_MOUDLE
|
||||
|
||||
/*听力验配功能*/
|
||||
#define TCFG_AUDIO_DHA_FITTING_ENABLE DISABLE
|
||||
#define TCFG_AUDIO_DHA_FITTING_ENABLE DISABLE //DISABLE
|
||||
/*辅听功能互斥配置*/
|
||||
#define TCFG_AUDIO_DHA_AND_MUSIC_MUTEX ENABLE //辅听功能和音乐播放互斥(默认互斥,资源有限)
|
||||
#define TCFG_AUDIO_DHA_AND_CALL_MUTEX ENABLE //辅听功能和通话互斥(默认互斥,资源有限)
|
||||
@ -365,7 +367,7 @@ DAC硬件上的连接方式,可选的配置:
|
||||
#define DAC_MODE_H2_DIFF (4) // 高压2档差分模式, 适用于高功率差分PA音箱, 输出幅度 0~5Vpp , VDDIO >= 3.3V
|
||||
#define DAC_MODE_H2_SINGLE (5) // 高压2档单端模式, 适用于高功率单端PA音箱, 输出幅度 0~2.5Vpp, VDDIO >= 3.3V
|
||||
*/
|
||||
#define TCFG_AUDIO_DAC_MODE DAC_MODE_L_DIFF // DAC_MODE_L_DIFF 低压, DAC_MODE_H1_DIFF 高压
|
||||
#define TCFG_AUDIO_DAC_MODE DAC_MODE_L_DIFF // DAC_MODE_L_DIFF 低压, DAC_MODE_H1_DIFF 高压 xtell
|
||||
|
||||
|
||||
/*预留接口,未使用*/
|
||||
@ -449,7 +451,7 @@ DAC硬件上的连接方式,可选的配置:
|
||||
#if (TCFG_AUDIO_ANC_ENABLE || TCFG_AD2DA_LOW_LATENCY_ENABLE || TCFG_AUDIO_HEARING_AID_ENABLE)
|
||||
#define SYS_VOL_TYPE VOL_TYPE_DIGITAL
|
||||
#else
|
||||
#define SYS_VOL_TYPE VOL_TYPE_DIGITAL_HW
|
||||
#define SYS_VOL_TYPE VOL_TYPE_DIGITAL //xtell
|
||||
#endif/*TCFG_AUDIO_ANC_ENABLE*/
|
||||
/*
|
||||
*通话的时候使用数字音量
|
||||
@ -628,7 +630,7 @@ DAC硬件上的连接方式,可选的配置:
|
||||
#define TCFG_AEC_TOOL_ONLINE_ENABLE DISABLE_THIS_MOUDLE
|
||||
|
||||
/*麦克风测试和传递函数测试*/
|
||||
#define TCFG_AUDIO_MIC_DUT_ENABLE DISABLE_THIS_MOUDLE
|
||||
#define TCFG_AUDIO_MIC_DUT_ENABLE DISABLE_THIS_MOUDLE //xtell
|
||||
|
||||
//*********************************************************************************//
|
||||
// Audio Smart Voice //
|
||||
@ -671,7 +673,7 @@ DAC硬件上的连接方式,可选的配置:
|
||||
//*********************************************************************************//
|
||||
// Spatial Audio Effect 空间音效配置 //
|
||||
//*********************************************************************************//
|
||||
#define TCFG_AUDIO_SPATIAL_EFFECT_ENABLE DISABLE_THIS_MOUDLE
|
||||
#define TCFG_AUDIO_SPATIAL_EFFECT_ENABLE DISABLE_THIS_MOUDLE //xtell
|
||||
#define TCFG_TWS_SPATIAL_AUDIO_AS_CHANNEL 'L'
|
||||
|
||||
/*独立任务里面跑空间音效*/
|
||||
@ -907,9 +909,9 @@ DAC硬件上的连接方式,可选的配置:
|
||||
//*********************************************************************************//
|
||||
// g-sensor配置 //
|
||||
//*********************************************************************************//
|
||||
#define TCFG_GSENSOR_ENABLE 0 //gSensor使能
|
||||
#define TCFG_GSENSOR_ENABLE 0//1 //gSensor使能
|
||||
#define TCFG_DA230_EN 0
|
||||
#define TCFG_SC7A20_EN 0
|
||||
#define TCFG_SC7A20_EN 0 //0 //xtell
|
||||
#define TCFG_STK8321_EN 0
|
||||
#define TCFG_IRSENSOR_ENABLE 0
|
||||
#define TCFG_JSA1221_ENABLE 0
|
||||
@ -925,7 +927,7 @@ DAC硬件上的连接方式,可选的配置:
|
||||
#define TCFG_MPU6887P_USER_IIC_TYPE 0 //iic有效:1:硬件iic, 0:软件iic
|
||||
#define TCFG_MPU6887P_USER_IIC_INDEX 0 //IIC 序号
|
||||
#define TCFG_MPU6887P_DETECT_IO (-1) //传感器中断io
|
||||
#define TCFG_MPU6887P_AD0_SELETE_IO IO_PORTC_03 //iic地址选择io
|
||||
#define TCFG_MPU6887P_AD0_SELETE_IO 0//IO_PORTC_03 //iic地址选择io xtellio
|
||||
//icm42607p cfg
|
||||
#define TCFG_ICM42670P_ENABLE 1
|
||||
#define TCFG_ICM42670P_INTERFACE_TYPE 0 //0:iic, 1:spi
|
||||
@ -960,14 +962,14 @@ DAC硬件上的连接方式,可选的配置:
|
||||
#define TCFG_LSM6DSL_DETECT_IO (-1) //传感器中断io
|
||||
#define TCFG_LSM6DSL_AD0_SELETE_IO (-1) //iic地址选择io
|
||||
//mpu6050 cfg
|
||||
#define TCFG_MPU6050_EN 0
|
||||
#define TCFG_MPU6050_EN 0 //xtell
|
||||
//qmc5883 cfg
|
||||
|
||||
/*
|
||||
*imu-sensor power manager
|
||||
*不用独立IO供电,则配置 NO_CONFIG_PORT
|
||||
*/
|
||||
#define TCFG_IMU_SENSOR_PWR_PORT IO_PORTG_05
|
||||
#define TCFG_IMU_SENSOR_PWR_PORT NO_CONFIG_PORT
|
||||
|
||||
|
||||
/*空间音效和传感器的依赖*/
|
||||
@ -993,15 +995,15 @@ DAC硬件上的连接方式,可选的配置:
|
||||
//*********************************************************************************//
|
||||
// 系统配置 //
|
||||
//*********************************************************************************//
|
||||
#define TCFG_AUTO_SHUT_DOWN_TIME 180 //没有蓝牙连接自动关机时间
|
||||
#define TCFG_AUTO_SHUT_DOWN_TIME 0 //180 //没有蓝牙连接自动关机时间,0 表示关闭系统自动关机 xtellbt
|
||||
#define TCFG_SYS_LVD_EN 1 //电量检测使能
|
||||
#define TCFG_POWER_ON_NEED_KEY 0 //是否需要按按键开机配置
|
||||
#define TWFG_APP_POWERON_IGNORE_DEV 0 //上电忽略挂载设备,0时不忽略,非0则n毫秒忽略
|
||||
#define TWFG_APP_POWERON_IGNORE_DEV 0 //上电忽略挂载设备,0时不忽略,非0则n毫秒忽略
|
||||
|
||||
//*********************************************************************************//
|
||||
// 蓝牙配置 //
|
||||
//*********************************************************************************//
|
||||
#define TCFG_USER_TWS_ENABLE 0 //tws功能使能
|
||||
#define TCFG_USER_TWS_ENABLE 0 //tws功能使能
|
||||
#define TCFG_USER_BLE_ENABLE 1 //BLE功能使能
|
||||
#define TCFG_BT_SUPPORT_AAC 1 //AAC格式支持
|
||||
#define TCFG_BT_SUPPORT_LDAC 0 //LDAC格式支持
|
||||
@ -1025,7 +1027,7 @@ DAC硬件上的连接方式,可选的配置:
|
||||
#define TCFG_AUTO_STOP_PAGE_SCAN_TIME 0 //配置一拖二第一台连接后自动关闭PAGE SCAN的时间(单位分钟)
|
||||
#else
|
||||
#define TCFG_BD_NUM 1 //连接设备个数配置
|
||||
#define TCFG_AUTO_STOP_PAGE_SCAN_TIME 0 //配置一拖二第一台连接后自动关闭PAGE SCAN的时间(单位分钟)
|
||||
#define TCFG_AUTO_STOP_PAGE_SCAN_TIME 0 //配置一拖二第一台连接后自动关闭PAGE SCAN的时间(单位分钟)
|
||||
#endif
|
||||
|
||||
#define BT_INBAND_RINGTONE 1 //是否播放手机自带来电铃声
|
||||
@ -1123,7 +1125,7 @@ DAC硬件上的连接方式,可选的配置:
|
||||
//*********************************************************************************//
|
||||
#if TCFG_USER_BLE_ENABLE
|
||||
#define DUEROS_DMA_EN 0
|
||||
#define TRANS_DATA_EN 1
|
||||
#define TRANS_DATA_EN 0//1 //xtellota
|
||||
#define BLE_HID_EN 0
|
||||
|
||||
#if (DUEROS_DMA_EN)
|
||||
|
||||
@ -5,10 +5,10 @@
|
||||
* 系统打印总开关
|
||||
*/
|
||||
|
||||
#define LIB_DEBUG 1
|
||||
#define LIB_DEBUG 1 //1 //xtelllog 1是打开库打印
|
||||
#define CONFIG_DEBUG_LIB(x) (x & LIB_DEBUG)
|
||||
|
||||
#define CONFIG_DEBUG_ENABLE
|
||||
#define CONFIG_DEBUG_ENABLE //xtelllog 注释就关闭log
|
||||
|
||||
#ifndef CONFIG_DEBUG_ENABLE
|
||||
//#define CONFIG_DEBUG_LITE_ENABLE //轻量级打印开关, 默认关闭
|
||||
@ -18,7 +18,7 @@
|
||||
//*********************************************************************************//
|
||||
// AI配置 //
|
||||
//*********************************************************************************//
|
||||
// #define CONFIG_APP_BT_ENABLE
|
||||
#define CONFIG_APP_BT_ENABLE
|
||||
|
||||
#ifdef CONFIG_APP_BT_ENABLE
|
||||
#define TRANS_DATA_EN 0
|
||||
@ -68,8 +68,8 @@
|
||||
#define OTA_TWS_SAME_TIME_ENABLE 1 //是否支持TWS同步升级
|
||||
#define OTA_TWS_SAME_TIME_NEW 1 //使用新的tws ota流程
|
||||
#else
|
||||
#define OTA_TWS_SAME_TIME_ENABLE 0 //是否支持TWS同步升级
|
||||
#define OTA_TWS_SAME_TIME_NEW 0 //使用新的tws ota流程
|
||||
#define OTA_TWS_SAME_TIME_ENABLE 1//0 xtellota //是否支持TWS同步升级
|
||||
#define OTA_TWS_SAME_TIME_NEW 1//0 //使用新的tws ota流程
|
||||
#endif //CONFIG_DOUBLE_BANK_ENABLE
|
||||
#else
|
||||
#define RCSP_UPDATE_EN 0 //是否支持rcsp升级
|
||||
@ -203,7 +203,7 @@
|
||||
|
||||
/* #undef TCFG_UART0_ENABLE
|
||||
#define TCFG_UART0_ENABLE DISABLE_THIS_MOUDLE */
|
||||
|
||||
dzfghsdfhgsfgh
|
||||
#endif //(CONFIG_BT_MODE != BT_NORMAL)
|
||||
|
||||
|
||||
|
||||
510
apps/earphone/xtell_Sensor/LIS2DH12.c
Normal file
510
apps/earphone/xtell_Sensor/LIS2DH12.c
Normal file
@ -0,0 +1,510 @@
|
||||
//LIS2DH12驱动
|
||||
#include "gSensor/gSensor_manage.h"
|
||||
#include "app_config.h"
|
||||
#include "math.h"
|
||||
#include "LIS2DH12.h"
|
||||
#include "colorful_lights/colorful_lights.h"
|
||||
#include <string.h> // For memcpy
|
||||
|
||||
#define ENABLE_XLOG 1
|
||||
#ifdef xlog
|
||||
#undef xlog
|
||||
#endif
|
||||
#if ENABLE_XLOG
|
||||
#define xlog(format, ...) printf("[%s] " format, __func__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define xlog(format, ...) ((void)0)
|
||||
#endif
|
||||
|
||||
|
||||
// #define SAMPLE_COUNT 25 // 定义静止状态检测所需的样本数量
|
||||
#define SAMPLE_COUNT 6 // 定义静止状态检测所需的样本数量
|
||||
// #define THRESHOLD 2.00f // 定义静止状态检测的阈值,单位g
|
||||
#define THRESHOLD 10.00f // 定义静止状态检测的阈值, 三轴传感器数据的方差
|
||||
#define STATIC_MAX_TIME 60*5*5 //传感器静止最大时间,单位 200ms ,超过这个值就发数据通知AI询问用户是否需要帮助
|
||||
#define DORMANCY_MAX_TIME 60*5 //三个角度超过一分钟没有更新就关闭当前灯效,如果有数据刷新就恢复之前的灯效,单位200ms
|
||||
u8 dormancy_flag = 0; //标识
|
||||
u8 dormancy_ago_moedl = 0; //记录休眠前灯效
|
||||
u16 gsensor_static_flag; //记录传感器静止的时间,单位 200ms
|
||||
axis_info_t current_data[32]; // 全局变量存储当前数据
|
||||
|
||||
|
||||
|
||||
// Global variables for motion data
|
||||
static motion_data_t motion_data = {{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}}; // 存储运动数据
|
||||
static axis_info_xtell gravity_vector = {0.0f, 0.0f, 0.0f};// 存储估算的重力方向
|
||||
static bool sensor_is_stable = false;
|
||||
|
||||
|
||||
u8 gsensor_alarm;
|
||||
// u8 xtell_uart_Gsensor_static[5]={0xAA,0x55,0x0F,0x55,0xAA}; //发现用户长时间静止时,串口发数据给AI芯片
|
||||
|
||||
|
||||
// 假设当前设置的满量程范围
|
||||
const scale_t CURRENT_SCALE = SCALE_8G;
|
||||
#define LIS2DH12_FROM_FS_8g_HR_TO_mg(lsb) (float)((int16_t)lsb>>4) * 4.0f
|
||||
axis_info_xtell gsensor_xtell;
|
||||
|
||||
|
||||
/***使用驱动前请根据实际接线情况配置(7bit)IIC地址******/
|
||||
/** LIS2DH12 的SDO 脚接地: 0x30****************/
|
||||
/** LIS2DH12 的SDO 脚接电源: 0x31****************/
|
||||
// #define LIS2DH12_W_ADDR (0x31U << 1 | 0x0)
|
||||
// #define LIS2DH12_R_ADDR (0x31U << 1 | 0x1)
|
||||
#define LIS2DH12_W_ADDR 0x32
|
||||
#define LIS2DH12_R_ADDR 0x33
|
||||
|
||||
/**IIC 寄存器地址宏定义***************/
|
||||
#define LIS2DH12_OUT_TEMP_L 0x0C //温度数据低位
|
||||
#define LIS2DH12_OUT_TEMP_H 0x0D //温度数据高位
|
||||
#define LIS2DH12_WHO_AM_I 0x0F //读IIC寄存器 自身地址的值,正确应该是0x33
|
||||
#define LIS2DH12_CTRL_RGE0 0x1E //设置SDO 内部上/下拉
|
||||
#define LIS2DH12_TEMP_CFG_REG 0x1F //使能温度传感器
|
||||
#define LIS2DH12_CTRL_REG1 0x20
|
||||
#define LIS2DH12_CTRL_REG2 0x21
|
||||
#define LIS2DH12_CTRL_REG3 0x22
|
||||
#define LIS2DH12_CTRL_REG4 0x23
|
||||
#define LIS2DH12_CTRL_REG5 0x24
|
||||
#define LIS2DH12_CTRL_REG6 0x25
|
||||
#define LIS2DH12_REFERENCE 0x26
|
||||
#define LIS2DH12_STATUS_REG 0x27
|
||||
#define LIS2DH12_OUT_X_L 0x28
|
||||
#define LIS2DH12_OUT_X_H 0x29
|
||||
#define LIS2DH12_OUT_Y_L 0x2A
|
||||
#define LIS2DH12_OUT_Y_H 0x2B
|
||||
#define LIS2DH12_OUT_Z_L 0x2C
|
||||
#define LIS2DH12_OUT_Z_H 0x2D
|
||||
#define LIS2DH12_FIFO_CTRL_REG 0x2E
|
||||
#define LIS2DH12_SRC_REG 0x2F
|
||||
#define LIS2DH12_INT1_CFG 0x30
|
||||
#define LIS2DH12_INT1_SRC 0x31
|
||||
#define LIS2DH12_INT1_THS 0x32
|
||||
#define LIS2DH12_INT1_DURATION 0x33
|
||||
#define LIS2DH12_INT2_CFG 0x34
|
||||
#define LIS2DH12_INT2_SRC 0x35
|
||||
#define LIS2DH12_INT2_THS 0x36
|
||||
#define LIS2DH12_INT2_DURATION 0x37
|
||||
#define LIS2DH12_CLICK_CFG 0x38
|
||||
#define LIS2DH12_CLICK_SRC 0x39
|
||||
#define LIS2DH12_CLICK_THS 0x3A
|
||||
#define LIS2DH12_TIME_LIMIT 0x3B
|
||||
#define LIS2DH12_TIME_LATENCY 0x3C
|
||||
#define LIS2DH12_TIME_WINDOW 0x3D
|
||||
#define LIS2DH12_ACT_THS 0x3E
|
||||
#define LIS2DH12_ACT_DUR 0x3F
|
||||
|
||||
u32 SL_MEMS_i2cRead(u8 addr, u8 reg, u8 len, u8 *buf)
|
||||
{
|
||||
return _gravity_sensor_get_ndata(addr, reg, buf, len);
|
||||
}
|
||||
u8 SL_MEMS_i2cWrite(u8 addr, u8 reg, u8 data)
|
||||
{
|
||||
gravity_sensor_command(addr, reg, data);
|
||||
return 0;
|
||||
}
|
||||
/***传感器校验 读 读IIC寄存器 自身地址的值*/
|
||||
char LIS2DH12_Check()
|
||||
{
|
||||
u8 reg_value = 0;
|
||||
SL_MEMS_i2cRead(LIS2DH12_R_ADDR, LIS2DH12_WHO_AM_I, 1, ®_value);
|
||||
xlog("xtell LIS2DH12_Check: reg WHO_AM_I value = %x H\n", reg_value);
|
||||
if (reg_value == 0x33) {
|
||||
return 0x01;
|
||||
} else {
|
||||
return 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
传感器配置 初始化
|
||||
*/
|
||||
u8 LIS2DH12_Config(void)
|
||||
{
|
||||
u8 Check_Flag = 0;
|
||||
u8 write_num = 0, i = 0;
|
||||
|
||||
// u8 ODR = 0x77; //数据速率400HZ, 正常模式(低功耗-> 0x7F)
|
||||
u8 ODR = 0x37; //速率25hz,
|
||||
u8 HP = 0x03; //开启高通滤波 HPCF位对应的表格没找到
|
||||
// u8 click_int = 0x04; //将Click中断映射到INT1 OVERRUN
|
||||
u8 range = 0xA0; //8g量程,块使能,正常模式(10位数据)
|
||||
u8 fifo_en = 0x40; //使能FIFO模式
|
||||
u8 fifo_mode = 0x80;//0x40; //流模式
|
||||
// u8 click_mode = 0x15; //单击3轴触发
|
||||
|
||||
Check_Flag = LIS2DH12_Check();
|
||||
if (Check_Flag == 1) {
|
||||
// SL_MEMS_i2cWrite(LIS2DH12_W_ADDR, LIS2DH12_TEMP_CFG_REG, 0xC0); //开启温度传感器
|
||||
SL_MEMS_i2cWrite(LIS2DH12_W_ADDR, LIS2DH12_CTRL_REG1, ODR);
|
||||
SL_MEMS_i2cWrite(LIS2DH12_W_ADDR, LIS2DH12_CTRL_REG2, HP);
|
||||
// SL_MEMS_i2cWrite(LIS2DH12_W_ADDR, LIS2DH12_CTRL_REG3, click_int);// 中断的使能,默认都是禁用
|
||||
SL_MEMS_i2cWrite(LIS2DH12_W_ADDR, LIS2DH12_CTRL_REG4, range); //
|
||||
SL_MEMS_i2cWrite(LIS2DH12_W_ADDR, LIS2DH12_CTRL_REG5, fifo_en);
|
||||
SL_MEMS_i2cWrite(LIS2DH12_W_ADDR, LIS2DH12_FIFO_CTRL_REG, fifo_mode);
|
||||
/*
|
||||
SL_MEMS_i2cWrite(LIS2DH12_W_ADDR, LIS2DH12_CLICK_CFG, click_mode);//单Z轴
|
||||
SL_MEMS_i2cWrite(LIS2DH12_W_ADDR, LIS2DH12_CLICK_THS, LIS2DH12_CLICK_TH);//62.6mg(4g)*10
|
||||
SL_MEMS_i2cWrite(LIS2DH12_W_ADDR, LIS2DH12_TIME_LIMIT, LIS2DH12_CLICK_WINDOWS);
|
||||
SL_MEMS_i2cWrite(LIS2DH12_W_ADDR, LIS2DH12_TIME_LATENCY, LIS2DH12_CLICK_LATENCY);
|
||||
*/
|
||||
// SL_MEMS_i2cWrite(LIS2DH12_W_ADDR, LIS2DH12_CTRL_REG6, LIS2DH12_INT_LEVEL);
|
||||
xlog(" LIS2DH12 i2c check ok\n");
|
||||
return 0;
|
||||
} else {
|
||||
xlog(" LIS2DH12 i2c check fail\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
u8 LIS2DH12_disable(void)
|
||||
{
|
||||
u8 Check_Flag = LIS2DH12_Check();
|
||||
if (Check_Flag == 1) {
|
||||
u8 ODR = 0x00;
|
||||
SL_MEMS_i2cWrite(LIS2DH12_W_ADDR, LIS2DH12_CTRL_REG1, ODR);
|
||||
xlog("check ok,LIS2DH12_disable\n");
|
||||
return 0;
|
||||
} else {
|
||||
xlog("check fail\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LIS2DH12_read_data_old(axis_info_t *sl_accel)
|
||||
{
|
||||
u8 data[6];
|
||||
u8 fifo_len = 0;
|
||||
u8 STATUS_REG_data =0;
|
||||
SL_MEMS_i2cRead(LIS2DH12_R_ADDR, LIS2DH12_SRC_REG, 1, &fifo_len);
|
||||
SL_MEMS_i2cRead(LIS2DH12_R_ADDR, LIS2DH12_STATUS_REG, 1, &STATUS_REG_data);
|
||||
xlog("STATUS_REG vlau = %xH\n",STATUS_REG_data);
|
||||
xlog("FIFO vlau = %xH\n",fifo_len);
|
||||
if ((fifo_len & 0x40) == 0x40) { //FIFO 溢出标志
|
||||
fifo_len = 32;
|
||||
xlog("FIFO is full\n");
|
||||
} else {
|
||||
fifo_len = fifo_len & 0x1f;
|
||||
}
|
||||
for (u8 i = 0; i < fifo_len; i++) {
|
||||
SL_MEMS_i2cRead(LIS2DH12_R_ADDR, LIS2DH12_OUT_X_L, 6, data);
|
||||
sl_accel[i].x = (short)((data[1] << 8) | data[0]);
|
||||
// sl_accel[i].x = sl_accel[i].x >> 4;
|
||||
sl_accel[i].y = (short)((data[3] << 8) | data[2]);
|
||||
// sl_accel[i].y = sl_accel[i].y >> 4;
|
||||
sl_accel[i].z = (short)((data[5] << 8) | data[4]);
|
||||
// sl_accel[i].z = sl_accel[i].z >> 4;
|
||||
// xlog("group:%2d,sl_accel_x:%5d, sl_accel_y:%5d, sl_accel_z:%5d\n", i, sl_accel[i].x, sl_accel[i].y, sl_accel[i].z);
|
||||
}
|
||||
xlog("group:%2d,sl_accel_x:%5d, sl_accel_y:%5d, sl_accel_z:%5d\n", sl_accel[fifo_len -1].x, sl_accel[fifo_len -1].y, sl_accel[fifo_len -1].z);
|
||||
}
|
||||
|
||||
//8.1 小李
|
||||
// 获取三轴传感器的x,y,z加速度值
|
||||
/**
|
||||
* @brief 获取三轴传感器的x,y,z加速度值
|
||||
*
|
||||
* @param axis_info_t 参数是axis_info_t类型结构体变量,用于存放x,y,z的加速度值
|
||||
* @return void 此函数无返回值
|
||||
*/
|
||||
extern u16 High_g;
|
||||
void LIS2DH12_read_data(axis_info_t *sl_accel)
|
||||
{
|
||||
u8 fifo_src = 0;
|
||||
u8 samples_available = 0;
|
||||
u8 data[192]; //32*6
|
||||
s16 raw_x,raw_y,raw_z;
|
||||
// print_register_values(); // 打印寄存器值
|
||||
// 读取FIFO状态
|
||||
SL_MEMS_i2cRead(LIS2DH12_R_ADDR, LIS2DH12_SRC_REG, 1, &fifo_src);
|
||||
// xlog("FIFO_SRC_REG: 0x%02X\n", fifo_src);
|
||||
// 检查FIFO是否为空
|
||||
// if (fifo_src & 0x20) {
|
||||
// xlog("FIFO is empty\n");
|
||||
// LIS2DH12_reinit_fifo(); //重新启用FIFO
|
||||
// 尝试重新初始化FIFO
|
||||
// SL_MEMS_i2cWrite(LIS2DH12_W_ADDR, LIS2DH12_CTRL_REG5, 0x40); // 使能FIFO
|
||||
// SL_MEMS_i2cWrite(LIS2DH12_W_ADDR, LIS2DH12_FIFO_CTRL_REG, 0x40); // FIFO模式
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 获取可用样本数
|
||||
samples_available = fifo_src & 0x1F;
|
||||
// xlog("Available samples: %d\n", samples_available);
|
||||
|
||||
// 一次性读取所有FIFO数据
|
||||
SL_MEMS_i2cRead(LIS2DH12_R_ADDR, LIS2DH12_OUT_X_L | 0x80, samples_available * 6, data);
|
||||
// if (SL_MEMS_i2cRead(LIS2DH12_R_ADDR, LIS2DH12_OUT_X_L | 0x80, samples_available * 6, data) != 0) {
|
||||
// xlog("Error reading FIFO data\n");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 解析数据
|
||||
for (u8 i = 0; i < samples_available; i++) {
|
||||
raw_x = (int16_t)((data[i * 6 + 1] << 8) | data[i * 6]) >> 6; //传感器输出的是10位数据
|
||||
raw_y = (int16_t)((data[i * 6 + 3] << 8) | data[i * 6 + 2]) >> 6;
|
||||
raw_z = (int16_t)((data[i * 6 + 5] << 8) | data[i * 6 + 4]) >> 6;
|
||||
raw_x =convert_10bit_2s_complement(raw_x);
|
||||
raw_y =convert_10bit_2s_complement(raw_y);
|
||||
raw_z =convert_10bit_2s_complement(raw_z);
|
||||
sl_accel[i].x = raw_x;
|
||||
sl_accel[i].y = raw_y;
|
||||
sl_accel[i].z = raw_z;
|
||||
// if (raw_z > 0) {
|
||||
// // High_g = raw_z * 0.16f;
|
||||
// High_g = (u8)((float)raw_z * 0.16f);
|
||||
// } else {
|
||||
// // High_g = -1.0f * raw_z * 0.16f;
|
||||
// High_g = (u8)((-1.0f * (float)raw_z) * 0.16f);
|
||||
// }
|
||||
// xlog("###High_g == %d\n",High_g);
|
||||
|
||||
// xlog("\nSample %d: X=%d, Y=%d, Z=%d\n", i, sl_accel[i].x, sl_accel[i].y, sl_accel[i].z); //打印从寄存器读到的数据
|
||||
// gsensor_xtell.x = raw_x;
|
||||
// gsensor_xtell.y = raw_y;
|
||||
// gsensor_xtell.z = raw_z;
|
||||
|
||||
|
||||
// sl_accel[i].x = raw_x;
|
||||
// sl_accel[i].y = raw_y;
|
||||
// sl_accel[i].z = raw_z;
|
||||
// sl_accel[i].x = (float)raw_x *0.16f; //实际的加速度值 8g 量程
|
||||
// sl_accel[i].y = (float)raw_y *0.16f;
|
||||
// sl_accel[i].z = (float)raw_z *0.16f;
|
||||
// xlog("Sample %d: X=%.2f g, Y=%.2f g, Z=%.2f g\n", i, sl_accel[i].x, sl_accel[i].y, sl_accel[i].z);
|
||||
}
|
||||
}
|
||||
// 判断传感器是否长期静止的函数
|
||||
bool is_sensor_stable(axis_info_t *accel_data, int sample_count) {
|
||||
float mean_x = 0, mean_y = 0, mean_z = 0;
|
||||
float variance_x = 0, variance_y = 0, variance_z = 0;
|
||||
// 计算每个轴的均值
|
||||
for (int i = 0; i < sample_count; i++) {
|
||||
mean_x += accel_data[i].x;
|
||||
mean_y += accel_data[i].y;
|
||||
mean_z += accel_data[i].z;
|
||||
}
|
||||
mean_x /= sample_count;
|
||||
mean_y /= sample_count;
|
||||
mean_z /= sample_count;
|
||||
// xlog("Mean X: %.2f, Y: %.2f, Z: %.2f\n", mean_x, mean_y, mean_z); //平均数
|
||||
gsensor_xtell.x = mean_x;
|
||||
gsensor_xtell.y = mean_y;
|
||||
gsensor_xtell.z = mean_z;
|
||||
|
||||
// 计算每个轴的方差
|
||||
for (int i = 0; i < sample_count; i++) {
|
||||
variance_x += (accel_data[i].x - mean_x) * (accel_data[i].x - mean_x);
|
||||
variance_y += (accel_data[i].y - mean_y) * (accel_data[i].y - mean_y);
|
||||
variance_z += (accel_data[i].z - mean_z) * (accel_data[i].z - mean_z);
|
||||
}
|
||||
variance_x /= (sample_count - 1);
|
||||
variance_y /= (sample_count - 1);
|
||||
variance_z /= (sample_count - 1);
|
||||
|
||||
// 打印均值和方差,用于调试
|
||||
// xlog("Variance X: %.2f, Y: %.2f, Z: %.2f\n", variance_x, variance_y, variance_z);
|
||||
|
||||
// 判断方差是否在阈值范围内
|
||||
//非静止状态
|
||||
if (variance_x > THRESHOLD || variance_y > THRESHOLD || variance_z > THRESHOLD) {
|
||||
gsensor_static_flag = 0;
|
||||
gsensor_alarm =0;
|
||||
// xlog("**********Sensor is not stable\n");
|
||||
|
||||
//超过预设值休眠后重新有数据刷新
|
||||
if(dormancy_flag){
|
||||
dormancy_flag = 0;
|
||||
set_rgb(dormancy_ago_moedl);
|
||||
dormancy_ago_moedl = 0;
|
||||
}
|
||||
return false;
|
||||
}else { //静止状态
|
||||
gsensor_static_flag++;
|
||||
if(gsensor_static_flag >= STATIC_MAX_TIME){
|
||||
gsensor_alarm =0xFF;
|
||||
// xlog("@@@Do you need help?@@@");
|
||||
// gsensor_static_flag =0;
|
||||
}
|
||||
#if 0 //0表示测试 1表示正式代码
|
||||
if(gsensor_static_flag >= DORMANCY_MAX_TIME){ //静止时间超过预设值就关闭灯效,有数据刷新再打开之前灯效
|
||||
if(dormancy_ago_moedl != RGB_model){ //休眠时灯效和当前灯效 不一致就关闭灯效
|
||||
dormancy_ago_moedl = RGB_model;
|
||||
dormancy_flag =1;
|
||||
colorful_lights_function().update_display_mode(COLORFUL_LIGHTS_DISPLAY_NULL); //关闭灯效
|
||||
// xlog("dormancy close LED\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return true; // 传感器处于静止状态
|
||||
}
|
||||
}
|
||||
void print_register_values(){
|
||||
u8 ctrl_reg1, ctrl_reg3, ctrl_reg5, fifo_ctrl;
|
||||
SL_MEMS_i2cRead(LIS2DH12_R_ADDR, LIS2DH12_CTRL_REG1, 1, &ctrl_reg1);
|
||||
SL_MEMS_i2cRead(LIS2DH12_R_ADDR, LIS2DH12_CTRL_REG3, 1, &ctrl_reg3);
|
||||
SL_MEMS_i2cRead(LIS2DH12_R_ADDR, LIS2DH12_CTRL_REG5, 1, &ctrl_reg5);
|
||||
SL_MEMS_i2cRead(LIS2DH12_R_ADDR, LIS2DH12_FIFO_CTRL_REG, 1, &fifo_ctrl);
|
||||
|
||||
// xlog("CTRL_REG1: 0x%02X, CTRL_REG3: 0x%02X, CTRL_REG5: 0x%02X, FIFO_CTRL_REG: 0x%02X\n", ctrl_reg1, ctrl_reg3, ctrl_reg5, fifo_ctrl);
|
||||
}
|
||||
|
||||
void LIS2DH12_reinit_fifo() {
|
||||
SL_MEMS_i2cWrite(LIS2DH12_W_ADDR, LIS2DH12_CTRL_REG5, 0x00); // 禁用FIFO
|
||||
SL_MEMS_i2cWrite(LIS2DH12_W_ADDR, LIS2DH12_FIFO_CTRL_REG, 0x00); // 禁用FIFO模式
|
||||
delay_2ms(1);
|
||||
SL_MEMS_i2cWrite(LIS2DH12_W_ADDR, LIS2DH12_CTRL_REG5, 0x40); // 重新使能FIFO
|
||||
SL_MEMS_i2cWrite(LIS2DH12_W_ADDR, LIS2DH12_FIFO_CTRL_REG, 0x40); // 重新设置FIFO模式
|
||||
}
|
||||
|
||||
// 转换函数
|
||||
float convert_to_g_old(int16_t raw_value, scale_t scale) {
|
||||
// 将 16 位有符号整数转换为浮点数
|
||||
float sensitivity;
|
||||
|
||||
switch(scale) {
|
||||
case SCALE_2G:
|
||||
sensitivity = 1.0f / 16384.0f; // ±2g 范围下的灵敏度
|
||||
break;
|
||||
case SCALE_4G:
|
||||
sensitivity = 1.0f / 8192.0f; // ±4g 范围下的灵敏度
|
||||
break;
|
||||
case SCALE_8G:
|
||||
sensitivity = 1.0f / 4096.0f; // ±8g 范围下的灵敏度
|
||||
break;
|
||||
case SCALE_16G:
|
||||
sensitivity = 1.0f / 2048.0f; // ±16g 范围下的灵敏度
|
||||
break;
|
||||
default:
|
||||
sensitivity = 1.0f / 16384.0f; // 默认使用 ±2g 范围
|
||||
}
|
||||
|
||||
return (float)raw_value * sensitivity * scale / 2.0f;
|
||||
}
|
||||
|
||||
//10位2补码转换
|
||||
int16_t convert_10bit_2s_complement(int16_t data) {
|
||||
if (data & 0x200) { // 判断最高位(符号位)是否为1,符号位为1表示2补码时负数
|
||||
// 如果2补码是负数,把2补码转成原码
|
||||
data = ~(data - 1); // 先减1,再按位取反
|
||||
data &= 0x3FF; // 保留低10位
|
||||
data = -data; // 加上负号
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
// 将原始数据转换为实际加速度值的函数
|
||||
float convert_to_g(int16_t raw_value) {
|
||||
float sensitivity = 0.016f; // 16 mg/digit
|
||||
// switch(CURRENT_SCALE) {
|
||||
// case SCALE_2G:
|
||||
// sensitivity = 0.001f; // 4 mg/digit
|
||||
// break;
|
||||
// case SCALE_4G:
|
||||
// sensitivity = 0.008f; // 8 mg/digit
|
||||
// break;
|
||||
// case SCALE_8G:
|
||||
// sensitivity = 0.016f; // 16 mg/digit
|
||||
// break;
|
||||
// case SCALE_16G:
|
||||
// sensitivity = 0.048f; // 48 mg/digit
|
||||
// break;
|
||||
// default:
|
||||
// sensitivity = 0.004f; // Default to ±2g range
|
||||
// }
|
||||
|
||||
if (raw_value & 0x200) { // 判断最高位(符号位)是否为1,符号位为1表示2补码时负数
|
||||
// 如果2补码是负数,把2补码转成原码
|
||||
raw_value = ~(raw_value - 1); // 先减1,再按位取反
|
||||
raw_value &= 0x3FF; // 保留低10位
|
||||
raw_value = -raw_value; // 加上负号
|
||||
}
|
||||
// xlog("raw value= %d",raw_value);
|
||||
|
||||
// Convert to g
|
||||
return (float)raw_value * sensitivity;
|
||||
}
|
||||
// 读取传感器数据的定时器回调函数
|
||||
|
||||
|
||||
// 在全局变量区域添加:
|
||||
axis_info_t last_accel_data = {0.0f, 0.0f, 0.0f}; // 用于存储上一时刻的加速度
|
||||
|
||||
// --- New functions for motion tracking ---
|
||||
|
||||
/**
|
||||
* @brief 获取当前加速度值,单位 m/s^2
|
||||
* @return axis_info_xtell 包含x,y,z轴加速度的结构体
|
||||
*/
|
||||
axis_info_xtell get_current_accel_mss(void) {
|
||||
axis_info_xtell accel_mss;
|
||||
// 1 LSb = 62 mg @ FS = 8 g
|
||||
// 8g量程: 16 mg/LSB == 0.016 g/LSB
|
||||
//g:ADC / (灵敏度LSB/g) = ADC * X g/LSB
|
||||
//实际加速度 = g * 9.8 m/s^2
|
||||
accel_mss.x = (float)gsensor_xtell.x * 0.016f * GRAVITY_EARTH;
|
||||
accel_mss.y = (float)gsensor_xtell.y * 0.016f * GRAVITY_EARTH;
|
||||
accel_mss.z = (float)gsensor_xtell.z * 0.016f * GRAVITY_EARTH;
|
||||
return accel_mss;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 获取计算出的运动数据(速度和距离)
|
||||
* @param data 指向 motion_data_t 结构体的指针,用于存放结果
|
||||
*/
|
||||
void get_motion_data(motion_data_t *data) {
|
||||
if (data) {
|
||||
// Use a critical section or disable interrupts if this can be called from another thread
|
||||
memcpy(data, &motion_data, sizeof(motion_data_t));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xtell_i2c_test() {
|
||||
|
||||
// 获取LIS2DH12三轴加速度
|
||||
LIS2DH12_read_data(current_data);
|
||||
|
||||
//判断是否静止, is_sensor_stable会更新全局变量gsensor_xtell
|
||||
sensor_is_stable = is_sensor_stable(current_data, SAMPLE_COUNT);
|
||||
|
||||
axis_info_xtell current_accel_mss = get_current_accel_mss();
|
||||
axis_info_xtell linear_accel;
|
||||
|
||||
// 低通滤波器,把运动产生的加速度和地球重力产生的加速度分开
|
||||
gravity_vector.x = LPF_ALPHA * gravity_vector.x + (1.0f - LPF_ALPHA) * current_accel_mss.x;
|
||||
gravity_vector.y = LPF_ALPHA * gravity_vector.y + (1.0f - LPF_ALPHA) * current_accel_mss.y;
|
||||
gravity_vector.z = LPF_ALPHA * gravity_vector.z + (1.0f - LPF_ALPHA) * current_accel_mss.z;
|
||||
|
||||
// 总加速度中减去重力
|
||||
linear_accel.x = current_accel_mss.x - gravity_vector.x;
|
||||
linear_accel.y = current_accel_mss.y - gravity_vector.y;
|
||||
linear_accel.z = current_accel_mss.z - gravity_vector.z;
|
||||
|
||||
// 积分得到速度
|
||||
motion_data.velocity.x += linear_accel.x * SAMPLING_PERIOD_S;
|
||||
motion_data.velocity.y += linear_accel.y * SAMPLING_PERIOD_S;
|
||||
motion_data.velocity.z += linear_accel.z * SAMPLING_PERIOD_S;
|
||||
|
||||
// 静止
|
||||
if (sensor_is_stable) {
|
||||
xlog("stop now\n");
|
||||
motion_data.velocity.x = 0.0f;
|
||||
motion_data.velocity.y = 0.0f;
|
||||
motion_data.velocity.z = 0.0f;
|
||||
}
|
||||
|
||||
// 再次积分得到距离
|
||||
motion_data.distance.x += motion_data.velocity.x * SAMPLING_PERIOD_S;
|
||||
motion_data.distance.y += motion_data.velocity.y * SAMPLING_PERIOD_S;
|
||||
motion_data.distance.z += motion_data.velocity.z * SAMPLING_PERIOD_S;
|
||||
|
||||
float total_distance_magnitude = sqrtf(motion_data.distance.x * motion_data.distance.x +
|
||||
motion_data.distance.y * motion_data.distance.y +
|
||||
motion_data.distance.z * motion_data.distance.z);
|
||||
xlog("================================================================\n");
|
||||
xlog("Total Distance Magnitude: %.2f m\n", total_distance_magnitude);
|
||||
xlog("================================================================\n");
|
||||
|
||||
}
|
||||
57
apps/earphone/xtell_Sensor/LIS2DH12.h
Normal file
57
apps/earphone/xtell_Sensor/LIS2DH12.h
Normal file
@ -0,0 +1,57 @@
|
||||
#ifndef LIS2DH12_H
|
||||
#define LIS2DH12_H
|
||||
#include "gSensor/gSensor_manage.h"
|
||||
// #include <stdatomic.h>
|
||||
#include "le_rcsp_adv_module.h"
|
||||
|
||||
|
||||
// Constants
|
||||
#define GRAVITY_EARTH 9.80665f // m/s^2
|
||||
#define SAMPLING_PERIOD_S 2 // 采样周期,s
|
||||
#define LPF_ALPHA 0.8f // 低通滤波系数
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
} axis_info_xtell;
|
||||
|
||||
typedef struct {
|
||||
axis_info_xtell velocity; // m/s
|
||||
axis_info_xtell distance; // m
|
||||
} motion_data_t;
|
||||
|
||||
|
||||
// 定义可能的满量程范围
|
||||
typedef enum {
|
||||
SCALE_2G = 2,
|
||||
SCALE_4G = 4,
|
||||
SCALE_8G = 8,
|
||||
SCALE_16G = 16
|
||||
} scale_t;
|
||||
|
||||
|
||||
unsigned char LIS2DH12_Config(void);
|
||||
char LIS2DH12_Check();
|
||||
unsigned char LIS2DH12_disable(void);
|
||||
void LIS2DH12_read_data(axis_info_t *sl_accel);
|
||||
void print_register_values();
|
||||
void LIS2DH12_reinit_fifo();
|
||||
// float convert_to_g(int16_t raw_value, scale_t scale);
|
||||
float convert_to_g(int16_t raw_value);
|
||||
void xtell_i2c_test();
|
||||
|
||||
// 获取运动数据
|
||||
void get_motion_data(motion_data_t *data);
|
||||
axis_info_xtell get_current_accel_mss(void);
|
||||
|
||||
|
||||
//10位2补码转换
|
||||
int16_t convert_10bit_2s_complement(int16_t data);
|
||||
// typedef struct {
|
||||
// short x;
|
||||
// short y;
|
||||
// short z;
|
||||
// } axis_info_t;
|
||||
|
||||
#endif
|
||||
62
apps/earphone/xtell_Sensor/main.c
Normal file
62
apps/earphone/xtell_Sensor/main.c
Normal file
@ -0,0 +1,62 @@
|
||||
#include "system/includes.h"
|
||||
/*#include "btcontroller_config.h"*/
|
||||
#include "btstack/btstack_task.h"
|
||||
#include "app_config.h"
|
||||
#include "app_action.h"
|
||||
#include "asm/pwm_led.h"
|
||||
#include "tone_player.h"
|
||||
#include "ui_manage.h"
|
||||
#include "gpio.h"
|
||||
#include "app_main.h"
|
||||
#include "asm/charge.h"
|
||||
#include "update.h"
|
||||
#include "app_power_manage.h"
|
||||
#include "audio_config.h"
|
||||
#include "app_charge.h"
|
||||
#include "bt_profile_cfg.h"
|
||||
#include "dev_manager/dev_manager.h"
|
||||
#include "update_loader_download.h"
|
||||
#include "LIS2DH12.h"
|
||||
|
||||
#define xlog(format, ...) printf("[%s] " format, __func__, ##__VA_ARGS__)
|
||||
|
||||
|
||||
u16 xtell_i2c_test_id;
|
||||
u16 print_motion_data_id;
|
||||
|
||||
// Task to print motion data periodically
|
||||
void print_motion_data_task(void) {
|
||||
motion_data_t current_motion;
|
||||
axis_info_xtell current_accel;
|
||||
|
||||
// Get the latest motion data
|
||||
get_motion_data(¤t_motion);
|
||||
current_accel = get_current_accel_mss();
|
||||
|
||||
xlog("--- Motion Data ---\n");
|
||||
xlog("Accel (m/s^2): X=%.2f, Y=%.2f, Z=%.2f\n", current_accel.x, current_accel.y, current_accel.z);
|
||||
xlog("Velo (m/s): X=%.2f, Y=%.2f, Z=%.2f\n", current_motion.velocity.x, current_motion.velocity.y, current_motion.velocity.z);
|
||||
xlog("Dist (m): X=%.2f, Y=%.2f, Z=%.2f\n", current_motion.distance.x, current_motion.distance.y, current_motion.distance.z);
|
||||
xlog("-------------------\n");
|
||||
}
|
||||
|
||||
void create_process(u16* pid,char* name, void *priv, void (*func)(void *priv), u32 msec){
|
||||
xlog("1 name=%s, pid =%d\n",name,*pid);
|
||||
if (*pid != 0) return;
|
||||
*pid = sys_timer_add(priv, func, msec);
|
||||
xlog("2 name=%s, pid =%d\n",name,*pid);
|
||||
}
|
||||
|
||||
|
||||
void xtell_main(void){
|
||||
soft_iic_init(0); // 引脚选择在demo_cf.h中
|
||||
extern u8 LIS2DH12_Config(void);
|
||||
LIS2DH12_Config();
|
||||
|
||||
// This task runs every 200ms to perform the calculations
|
||||
create_process(&xtell_i2c_test_id, "xtell_i2c_test",NULL, xtell_i2c_test, SAMPLING_PERIOD_S*1000);
|
||||
|
||||
// This task runs every 1000ms to print the results
|
||||
create_process(&print_motion_data_id, "print_motion_data_task", NULL, print_motion_data_task, 1000);
|
||||
}
|
||||
|
||||
1
cpu/br28/tools/AC69.key
Normal file
1
cpu/br28/tools/AC69.key
Normal file
@ -0,0 +1 @@
|
||||
1cfdc466ec927dbedd4d12447b6bbff1da1bd6ddb6b375ecda1bd6ddb6b375ec950b1206
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -21,6 +21,7 @@ Setlocal enabledelayedexpansion
|
||||
@echo SDK BR28
|
||||
@echo ********************************************************************************
|
||||
@echo %date%
|
||||
set KEY_FILE=-key AC69.key
|
||||
|
||||
|
||||
cd /d %~dp0
|
||||
@ -59,4 +60,4 @@ copy /b text.bin + data.bin + mov_slot.bin + data_code.bin + aec.bin + aac.bin +
|
||||
|
||||
del !bankfiles! common.bin text.bin data.bin bank.bin
|
||||
copy eq_cfg_hw_less.bin eq_cfg_hw.bin
|
||||
call download/earphone/download.bat
|
||||
call download/earphone/download_app_ota.bat
|
||||
|
||||
@ -93,6 +93,7 @@ Setlocal enabledelayedexpansion
|
||||
@echo SDK BR28
|
||||
@echo ********************************************************************************
|
||||
@echo %date%
|
||||
set KEY_FILE=-key AC69.key
|
||||
|
||||
|
||||
cd /d %~dp0
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
430590
cpu/br28/tools/sdk.lst
430590
cpu/br28/tools/sdk.lst
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -88,4 +88,7 @@ objs/apps/common/device/key/key_driver.c.o: \
|
||||
include_lib/btctrler/classic/hci_lmp.h \
|
||||
include_lib/system/device\rdec_key.h \
|
||||
include_lib/driver/cpu/br28\asm/rdec.h \
|
||||
include_lib/system/device\tent600_key.h include_lib/system\debug.h
|
||||
include_lib/system/device\tent600_key.h \
|
||||
apps/earphone/include\tone_player.h cpu/br28\tone_player_api.h \
|
||||
cpu/br28/audio_config.h apps/common/audio\sine_make.h \
|
||||
include_lib/system\debug.h
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user