From: SnickerSun Date: Wed, 3 Jan 2024 08:52:03 +0000 (+0800) Subject: hx3596 心率 合并参数,脱手检测工作 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=61d91e283488220e1bffc93df6d84878e2594207;p=mirrors%2FFD230.git hx3596 心率 合并参数,脱手检测工作 --- diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c index 232c064e1..a88f9d2b4 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c @@ -59,7 +59,9 @@ uint8_t hrs_phase_num= 3; uint8_t spo2_phase_num= 4; uint8_t hrv_phase_num = 4; extern uint8_t data_count; - +// extern uint8_t hr_no_living_dur; +uint8_t hr_no_living_dur; +// extern int tyhx_long_timer_tick; //spo2 agc const uint8_t hx3695_spo2_agc_red_idac = RED_AGC_OFFSET; const uint8_t hx3695_spo2_agc_ir_idac = IR_AGC_OFFSET; @@ -85,14 +87,14 @@ const uint8_t gsen_lv_val = 0; uint8_t read_fifo_first_flg = 0; //HRS_INFRARED_THRES -const int32_t hrs_ir_unwear_thres = 20000; -const int32_t hrs_ir_wear_thres = 10000; +const int32_t hrs_ir_unwear_thres = 4000; +const int32_t hrs_ir_wear_thres = 5000; //HRV_INFRARED_THRES -const int32_t hrv_ir_unwear_thres = 10000; //demo143b 25000 -const int32_t hrv_ir_wear_thres = 20000; +const int32_t hrv_ir_unwear_thres = 4000; //demo143b 25000 +const int32_t hrv_ir_wear_thres = 5000; //SPO2_INFRARED_THRES -const int32_t spo2_ir_unwear_thres = 8000; //demo143b 25000 30000 -const int32_t spo2_ir_wear_thres = 10000; +const int32_t spo2_ir_unwear_thres = 4000; //demo143b 25000 30000 +const int32_t spo2_ir_wear_thres = 5000; const uint8_t spo2_ir_wear_offset = 15; //CHECK_WEAR_MODE_THRES const int32_t check_mode_unwear_thre = 20000; @@ -246,26 +248,114 @@ void hx3695_gpioint_cfg(bool en) } #endif + + +#define RA_MEM_WRDATA_7_0 0x50 +#define RA_MEM_WRDATA_15_8 0x51 +#define RA_MEM_WRDATA_23_16 0x52 +#define RA_MEM_WRDATA_31_24 0x53 +#define RA_MEM_WRDATA_39_32 0x54 +#define RA_MEM_WRDATA_47_40 0x55 +#define RA_MEM_WRDATA_55_48 0x56 +#define RA_MEM_WRDATA_63_56 0x57 +#define RA_MEM_PWE_PULSE_CYCLE7_0 0x58 +#define RA_MEM_PWE_PULSE_CYCLE10_8 0x59 +#define RA_MEM_GLOBAL_CTRL 0x5A +#define RA_MEM_MANNUAL_CTRL 0x5B +#define RA_DEBUG_CFG0 0x5C +#define RA_DEBUG_CFG1 0x5D + +uint8_t REG_50_E, REG_51_E, REG_52_E, REG_53_E; + +void Efuse_Mode_Check(void) +{ + uint8_t efuse0, efuse1, efuse2, efuse3; + + hx3695_write_reg(RA_DEBUG_CFG0, 0x8) ; //0x5c + hx3695_write_reg(RA_DEBUG_CFG1, 0x2) ; //0x5d + hx3695_delay_us(1000); + + hx3695_write_reg(RA_MEM_GLOBAL_CTRL,0x10); //0x5A +// delay_us(2000); + + hx3695_write_reg(RA_MEM_MANNUAL_CTRL,0x04); + hx3695_write_reg(RA_MEM_MANNUAL_CTRL,0x00); + + hx3695_write_reg(RA_MEM_MANNUAL_CTRL,0x44); + hx3695_write_reg(RA_MEM_MANNUAL_CTRL,0x40); + + REG_50_E = hx3695_read_reg(0x50); + REG_51_E = hx3695_read_reg(0x51); + REG_52_E = hx3695_read_reg(0x52); + REG_53_E = hx3695_read_reg(0x53); + +// AGC_LOG("0x50=0x%x\r\n", REG_50_E); +// hal_gpt_delay_ms(100); +// AGC_LOG("0x51=0x%x\r\n", REG_51_E); +// hal_gpt_delay_ms(100); +// AGC_LOG("0x52=0x%x\r\n", REG_52_E); +// hal_gpt_delay_ms(100); +// AGC_LOG("0x53=0x%x\r\n", REG_53_E); +// hal_gpt_delay_ms(100); + + hx3695_write_reg(RA_MEM_GLOBAL_CTRL,0x20); //0x5A + hx3695_write_reg(0x50,REG_50_E); + hx3695_write_reg(0x51,REG_51_E); + hx3695_write_reg(0x52,REG_52_E); + hx3695_write_reg(0x53,REG_53_E); + + + hx3695_write_reg(RA_MEM_GLOBAL_CTRL,0x0); + + hx3695_write_reg(RA_DEBUG_CFG0, 0x0); //0x5c + hx3695_write_reg(RA_DEBUG_CFG1, 0x0); //0x5d + +} bool hx3695_chip_check(void) { uint8_t i = 0; uint8_t chip_id = 0; - for(i=0; i<10; i++) + for(i=0; i<5; i++) { -// hx3695_write_reg(0x02, 0x00); -// hx3695_delay_ms(5); + hx3695_write_reg(0x5c, 0x00); + hx3695_delay_ms(5); chip_id = hx3695_read_reg(0x00); if (chip_id == 0x65) { - TYHX_LOG(" %x, hx3695_chip_check ok\r\n",chip_id); + TYHX_LOG("hx3695_chip_check ok chip_id: 0x%x \r\n",chip_id); + Efuse_Mode_Check(); return true; } } - TYHX_LOG(" %x, hx3695_chip_check fail!\r\n",chip_id); + + TYHX_LOG(" hx3695_chip_check fail! chip_id: 0x%x \r\n", chip_id); + return false; } +uint8_t hx3695_get_chip_id(void) +{ + uint8_t i = 0; + uint8_t chip_id = 0; + for(i=0; i<5; i++) + { + hx3695_write_reg(0x5c, 0x00); + hx3695_delay_ms(5); + chip_id = hx3695_read_reg(0x00); + + if (chip_id == 0x65) + { + TYHX_LOG("hx3695_chip_check ok chip_id: 0x%x \r\n",chip_id); + return chip_id; + } + } + + TYHX_LOG(" hx3695_chip_check fail! chip_id: 0x%x \r\n", chip_id); + + return chip_id; +} + uint8_t hx3695_read_fifo_size(void) { uint8_t data_len_h,data_len_l; @@ -452,7 +542,7 @@ void hx3695_hrs_ppg_init(void) // ppg fs=25hz, phase conversion ready interupt e uint8_t phase1_tia_cap = 4; /* 0= ; 1= ; 2= ; 3= ; 4= ; 5= ; 6= ; 7= */ uint8_t phase1_led_drv1_cha_sel = 0; /* 1 = ldr1 NG; 2 = ldr2 GR; 4 = ldr3 IR; 8 = ldr4 RED; */ uint8_t phase1_led_drv2_cha_sel = 0; /*ldr5:0x20 ldr6: 0x40 red ldr8 0x80 ir */ - uint8_t phase1_pd_sel = 0x03; /* 1 = pd1; 2 = pd2; 4 = pd3*/ + uint8_t phase1_pd_sel = 0x0F; //0x03 /* 1 = pd1; 2 = pd2; 4 = pd3*/ uint8_t phase1_als_offset_idac = 0; /* 0~255 = 0 ~ 128ua , step = 0.5ua */ uint8_t phase1_led_offset_idac = 0; /* 0~255 = 0 ~ 64ua , step = 0.25ua */ uint8_t phase1_ldr1_cur = 0; /* 0~255 = 0 ~ 200ma, step = 0.8ma */ @@ -472,9 +562,9 @@ void hx3695_hrs_ppg_init(void) // ppg fs=25hz, phase conversion ready interupt e uint8_t phase2_inner_avg = 0; /* phase1 adc avg num 0=1, 1=2, 2=4, 3=8 , 4=16*/ uint8_t phase2_tia_res = 0; /* 0= 10K; 1= 20k; 2= 50k; 3= 100k; 4= 150k; 5= 200k; 6= 500k; 7= 1M*/ uint8_t phase2_tia_cap = 4; /* 0= ; 1= ; 2= ; 3= ; 4= ; 5= ; 6= ; 7= */ - uint8_t phase2_led_drv1_cha_sel = 0x10; //GREEN_LED_SLE; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ + uint8_t phase2_led_drv1_cha_sel = 0x50; //0x10 //GREEN_LED_SLE; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ uint8_t phase2_led_drv2_cha_sel = 0; - uint8_t phase2_pd_sel = 0x03; /* 1 = pd1; 2 = pd2; 4 = pd3*/ + uint8_t phase2_pd_sel = 0x0F; //0x0C //0x03 /* 1 = pd1; 2 = pd2; 4 = pd3*/ uint8_t phase2_als_offset_idac = 0; /* 0~255 = 0 ~ 128ua , step = 0.5ua */ uint8_t phase2_led_offset_idac = 0; /* 0~255 = 0 ~ 64ua , step = 0.25ua */ uint8_t phase2_ldr1_cur = 0; /* 0~255 = 0 ~ 200ma, step = 0.8ma */ @@ -495,7 +585,7 @@ void hx3695_hrs_ppg_init(void) // ppg fs=25hz, phase conversion ready interupt e uint8_t phase3_tia_cap = 4; /* 0= ; 1= ; 2= ; 3= ; 4= ; 5= ; 6= ; 7= */ uint8_t phase3_led_drv1_cha_sel = 0; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ uint8_t phase3_led_drv2_cha_sel = 0; - uint8_t phase3_pd_sel = 0x03; /* 1 = pd1; 2 = pd2; 4 = pd3*/ + uint8_t phase3_pd_sel = 0x0F; //0x03 /* 1 = pd1; 2 = pd2; 4 = pd3*/ uint8_t phase3_als_offset_idac = 0; /* 0~255 = 0 ~ 128ua , step = 0.5ua */ uint8_t phase3_led_offset_idac = 0; /* 0~255 = 0 ~ 64ua , step = 0.25ua */ uint8_t phase3_ldr1_cur = 0; /* 0~255 = 0 ~ 200ma, step = 0.8ma */ @@ -516,7 +606,7 @@ void hx3695_hrs_ppg_init(void) // ppg fs=25hz, phase conversion ready interupt e uint8_t phase4_tia_cap = 4; /* 0= ; 1= ; 2= ; 3= ; 4= ; 5= ; 6= ; 7= */ uint8_t phase4_led_drv1_cha_sel = 0; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ uint8_t phase4_led_drv2_cha_sel = 0; - uint8_t phase4_pd_sel = 0x0c; /* 1 = pd1; 2 = pd2; 4 = pd3*/ + uint8_t phase4_pd_sel = 0x0F; //0x0C /* 1 = pd1; 2 = pd2; 4 = pd3*/ uint8_t phase4_als_offset_idac = 0; /* 0~255 = 0 ~ 128ua , step = 0.5ua */ uint8_t phase4_led_offset_idac = 0; /* 0~255 = 0 ~ 64ua , step = 0.25ua */ uint8_t phase4_ldr1_cur = 0; /* 0~255 = 0 ~ 200ma, step = 0.8ma */ @@ -534,9 +624,9 @@ void hx3695_hrs_ppg_init(void) // ppg fs=25hz, phase conversion ready interupt e uint8_t phase5_inner_avg = 0; /* phase1 adc avg num 0=1, 1=2, 2=4, 3=8 , 4=16*/ uint8_t phase5_tia_res = 0; /* 0= 10K; 1= 20k; 2= 50k; 3= 100k; 4= 150k; 5= 200k; 6= 500k; 7= 1M*/ uint8_t phase5_tia_cap = 4; /* 0= ; 1= ; 2= ; 3= ; 4= ; 5= ; 6= ; 7= */ - uint8_t phase5_led_drv1_cha_sel = 0x10; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ + uint8_t phase5_led_drv1_cha_sel = 0x50; //0x10 /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ uint8_t phase5_led_drv2_cha_sel = 0; - uint8_t phase5_pd_sel = 0x0c; /* 1 = pd1; 2 = pd2; */ + uint8_t phase5_pd_sel = 0x0F; //0x0C /* 1 = pd1; 2 = pd2; */ uint8_t phase5_als_offset_idac = 0; /* 0~255 = 0 ~ 128ua , step = 0.5ua */ uint8_t phase5_led_offset_idac = 0; /* 0~255 = 0 ~ 64ua , step = 0.25ua */ uint8_t phase5_ldr1_cur = 0; /* 0~255 = 0 ~ 200ma, step = 0.8ma */ @@ -556,7 +646,7 @@ void hx3695_hrs_ppg_init(void) // ppg fs=25hz, phase conversion ready interupt e uint8_t phase6_tia_cap = 4; /* 0= ; 1= ; 2= ; 3= ; 4= ; 5= ; 6= ; 7= */ uint8_t phase6_led_drv1_cha_sel = 0; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ uint8_t phase6_led_drv2_cha_sel = 0; - uint8_t phase6_pd_sel = 0x0c; /* 1 = pd1; 2 = pd2; */ + uint8_t phase6_pd_sel = 0x0F; //0x0C /* 1 = pd1; 2 = pd2; */ uint8_t phase6_als_offset_idac = 0; /* 0~255 = 0 ~ 128ua , step = 0.5ua */ uint8_t phase6_led_offset_idac = 0; /* 0~255 = 0 ~ 64ua , step = 0.25ua */ uint8_t phase6_ldr1_cur = 0; /* 0~255 = 0 ~ 200ma, step = 0.8ma */ @@ -576,7 +666,7 @@ void hx3695_hrs_ppg_init(void) // ppg fs=25hz, phase conversion ready interupt e uint8_t phase7_tia_cap = 4; /* 0= ; 1= ; 2= ; 3= ; 4= ; 5= ; 6= ; 7= */ uint8_t phase7_led_drv1_cha_sel = 0; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ uint8_t phase7_led_drv2_cha_sel = 0; - uint8_t phase7_pd_sel = 0x0c; /* 1 = pd1; 2 = pd2; */ + uint8_t phase7_pd_sel = 0x02; //0x0C /* 1 = pd1; 2 = pd2; */ uint8_t phase7_als_offset_idac = 0; /* 0~255 = 0 ~ 128ua , step = 0.5ua */ uint8_t phase7_led_offset_idac = 0; /* 0~255 = 0 ~ 64ua , step = 0.25ua */ uint8_t phase7_ldr1_cur = 0; /* 0~255 = 0 ~ 200ma, step = 0.8ma */ @@ -594,9 +684,9 @@ void hx3695_hrs_ppg_init(void) // ppg fs=25hz, phase conversion ready interupt e uint8_t phase8_inner_avg = 0; /* phase1 adc avg num 0=1, 1=2, 2=4, 3=8 , 4=16*/ uint8_t phase8_tia_res = 0; /* 0= 10K; 1= 20k; 2= 50k; 3= 100k; 4= 150k; 5= 200k; 6= 500k; 7= 1M*/ uint8_t phase8_tia_cap = 4; /* 0= ; 1= ; 2= ; 3= ; 4= ; 5= ; 6= ; 7= */ - uint8_t phase8_led_drv1_cha_sel = 0x40; //IR_LED_SLE; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ + uint8_t phase8_led_drv1_cha_sel = 0x20; //0x40 //IR_LED_SLE; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ uint8_t phase8_led_drv2_cha_sel = 0; - uint8_t phase8_pd_sel = 0x0c; /* 1 = pd1; 2 = pd2; */ + uint8_t phase8_pd_sel = 0x02; //0x0C /* 1 = pd1; 2 = pd2; */ uint8_t phase8_als_offset_idac = 0; /* 0~255 = 0 ~ 128ua , step = 0.5ua */ uint8_t phase8_led_offset_idac = 0; /* 0~255 = 0 ~ 64ua , step = 0.25ua */ uint8_t phase8_ldr1_cur = 32; /* 0~255 = 0 ~ 200ma, step = 0.8ma */ @@ -884,7 +974,7 @@ void hx3695_spo2_ppg_init(void) //20200615 ericy ppg fs=25hz, phase3 conversion uint8_t phase1_tia_cap = 4; /* 0= ; 1= ; 2= ; 3= ; 4= ; 5= ; 6= ; 7= */ uint8_t phase1_led_drv1_cha_sel = 0; /* 1 = ldr1 NG; 2 = ldr2 GR; 4 = ldr3 IR; 8 = ldr4 RED; */ uint8_t phase1_led_drv2_cha_sel = 0; /*ldr5:0x20 ldr6: 0x40 red ldr8 0x80 ir */ - uint8_t phase1_pd_sel = 0x08; /* 1 = pd1; 2 = pd2; 4 = pd3*/ + uint8_t phase1_pd_sel = 0x0a; /* 1 = pd1; 2 = pd2; 4 = pd3*/ uint8_t phase1_als_offset_idac = 0; /* 0~255 = 0 ~ 128ua , step = 0.5ua */ uint8_t phase1_led_offset_idac = 0; /* 0~255 = 0 ~ 64ua , step = 0.25ua */ uint8_t phase1_ldr1_cur = 0; /* 0~255 = 0 ~ 200ma, step = 0.8ma */ @@ -904,9 +994,9 @@ void hx3695_spo2_ppg_init(void) //20200615 ericy ppg fs=25hz, phase3 conversion uint8_t phase2_inner_avg = 0; /* phase1 adc avg num 0=1, 1=2, 2=4, 3=8 , 4=16*/ uint8_t phase2_tia_res = 0; /* 0= 10K; 1= 20k; 2= 50k; 3= 100k; 4= 150k; 5= 200k; 6= 500k; 7= 1M*/ uint8_t phase2_tia_cap = 4; /* 0= ; 1= ; 2= ; 3= ; 4= ; 5= ; 6= ; 7= */ - uint8_t phase2_led_drv1_cha_sel = 0X10; //GREEN_LED_SLE; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ + uint8_t phase2_led_drv1_cha_sel = 0X50; //GREEN_LED_SLE; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ uint8_t phase2_led_drv2_cha_sel = 0x00; - uint8_t phase2_pd_sel = 0x08; /* 1 = pd1; 2 = pd2; 4 = pd3*/ + uint8_t phase2_pd_sel = 0x0a; /* 1 = pd1; 2 = pd2; 4 = pd3*/ uint8_t phase2_als_offset_idac = 0; /* 0~255 = 0 ~ 128ua , step = 0.5ua */ uint8_t phase2_led_offset_idac = 0; /* 0~255 = 0 ~ 64ua , step = 0.25ua */ uint8_t phase2_ldr1_cur = 0; /* 0~255 = 0 ~ 200ma, step = 0.8ma */ @@ -927,7 +1017,7 @@ void hx3695_spo2_ppg_init(void) //20200615 ericy ppg fs=25hz, phase3 conversion uint8_t phase3_tia_cap = 4; /* 0= ; 1= ; 2= ; 3= ; 4= ; 5= ; 6= ; 7= */ uint8_t phase3_led_drv1_cha_sel = 0; //RED_LED_SLE; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ uint8_t phase3_led_drv2_cha_sel = 0; - uint8_t phase3_pd_sel = 0x08; /* 1 = pd1; 2 = pd2; 4 = pd3*/ + uint8_t phase3_pd_sel = 0x0a; /* 1 = pd1; 2 = pd2; 4 = pd3*/ uint8_t phase3_als_offset_idac = 0; /* 0~255 = 0 ~ 128ua , step = 0.5ua */ uint8_t phase3_led_offset_idac = 0; /* 0~255 = 0 ~ 64ua , step = 0.25ua */ uint8_t phase3_ldr1_cur = 0; /* 0~255 = 0 ~ 200ma, step = 0.8ma */ @@ -946,9 +1036,9 @@ void hx3695_spo2_ppg_init(void) //20200615 ericy ppg fs=25hz, phase3 conversion uint8_t phase4_inner_avg = 0; /* phase1 adc avg num 0=1, 1=2, 2=4, 3=8 , 4=16*/ uint8_t phase4_tia_res = 0; /* 0= 10K; 1= 20k; 2= 50k; 3= 100k; 4= 150k; 5= 200k; 6= 500k; 7= 1M*/ uint8_t phase4_tia_cap = 4; /* 0= ; 1= ; 2= ; 3= ; 4= ; 5= ; 6= ; 7= */ - uint8_t phase4_led_drv1_cha_sel = 0x20; //IR_LED_SLE; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ + uint8_t phase4_led_drv1_cha_sel = 0x80; //0x20 //IR_LED_SLE; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ uint8_t phase4_led_drv2_cha_sel = 0; - uint8_t phase4_pd_sel = 0x08; /* 1 = pd1; 2 = pd2; 4 = pd3*/ + uint8_t phase4_pd_sel = 0x0a; /* 1 = pd1; 2 = pd2; 4 = pd3*/ uint8_t phase4_als_offset_idac = 0; /* 0~255 = 0 ~ 128ua , step = 0.5ua */ uint8_t phase4_led_offset_idac = 0; /* 0~255 = 0 ~ 64ua , step = 0.25ua */ uint8_t phase4_ldr1_cur = 0; /* 0~255 = 0 ~ 200ma, step = 0.8ma */ @@ -968,7 +1058,7 @@ void hx3695_spo2_ppg_init(void) //20200615 ericy ppg fs=25hz, phase3 conversion uint8_t phase5_tia_cap = 4; /* 0= ; 1= ; 2= ; 3= ; 4= ; 5= ; 6= ; 7= */ uint8_t phase5_led_drv1_cha_sel = 0x00; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ uint8_t phase5_led_drv2_cha_sel = 0; - uint8_t phase5_pd_sel = 0x08; /* 1 = pd1; 2 = pd2; */ + uint8_t phase5_pd_sel = 0x0a; /* 1 = pd1; 2 = pd2; */ uint8_t phase5_als_offset_idac = 0; /* 0~255 = 0 ~ 128ua , step = 0.5ua */ uint8_t phase5_led_offset_idac = 0; /* 0~255 = 0 ~ 64ua , step = 0.25ua */ uint8_t phase5_ldr1_cur = 0; /* 0~255 = 0 ~ 200ma, step = 0.8ma */ @@ -986,9 +1076,9 @@ void hx3695_spo2_ppg_init(void) //20200615 ericy ppg fs=25hz, phase3 conversion uint8_t phase6_inner_avg = 0; /* phase1 adc avg num 0=1, 1=2, 2=4, 3=8 , 4=16*/ uint8_t phase6_tia_res = 0; /* 0= 10K; 1= 20k; 2= 50k; 3= 100k; 4= 150k; 5= 200k; 6= 500k; 7= 1M*/ uint8_t phase6_tia_cap = 4; /* 0= ; 1= ; 2= ; 3= ; 4= ; 5= ; 6= ; 7= */ - uint8_t phase6_led_drv1_cha_sel = 0x40; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ + uint8_t phase6_led_drv1_cha_sel = 0x20; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ uint8_t phase6_led_drv2_cha_sel = 0; - uint8_t phase6_pd_sel = 0x08; /* 1 = pd1; 2 = pd2; */ + uint8_t phase6_pd_sel = 0x0a; /* 1 = pd1; 2 = pd2; */ uint8_t phase6_als_offset_idac = 0; /* 0~255 = 0 ~ 128ua , step = 0.5ua */ uint8_t phase6_led_offset_idac = 0; /* 0~255 = 0 ~ 64ua , step = 0.25ua */ uint8_t phase6_ldr1_cur = 0; /* 0~255 = 0 ~ 200ma, step = 0.8ma */ @@ -1008,7 +1098,7 @@ void hx3695_spo2_ppg_init(void) //20200615 ericy ppg fs=25hz, phase3 conversion uint8_t phase7_tia_cap = 4; /* 0= ; 1= ; 2= ; 3= ; 4= ; 5= ; 6= ; 7= */ uint8_t phase7_led_drv1_cha_sel = 0; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ uint8_t phase7_led_drv2_cha_sel = 0; - uint8_t phase7_pd_sel = 0x08; /* 1 = pd1; 2 = pd2; */ + uint8_t phase7_pd_sel = 0x02; /* 1 = pd1; 2 = pd2; */ uint8_t phase7_als_offset_idac = 0; /* 0~255 = 0 ~ 128ua , step = 0.5ua */ uint8_t phase7_led_offset_idac = 0; /* 0~255 = 0 ~ 64ua , step = 0.25ua */ uint8_t phase7_ldr1_cur = 0; /* 0~255 = 0 ~ 200ma, step = 0.8ma */ @@ -1026,9 +1116,9 @@ void hx3695_spo2_ppg_init(void) //20200615 ericy ppg fs=25hz, phase3 conversion uint8_t phase8_inner_avg = 0; /* phase1 adc avg num 0=1, 1=2, 2=4, 3=8 , 4=16*/ uint8_t phase8_tia_res = 0; /* 0= 10K; 1= 20k; 2= 50k; 3= 100k; 4= 150k; 5= 200k; 6= 500k; 7= 1M*/ uint8_t phase8_tia_cap = 4; /* 0= ; 1= ; 2= ; 3= ; 4= ; 5= ; 6= ; 7= */ - uint8_t phase8_led_drv1_cha_sel = 0x40; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ + uint8_t phase8_led_drv1_cha_sel = 0x20; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ uint8_t phase8_led_drv2_cha_sel = 0; - uint8_t phase8_pd_sel = 0x08; /* 1 = pd1; 2 = pd2; */ + uint8_t phase8_pd_sel = 0x02; /* 1 = pd1; 2 = pd2; */ uint8_t phase8_als_offset_idac = 0; /* 0~255 = 0 ~ 128ua , step = 0.5ua */ uint8_t phase8_led_offset_idac = 0; /* 0~255 = 0 ~ 64ua , step = 0.25ua */ uint8_t phase8_ldr1_cur = 20; /* 0~255 = 0 ~ 200ma, step = 0.8ma */ @@ -1356,7 +1446,7 @@ void hx3695_hrv_ppg_init(void) //20200615 ericy ppg fs=25hz, phase3 conversion r uint8_t phase3_inner_avg = 0; /* phase1 adc avg num 0=1, 1=2, 2=4, 3=8 , 4=16*/ uint8_t phase3_tia_res = 0; /* 0= 10K; 1= 20k; 2= 50k; 3= 100k; 4= 150k; 5= 200k; 6= 500k; 7= 1M*/ uint8_t phase3_tia_cap = 4; /* 0= ; 1= ; 2= ; 3= ; 4= ; 5= ; 6= ; 7= */ - uint8_t phase3_led_drv1_cha_sel = 0x40; //RED_LED_SLE; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ + uint8_t phase3_led_drv1_cha_sel = 0x08; //0x40 //RED_LED_SLE; /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ uint8_t phase3_led_drv2_cha_sel = 0; uint8_t phase3_pd_sel = 0x0a; /* 1 = pd1; 2 = pd2; 4 = pd3*/ uint8_t phase3_als_offset_idac = 0; /* 0~255 = 0 ~ 128ua , step = 0.5ua */ @@ -1888,7 +1978,7 @@ void hx3695_check_touch_init(void) // uint8_t phase8_inner_avg = 0; /* phase1 adc avg num 0=1, 1=2, 2=4, 3=8 , 4=16*/ uint8_t phase8_tia_res = 0; /* 0= 10K; 1= 20k; 2= 50k; 3= 100k; 4= 150k; 5= 200k; 6= 500k; 7= 1M*/ uint8_t phase8_tia_cap = 4; /* 0= ; 1= ; 2= ; 3= ; 4= ; 5= ; 6= ; 7= */ - uint8_t phase8_led_drv1_cha_sel = 0x40; //IR_LED_SLE /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ + uint8_t phase8_led_drv1_cha_sel = 0x20;//0x40; //IR_LED_SLE /* 1 = ldr1; 2 = ldr2; 4 = ldr3; 8 = ldr4 ; */ uint8_t phase8_led_drv2_cha_sel = 0; uint8_t phase8_pd_sel = 0x0c; /* 1 = pd1; 2 = pd2; */ uint8_t phase8_als_offset_idac = 0; /* 0~255 = 0 ~ 128ua , step = 0.5ua */ @@ -2132,14 +2222,19 @@ void hx3695_check_touch_init(void) // // 初始化调用入口函数 bool hx3695_init(WORK_MODE_T mode) { + TYHX_LOG(" hx3695_init mode : %d \n", mode); + work_mode_flag = mode; hx3695_data_reset(); hx3695_vin_check(3800); switch (work_mode_flag) { case HRS_MODE: + TYHX_LOG(" hx3695_init mode : HRS_MODE \n"); #ifdef HRS_ALG_LIB - tyhx_hrs_set_living(1, 15, 30); + tyhx_hrs_set_alg_para(NORMAL_MODE, 150, 1); + + tyhx_hrs_set_living(1, 15, 30); if(hx3695_hrs_enable()== SENSOR_OP_FAILED) { return false; @@ -2307,6 +2402,46 @@ void agc_timeout_handler(void * p_context) #endif } + +void hx3695_factory_test_process(uint8_t data[], uint8_t mode, uint8_t* ppg_src) +{ + extern bool factory_test_flag; + extern bool factory_test_aging; + extern bool factory_test_sensor_on; + if(factory_test_flag == false || factory_test_aging != false) return; + if(factory_test_sensor_on == true ) return; + + static uint8_t ppg_data[15] = {0}; + + if(ppg_src == NULL) + { + memcpy(ppg_data, data, 3); + return; + } + + // switch(mode) + // { + // case APP_FACTORY_TEST_HR_START: + // memcpy((void *)&ppg_data[3], ppg_src, 4); + // factory_test_send_data(ppg_data, 7); + // break; + // case APP_FACTORY_TEST_SPO2_START: + // memcpy((void *)&ppg_data[3], ppg_src, 4); + // factory_test_send_data(ppg_data, 7); + // break; + // case APP_FACTORY_TEST_LEAKING_START: + // memcpy((void *)&ppg_data[3], ppg_src, 12); + // factory_test_send_data(ppg_data, 15); + // break; + // case APP_FACTORY_TEST_GRAY_CARD: + // memcpy((void *)&ppg_data[3], ppg_src, 12); + // factory_test_send_data(ppg_data, 15); + // break; + // default: + // break; + // } +} + void heart_rate_meas_timeout_handler(void * p_context) { switch(work_mode_flag) @@ -2346,6 +2481,19 @@ void heart_rate_meas_timeout_handler(void * p_context) hx3695_hrspo2_ppg_Int_handle(); #endif + case FT_LEAK_LIGHT_MODE: + hx3695_factroy_test(LEAK_LIGHT_TEST); + break; + + case FT_GRAY_CARD_MODE: + { + FT_RESULTS_t ft_result = hx3695_factroy_test(GRAY_CARD_TEST); + uint8_t data[12] = {0}; + memcpy(data, (void *)&ft_result.gr_data_final, 12); + // hx3695_factory_test_process(NULL, APP_FACTORY_TEST_GRAY_CARD, data); + } + break; + default: break; } @@ -2440,6 +2588,7 @@ void hx3695_hrs_ppg_Int_handle(void) #else if(hx3695_hrs_read(&hrs_s_dat) == 0) { + AGC_LOG("hx3695_hrs_read(&hrs_s_dat) == 0\r\n"); return; } @@ -2458,6 +2607,7 @@ void hx3695_hrs_ppg_Int_handle(void) } hrs_wear_status = hx3695_hrs_get_wear_status(); + AGC_LOG("hrs_wear_status: %d !!\r\n", hrs_wear_status); if(hrs_wear_status == MSG_HRS_WEAR) { tyhx_hrs_alg_send_data(PPG_buf, *count, gsen_fifo_x_send, gsen_fifo_y_send, gsen_fifo_z_send, cal.Group1_Ledidac); @@ -2470,10 +2620,36 @@ void hx3695_hrs_ppg_Int_handle(void) hrsresult.hr_living_qu = alg_results.hr_result_qual; hrsresult.hr_living_std = alg_results.hr_result_std; - - - - DEBUG_PRINTF("data_cnt: %d, hr_result:%d \r\n",alg_results.data_cnt, alg_results.hr_result); + AGC_LOG("hx3695 data_cnt: %d, hr_living: %d, hr_living_qu: %d, hr_living_std: %d, hr_result:%d \r\n", + alg_results.data_cnt, hrsresult.hr_living, hrsresult.hr_living_qu, hrsresult.hr_living_std, hrsresult.lastesthrs); + if(hrs_wear_status == MSG_HRS_WEAR && hrsresult.hr_living == MSG_LIVING_TRUE) + { +// app_hr_reset_stop_timer(); + if(alg_results.hr_result) + { + + // app_hr_cal_hr_values(alg_results.hr_result); + // AGC_LOG("app_hr_cal_hr_values tick:%d hr:%d", xTaskGetTickCount(), alg_results.hr_result); + AGC_LOG("app_hr_cal_hr_values hr:%d", alg_results.hr_result); + //hr_sensor_notify_factory_test(); + } + hr_no_living_dur = 0; + } + else if(hrs_wear_status == MSG_HRS_WEAR && hrsresult.hr_living != MSG_LIVING_TRUE) + { + // if (++hr_no_living_dur > 12 * 1000 / tyhx_long_timer_tick) + { + // hr_stop_detect(); + // AGC_LOG("tyhx_hrs_module_start(WEAR_MODE) wear:%d liv:%d", hrs_wear_status, hrsresult.hr_living); + // hr_no_living_dur = 0; + } + } + else if(hrs_wear_status == MSG_HRS_NO_WEAR || hrsresult.hr_living == MSG_LIVING_FAIL) + { + // hr_stop_detect(); + AGC_LOG("tyhx_hrs_module_start(WEAR_MODE) wear:%d liv:%d", hrs_wear_status, hrsresult.hr_living); + hr_no_living_dur = 0; + } #ifdef BP_CUSTDOWN_ALG_LIB bp_results_t bp_alg_results; bp_alg_results = tyhx_alg_get_bp_results(); @@ -2774,9 +2950,10 @@ void hx3695_spo2_ppg_Int_handle(void) gsen_fifo_y_send[ii] = gsen_fifo_y[32-*count+ii]; gsen_fifo_z_send[ii] = gsen_fifo_z[32-*count+ii]; //DEBUG_PRINTF("%d/%d %d %d %d %d %d %d\r\n" ,1+ii,*count,red_buf[ii],ir_buf[ii],green_buf[ii],gsen_fifo_x[ii],gsen_fifo_y[ii],gsen_fifo_z[ii]); + // hx3695_factory_test_process(NULL, APP_FACTORY_TEST_SPO2_START, (uint8_t *)&red_buf[ii]); } - //DEBUG_PRINTF("%d %d %d %d %d %d\r\n", cal.R_LED, cal.IR_LED, cal.G_LED, cal.R_LEDDAC, cal.IR_LEDDAC, cal.G_LEDDAC); + AGC_LOG("hx3695 current value: %d %d %d %d %d %d\r\n", cal.R_LED, cal.IR_LED1, cal.G_LED, cal.R_LEDDAC, cal.IR_LEDDAC1, cal.G_LEDDAC); spo2_wear_status = hx3695_spo2_get_wear_status(); if(spo2_wear_status == MSG_SPO2_WEAR) { @@ -2789,6 +2966,14 @@ void hx3695_spo2_ppg_Int_handle(void) //DEBUG_PRINTF("block_cnt: %d, data_cnt:%d, hr_result:%d,ir_quality:%d,motion:%d,poor_signal:%d,reliable_score_result:%d,screen_up:%d,spo2_result:%d\r\n",spo2_alg_results.block_cnt,spo2_alg_results.data_cnt,spo2_alg_results.hr_result,spo2_alg_results.ir_quality,spo2_alg_results.motion,spo2_alg_results.poor_signal,spo2_alg_results.reliable_score_result,spo2_alg_results.screen_up,spo2_alg_results.spo2_result); hrsresult.lastestspo2 = spo2_alg_results.spo2_result; +// if(hrsresult.lastestspo2) + { + // store_latest_spo2(hrsresult.lastestspo2); + // app_hr_cal_hr_values(hrsresult.lastesthrs); +// gui_send_message_by_data(MSG_SPO2_DATA, &hrsresult.lastestspo2, 1); +// hr_sensor_notify_factory_test(); + } + /////////////////////////////////////////BLE+DISPLAY////////////////////////////////////////// @@ -3009,6 +3194,21 @@ void hx3695_wear_ppg_Int_handle(void) hx3695_check_touch_read(&ppg_s_data); hx3695_wear_status = hx3695_check_touch_send_data(ir_buf,*count); hrsresult.wearstatus = hx3695_wear_status; + extern uint8_t notouch_cnt; + extern uint8_t touch_cnt; + + if (hrsresult.wearstatus) + { + cwm_gsensor_enable(); + } + else + { + cwm_gsensor_disable(); + } +// AGC_LOG("===> touch_cnt: %d, notouch_cnt: %d, wear status: %d, \r\n", touch_cnt, notouch_cnt, hx3695_wear_status); + +// AGC_LOG("hx3695_wear_ppg_Int_handle wearstatus = %d\r\n", hrsresult.wearstatus); + // for(int i=0;i<*count;i++) // { // DEBUG_PRINTF("%d,%d,%d,%d,%d,%d\r\n",1+i,*count,ir_buf[i],ppg_s_data.s_buf[i*2],ppg_s_data.s_buf[i*2+1],hx3695_wear_status); diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_at_cmd.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_at_cmd.c index 27a54bd4e..630f41488 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_at_cmd.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_at_cmd.c @@ -1,8 +1,6 @@ #include "hx3695.h" #include "tyhx_hrs_custom.h" -#ifdef CHIP_HX3695 -#ifdef SUPPORT_AT_CMD #include "at_cmd_api.h" #include "pm_control.h" @@ -113,9 +111,3 @@ 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