MCUXpresso SDK API Reference Manual  Rev 2.13.0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
PWM_Adapter

Overview

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...
 

Data Structure Documentation

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.
 

Macro Definition Documentation

#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,

* HAL_PWM_HANDLE_DEFINE(pwmHandle);
*
Parameters
nameThe name string of the PMW handle.

Typedef Documentation

typedef void* hal_pwm_handle_t

Enumeration Type Documentation

Enumerator
kHAL_EdgeAlignedPwm 

Edge aligned PWM.

kHAL_CenterAlignedPwm 

Center aligned PWM.

Enumerator
kHAL_PwmNoPwmSignal 

No PWM output on pin.

kHAL_PwmLowTrue 

Low true pulses.

kHAL_PwmHighTrue 

High true pulses.

Enumerator
kStatus_HAL_PwmSuccess 

Success.

kStatus_HAL_PwmFail 

Failure.

kStatus_HAL_PwmNotSupport 

Not support.

kStatus_HAL_PwmOutOfRanger 

Pwm is Out Of Ranger.

Function Documentation

hal_pwm_status_t HAL_PwmInit ( hal_pwm_handle_t  halPwmHandle,
uint8_t  instance,
uint32_t  srcClock_Hz 
)
Note
This API should be called at the beginning of the application using the pwm adapter.

Example below shows how to use this API to configure the PWM.

* HAL_PWM_HANDLE_DEFINE(pwmHandle);
* HAL_PwmInit((hal_pwm_handle_t)pwmHandle, BOARD_PWM_INSTANCE, BOARD_PWM_SOURCE_CLOCK);
*
Parameters
halPwmHandleHal 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))];
instanceThe 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_HzFrequency of source clock of the pwm module
Return values
kStatus_HAL_PwmSuccesspwm initialization succeed
void HAL_PwmDeinit ( hal_pwm_handle_t  halPwmHandle)
Note
This API should be called when not using the pwm adapter driver anymore.
Parameters
halPwmHandleHal pwm adapter handle
hal_pwm_status_t HAL_PwmSetupPwm ( hal_pwm_handle_t  halPwmHandle,
uint8_t  channel,
hal_pwm_setup_config_t setupConfig 
)
Note
This API should be called when setup the pwm.
Parameters
halPwmHandleHal pwm adapter handle
channelChannel of pwm
setupConfigA pointer to the HAL pwm setup configuration structure
Return values
kStatus_HAL_PwmSuccesspwm setup succeed
hal_pwm_status_t HAL_PwmUpdateDutycycle ( hal_pwm_handle_t  halPwmHandle,
uint8_t  channel,
hal_pwm_mode_t  mode,
uint8_t  dutyCyclePercent 
)
Note
This API should be called when need update duty cycle.
Parameters
halPwmHandleHal pwm adapter handle
channelChannel of pwm
modePWM mode select
dutyCyclePercentPWM duty cycle percent
Return values
kStatus_HAL_PwmSuccesspwm Update duty cycle succeed