atomvm_gleam/esp_dac
ESP32 digital-to-analog converter (DAC) oneshot channel APIs.
Source: libs/avm_esp32/src/esp_dac.erl.
ESP32 classic has two 8-bit DAC channels (chan_id 0 and 1). Create a
oneshot channel, write a level with oneshot_output_voltage,
then release it with oneshot_del_channel.
Types
Opaque DAC channel resource from new_channel.
Matches upstream dac_rsrc().
pub type Channel
Errors from the AtomVM ESP32 DAC NIFs.
Known reason atoms are Gleam constructors (so {error, badarg} is
Error(Badarg)). Bare AtomVM error becomes Failed. Anything else
lands in Other as a string because AtomVM types reasons as open term().
pub type Error {
Failed
NotSupported
Badarg
Timeout
Other(String)
}
Constructors
-
Failed -
NotSupported -
Badarg -
Timeout -
Other(String)
Channel creation mode for new_channel.
Upstream currently supports only oneshot.
pub type Mode {
Oneshot
}
Constructors
-
Oneshot
Options for oneshot channel creation (oneshot_channel_opts()).
chan_id must be 0 or 1.
pub type OneshotOptions {
OneshotOptions(chan_id: Int)
}
Constructors
-
OneshotOptions(chan_id: Int)
Values
pub fn new_channel(
mode: Mode,
options: OneshotOptions,
) -> Result(Channel, Error)
Allocate a DAC channel. Pass Oneshot and
OneshotOptions with chan_id 0 or 1.
pub fn oneshot_del_channel(
channel: Channel,
) -> Result(Nil, Error)
Delete a oneshot DAC channel and release its resource.
pub fn oneshot_output_voltage(
channel: Channel,
level: Int,
) -> Result(Nil, Error)
Set the oneshot output voltage level (0..255) on a channel from
new_channel.