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 send status of the previous message for the peer.
20    NetSendStatus([u8; 6]),
21    /// Get the latest touchpad and buttons inputs.
22    ReadInput,
23}
24
25impl<'a> Encode<'a> for Request<'a> {}
26
27/// Response that the IO chip sends back to the main chip.
28#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
29pub enum Response<'a> {
30    Error(&'a str),
31    NetStarted,
32    NetStopped,
33    NetLocalAddr([u8; 6]),
34    NetAdvertised,
35    NetIncoming([u8; 6], &'a [u8]),
36    NetNoIncoming,
37    NetSent,
38    NetSendStatus(SendStatus),
39    Input(Option<(u16, u16)>, u8),
40}
41
42impl<'a> Encode<'a> for Response<'a> {}
43
44#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
45pub enum SendStatus {
46    /// Trying to send the message. The value is the number of attempts so far.
47    Sending(u8),
48    /// Message is delivered. The value is the number of attempts that it took.
49    Delivered(u8),
50    /// Message delivery failed.
51    Failed,
52    /// No messages were sent to the peer.
53    Empty,
54}