9 #include "eFlexPwmPin.h"
10 #include "eFlexPwmConfig.h"
11 #include "eFlexPwmTimer.h"
81 bool begin (
bool doStart =
true,
bool doSync =
true);
115 inline void start (
bool value =
true) {
217 for (uint8_t i = ChanA; i <= ChanB ; i++) {
250 for (uint8_t i = ChanA; i <= ChanB ; i++) {
272 m_signal[channel].
level = level;
282 for (uint8_t i = ChanA; i <= ChanB ; i++) {
293 return m_signal[channel].
level;
323 for (uint8_t i = ChanA; i <= ChanB ; i++) {
357 for (uint8_t i = ChanA; i <= ChanB ; i++) {
397 m_ptr->SM[m_smidx].INIT = value;
411 m_ptr->SM[m_smidx].VAL0 = value;
425 m_ptr->SM[m_smidx].VAL1 = value;
439 m_ptr->SM[m_smidx].VAL2 = value;
453 m_ptr->SM[m_smidx].VAL3 = value;
467 m_ptr->SM[m_smidx].VAL4 = value;
481 m_ptr->SM[m_smidx].VAL5 = value;
490 return m_ptr->SM[m_smidx].INIT;
499 return m_ptr->SM[m_smidx].VAL0;
508 return m_ptr->SM[m_smidx].VAL1;
517 return m_ptr->SM[m_smidx].VAL2;
526 return m_ptr->SM[m_smidx].VAL3;
535 return m_ptr->SM[m_smidx].VAL4;
544 return m_ptr->SM[m_smidx].VAL5;
575 PWM_UpdatePwmDutycycleHighAccuracy (ptr(), SM[m_smidx], kPwmChan (channel), m_config.m_mode, m_duty[
static_cast<uint8_t
> (channel)]);
593 m_duty[
static_cast<uint8_t
> (channel)] = dutyCycle;
594 PWM_UpdatePwmDutycycleHighAccuracy (ptr(), SM[m_smidx], kPwmChan (channel), m_config.m_mode, dutyCycle);
609 return (PWM_SetupPwmPhaseShift (ptr(), SM[m_smidx], kPwmChan (channel), m_config.
pwmFreqHz(),
timer().srcClockHz(), shiftvalue, doSync) == kStatus_Success);
622 PWM_SetupInputCapture (ptr(), SM[m_smidx], kPwmChan (channel), inputCaptureParams);
635 PWM_SetupForceSignal (ptr(), SM[m_smidx], kPwmChan (channel), mode);
645 return PWM_GetStatusFlags (ptr(), SM[m_smidx]);
655 PWM_ClearStatusFlags (ptr(), SM[m_smidx], mask);
665 PWM_EnableInterrupts (ptr(), SM[m_smidx], mask);
675 PWM_DisableInterrupts (ptr(), SM[m_smidx], mask);
685 return PWM_GetEnabledInterrupts (ptr(), SM[m_smidx]);
694 PWM_DMAFIFOWatermarkControl (ptr(), SM[m_smidx], pwm_watermark_control);
703 PWM_DMACaptureSourceSelect (ptr(), SM[m_smidx], pwm_dma_source_select);
714 PWM_EnableDMACapture (ptr(), SM[m_smidx], mask, activate);
723 PWM_EnableDMAWrite (ptr(), SM[m_smidx], activate);
738 PWM_SetVALxValue (ptr(), SM[m_smidx], valueRegister, value);
748 return PWM_GetVALxValue (ptr(), SM[m_smidx], valueRegister);
762 PWM_OutputTriggerEnable (ptr(), SM[m_smidx], valueRegister, activate);
774 PWM_ActivateOutputTrigger (ptr(), SM[m_smidx], valueRegisterMask);
786 PWM_DeactivateOutputTrigger (ptr(), SM[m_smidx], valueRegisterMask);
799 PWM_SetupSwCtrlOut (ptr(), SM[m_smidx], kPwmChan (channel), value);
814 PWM_SetPwmFaultState (ptr(), SM[m_smidx], kPwmChan (channel), faultState);
831 PWM_SetupFaultDisableMap (ptr(), SM[m_smidx], kPwmChan (channel), pwm_fault_channels, value);
842 PWM_OutputEnable (ptr(), kPwmChan (channel), SM[m_smidx]);
853 PWM_OutputDisable (ptr(), kPwmChan (channel), SM[m_smidx]);
864 return PWM_GetPwmChannelState (ptr(), SM[m_smidx], kPwmChan (channel));
878 return (PWM_SetOutputToIdle (ptr(), kPwmChan (channel), SM[m_smidx], idleStatus) == kStatus_Success);
889 PWM_SetClockMode (ptr(), SM[m_smidx],
prescaler);
918 PWM_SetPwmForceOutputToZero (ptr(), SM[m_smidx], kPwmChan (channel), forcetozero);
928 PWM_SetChannelOutput (ptr(), SM[m_smidx], kPwmChan (channel), outputstate);
952 inline PWM_Type *ptr() {
956 inline const PWM_Type *ptr()
const {
985 uint16_t m_duty[NofPins];
988 extern SubModule *SmList[NofTimers][NofSubmodules];
enum _pwm_dma_source_select pwm_dma_source_select_t
List of PWM capture DMA enable source select.
enum _pwm_force_signal pwm_force_signal_t
PWM output options when a FORCE_OUT signal is asserted.
enum _pwm_value_register pwm_value_register_t
List of PWM value registers.
enum _pwm_output_state pwm_output_state_t
PWM channel output status.
enum _pwm_clock_prescale pwm_clock_prescale_t
PWM prescaler factor selection for clock source.
enum _pwm_fault_channels pwm_fault_channels_t
List of PWM fault channels.
enum _pwm_fault_state pwm_fault_state_t
PWM output fault status.
enum _pwm_mode pwm_mode_t
PWM operation mode.
enum _pwm_watermark_control pwm_watermark_control_t
PWM FIFO Watermark AND Control.
enum _pwm_level_select pwm_level_select_t
PWM output pulse mode, high-true or low-true.
uint16_t reloadValue(uint8_t dutyCyclePercent)
Convert duty cycle to reload value.
uint32_t pwmFreqHz() const
PWM signal frequency in Hz, default 5000.
void setPrescale(pwm_clock_prescale_t prescale)
Set the Pre-scaler to divide down the clock.
void setMode(pwm_mode_t mode)
Set the PWM operation mode.
pwm_clock_prescale_t prescale() const
Pre-scaler to divide down the clock, default kPWM_Prescale_Divide_1.
pwm_mode_t mode() const
PWM operation mode, default CenterAligned.
void setChannelOutput(Channel channel, pwm_output_state_t outputstate)
This function set the output state of the PWM pin as requested for the current cycle.
uint8_t dutyCyclePercentSetting(Channel channel)
value of the parameter set by setupDutyCyclePercent (Channel, uint8_t)
pwm_clock_prescale_t prescaler() const
the pwm submodule prescaler
void setupSwCtrlOut(Channel channel, bool value)
Sets the software control output for a pin to high or low.
void setupForceSignal(Channel channel, pwm_force_signal_t mode)
Selects the signal to output on a PWM pin when a FORCE_OUT signal is asserted.
void setPwmForceOutputToZero(Channel channel, bool forcetozero)
This function enables-disables the forcing of the output of a given eFlexPwm channel to logic 0.
uint16_t val4Value()
Get the PWM VAL4 register.
void disableOutputTrigger(uint16_t valueRegisterMask)
Disables the PWM output trigger.
void enableDMAWrite(bool activate)
Enables or disables the PWM DMA write request.
void stop()
Stops the PWM counter for this submodule.
bool setupPwmPhaseShift(Channel channel, uint8_t shiftvalue, bool doSync=true)
Set PWM phase shift for PWM channel running on channel PWM_A, PWM_B which with 50% duty cycle....
uint8_t dutyCyclePercent(Channel channel)
Get the dutycycle value.
void setVal4Value(uint16_t value)
Set the PWM VAL4 register.
bool isValid() const
Checks the validity of the parameters passed to the constructor.
void setPwmLdok(bool value=true)
Sets or clears the PWM LDOK bit on all instantiated submodules for this timer.
uint16_t val1Value()
Get the PWM VAL1 register.
uint32_t pwmFrequency() const
Current PWM signal frequency in Hz.
void disableOutput(Channel channel)
Set PWM output disable.
bool setPwmFrequency(uint32_t freq, bool doSync=true, bool adjustPrescaler=false)
Set the Pwm Frequency.
void setupDutyCyclePercent(Channel channel, uint8_t dutyCyclePercent)
Setting the duty cycle before calling begin.
bool isEnabled() const
Returns true if the outputsof submodule were enabled.
void setupFaultState(pwm_fault_state_t faultState)
Setting the output fault status for all channels before calling begin.
uint32_t enabledInterrupts()
Gets the enabled PWM interrupts.
void setClockMode(pwm_clock_prescale_t prescaler)
Set the pwm submodule prescaler.
void setInitValue(uint16_t value)
Set the PWM INIT register.
void setupFaultState(Channel channel, pwm_fault_state_t faultState)
Setting the output fault status before calling begin.
void enableOutputTrigger(pwm_value_register_t valueRegister, bool activate=true)
Enables or disables the PWM output trigger.
void setDMAWatermarkControl(pwm_watermark_control_t pwm_watermark_control)
Capture DMA Enable Source Select.
void printRegs(Stream &out=Serial)
Print submodule registers to stream out.
uint32_t minPwmFrequency() const
Current minimal PWM frequency in Hz.
void setupDeadtime(Channel channel, uint16_t deadtimeValue, uint32_t unit=1)
Setting the deadtime before calling begin.
void enableDMACapture(uint16_t mask, bool activate=true)
Enables or disables the selected PWM DMA Capture read request.
void setupLevel(pwm_level_select_t level)
Setting the output pulse mode for all channels before calling begin.
bool adjustPrescaler(uint32_t pwmFreq)
Adjust the prescaler if necessary.
uint16_t deadtimeSetting(Channel channel)
value of the parameter set by setupDeadtime (Channel, uint16_t)
bool configure(const Config &config)
Configures the peripheral for basic operation.
void setupLevel(Channel channel, pwm_level_select_t level)
Setting the output pulse mode before calling begin.
bool outputEnableSetting(Channel channel)
value of the parameter set by setupOutputEnable (Channel, bool)
SubModule(int pinChanA, int pinChanB=-1)
Construct a new SubModule object.
void updateDutyCyclePercent(uint8_t dutyCyclePercent, Channel channel=ChanA)
Updates the PWM signal's dutycycle.
void setupOutputEnable(bool activate=true)
Setting output enable for all channels before calling begin.
uint16_t initValue()
Get the PWM INIT register.
void setVal3Value(uint16_t value)
Set the PWM VAL3 register.
bool begin(bool doStart=true, bool doSync=true)
Sets up the PWM signals for a PWM submodule.
void setVALxValue(pwm_value_register_t valueRegister, uint16_t value)
Set the PWM VALx registers.
void enableInterrupts(uint32_t mask)
Enables the selected PWM interrupts.
uint16_t val2Value()
Get the PWM VAL2 register.
uint16_t val0Value()
Get the PWM VAL1 register.
void setDMACaptureSourceSelect(pwm_dma_source_select_t pwm_dma_source_select)
Capture DMA Enable Source Select.
void disableInterrupts(uint32_t mask)
Disables the selected PWM interrupts.
void updateDutyCycle(uint16_t dutyCycle, Channel channel=ChanA)
Updates the PWM signal's dutycycle with 16-bit accuracy.
void setupInputCapture(Channel channel, const pwm_input_capture_param_t *inputCaptureParams)
Sets up the PWM input capture.
Timer & timer()
Returns the parent PWM module.
bool updateSetting(bool doSync=true)
Update PWM signals for a PWM submodule.
void setPrescaler(pwm_clock_prescale_t prescaler)
Set the pwm submodule prescaler.
void setupDutyCyclePercent(uint8_t dutyCyclePercent)
Setting the duty cycle for all channels before calling begin.
uint16_t val3Value()
Get the PWM VAL3 register.
void setVal0Value(uint16_t value)
Set the PWM VAL0 register.
void enableOutput(Channel channel)
Set PWM output enable.
void setupDeadtime(uint16_t deadtimeValue, uint32_t unit=1)
Setting the deadtime for all channels before calling begin.
void setVal5Value(uint16_t value)
Set the PWM VAL5 register.
pwm_fault_state_t faultStateSetting(Channel channel)
value of the parameter set by setupFaultState (Channel, pwm_fault_state_t)
bool setOutputToIdle(Channel channel, bool idleStatus)
Set PWM output in idle status (high or low).
const Config & config() const
Current configuration.
void setupFaultDisableMap(Channel channel, pwm_fault_channels_t pwm_fault_channels, uint16_t value)
Set PWM fault disable mapping.
pwm_level_select_t levelSetting(Channel channel)
value of the parameter set by setupLevel (Channel, pwm_level_select_t)
void setupOutputEnable(Channel channel, bool activate=true)
Setting output enable before calling begin.
uint8_t index() const
Returns the Submodule index (0 for Submodule0...)
void start(bool value=true)
Starts the PWM counter for this submodule.
uint16_t val5Value()
Get the PWM VAL5 register.
uint16_t VALxValue(pwm_value_register_t valueRegister)
Get the PWM VALx registers.
void setVal1Value(uint16_t value)
Set the PWM VAL1 register.
uint32_t statusFlags()
Gets the PWM status flags.
void enableOutputTrigger(uint16_t valueRegisterMask)
Enables the PWM output trigger.
pwm_mode_t pwmMode() const
Current PWM signal frequency in Hz.
void setPwmFaultState(Channel channel, pwm_fault_state_t faultState)
Set PWM output fault status.
bool setPwmMode(pwm_mode_t mode, bool doSync=true)
Set the Pwm operation mode.
void enable(bool value=true)
Enable or disable the submodule.
void disable()
Disable the submodule.
void setVal2Value(uint16_t value)
Set the PWM VAL2 register.
void clearStatusFlags(uint32_t mask)
Clears the PWM status flags.
static uint32_t prescalerToMinPwmFrequency(unsigned prescaler)
Calculates the minimum PWM frequency corresponding to a prescaler.
uint32_t srcClockHz() const
PWM main counter clock in Hz.
void start(uint8_t subModulesToStart, bool startit=true)
Starts or stops the PWM counter for a single or multiple submodules.
void setPwmLdok(bool value=true)
Sets or clears the PWM LDOK bit on all instantiated submodules for this timer.
Structure for the user to define the PWM signal characteristics.
pwm_fault_state_t faultState
Structure is used to hold parameters to configure the capture capability of a signal pin.