atomvm_gleam/ledc

Types

Channel configuration for channel_config.

See channel_config().

pub type ChannelConfig {
  ChannelConfig(
    channel: Int,
    duty: Int,
    gpio_num: Int,
    speed_mode: SpeedMode,
    hpoint: Int,
    timer_sel: Int,
  )
}

Constructors

  • ChannelConfig(
      channel: Int,
      duty: Int,
      gpio_num: Int,
      speed_mode: SpeedMode,
      hpoint: Int,
      timer_sel: Int,
    )

Errors from the LEDC NIFs.

AtomVM returns {error, ledc_error_code()} with a numeric IDF code, or known atoms; bare error becomes Failed.

pub type Error {
  Failed
  NotSupported
  Badarg
  Timeout
  Code(Int)
  Other(String)
}

Constructors

  • Failed
  • NotSupported
  • Badarg
  • Timeout
  • Code(Int)

    ESP-IDF LEDC error code from {error, Code} when Code is an integer.

  • Other(String)

LEDC speed mode. AtomVM uses 0 for high speed and 1 for low speed.

See speed_mode().

pub type SpeedMode {
  HighSpeed
  LowSpeed
}

Constructors

  • HighSpeed
  • LowSpeed

Timer configuration for timer_config.

See timer_config().

pub type TimerConfig {
  TimerConfig(
    duty_resolution: Int,
    freq_hz: Int,
    speed_mode: SpeedMode,
    timer_num: Int,
  )
}

Constructors

  • TimerConfig(
      duty_resolution: Int,
      freq_hz: Int,
      speed_mode: SpeedMode,
      timer_num: Int,
    )

Values

pub fn channel_config(
  config: ChannelConfig,
) -> Result(Nil, Error)

Configure an LEDC channel.

See ledc:channel_config/1.

pub fn error_to_string(error: Error) -> String

Format an Error for logging.

pub fn fade_func_install(flags: Int) -> Result(Nil, Error)

Install the LEDC fade function (occupies the LEDC interrupt).

See ledc:fade_func_install/1.

pub fn fade_func_uninstall() -> Result(Nil, Error)

Uninstall the LEDC fade function.

See ledc:fade_func_uninstall/0.

pub fn fade_start(
  speed_mode: SpeedMode,
  channel: Int,
  fade_mode: Int,
) -> Result(Nil, Error)

Start a previously configured fade.

See ledc:fade_start/3.

pub fn fade_stop(
  speed_mode: SpeedMode,
  channel: Int,
) -> Result(Nil, Error)

Stop an in-progress fade (platforms with SOC_LEDC_SUPPORT_FADE_STOP only).

See ledc:fade_stop/2.

pub fn get_duty(
  speed_mode: SpeedMode,
  channel: Int,
) -> Result(Int, Error)

Read the current duty for a channel.

See ledc:get_duty/2.

pub fn get_freq(
  speed_mode: SpeedMode,
  timer_num: Int,
) -> Result(Int, Error)

Read the current timer frequency in Hz.

See ledc:get_freq/2.

pub fn high_speed_mode() -> SpeedMode

High-speed LEDC mode (0).

See speed_mode().

pub fn low_speed_mode() -> SpeedMode

Low-speed LEDC mode (1). Prefer this on ESP32-S3 backlight PWM.

See speed_mode().

pub fn set_duty(
  speed_mode: SpeedMode,
  channel: Int,
  duty: Int,
) -> Result(Nil, Error)

Set channel duty (does not apply until update_duty).

See ledc:set_duty/3.

pub fn set_duty_and_update(
  speed_mode: SpeedMode,
  channel: Int,
  duty: Int,
  hpoint: Int,
) -> Result(Nil, Error)

Set duty and hpoint and apply them immediately (thread-safe).

See ledc:set_duty_and_update/4.

pub fn set_fade_step_and_start(
  speed_mode: SpeedMode,
  channel: Int,
  target_duty: Int,
  scale: Int,
  cycle_num: Int,
  fade_mode: Int,
) -> Result(Nil, Error)

Atomically configure a step-based fade and start it.

See ledc:set_fade_step_and_start/6.

pub fn set_fade_time_and_start(
  speed_mode: SpeedMode,
  channel: Int,
  target_duty: Int,
  max_fade_time_ms: Int,
  fade_mode: Int,
) -> Result(Nil, Error)

Atomically configure a time-limited fade and start it.

See ledc:set_fade_time_and_start/5.

pub fn set_fade_with_step(
  speed_mode: SpeedMode,
  channel: Int,
  target_duty: Int,
  scale: Int,
  cycle_num: Int,
) -> Result(Nil, Error)

Configure a step-based fade. Call fade_start afterward.

See ledc:set_fade_with_step/5.

pub fn set_fade_with_time(
  speed_mode: SpeedMode,
  channel: Int,
  target_duty: Int,
  max_fade_time_ms: Int,
) -> Result(Nil, Error)

Configure a time-limited fade. Call fade_start afterward.

See ledc:set_fade_with_time/4.

pub fn set_freq(
  speed_mode: SpeedMode,
  timer_num: Int,
  freq_hz: Int,
) -> Result(Nil, Error)

Set the timer frequency in Hz.

See ledc:set_freq/3.

pub fn stop(
  speed_mode: SpeedMode,
  channel: Int,
  idle_level: Int,
) -> Result(Nil, Error)

Stop LEDC output on a channel and set the idle level.

See ledc:stop/3.

pub fn timer_config(config: TimerConfig) -> Result(Nil, Error)

Configure an LEDC timer.

See ledc:timer_config/1.

pub fn update_duty(
  speed_mode: SpeedMode,
  channel: Int,
) -> Result(Nil, Error)

Apply pending duty changes for a channel.

See ledc:update_duty/2.

✨ Search Document