25_R1_chassis/User/bsp/pwm.h

35 lines
1.1 KiB
C

#ifndef PWM_H
#define PWM_H
/* Includes ----------------------------------------------------------------- */
#include <stdint.h>
#include "bsp\bsp.h"
#include <stdbool.h>
/* Exported constants ------------------------------------------------------- */
/* Exported macro ----------------------------------------------------------- */
/* Exported types ----------------------------------------------------------- */
/* PWM通道 */
typedef enum {
BSP_PWM_IMU_HEAT,
BSP_PWM_BUZZER,
} BSP_PWM_Channel_t;
typedef struct {
uint32_t timer;
bool state;
uint16_t beep_duration; // 蜂鸣持续时间(ms)
uint16_t silent_duration; // 静默间隔时间(ms)
float duty_cycle; // 占空比(0-1)
} Buzzer_t;
/* Exported functions prototypes -------------------------------------------- */
int8_t BSP_PWM_Start(BSP_PWM_Channel_t ch);
int8_t BSP_PWM_Set(BSP_PWM_Channel_t ch, float duty_cycle);
int8_t BSP_PWM_Stop(BSP_PWM_Channel_t ch);
void Buzzer_Init(Buzzer_t* ctrl,uint16_t beep_duration,uint16_t silent_duration,float duty_cycle);
void Buzzer_Control(Buzzer_t* ctrl, bool condition);
#endif