增加了大量注释

This commit is contained in:
NeoZng
2023-01-01 17:32:22 +08:00
parent c2f8b5c8c3
commit c05513587c
56 changed files with 773 additions and 598 deletions

View File

@@ -13,9 +13,8 @@ void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
if (pwm_instance[i]->htim == htim && htim->Channel == pwm_instance[i]->channel)
{
if (pwm_instance[i]->callback) // 如果有回调函数
{
pwm_instance[i]->callback(pwm_instance[i]);
}
return; // 一次只能有一个通道的中断,所以直接返回
}
}
@@ -23,6 +22,9 @@ void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
PWMInstance *PWMRegister(PWM_Init_Config_s *config)
{
if (idx >= PWM_DEVICE_CNT) // 超过最大实例数,考虑增加或查看是否有内存泄漏
while (1)
;
PWMInstance *pwm = (PWMInstance *)malloc(sizeof(PWMInstance));
memset(pwm, 0, sizeof(PWMInstance));
@@ -33,8 +35,8 @@ PWMInstance *PWMRegister(PWM_Init_Config_s *config)
pwm->callback = config->callback;
pwm->id = config->id;
HAL_TIM_PWM_Start(pwm->htim, pwm->channel);
__HAL_TIM_SetCompare(pwm->htim, pwm->channel, pwm->pulse);
HAL_TIM_PWM_Start(pwm->htim, pwm->channel); // 启动PWM
__HAL_TIM_SetCompare(pwm->htim, pwm->channel, pwm->pulse); // 设置占空比,初始为0
pwm_instance[idx++] = pwm;
return pwm;