Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
LinuxPWM Class Reference

Implementation of a single PWM channel using the linux sysfs API. More...

#include <LinuxPWM.hxx>

Inheritance diagram for LinuxPWM:
PWM

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.
 

Detailed Description

Implementation of a single PWM channel using the linux sysfs API.

Definition at line 58 of file LinuxPWM.hxx.

Constructor & Destructor Documentation

◆ LinuxPWM()

LinuxPWM::LinuxPWM ( int  chip,
int  channel 
)
inline

Constructor.

Parameters
chipis an integer, the index in the kernel where the PWM chip is registered.
channelthe index of the output channel on the specific chip to use.

Definition at line 66 of file LinuxPWM.hxx.

Member Function Documentation

◆ disable()

void LinuxPWM::disable ( )
inline

Disables the output PWM waveform.

Definition at line 162 of file LinuxPWM.hxx.

◆ enable()

void LinuxPWM::enable ( )
inline

Enables the output PWM waveform.

Definition at line 156 of file LinuxPWM.hxx.

◆ enabled()

bool LinuxPWM::enabled ( )
inline

Returns whether the output PWM waveform is enabled or not.

Definition at line 168 of file LinuxPWM.hxx.

◆ export_pin()

void LinuxPWM::export_pin ( )
inline

Call this once after instantiating the object but before using any of the PWM apis.

Definition at line 76 of file LinuxPWM.hxx.

◆ get_duty()

uint32_t LinuxPWM::get_duty ( )
inlineoverridevirtual

Gets the duty cycle.

Returns
counts duty cycle in counts

Implements PWM.

Definition at line 137 of file LinuxPWM.hxx.

◆ get_period()

uint32_t LinuxPWM::get_period ( )
inlineoverridevirtual

Get PWM period.

Returns
PWM period in counts

Implements PWM.

Definition at line 115 of file LinuxPWM.hxx.

◆ get_period_max()

uint32_t LinuxPWM::get_period_max ( )
inlineoverridevirtual

Get max period supported.

Returns
period in counts

Implements PWM.

Definition at line 144 of file LinuxPWM.hxx.

◆ get_period_min()

uint32_t LinuxPWM::get_period_min ( )
inlineoverridevirtual

Get min period supported.

Returns
period in counts

Implements PWM.

Definition at line 149 of file LinuxPWM.hxx.

◆ get_sysfs_file_value()

uint32_t LinuxPWM::get_sysfs_file_value ( const char *  basename)
inlineprivate

Returns a single file's content from the channel directory on sysfs.

Parameters
basenameis the name of the file (e.g. "period")
Returns
the contents of the file converted to integer.

Definition at line 193 of file LinuxPWM.hxx.

◆ set_duty()

void LinuxPWM::set_duty ( uint32_t  counts)
inlineoverridevirtual

Sets the duty cycle.

Parameters
countsduty cycle in counts

Implements PWM.

Definition at line 122 of file LinuxPWM.hxx.

◆ set_period()

void LinuxPWM::set_period ( uint32_t  counts)
inlineoverridevirtual

Set PWM period.

Parameters
PWMperiod in counts

Implements PWM.

Definition at line 99 of file LinuxPWM.hxx.

◆ set_sysfs_file_value()

void LinuxPWM::set_sysfs_file_value ( const char *  basename,
uint32_t  value 
)
inlineprivate

Writes a single integer into a sysfs file of the channel directory.

Parameters
basenameis the name of the file (e.g. "period")
valueis the number to write.

Definition at line 214 of file LinuxPWM.hxx.

Member Data Documentation

◆ channel_

const uint32_t LinuxPWM::channel_
private

Number of the channel in the chip.

Definition at line 186 of file LinuxPWM.hxx.

◆ chip_

const uint32_t LinuxPWM::chip_
private

Kernel number of the chip.

Definition at line 184 of file LinuxPWM.hxx.

◆ DUTY_CYCLE_FILE

constexpr const char* LinuxPWM::DUTY_CYCLE_FILE = "duty_cycle"
staticconstexprprivate

Basename for sysfs file for setting the duty cycle.

Definition at line 181 of file LinuxPWM.hxx.

◆ ENABLE_FILE

constexpr const char* LinuxPWM::ENABLE_FILE = "enable"
staticconstexprprivate

Basename for sysfs file for enabling the channel.

Definition at line 177 of file LinuxPWM.hxx.

◆ PERIOD_FILE

constexpr const char* LinuxPWM::PERIOD_FILE = "period"
staticconstexprprivate

Basename for sysfs file for setting the period.

Definition at line 179 of file LinuxPWM.hxx.

◆ pwmdir_

const string LinuxPWM::pwmdir_
private

Diretory path of the channel, with trailing /.

Definition at line 188 of file LinuxPWM.hxx.


The documentation for this class was generated from the following file: