|
@@ -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();
|
|
|
|