38#define PWM_SYSFS_DEFAULT_PERIOD 10000000
42#define PS_DEBUG_PRINT printf
44#define PS_DEBUG_PRINT(...) {}
48static int write_file(
const char *path,
const char *fmt, ...);
73 export_path, pwm->enable_path, pwm->duty_path, pwm->period_path);
79 if (pwm->duty_cycle_fd < 0) {
81 PS_DEBUG_PRINT(
"failed to open FD cycle: %d\n", pwm->duty_cycle_fd);
152static int read_file(
const char *path,
const char *fmt, ...)
152static int read_file(
const char *path,
const char *fmt, ...) {
…}
void pwm_sysfs_set_period(struct PWM_Sysfs *pwm, uint32_t period)
#define PS_DEBUG_PRINT(...)
void pwm_sysfs_set_duty(struct PWM_Sysfs *pwm, uint32_t duty)
void pwm_sysfs_enable(struct PWM_Sysfs *pwm, bool enable)
static int read_file(const char *path, const char *fmt,...)
#define PWM_SYSFS_DEFAULT_PERIOD
static int write_file(const char *path, const char *fmt,...)
int pwm_sysfs_init(struct PWM_Sysfs *pwm, char *base_path, char *_export, char *_enable, char *_duty, char *_period, uint8_t channel)
PWM servos handling using Linux sysfs.
char enable_path[PWM_SYSFS_PATH_LEN]
path to enable file
int duty_cycle_fd
file descriptor to write/update duty cycle
uint32_t duty_cycle_nsec
current duty cycle (in nsec)
uint32_t period_nsec
current period (in nsec)
char duty_path[PWM_SYSFS_PATH_LEN]
path to duty file
char period_path[PWM_SYSFS_PATH_LEN]
path to period file
#define PWM_SYSFS_PATH_LEN
bool enabled
true if pwm is enabled
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.