Created
May 17, 2021 16:53
-
-
Save hgomersall/6c025513950976137ca5c1b3dcdede46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn transfer(&mut self, value_in: u8) | |
-> Result<u8, nb::Error<T::Error>> | |
{ | |
// We always have to do a complete transfer - writing out and reading | |
// in. If we don't do the read, then the read buffer overflows and | |
// we can't use it when we need it. | |
self.spi.send(value_in)?; | |
Ok(self.spi.read()?) | |
} | |
fn instruction(&mut self, instruction: u8, data: u8) | |
-> Result<u8, T::Error> | |
{ | |
// The chip select is a bit mucky. The SPI transaction returns | |
// before the data is all transferred out, which means we time how | |
// long to hold the chip select low for. | |
self.chip_select.set_high(); | |
// We need to assert high for a minimum time. | |
self.delay.delay_us(CHIP_SELECT_ASSERT_HIGH_TIME_US); | |
self.chip_select.set_low(); | |
let _ = block!(self.transfer(instruction))?; | |
let read_val = block!(self.transfer(data))?; | |
//self.delay.delay_us(CHIP_SELECT_TRANSACTION_TIME_US); | |
// | |
if read_val != 0xFF { | |
self.chip_select.set_low(); | |
} else { | |
self.chip_select.set_high(); | |
} | |
Ok(read_val) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment