心率电源IO调整
authorp15692025051 <846603105@qq.com>
Wed, 29 Mar 2023 03:23:28 +0000 (11:23 +0800)
committerp15692025051 <846603105@qq.com>
Wed, 29 Mar 2023 03:23:28 +0000 (11:23 +0800)
2.sdk/gui/lv_drivers/indev/gh3018.c

index 5d06f54..3e0d346 100644 (file)
 /************************simware add start***********************************/
 static  uint32_t gh3018_mfp_cfgs[] = {
      MFP_REG(GPIO_32) | MFP_AF0 | MFP_DRIVE_MEDIUM | MFP_PULL_LOW | MFP_SLEEP_DIR | MFP_LPM_EDGE_NONE,
+     MFP_REG(GPIO_32) | MFP_AF0 | MFP_DRIVE_MEDIUM | MFP_PULL_LOW | MFP_SLEEP_DIR | MFP_LPM_EDGE_NONE,
+     MFP_REG(GPIO_18) | MFP_AF0 | MFP_DRIVE_MEDIUM | MFP_PULL_LOW | MFP_SLEEP_DIR | MFP_LPM_EDGE_NONE,
+     MFP_REG(GPIO_81) | MFP_AF0 | MFP_DRIVE_MEDIUM | MFP_PULL_LOW | MFP_SLEEP_DIR | MFP_LPM_EDGE_NONE,
+     MFP_REG(GPIO_84) | MFP_AF0 | MFP_DRIVE_MEDIUM | MFP_PULL_LOW | MFP_SLEEP_DIR | MFP_LPM_EDGE_NONE,
     MFP_EOC
 };
 static const struct gh3018_info_s gh3018_info = {
@@ -31,6 +35,34 @@ static Hr_Bp_Bo_t gh3018_hr_bp_bo_value = {0};
 static uint16_t HR_value = 0;
 static uint16_t SPO2_value = 0;
 static EMGh30xRunMode measure_mode = RUN_MODE_INVALID;
+static void gh3018_en_gpio_init(void)
+{
+    gpio_set_direction(GPIO18, GPIO_OUT);
+    gpio_set_direction(GPIO81, GPIO_OUT);
+    gpio_set_direction(GPIO84, GPIO_OUT);
+}
+//Hsensor 电源、复位
+static void gh3018_en_gpio_enable(bool param)
+{
+    static flag = 0;
+    if(param)
+        flag++;
+    else 
+    {
+        if(flag > 0)
+            flag --;
+    }
+        
+    if(flag > 0) {
+        gpio_set_value(GPIO18, GPIO_HIGH);
+        gpio_set_value(GPIO81, GPIO_HIGH);
+        gpio_set_value(GPIO84, GPIO_HIGH);
+    } else {
+        gpio_set_value(GPIO18, GPIO_LOW);
+        gpio_set_value(GPIO81, GPIO_LOW);
+        gpio_set_value(GPIO84, GPIO_LOW);
+    }
+}
 
 static void gh3018_hisr_callback(void)
 {
@@ -62,7 +94,9 @@ static void DelayInUs(unsigned int us)
 
 static void gh3018_start(void)
 {
+    gh3018_en_gpio_enable(true);
     Timer0_Switch(1);
+    
     gh30x_module_start_without_adt(measure_mode);
 }
 
@@ -70,6 +104,7 @@ static void gh3018_stop(void)
 {
     gh30x_module_stop();
     Timer0_Switch(0);
+    gh3018_en_gpio_enable(false);
 }
 
 void gh3018_init(void)
@@ -81,6 +116,8 @@ void gh3018_init(void)
 
 uint8_t get_gh3018_id(void)
 {
+    gh3018_en_gpio_enable(true);
+    hal_gh30x_delay_us(10000);
     uint8_t cmd[] = {0xdd,0xdd,0xc0};
     uint8_t reg_addr[] = {0x00,0x28};
     uint8_t id_buf[2] = {0};
@@ -90,11 +127,12 @@ uint8_t get_gh3018_id(void)
     hal_gh30x_delay_us(1000);
     hal_gh30x_i2c_read(sensor_addr, reg_addr, sizeof(reg_addr), id_buf, sizeof(id_buf));
     if(id_buf[0] == 0x00 && id_buf[1] == 0x31)
-        cplog_printf("GH3011 id : 0x0031\r\n");
+        printf("GH3011 id : 0x0031\r\n");
     else
-        cplog_printf("read id error\r\n");
+        printf("read id error\r\n");
     id  = id_buf[1] << 0;
     id += id_buf[0] << 8;
+    gh3018_en_gpio_enable(false);
     return id;
 }
 
@@ -106,6 +144,7 @@ void gh3018_measure_hr_start(void)
 
     Timer0_Switch(1);
     measure_mode = RUN_MODE_ADT_HB_DET;
+    hal_gh30x_int_init();
     sensor_task_send_message(GH3018_ID,0);
 }
 
@@ -343,6 +382,7 @@ void hal_gh30x_int_init(void)
        // code implement by user
     // must register func hal_gh30x_int_handler as callback
     mfp_config(gh3018_mfp_cfgs);
+    gh3018_en_gpio_init();
     printf("GH3018 ID : 0x%02x\n",get_gh3018_id());
 
     sensor_drv_t sensor_drv;