From: SnickerSun Date: Sun, 31 Dec 2023 05:13:36 +0000 (+0800) Subject: 添加hx3695心率驱动,当下支持hrs,spo2,leaklight和graycard测试 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=0a3b09e127c2415afcd149f7da26ec79817911a7;p=mirrors%2FFD230.git 添加hx3695心率驱动,当下支持hrs,spo2,leaklight和graycard测试 --- diff --git a/code/sdk/application/brandy/brandy_standard/service_init.c b/code/sdk/application/brandy/brandy_standard/service_init.c index 359fe53ff..f7547eb57 100755 --- a/code/sdk/application/brandy/brandy_standard/service_init.c +++ b/code/sdk/application/brandy/brandy_standard/service_init.c @@ -37,6 +37,10 @@ #ifdef SUPPORT_AT_MEDIA #include "media_cmd_manager.h" #endif + +#ifdef SUPPORT_AT_HX3695 +#include "hx3695_at_cmd.h" +#endif #include "log_file.h" #ifdef CONFIG_OTA_UPDATE_SUPPORT #include "upg.h" @@ -75,6 +79,12 @@ static void register_at_service(void) at_cmd_table_t *media_table = get_media_cmd_table(&media_cmd_count); at_cmd_add_moudle(media_table, media_cmd_count); #endif + +#ifdef SUPPORT_AT_HX3695 + uint32_t hx3695_cmd_count; + at_cmd_table_t *hx3695_table = get_hx3695_cmd_table(&hx3695_cmd_count); + at_cmd_add_moudle(hx3695_table, hx3695_cmd_count); +#endif } #ifdef CONFIG_OTA_UPDATE_SUPPORT diff --git a/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h b/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h index 2e28e1ae4..014633a54 100755 --- a/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h +++ b/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h @@ -248,8 +248,14 @@ const hal_gpio_config_t g_gpio_function_config[PIN_MAX_NUMBER] = { // // S_AGPIO_L13 SCLK_BT // { S_AGPIO_L13, HAL_GPIO_DIRECTION_INPUT, NULL, 0, NULL }, + // S_AGPIO_L26 心率复位 PPG reset + { S_AGPIO_L26, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL }, + // S_AGPIO_R0 PRG_LED_POWER ON 心率等电源控制脚 + { S_AGPIO_R0, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL }, + + //S_AGPIO_L21 NTC_VDD_ON 给低打开 NTC上拉电源 - { S_AGPIO_L21, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL }, + { S_AGPIO_L21, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL }, }; diff --git a/code/sdk/drivers/boards/brandy_evb/product/product.h b/code/sdk/drivers/boards/brandy_evb/product/product.h index eeabd6293..ddddd2aa8 100755 --- a/code/sdk/drivers/boards/brandy_evb/product/product.h +++ b/code/sdk/drivers/boards/brandy_evb/product/product.h @@ -72,5 +72,5 @@ #define EMMC_SD_BUSWIDTH MMCSD_BUSWIDTH_8 #define PARTITION_EXIST YES #define ALIPAY_SEC_I2C_INDEX I2C_BUS_3 -#define ALIPAY_SEC_GPIO S_AGPIO_L29 +#define ALIPAY_SEC_GPIO S_AGPIO_R1 #endif diff --git a/code/sdk/drivers/chips/brandy/clocks/drivers/acore/clocks_config_priv.c b/code/sdk/drivers/chips/brandy/clocks/drivers/acore/clocks_config_priv.c index 99b1a1b8f..861e30cf7 100755 --- a/code/sdk/drivers/chips/brandy/clocks/drivers/acore/clocks_config_priv.c +++ b/code/sdk/drivers/chips/brandy/clocks/drivers/acore/clocks_config_priv.c @@ -371,7 +371,7 @@ static const system_mcu_perip_clk_t g_system_mcu_perp_clk_set_config[] = { {HAL_CLOCKS_APP_UART_H1_CLK, TURN_ON}, // uart h1 clock {HAL_CLOCKS_APP_I2C0_CLK, TURN_OFF}, // i2c0 clock {HAL_CLOCKS_APP_I2C1_CLK, TURN_ON}, // i2c1 clock - {HAL_CLOCKS_APP_I2C2_CLK, TURN_OFF}, // i2c2 clock + {HAL_CLOCKS_APP_I2C2_CLK, TURN_ON}, // i2c2 clock {HAL_CLOCKS_APP_I2C3_CLK, TURN_ON}, // i2c3 clock {HAL_CLOCKS_APP_QSPI_1CS_CLK, TURN_ON}, // qspi clock {HAL_CLOCKS_APP_XIP_BUS_CLK, TURN_ON}, // xip bus clock diff --git a/code/sdk/drivers/peripheral/ppg/CMakeLists.txt b/code/sdk/drivers/peripheral/ppg/CMakeLists.txt index 8d59792ff..6d67b878e 100644 --- a/code/sdk/drivers/peripheral/ppg/CMakeLists.txt +++ b/code/sdk/drivers/peripheral/ppg/CMakeLists.txt @@ -13,6 +13,7 @@ set(SOURCES ${SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/hx3695/hx3695_hrv_agc.c ${CMAKE_CURRENT_SOURCE_DIR}/hx3695/hx3695_spo2_agc.c ${CMAKE_CURRENT_SOURCE_DIR}/hx3695/hx3695_hrs_custom.c + ${CMAKE_CURRENT_SOURCE_DIR}/hx3695/hx3695_at_cmd.c ) set(PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/hx3695 @@ -35,6 +36,7 @@ set(PRIVATE_DEFINES ) set(PUBLIC_DEFINES +SUPPORT_AT_HX3695 ) # use this when you want to add ccflags like -include xxx diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c index 38aabca31..232c064e1 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c @@ -155,7 +155,7 @@ void hx3695_delay_ms(uint32_t ms) bool hx3695_write_reg(uint8_t addr, uint8_t data) { - tyhx_write_reg(I2C_DEV_8ADDR,addr,data); + tyhx_write_reg(addr,data); return true; } @@ -164,7 +164,7 @@ uint8_t hx3695_read_reg(uint8_t addr) { uint8_t data_buf = 0; - tyhx_read_regs(I2C_DEV_8ADDR,addr,&data_buf,1); + tyhx_read_regs(addr,&data_buf,1); return data_buf; } @@ -172,7 +172,7 @@ uint8_t hx3695_read_reg(uint8_t addr) bool hx3695_brust_read_reg(uint8_t addr, uint8_t *buf, uint8_t length) { //TYHX_LOG("brust read\r\n"); - tyhx_read_regs(I2C_DEV_8ADDR,addr,buf,length); + tyhx_read_regs(addr,buf,length); return true; } @@ -296,13 +296,13 @@ uint16_t hx3695_read_fifo_data(int32_t *buf, uint8_t phase_num, uint8_t sig) data_len_h = hx3695_read_reg(0x21); data_len_l = hx3695_read_reg(0x20); fifo_data_length = (((data_len_h&0x01)<<8)|data_len_l); -// SEGGER_RTT_printf(0,"fifo_data_length = %d\r\n", fifo_data_length); +// AGC_LOG("fifo_data_length = %d\r\n", fifo_data_length); if(fifo_data_length<2*phase_num) { return 0; } fifo_read_length = ((fifo_data_length-phase_num)/phase_num)*phase_num; -// SEGGER_RTT_printf(0,"fifo_data_length_change = %d\r\n", fifo_read_length); +// AGC_LOG("fifo_data_length_change = %d\r\n", fifo_read_length); fifo_read_bytes = fifo_read_length*3; if(read_fifo_first_flg == 1) { @@ -312,7 +312,7 @@ uint16_t hx3695_read_fifo_data(int32_t *buf, uint8_t phase_num, uint8_t sig) hx3695_brust_read_reg(0x22, fifo_data_buf, fifo_read_bytes); // for(ii=0; ii>5); + AGC_LOG("fifo_length = %d/%d, %d %d\r\n", ii+1,fifo_read_length,buf[ii],fifo_data_buf[ii*3+2]>>5); } data_flg_start = fifo_data_buf[2]>>5; data_flg_end = fifo_data_buf[fifo_read_bytes-1]>>5; @@ -356,7 +356,7 @@ uint16_t hx3695_read_fifo_data(int32_t *buf, uint8_t phase_num, uint8_t sig) } for(ii=0; ii= HX3695_MAX_ARGC) { + return HX3695_FAILED; + } + } else { + argv[*argc][pos] = para[i]; + pos++; + if (pos >= HX3695_MAX_ARGV_LEN) { + return HX3695_FAILED; + } + } + } + if (pos != 0) { + *argc += 1; + } + + return HX3695_SUCCESS; +} + + +static uint32_t hx3695_do_test(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + uint8_t argv[HX3695_MAX_ARGC][HX3695_MAX_ARGV_LEN] = { 0 }; + uint32_t argc = 0; + + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != HX3695_SUCCESS) { + TYHX_ERROR("HX3695TEST ATCMD Convert Command Failed\n"); + return ERRCODE_FAIL; + } + + if (argc != 2) { + TYHX_ERROR("HX3695TEST ATCMD Set Parameter Failed\n"); + return ERRCODE_FAIL; + } + char *mode = (char*)argv[0]; + WORK_MODE_T md = NULL_MODE; + if (strcmp(mode, "hrs") == 0) { + md = HRS_MODE; + } else if (strcmp(mode, "hrv") == 0) { + md = HRV_MODE; + } else if (strcmp(mode, "spo2") == 0) { + md = SPO2_MODE; + } else if (strcmp(mode, "leaklight") == 0) { + md = FT_LEAK_LIGHT_MODE; + } else if (strcmp(mode, "graycard") == 0) { + md = FT_GRAY_CARD_MODE; + } + char *enable = (char *)argv[1]; + if (strcmp(enable, "enable") == 0) { + + uapi_pm_control(PM_APP_WAKE_NEEDED); + tyhx_poweron(); + hx3695_init(md); + } else { + if(md == HRS_MODE|| md == FT_LEAK_LIGHT_MODE || md == FT_GRAY_CARD_MODE) + { +#ifdef HRS_ALG_LIB + hx3695_hrs_disable(); +#endif + }else if(md == HRV_MODE) + { +#ifdef HRV_ALG_LIB + hx3695_hrv_disable(); +#endif + }else if(md == SPO2_MODE) + { +#ifdef SPO2_ALG_LIB + hx3695_spo2_disable(); +#endif + } + + uapi_pm_control(PM_APP_WAKE_NONEED); + tyhx_poweroff(); + } + + return ERRCODE_SUCC; +} + +static const at_cmd_table_t g_hx3695_cmd[] = { + { (char *)"AT^HX3695TEST", hx3695_do_test, (char *)"hrs enable" }, +}; + +at_cmd_table_t *get_hx3695_cmd_table(uint32_t *cmd_count) +{ + *cmd_count = ARRAY_COUNT(g_hx3695_cmd); + return (at_cmd_table_t *)g_hx3695_cmd; +} + + + +#endif + +#endif \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_at_cmd.h b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_at_cmd.h new file mode 100644 index 000000000..6d7574b12 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_at_cmd.h @@ -0,0 +1,32 @@ +/** + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n + * + * Description: Provides at cmd register func \n + * Author: @CompanyNameTag \n + * History: \n + * 2022-07-20, Create file. \n + */ +#ifndef HX3695_AT_PROCESS_H +#define HX3695_AT_PROCESS_H + +#include +#include +#include "errcode.h" +#include "soc_osal.h" +#include "at_cmd_api.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +at_cmd_table_t *get_hx3695_cmd_table(uint32_t *cmd_count); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_agc.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_agc.c index 65da39f93..7ea0bc334 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_agc.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_agc.c @@ -114,7 +114,7 @@ hrs_wear_msg_code_t hx3695_hrs_wear_mode_check(WORK_MODE_T mode, int32_t infrare hrs_wear_status = MSG_HRS_NO_WEAR; } } -// SEGGER_RTT_printf(0,"hrs ir_data: %d, hrs_wear_status_pre=%d, hrs_wear_status=%d\r\n", +// AGC_LOG("hrs ir_data: %d, hrs_wear_status_pre=%d, hrs_wear_status=%d\r\n", // infrared_data,hrs_wear_status_pre,hrs_wear_status); if(mode == WEAR_MODE) { @@ -125,7 +125,7 @@ hrs_wear_msg_code_t hx3695_hrs_wear_mode_check(WORK_MODE_T mode, int32_t infrare hrs_wear_status_pre = hrs_wear_status; if(hrs_wear_status_pre == MSG_HRS_NO_WEAR) { - SEGGER_RTT_printf(0,"run here_low_pow!! \r\n"); + AGC_LOG("run here_low_pow!! \r\n"); hx3695_hrs_low_power(); @@ -490,7 +490,7 @@ void hx3695_hrs_cal_off(void) hx3695_write_reg(0x5c,0x08); //Chip state machine work normal hx3695_delay_ms(5); read_fifo_first_flg = 1; -// SEGGER_RTT_printf(0,"caloff_fifo: %d\r\n", (fifo_data_temp[0]|(fifo_data_temp[1]<<8)|(fifo_data_temp[2]<<16))); +// AGC_LOG("caloff_fifo: %d\r\n", (fifo_data_temp[0]|(fifo_data_temp[1]<<8)|(fifo_data_temp[2]<<16))); } void read_hrs_data_packet(int32_t *s_buf) @@ -515,7 +515,7 @@ void read_hrs_data_packet(int32_t *s_buf) s_buf[6] = ((databuf4[0])|(databuf4[1]<<8)|(databuf4[2]<<16)); s_buf[7] = ((databuf4[3])|(databuf4[4]<<8)|(databuf4[5]<<16)); -// SEGGER_RTT_printf(0,"phase7_data: %d, phase8_data: %d\r\n", s_buf[6],s_buf[7]); +// AGC_LOG("phase7_data: %d, phase8_data: %d\r\n", s_buf[6],s_buf[7]); } @@ -552,7 +552,7 @@ void hx3695_hrs_read_data_packet(int32_t *buf) // TYHX_LOG("tyhx_here ! \r\n"); -// SEGGER_RTT_printf(0,"P1~P4: %x, %x %x, %x \r\n", P1,P2,P3,P4); +// AGC_LOG("P1~P4: %x, %x %x, %x \r\n", P1,P2,P3,P4); } @@ -915,8 +915,8 @@ uint8_t hx3695_hrs_read(hrs_sensor_data_t * s_dat) } // TYHX_LOG("ppg_state: %d ,hrs_cal_state: %d\r\n",s_ppg_state,hrs_cal_state); data_count = hx3695_read_fifo_data(s_buf,hrs_phase_num,1); - //SEGGER_RTT_printf(0,"ppg data size: %d %d\r\n", data_count,hrs_phase_num); -// SEGGER_RTT_printf(0,"af_hx3695_read_fifo_data:::%d %d %d\r\n", hx3695_read_reg(0X2a),hx3695_read_reg(0X2b),hx3695_read_reg(0X2c)); + //AGC_LOG("ppg data size: %d %d\r\n", data_count,hrs_phase_num); +// AGC_LOG("af_hx3695_read_fifo_data:::%d %d %d\r\n", hx3695_read_reg(0X2a),hx3695_read_reg(0X2b),hx3695_read_reg(0X2c)); s_dat->count = data_count; read_hrs_data_packet(ps_data); @@ -930,14 +930,14 @@ uint8_t hx3695_hrs_read(hrs_sensor_data_t * s_dat) PPG_buf[i] = PPG_src_data * 2; ir_buf[i] = PPG_src_data2 * 2; //Ir_src_data; -// SEGGER_RTT_printf(0,"PPG_data: %d , PPG_src_data2: %d\r\n", PPG_src_data,PPG_src_data2); +// AGC_LOG("PPG_data: %d , PPG_src_data2: %d\r\n", PPG_src_data,PPG_src_data2); hx3695_hrs_wear_mode_check(HRS_MODE,Ir_src_data); -// SEGGER_RTT_printf(0,"hx3690_hrs_wear_mode_check:::%d %d %d\r\n", hx3695_read_reg(0X2a),hx3695_read_reg(0X2b),hx3695_read_reg(0X2c)); - // SEGGER_RTT_printf(0,"fifo:%d/%d %d %d, fifo_data: %d %d %d %d\r\n" ,1+i,data_count, +// AGC_LOG("hx3690_hrs_wear_mode_check:::%d %d %d\r\n", hx3695_read_reg(0X2a),hx3695_read_reg(0X2b),hx3695_read_reg(0X2c)); + // AGC_LOG("fifo:%d/%d %d %d, fifo_data: %d %d %d %d\r\n" ,1+i,data_count, // PPG_buf[i],ir_buf[i],s_buf[i*3],s_buf[i*3+1],s_buf[i*3+2],calReg_Hrs.LED); } ps_green_data = ps_data[1]; // - ((ps_data[2]+ps_data[0])>>1); -// SEGGER_RTT_printf(0,"ps_green_data: %d PS8: %d, PS7: %d\r\n", ps_green_data,ps_data[7],ps_data[6]); +// AGC_LOG("ps_green_data: %d PS8: %d, PS7: %d\r\n", ps_green_data,ps_data[7],ps_data[6]); if (ps_green_data<300000 || ps_green_data>800000) { recal = true; diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_custom.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_custom.c index 70d70776e..6a6224b15 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_custom.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_custom.c @@ -5,36 +5,227 @@ #include #include "tyhx_hrs_custom.h" +#include "osal_timer.h" +#include "osal_mutex.h" +#include "pinctrl.h" +#include "chip_io.h" +#include "time.h" +#include "i2c.h" +#include "gpio.h" +#include "hal_gpio.h" +#include "hal_i2c.h" +#include "soc_osal.h" +#include "tcxo.h" +typedef struct { + i2c_bus_t i2c_id; + uint32_t i2c_speed; +} hx3695_ctrl_attr; + +static hx3695_ctrl_attr g_hx3695_ctl_handler={HX3695_I2C_BUS,400000}; +static uint8_t g_hx3695_installed = 0; +static errcode_t hx3695_i2c_init(void) +{ + errcode_t result; + /* init i2c */ + if ( g_hx3695_installed == 1 ) + return ERRCODE_SUCC; + + result = uapi_i2c_master_init(HX3695_I2C_BUS, 400000, I2C_SPEED_MODE_FS); /* 400000: 400KHz */ + if (result != ERRCODE_SUCC) { + TYHX_ERROR("hx3695 i2c init fail! ret=0x%x", result); + return ERRCODE_FAIL; + } + + TYHX_WARNING("hx3695:i2c_id = %d i2c_speed = %d slave_addr = 0x%x \r\n", + HX3695_I2C_BUS, 400000, HX3695_I2C_DEV_8ADDR); + + g_hx3695_installed = 1; + + return ERRCODE_SUCC; +} + +uint32_t tyhx_write_reg(uint8_t reg_addr, uint8_t reg) +{ + errcode_t ret; + uint32_t retry; + i2c_data_t data; + uint8_t *write_data = NULL; + uint16_t send_len; + uint8_t *data_buf=® + uint16_t data_len=1; + + hx3695_i2c_init(); + send_len = data_len + sizeof(uint8_t); + write_data = (uint8_t *)osal_kmalloc(send_len, OSAL_GFP_KERNEL); + if (write_data == NULL) { + TYHX_ERROR("hx3695 send buff malloc fail!"); + return ERRCODE_FAIL; + } + write_data[0] = reg_addr; + ret = (uint32_t)memcpy_s(write_data + sizeof(uint8_t), send_len - sizeof(uint8_t), data_buf, data_len); + if (ret != EOK) { + TYHX_ERROR("hx3695 send_buf content copy fail! ret=0x%x", ret); + return ret; + } + + data.send_buf = write_data; + data.send_len = send_len; + data.receive_buf = NULL; + data.receive_len = 0; + + for (retry = 0; retry < HX3695_I2C_TIME_MAX; retry++) { + ret = uapi_i2c_master_write(HX3695_I2C_BUS, HX3695_I2C_DEV_8ADDR, &data); + if (ret == ERRCODE_SUCC) { + break; + } + } + if (ret != ERRCODE_SUCC) { + TYHX_ERROR("hx3695 data write fail! ret=0x%x", ret); + return ret; + } + + osal_kfree(write_data); + return ERRCODE_SUCC; +} + +uint32_t tyhx_read_regs(uint8_t reg_addr, uint8_t *data_buf, uint8_t data_len) +{ + errcode_t ret; + uint32_t retry; + i2c_data_t data; + + hx3695_i2c_init(); + memset_s(data_buf, data_len, 0, data_len); + data.send_buf = ®_addr; + data.send_len = 1; + data.receive_buf = data_buf; + data.receive_len = data_len; + + for (retry = 0; retry < HX3695_I2C_TIME_MAX; retry++) { + ret = uapi_i2c_master_writeread(HX3695_I2C_BUS, HX3695_I2C_DEV_8ADDR, &data); + if (ret == ERRCODE_SUCC) { + break; + } + } + if (ret != ERRCODE_SUCC) { + TYHX_ERROR("hx3695 data read fail! ret=0x%x", ret); + return ret; + } + + return ERRCODE_SUCC; +} // us 延时函数, 客户需填写 void tyhx_delay_us(uint32_t us) { - + uapi_tcxo_delay_us(us); } void tyhx_delay_ms(uint32_t ms) { + uapi_tcxo_delay_ms(ms); +} + + + +#include "cmsis_os2.h" +#define BUTTON_APP_TIMER_INTERVAL 20 +osTimerId_t g_timer40_timer = NULL; +osTimerId_t g_timer320_timer = NULL; +static uint8_t g_hx3695_timer_installed = 0; + +static void timer40_func(void) +{ + agc_timeout_handler(NULL); } -// i2c 写函数, 客户需填写, 地址0x44(7bit) -bool tyhx_write_reg(uint8_t i2c_addr,uint8_t reg_addr, uint8_t data) +static void timer320_func(void) +{ + heart_rate_meas_timeout_handler(NULL); +} +bool tyhx_timer_init(void) { - return 1; + if (g_hx3695_timer_installed == 1) + return true; + g_timer40_timer = osTimerNew((osTimerFunc_t)timer40_func, osTimerPeriodic, NULL, NULL); + g_timer320_timer = osTimerNew((osTimerFunc_t)timer320_func, osTimerPeriodic, NULL, NULL); + g_hx3695_timer_installed = true; + return true; } -// i2c 读函数, 客户需填写 -uint8_t tyhx_read_regs(uint8_t i2c_addr,uint8_t reg_addr,uint8_t *readbuf,uint8_t readlen) +void readFifoByHrsModule(void) { - return 0; + } bool tyhx_timer_start(uint32_t ms) { - return 1; + tyhx_timer_init(); + if( ms == TYHX_TIMER_40MS) + { + if(osTimerIsRunning(g_timer40_timer)==0) + osTimerStart(g_timer40_timer, TYHX_TIMER_40MS); + }else if (ms == TYHX_TIMER_320MS) + { + if(osTimerIsRunning(g_timer320_timer)==0) + osTimerStart(g_timer320_timer, TYHX_TIMER_320MS); + } + return 1; } bool tyhx_timer_stop(uint32_t ms) { - return 1; -} \ No newline at end of file + tyhx_timer_init(); + if( ms == TYHX_TIMER_40MS) + { + if(osTimerIsRunning(g_timer40_timer)) + osTimerStop(g_timer40_timer); + }else if (ms == TYHX_TIMER_320MS) + { + if(osTimerIsRunning(g_timer320_timer)) + osTimerStop(g_timer320_timer); + } + return 1; +} + +uint32_t tyhx_suspend(void) +{ + + return 0; +} +uint32_t tyhx_resume(void) +{ + + return 0; +} + +// S_AGPIO_L26 心率复位 PPG reset +#define GPIO_PIN_PRG_RESET S_AGPIO_L26 +// S_AGPIO_R0 PRG_LED_POWER ON 心率等电源控制脚 +#define GPIO_PIN_PRG_LED_ON S_AGPIO_R0 + +uint32_t tyhx_poweron(void) +{ + uapi_pin_set_mode(GPIO_PIN_PRG_RESET, (pin_mode_t)HAL_PIO_FUNC_GPIO); + uapi_gpio_set_dir(GPIO_PIN_PRG_RESET, GPIO_DIRECTION_OUTPUT); + uapi_gpio_set_val(GPIO_PIN_PRG_RESET, GPIO_LEVEL_HIGH); + + uapi_pin_set_mode(GPIO_PIN_PRG_LED_ON, (pin_mode_t)HAL_PIO_FUNC_GPIO); + uapi_gpio_set_dir(GPIO_PIN_PRG_LED_ON, GPIO_DIRECTION_OUTPUT); + uapi_gpio_set_val(GPIO_PIN_PRG_LED_ON, GPIO_LEVEL_HIGH); + return 0; +} +uint32_t tyhx_poweroff(void) +{ + uapi_pin_set_mode(GPIO_PIN_PRG_RESET, (pin_mode_t)HAL_PIO_FUNC_GPIO); + uapi_gpio_set_dir(GPIO_PIN_PRG_RESET, GPIO_DIRECTION_OUTPUT); + uapi_gpio_set_val(GPIO_PIN_PRG_RESET, GPIO_LEVEL_HIGH); + + uapi_pin_set_mode(GPIO_PIN_PRG_LED_ON, (pin_mode_t)HAL_PIO_FUNC_GPIO); + uapi_gpio_set_dir(GPIO_PIN_PRG_LED_ON, GPIO_DIRECTION_OUTPUT); + uapi_gpio_set_val(GPIO_PIN_PRG_LED_ON, GPIO_LEVEL_HIGH); + return 0; +} + + diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_spo2_agc.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_spo2_agc.c index 74b0be626..fa030eeea 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_spo2_agc.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_spo2_agc.c @@ -1081,11 +1081,11 @@ uint8_t hx3695_spo2_read(spo2_sensor_data_t * s_dat) ir_buf1[i] = Ir_src_data1; ir_buf2[i] = Ir_src_data2; - //SEGGER_RTT_printf(0,"G_LEDDAC: %d,R_LEDDAC: %d\r\n", calReg_SPO2.R_LEDDAC,cal.R_LEDDAC); + //AGC_LOG("G_LEDDAC: %d,R_LEDDAC: %d\r\n", calReg_SPO2.R_LEDDAC,cal.R_LEDDAC); //DEBUG_PRINTF(0,"%d/%d %d %d %d %d %d %d %d %d\r\n" ,1+i,data_count, // green_buf[i],red_buf[i],ir_buf[i],s_buf[i*4],s_buf[i*4+1],s_buf[i*4+2],s_buf[i*4+3],spo2_wear_status); -// SEGGER_RTT_printf(0,"fifo_data: %d/%d %d %d %d %d\r\n", i+1,data_count,s_buf[i*4], +// AGC_LOG("fifo_data: %d/%d %d %d %d %d\r\n", i+1,data_count,s_buf[i*4], // s_buf[i*4+1],s_buf[i*4+2],s_buf[i*4+3]); diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/tyhx_hrs_custom.h b/code/sdk/drivers/peripheral/ppg/hx3695/tyhx_hrs_custom.h index 133cd2543..de67fcb7c 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/tyhx_hrs_custom.h +++ b/code/sdk/drivers/peripheral/ppg/hx3695/tyhx_hrs_custom.h @@ -2,6 +2,7 @@ #define __TYHX_HRS_CUSTOM_H__ #include "debug_print.h" +#include "platform_core.h" typedef struct { int32_t leak_green; int32_t leak_red; @@ -30,34 +31,52 @@ extern FT_CUSTOM_RESULTS_t hrsresult; #define TYHX_LOG(ftm, ...) #endif +#define TYHX_ERROR(x, ...) \ + do { \ + PRINT("[ERROR]%s(%d): "x"\r\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \ + } while (0) + +#define TYHX_WARNING(x, ...) \ + do { \ + PRINT("[WARNING]%s(%d): "x"\r\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \ + } while (0) + #define CHIP_HX3695 -#define HRS_ALG_LIB -#define SPO2_ALG_LIB -#define HRV_ALG_LIB -#define CHECK_TOUCH_LIB -// #define HRS_BLE_APP -// #define INT_MODE -#define I2C_DEV_8ADDR 0X44 + +#define HX3695_I2C_BUS I2C_BUS_2 +#define HX3695_I2C_DEV_8ADDR 0X44 +#define HX3695_I2C_TIME_MAX 3 // us 延时函数, 客户需填写 void tyhx_delay_us(uint32_t us); void tyhx_delay_ms(uint32_t ms); // i2c 写函数, 客户需填写, 地址0x44(7bit) -bool tyhx_write_reg(uint8_t i2c_addr,uint8_t reg_addr, uint8_t data); +uint32_t tyhx_write_reg( uint8_t reg_addr, uint8_t data); // i2c 读函数, 客户需填写 -uint8_t tyhx_read_regs(uint8_t i2c_addr,uint8_t reg_addr,uint8_t *readbuf,uint8_t readlen); +uint32_t tyhx_read_regs( uint8_t reg_addr,uint8_t *readbuf,uint8_t readlen); -typedef enum{ - TYHX_TIMER_40MS, - TYHX_TIMER_320MS, -} TYHX_TIMER_TYPE; +#define TYHX_TIMER_40MS 40 +#define TYHX_TIMER_320MS 320 bool tyhx_timer_start(uint32_t ms); bool tyhx_timer_stop(uint32_t ms); +uint32_t tyhx_suspend(void); +uint32_t tyhx_resume(void); + + +uint32_t tyhx_poweron(void); +uint32_t tyhx_poweroff(void); + + +extern void hx3695_hrs_disable(void); +extern void hx3695_hrv_disable(void); +extern void hx3695_spo2_disable(void); + +void readFifoByHrsModule(void); #endif //__TYHX_HRS_CUSTOM_H__ \ No newline at end of file diff --git a/code/sdk/middleware/chips/brandy/pm/pm_adapt/pm_control.c b/code/sdk/middleware/chips/brandy/pm/pm_adapt/pm_control.c index fe3400ab6..7a22bdc8a 100755 --- a/code/sdk/middleware/chips/brandy/pm/pm_adapt/pm_control.c +++ b/code/sdk/middleware/chips/brandy/pm/pm_adapt/pm_control.c @@ -67,6 +67,20 @@ static void pm_sdio_power_off(void) pmu1_dig_pg_sub_power_on(PMU1_DIG_PG_MCU_HS, TURN_OFF); osal_irq_restore(irq); } +static void pm_ppg_power_on(void) +{ + uint32_t irq = osal_irq_lock(); + pmu_sdio_glb_common_reset(TURN_OFF); + hal_pmu_mcpu_perip_config(HAL_PMU_MCPU_PERIP_EMMC, HAL_PMU_PERIP_REQUEST_RESET); + hal_pmu_mcpu_perip_config(HAL_PMU_MCPU_PERIP_SDIO_HOST, HAL_PMU_PERIP_REQUEST_RESET); + + pmu1_dig_pg_sub_power_on(PMU1_DIG_PG_MCU_HS, TURN_ON); + + pmu_sdio_glb_common_reset(TURN_ON); + hal_pmu_mcpu_perip_config(HAL_PMU_MCPU_PERIP_EMMC, HAL_PMU_PERIP_REQUEST_DERESET); + hal_pmu_mcpu_perip_config(HAL_PMU_MCPU_PERIP_SDIO_HOST, HAL_PMU_PERIP_REQUEST_DERESET); + osal_irq_restore(irq); +} static void pm_display_power_on(void) { @@ -215,6 +229,15 @@ static void pm_sdio_power_control(pm_control_t type) } } +static void pm_app_wake_power_control(pm_control_t type) +{ + if (type == PM_APP_WAKE_NEEDED) { + uapi_pm_add_sleep_veto(PM_ID_SCREEN); + } else if (type == PM_APP_WAKE_NONEED) { + uapi_pm_remove_sleep_veto(PM_ID_SCREEN); + } +} + static void pm_display_power_control(pm_control_t type) { if (type == PM_DISPLAY_POWER_UP_AND_RUN) { @@ -258,6 +281,8 @@ void uapi_pm_control(pm_control_t type) pm_display_power_control(type); } else if (type <= PM_SDIO_POWER_OFF) { pm_sdio_power_control(type); + }else if (type <= PM_APP_WAKE_NONEED) { + pm_app_wake_power_control(type); } } diff --git a/code/sdk/middleware/chips/brandy/pm/pm_adapt/pm_control.h b/code/sdk/middleware/chips/brandy/pm/pm_adapt/pm_control.h index aafaed039..3ed1febe8 100755 --- a/code/sdk/middleware/chips/brandy/pm/pm_adapt/pm_control.h +++ b/code/sdk/middleware/chips/brandy/pm/pm_adapt/pm_control.h @@ -22,6 +22,8 @@ typedef enum { PM_DISPLAY_POWER_OFF = 5, // !< Power off off. PM_SDIO_POWER_UP_AND_RUN = 6, // !< Power up and run sdio PM_SDIO_POWER_OFF = 7, // !< Power off off. + PM_APP_WAKE_NEEDED = 8, + PM_APP_WAKE_NONEED = 9, PM_CONTROL_MAX, } pm_control_t;