How to Use PAC (Peripheral Access Crate) and BSP (Board Support Package) in Rust

Use a BSP to get pre-configured hardware access and the PAC to interact with specific peripherals via safe abstractions. Add the BSP as a dependency in your `Cargo.toml` and import the peripherals to control hardware registers directly.

How to Use PAC (Peripheral Access Crate) and BSP (Board Support Package) in Rust

Use a BSP to get pre-configured hardware access and the PAC to interact with specific peripherals via safe abstractions. Add the BSP as a dependency in your Cargo.toml and import the peripherals to control hardware registers directly.

[dependencies]
# Replace with your specific board BSP
esp32c3-bsp = "0.1"
# The PAC is usually a transitive dependency of the BSP
# Access it via the BSP re-export or direct import if needed
esp32c3-pac = "0.1"
use esp32c3_bsp::Peripherals;
use esp32c3_bsp::prelude::*;

fn main() {
    // Initialize the board and get peripherals
    let peripherals = Peripherals::take().unwrap();
    
    // Access a specific peripheral (e.g., GPIO) via the PAC
    let io = &peripherals.GPIO;
    
    // Configure a pin as output
    io.pin[0].control().write(|w| w.output_en().set_bit());
    
    // Toggle the pin
    io.pin[0].scl().write(|w| w.set_bit());
}