#include <libsimpleio/libpwm.h> typedef enum { PWM_POLARITY_ACTIVELOW, PWM_POLARITY_ACTIVEHIGH, } PWM_POLARITY_t; void PWM_configure(int32_t chip, int32_t channel, int32_t period, int32_t ontime, int32_t polarity, int32_t *error); void PWM_open(int32_t chip, int32_t channel, int32_t *fd, int32_t *error); void PWM_close(int32_t fd, int32_t *error); void PWM_write(int32_t fd, int32_t ontime, int32_t *error);Link with -lsimpleio.
PWM_configure() configures a single PWM output. The chip parameter selects the PWM controller chip (as numbered by the Linux kernel) and the channel parameter selects the PWM output (also as numbered by the Linux kernel) to be configured. The period parameter sets the PWM output pulse period in nanoseconds. Note that many PWM controllers require the same PWM pulse frequency for all channels. Therefore, configuring different pulse period values for different channels within the same PWM controller may result in incorrect operation. The ontime parameter sets the initial PWM output pulse width in nanoseconds. The polarity parameter sets the PWM output polarity and may be PWM_POLARITY_ACTIVELOW or PWM_POLARITY_ACTIVEHIGH. Note that some PWM controllers will not allow the PWM_POLARITY_ACTIVELOW setting.
PWM_open() opens a (previously) configured PWM output device. The PWM controller chip number must be passed in the chip parameter and the PWM output number must be passed in the channel parameter. Upon success, a file descriptor for the PWM output device is returned in *fd.
PWM_close() closes a previously opened PWM output device.
PWM_write() changes the PWM output pulse width. The file descriptor for an open PWM output device must be passed in the fd parameter. The new PWM output pulse width in nanoseconds must be passed in the ontime parameter.