@@ -44,7 +44,10 @@ pub mod vga;
4444// -----------------------------------------------------------------------------
4545
4646// Standard Library Stuff
47- use core:: { fmt:: Write , sync:: atomic:: AtomicBool } ;
47+ use core:: {
48+ fmt:: Write ,
49+ sync:: atomic:: { AtomicBool , AtomicU8 , Ordering } ,
50+ } ;
4851
4952// Third Party Stuff
5053use cortex_m_rt:: entry;
@@ -533,7 +536,7 @@ impl Hardware {
533536 i2s_lr_clock : hal_pins. gpio28 . into_mode ( ) ,
534537 pico_led : hal_pins. led . into_mode ( ) ,
535538 } ,
536- // Set SPI up for 1 MHz clock, 8 data bits.
539+ // Set SPI up for 2 MHz clock, 8 data bits.
537540 spi_bus : hal:: Spi :: new ( spi) . init (
538541 resets,
539542 clocks. peripheral_clock . freq ( ) ,
@@ -739,15 +742,21 @@ impl Hardware {
739742 ///
740743 /// We ask for 8 bytes of data. We get `1` byte of 'length', then `N` bytes of valid data, and `32 - (N + 1)` bytes of padding.
741744 fn bmc_read_ps2_keyboard_fifo ( & mut self , out_buffer : & mut [ u8 ; 8 ] ) -> Result < usize , ( ) > {
745+ static COUNTER : AtomicU8 = AtomicU8 :: new ( 0 ) ;
742746 let req = neotron_bmc_protocol:: Request :: new_read ( USE_ALT . get ( ) , 0x40 , 8 ) ;
743747 for _retry in 0 ..4 {
744748 let mut buffer = [ 0xFF ; 32 ] ;
745749 buffer[ 0 ..=3 ] . copy_from_slice ( & req. as_bytes ( ) ) ;
750+ buffer[ 4 ] = COUNTER . load ( Ordering :: Relaxed ) ;
751+ COUNTER . store ( buffer[ 4 ] . wrapping_add ( 1 ) , Ordering :: Relaxed ) ;
752+ defmt:: trace!( "out: {=[u8]:02x}" , buffer) ;
746753 self . with_bus_cs ( 0 , |spi| {
747754 spi. transfer ( & mut buffer) . unwrap ( ) ;
748755 } ) ;
749- defmt:: trace!( "buffer: {=[u8]:x}" , buffer) ;
750- let mut result = & buffer[ ..] ;
756+ defmt:: trace!( "in : {=[u8]:02x}" , buffer) ;
757+ // Skip the first four bytes at least (that's our command, and also
758+ // the BMC FIFO length which might have crud in it). Then trip any padding.
759+ let mut result = & buffer[ 4 ..] ;
751760 let mut latency = 0 ;
752761 while !result. is_empty ( ) && ( result[ 0 ] == 0xFF || result[ 0 ] == 0x00 ) {
753762 latency += 1 ;
@@ -1520,7 +1529,7 @@ extern "C" fn block_dev_eject(dev_id: u8) -> common::Result<()> {
15201529/// Sleep the CPU until the next interrupt.
15211530extern "C" fn power_idle ( ) {
15221531 // cortex_m::asm::wfe();
1523- cortex_m:: asm:: delay ( 1_000_000 ) ;
1532+ // cortex_m::asm::delay(20_000_000 );
15241533}
15251534
15261535/// TODO: Get the monotonic run-time of the system from SysTick.
0 commit comments