#![no_std]
#![feature(doc_auto_cfg)]
#![feature(never_type)]
extern crate alloc;
use core::marker::PhantomData;
use core::ops::Deref;
use derivative::Derivative;
pub use wasefire_error::Error;
#[cfg(feature = "api-button")]
pub mod button;
#[cfg(feature = "internal-api-crypto")]
pub mod crypto;
pub mod debug;
#[cfg(feature = "api-gpio")]
pub mod gpio;
#[cfg(feature = "api-led")]
pub mod led;
#[cfg(feature = "internal-api-platform")]
pub mod platform;
#[cfg(feature = "internal-api-radio")]
pub mod radio;
#[cfg(feature = "api-rng")]
pub mod rng;
#[cfg(feature = "api-timer")]
pub mod timer;
#[cfg(feature = "api-uart")]
pub mod uart;
#[cfg(feature = "internal-api-usb")]
pub mod usb;
pub trait Api: Send + 'static {
fn try_event() -> Option<Event<Self>>;
fn wait_event() -> Event<Self>;
fn syscall(_x1: u32, _x2: u32, _x3: u32, _x4: u32) -> Option<Result<u32, Error>> {
None
}
#[cfg(feature = "api-button")]
type Button: button::Api;
#[cfg(feature = "internal-api-crypto")]
type Crypto: crypto::Api;
type Debug: debug::Api;
#[cfg(feature = "api-gpio")]
type Gpio: gpio::Api;
#[cfg(feature = "api-led")]
type Led: led::Api;
#[cfg(feature = "internal-api-platform")]
type Platform: platform::Api;
#[cfg(feature = "internal-api-radio")]
type Radio: radio::Api;
#[cfg(feature = "api-rng")]
type Rng: rng::Api;
#[cfg(feature = "api-storage")]
type Storage: Singleton + wasefire_store::Storage + Send;
#[cfg(feature = "api-timer")]
type Timer: timer::Api;
#[cfg(feature = "api-uart")]
type Uart: uart::Api;
#[cfg(feature = "internal-api-usb")]
type Usb: usb::Api;
}
pub trait Support<Value> {
const SUPPORT: Value;
}
pub trait Supported {}
pub trait Singleton: Sized {
fn take() -> Option<Self>;
}
#[derive(Derivative)]
#[derivative(Debug(bound = ""), PartialEq(bound = ""), Eq(bound = ""))]
pub enum Event<B: Api + ?Sized> {
#[cfg(feature = "api-button")]
Button(button::Event<B>),
#[cfg(feature = "internal-api-radio")]
Radio(radio::Event),
#[cfg(feature = "api-timer")]
Timer(timer::Event<B>),
#[cfg(feature = "api-uart")]
Uart(uart::Event<B>),
#[cfg(feature = "internal-api-usb")]
Usb(usb::Event),
Impossible(Impossible<B>),
}
#[derive(Derivative)]
#[derivative(Debug(bound = ""), Copy(bound = ""), Hash(bound = ""))]
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Ord(bound = ""))]
#[derivative(Ord = "feature_allow_slow_enum")]
pub struct Impossible<B: Api + ?Sized>(Void, PhantomData<B>);
impl<B: Api + ?Sized> Clone for Impossible<B> {
fn clone(&self) -> Self {
*self
}
}
impl<B: Api + ?Sized> PartialOrd for Impossible<B> {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl<B: Api + ?Sized> Impossible<B> {
pub fn unreachable(&self) -> ! {
match self.0 {}
}
}
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
enum Void {}
#[cfg(feature = "api-button")]
pub type Button<B> = <B as Api>::Button;
#[cfg(feature = "internal-api-crypto")]
pub type Crypto<B> = <B as Api>::Crypto;
pub type Debug<B> = <B as Api>::Debug;
#[cfg(feature = "api-gpio")]
pub type Gpio<B> = <B as Api>::Gpio;
#[cfg(feature = "api-led")]
pub type Led<B> = <B as Api>::Led;
#[cfg(feature = "internal-api-platform")]
pub type Platform<B> = <B as Api>::Platform;
#[cfg(feature = "internal-api-radio")]
pub type Radio<B> = <B as Api>::Radio;
#[cfg(feature = "api-rng")]
pub type Rng<B> = <B as Api>::Rng;
#[cfg(feature = "api-storage")]
pub type Storage<B> = <B as Api>::Storage;
#[cfg(feature = "api-timer")]
pub type Timer<B> = <B as Api>::Timer;
#[cfg(feature = "api-uart")]
pub type Uart<B> = <B as Api>::Uart;
#[cfg(feature = "internal-api-usb")]
pub type Usb<B> = <B as Api>::Usb;
#[derive(Derivative)]
#[derivative(Debug(bound = ""), Copy(bound = ""), Hash(bound = ""))]
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Ord(bound = ""))]
pub struct Id<T: Support<usize> + ?Sized> {
value: usize,
count: PhantomData<T>,
}
impl<T: Support<usize> + ?Sized> Clone for Id<T> {
fn clone(&self) -> Self {
*self
}
}
impl<T: Support<usize> + ?Sized> PartialOrd for Id<T> {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl<T: Support<usize>> Id<T> {
pub fn new(value: usize) -> Option<Self> {
(value < T::SUPPORT).then_some(Self { value, count: PhantomData })
}
}
impl<T: Support<usize>> Deref for Id<T> {
type Target = usize;
fn deref(&self) -> &Self::Target {
&self.value
}
}
impl<T: Supported> Support<bool> for T {
const SUPPORT: bool = true;
}