RKTK API Docs RKTK Home Repo

rktk/drivers/interface/
split.rs

1use postcard::experimental::max_size::MaxSize;
2use serde::{Deserialize, Serialize};
3
4use super::rgb::RgbCommand;
5
6pub trait SplitDriver: 'static {
7    type Error: super::Error;
8
9    async fn init(&mut self) -> Result<(), Self::Error> {
10        Ok(())
11    }
12
13    /// Receive data from the other side and return the number of bytes received.
14    ///
15    /// If there is no data, this function should wait until data is received.
16    async fn recv(&mut self, buf: &mut [u8], is_master: bool) -> Result<usize, Self::Error>;
17
18    /// Send data to the other side.
19    ///
20    /// Implemention should wait until the *all* data is sent.
21    async fn send_all(&mut self, buf: &[u8], is_master: bool) -> Result<(), Self::Error>;
22}
23
24#[derive(Debug, Deserialize, Serialize, MaxSize)]
25#[cfg_attr(feature = "defmt", derive(defmt::Format))]
26pub enum MasterToSlave {
27    Rgb(RgbCommand),
28    Message(u8),
29}
30
31#[derive(Debug, Deserialize, Serialize, MaxSize)]
32#[cfg_attr(feature = "defmt", derive(defmt::Format))]
33pub enum SlaveToMaster {
34    Pressed(u8, u8),
35    Released(u8, u8),
36    Mouse { x: i8, y: i8 },
37    Message(u8),
38}