Crate esp_hal_embassy

Source
Expand description

Embassy support for esp-hal.

Embassy is a modern asynchronous framework intended for use with embedded systems. This package provides support for building applications using Embassy with esp-hal.

Note that this crate currently requires you to enable the unstable feature on esp-hal.

§Executors

Two types of executors are provided:

InterruptExecutor can be used to achieve preemptive multitasking in asynchronous applications, which is typically something reserved for more traditional RTOS. More information can be found in the Embassy documentation.

§Initialization

Embassy must be initialized by calling the init function. This initialization must be performed prior to spawning any tasks.

Initialization requires a number of timers to be passed in. The number of timers required depends on the timer queue flavour used, as well as the number of executors started.

§Configuration

You can configure the behaviour of the embassy runtime by using the following environment variables:

NameDescriptionDefault valueAllowed value
ESP_HAL_EMBASSY_CONFIG_LOW_POWER_WAITEnables the lower-power wait if no tasks are ready to run on the thread-mode executor. This allows the MCU to use less power if the workload allows. Recommended for battery-powered systems. May impact analog performance.true-
ESP_HAL_EMBASSY_CONFIG_TIMER_QUEUE

The flavour of the timer queue provided by this crate. Accepts either single-integrated or generic. Integrated queues require the executors feature to be enabled.

If you use embassy-executor, the single-integrated queue is recommended.

The generic queue allows using embassy-time without the embassy executors.

single-integrated-
ESP_HAL_EMBASSY_CONFIG_GENERIC_QUEUE_SIZEThe capacity of the queue when the generic timer queue flavour is selected.64Positive integer

§Feature Flags

  • defmt — Implement defmt::Format on certain types.
  • log — Enable logging via the log crate
  • executors (enabled by default) — Provide Executor and InterruptExecutor

Structs§

Executor
Thread mode executor.
InterruptExecutor
Interrupt mode executor.

Traits§

TimerCollection
A trait to allow better UX for initializing the timers.

Functions§

init
Initialize embassy.

Attribute Macros§

main
Creates a new executor instance and declares an application entry point spawning the corresponding function body as an async task.