vex_cdc/cdc2/
factory.rs

1//! Factory control packets.
2
3use crate::{
4    Decode, DecodeError,
5    cdc::cmds::USER_CDC,
6    cdc2::{
7        Cdc2CommandPacket, Cdc2ReplyPacket,
8        ecmds::{FACTORY_CHAL, FACTORY_EBL, FACTORY_RESP, FACTORY_STATUS},
9    },
10};
11
12#[derive(Debug, Clone, Copy, Eq, PartialEq)]
13pub struct FactoryStatus {
14    pub status: u8,
15    pub percent: u8,
16}
17impl Decode for FactoryStatus {
18    fn decode(data: &mut &[u8]) -> Result<Self, DecodeError> {
19        let status = u8::decode(data)?;
20        let percent = u8::decode(data)?;
21        Ok(Self { status, percent })
22    }
23}
24
25pub type FactoryChallengePacket = Cdc2CommandPacket<USER_CDC, FACTORY_CHAL, ()>;
26pub type FactoryChallengeReplyPacket = Cdc2ReplyPacket<USER_CDC, FACTORY_CHAL, [u8; 16]>;
27
28pub type FactoryResponsePacket = Cdc2CommandPacket<USER_CDC, FACTORY_RESP, [u8; 16]>;
29pub type FactoryResponseReplyPacket = Cdc2ReplyPacket<USER_CDC, FACTORY_RESP, ()>;
30
31pub type FactoryStatusPacket = Cdc2CommandPacket<USER_CDC, FACTORY_STATUS, ()>;
32pub type FactoryStatusReplyPacket = Cdc2ReplyPacket<USER_CDC, FACTORY_STATUS, FactoryStatus>;
33
34pub type FactoryEnablePacket = Cdc2CommandPacket<USER_CDC, FACTORY_EBL, [u8; 4]>;
35pub type FactoryEnableReplyPacket = Cdc2ReplyPacket<USER_CDC, FACTORY_EBL, ()>;
36
37impl FactoryEnablePacket {
38    pub const MAGIC: [u8; 4] = [0x4D, 0x4C, 0x4B, 0x4A];
39}