Crate macros

Source
Expand description

§Overview

Procedural macros for use with the esp-hal family of HAL packages. In general, you should not need to depend on this package directly, as the relevant procmacros are re-exported by the various HAL packages.

Provides macros for:

  • Placing statics and functions into RAM
  • Marking interrupt handlers
  • Automatically creating an embassy executor instance and spawning the defined entry point

These macros offer developers a convenient way to control memory placement and define interrupt handlers in their embedded applications, allowing for optimized memory usage and precise handling of hardware interrupts.

Key Components:

  • interrupt - Attribute macro for marking interrupt handlers. Interrupt handlers are used to handle specific hardware interrupts generated by peripherals.
    The macro allows users to specify the interrupt name explicitly or use the function name to match the interrupt.
  • main - Creates a new `executor`` instance and declares an application entry point spawning the corresponding function body as an async task.
  • ram - Attribute macro for placing statics and functions into specific memory sections, such as SRAM or RTC RAM (slow or fast) with different initialization options. Supported options are:
    • rtc_fast - Use RTC fast RAM
    • rtc_slow - Use RTC slow RAM (not all targets support slow RTC RAM)
    • uninitialized - Skip initialization of the memory
    • zeroed - Initialize the memory to zero

§Examples

§interrupt macro

Requires the interrupt feature to be enabled.

#[interrupt]
fn INTR_NAME() {
    // Interrupt handling code here
}
§main macro

Requires the embassy feature to be enabled.

#[main]
async fn main(spawner: Spawner) {
    // Your application's entry point
}
§ram macro

Requires the ram feature to be enabled.

#[ram(rtc_fast)]
static mut SOME_INITED_DATA: [u8; 2] = [0xaa, 0xbb];

#[ram(rtc_fast, uninitialized)]
static mut SOME_UNINITED_DATA: [u8; 2] = [0; 2];

#[ram(rtc_fast, zeroed)]
static mut SOME_ZEROED_DATA: [u8; 8] = [0; 8];

Macros§

load_lp_code
Load code to be run on the LP/ULP core.
make_gpio_enum_dispatch_macro
Create an enum for erased GPIO pins, using the enum-dispatch pattern

Attribute Macros§

interrupt
Marks a function as an interrupt handler
ram
This attribute allows placing statics and functions into ram.