forked from limingth/arceos
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmod.rs
96 lines (84 loc) · 2.71 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
pub mod drivers;
pub mod operation;
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use drivers::driverapi::{USBSystemDriverModule, USBSystemDriverModuleInstance};
use log::trace;
use spinlock::SpinNoIrq;
use urb::URB;
use crate::{
abstractions::PlatformAbstractions,
glue::driver_independent_device_instance::DriverIndependentDeviceInstance, USBSystemConfig,
};
use self::drivers::DriverContainers;
pub mod descriptors;
pub mod trasnfer;
pub mod urb;
#[cfg(feature = "packed_drivers")]
pub(crate) mod universal_drivers;
pub struct USBDriverSystem<'a, O>
where
O: PlatformAbstractions,
{
config: Arc<SpinNoIrq<USBSystemConfig<O>>>,
managed_modules: DriverContainers<'a, O>,
driver_device_instances: Vec<Arc<SpinNoIrq<dyn USBSystemDriverModuleInstance<'a, O>>>>,
}
impl<'a, O> USBDriverSystem<'a, O>
where
O: PlatformAbstractions + 'static,
{
pub fn new(config: Arc<SpinNoIrq<USBSystemConfig<O>>>) -> Self {
Self {
config,
managed_modules: DriverContainers::new(),
driver_device_instances: Vec::new(),
}
}
pub fn init(&mut self) {
#[cfg(feature = "packed_drivers")]
{
self.managed_modules.load_driver(Box::new(
universal_drivers::hid_drivers::hid_mouse::HidMouseDriverModule,
));
self.managed_modules.load_driver(Box::new(
universal_drivers::hid_drivers::hid_keyboard::HidKeyboardDriverModule,
));
self.managed_modules.load_driver(Box::new(
universal_drivers::uvc_drivers::generic_uvc::GenericUVCDriverModule,
));
}
trace!("usb system driver modules load complete!")
}
/**
* this method should invoked after driver independent devices created
*/
pub fn init_probe(
&mut self,
devices: &Vec<DriverIndependentDeviceInstance<O>>,
preparing_list: &mut Vec<Vec<URB<'a, O>>>,
) {
devices
.iter()
.flat_map(|device| {
self.managed_modules
.create_for_device(device, self.config.clone(), preparing_list)
})
.collect_into(&mut self.driver_device_instances);
trace!(
"current driver managed device num: {}",
self.driver_device_instances.len()
)
}
pub fn tick(&mut self) -> Vec<Vec<URB<'a, O>>> {
self.driver_device_instances
.iter()
.filter_map(|drv_dev| {
drv_dev.lock().gather_urb().map(|mut vec| {
vec.iter_mut()
.for_each(|urb| urb.set_sender(drv_dev.clone()));
vec
})
})
.collect()
}
}