The
pwmc
driver provides device-control access to a channel of PWM hardware.
Each instance of a
pwmc
device is associated with a single PWM output channel.
Some PWM hardware is organized with multiple channels sharing a
common clock or other resources.
In such cases, a separate
pwmc
instance will exist for each channel, but changing the period or
duty cycle of any one channel may affect other channels within the
hardware which share the same resources.
Consult the documentation for the underlying PWM hardware device driver
for details on channels that share resources.
An instance of
pwmc
creates a character device named
/dev/pwm/pwmcX.Y
where
X
is a sequential number assigned to each PWM hardware controller
as it is discovered by the system, and
Y
is the channel number within that hardware controller.
The driver can be configured to create aliases that point to the
pwmcX.Y
entries, in effect creating named channels.
The
pwmc
driver provides control of a PWM channel with the following
ioctl(2)
calls and data structures, defined in
<dev/pwm/pwmc.h>:
| PWMGETSTATE (struct pwm_state)
|
| |
Retrieve the current state of the channel.
|
| PWMSETSTATE (struct pwm_state)
|
| |
Set the current state of the channel.
All parameters are updated on every call.
To change just one of the values, use
PWMGETSTATE
to get the current state and then submit the same data back with
just the appropriate value changed.
|
The
pwm_state
structure is defined as follows:
struct pwm_state {
u_int period;
u_int duty;
uint32_t flags;
bool enable;
};
| period
|
| |
The duration, in nanoseconds, of one complete on-off cycle.
|
| duty
|
| |
The duration, in nanoseconds, of the on portion of one cycle.
|
| flags
|
| |
Flags that affect the output signal can be bitwise-ORed together.
The following flags are currently defined:
|
| PWM_POLARITY_INVERTED
|
| |
Invert the signal polarity.
|
| enable
|
| |
False to disable the output signal or true to enable it.
|