/** * @file hal_pwm.h * @author Xiao, Lifan (xiaolf6@midea.com) * @brief * @version 0.1 * @date 2021-08-09 * * @copyright Copyright (c) 2021 * * @details The interface of PWM module * */ #ifndef _HAL_PWM_H_ #define _HAL_PWM_H_ #include "hal_config.h" /**************************************************************** * * Standard Interface * * *************************************************************/ /********************/ /* Type definations */ /********************/ /** * @brief The PWM wave type * @note Four type of PWM wave is supported, as * * RightAligned: * ┌────── * │ * │ * ──────┘ * * LeftAligned: * ──────┐ * │ * │ * └────── * * CenterAligned: * ┌───┐ * │ │ * │ │ * ────┘ └──── * * CenterAlignedInverse: * ────┐ ┌──── * │ │ * │ │ * └───┘ * */ typedef enum { RightAligned, LeftAligned, CenterAligned, CenterAlignedInverse, EdgeAlignedAutoReverse, #if HAL_PWM_SUPPORT_CUSTOM_VECTOR_TYPE Custom, #endif } Hal_Pwm_WaveModeEnum; typedef enum { VectorTypeUp, VectorTypeDown, VectorTypeUpDown, VectorTypeDownUp, } Hal_Pwm_VectorType; /******************************/ /* Global Interface Variables */ /******************************/ /* !!!Important!!! */ /* Interface Variable Should Not Be Modified By Application */ /** * @brief The clock of the pwm module (in unit Hz) * */ extern uint32_t Hal_Pwm_Clock; /** * @brief The period of the pwm module (in unit Ticks) * */ extern uint32_t Hal_Pwm_PeriodTicks; /** * @brief The period of the pwm module (in unit us) * */ extern uint32_t Hal_Pwm_PeriodUs; /** * @brief Avaliable pwm channel number * */ extern const uint32_t Hal_Pwm_ChannelNum; /** * @brief Actual phase duty cycle (in unit ticks) * */ extern uint32_t *Hal_Pwm_ActualDutyCycleTicks; /** * @brief Drive pwm output status * */ extern int8_t Hal_Pwm_DriveOutputEnable; /*************************/ /* Global Interface Hook */ /*************************/ /** * @brief Function hook called at Zero Interrupt * */ extern void (*Hal_Pwm_ZeroIsrHook)(); /** * @brief Function hook called at Period Interrupt * */ extern void (*Hal_Pwm_PeriodIsrHook)(); /*****************************************/ /* Application Layer Interface Functions */ /*****************************************/ /** * @brief Set the duty cycle for all channel (in q15 format) * * @param da Pointer to the list of duty cycles * @param channels The number of channel to set duty cycle * * @note If current PWM mode is EdgeAlignedAutoReverse, the modulation mode will reverse after calling this function */ void Hal_Pwm_SetDutyCycle(int32_t *da, int8_t channels); /** * @brief Set the duty cycle for specified channel (in q15 format) * * @param duty duty cycle * @param chindex The index of channel to set duty cycle * * @note Calling this function will not affect PWM mode */ void Hal_Pwm_SetChannelDutyCycle(int32_t duty, int8_t chindex); /** * @brief Set the pwm period (in ticks) * * @param ticks Pwm period */ void Hal_Pwm_SetPeriod(int32_t ticks); /** * @brief Set the Wave Mode * * @param mode Target mode */ void Hal_Pwm_SetWaveMode(Hal_Pwm_WaveModeEnum mode); /** * @brief Set the pwm output deadband * * @param ticks Deadband length */ void Hal_Pwm_SetDeadband(int32_t ticks); /** * @brief Enable drive pwm immediately * */ void Hal_Pwm_EnableDriveOutput(); /** * @brief Disable drive pwm output immediately * */ void Hal_Pwm_DisableDriveOutput(); /** * @brief Enable channel pwm immediately * * @param ch_index Channel index */ void Hal_Pwm_EnableChannelOutput(uint8_t ch_index); /** * @brief Disable channel pwm immediately * * @param ch_index Channel index */ void Hal_Pwm_DisableChannelOutput(uint8_t ch_index); /** * @brief Enable standard hooks, function address for enable, 0 for disable * * @param zeroHook Zero interrupt hook address * @param prdHook Period interrupt hook address */ void Hal_Pwm_EnableStdHooks(void *zeroHook, void *prdHook); /**************************************/ /* Platform Layer Interface Functions */ /**************************************/ /** * @brief Init pwm module * */ void Hal_Pwm_Init(); #if HAL_PWM_SUPPORT_CUSTOM_VECTOR_TYPE /**************************************************************** * * Extended Interface * Support Custom Modulation Like TSPWM * Different Vector Type On Different Channel * * *************************************************************/ void Hal_Pwm_Ext_SetCustomVectorType(Hal_Pwm_VectorType *type, uint8_t channels); #endif #if HAL_PWM_SUPPORT_SINGLE_RESISTOR_SAMPLING /**************************************************************** * * Extended Interface * Support Single Resistor Sampling * * *************************************************************/ /*************************/ /* Global Interface Hook */ /*************************/ /** * @brief Function hook for pwm sampling trigger * */ void (*Hal_Pwm_Ext_SamplingTriggerHook)(); /*****************************************/ /* Application Layer Interface Functions */ /*****************************************/ /** * @brief Set the duty cycle of the extra channel, affect the * sampling trigger moment * * @param dutycycle Duty cycle in q15 format */ void Hal_Pwm_Ext_SetSamplingDutyCycle(uint32_t dutycycle); /**************************************/ /* Platform Layer Interface Functions */ /**************************************/ /** * @brief Extra init process to support single resistor sampling * @note * An extra channel will be used to trigger sampling at attribute time. * The counter of extra channel always runs counting up mode for * controlling the sampling trigger time * */ void Hal_Pwm_Ext_Init(); #endif #if HAL_PWM_SUPPORT_COMPLEMENTARY_PULSE_GENERATION #endif #if HAL_PWM_SUPPORT_HALF_PULSE_GENERATION #endif #endif