Rework fast blinking after reset

This commit is contained in:
Jakob Lechner 2025-09-24 10:46:11 +02:00
parent eb4921afce
commit 43bec436eb

View file

@ -98,19 +98,6 @@ fn main() -> ! {
let mut led_pin = pins.gpio12.into_push_pull_output(); let mut led_pin = pins.gpio12.into_push_pull_output();
let mut start_time: u64 = 0;
let mut count: u64 = 0;
loop {
if timer.get_counter().ticks() - start_time > 25_000 {
count += 1;
let _ = led_pin.toggle();
start_time = timer.get_counter().ticks();
if count == 125 {
break;
}
}
}
let usb_bus = UsbBusAllocator::new(hal::usb::UsbBus::new( let usb_bus = UsbBusAllocator::new(hal::usb::UsbBus::new(
pac.USB, pac.USB,
pac.USB_DPRAM, pac.USB_DPRAM,
@ -131,8 +118,6 @@ fn main() -> ! {
.self_powered(false) .self_powered(false)
.build(); .build();
let mut start_time: u64 = 0;
let mut storage: [u8; (DISK_BLOCK_SIZE * DISK_BLOCK_NUM) as usize] = [0u8; (DISK_BLOCK_SIZE * DISK_BLOCK_NUM) as usize]; let mut storage: [u8; (DISK_BLOCK_SIZE * DISK_BLOCK_NUM) as usize] = [0u8; (DISK_BLOCK_SIZE * DISK_BLOCK_NUM) as usize];
const LBA: u32 = DISK_BLOCK_NUM - 1; const LBA: u32 = DISK_BLOCK_NUM - 1;
@ -192,20 +177,26 @@ fn main() -> ! {
defmt::info!("entering main loop"); defmt::info!("entering main loop");
let mut start_time: u64 = 0;
loop { loop {
let interval = match (usb_device.state(), led_pin.is_set_high().unwrap_or_else(|_| false)) { let interval = if timer.get_counter().ticks() < 2_000_000 {
// The USB device has just been created or reset. 25_000
(UsbDeviceState::Default, true) => 100_000, }
(UsbDeviceState::Default, false) => 100_000, else {
// The USB device has received an address from the host. match (usb_device.state(), led_pin.is_set_high().unwrap_or_else(|_| false)) {
(UsbDeviceState::Addressed, true) => 250_000, // The USB device has just been created or reset.
(UsbDeviceState::Addressed, false) => 250_000, (UsbDeviceState::Default, true) => 100_000,
// The USB device has been configured and is fully functional. (UsbDeviceState::Default, false) => 100_000,
(UsbDeviceState::Configured, true) => 8, // The USB device has received an address from the host.
(UsbDeviceState::Configured, false) => 16, (UsbDeviceState::Addressed, true) => 250_000,
// The USB device has been suspended by the host or it has been unplugged from the USB bus. (UsbDeviceState::Addressed, false) => 250_000,
(UsbDeviceState::Suspend, true) => 10_000, // The USB device has been configured and is fully functional.
(UsbDeviceState::Suspend, false) => 2_000_000, (UsbDeviceState::Configured, true) => 8,
(UsbDeviceState::Configured, false) => 16,
// The USB device has been suspended by the host or it has been unplugged from the USB bus.
(UsbDeviceState::Suspend, true) => 10_000,
(UsbDeviceState::Suspend, false) => 2_000_000,
}
}; };
if timer.get_counter().ticks() - start_time > interval { if timer.get_counter().ticks() - start_time > interval {
let _ = led_pin.toggle(); let _ = led_pin.toggle();