优化马达震动 1305/1 1305/head 1306/target/1 1307/target/1 1308/target/1
authorpenglei <1624952103@qq.com>
Thu, 31 Oct 2024 09:32:37 +0000 (17:32 +0800)
committerpenglei <1624952103@qq.com>
Thu, 31 Oct 2024 09:32:37 +0000 (17:32 +0800)
code/sdk/drivers/peripheral/vibrator/vibrator.c

index 80b9f66..17d05d3 100644 (file)
@@ -135,10 +135,10 @@ static int pwm_stop(void)
 
     errcode_t ret  = uapi_pwm_close(channel);
     // PRINT("uapi_pwm_close %d\n",ret);
-    // LOS_Msleep((uint32_t)TEST_TCXO_DELAY_1000MS);
-    LOS_Msleep(delay_ms);
+    // LOS_Mdelay((uint32_t)TEST_TCXO_DELAY_1000MS);
+    LOS_Mdelay(delay_ms);
     uapi_pwm_deinit();
-    LOS_Msleep(delay_ms);
+    LOS_Mdelay(delay_ms);
     uapi_pin_set_mode(VIBRATOR_GPIOPPIN, (pin_mode_t)HAL_PIO_FUNC_GPIO);
     uapi_gpio_set_dir(VIBRATOR_GPIOPPIN,GPIO_DIRECTION_OUTPUT);
     uapi_gpio_set_val(VIBRATOR_GPIOPPIN,GPIO_LEVEL_LOW);
@@ -154,7 +154,7 @@ static uint8_t switch_flag = 1;
 
 void g_VibratorFunc(uint16_t duty , uint16_t cycle_time_ms,uint16_t duration_time_ms)
 {
-
+    errcode_t ret;
     if( duty>100 || duty ==0 ||cycle_time_ms == 0 || duration_time_ms == 0)
     {
         PRINT("Not Supported param duty %u cycle_time_ms %u duration_time_ms %u !\r\n",duty,cycle_time_ms,duration_time_ms );
@@ -173,11 +173,16 @@ void g_VibratorFunc(uint16_t duty , uint16_t cycle_time_ms,uint16_t duration_tim
 
         pwm_start(duty,cycle_time_ms);
 
-        // LOS_Msleep(duration_time_ms);
+        // LOS_Mdelay(duration_time_ms);
         LOS_Mdelay(duration_time_ms);
         
+        ret = pwm_stop();
+
+        if(ret != 0)
+        {
+            pwm_stop();
+        }
         pwm_stop();
-  
         vibrating = 0;
     }
 }
@@ -221,9 +226,9 @@ void g_VibratorFunc(uint16_t duty , uint16_t cycle_time_ms,uint16_t duration_tim
         while(duration_time_ms)
         {
             uapi_gpio_set_val(VIBRATOR_GPIOPPIN,GPIO_LEVEL_HIGH);
-            LOS_Msleep(delaytime_ms_high); 
+            LOS_Mdelay(delaytime_ms_high); 
             uapi_gpio_set_val(VIBRATOR_GPIOPPIN,GPIO_LEVEL_LOW);
-            LOS_Msleep(delaytime_ms_low); 
+            LOS_Mdelay(delaytime_ms_low); 
             duration_time_ms-=delaytime_ms_high;
             duration_time_ms-=delaytime_ms_low;