2.19. pwm — Pulse width modulation

Source code: src/drivers/pwm.h, src/drivers/pwm.c


Functions

int pwm_module_init(void)

Initialize the pwm module. This function must be called before calling any other function in this module.

The module will only be initialized once even if this function is called multiple times.

Return
zero(0) or negative error code.

int pwm_init(struct pwm_driver_t *self_p, struct pwm_device_t *dev_p)

Initialize given PWM driver object.

Return
zero(0) or negative error code.
Parameters
  • self_p: Driver object to be initialized.
  • dev_p: PWM device to use.

int pwm_set_duty_cycle(struct pwm_driver_t *self_p, int value)

Set the duty cycle.

Return
zero(0) or negative error code.
Parameters
  • self_p: Driver object.
  • value: Duty cycle. Use pwm_duty_cycle() to convert a duty cycle percentage to a value expected by this function.

int pwm_get_duty_cycle(struct pwm_driver_t *self_p)

Get current duty cycle.

Return
Current duty cycle.
Parameters
  • self_p: Driver object.

int pwm_duty_cycle(int percentage)

Convert a duty cycle percentage to a value for pwm_init() and pwm_set_duty_cycle().

Return
Duty cycle.
Parameters
  • percentage: Duty cycle percentage.

int pwm_duty_cycle_as_percent(int value)

Convert a duty cycle value for pwm_init() and pwm_set_duty_cycle() to a percentage.

Return
Duty cycle percentage.
Parameters
  • value: Duty cycle.

struct pwm_device_t *pwm_pin_to_device(struct pin_device_t *pin_p)

Get the PWM device for given pin.

Return
PWM device, or NULL on error.
Parameters
  • pin_p: The pin device to get the pwm device for.

Variables

struct pwm_device_t pwm_device[PWM_DEVICE_MAX]