rdrive/
descriptor.rs

1use core::sync::atomic::{AtomicU64, Ordering};
2
3pub use alloc::vec::Vec;
4pub use rdif_base::irq::IrqConfig;
5
6use crate::custom_id;
7
8custom_id!(DeviceId, u64);
9custom_id!(DriverId, u64);
10
11#[derive(Default, Debug, Clone)]
12pub struct Descriptor {
13    pub(crate) device_id: DeviceId,
14    pub name: &'static str,
15    pub irq_parent: Option<DeviceId>,
16    // pub irqs: Vec<IrqConfig>,
17}
18
19impl Descriptor {
20    pub fn new() -> Self {
21        Self {
22            device_id: DeviceId::new(),
23            ..Default::default()
24        }
25    }
26}
27
28impl Descriptor {
29    pub fn device_id(&self) -> DeviceId {
30        self.device_id
31    }
32}
33
34static ITER: AtomicU64 = AtomicU64::new(0);
35
36impl DeviceId {
37    pub fn new() -> Self {
38        Self(ITER.fetch_add(1, Ordering::SeqCst))
39    }
40}
41
42macro_rules! impl_driver_id_for {
43    ($t:ty) => {
44        impl From<$t> for DriverId {
45            fn from(value: $t) -> Self {
46                Self(value as _)
47            }
48        }
49    };
50}
51
52impl_driver_id_for!(usize);
53impl_driver_id_for!(u32);