Skip to content

Commit 06be374

Browse files
Empty HID FIFO on start-up.
Avoids the printing of garbage that was stored before the RP2040 booted.
1 parent f70c19b commit 06be374

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/main.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,11 @@ fn main() -> ! {
392392
pac::NVIC::unmask(pac::Interrupt::IO_IRQ_BANK0);
393393
}
394394

395+
// Empty the keyboard FIFO
396+
while let common::Result::Ok(common::Option::Some(_x)) = hid_get_event() {
397+
// Spin
398+
}
399+
395400
// Say hello over VGA
396401
sign_on();
397402

@@ -421,8 +426,8 @@ impl Hardware {
421426
/// Give the device 2000ns before we take away CS.
422427
const CS_BUS_HOLD_CPU_CLOCKS: u32 = 2000 / Self::NS_PER_CLOCK_CYCLE;
423428

424-
/// Give the device 10us when we do a retry.
425-
const SPI_RETRY_CPU_CLOCKS: u32 = 10_000 / Self::NS_PER_CLOCK_CYCLE;
429+
/// Give the device 10ms to sort itself out when we do a retry.
430+
const SPI_RETRY_CPU_CLOCKS: u32 = 10_000_000 / Self::NS_PER_CLOCK_CYCLE;
426431

427432
/// Give the BMC 6us to calculate its response
428433
const BMC_REQUEST_RESPONSE_DELAY_CLOCKS: u32 = 6_000 / Self::NS_PER_CLOCK_CYCLE;
@@ -828,7 +833,7 @@ impl Hardware {
828833
/// The number of bytes you want is set by the length of the `buffer` argument.
829834
///
830835
fn bmc_read_register(&mut self, register: u8, buffer: &mut [u8]) -> Result<(), ()> {
831-
const MAX_LATENCY: usize = 8;
836+
const MAX_LATENCY: usize = 12;
832837

833838
if (buffer.len() + MAX_LATENCY) > self.bmc_buffer.len() {
834839
defmt::error!("Asked for too much data ({})", buffer.len());
@@ -1274,7 +1279,8 @@ pub extern "C" fn hid_get_event() -> common::Result<common::Option<common::hid::
12741279
// Need more data
12751280
}
12761281
Err(_e) => {
1277-
panic!("Keyboard decode error!");
1282+
defmt::warn!("Keyboard decode error!");
1283+
hw.keyboard.clear();
12781284
}
12791285
}
12801286
}

0 commit comments

Comments
 (0)