Crates HAL
Los crates HAL de muchos microcontroladores incluyen envoltorios alrededor de varios periféricos. Por lo general, implementan traits de embedded-hal.
#![no_main]
#![no_std]
extern crate panic_halt as _;
use cortex_m_rt::entry;
use embedded_hal::digital::OutputPin;
use nrf52833_hal::gpio::{p0, Level};
use nrf52833_hal::pac::Peripherals;
#[entry]
fn main() -> ! {
let p = Peripherals::take().unwrap();
// Crea un envoltorio HAL para el puerto GPIO 0.
let gpio0 = p0::Parts::new(p.P0);
// Configura los pines 21 y 28 de GPIO 0 como salidas push-pull.
let mut col1 = gpio0.p0_28.into_push_pull_output(Level::High);
let mut row1 = gpio0.p0_21.into_push_pull_output(Level::Low);
// Define el pin 28 bajo y 21 alto para encender el LED.
col1.set_low().unwrap();
row1.set_high().unwrap();
loop {}
}
set_lowyset_highson métodos del traitOutputPindeembedded_hal.- Hay crates HAL para muchos dispositivos Cortex-M y RISC-V, incluidos varios microcontroladores STM32, GD32, nRF, NXP, MSP430, AVR y PIC.
Ejecuta el ejemplo con:
cargo embed --bin hal