Skip to content

File syn_pwm.c

FileList > drivers > syn_pwm.c

Go to the source code of this file

Hardware PWM driver implementation.

  • #include "../util/syn_assert.h"
  • #include "syn_pwm.h"

Public Functions

Type Name
SYN_Status syn_pwm_enable (const SYN_PWM * pwm, bool enable)
Enable or disable the PWM output.
SYN_Status syn_pwm_init (SYN_PWM * pwm, uint8_t channel, uint32_t freq_hz)
Initialize a hardware PWM channel.
SYN_Status syn_pwm_set_duty (const SYN_PWM * pwm, uint8_t duty_pct)
Set the PWM duty cycle as a percentage (0–100%).
SYN_Status syn_pwm_set_duty_raw (const SYN_PWM * pwm, uint16_t duty_u16)
Set the PWM duty cycle with 16-bit raw resolution (0–65535).
SYN_Status syn_pwm_set_freq (SYN_PWM * pwm, uint32_t freq_hz)
Change the PWM frequency at runtime.

Public Functions Documentation

function syn_pwm_enable

Enable or disable the PWM output.

SYN_Status syn_pwm_enable (
    const SYN_PWM * pwm,
    bool enable
) 

Parameters:

  • pwm Initialized PWM handle.
  • enable true to enable, false to disable.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if handle is invalid.


function syn_pwm_init

Initialize a hardware PWM channel.

SYN_Status syn_pwm_init (
    SYN_PWM * pwm,
    uint8_t channel,
    uint32_t freq_hz
) 

Parameters:

  • pwm Handle to initialize. Must not be NULL.
  • channel Platform PWM channel index.
  • freq_hz Desired PWM frequency in Hz (must be > 0).

Returns:

SYN_OK on success, SYN_INVALID_PARAM or SYN_ERROR on failure.


function syn_pwm_set_duty

Set the PWM duty cycle as a percentage (0–100%).

SYN_Status syn_pwm_set_duty (
    const SYN_PWM * pwm,
    uint8_t duty_pct
) 

Parameters:

  • pwm Initialized PWM handle.
  • duty_pct Duty cycle percentage (0 = 0%, 100 = 100%).

Returns:

SYN_OK on success, SYN_INVALID_PARAM if handle is invalid.


function syn_pwm_set_duty_raw

Set the PWM duty cycle with 16-bit raw resolution (0–65535).

SYN_Status syn_pwm_set_duty_raw (
    const SYN_PWM * pwm,
    uint16_t duty_u16
) 

Parameters:

  • pwm Initialized PWM handle.
  • duty_u16 16-bit duty value (0 = off, 65535 = 100%).

Returns:

SYN_OK on success, SYN_INVALID_PARAM if handle is invalid.


function syn_pwm_set_freq

Change the PWM frequency at runtime.

SYN_Status syn_pwm_set_freq (
    SYN_PWM * pwm,
    uint32_t freq_hz
) 

Parameters:

  • pwm Initialized PWM handle.
  • freq_hz New frequency in Hz (must be > 0).

Returns:

SYN_OK on success, SYN_INVALID_PARAM if handle is invalid.



The documentation for this class was generated from the following file src/syntropic/drivers/syn_pwm.c