![]() |
MCUXpresso SDK API Reference Manual
Rev 2.13.0
NXP Semiconductors
|
Data Structures | |
struct | hal_pwm_setup_config_t |
hal pwm configuration structure for hal pwm setting. More... | |
Macros | |
#define | HAL_PWM_HANDLE_SIZE (8U) |
Hal pwm handle size. More... | |
#define | HAL_PWM_HANDLE_DEFINE(name) uint32_t name[(HAL_PWM_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)] |
Defines the PMW handle. More... | |
Typedefs | |
typedef void * | hal_pwm_handle_t |
Hal pwm handle. More... | |
Enumerations | |
enum | hal_pwm_mode_t { kHAL_EdgeAlignedPwm = 0U, kHAL_CenterAlignedPwm } |
Hal pwm mode. More... | |
enum | hal_pwm_level_select_t { kHAL_PwmNoPwmSignal = 0U, kHAL_PwmLowTrue, kHAL_PwmHighTrue } |
PWM output pulse level select: high-true, low-true or no output. More... | |
enum | hal_pwm_status_t { kStatus_HAL_PwmSuccess = kStatus_Success, kStatus_HAL_PwmFail = MAKE_STATUS(kStatusGroup_HAL_PWM, 1), kStatus_HAL_PwmNotSupport = MAKE_STATUS(kStatusGroup_HAL_PWM, 2), kStatus_HAL_PwmOutOfRanger = MAKE_STATUS(kStatusGroup_HAL_PWM, 3) } |
Hal pwm status. More... | |
Functions | |
hal_pwm_status_t | HAL_PwmInit (hal_pwm_handle_t halPwmHandle, uint8_t instance, uint32_t srcClock_Hz) |
Initializes the pwm adapter module for a pwm basic operation. More... | |
void | HAL_PwmDeinit (hal_pwm_handle_t halPwmHandle) |
DeInitilizate the pwm adapter module. More... | |
hal_pwm_status_t | HAL_PwmSetupPwm (hal_pwm_handle_t halPwmHandle, uint8_t channel, hal_pwm_setup_config_t *setupConfig) |
setup pwm. More... | |
hal_pwm_status_t | HAL_PwmUpdateDutycycle (hal_pwm_handle_t halPwmHandle, uint8_t channel, hal_pwm_mode_t mode, uint8_t dutyCyclePercent) |
Update duty cycle of pwm. More... | |
struct hal_pwm_setup_config_t |
Data Fields | |
hal_pwm_level_select_t | level |
PWM output pulse level select. | |
hal_pwm_mode_t | mode |
PWM mode select. | |
uint32_t | pwmFreq_Hz |
PWM frequency. | |
uint8_t | dutyCyclePercent |
PWM duty cycle percent. | |
#define HAL_PWM_HANDLE_SIZE (8U) |
#define HAL_PWM_HANDLE_DEFINE | ( | name | ) | uint32_t name[(HAL_PWM_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)] |
This macro is used to define a 4 byte aligned PWM handle. Then use "(hal_pwm_handle_t)name" to get the PWM handle.
The macro should be global and could be optional. You could also define PWM handle by yourself.
This is an example,
name | The name string of the PMW handle. |
typedef void* hal_pwm_handle_t |
enum hal_pwm_mode_t |
enum hal_pwm_status_t |
hal_pwm_status_t HAL_PwmInit | ( | hal_pwm_handle_t | halPwmHandle, |
uint8_t | instance, | ||
uint32_t | srcClock_Hz | ||
) |
Example below shows how to use this API to configure the PWM.
halPwmHandle | Hal pwm adapter handle, the handle buffer with size HAL_PWM_HANDLE_SIZE should be allocated at upper level The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices. You can define the handle in the following two ways: HAL_PWM_HANDLE_DEFINE(halPwmHandle); or uint32_t halPwmHandle[((HAL_PWM_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]; |
instance | The instance index of the hardware PWM. For example, if FTM is used as the PWM hardware, 0 should be set to "instance" to use FTM0; 2 should be set to "instance" to use FTM2 detail information please refer to the SOC corresponding RM. Invalid instance value will cause initialization failure. |
srcClock_Hz | Frequency of source clock of the pwm module |
kStatus_HAL_PwmSuccess | pwm initialization succeed |
void HAL_PwmDeinit | ( | hal_pwm_handle_t | halPwmHandle | ) |
halPwmHandle | Hal pwm adapter handle |
hal_pwm_status_t HAL_PwmSetupPwm | ( | hal_pwm_handle_t | halPwmHandle, |
uint8_t | channel, | ||
hal_pwm_setup_config_t * | setupConfig | ||
) |
halPwmHandle | Hal pwm adapter handle |
channel | Channel of pwm |
setupConfig | A pointer to the HAL pwm setup configuration structure |
kStatus_HAL_PwmSuccess | pwm setup succeed |
hal_pwm_status_t HAL_PwmUpdateDutycycle | ( | hal_pwm_handle_t | halPwmHandle, |
uint8_t | channel, | ||
hal_pwm_mode_t | mode, | ||
uint8_t | dutyCyclePercent | ||
) |
halPwmHandle | Hal pwm adapter handle |
channel | Channel of pwm |
mode | PWM mode select |
dutyCyclePercent | PWM duty cycle percent |
kStatus_HAL_PwmSuccess | pwm Update duty cycle succeed |