diff --git a/src/main.rs b/src/main.rs index 25bd191..91e7c2a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -98,19 +98,6 @@ fn main() -> ! { 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( pac.USB, pac.USB_DPRAM, @@ -131,8 +118,6 @@ fn main() -> ! { .self_powered(false) .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]; const LBA: u32 = DISK_BLOCK_NUM - 1; @@ -192,20 +177,26 @@ fn main() -> ! { defmt::info!("entering main loop"); + let mut start_time: u64 = 0; loop { - let interval = match (usb_device.state(), led_pin.is_set_high().unwrap_or_else(|_| false)) { - // The USB device has just been created or reset. - (UsbDeviceState::Default, true) => 100_000, - (UsbDeviceState::Default, false) => 100_000, - // The USB device has received an address from the host. - (UsbDeviceState::Addressed, true) => 250_000, - (UsbDeviceState::Addressed, false) => 250_000, - // The USB device has been configured and is fully functional. - (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, + let interval = if timer.get_counter().ticks() < 2_000_000 { + 25_000 + } + else { + match (usb_device.state(), led_pin.is_set_high().unwrap_or_else(|_| false)) { + // The USB device has just been created or reset. + (UsbDeviceState::Default, true) => 100_000, + (UsbDeviceState::Default, false) => 100_000, + // The USB device has received an address from the host. + (UsbDeviceState::Addressed, true) => 250_000, + (UsbDeviceState::Addressed, false) => 250_000, + // The USB device has been configured and is fully functional. + (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 { let _ = led_pin.toggle();