|
Open Model Railroad Network (OpenMRN)
|
Implementation of a single PWM channel using the linux sysfs API. More...
#include <LinuxPWM.hxx>
Public Member Functions | |
| LinuxPWM (int chip, int channel) | |
| Constructor. | |
| void | export_pin () |
| Call this once after instantiating the object but before using any of the PWM apis. | |
| void | set_period (uint32_t counts) override |
| Set PWM period. | |
| uint32_t | get_period () override |
| Get PWM period. | |
| void | set_duty (uint32_t counts) override |
| Sets the duty cycle. | |
| uint32_t | get_duty () override |
| Gets the duty cycle. | |
| uint32_t | get_period_max () override |
| Get max period supported. | |
| uint32_t | get_period_min () override |
| Get min period supported. | |
| void | enable () |
| Enables the output PWM waveform. | |
| void | disable () |
| Disables the output PWM waveform. | |
| bool | enabled () |
| Returns whether the output PWM waveform is enabled or not. | |
Public Member Functions inherited from PWM | |
| void | set_duty_percent (uint8_t percent) |
| Sets the duty cycle. | |
| uint8_t | get_duty_percent () |
| Gets the duty cycle. | |
Private Member Functions | |
| uint32_t | get_sysfs_file_value (const char *basename) |
| Returns a single file's content from the channel directory on sysfs. | |
| void | set_sysfs_file_value (const char *basename, uint32_t value) |
| Writes a single integer into a sysfs file of the channel directory. | |
Private Attributes | |
| const uint32_t | chip_ |
| Kernel number of the chip. | |
| const uint32_t | channel_ |
| Number of the channel in the chip. | |
| const string | pwmdir_ |
| Diretory path of the channel, with trailing /. | |
Static Private Attributes | |
| static constexpr const char * | ENABLE_FILE = "enable" |
| Basename for sysfs file for enabling the channel. | |
| static constexpr const char * | PERIOD_FILE = "period" |
| Basename for sysfs file for setting the period. | |
| static constexpr const char * | DUTY_CYCLE_FILE = "duty_cycle" |
| Basename for sysfs file for setting the duty cycle. | |
Additional Inherited Members | |
Protected Member Functions inherited from PWM | |
| constexpr | PWM ()=default |
| Constructor. | |
| ~PWM ()=default | |
| Destructor. | |
Implementation of a single PWM channel using the linux sysfs API.
Definition at line 58 of file LinuxPWM.hxx.
|
inline |
Constructor.
| chip | is an integer, the index in the kernel where the PWM chip is registered. |
| channel | the index of the output channel on the specific chip to use. |
Definition at line 66 of file LinuxPWM.hxx.
|
inline |
Disables the output PWM waveform.
Definition at line 162 of file LinuxPWM.hxx.
|
inline |
Enables the output PWM waveform.
Definition at line 156 of file LinuxPWM.hxx.
|
inline |
Returns whether the output PWM waveform is enabled or not.
Definition at line 168 of file LinuxPWM.hxx.
|
inline |
Call this once after instantiating the object but before using any of the PWM apis.
Definition at line 76 of file LinuxPWM.hxx.
|
inlineoverridevirtual |
Gets the duty cycle.
Implements PWM.
Definition at line 137 of file LinuxPWM.hxx.
|
inlineoverridevirtual |
Get PWM period.
Implements PWM.
Definition at line 115 of file LinuxPWM.hxx.
|
inlineoverridevirtual |
Get max period supported.
Implements PWM.
Definition at line 144 of file LinuxPWM.hxx.
|
inlineoverridevirtual |
Get min period supported.
Implements PWM.
Definition at line 149 of file LinuxPWM.hxx.
|
inlineprivate |
Returns a single file's content from the channel directory on sysfs.
| basename | is the name of the file (e.g. "period") |
Definition at line 193 of file LinuxPWM.hxx.
|
inlineoverridevirtual |
Sets the duty cycle.
| counts | duty cycle in counts |
Implements PWM.
Definition at line 122 of file LinuxPWM.hxx.
|
inlineoverridevirtual |
Set PWM period.
| PWM | period in counts |
Implements PWM.
Definition at line 99 of file LinuxPWM.hxx.
|
inlineprivate |
Writes a single integer into a sysfs file of the channel directory.
| basename | is the name of the file (e.g. "period") |
| value | is the number to write. |
Definition at line 214 of file LinuxPWM.hxx.
|
private |
Number of the channel in the chip.
Definition at line 186 of file LinuxPWM.hxx.
|
private |
Kernel number of the chip.
Definition at line 184 of file LinuxPWM.hxx.
|
staticconstexprprivate |
Basename for sysfs file for setting the duty cycle.
Definition at line 181 of file LinuxPWM.hxx.
|
staticconstexprprivate |
Basename for sysfs file for enabling the channel.
Definition at line 177 of file LinuxPWM.hxx.
|
staticconstexprprivate |
Basename for sysfs file for setting the period.
Definition at line 179 of file LinuxPWM.hxx.
|
private |
Diretory path of the channel, with trailing /.
Definition at line 188 of file LinuxPWM.hxx.