Add print command

This commit is contained in:
Jeremy Soller
2020-03-14 21:13:07 -06:00
parent 8a8ab165a7
commit 25a60568d0
2 changed files with 41 additions and 1 deletions

View File

@ -16,7 +16,7 @@ pub enum Cmd {
Probe = 1,
Board = 2,
Version = 3,
Debug = 4,
Print = 4,
Spi = 5,
Reset = 6,
}
@ -151,6 +151,23 @@ impl<T: Timeout> Ec<T> {
Ok(i)
}
pub unsafe fn print(&mut self, data: &[u8]) -> Result<usize, Error> {
let flags = 0;
for chunk in data.chunks(256 - 4) {
for i in 0..chunk.len() {
self.write(i as u8 + 4, chunk[i]);
}
self.write(2, flags);
self.write(3, chunk.len() as u8);
self.command(Cmd::Print)?;
if self.read(3) != chunk.len() as u8 {
return Err(Error::Verify);
}
}
Ok(data.len())
}
pub unsafe fn spi(&mut self, target: SpiTarget, scratch: bool) -> Result<EcSpi<T>, Error> {
let mut spi = EcSpi {
ec: self,