From a60a6c1a35c0dc2e935f6c8c0509f65dca0d8fa1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=BD=AD=E7=A3=8A?= <1624952103@qq.com> Date: Fri, 8 Aug 2025 08:48:15 +0000 Subject: [PATCH] Merge #2059 into sdk650pathc0423 from refs/changes/2059/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 优化运动心率;降低待机功耗 * refs/changes/2059/head: (1 commits squashed) - 优化运动心率;降低待机功耗 Signed-off-by: aliyun6865282430 <1624952103@qq.com> Merged-by: aliyun6865282430 <1624952103@qq.com> CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/2059 --- .../brandy/brandy_standard/thread_pri_init.c | 4 + .../config/target_config/brandy/config.py | 4 +- .../boards/brandy_evb/board_config/board_w9.h | 8 +- .../driver/touch/cst86xx_touch/cst86xx_ctrl.c | 1 + .../touch/cst86xx_touch/cst86xx_touch1.c | 2 +- .../driver/touch/ft6x46_touch/ft6x46_touch1.c | 2 +- .../cywee/ble_service/cywee_ble_service.c | 13 +- .../zhihui/drivers/cywee/dml/board_yh601s.c | 2 +- code/sdk/zhihui/drivers/cywee/dml/cywee_dml.c | 4 + .../drivers/cywee/service/cywee_service.c | 3 - code/sdk/zhihui/drivers/gyro/CMakeLists.txt | 2 +- .../zhihui/drivers/gyro/service/gyro_at_cmd.c | 9 +- .../zhihui/drivers/gyro/service/gyro_hal.c | 76 ++++++++++ .../zhihui/drivers/gyro/service/gyro_hal.h | 42 ++++++ .../drivers/gyro/service/gyro_service.c | 101 +++++--------- .../drivers/gyro/service/gyro_service.h | 15 +- code/sdk/zhihui/drivers/gyro/sh5001/sh5001.c | 38 ++++- code/sdk/zhihui/drivers/gyro/sh5001/sh5001.h | 9 +- .../drivers/ppg/pah8009/sensor/pah800x_main.c | 131 ++++++++++-------- .../ppg/pah8009/sensor/pah_800x_config.h | 8 +- 20 files changed, 314 insertions(+), 160 deletions(-) create mode 100644 code/sdk/zhihui/drivers/gyro/service/gyro_hal.c create mode 100644 code/sdk/zhihui/drivers/gyro/service/gyro_hal.h diff --git a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c index 7e6b57ec4..ce6996b57 100644 --- a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c +++ b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c @@ -546,6 +546,10 @@ static void thread_main(const void *unused) uapi_bp_service_init(); #endif +#ifdef SUPPORT_GYRO_SERVICE + uapi_gyro_service_init(); +#endif + #endif diff --git a/code/sdk/build/config/target_config/brandy/config.py b/code/sdk/build/config/target_config/brandy/config.py index 0e51687b1..175dbd90f 100644 --- a/code/sdk/build/config/target_config/brandy/config.py +++ b/code/sdk/build/config/target_config/brandy/config.py @@ -986,7 +986,8 @@ target = { # 'DISABLE_UART_LOG', # 'CONFIG_GNSS_UART_WITH_FLOWCTRL', # 'DOWNLOAD_GNSS_SWITCH', - + 'SUPPORT_GYRO_SERVICE', + 'GYRO_SH5001', ], #添加自定义应用 'ram_component': [ @@ -1024,6 +1025,7 @@ target = { "gnss", "pgnss_sample", "cyweeBleService", + "gyro", ], 'image_analysis': False, 'fs_image_path':'fd230', diff --git a/code/sdk/drivers/boards/brandy_evb/board_config/board_w9.h b/code/sdk/drivers/boards/brandy_evb/board_config/board_w9.h index 7c0f984a6..718933d2c 100644 --- a/code/sdk/drivers/boards/brandy_evb/board_config/board_w9.h +++ b/code/sdk/drivers/boards/brandy_evb/board_config/board_w9.h @@ -19,7 +19,7 @@ extern void bp_int_callback(pin_t pin, uintptr_t param); extern void ppg_int_callback(pin_t pin, uintptr_t param); #endif -#ifdef ENABLE_GYRO +#ifdef SUPPORT_GYRO_SERVICE extern void gyro_int_callback(pin_t pin, uintptr_t param); #endif @@ -224,7 +224,7 @@ const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = { { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_R5 touch int { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_R6 PRG_INT 心率中断 { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R7 GYRO_INT2 -#ifdef ENABLE_GYRO +#ifdef SUPPORT_GYRO_SERVICE { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_R8 GYRO_INT1 #else { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R8 GYRO_INT1 @@ -326,7 +326,7 @@ const hal_gpio_config_t g_gpio_function_config[PIN_MAX_NUMBER] = { // { S_AGPIO_L31, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_RISING_EDGE, cat1_ring_isr_callback}, #endif -#ifdef ENABLE_GYRO +#ifdef SUPPORT_GYRO_SERVICE { S_AGPIO_R8, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_RISING_EDGE, gyro_int_callback }, #else /**S_AGPIO_L32 GPO gps reset*/ @@ -339,7 +339,7 @@ const hal_gpio_config_t g_gpio_function_config[PIN_MAX_NUMBER] = { #ifdef PPG_GH3X2X { S_AGPIO_R6, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_RISING_EDGE, ppg_int_callback}, #elif defined PPG_PAH8009 - // { S_AGPIO_R6, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_FALLING_EDGE, ppg_int_callback}, + { S_AGPIO_R6, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_FALLING_EDGE, ppg_int_callback}, #endif #endif #ifdef ROTARYENCODER_MIXO diff --git a/code/sdk/drivers/drivers/driver/touch/cst86xx_touch/cst86xx_ctrl.c b/code/sdk/drivers/drivers/driver/touch/cst86xx_touch/cst86xx_ctrl.c index 4eea84762..0c9910109 100644 --- a/code/sdk/drivers/drivers/driver/touch/cst86xx_touch/cst86xx_ctrl.c +++ b/code/sdk/drivers/drivers/driver/touch/cst86xx_touch/cst86xx_ctrl.c @@ -178,6 +178,7 @@ ext_errno cst86xx_tp_i2c_reg_write(uint16_t reg_addr, uint16_t reg_cfg) } g_tp_send_buf[CST86XX_I2C_SEND_INDEX0] = reg_addr & 0xff; + g_tp_send_buf[1] = reg_cfg & 0xff; data.send_buf = g_tp_send_buf; data.send_len = CST86XX_REG_WRITE_LEN; diff --git a/code/sdk/drivers/drivers/driver/touch/cst86xx_touch/cst86xx_touch1.c b/code/sdk/drivers/drivers/driver/touch/cst86xx_touch/cst86xx_touch1.c index 262a4213a..04b246dd5 100644 --- a/code/sdk/drivers/drivers/driver/touch/cst86xx_touch/cst86xx_touch1.c +++ b/code/sdk/drivers/drivers/driver/touch/cst86xx_touch/cst86xx_touch1.c @@ -410,7 +410,7 @@ void cst86xx_get_chip_id(uint16_t *chip_id) tp_err("configuration error (read chip id) 0x%x", ret); return; } - cst86xx_suspend(); + // cst86xx_suspend(); } #ifdef __cplusplus diff --git a/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_touch1.c b/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_touch1.c index f6fb5354d..f725eb572 100644 --- a/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_touch1.c +++ b/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_touch1.c @@ -993,7 +993,7 @@ void ft6x46_get_chip_id(uint16_t *id) //sprintf(id,"0x%02x%02x", chip_id[0], chip_id[1]); } } - ft6x46_suspend(); + // ft6x46_suspend(); } #ifdef __cplusplus diff --git a/code/sdk/zhihui/drivers/cywee/ble_service/cywee_ble_service.c b/code/sdk/zhihui/drivers/cywee/ble_service/cywee_ble_service.c index f14fb16db..b81fc5002 100644 --- a/code/sdk/zhihui/drivers/cywee/ble_service/cywee_ble_service.c +++ b/code/sdk/zhihui/drivers/cywee/ble_service/cywee_ble_service.c @@ -12,7 +12,7 @@ #endif #include "securec.h" #include "wearable_log.h" -#ifdef SUPPORT_OHOSFWK +#ifdef SUPPORT_AT_OHOSFWK #include "BluetoothWrapper.h" #endif @@ -48,7 +48,7 @@ static void ble_cywee_add_service(uint8_t server_id) bts_data_to_uuid_len2(BLE_UUID_CYWEE_REPORT_SERVICE, &cywee_service_uuid); //只有一个服务,永远是1 errcode_t ret = 0; -#ifndef SUPPORT_OHOSFWK +#ifndef SUPPORT_AT_OHOSFWK ret = gatts_add_service(server_id, &cywee_service_uuid, true); printf("ble_cywee_add_service gatts_add_service ret: 0x%x serverId = 0x%x uuid.uuid_len:%d\n", ret, server_id,cywee_service_uuid.uuid_len); #else @@ -117,7 +117,7 @@ errcode_t ble_cywee_server_send_input_report(const uint8_t *data, uint8_t len) } errcode_t ret = 0; ret = gatts_notify_indicate(g_ble_server_id, g_ble_conn_id, ¶m); - printf("ble_cywee_server_send_input_report: 0x%x g_ble_conn_id:%d g_cywee_notify_report_att_hdl:%d\r\n",ret,g_ble_conn_id,g_cywee_notify_report_att_hdl); + // printf("ble_cywee_server_send_input_report: 0x%x g_ble_conn_id:%d g_cywee_notify_report_att_hdl:%d\r\n",ret,g_ble_conn_id,g_cywee_notify_report_att_hdl); bt_os_free(param.value); return ERRCODE_BT_SUCCESS; } @@ -160,9 +160,10 @@ void ble_cywee_server_init(uint8_t server_id) //协议接收client下发的数据接口 void cywee_recv_cmd_data(uint8_t *buf, uint16_t event_size,uint16_t handle) { - if(buf != NULL) - printf("cywee_recv_cmd_data len %d , handle 0x%X ,*buf 0x%02X\r\n",event_size,handle,*buf); + if(buf == NULL) + return; + // printf("cywee_recv_cmd_data len %d , handle 0x%X ,*buf 0x%02X\r\n",event_size,handle,*buf); /****此处为接收指令,处理后反馈结果的参考**/ - // cywee_set_log_switch(*buf); + cywee_set_log_switch(*buf); /*****参考结束****/ } diff --git a/code/sdk/zhihui/drivers/cywee/dml/board_yh601s.c b/code/sdk/zhihui/drivers/cywee/dml/board_yh601s.c index d801efb0d..cb5e12b08 100644 --- a/code/sdk/zhihui/drivers/cywee/dml/board_yh601s.c +++ b/code/sdk/zhihui/drivers/cywee/dml/board_yh601s.c @@ -241,7 +241,7 @@ void CWM_OS_free(void *ptr) int CWM_OS_dbgOutput(const char * format) { - PRINT("%s", format); + printf("%s", format); #ifdef SUPPORT_CYWEE_BLE_SERVICE if(cywee_get_log_flag()) ble_cywee_server_send_input_report((uint8_t *)format,strlen(format)); diff --git a/code/sdk/zhihui/drivers/cywee/dml/cywee_dml.c b/code/sdk/zhihui/drivers/cywee/dml/cywee_dml.c index 63733ce6d..4a83df3db 100644 --- a/code/sdk/zhihui/drivers/cywee/dml/cywee_dml.c +++ b/code/sdk/zhihui/drivers/cywee/dml/cywee_dml.c @@ -2067,6 +2067,10 @@ int cywee_start(void) //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); // cywee_restoreData(); + do_custom_fileoperate_service_check_msg(CUSTOM_FILEOPERATE_MSG_TYPE_SPORTDATA_READ, NULL, 0); + do_custom_fileoperate_service_check_msg(CUSTOM_FILEOPERATE_MSG_TYPE_SLEEPDATA_READ, NULL, 0); + do_custom_fileoperate_service_check_msg(CUSTOM_FILEOPERATE_MSG_TYPE_NAPDATA_READ, NULL, 0); + cywee_set_user_info(); cywee_activity_mode_change(SPORT_ACTIVE_MODE_NORMAL); diff --git a/code/sdk/zhihui/drivers/cywee/service/cywee_service.c b/code/sdk/zhihui/drivers/cywee/service/cywee_service.c index 4c13f5730..afa9532ed 100644 --- a/code/sdk/zhihui/drivers/cywee/service/cywee_service.c +++ b/code/sdk/zhihui/drivers/cywee/service/cywee_service.c @@ -457,9 +457,6 @@ errcode_t uapi_cywee_service_init(void) // cywee_register_msg_callback(cywee_msg_callback); do_cywee_service_check_msg(CYWEE_SERVICE_CMD_START_CHECK, NULL); - do_custom_fileoperate_service_check_msg(CUSTOM_FILEOPERATE_MSG_TYPE_SPORTDATA_READ, NULL, 0); - do_custom_fileoperate_service_check_msg(CUSTOM_FILEOPERATE_MSG_TYPE_SLEEPDATA_READ, NULL, 0); - do_custom_fileoperate_service_check_msg(CUSTOM_FILEOPERATE_MSG_TYPE_NAPDATA_READ, NULL, 0); return ERRCODE_SUCC; } diff --git a/code/sdk/zhihui/drivers/gyro/CMakeLists.txt b/code/sdk/zhihui/drivers/gyro/CMakeLists.txt index 161f02e88..750a48fed 100644 --- a/code/sdk/zhihui/drivers/gyro/CMakeLists.txt +++ b/code/sdk/zhihui/drivers/gyro/CMakeLists.txt @@ -8,6 +8,7 @@ set(SOURCES ${SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/sh5001/sh5001.c ${CMAKE_CURRENT_SOURCE_DIR}/service/gyro_at_cmd.c ${CMAKE_CURRENT_SOURCE_DIR}/service/gyro_service.c + ${CMAKE_CURRENT_SOURCE_DIR}/service/gyro_hal.c ) set(PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/sh5001 @@ -15,7 +16,6 @@ set(PUBLIC_HEADER ) set(PUBLIC_DEFINES SUPPORT_AT_GYRO - ENABLE_GYRO ) set(PRIVATE_HEADER diff --git a/code/sdk/zhihui/drivers/gyro/service/gyro_at_cmd.c b/code/sdk/zhihui/drivers/gyro/service/gyro_at_cmd.c index 300f46f8d..ef0237f5d 100644 --- a/code/sdk/zhihui/drivers/gyro/service/gyro_at_cmd.c +++ b/code/sdk/zhihui/drivers/gyro/service/gyro_at_cmd.c @@ -2,14 +2,14 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-12-16 20:49:09 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2025-01-04 17:01:37 + * @LastEditTime: 2025-05-12 17:47:30 * @FilePath: /sdk615/code/sdk/drivers/peripheral/GYRO/service/lqbp_at_cmd.c * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ #include "at_cmd_api.h" #include "pm_control.h" #include "gyro_service.h" -#include "sh5001.h" +#include "gyro_hal.h" #define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) #define GYRO_MAX_ARGC 8 @@ -52,8 +52,7 @@ static uint32_t gyro_start_test(uint8_t *para, uint32_t paraLen, char *strCommon UNUSED(strCommonCmd); UNUSED(paraLen); UNUSED(para); - // do_lqbp_service_check_msg(GYRO_SERVICE_CMD_START_CHECK); - SH5001_init(); + gyro_start(); return ERRCODE_SUCC; } static uint32_t gyro_stop_test(uint8_t *para, uint32_t paraLen, char *strCommonCmd) @@ -61,7 +60,7 @@ static uint32_t gyro_stop_test(uint8_t *para, uint32_t paraLen, char *strCommonC UNUSED(strCommonCmd); UNUSED(paraLen); UNUSED(para); - // do_lqbp_service_check_msg(GYRO_SERVICE_CMD_STOP_CHECK); + gyro_stop(); return ERRCODE_SUCC; } static const at_cmd_table_t g_gyro_cmd[] = { diff --git a/code/sdk/zhihui/drivers/gyro/service/gyro_hal.c b/code/sdk/zhihui/drivers/gyro/service/gyro_hal.c new file mode 100644 index 000000000..9e0f083f1 --- /dev/null +++ b/code/sdk/zhihui/drivers/gyro/service/gyro_hal.c @@ -0,0 +1,76 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2025-05-12 09:59:09 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-05-12 17:45:29 + * @FilePath: /sdk615/code/sdk/zhihui/drivers/gyro/service/gyro_hal.c + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AEin + */ +#include +#include +#include "gyro_hal.h" + +#ifdef GYRO_SH5001 +#include "sh5001.h" +#endif + +void gyro_power_on(void) +{ +#ifdef GYRO_SH5001 + if(SH5001_init() == SH5001_TRUE) + printf("sh5001 init successful \n"); + else + printf("sh5001 init failed \n"); + + if(SH5001_SwitchPowerMode(SH5001_NORMAL_MODE) == SH5001_TRUE) + printf("sh5001 start successful \n"); + else + printf("sh5001 start failed \n"); +#endif +} + +void gyro_power_off(void) +{ +#ifdef GYRO_SH5001 + if(SH5001_SwitchPowerMode(SH5001_POWERDOWN_MODE) == SH5001_TRUE) + printf("sh5001 stop successful \n"); + else + printf("sh5001 stop failed \n"); +#endif +} + +void gyro_check(void) +{ +#ifdef GYRO_SH5001 + SH5001_ReadFIFO(); +#endif +} + +bool gyro_check_exist(void) +{ +#ifdef GYRO_SH5001 + if(gyro_get_chip_id() != SH5001_ID) + return false; + else + return true; +#endif + return false; +} + +gyro_data_t gyro_get_data(void) +{ + gyro_data_t data = {0}; +#ifdef GYRO_SH5001 + data = sh5001_get_gyro_data(); + // printf("%.3f %.3f %.3f\r\n",data.x,data.y,data.z); +#endif + return data; +} + +uint8_t gyro_get_chip_id(void) +{ +#ifdef GYRO_SH5001 + return SH5001_get_chip_id(); +#endif + return 0; +} \ No newline at end of file diff --git a/code/sdk/zhihui/drivers/gyro/service/gyro_hal.h b/code/sdk/zhihui/drivers/gyro/service/gyro_hal.h new file mode 100644 index 000000000..2e732483f --- /dev/null +++ b/code/sdk/zhihui/drivers/gyro/service/gyro_hal.h @@ -0,0 +1,42 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2025-05-12 10:00:46 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-05-23 14:14:26 + * @FilePath: /sdk615/code/sdk/zhihui/drivers/gyro/service/gyro_hal.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +#ifndef GYRO_HAL_H__ +#define GYRO_HAL_H__ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#include "stdint.h" +#include "errcode.h" +#include + +typedef struct { + float x; + float y; + float z; +} gyro_data_t; + + +void gyro_power_on(void); +void gyro_power_off(void); +void gyro_check(void); +gyro_data_t gyro_get_data(void); +uint8_t gyro_get_chip_id(void); +bool gyro_check_exist(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif \ No newline at end of file diff --git a/code/sdk/zhihui/drivers/gyro/service/gyro_service.c b/code/sdk/zhihui/drivers/gyro/service/gyro_service.c index ef6bae79d..51e46eef4 100644 --- a/code/sdk/zhihui/drivers/gyro/service/gyro_service.c +++ b/code/sdk/zhihui/drivers/gyro/service/gyro_service.c @@ -9,71 +9,28 @@ #include "input_app.h" #include "cmsis_os2.h" #include "custom_utils.h" -#include "sh5001.h" +#include "gyro_hal.h" #include "gyro_service.h" +#ifdef ROTARYENCODER_MIXO +#include "mixo_service.h" +#endif // #include "custom_runtime.h" /*** * 其他cmd在Header里定义,对外开放 */ #define GYRO_SERVICE_CMD_TIMER_CHECK 0x11 -#define GYRO_CHECK_MS 30 - static bool g_gyro_service_initialled = false; -osTimerId_t g_gyro_service_timer = NULL; static bool g_gyro_sensor_exist = false; -static bool g_bat_timer_is_running = false; static unsigned long g_app_queue= 0xFFFFFFFF; -static bool gyro_service_running_stat = false; - -static void gyro_service_check_timer_callback(void* data); -static void gyro_service_timer_start_check(uint32_t rtc_ms) -{ - - if (g_bat_timer_is_running ) - osTimerStop(g_gyro_service_timer); - - if (gyro_service_running_stat == true) - osTimerStart(g_gyro_service_timer, rtc_ms); - - g_bat_timer_is_running = true; - -} void do_gyro_service_check_msg(int cmd); -static void gyro_service_check_timer_callback(void * data) -{ - unused(data); - - g_bat_timer_is_running = false; - - if(gyro_service_running_stat == true){ - // mmc5603_check(); //此处只能直接加到timer callback中,采用queue的话,新能跟不上,系统资源会挂掉。 - do_gyro_service_check_msg(GYRO_SERVICE_CMD_TIMER_CHECK); - // gyro_service_timer_start_check(gyro_CHECK_MS); - } - - - -} -void uapi_gyro_service_deinit(void) -{ - /* Stop the time and clear the pin map */ - osTimerStop(g_gyro_service_timer); - osTimerDelete(g_gyro_service_timer); - - g_bat_timer_is_running = false; - g_gyro_service_timer = NULL; -} - - - void do_gyro_service_check_msg(int cmd) { int ret; @@ -105,15 +62,9 @@ static void gyro_service_check_task(void const *arg) if (mail.comm.app == GYRO_SERVICE_CMD_TIMER_CHECK) { gyro_check(); }else if (mail.comm.app == GYRO_SERVICE_CMD_START_CHECK){ - gyro_start(); - LOS_Mdelay(30); - gyro_service_running_stat = true; - gyro_service_timer_start_check(GYRO_CHECK_MS); + gyro_power_on(); }else if (mail.comm.app == GYRO_SERVICE_CMD_STOP_CHECK){ - gyro_service_running_stat = false; - osTimerStop(g_gyro_service_timer); - gyro_stop(); - LOS_Mdelay(20); + gyro_power_off(); } @@ -128,19 +79,21 @@ void create_gyro_queue(void) } } -#define GYRO_BOARD_TASK_SIZE 0x1000 +#define GYRO_BOARD_TASK_SIZE 0x500 errcode_t uapi_gyro_service_init(void) { PRINT("uapi_gyro_service_init !\r\n"); if(!gyro_check_exist()) { - //TODO 设置气压计检测是否存在标识 + //TODO 设置陀螺仪检测是否存在标识 PRINT("gyro not found!\r\n"); return ERRCODE_FAIL; } g_gyro_sensor_exist = true; + gyro_power_off(); + app_task_definition_t taskcfg={0}; taskcfg.create_queue_handle = create_gyro_queue; taskcfg.attr.name="gyro_service"; @@ -156,18 +109,28 @@ errcode_t uapi_gyro_service_init(void) return ERRCODE_FAIL; } - g_gyro_service_timer = osTimerNew((osTimerFunc_t)gyro_service_check_timer_callback, osTimerPeriodic, NULL, NULL); - - return ERRCODE_SUCC; } -// void gyro_service_service_resume(void) -// { -// MMC_LOG("gyro_service_service resume!\r\n"); -// gyro_service_check_timer_callback(0); -// } -// void gyro_service_service_suspend(void) -// { -// MMC_LOG("gyro_service_service suspend!\r\n"); -// } \ No newline at end of file +void gyro_int_callback(pin_t pin, uintptr_t param) +{ + // PRINT("gyro_int_callback %d 0x%X\n",pin,param); + uapi_gpio_clear_interrupt(pin); + do_gyro_service_check_msg(GYRO_SERVICE_CMD_TIMER_CHECK); +} + +void gyro_start(void) +{ + do_gyro_service_check_msg(GYRO_SERVICE_CMD_START_CHECK); +#ifdef ROTARYENCODER_MIXO + mixo_stop(); +#endif +} + +void gyro_stop(void) +{ + do_gyro_service_check_msg(GYRO_SERVICE_CMD_STOP_CHECK); +#ifdef ROTARYENCODER_MIXO + mixo_start(); +#endif +} diff --git a/code/sdk/zhihui/drivers/gyro/service/gyro_service.h b/code/sdk/zhihui/drivers/gyro/service/gyro_service.h index 27f9f1d4a..3dd128822 100644 --- a/code/sdk/zhihui/drivers/gyro/service/gyro_service.h +++ b/code/sdk/zhihui/drivers/gyro/service/gyro_service.h @@ -1,3 +1,11 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-12-23 15:12:01 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-05-12 17:47:11 + * @FilePath: /sdk615/code/sdk/zhihui/drivers/gyro/service/gyro_service.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ /** * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n * @@ -18,7 +26,7 @@ extern "C" { #include "stdint.h" #include "errcode.h" - +#include "platform_core.h" #define GYRO_SERVICE_CMD_START_CHECK 0x12 #define GYRO_SERVICE_CMD_STOP_CHECK 0x13 @@ -26,8 +34,9 @@ extern "C" { errcode_t uapi_gyro_service_init(void); void uapi_gyro_service_deinit(void); void do_gyro_service_check_msg(int cmd); - - +void gyro_int_callback(pin_t pin, uintptr_t param); +void gyro_start(void); +void gyro_stop(void); #ifdef __cplusplus #if __cplusplus } diff --git a/code/sdk/zhihui/drivers/gyro/sh5001/sh5001.c b/code/sdk/zhihui/drivers/gyro/sh5001/sh5001.c index 77ff6b803..27035beb4 100644 --- a/code/sdk/zhihui/drivers/gyro/sh5001/sh5001.c +++ b/code/sdk/zhihui/drivers/gyro/sh5001/sh5001.c @@ -23,6 +23,8 @@ #define SH5001_I2C_BUS I2C_BUS_2 +static gyro_data_t gyro_data = {0}; + /****************************************************************** * Description: I2C or SPI bus interface functions and delay time function * @@ -1920,7 +1922,7 @@ void SH5001_ReadFIFO(void) SH5001_FIFO_Read_Data(fifoData, fifoEntriesCount); - printf("fc %d\r\n", fifoEntriesCount); + // printf("fc %d\r\n", fifoEntriesCount); for(i = 0; i < dataGroup; i++) { @@ -1931,14 +1933,18 @@ void SH5001_ReadFIFO(void) gyroData[1] = ((short)fifoData[j+9] << 8) | fifoData[j+8]; gyroData[2] = ((short)fifoData[j+11] << 8) | fifoData[j+10]; - printf("%d %d %d %d %d %d\r\n", accData[0], accData[1], accData[2],gyroData[0], gyroData[1], gyroData[2]); + gyro_data.x = (float)gyroData[0]; + gyro_data.y = (float)gyroData[1]; + gyro_data.z = (float)gyroData[2]; + + // printf("%d %d %d %d %d %d\r\n", accData[0], accData[1], accData[2],gyroData[0], gyroData[1], gyroData[2]); j = j + SH5001_WATERMARK_DIV; } // clear INT - // SH5001_INT_Read_Status01(); + SH5001_INT_Read_Status01(); } @@ -2077,6 +2083,26 @@ void SH5001_Get_Otpoffset(short vacc[3]) * return: SH5001_TRUE or SH5001_FALSE * ******************************************************************/ + +uint8_t SH5001_get_chip_id(void) +{ + unsigned char regData = 0; + unsigned char i = 0; + + // SH5001 chipID = 0xA1; + while((regData != 0xA1U) && (i++ < 3U)) + { + SH5001_read(SH5001_ADDRESS, SH5001_CHIP_ID, 1, ®Data); + if((i == 3) && (regData != 0xA1U)) + { + printf("SH5001 init fail, Chip ID = 0x%x\r\n", regData); + return SH5001_FALSE; + } + } + printf("SH5001 Chip ID = 0x%x\r\n", regData); + return regData; +} + unsigned char SH5001_init(void) { unsigned char regData = 0; @@ -3051,4 +3077,10 @@ void SH5001_Get_Adc_Polarity(short gyroPolarity[3]) int sh5001_get_version(void) { return MCU_VERSION_SH5001; +} + +gyro_data_t sh5001_get_gyro_data(void) +{ + gyro_data_t data = gyro_data; + return data; } \ No newline at end of file diff --git a/code/sdk/zhihui/drivers/gyro/sh5001/sh5001.h b/code/sdk/zhihui/drivers/gyro/sh5001/sh5001.h index 58ee98b5f..08cd2cd85 100644 --- a/code/sdk/zhihui/drivers/gyro/sh5001/sh5001.h +++ b/code/sdk/zhihui/drivers/gyro/sh5001/sh5001.h @@ -1,7 +1,9 @@ #ifndef __SH5001_H #define __SH5001_H -//#define SH5001_FIFO_WM_INT +#include "gyro_hal.h" + +#define SH5001_FIFO_WM_INT //#define SH5001_ACTIVITY_INT //#define SH5001_DATA_READY_INT @@ -12,6 +14,7 @@ ******************************************************************/ #define SH5001_ADDRESS (0x36U) #define SENODIA_VDD_3V3 1 +#define SH5001_ID 0xA1 /****************************************************************** * SH5001 Registers Macro Definitions @@ -690,6 +693,8 @@ extern void SH5001_FastOffsetComp(unsigned char SH5001Positon); extern void SH5001_initFIFO(void); extern void SH5001_ReadFIFO(void); - + +unsigned char SH5001_get_chip_id(void); +gyro_data_t sh5001_get_gyro_data(void); #endif diff --git a/code/sdk/zhihui/drivers/ppg/pah8009/sensor/pah800x_main.c b/code/sdk/zhihui/drivers/ppg/pah8009/sensor/pah800x_main.c index 279ab28eb..6f74e0c63 100644 --- a/code/sdk/zhihui/drivers/ppg/pah8009/sensor/pah800x_main.c +++ b/code/sdk/zhihui/drivers/ppg/pah8009/sensor/pah800x_main.c @@ -84,13 +84,12 @@ static uint8_t wear_status = 0; static osTimerId_t g_pah8009_timer = NULL; static uint8_t time_cnt = 0; +static uint8_t wear_cnt = 0; static int history_wear_status = -1; - -#if POLLING_MODE static int time_out = 40; -#endif + static uint8_t hrs_num = 0; static int32_t sum_hrs = 0; @@ -148,15 +147,26 @@ static void pah8009_wearstatus_update(int wear_status) { if(history_wear_status != wear_status) { + if(uapi_dev_runtime_get_train_status()) + { + // printf("wear_cnt : %d\n",wear_cnt); + wear_cnt++; + if(wear_cnt < 50) + return; + } + wear_cnt = 0; history_wear_status = wear_status; #ifdef SUPPORT_CYWEE_SERVICE cywee_wear_status_update((uint8_t *)&history_wear_status); #endif - // if(wear_status != 1) - // { - // pah8009_unwearstatus_update(); - // } + if(history_wear_status != 1) + { + // pah8009_unwearstatus_update(); + avg_hrs = 0; + } } + else + wear_cnt = 0; } @@ -385,6 +395,7 @@ void pah_sensor_stop(void) left = 0; right = -1; avg_hrs = 0; + wear_cnt = 0; } void ppg_interrupt_handle(void) @@ -478,18 +489,18 @@ static void get_avg_hrs(uint8_t hrs) { int32_t min_hrs = 0; int32_t max_hrs = 0; - if(hrs_num == 7) + if(hrs_num == 5) { sum_hrs -= hrs_data[left]; hrs_data[left] = 0; left++; - left = left % 7; + left = left % 5; hrs_num--; } hrs_num++; right++; - right = right % 7; + right = right % 5; hrs_data[right] = hrs; sum_hrs += hrs_data[right]; @@ -569,7 +580,7 @@ void hr_alg_task(void) #ifdef SUPPORT_PPG_SERVICE time_cnt++; - if(time_cnt >= 15) + if(time_cnt >= 20) { // ppg_msg_callback_t func = ppg_get_send_msg_callback_func(); @@ -591,6 +602,13 @@ void hr_alg_task(void) ble_ppgtest_server_send_input_report(&avg_hrs,1); } #endif + +#ifdef SUPPORT_CYWEE_SERVICE + // if(uapi_dev_runtime_get_train_status()) + { + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_CHECK_ACC, NULL); // 检查gsensor是否停止 + } +#endif } @@ -1463,6 +1481,11 @@ static void process(uint64_t timestamp) ppg_mems_data.MEMS_Data[0] = mems_data[0] * 2048 / 10;//ReadGSensorX(); ppg_mems_data.MEMS_Data[1] = mems_data[1] * 2048 / 10;//ReadGSensorY(); ppg_mems_data.MEMS_Data[2] = mems_data[2] * 2048 / 10;//ReadGSensorZ(); + + // ppg_mems_data.MEMS_Data[0] = mems_data[0] * 4096 / 10;//ReadGSensorX(); + // ppg_mems_data.MEMS_Data[1] = mems_data[1] * 4096 / 10;//ReadGSensorY(); + // ppg_mems_data.MEMS_Data[2] = mems_data[2] * 4096 / 10;//ReadGSensorZ(); + // printf("x:%f y:%f z:%f\n",ppg_mems_data.MEMS_Data[0],ppg_mems_data.MEMS_Data[1],ppg_mems_data.MEMS_Data[2]); ppg_mems_data.duration = duration; @@ -1724,6 +1747,28 @@ void pah8009_int_handler(void) } +void pah8009_check_int(void) +{ + if(work_mode != 1) + { + // printf("work_mode != 1\n"); + return; + } + + if(!timeout) + { + // printf("pah8009_check_int \n"); +#ifdef SUPPORT_PPG_SERVICE + send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_INT_HANDLER); +#endif + + } + else + { + timeout = 0; + } +} + void pah8009_timer_handler(void) { ppg_sensor_task_polling(); @@ -1743,10 +1788,11 @@ void pah8009_timer_handler(void) static void pah8009_timer_callback(void) { - // printf("pah8009_timer_callback \n"); -#ifdef SUPPORT_PPG_SERVICE - send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_DO_PPG_HRS_TIMER_CALLBACK); -#endif + printf("pah8009_timer_callback \n"); +// #ifdef SUPPORT_PPG_SERVICE +// send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_CHECK_INT); +// #endif + pah8009_check_int(); } static void pah8009_timer_init(void) @@ -1755,26 +1801,6 @@ static void pah8009_timer_init(void) g_pah8009_timer = osTimerNew((osTimerFunc_t)pah8009_timer_callback, osTimerPeriodic, NULL, NULL); } -void pah8009_check_int(void) -{ -#if INTERRUPT_MODE - if(work_mode != 1) - { - // printf("work_mode != 1\n"); - return; - } - - if(!timeout) - { - // printf("pah8009_check_int \n"); - pah8009_int_handler(); - } - else - { - timeout = 0; - } -#endif -} void pah8009_reset(void) { @@ -1788,10 +1814,10 @@ void pah8009_control(char *mode,uint8_t enable) // printf("mode : %s ,enable : %d\n",mode,enable); if(!enable) { -#if POLLING_MODE - if(g_pah8009_timer != NULL) + + if(g_pah8009_timer != NULL && work_mode < 3 && work_mode > 0) osTimerStop(g_pah8009_timer); -#endif + pah_sensor_stop(); work_mode = 0; if(uapi_dev_runtime_get_sleep_monitoring_status() && uapi_dev_runtime_get_hrs_passivity_flag()) @@ -1802,21 +1828,13 @@ void pah8009_control(char *mode,uint8_t enable) } else { -#if POLLING_MODE - pah8009_timer_init(); -#endif - - time_cnt = 0; - if (strcmp(mode, "hrs") == 0) { pah_sensor_init(diw_4mm_g_ir_hrd); // auto_mode_sensor_start(); work_mode = 1; // touch_only_sensor_start(); ppg_only_sensor_start(); -#if POLLING_MODE - time_out = 40; -#endif + } else if (strcmp(mode, "hrv") == 0) { // md = HRV_MODE; } else if (strcmp(mode, "spo2") == 0) { @@ -1824,25 +1842,26 @@ void pah8009_control(char *mode,uint8_t enable) pah_sensor_init(diw_4mm_ir_r_ir_spo2); ppg_only_sensor_start(); work_mode = 2; -#if POLLING_MODE - time_out = 40; -#endif } else if (strcmp(mode, "leaklight") == 0) { // md = FT_LEAK_LIGHT_MODE; factory_test_mode(factory_test_leak_light_target_sample, 0, 0, 0, 0); // extern void test_library_HRD(void); // test_library_HRD(); + work_mode = 4; } else if (strcmp(mode, "wear") == 0) { pah_sensor_init(diw_4mm_g_ir_hrd); touch_only_sensor_start(); -#if POLLING_MODE - time_out = 5000; -#endif + work_mode = 3; } -#if POLLING_MODE - if(g_pah8009_timer != NULL) + + if(work_mode < 3 && work_mode > 0) + pah8009_timer_init(); + + time_cnt = 0; + + if(g_pah8009_timer != NULL && work_mode < 3 && work_mode > 0) osTimerStart(g_pah8009_timer,time_out); -#endif + } } diff --git a/code/sdk/zhihui/drivers/ppg/pah8009/sensor/pah_800x_config.h b/code/sdk/zhihui/drivers/ppg/pah8009/sensor/pah_800x_config.h index b484f21c2..ea45c7366 100644 --- a/code/sdk/zhihui/drivers/ppg/pah8009/sensor/pah_800x_config.h +++ b/code/sdk/zhihui/drivers/ppg/pah8009/sensor/pah_800x_config.h @@ -40,8 +40,8 @@ #define ENABLE_AE_RECONVERGENCE 1 -#define PAH_800x_ENABLE_DEBUG_PRINT -#define PAH_800x_ENABLE_LOG_PRINT +// #define PAH_800x_ENABLE_DEBUG_PRINT +// #define PAH_800x_ENABLE_LOG_PRINT #ifdef PAH_800x_ENABLE_LOG_PRINT @@ -67,8 +67,8 @@ * This definition will enable the corresponding demo functionin main.c * If select INT mode, then slect following INT configuration type */ -#define INTERRUPT_MODE 0 -#define POLLING_MODE 1 +#define INTERRUPT_MODE 1 +#define POLLING_MODE 0 #define Test_pattern_mode 0 /* -- 2.17.1