### Espressif ESP32 HAL Project Setup Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32/esp_hal/index Provides instructions on how to get started with the esp-hal project examples. It guides users to invoke `cargo xtask help` in the repository root to automate building, running, and testing code and examples. ```rust cargo xtask help ``` -------------------------------- ### ESP-HAL Project Setup and Examples (esp-hal) Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32h2/esp_hal/index Provides instructions on how to get started with ESP-HAL examples using the `cargo-xtask` tool. This includes commands for building, running, and testing code within the esp-hal repository. ```bash cargo xtask help ``` -------------------------------- ### Espressif ESP-HAL Project Examples Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c6/esp_hal/index Instructions on how to access and utilize the examples provided within the esp-hal repository. It guides users to the `cargo xtask` tool for building, running, and testing examples. ```bash cargo xtask help ``` -------------------------------- ### General-purpose Timer Example (Rust) Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c3/esp_hal/timer/timg/index Demonstrates how to use a general-purpose timer from the Timer Group. It shows how to get the current timestamp, load a value, start the timer, wait for an interrupt, and clear it. Requires the `esp-hal` crate and specific timer peripherals. ```rust use esp_hal::timer::{Timer, timg::TimerGroup}; let timg0 = TimerGroup::new(peripherals.TIMG0); let timer0 = timg0.timer0; // Get the current timestamp, in microseconds: let now = timer0.now(); // Wait for timeout: timer0.load_value(Duration::from_secs(1)); timer0.start(); while !timer0.is_interrupt_set() { // Wait } timer0.clear_interrupt(); ``` -------------------------------- ### General-purpose Timer Example (Rust) Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c2/esp_hal/timer/timg/index Demonstrates how to use a general-purpose timer from the Timer Group. It shows how to get the current timestamp, load a value, start the timer, wait for an interrupt, and clear it. Requires the `esp-hal` crate and specific timer peripherals. ```rust use esp_hal::timer::{Timer, timg::TimerGroup}; let timg0 = TimerGroup::new(peripherals.TIMG0); let timer0 = timg0.timer0; // Get the current timestamp, in microseconds: let now = timer0.now(); // Wait for timeout: timer0.load_value(Duration::from_secs(1)); timer0.start(); while !timer0.is_interrupt_set() { // Wait } timer0.clear_interrupt(); ``` -------------------------------- ### UlpCore Methods Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32s2/esp_hal/ulp_core/struct.UlpCore Provides methods for interacting with the ULP core. Includes creating a new instance and running the core with a specified wakeup source. ```rust impl<'d> UlpCore<'d> { /// Creates a new instance of the `UlpCore` struct. pub fn new(lp_core: ULP_RISCV_CORE<'d>) -> Self /// Runs the ULP core with the specified wakeup source. pub fn run(&mut self, wakeup_src: UlpCoreWakeupSource) } ``` -------------------------------- ### Project Generation Tool Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c6/src/esp_hal/lib.rs Instructions on how to install and use the `esp-generate` tool to create new projects for Espressif devices. This tool simplifies the setup process for new embedded Rust projects. ```bash cargo install esp-generate esp-generate --chip=esp32c6 your-project ``` -------------------------------- ### Rust Slice get Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32s3/esp_hal/dma/struct.DmaLoopBuf Demonstrates the `get` method for safely accessing elements or subslices by index. It shows retrieving a single element, a range, and handling out-of-bounds access by returning None. ```Rust let v = [10, 40, 30]; assert_eq!(Some(&40), v.get(1)); assert_eq!(Some(&[10, 40][..]), v.get(0..2)); assert_eq!(None, v.get(3)); assert_eq!(None, v.get(0..4)); ``` -------------------------------- ### Project Generation Tool Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c2/src/esp_hal/lib.rs Instructions on how to install and use the `esp-generate` tool to create new projects for Espressif devices. This tool simplifies the setup process for new embedded Rust projects. ```bash cargo install esp-generate esp-generate --chip=esp32c6 your-project ``` -------------------------------- ### Project Generation Tool Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c3/src/esp_hal/lib.rs Instructions on how to install and use the `esp-generate` tool to create new projects for Espressif devices. This tool simplifies the setup process for new embedded Rust projects. ```bash cargo install esp-generate esp-generate --chip=esp32c6 your-project ``` -------------------------------- ### Rust Slice get Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32s2/esp_hal/dma/struct.DmaLoopBuf Demonstrates the `get` method for safely accessing elements or subslices by index. It shows retrieving a single element, a range, and handling out-of-bounds access by returning None. ```Rust let v = [10, 40, 30]; assert_eq!(Some(&40), v.get(1)); assert_eq!(Some(&[10, 40][..]), v.get(0..2)); assert_eq!(None, v.get(3)); assert_eq!(None, v.get(0..4)); ``` -------------------------------- ### Project Generation Tool Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32s3/src/esp_hal/lib.rs Instructions on how to install and use the `esp-generate` tool to create new projects for Espressif devices. This tool simplifies the setup process for new embedded Rust projects. ```bash cargo install esp-generate esp-generate --chip=esp32c6 your-project ``` -------------------------------- ### Rust Slice get Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32h2/esp_hal/dma/struct.DmaLoopBuf Demonstrates the `get` method for safely accessing elements or subslices by index. It shows retrieving a single element, a range, and handling out-of-bounds access by returning None. ```Rust let v = [10, 40, 30]; assert_eq!(Some(&40), v.get(1)); assert_eq!(Some(&[10, 40][..]), v.get(0..2)); assert_eq!(None, v.get(3)); assert_eq!(None, v.get(0..4)); ``` -------------------------------- ### Project Generation Tool Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32s2/src/esp_hal/lib.rs Instructions on how to install and use the `esp-generate` tool to create new projects for Espressif devices. This tool simplifies the setup process for new embedded Rust projects. ```bash cargo install esp-generate esp-generate --chip=esp32c6 your-project ``` -------------------------------- ### Rust Slice get Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c6/esp_hal/dma/struct.DmaLoopBuf Demonstrates the `get` method for safely accessing elements or subslices by index. It shows retrieving a single element, a range, and handling out-of-bounds access by returning None. ```Rust let v = [10, 40, 30]; assert_eq!(Some(&40), v.get(1)); assert_eq!(Some(&[10, 40][..]), v.get(0..2)); assert_eq!(None, v.get(3)); assert_eq!(None, v.get(0..4)); ``` -------------------------------- ### Project Generation Tool Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32h2/src/esp_hal/lib.rs Instructions on how to install and use the `esp-generate` tool to create new projects for Espressif devices. This tool simplifies the setup process for new embedded Rust projects. ```bash cargo install esp-generate esp-generate --chip=esp32c6 your-project ``` -------------------------------- ### Rust Slice get Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c3/esp_hal/dma/struct.DmaLoopBuf Demonstrates the `get` method for safely accessing elements or subslices by index. It shows retrieving a single element, a range, and handling out-of-bounds access by returning None. ```Rust let v = [10, 40, 30]; assert_eq!(Some(&40), v.get(1)); assert_eq!(Some(&[10, 40][..]), v.get(0..2)); assert_eq!(None, v.get(3)); assert_eq!(None, v.get(0..4)); ``` -------------------------------- ### Rust Slice get Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c2/esp_hal/dma/struct.DmaLoopBuf Demonstrates the `get` method for safely accessing elements or subslices by index. It shows retrieving a single element, a range, and handling out-of-bounds access by returning None. ```Rust let v = [10, 40, 30]; assert_eq!(Some(&40), v.get(1)); assert_eq!(Some(&[10, 40][..]), v.get(0..2)); assert_eq!(None, v.get(3)); assert_eq!(None, v.get(0..4)); ``` -------------------------------- ### Project Generation Tool Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32/src/esp_hal/lib.rs Instructions on how to install and use the `esp-generate` tool to create new projects for Espressif devices. This tool simplifies the setup process for new embedded Rust projects. ```bash cargo install esp-generate esp-generate --chip=esp32c6 your-project ``` -------------------------------- ### Install and Use esp-generate Tool Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c6/esp_hal/index Instructions for installing the `esp-generate` tool and using it to create a new ESP-RS project for a specific chip, like the ESP32-C6. ```bash cargo install esp-generate esp-generate --chip=esp32c6 your-project ``` -------------------------------- ### Rust Slice get Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32/esp_hal/dma/struct.DmaLoopBuf Demonstrates the `get` method for safely accessing elements or subslices by index. It shows retrieving a single element, a range, and handling out-of-bounds access by returning None. ```Rust let v = [10, 40, 30]; assert_eq!(Some(&40), v.get(1)); assert_eq!(Some(&[10, 40][..]), v.get(0..2)); assert_eq!(None, v.get(3)); assert_eq!(None, v.get(0..4)); ``` -------------------------------- ### Functions Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32/esp_hal/index Core system initialization function. ```APIDOC fn init Description: Initialize the system. Attributes: rt ``` -------------------------------- ### Rust CPU Control Example: Start APP Core Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32/src/esp_hal/soc/esp32/cpu_control.rs Demonstrates how to start the APP (second) CPU core using `CpuControl`. It shows initializing a stack, defining a task for the second core, and starting it. The returned `AppCoreGuard` manages the core's lifecycle. ```rust /// Control CPU Cores /// /// ## Examples /// ```rust, no_run /// # {before_snippet} /// # use esp_hal::delay::Delay; /// # use esp_hal::system::{CpuControl, Stack}; /// # use core::{cell::RefCell, ptr::addr_of_mut}; /// # use critical_section::Mutex; /// # let delay = Delay::new(); /// static mut APP_CORE_STACK: Stack<8192> = Stack::new(); /// /// let counter = Mutex::new(RefCell::new(0)); /// /// let mut cpu_control = CpuControl::new(peripherals.CPU_CTRL); /// let cpu1_fnctn = || { /// cpu1_task(&delay, &counter); /// }; /// let _guard = /// cpu_control.start_app_core(unsafe { &mut *addr_of_mut!(APP_CORE_STACK) }, cpu1_fnctn)?; /// /// loop { /// delay.delay(Duration::from_secs(1)); /// let count = critical_section::with(|cs| *counter.borrow_ref(cs)); /// } /// # } /// /// // Where `cpu1_task()` may be defined as: /// # use esp_hal::delay::Delay; /// # use core::cell::RefCell; /// /// fn cpu1_task(delay: &Delay, counter: &critical_section::Mutex>) -> ! { /// loop { /// delay.delay(Duration::from_millis(500)); /// /// critical_section::with(|cs| { /// let mut val = counter.borrow_ref_mut(cs); /// *val = val.wrapping_add(1); /// }); /// } /// } /// ``` ``` -------------------------------- ### Rust chip macro usage example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c6/esp_hal/macro.chip Demonstrates how to use the `chip!` macro to get the current chip name and assert its value. This example assumes the target chip is ESP32-C6. ```rust use esp_hal::chip; let chip_name = chip!(); assert_eq!(chip_name, esp32c6) ``` -------------------------------- ### Install and Use esp-generate Tool Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32h2/esp_hal/index Instructions for installing the `esp-generate` tool and using it to create a new ESP-RS project for a specific chip, like the ESP32-C6. ```bash cargo install esp-generate esp-generate --chip=esp32c6 your-project ``` -------------------------------- ### RtcioWakeupSource Usage Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c3/esp_hal/rtc_cntl/sleep/struct.RtcioWakeupSource Example demonstrating how to initialize an Rtc controller, get wake reasons, create a TimerWakeupSource and an RtcioWakeupSource with specific pins and wakeup levels, and then put the chip into deep sleep. ```rust let mut rtc = Rtc::new(peripherals.LPWR); let reason = reset_reason(Cpu::ProCpu); let wake_reason = wakeup_cause(); println!("{:?} {{}}", reason, wake_reason); let delay = Delay::new(); let timer = TimerWakeupSource::new(Duration::from_secs(10)); let mut pin_0 = peripherals.GPIO2; let mut pin_1 = peripherals.GPIO3; let wakeup_pins: &mut [(&mut dyn gpio::RtcPinWithResistors, WakeupLevel)] = &mut [(&mut pin_0, WakeupLevel::Low),(&mut pin_1, WakeupLevel::High)]; let rtcio = RtcioWakeupSource::new(wakeup_pins); delay.delay_millis(100); rtc.sleep_deep(&[&timer, &rtcio]); ``` -------------------------------- ### Functions Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32h2/esp_hal/index Core system initialization function. ```APIDOC fn init Description: Initialize the system. Attributes: rt ``` -------------------------------- ### Periodic Timer Example (Rust) Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32s3/esp_hal/timer/index Illustrates the usage of a periodic timer for recurring events. This example shows how to start a periodic timer and wait for its next tick, using TimerGroup and PeriodicTimer. ```rust let timg0 = TimerGroup::new(peripherals.TIMG0); let mut periodic = PeriodicTimer::new(timg0.timer0); periodic.start(Duration::from_secs(1)); loop { periodic.wait(); } ``` -------------------------------- ### I2c Master Initialization and Usage Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32s3/esp_hal/i2c/master/struct.I2c Demonstrates how to initialize an I2C master instance using the esp-hal library. It shows setting up the I2C peripheral, configuring SDA and SCL pins, and performing a write-read transaction. ```rust use esp_hal::i2c::master::{Config, I2c}; let mut i2c = I2c::new(peripherals.I2C0, Config::default())? .with_sda(peripherals.GPIO1) .with_scl(peripherals.GPIO2); let mut data = [0u8; 22]; i2c.write_read(DEVICE_ADDR, &[0xaa], &mut data)?; ``` -------------------------------- ### Periodic Timer Example (Rust) Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32s2/esp_hal/timer/index Illustrates the usage of a periodic timer for recurring events. This example shows how to start a periodic timer and wait for its next tick, using TimerGroup and PeriodicTimer. ```rust let timg0 = TimerGroup::new(peripherals.TIMG0); let mut periodic = PeriodicTimer::new(timg0.timer0); periodic.start(Duration::from_secs(1)); loop { periodic.wait(); } ``` -------------------------------- ### I2c Master Initialization and Usage Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c6/esp_hal/i2c/master/struct.I2c Demonstrates how to initialize an I2C master instance using the esp-hal library. It shows setting up the I2C peripheral, configuring SDA and SCL pins, and performing a write-read transaction. ```rust use esp_hal::i2c::master::{Config, I2c}; let mut i2c = I2c::new(peripherals.I2C0, Config::default())? .with_sda(peripherals.GPIO1) .with_scl(peripherals.GPIO2); let mut data = [0u8; 22]; i2c.write_read(DEVICE_ADDR, &[0xaa], &mut data)?; ``` -------------------------------- ### Periodic Timer Example (Rust) Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32h2/esp_hal/timer/index Illustrates the usage of a periodic timer for recurring events. This example shows how to start a periodic timer and wait for its next tick, using TimerGroup and PeriodicTimer. ```rust let timg0 = TimerGroup::new(peripherals.TIMG0); let mut periodic = PeriodicTimer::new(timg0.timer0); periodic.start(Duration::from_secs(1)); loop { periodic.wait(); } ``` -------------------------------- ### I2c Master Initialization and Usage Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32s2/esp_hal/i2c/master/struct.I2c Demonstrates how to initialize an I2C master instance using the esp-hal library. It shows setting up the I2C peripheral, configuring SDA and SCL pins, and performing a write-read transaction. ```rust use esp_hal::i2c::master::{Config, I2c}; let mut i2c = I2c::new(peripherals.I2C0, Config::default())? .with_sda(peripherals.GPIO1) .with_scl(peripherals.GPIO2); let mut data = [0u8; 22]; i2c.write_read(DEVICE_ADDR, &[0xaa], &mut data)?; ``` -------------------------------- ### Periodic Timer Example (Rust) Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c6/esp_hal/timer/index Illustrates the usage of a periodic timer for recurring events. This example shows how to start a periodic timer and wait for its next tick, using TimerGroup and PeriodicTimer. ```rust let timg0 = TimerGroup::new(peripherals.TIMG0); let mut periodic = PeriodicTimer::new(timg0.timer0); periodic.start(Duration::from_secs(1)); loop { periodic.wait(); } ``` -------------------------------- ### I2c Master Initialization and Usage Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32h2/esp_hal/i2c/master/struct.I2c Demonstrates how to initialize an I2C master instance using the esp-hal library. It shows setting up the I2C peripheral, configuring SDA and SCL pins, and performing a write-read transaction. ```rust use esp_hal::i2c::master::{Config, I2c}; let mut i2c = I2c::new(peripherals.I2C0, Config::default())? .with_sda(peripherals.GPIO1) .with_scl(peripherals.GPIO2); let mut data = [0u8; 22]; i2c.write_read(DEVICE_ADDR, &[0xaa], &mut data)?; ``` -------------------------------- ### Periodic Timer Example (Rust) Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c3/esp_hal/timer/index Illustrates the usage of a periodic timer for recurring events. This example shows how to start a periodic timer and wait for its next tick, using TimerGroup and PeriodicTimer. ```rust let timg0 = TimerGroup::new(peripherals.TIMG0); let mut periodic = PeriodicTimer::new(timg0.timer0); periodic.start(Duration::from_secs(1)); loop { periodic.wait(); } ``` -------------------------------- ### I2c Master Initialization and Usage Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c3/esp_hal/i2c/master/struct.I2c Demonstrates how to initialize an I2C master instance using the esp-hal library. It shows setting up the I2C peripheral, configuring SDA and SCL pins, and performing a write-read transaction. ```rust use esp_hal::i2c::master::{Config, I2c}; let mut i2c = I2c::new(peripherals.I2C0, Config::default())? .with_sda(peripherals.GPIO1) .with_scl(peripherals.GPIO2); let mut data = [0u8; 22]; i2c.write_read(DEVICE_ADDR, &[0xaa], &mut data)?; ``` -------------------------------- ### I2c Master Initialization and Usage Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c2/esp_hal/i2c/master/struct.I2c Demonstrates how to initialize an I2C master instance using the esp-hal library. It shows setting up the I2C peripheral, configuring SDA and SCL pins, and performing a write-read transaction. ```rust use esp_hal::i2c::master::{Config, I2c}; let mut i2c = I2c::new(peripherals.I2C0, Config::default())? .with_sda(peripherals.GPIO1) .with_scl(peripherals.GPIO2); let mut data = [0u8; 22]; i2c.write_read(DEVICE_ADDR, &[0xaa], &mut data)?; ``` -------------------------------- ### Periodic Timer Example (Rust) Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c2/esp_hal/timer/index Illustrates the usage of a periodic timer for recurring events. This example shows how to start a periodic timer and wait for its next tick, using TimerGroup and PeriodicTimer. ```rust let timg0 = TimerGroup::new(peripherals.TIMG0); let mut periodic = PeriodicTimer::new(timg0.timer0); periodic.start(Duration::from_secs(1)); loop { periodic.wait(); } ``` -------------------------------- ### SpiDma DMA Buffer Setup Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32s3/esp_hal/spi/master/struct.SpiDma Demonstrates how to set up SpiDma with DMA buffers for SPI communication. This example shows the initialization of DMA buffers and configuring the SPI peripheral for DMA transfers. ```rust use esp_hal::{ dma::{DmaRxBuf, DmaTxBuf}, dma_buffers, spi::{ Mode, master::Config, }, }; let dma_channel = peripherals.DMA_CH0; let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) = dma_buffers!(32000); let dma_rx_buf = DmaRxBuf::new(rx_descriptors, rx_buffer)?; let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer)?; let mut spi = Spi::new( peripherals.SPI2, Config::default() .with_frequency(Rate::from_khz(100)) .with_mode(Mode::_0), )? .with_dma(dma_channel) .with_buffers(dma_rx_buf, dma_tx_buf); ``` -------------------------------- ### Install and Run esp-generate Tool Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32s2/esp_hal/index Installs the esp-generate command-line tool and demonstrates its usage to create a new Rust project for a specified ESP32 chip, such as the ESP32-C6. ```shell cargo install esp-generate esp-generate --chip=esp32c6 your-project ``` -------------------------------- ### I2c Master Initialization and Usage Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32/esp_hal/i2c/master/struct.I2c Demonstrates how to initialize an I2C master instance using the esp-hal library. It shows setting up the I2C peripheral, configuring SDA and SCL pins, and performing a write-read transaction. ```rust use esp_hal::i2c::master::{Config, I2c}; let mut i2c = I2c::new(peripherals.I2C0, Config::default())? .with_sda(peripherals.GPIO1) .with_scl(peripherals.GPIO2); let mut data = [0u8; 22]; i2c.write_read(DEVICE_ADDR, &[0xaa], &mut data)?; ``` -------------------------------- ### SpiDma DMA Buffer Setup Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32h2/esp_hal/spi/master/struct.SpiDma Demonstrates how to set up SpiDma with DMA buffers for SPI communication. This example shows the initialization of DMA buffers and configuring the SPI peripheral for DMA transfers. ```rust use esp_hal::{ dma::{DmaRxBuf, DmaTxBuf}, dma_buffers, spi::{ Mode, master::Config, }, }; let dma_channel = peripherals.DMA_CH0; let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) = dma_buffers!(32000); let dma_rx_buf = DmaRxBuf::new(rx_descriptors, rx_buffer)?; let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer)?; let mut spi = Spi::new( peripherals.SPI2, Config::default() .with_frequency(Rate::from_khz(100)) .with_mode(Mode::_0), )? .with_dma(dma_channel) .with_buffers(dma_rx_buf, dma_tx_buf); ``` -------------------------------- ### Io Initialization and Configuration Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c6/esp_hal/gpio/struct.Io Provides API documentation for initializing the Io driver and configuring GPIO interrupts. Includes methods for creating a new Io instance and setting interrupt priorities and handlers. ```APIDOC Io::new pub fn new(_io_mux: IO_MUX<'d>) -> Self Initializes the I/O driver. Parameters: _io_mux: The IO_MUX peripheral instance required for initialization. Returns: A new instance of the Io driver. Stability: This API is marked as unstable and requires the 'unstable' crate feature. Io::set_interrupt_priority pub fn set_interrupt_priority(&self, prio: Priority) Set the interrupt priority for GPIO interrupts. Parameters: prio: The desired interrupt priority level. Panics: Panics if passed interrupt handler is invalid (e.g. has priority None). Stability: This API is marked as unstable and requires the 'unstable' crate feature. Io::set_interrupt_handler pub fn set_interrupt_handler(&mut self, handler: InterruptHandler) Registers an interrupt handler for all GPIO pins. Note: When using interrupt handlers registered by this function, or by defining a #[no_mangle] unsafe extern "C" fn GPIO() function, the interrupt status register and the interrupt enable setting are not cleared automatically. Users must manage clearing the status or disabling the interrupt enable setting based on their use case. Parameters: handler: The InterruptHandler to register for GPIO interrupts. Panics: Panics if passed interrupt handler is invalid (e.g. has priority None). Stability: This API is marked as unstable and requires the 'unstable' crate feature. ``` -------------------------------- ### SpiDma DMA Buffer Setup Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c6/esp_hal/spi/master/struct.SpiDma Demonstrates how to set up SpiDma with DMA buffers for SPI communication. This example shows the initialization of DMA buffers and configuring the SPI peripheral for DMA transfers. ```rust use esp_hal::{ dma::{DmaRxBuf, DmaTxBuf}, dma_buffers, spi::{ Mode, master::Config, }, }; let dma_channel = peripherals.DMA_CH0; let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) = dma_buffers!(32000); let dma_rx_buf = DmaRxBuf::new(rx_descriptors, rx_buffer)?; let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer)?; let mut spi = Spi::new( peripherals.SPI2, Config::default() .with_frequency(Rate::from_khz(100)) .with_mode(Mode::_0), )? .with_dma(dma_channel) .with_buffers(dma_rx_buf, dma_tx_buf); ``` -------------------------------- ### SpiDma DMA Buffer Setup Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c3/esp_hal/spi/master/struct.SpiDma Demonstrates how to set up SpiDma with DMA buffers for SPI communication. This example shows the initialization of DMA buffers and configuring the SPI peripheral for DMA transfers. ```rust use esp_hal::{ dma::{DmaRxBuf, DmaTxBuf}, dma_buffers, spi::{ Mode, master::Config, }, }; let dma_channel = peripherals.DMA_CH0; let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) = dma_buffers!(32000); let dma_rx_buf = DmaRxBuf::new(rx_descriptors, rx_buffer)?; let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer)?; let mut spi = Spi::new( peripherals.SPI2, Config::default() .with_frequency(Rate::from_khz(100)) .with_mode(Mode::_0), )? .with_dma(dma_channel) .with_buffers(dma_rx_buf, dma_tx_buf); ``` -------------------------------- ### Io Initialization and Configuration Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c3/esp_hal/gpio/struct.Io Provides API documentation for initializing the Io driver and configuring GPIO interrupts. Includes methods for creating a new Io instance and setting interrupt priorities and handlers. ```APIDOC Io::new pub fn new(_io_mux: IO_MUX<'d>) -> Self Initializes the I/O driver. Parameters: _io_mux: The IO_MUX peripheral instance required for initialization. Returns: A new instance of the Io driver. Stability: This API is marked as unstable and requires the 'unstable' crate feature. Io::set_interrupt_priority pub fn set_interrupt_priority(&self, prio: Priority) Set the interrupt priority for GPIO interrupts. Parameters: prio: The desired interrupt priority level. Panics: Panics if passed interrupt handler is invalid (e.g. has priority None). Stability: This API is marked as unstable and requires the 'unstable' crate feature. Io::set_interrupt_handler pub fn set_interrupt_handler(&mut self, handler: InterruptHandler) Registers an interrupt handler for all GPIO pins. Note: When using interrupt handlers registered by this function, or by defining a #[no_mangle] unsafe extern "C" fn GPIO() function, the interrupt status register and the interrupt enable setting are not cleared automatically. Users must manage clearing the status or disabling the interrupt enable setting based on their use case. Parameters: handler: The InterruptHandler to register for GPIO interrupts. Panics: Panics if passed interrupt handler is invalid (e.g. has priority None). Stability: This API is marked as unstable and requires the 'unstable' crate feature. ``` -------------------------------- ### Io Initialization and Configuration Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32s2/esp_hal/gpio/struct.Io Provides API documentation for initializing the Io driver and configuring GPIO interrupts. Includes methods for creating a new Io instance and setting interrupt priorities and handlers. ```APIDOC Io::new pub fn new(_io_mux: IO_MUX<'d>) -> Self Initializes the I/O driver. Parameters: _io_mux: The IO_MUX peripheral instance required for initialization. Returns: A new instance of the Io driver. Stability: This API is marked as unstable and requires the 'unstable' crate feature. Io::set_interrupt_priority pub fn set_interrupt_priority(&self, prio: Priority) Set the interrupt priority for GPIO interrupts. Parameters: prio: The desired interrupt priority level. Panics: Panics if passed interrupt handler is invalid (e.g. has priority None). Stability: This API is marked as unstable and requires the 'unstable' crate feature. Io::set_interrupt_handler pub fn set_interrupt_handler(&mut self, handler: InterruptHandler) Registers an interrupt handler for all GPIO pins. Note: When using interrupt handlers registered by this function, or by defining a #[no_mangle] unsafe extern "C" fn GPIO() function, the interrupt status register and the interrupt enable setting are not cleared automatically. Users must manage clearing the status or disabling the interrupt enable setting based on their use case. Parameters: handler: The InterruptHandler to register for GPIO interrupts. Panics: Panics if passed interrupt handler is invalid (e.g. has priority None). Stability: This API is marked as unstable and requires the 'unstable' crate feature. ``` -------------------------------- ### SpiDma DMA Buffer Setup Example Source: https://docs.espressif.com/projects/rust/esp-hal/1.0.0-rc.0/esp32c2/esp_hal/spi/master/struct.SpiDma Demonstrates how to set up SpiDma with DMA buffers for SPI communication. This example shows the initialization of DMA buffers and configuring the SPI peripheral for DMA transfers. ```rust use esp_hal::{ dma::{DmaRxBuf, DmaTxBuf}, dma_buffers, spi::{ Mode, master::Config, }, }; let dma_channel = peripherals.DMA_CH0; let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) = dma_buffers!(32000); let dma_rx_buf = DmaRxBuf::new(rx_descriptors, rx_buffer)?; let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer)?; let mut spi = Spi::new( peripherals.SPI2, Config::default() .with_frequency(Rate::from_khz(100)) .with_mode(Mode::_0), )? .with_dma(dma_channel) .with_buffers(dma_rx_buf, dma_tx_buf); ```