#include <MyProject.h>

/**
    @function     PWM_Timer_Init
    @brief        输入捕获 TIM3实现
    @date         2025-12-27
*/
void PWM_Timer_Init(void)
{
    ClrBit(TIM3_CR1, T3EN);
    // 配置端口复用 GP11
    SetBit(PH_SEL, T3SEL);
    ClrBit(PH_SEL1, T3CT1 | T3CT0);
    // 配置定时器时钟 750KHz
    SetReg(TIM3_CR0, T3PSC2 | T3PSC1 | T3PSC0, T3PSC2 | T3PSC0);
    // 模式配置
    ClrBit(TIM3_CR0, T3MOD);
    ClrBit(TIM3_CR0, T3OCM | T3OPM);
    // 中断配置
    SetBit(TIM3_CR0, T3IRE);
    ClrBit(TIM3_CR1, T3IR | T3IF | T3IP);
    SetBit(TIM3_CR1, T3IPE | T3IFE);
    // 计数值配置
    TIM3__CNTR = 0;
    TIM3__DR = 0;
    TIM3__ARR = 0;
    // 配置中断优先级
    SetReg(IP2, PTIM31 | PTIM30, PTIM30);
    SetBit(TIM3_CR1, T3EN);
}
