1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use lpc55::secure_binary::Version;
use crate::{App as _, Result, Uuid};
app_boilerplate!();
impl crate::App for App {
const RID: &'static [u8] = super::SOLOKEYS_RID;
const PIX: &'static [u8] = super::ADMIN_PIX;
}
impl App {
pub const BOOT_TO_BOOTROM_COMMAND: u8 = 0x51;
pub const REBOOT_COMMAND: u8 = 0x53;
pub const VERSION_COMMAND: u8 = 0x61;
pub const UUID_COMMAND: u8 = 0x62;
pub fn boot_to_bootrom(&mut self) -> Result<()> {
self.call(Self::BOOT_TO_BOOTROM_COMMAND).map(drop)
}
pub fn reboot(&mut self) -> Result<()> {
self.call(Self::REBOOT_COMMAND).map(drop)
}
pub fn uuid(&mut self) -> Result<Uuid> {
let version_bytes = self.call(Self::UUID_COMMAND)?;
let bytes: &[u8] = &version_bytes;
Ok(Uuid::from_u128(
bytes
.try_into()
.map_err(|_| anyhow::anyhow!("expected 16 byte UUID, got {}", &hex::encode(bytes)))
.map(u128::from_be_bytes)?,
))
}
pub fn version(&mut self) -> Result<Version> {
let version_bytes = self.call(Self::VERSION_COMMAND)?;
let bytes: [u8; 4] = version_bytes.as_slice().try_into().map_err(|_| {
anyhow::anyhow!(
"expected 4 bytes version, got {}",
&hex::encode(version_bytes)
)
})?;
Ok(bytes.into())
}
}