Fixed Rust drivers

This commit is contained in:
Kevin Thomas
2026-04-02 11:36:06 -04:00
parent 2792583302
commit 9834d5c96c
245 changed files with 1110 additions and 650 deletions
+40 -1
View File
@@ -30,7 +30,7 @@ use fugit::RateExtU32;
// Clock trait for accessing system clock frequency
use hal::Clock;
// GPIO pin types and function selectors
use hal::gpio::{FunctionNull, FunctionUart, Pin, PullDown, PullNone};
use hal::gpio::{FunctionNull, FunctionSioOutput, FunctionUart, Pin, PullDown, PullNone};
// UART configuration and peripheral types
use hal::uart::{DataBits, Enabled, StopBits, UartConfig, UartPeripheral};
@@ -170,4 +170,43 @@ pub(crate) fn init_delay(clocks: &hal::clocks::ClocksManager) -> cortex_m::delay
cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz())
}
/// Type alias for the onboard LED pin configured as push-pull output.
type LedPin = Pin<hal::gpio::bank0::Gpio25, FunctionSioOutput, PullDown>;
/// Initialise all peripherals and run the blink demo.
///
/// # Arguments
///
/// * `pac` - PAC Peripherals singleton (consumed).
pub(crate) fn run(mut pac: hal::pac::Peripherals) -> ! {
let mut wd = hal::Watchdog::new(pac.WATCHDOG);
let clocks = init_clocks(pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, &mut wd);
let pins = init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS);
let uart = init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks);
let mut delay = init_delay(&clocks);
let mut led = crate::blink::BlinkDriver::init(pins.gpio25.into_push_pull_output());
uart.write_full_blocking(b"Blink driver initialized on GPIO 25\r\n");
blink_loop(&uart, &mut delay, &mut led)
}
/// Toggle LED, report state, and delay in a loop forever.
///
/// # Arguments
///
/// * `uart` - Reference to the enabled UART peripheral for serial output.
/// * `delay` - Mutable reference to the blocking delay provider.
/// * `led` - Mutable reference to the blink driver.
fn blink_loop(
uart: &EnabledUart,
delay: &mut cortex_m::delay::Delay,
led: &mut crate::blink::BlinkDriver<LedPin>,
) -> ! {
loop {
led.toggle();
let msg = if led.get_state() { b"LED: ON\r\n" as &[u8] } else { b"LED: OFF\r\n" };
uart.write_full_blocking(msg);
delay.delay_ms(BLINK_DELAY_MS);
}
}
// End of file
+1 -26
View File
@@ -74,34 +74,9 @@ pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe();
/// Application entry point for the LED blink demo.
///
/// Initializes the onboard LED and enters an infinite loop that
/// toggles the LED state every BLINK_DELAY_MS milliseconds.
///
/// # Returns
///
/// Does not return.
#[entry]
fn main() -> ! {
let mut pac = hal::pac::Peripherals::take().unwrap();
let clocks = board::init_clocks(
pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS,
&mut hal::Watchdog::new(pac.WATCHDOG),
);
let pins = board::init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS);
let uart = board::init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks);
let mut delay = board::init_delay(&clocks);
let mut led = blink::BlinkDriver::init(pins.gpio25.into_push_pull_output());
uart.write_full_blocking(b"Blink driver initialized on GPIO 25\r\n");
loop {
led.toggle();
if led.get_state() {
uart.write_full_blocking(b"LED: ON\r\n");
} else {
uart.write_full_blocking(b"LED: OFF\r\n");
}
delay.delay_ms(board::BLINK_DELAY_MS);
}
board::run(hal::pac::Peripherals::take().unwrap())
}
// Picotool binary info metadata