Browse Source

修复pwm无法被正常点亮的异常

kindring 1 năm trước cách đây
mục cha
commit
9acc219e71
4 tập tin đã thay đổi với 25 bổ sung13 xóa
  1. 2 2
      src/app_wrist.c
  2. 3 3
      src/light.c
  3. 18 7
      src/pwm_light/pwm_light.c
  4. 2 1
      src/pwm_light/pwm_light.h

+ 2 - 2
src/app_wrist.c

@@ -87,13 +87,13 @@ static gapRolesCBs_t WristPeripheralCB =
 
 static void appWristProcOSALMsg( osal_event_hdr_t *pMsg )
 {
-    LOG("[fn : appWristProcOSALMsg]  run event is: %d", pMsg->event);
+    LOG("[fn : appWristProcOSALMsg]  run event is: %d \n", pMsg->event);
 }
 
 // Notification from the profile of a state change
 static void WristGapStateCB(gaprole_States_t newState)
 {
-    LOG("app is start WristGapStateCB: %d", newState);
+    LOG("app is start WristGapStateCB: %d \n", newState);
     // if connected
     if (newState == GAPROLE_CONNECTED)
     {

+ 3 - 3
src/light.c

@@ -14,7 +14,7 @@ int light_init(){
     LOG("[light_init]\n");
     // 初始化pwm
     int ret = 0;
-    if()
+    // if()
     ret = pwm_light_init(0, GPIO_WARM, 100, 100, 5, PWM_CLK_DIV_16);
 
     if(ret != 0){
@@ -33,7 +33,7 @@ int light_init(){
 }
 
 int light_set(uint8_t ch, uint8_t val){
-    LOG("[light_set] set ch%d val to %d\n", ch, val);
-    ret = pwm_light_set_val(ch, val);
+    LOG("[light_set] set ch%d val to %d \n", ch, val);
+    int ret = pwm_light_set_val(ch, val);
     return ret;
 }

+ 18 - 7
src/pwm_light/pwm_light.c

@@ -1,9 +1,13 @@
 #include "pwm.h"
 #include "gpio.h"
+#include "OSAL.h"
+#include "gpio.h"
+#include "error.h"
+#include "log.h"
 
 #include "pwm_light.h"
 
-uint8_t max_pwm_light = 5;
+const uint8_t max_pwm_light = 5;
 uint8_t pwm_light_len = 0;
 // 申请5个通道的内存
 pwm_t pwm_light_chann_list[max_pwm_light] = {
@@ -19,7 +23,7 @@ static void pwm_light_reflash(void)
 {
 
     // 遍历 pwm_light_chann_list
-    for (int i = 0; i < sizeof(pwm_light_chann_list) / sizeof(pwm_t); i++)
+    for (int i = 0; i < max_pwm_light; i++)
     {
         // 获取 pwm
         pwm_t *pwm = &pwm_light_chann_list[i];
@@ -27,19 +31,21 @@ static void pwm_light_reflash(void)
         if(pwm->pin == GPIO_DUMMY){
             continue;
         }
+        LOG("pwm ch%d is reflash \n", i);
+        
         hal_pwm_close_channel(pwm->pwm_ch);
         hal_pwm_destroy(pwm->pwm_ch);
 
         hal_pwm_stop();
 
         hal_gpio_pin_init(pwm->pin, IE);
-        hal_gpio_write(pwm->pin, WEAK_PULL_UP);
+        hal_gpio_pull_set(pwm->pin, WEAK_PULL_UP);
 
         hal_pwm_init(pwm->pwm_ch, pwm->div, PWM_CNT_UP, PWM_POLARITY_FALLING);
 
-        hal_pwm_set_count_val(PWM_CH0, pwm->val, pwm->total);
+        hal_pwm_set_count_val(pwm->pwm_ch, pwm->val, pwm->total);
 
-        hal_pwm_open_channel(PWM_CH1, pwm->pin);
+        hal_pwm_open_channel(pwm->pwm_ch, pwm->pin);
     }
     hal_pwm_start();
 }
@@ -48,7 +54,11 @@ static void pwm_light_reflash(void)
 pwm_t *pwm_light_get(uint8_t ch)
 {
     // 判断 ch 是否合法
-    CHECK_PWM_CH
+    if (ch < 0 || ch > max_pwm_light)
+    {
+        ch = 0;
+    }
+    
 
     // 获取 pwm
     pwm_t *pwm = &pwm_light_chann_list[ch];
@@ -128,9 +138,10 @@ int pwm_light_set_val(uint8_t ch , uint8_t val)
         val = pwm->total;
     }
 
+    LOG("light val %d --->> %d \n", pwm->val, val);
     // 设置 pwm
     pwm->val = val;
-
+    
     // 刷新 pwm 引脚
     pwm_light_reflash();
 

+ 2 - 1
src/pwm_light/pwm_light.h

@@ -9,6 +9,7 @@
 #define CHECK_PWM_PIN if(pin < P0 || pin > P34){return -1;}
 
 
+
 // pwm 结构体
 typedef struct pwm_t {
     PWMN_e pwm_ch;// pwm通道
@@ -48,7 +49,7 @@ extern int pwm_light_init(uint8_t ch, GPIO_Pin_e pin, int val, uint8_t total, ui
  * @param int total 总量
  * @return 0 成功 -1 失败
 */
-extern int pwm_light_set_total(uint8_t ch, int total )
+extern int pwm_light_set_total(uint8_t ch, int total );
 
 /**
  * @brief 设置pwm引脚