1#![cfg_attr(not(feature = "libusb"), no_std)]
2#![feature(iterator_try_collect)]
3
4extern crate alloc;
5
6use core::time::Duration;
7pub use usb_if::descriptor::*;
8pub use usb_if::err::*;
9pub use usb_if::transfer::*;
10
11#[macro_use]
12mod _macros;
13
14pub mod err;
15mod host;
16
17pub use futures::future::BoxFuture;
18pub use host::*;
19
20pub trait Kernel {
21 fn sleep<'a>(duration: Duration) -> BoxFuture<'a, ()>;
22 fn page_size() -> usize;
23}
24
25pub(crate) async fn sleep(duration: Duration) {
26 unsafe extern "Rust" {
27 fn _usb_host_sleep<'a>(duration: Duration) -> BoxFuture<'a, ()>;
28 }
29
30 unsafe {
31 _usb_host_sleep(duration).await;
32 }
33}
34
35pub(crate) fn page_size() -> usize {
36 unsafe {
37 unsafe extern "Rust" {
38 fn _usb_host_page_size() -> usize;
39 }
40
41 _usb_host_page_size()
42 }
43}
44
45#[macro_export]
46macro_rules! set_impl {
47 ($t: ty) => {
48 #[unsafe(no_mangle)]
49 unsafe fn _usb_host_sleep<'a>(duration: core::time::Duration) -> $crate::BoxFuture<'a, ()> {
50 <$t as $crate::Kernel>::sleep(duration)
51 }
52
53 #[unsafe(no_mangle)]
54 unsafe fn _usb_host_page_size() -> usize {
55 <$t as $crate::Kernel>::page_size()
56 }
57 };
58}
59
60define_int_type!(BusAddr, u64);