atomvm_gleam/esp

Types

Errors from ESP NIFs and helpers.

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

Constructors

  • Failed
  • NotSupported
  • Badarg
  • Timeout
  • NotFound
  • Other(String)

Filesystem type for mount. Only fat is supported in 0.7.

pub type Filesystem {
  Fat
}

Constructors

  • Fat

Network interface for get_mac.

See interface().

pub type Interface {
  WifiSta
  WifiSoftap
}

Constructors

  • WifiSta
  • WifiSoftap

One mount option for SDMMC / SDSPI.

See mount_options().

pub type MountOption {
  Clk(Int)
  Cmd(Int)
  D0(Int)
  D1(Int)
  D2(Int)
  D3(Int)
  Width(Int)
  SpiHost(String)
  Cs(Int)
  Cd(Int)
}

Constructors

  • Clk(Int)
  • Cmd(Int)
  • D0(Int)
  • D1(Int)
  • D2(Int)
  • D3(Int)
  • Width(Int)
  • SpiHost(String)
  • Cs(Int)
  • Cd(Int)

Opaque handle for a mounted filesystem resource.

See mounted_fs().

pub type MountedFs

One flash partition from partition_list.

Upstream props are always [] in AtomVM 0.7 and are omitted here.

See esp_partition().

pub type Partition {
  Partition(
    id: BitArray,
    partition_type: Int,
    subtype: Int,
    address: Int,
    size: Int,
  )
}

Constructors

  • Partition(
      id: BitArray,
      partition_type: Int,
      subtype: Int,
      address: Int,
      size: Int,
    )

Why the chip last restarted.

See esp_reset_reason().

pub type ResetReason {
  EspRstUnknown
  EspRstPoweron
  EspRstExt
  EspRstSw
  EspRstPanic
  EspRstIntWdt
  EspRstTaskWdt
  EspRstWdt
  EspRstDeepsleep
  EspRstBrownout
  EspRstSdio
  EspRstUsb
  EspRstJtag
  EspRstEfuse
  EspRstPwrGlitch
  EspRstCpuLockup
  OtherReason(String)
}

Constructors

  • EspRstUnknown
  • EspRstPoweron
  • EspRstExt
  • EspRstSw
  • EspRstPanic
  • EspRstIntWdt
  • EspRstTaskWdt
  • EspRstWdt
  • EspRstDeepsleep
  • EspRstBrownout
  • EspRstSdio
  • EspRstUsb
  • EspRstJtag
  • EspRstEfuse
  • EspRstPwrGlitch
  • EspRstCpuLockup
  • OtherReason(String)

Task watchdog configuration: timeout (ms), idle-core mask, trigger panic.

See task_wdt_config().

pub type TaskWdtConfig {
  TaskWdtConfig(
    timeout_ms: Int,
    idle_core_mask: Int,
    trigger_panic: Bool,
  )
}

Constructors

  • TaskWdtConfig(
      timeout_ms: Int,
      idle_core_mask: Int,
      trigger_panic: Bool,
    )

Opaque handle from task_wdt_add_user.

See task_wdt_user_handle().

pub type TaskWdtUserHandle

Cause of the last wakeup from sleep.

See esp_wakeup_cause().

pub type WakeupCause {
  SleepWakeupExt0
  SleepWakeupExt1
  SleepWakeupTimer
  SleepWakeupTouchpad
  SleepWakeupUlp
  SleepWakeupGpio
  SleepWakeupUart
  SleepWakeupWifi
  SleepWakeupCocpu
  SleepWakeupCocpuTrapTrig
  SleepWakeupBt
  OtherCause(String)
}

Constructors

  • SleepWakeupExt0
  • SleepWakeupExt1
  • SleepWakeupTimer
  • SleepWakeupTouchpad
  • SleepWakeupUlp
  • SleepWakeupGpio
  • SleepWakeupUart
  • SleepWakeupWifi
  • SleepWakeupCocpu
  • SleepWakeupCocpuTrapTrig
  • SleepWakeupBt
  • OtherCause(String)

Values

pub fn deep_sleep() -> Nil

Enter deep sleep. Never returns; the program restarts on wake.

See esp:deep_sleep/0.

