Add led blink indicator
This commit is contained in:
parent
73f6f7cbd4
commit
824ce0225d
1 changed files with 22 additions and 2 deletions
24
src/main.rs
24
src/main.rs
|
|
@ -4,6 +4,7 @@
|
|||
use rp_pico::entry;
|
||||
|
||||
use embedded_hal::digital::OutputPin;
|
||||
use embedded_hal::digital::StatefulOutputPin;
|
||||
|
||||
use rp_pico::hal::pac;
|
||||
|
||||
|
|
@ -91,6 +92,8 @@ fn main() -> ! {
|
|||
.ok()
|
||||
.unwrap();
|
||||
|
||||
let timer = hal::timer::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks);
|
||||
|
||||
let sio = hal::Sio::new(pac.SIO);
|
||||
let pins = rp_pico::Pins::new(
|
||||
pac.IO_BANK0,
|
||||
|
|
@ -122,8 +125,26 @@ fn main() -> ! {
|
|||
.self_powered(false)
|
||||
.build();
|
||||
|
||||
let mut start_time: u64 = 0;
|
||||
loop {
|
||||
led_pin.set_high().unwrap();
|
||||
let interval = match (usb_device.state(), led_pin.is_set_high().unwrap()) {
|
||||
// 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) => 1_000_000,
|
||||
(UsbDeviceState::Configured, false) => 0,
|
||||
// The USB device has been suspended by the host or it has been unplugged from the USB bus.
|
||||
(UsbDeviceState::Suspend, true) => 25_000,
|
||||
(UsbDeviceState::Suspend, false) => 2_000_000,
|
||||
};
|
||||
if timer.get_counter().ticks() - start_time > interval {
|
||||
led_pin.toggle().unwrap();
|
||||
start_time = timer.get_counter().ticks();
|
||||
}
|
||||
|
||||
if !usb_device.poll(&mut [&mut scsi]) {
|
||||
continue;
|
||||
|
|
@ -134,7 +155,6 @@ fn main() -> ! {
|
|||
}
|
||||
|
||||
let _ = scsi.poll(|command| {
|
||||
led_pin.set_low().unwrap();
|
||||
if let Err(err) = process_command(command, &mut state, &mut storage) {
|
||||
//defmt::error!("{}", err);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue