firefly_types/
spi.rs

1use crate::encode::Encode;
2use serde::{Deserialize, Serialize};
3
4/// Request that the main chip sends to the IO chip.
5#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
6pub enum Request<'a> {
7    /// Start listening for messages.
8    NetStart,
9    /// Stop accepting new messages and connections.
10    NetStop,
11    /// Get MAC address of this device's IO chip.
12    NetLocalAddr,
13    /// Broadcast advertisement message.
14    NetAdvertise,
15    /// Read an incoming message (if any) from the IO chip.
16    NetRecv,
17    /// Send an outgoing message to the IO chip.
18    NetSend([u8; 6], &'a [u8]),
19    /// Get the latest touchpad and buttons inputs.
20    ReadInput,
21}
22
23impl<'a> Encode<'a> for Request<'a> {}
24
25/// Response that the IO chip sends back to the main chip.
26#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
27pub enum Response<'a> {
28    Error(&'a str),
29    NetStarted,
30    NetStopped,
31    NetLocalAddr([u8; 6]),
32    NetAdvertised,
33    NetIncoming([u8; 6], &'a [u8]),
34    NetNoIncoming,
35    NetSent,
36    Input(Option<(i16, i16)>, u8),
37}
38
39impl<'a> Encode<'a> for Response<'a> {}