pub fn deep_sleep_enable_gpio_wakeup(
  mask: Int,
  mode: Int,
) -> Result(Nil, Error)

Enable GPIO deep-sleep wakeup (mask bitset, mode 0..1).

See esp:deep_sleep_enable_gpio_wakeup/2.

pub fn deep_sleep_ms(sleep_ms: Int) -> Nil

Enter deep sleep for sleep_ms milliseconds. Never returns.

See esp:deep_sleep/1.

pub fn error_to_string(error: Error) -> String

Format an Error for logging.

pub fn freq_hz() -> Result(Int, Error)

Chip clock frequency in Hz.

See esp:freq_hz/0.

pub fn get_default_mac() -> Result(BitArray, Error)

Factory-programmed default MAC address (6 bytes).

See esp:get_default_mac/0.

pub fn get_mac(interface: Interface) -> Result(BitArray, Error)

MAC address of a network interface (6 bytes).

See esp:get_mac/1.

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

Enter light sleep until a configured wake source fires.

See esp:light_sleep/0.

pub fn mount(
  source: String,
  target: String,
  filesystem: Filesystem,
  options: List(MountOption),
) -> Result(MountedFs, Error)

Mount a filesystem and return a handle for umount.

See esp:mount/4.

pub fn nvs_erase_all(namespace: String) -> Result(Nil, Error)

Erase all keys in an NVS namespace.

See esp:nvs_erase_all/1.

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

Erase all keys in the default atomvm NVS namespace (esp:nvs_erase_all/0).

See esp:nvs_erase_all/0.

pub fn nvs_erase_key(
  namespace: String,
  key: String,
) -> Result(Nil, Error)

Erase a key from NVS.

See esp:nvs_erase_key/2.

pub fn nvs_erase_key_default(key: String) -> Result(Nil, Error)

Erase a key from the default atomvm NVS namespace (esp:nvs_erase_key/1).

See esp:nvs_erase_key/1.

pub fn nvs_fetch_binary(
  namespace: String,
  key: String,
) -> Result(BitArray, Error)

Fetch a binary from NVS ({ok, Value} / {error, not_found}).

See esp:nvs_fetch_binary/2.

pub fn nvs_get_binary(
  namespace: String,
  key: String,
) -> Result(option.Option(BitArray), Error)

Read a binary from NVS, or None when the key is absent.

namespace and key are turned into Erlang atoms.

See esp:nvs_get_binary/2.

pub fn nvs_get_binary_default(
  key: String,
) -> Result(option.Option(BitArray), Error)

Read a binary from the default atomvm NVS namespace (esp:nvs_get_binary/1).

See esp:nvs_get_binary/1.

pub fn nvs_put_binary(
  namespace: String,
  key: String,
  value: BitArray,
) -> Result(Nil, Error)

Write a binary to NVS (esp:nvs_put_binary/3).

See esp:nvs_put_binary/3.

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

Reformat the entire NVS partition. Deletes all NVS data.

See esp:nvs_reformat/0.

pub fn nvs_set_binary(
  namespace: String,
  key: String,
  value: BitArray,
) -> Result(Nil, Error)

Deprecated alias of nvs_put_binary (esp:nvs_set_binary/3).

See esp:nvs_set_binary/3.

pub fn nvs_set_binary_default(
  key: String,
  value: BitArray,
) -> Result(Nil, Error)

Write a binary to the default atomvm NVS namespace (esp:nvs_set_binary/2).

See esp:nvs_set_binary/2.

pub fn partition_erase_range(
  id: BitArray,
  offset: Int,
) -> Result(Nil, Error)

Erase from offset to the end of partition id.

See esp:partition_erase_range/2.

pub fn partition_erase_range_size(
  id: BitArray,
  offset: Int,
  size: Int,
) -> Result(Nil, Error)

Erase size bytes of partition id starting at offset.

See esp:partition_erase_range/3.

pub fn partition_list() -> Result(List(Partition), Error)

List flash partitions.

See esp:partition_list/0.

pub fn partition_mmap(
  id: BitArray,
  offset: Int,
  size: Int,
) -> Result(BitArray, Error)

Memory-map size bytes of partition id at offset into RAM.

The mapping is released when all references are garbage collected.

See esp:partition_mmap/3.

