picofuse

pwm.h
Go to the documentation of this file.
1 
45 #pragma once
46 #include "gpio.h"
47 #include <stdbool.h>
48 #include <stdint.h>
49 
51 // TYPES
52 
58 typedef struct hw_pwm_t hw_pwm_t;
59 
66 typedef struct {
67  uint64_t period_ns;
68  float duty_percent;
69  bool enabled;
71 
80 typedef void (*hw_pwm_callback_t)(hw_pwm_t *pwm, void *userdata);
81 
83 // LIFECYCLE
84 
100  void *userdata, const hw_pwm_config_t *config);
101 
118 hw_pwm_t *hw_pwm_init_device(const char *device, uint8_t channel,
119  const hw_pwm_config_t *config);
120 
126 void hw_pwm_deinit(hw_pwm_t *pwm);
127 
130 // CONFIGURATION
132 
144 bool hw_pwm_set_period_ns(hw_pwm_t *pwm, uint64_t period_ns);
145 
152 uint64_t hw_pwm_get_period_ns(const hw_pwm_t *pwm);
153 
163 bool hw_pwm_set_duty_percent(hw_pwm_t *pwm, float duty_percent);
164 
171 float hw_pwm_get_duty_percent(const hw_pwm_t *pwm);
172 
181 bool hw_pwm_set_config(hw_pwm_t *pwm, const hw_pwm_config_t *config);
182 
191 bool hw_pwm_get_config(const hw_pwm_t *pwm, hw_pwm_config_t *out_config);
192 
195 // CONTROL
197 
207 void hw_pwm_set_enabled(hw_pwm_t *pwm, bool enabled);
208 
216 bool hw_pwm_get_enabled(const hw_pwm_t *pwm);
217 
220 // INTERRUPTS
222 
232 bool hw_pwm_irq_supported(void);
233 
struct hw_pwm_t hw_pwm_t
Opaque PWM handle.
Definition: pwm.h:58
struct hw_gpio_t hw_gpio_t
GPIO logical pin structure.
Definition: gpio.h:50
float duty_percent
Requested duty cycle percentage in [0.0, 100.0].
Definition: pwm.h:68
GPIO (General Purpose Input/Output) interface.
uint64_t hw_pwm_get_period_ns(const hw_pwm_t *pwm)
Get the configured PWM period.
bool hw_pwm_get_config(const hw_pwm_t *pwm, hw_pwm_config_t *out_config)
Read current PWM configuration.
PWM configuration.
Definition: pwm.h:66
hw_pwm_t * hw_pwm_init_device(const char *device, uint8_t channel, const hw_pwm_config_t *config)
Initialize a PWM output from a platform-specific device path.
bool hw_pwm_get_enabled(const hw_pwm_t *pwm)
Query whether PWM output is enabled.
float hw_pwm_get_duty_percent(const hw_pwm_t *pwm)
Get duty cycle percentage.
void hw_pwm_set_enabled(hw_pwm_t *pwm, bool enabled)
Enable or disable PWM output.
void hw_pwm_deinit(hw_pwm_t *pwm)
Deinitialize a PWM handle.
bool hw_pwm_set_period_ns(hw_pwm_t *pwm, uint64_t period_ns)
Set the PWM period.
void(* hw_pwm_callback_t)(hw_pwm_t *pwm, void *userdata)
PWM wrap callback function pointer.
Definition: pwm.h:80
bool hw_pwm_irq_supported(void)
Check whether PWM wrap interrupt callbacks are supported.
hw_pwm_t * hw_pwm_init(hw_gpio_t *gpio, hw_pwm_callback_t callback, void *userdata, const hw_pwm_config_t *config)
Initialize a PWM output on a GPIO pin.
uint64_t period_ns
Requested PWM period in nanoseconds.
Definition: pwm.h:67
bool hw_pwm_set_config(hw_pwm_t *pwm, const hw_pwm_config_t *config)
Apply a complete PWM configuration.
bool enabled
Initial output enable state.
Definition: pwm.h:69
bool hw_pwm_set_duty_percent(hw_pwm_t *pwm, float duty_percent)
Set duty cycle percentage.