RKTK API Docs RKTK Home Repo

rktk/drivers/interface/
split.rs

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