38 #define PWM_SYSFS_DEFAULT_PERIOD 10000000
42 #define PS_DEBUG_PRINT printf
44 #define PS_DEBUG_PRINT(...) {}
48 static int write_file(
const char *path,
const char *fmt, ...);
50 static int read_file(
const char *path,
const char *fmt, ...) __attribute__((unused));
53 char *_export,
char *_enable,
54 char *_duty,
char *_period,
60 if (base_path == NULL || _export == NULL || _enable == NULL ||
61 _period == NULL || _duty == NULL) {
73 export_path,
pwm->enable_path,
pwm->duty_path,
pwm->period_path);
78 pwm->duty_cycle_fd = open(
pwm->duty_path, O_RDWR | O_CLOEXEC);
79 if (
pwm->duty_cycle_fd < 0) {
98 pwm->period_nsec = period;
103 if (dprintf(
pwm->duty_cycle_fd,
"%u", duty) < 0) {
107 pwm->duty_cycle_nsec = duty;
116 int en = enable ? 1 : 0;
123 pwm->enabled = enable;
127 static int write_file(
const char *path,
const char *fmt, ...)
131 int fd = open(path, O_WRONLY | O_CLOEXEC);
139 int ret = vdprintf(
fd, fmt, args);
140 int errno_bkp = errno;
152 static int read_file(
const char *path,
const char *fmt, ...)
156 FILE *file = fopen(path,
"re");
164 int ret = vfscanf(file, fmt, args);
165 int errno_bkp = errno;