Expand description
§esp-ward
esp-ward
is a Rust crate designed as a higher-level abstraction over
esp-hal
to simplify the usage of ESP32, ESP32S2, ESP32C3, ESP32C6,
ESP32S3, ESP32C2 and ESP32H2 chips with Rust. It provides common APIs, traits, and
structs to interact with various peripherals such as GPIOs, I2C, and SPI
devices.
This crate is targeted at developers new to the esp-rs
ecosystem or those
who prefer a simplified interface for common operations.
§Features
- Traits and structs for common peripheral interactions.
- Easy configuration of SPI and I2C.
- Predefined macros for common operations and setup routines.
- Compatible with various ESP32 family chips.
- Simplified Wi-Fi and MQTT features
§Usage
To use esp-ward
, include it as a dependency in your Cargo.toml
and refer
to the following examples to start interacting with your ESP device’s
hardware features.
§Quick Start
Here’s how you might initialize the system peripherals and configure I2C and SPI with default settings:
use esp_ward::{init_chip, take_periph, take_system};
let peripherals = take_periph!();
let system = take_system!(peripherals);
let (clocks, pins) = init_chip!(peripherals, system);
// Now you can use `clocks` and `pins` to interact with the peripherals
§Example: Configuring I2C
use esp_ward::init_i2c_default;
let i2c = init_i2c_default!(peripherals, pins, clocks);
// Now `i2c` is ready to communicate with I2C devices
§Example: Configuring SPI
use esp_ward::init_spi_default;
let spi = init_spi_default!(peripherals, pins, clocks);
// Now `spi` is ready to transfer data with SPI devices
§Macros
This crate also provides several macros to ease the setup and usage of ESP peripherals.
§take_periph
Takes the peripherals from the ESP board. This is typically one of the first steps in a Rust-ESP application.
§take_system
Splits the SYSTEM
peripheral into its constituent parts.
§init_chip
Initializes the system clocks and IO pins.
§init_i2c_default
and init_i2c_custom
Initializes the I2C peripheral with either default or custom configurations.
§init_spi_default
and init_spi_custom
Initializes the SPI peripheral with either default or custom configurations.
§init_wifi
Initializes Wi-Fi connection in async or non-async way - depending on your project
and more…
§Contributing
Contributions to esp-ward
are welcome. Check out the repository on GitHub
to report issues or submit pull requests.
§License
esp-ward
is distributed under the terms of both the MIT license and the
Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.
Modules§
- Connectivity Features
- Display Module
- Minimal and reusable non-blocking I/O layer
- Peripherals Module
Macros§
- Macro for creating a
Joystick
instance. - Macro to create a network stack for WiFi communication.
- Macro to retrieve the IP configuration from the network stack.
- Macro to obtain a suitable timer based on the ESP device mod
- Initializes the system clocks and IO pins, providing the base setup required for any operation with peripherals.
- Initializes a custom I2C configuration, allowing for arbitrary SDA and SCL pins and frequency.
- Initializes the default I2C configuration for the ESP board. Assumes the use of the standard I2C0 peripheral and “default” pin configuration. The rest of “default” functions
- Initializes a custom SPI configuration, allowing for arbitrary CLK, MOSI, MISO, and CS pins and frequency.
- Initializes the default SPI configuration for the chip. Assumes the use of the standard SPI2 peripheral and default pin configuration.
- Macro to initialize the WiFi interface with the given SSID and password in
mqtt
(or async) configuration. This macro configures the WiFi controller and initializes the WiFi interface. Example: - Load code to be run on the LP/ULP core.
- Create an enum for erased GPIO pins, using the enum-dispatch pattern
- Sets up a global allocator for heap memory, required for the
alloc
crate functionalities. This is essential for using heap-allocated data structures which are used, for example, formax7219
display. ATTENTION: MAKE SURE to use thisprepare_alloc
as a first function in your program if you’re using module which utilizesalloc
. Modules like this will have a warning that you should use thealloc
feature - Macro to prepare buffers with fixed sizes for MQTT communication.
- Takes the ESP peripherals. This should be one of the first steps in an ESP application, ensuring that the peripherals are properly acquired before use.
- Splits the
SYSTEM
peripheral into its constituent parts. This macro is a convenience wrapper for quickly accessing system components. - Pauses the execution for a specified number of milliseconds using a delay provider.
- Macro to wait until WiFi is connected in async variation Typically used after
net_task
async task call.
Structs§
- Frozen clock frequencies
- Full-duplex operation
- I2C peripheral container (I2C)
- General Purpose Input/Output driver
- SPI peripheral driver
Enums§
- SPI modes
Traits§
- I2C Peripheral Instance
- Trait for any type that can be used as a peripheral of type
P
. - Trait for buffers that can be given to DMA for reading.
- Trait for
Deref
targets used by the blanketDmaReadBuffer
impl. - Trait for DMA word types used by the blanket DMA buffer impls.
- Trait for buffers that can be given to DMA for writing.
- Trait for
DerefMut
targets used by the blanketDmaWriteBuffer
impl. - Input capture
- Pulse Width Modulation
- A single PWM channel / pin
- Quadrature encoder interface
- ADCs that sample on single channels per request, and do so at the time of the request.
- Millisecond delay
- Microsecond delay
- Blocking read
- Blocking write
- Blocking write + read
- Blocking read
- Write half of a serial interface (blocking variant)
- Blocking transfer
- Blocking write
- _embedded_hal_digital_InputPinDeprecatedSingle digital input pin
- _embedded_hal_digital_OutputPinDeprecatedSingle digital push-pull output pin
- Output pin that can be toggled
- Single digital input pin
- Single digital push-pull output pin
- Push-pull output pin that can read its output state
- Output pin that can be toggled
- Read half of a serial interface
- Write half of a serial interface
- Full duplex (master mode)
- A count down timer
- Feeds an existing watchdog to ensure the processor isn’t reset. Sometimes commonly referred to as “kicking” or “refreshing”.
- Disables a running watchdog timer so the processor won’t be reset.
- Enables A watchdog timer to reset the processor if software is frozen or stalled.
- Trait to be implemented for an in progress dma transfer.
- Trait to be implemented for an in progress dma transfer.
- I2C Peripheral Instance
- Channel HW interface
- Channel interface
- Interface for HW configuration of timer
- Interface for Timers
- Extension trait to split a SYSTEM/DPORT peripheral in independent logical parts
- Timer peripheral instance
- UART peripheral instance
- Pins used by the UART interface
- Extension trait for simple short-hands for u32 Durations
- Extension trait for simple short-hands for u64 Durations
- Extension trait for simple short-hands for u32 Rate
- Extension trait for simple short-hands for u64 Rate
Attribute Macros§
- Attribute to declare the entry point of the program
- Marks a function as an interrupt handler
- Creates a new
executor
instance and declares an application entry point spawning the corresponding function body as an async task. - This attribute allows placing statics and functions into ram.