32#define PWM_CHANNEL_NUM (4)
37#define PWM_CH_0_MASK (1UL)
38#define PWM_CH_1_MASK (2UL)
39#define PWM_CH_2_MASK (4UL)
40#define PWM_CH_3_MASK (8UL)
41#define PWM_CLK_DIV_1 (4UL)
42#define PWM_CLK_DIV_2 (0UL)
43#define PWM_CLK_DIV_4 (1UL)
44#define PWM_CLK_DIV_8 (2UL)
45#define PWM_CLK_DIV_16 (3UL)
46#define PWM_EDGE_ALIGNED (0UL)
47#define PWM_CENTER_ALIGNED (1UL)
48#define PWM_RISING_LATCH_INT_ENABLE (1UL)
49#define PWM_FALLING_LATCH_INT_ENABLE (2UL)
50#define PWM_RISING_FALLING_LATCH_INT_ENABLE (3UL)
51#define PWM_RISING_LATCH_INT_FLAG (2UL)
52#define PWM_FALLING_LATCH_INT_FLAG (4UL)
53#define PWM_RISING_FALLING_LATCH_INT_FLAG (6UL)
54#define PWM_RISING_LATCH_PDMA_ENABLE (0x10UL)
55#define PWM_FALLING_LATCH_PDMA_ENABLE (0x20UL)
56#define PWM_RISING_FALLING_LATCH_PDMA_ENABLE (0x30UL)
57#define PWM_CAP_PDMA_RFORDER_R (0x1000UL)
58#define PWM_CAP_PDMA_RFORDER_F (0UL)
75#define PWM_ENABLE_OUTPUT_INVERTER(pwm, u32ChannelMask)\
78 (pwm)->CTL &= ~(PWM_CTL_CH0INV_Msk | PWM_CTL_CH1INV_Msk | PWM_CTL_CH2INV_Msk | PWM_CTL_CH3INV_Msk);\
79 for (i = 0; i < PWM_CHANNEL_NUM; i++) { \
80 if ( (u32ChannelMask) & (1 << i)) { \
81 (pwm)->CTL |= (PWM_CTL_CH0INV_Msk << (i * 8)); \
93#define PWM_GET_CAPTURE_RISING_DATA(pwm, u32ChannelNum) (*(__IO uint32_t *) (&(pwm)->CRL0 + 2 * (u32ChannelNum)))
102#define PWM_GET_CAPTURE_FALLING_DATA(pwm, u32ChannelNum) (*(__IO uint32_t *) (&(pwm)->CFL0 + 2 * (u32ChannelNum)))
114#define PWM_SET_PRESCALER(pwm, u32ChannelNum, u32Prescaler) \
115 ((pwm)->PRES = ((pwm)->PRES & ~(PWM_PRES_CP01_Msk << (((u32ChannelNum) >> 1) * 8))) | ((u32Prescaler) << (((u32ChannelNum) >> 1) * 8)))
130#define PWM_SET_DIVIDER(pwm, u32ChannelNum, u32Divider) \
131 ((pwm)->CLKSEL = ((pwm)->CLKSEL & ~(PWM_CLKSEL_CLKSEL0_Msk << (4 * (u32ChannelNum)))) | (u32Divider << (4 * (u32ChannelNum))))
142#define PWM_SET_CMR(pwm, u32ChannelNum, u32CMR) \
144 *(__IO uint32_t *) (&(pwm)->DUTY0 + 3 * (u32ChannelNum)) &= ~PWM_DUTY0_CM_Msk; \
145 *(__IO uint32_t *) (&(pwm)->DUTY0 + 3 * (u32ChannelNum)) |= (u32CMR << PWM_DUTY0_CM_Pos); \
158#define PWM_SET_CNR(pwm, u32ChannelNum, u32CNR) \
160 *(__IO uint32_t *) (&(pwm)->DUTY0 + 3 * (u32ChannelNum)) &= ~PWM_DUTY0_CN_Msk; \
161 *(__IO uint32_t *) (&(pwm)->DUTY0 + 3 * (u32ChannelNum)) |= u32CNR; \
175#define PWM_SET_ALIGNED_TYPE(pwm, u32ChannelMask, u32AlignedType) \
178 (pwm)->CTL &= ~(PWM_CTL_PWMTYPE01_Msk | PWM_CTL_PWMTYPE23_Msk); \
179 for (i = 0; i < PWM_CHANNEL_NUM; i++) { \
180 if (u32AlignedType == PWM_CENTER_ALIGNED) \
181 if ( (u32ChannelMask) & (1 << i)) \
182 (pwm)->CTL |= (PWM_CTL_PWMTYPE01_Msk << (i >> 1)); \
187 uint32_t u32ChannelNum,
188 uint32_t u32Frequency,
189 uint32_t u32DutyCycle);
191 uint32_t u32ChannelNum,
192 uint32_t u32UnitTimeNsec,
193 uint32_t u32CaptureEdge);
219void PWM_EnablePDMA(
PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32RisingFirst, uint32_t u32Mode);
void PWM_ForceStop(PWM_T *pwm, uint32_t u32ChannelMask)
This function stop PWM generation immediately by clear channel enable bit.
void PWM_Stop(PWM_T *pwm, uint32_t u32ChannelMask)
This function stop PWM module.
void PWM_EnableCapture(PWM_T *pwm, uint32_t u32ChannelMask)
This function enables PWM capture of selected channels.
void PWM_EnablePDMA(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32RisingFirst, uint32_t u32Mode)
This function enable capture PDMA of selected channel.
void PWM_EnableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Duration)
This function enable Dead zone of selected channel.
void PWM_ClearCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge)
This function clear capture interrupt flag of selected channel.
void PWM_ClearADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition)
This function clear selected channel trigger ADC flag.
void PWM_DisableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable selected channel to trigger ADC.
uint32_t PWM_ConfigCaptureChannel(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32UnitTimeNsec, uint32_t u32CaptureEdge)
This function config PWM capture and get the nearest unit time.
void PWM_DisablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable period interrupt of selected channel.
void PWM_EnableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntDutyType)
void PWM_DisableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge)
This function disable capture interrupt of selected channel.
uint32_t PWM_ConfigOutputChannel(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Frequency, uint32_t u32DutyCycle)
This function config PWM generator and get the nearest frequency in edge aligned auto-reload mode.
uint32_t PWM_GetADCTriggerFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get selected channel trigger ADC flag.
void PWM_DisableCapture(PWM_T *pwm, uint32_t u32ChannelMask)
This function disables PWM capture of selected channels.
void PWM_DisableDutyInt(PWM_T *pwm, uint32_t u32ChannelNum)
void PWM_ClearDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function clears duty interrupt flag of selected channel.
void PWM_EnablePeriodInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType)
This function enable period interrupt of selected channel.
uint32_t PWM_GetDutyIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get duty interrupt flag of selected channel.
void PWM_DisableDeadZone(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable Dead zone of selected channel.
void PWM_DisableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function disables PWM output generation of selected channels.
void PWM_DisablePDMA(PWM_T *pwm, uint32_t u32ChannelNum)
This function disable capture PDMA of selected channel.
void PWM_Start(PWM_T *pwm, uint32_t u32ChannelMask)
This function start PWM module.
void PWM_ClearPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function clear period interrupt of selected channel.
void PWM_EnableOutput(PWM_T *pwm, uint32_t u32ChannelMask)
This function enables PWM output generation of selected channels.
uint32_t PWM_GetCaptureIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get capture interrupt flag of selected channel.
uint32_t PWM_GetPeriodIntFlag(PWM_T *pwm, uint32_t u32ChannelNum)
This function get period interrupt of selected channel.
void PWM_EnableCaptureInt(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Edge)
This function enable capture interrupt of selected channel.
void PWM_EnableADCTrigger(PWM_T *pwm, uint32_t u32ChannelNum, uint32_t u32Condition)
This function enable selected channel to trigger ADC.