PWM


Data Types


shared_mode

Determines the way in which libsoc handles exporting and unexporting PWMs in the Linux subsystem.

pwm_enabled

Used for setting and reading the enabled state of the PWM device


pwm_polarity

Used for setting and reading the polarity of the PWM device

Functions


libsoc_pwm_request

pwm* libsoc_pwm_request(unsigned int pwm_chip, unsigned int pwm_num, enum shared_mode mode)

Request a pwm by specifying its pwm chip number and the pwm number it is on that chip. Set shared_mode to handle how libsoc manages the file descriptor. Returns a malloced pwm struct which will need to be freed by libsoc_pwm_free when no longer needed.


libsoc_pwm_free

int libsoc_pwm_free(pwm *pwm)

Free the memory associated with a previously requested PWM device and close the file descriptors.


libsoc_pwm_set_enabled

int libsoc_pwm_set_enabled(pwm *pwm, pwm_enabled enabled)

Set the state of a PWM device, ENABLED to enable to the device, DISABLED to disable the device.


libsoc_pwm_get_enabled

pwm_enabled libsoc_pwm_get_enabled(pwm *pwm)

Get the current pwm_enabled state of a requested PWM device.


libsoc_pwm_set_period

int libsoc_pwm_set_period(pwm *pwm, unsigned int period)

Set the period of a PWM device, the value is specified in nanoseconds and is the sum of the active and inactive time of the signal.


libsoc_pwm_get_period

int libsoc_pwm_get_period(pwm *pwm)

Get the currently set perioid of the PWM device in nanoseconds.


libsoc_pwm_set_duty_cycle

int libsoc_pwm_set_duty_cycle(pwm *pwm, unsigned int duty)

Set the duty cycle of the specified PWM device in nanoseconds. The duty cycle is the active time of the PWM signal and must be less than the period.


libsoc_pwm_get_duty_cycle

int libsoc_pwm_get_duty_cycle(pwm *pwm)

Get the currently set duty cycle of a requested PWM device in nanoseconds.


libsoc_pwm_set_polarity

int libsoc_pwm_set_polarity(pwm *pwm, pwm_polarity polarity)

Set the polarity of a PWM device, NORMAL will give you the default polarity, INVERSED will give you the inverse polarity of normal.

Polarity support is optional, ensure your PWM devices kernel driver is capable before relying on this support. The value -1 will be returned on failure to set the polarity.


libsoc_pwm_get_polarity

pwm_polarity libsoc_pwm_get_polarity(pwm *pwm)

Get the current pwm_polarity of a requested PWM device.