use derive_where::derive_where;
use crate::{Error, Id, Support};
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive_where(Debug, PartialEq, Eq)]
pub struct Event<B: crate::Api + ?Sized> {
pub gpio: Id<crate::Gpio<B>>,
}
impl<B: crate::Api> From<Event<B>> for crate::Event<B> {
fn from(event: Event<B>) -> Self {
crate::Event::Gpio(event)
}
}
#[derive(Debug, Copy, Clone, bytemuck::CheckedBitPattern)]
#[repr(u8)]
pub enum InputConfig {
Disabled = 0,
Floating = 1,
PullDown = 2,
PullUp = 3,
}
#[derive(Debug, Copy, Clone, bytemuck::CheckedBitPattern)]
#[repr(u8)]
pub enum OutputConfig {
Disabled = 0,
OpenDrain = 1,
OpenSource = 2,
PushPull = 3,
}
#[derive(Debug, Copy, Clone, bytemuck::CheckedBitPattern)]
#[repr(C)]
pub struct Config {
pub input: InputConfig,
pub output: OutputConfig,
pub initial: bool,
reserved: u8,
}
pub trait Api: Support<usize> + Send {
fn configure(gpio: Id<Self>, config: Config) -> Result<(), Error>;
fn read(gpio: Id<Self>) -> Result<bool, Error>;
fn write(gpio: Id<Self>, value: bool) -> Result<(), Error>;
fn last_write(gpio: Id<Self>) -> Result<bool, Error>;
fn enable(gpio: Id<Self>, falling: bool, rising: bool) -> Result<(), Error>;
fn disable(gpio: Id<Self>) -> Result<(), Error>;
}