rdrive/device/
descriptor.rs1use core::sync::atomic::{AtomicU64, Ordering};
2
3pub use alloc::vec::Vec;
4pub use rdif_base::*;
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 device_id: DeviceId,
14 pub name: &'static str,
15 pub irq_parent: Option<DeviceId>,
16 pub irqs: Vec<IrqConfig>,
17}
18
19static ITER: AtomicU64 = AtomicU64::new(0);
20
21impl DeviceId {
22 pub fn new() -> Self {
23 Self(ITER.fetch_add(1, Ordering::SeqCst))
24 }
25}
26
27macro_rules! impl_driver_id_for {
28 ($t:ty) => {
29 impl From<$t> for DriverId {
30 fn from(value: $t) -> Self {
31 Self(value as _)
32 }
33 }
34 };
35}
36
37impl_driver_id_for!(usize);
38impl_driver_id_for!(u32);