#![no_std]
#![no_main]
use core::fmt::Write;
use core::ops::ControlFlow;
use rpi_hal::halt;
use rpi_hal::mailbox::Mailbox;
use rpi_hal::pac;
use rpi_hal::timer::Timer;
use rpi_hal::uart::Uart;
use rpi_hal::usb;
use rpi_hal::usb::dwc2::Dwc2Host;
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
let peripherals = unsafe { pac::Peripherals::steal() };
let mut uart = Uart::init(&peripherals.GPIO, peripherals.UART0);
let _ = writeln!(uart, "PANIC: {info}");
halt();
}
#[no_mangle]
pub extern "C" fn kmain() -> ! {
let peripherals = unsafe { pac::Peripherals::steal() };
let mut uart = Uart::init(&peripherals.GPIO, peripherals.UART0);
let timer = Timer::new(peripherals.SYSTMR);
let mut mailbox = Mailbox::new(peripherals.VCMAILBOX);
if !usb::power_on(&mut mailbox) {
let _ = writeln!(uart, "USB power-on failed");
halt();
}
let dwc2 = Dwc2Host::init(
peripherals.USB_OTG_GLOBAL,
peripherals.USB_OTG_HOST,
peripherals.USB_OTG_PWRCLK,
&timer,
);
let _ = writeln!(uart, "waiting for the on-board hub...");
while !dwc2.port_connected() {
timer.delay_ms(100);
}
let result = usb::enumerate(&dwc2, &timer, |_channel, _timer, device| {
let _ = writeln!(
uart,
"port {}: {:04x}:{:04x} class={} -> address {}",
device.port,
device.descriptor.vendor_id,
device.descriptor.product_id,
device.descriptor.device_class,
device.endpoint.address,
);
ControlFlow::Continue(())
});
match result {
Ok(()) => {
let _ = writeln!(uart, "enumeration complete");
}
Err(e) => {
let _ = writeln!(uart, "enumeration failed: {e:?}");
}
}
halt();
}