pub fn partition_read(
  id: BitArray,
  offset: Int,
  size: Int,
) -> Result(BitArray, Error)

Read size bytes from partition id at offset.

See esp:partition_read/3.

pub fn partition_write(
  id: BitArray,
  offset: Int,
  data: BitArray,
) -> Result(Nil, Error)

Write data to partition id at offset.

See esp:partition_write/3.

pub fn reset_reason() -> ResetReason

Reason for the last restart.

See esp:reset_reason/0.

pub fn restart() -> Nil

Restart the ESP device. Does not return on success.

See esp:restart/0.

pub fn rtc_slow_get_binary() -> Result(BitArray, Error)

Binary currently stored in RTC slow memory.

Must only be called after a successful rtc_slow_set_binary.

See esp:rtc_slow_get_binary/0.

pub fn rtc_slow_set_binary(bin: BitArray) -> Result(Nil, Error)

Store a binary in RTC slow memory (survives reset and deep sleep).

See esp:rtc_slow_set_binary/1.

pub fn sleep_disable_ext1_wakeup_io(
  mask: Int,
) -> Result(Nil, Error)

Disable previously configured ext1 wakeup IOs (mask bitset).

See esp:sleep_disable_ext1_wakeup_io/1.

pub fn sleep_enable_ext0_wakeup(
  pin: Int,
  level: Int,
) -> Result(Nil, Error)

Enable ext0 deep-sleep wakeup on pin at level (0 or 1).

See esp:sleep_enable_ext0_wakeup/2.

pub fn sleep_enable_ext1_wakeup(
  mask: Int,
  mode: Int,
) -> Result(Nil, Error)

Enable ext1 deep-sleep wakeup (mask bitset, mode 0..3).

Prefer sleep_enable_ext1_wakeup_io on newer ESP-IDF.

See esp:sleep_enable_ext1_wakeup/2.

pub fn sleep_enable_ext1_wakeup_io(
  mask: Int,
  mode: Int,
) -> Result(Nil, Error)

Enable ext1 deep-sleep wakeup IOs (mask bitset, mode 0..3).

See esp:sleep_enable_ext1_wakeup_io/2.

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

Enable GPIO wake from light sleep (after gpio:wakeup_enable/2).

See esp:sleep_enable_gpio_wakeup/0.

pub fn sleep_enable_timer_wakeup(
  sleep_us: Int,
) -> Result(Nil, Error)

Enable timer wakeup from light sleep after sleep_us microseconds.

See esp:sleep_enable_timer_wakeup/1.

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

Enable ULP wakeup from deep sleep.

See esp:sleep_enable_ulp_wakeup/0.

pub fn sleep_get_wakeup_cause() -> Result(
  option.Option(WakeupCause),
  Error,
)

Cause of the last wakeup, or None when undefined.

See esp:sleep_get_wakeup_cause/0.

pub fn task_wdt_add_user(
  username: String,
) -> Result(TaskWdtUserHandle, Error)

Register a task watchdog user; returns a handle for reset/delete.

See esp:task_wdt_add_user/1.

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

Deinitialize the task watchdog timer.

See esp:task_wdt_deinit/0.

pub fn task_wdt_delete_user(
  handle: TaskWdtUserHandle,
) -> Result(Nil, Error)

Unsubscribe a watchdog user.

See esp:task_wdt_delete_user/1.

pub fn task_wdt_init(config: TaskWdtConfig) -> Result(Nil, Error)

Initialize the task watchdog timer.

See esp:task_wdt_init/1.

pub fn task_wdt_reconfigure(
  config: TaskWdtConfig,
) -> Result(Nil, Error)

Update the task watchdog timer configuration.

See esp:task_wdt_reconfigure/1.

pub fn task_wdt_reset_user(
  handle: TaskWdtUserHandle,
) -> Result(Nil, Error)

Reset the timer for a previously registered watchdog user.

See esp:task_wdt_reset_user/1.

pub fn timer_get_time() -> Result(Int, Error)

Microseconds since boot or wakeup from deep sleep.

See esp:timer_get_time/0.

pub fn umount(mounted: MountedFs) -> Result(Nil, Error)

Unmount a filesystem previously returned by mount.

See esp:umount/1.

✨ Search Document