eFlexPwm
Arduino eFlexPwm library for Teensy 4.x
eFlexPwmConfig.h
1 /*
2  Copyright (c) 2023, epsilonrt
3  All rights reserved.
4 
5  SPDX-License-Identifier: BSD-3-Clause
6 */
7 #pragma once
8 
9 #include "eFlexPwmGlobal.h"
10 
11 namespace eFlex {
12 
13  class Timer;
14  class Submodule;
15 
20  class Config {
21  public:
22 
40  Config();
41 
45  inline void setPwmFreqHz (uint32_t pwmFreqHz) {
46 
47  m_pwmfreq = pwmFreqHz;
48  }
49 
53  inline uint32_t pwmFreqHz() const {
54 
55  return m_pwmfreq;
56  }
57 
61  inline void setMode (pwm_mode_t mode) {
62 
63  m_mode = mode;
64  }
65 
69  inline pwm_mode_t mode() const {
70 
71  return m_mode;
72  }
73 
78 
79  m_config.reloadSelect = reloadSelect;
80  }
81 
86 
87  return m_config.reloadSelect;
88  }
89 
94 
95  m_config.clockSource = clockSource;
96  }
97 
102 
103  return m_config.clockSource;
104  }
105 
110 
111  m_config.prescale = prescale;
112  }
113 
118 
119  return m_config.prescale;
120  }
121 
126 
128  }
129 
134 
135  return m_config.initializationControl;
136  }
137 
142 
143  m_config.forceTrigger = forceTrigger;
144  }
145 
150 
151  return m_config.forceTrigger;
152  }
153 
158 
159  m_config.reloadFrequency = reloadFrequency;
160  }
161 
168 
169  return m_config.reloadFrequency;
170  }
171 
176 
177  m_config.reloadLogic = reloadLogic;
178  }
179 
184 
185  return m_config.reloadLogic;
186  }
187 
192 
193  m_config.pairOperation = pairOperation;
194  }
195 
200 
201  return m_config.pairOperation;
202  }
203 
209  inline void enableDebugMode (bool enable) {
210 
211  m_config.enableDebugMode = enable;
212  }
213 
220  inline bool debugModeEnabled() const {
221 
222  return m_config.enableDebugMode;
223  }
224 
230  inline void enableWaitMode (bool enable) {
231 
232  m_config.enableWait = enable;
233  }
234 
241  inline bool waitModeEnabled() const {
242 
243  return m_config.enableWait;
244  }
245 
246  protected:
247  pwm_config_t *kPwmConfig();
248  const pwm_config_t *kPwmConfig() const;
249 
250  private:
251  friend class Timer;
252  friend class SubModule;
253 
254  private:
255  pwm_mode_t m_mode;
256  uint32_t m_pwmfreq;
257  pwm_config_t m_config;
258  };
259 }
enum _pwm_load_frequency pwm_load_frequency_t
PWM load frequency selection.
enum _pwm_clock_source pwm_clock_source_t
PWM clock source selection.
enum _pwm_clock_prescale pwm_clock_prescale_t
PWM prescaler factor selection for clock source.
enum _pwm_force_output_trigger pwm_force_output_trigger_t
Options that can trigger a PWM FORCE_OUT.
enum _pwm_reload_source_select pwm_reload_source_select_t
PWM reload source select.
enum _pwm_register_reload pwm_register_reload_t
Options available on how to load the buffered-registers with new values.
enum _pwm_init_source pwm_init_source_t
PWM counter initialization options.
enum _pwm_mode pwm_mode_t
PWM operation mode.
enum _pwm_chnl_pair_operation pwm_chnl_pair_operation_t
Options available for the PWM A & B pair operation.
Library namespace.
Configuration.
void enableWaitMode(bool enable)
enable Wait Mode
void setPairOperation(pwm_chnl_pair_operation_t pairOperation)
Set the channel pair in indepedent or complementary mode.
bool debugModeEnabled() const
Debug mode, default false.
void setInitializationControl(pwm_init_source_t initializationControl)
Set the Option to initialize the counter.
pwm_load_frequency_t reloadFrequency() const
Specifies when to reload, default kPWM_LoadEveryOportunity.
uint32_t pwmFreqHz() const
PWM signal frequency in Hz, default 5000.
void setPwmFreqHz(uint32_t pwmFreqHz)
Set the PWM signal frequency in Hz.
void setReloadLogic(pwm_register_reload_t reloadLogic)
Set the PWM Reload logic setup.
void setReloadFrequency(pwm_load_frequency_t reloadFrequency)
Specifies when to reload.
Config()
Construct a new Config object with the default settings.
void enableDebugMode(bool enable)
enable Debug Mode
pwm_register_reload_t reloadLogic() const
PWM Reload logic setup, default kPWM_ReloadImmediate.
void setReloadSelect(pwm_reload_source_select_t reloadSelect)
Set the reload source select.
void setForceTrigger(pwm_force_output_trigger_t forceTrigger)
Specify which signal will trigger a FORCE_OUT.
pwm_init_source_t initializationControl() const
Reload source select, default kPWM_Initialize_LocalSync.
void setPrescale(pwm_clock_prescale_t prescale)
Set the Pre-scaler to divide down the clock.
pwm_chnl_pair_operation_t pairOperation() const
Channel pair in indepedent or complementary mode, default kPWM_Independent.
void setMode(pwm_mode_t mode)
Set the PWM operation mode.
pwm_clock_source_t clockSource() const
Clock source for the counter, default kPWM_BusClock.
pwm_clock_prescale_t prescale() const
Pre-scaler to divide down the clock, default kPWM_Prescale_Divide_1.
void setClockSource(pwm_clock_source_t clockSource)
Select the Clock source for the counter.
bool waitModeEnabled() const
Wait mode, default false.
pwm_reload_source_select_t reloadSelect() const
Option to initialize the counter, default kPWM_LocalReload.
pwm_mode_t mode() const
PWM operation mode, default CenterAligned.
pwm_force_output_trigger_t forceTrigger() const
Specify which signal will trigger a FORCE_OUT, default kPWM_Force_Local.
PWM Module.
Definition: eFlexPwmTimer.h:19
PWM config structure.
pwm_load_frequency_t reloadFrequency
pwm_clock_source_t clockSource
pwm_force_output_trigger_t forceTrigger
pwm_chnl_pair_operation_t pairOperation
pwm_clock_prescale_t prescale
pwm_register_reload_t reloadLogic
pwm_reload_source_select_t reloadSelect
pwm_init_source_t initializationControl