use serde::{Deserialize, Serialize};
trait Sealed {}
#[allow(private_bounds)]
pub trait Command: Serialize + Sealed {
const CMD: u8;
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Write;
impl Sealed for Write {}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Read {
pub wlen: u8,
}
impl Sealed for Read {}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Register<C> {
pub page: u8,
pub addr: u8,
pub cmd: C,
}
impl Sealed for Register<Write> {}
impl Sealed for Register<Read> {}
impl Command for Register<Write> {
const CMD: u8 = 0x80;
}
impl Command for Register<Read> {
const CMD: u8 = 0x81;
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Word<C> {
pub addr: u16,
pub cmd: C,
}
impl Sealed for Word<Write> {}
impl Sealed for Word<Read> {}
impl Command for Word<Write> {
const CMD: u8 = 0x82;
}
impl Command for Word<Read> {
const CMD: u8 = 0x83;
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Dword<C> {
pub addr: u32,
pub cmd: C,
}
impl Sealed for Dword<Write> {}
impl Sealed for Dword<Read> {}
impl Command for Dword<Write> {
const CMD: u8 = 0x86;
}
impl Command for Dword<Read> {
const CMD: u8 = 0x87;
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Curve {
pub ch: u8,
}
impl Sealed for Curve {}
impl Command for Curve {
const CMD: u8 = 0x84;
}