6#include "dawn/porting/pwm.hxx"
11#include <nuttx/timers/pwm.h>
15#include "dawn/debug.hxx"
16#include "dawn/porting/config.hxx"
26int pwm_open(
const char *path)
30 fd = open(path, O_WRONLY | O_NONBLOCK);
31 DAWNINFO(
"PWM: open %s %d\n", path, fd);
34 DAWNERR(
"Failed to open PWM file %s (error %d)\n", path, fd);
70 return ioctl(fd, PWMIOC_START, 0);
79 return ioctl(fd, PWMIOC_STOP, 0);
88 struct pwm_info_s info = {0};
93 info.frequency = pwm->freq;
95 for (
int i = 0; i < CONFIG_PWM_NCHANNELS; i++)
97 info.channels[i].duty = b16idiv(pwm->channels[i].duty, 1000);
98 if (pwm->channels[i].channel > SCHAR_MAX)
103 info.channels[i].channel =
static_cast<int8_t
>(pwm->channels[i].channel);
108 ret = ioctl(fd, PWMIOC_SETCHARACTERISTICS,
reinterpret_cast<unsigned long>(&info));
111 DAWNERR(
"PWMIOC_SETCHARACTERISTICS failed %d\n", -errno);