1 use alloc::sync::Arc; 2 use system_error::SystemError; 3 4 use crate::driver::base::device::{bus::Bus, Device}; 5 6 use super::serio_bus; 7 8 /// 串行设备,实现该trait的设备实例挂载在serio总线上,同时应该实现Device trait 9 /// 10 /// 参考: https://code.dragonos.org.cn/xref/linux-6.1.9/include/linux/serio.h#20 11 pub trait SerioDevice: Device { 12 /// # 函数功能 13 /// 14 /// Serio设备写入数据 15 /// 16 /// ## 参数 17 /// 18 /// - data 写入的数据 19 /// 20 /// ## 返回值 21 /// 22 /// 无 23 fn write(&self, device: &Arc<dyn SerioDevice>, data: u8) -> Result<(), SystemError>; 24 /// Serio设备连接驱动时调用 25 fn open(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>; 26 /// Serio设备断开驱动时调用 27 fn close(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>; 28 /// Serio设备初始化时调用 29 fn start(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>; 30 /// Serio设备销毁时调用 31 fn stop(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>; 32 } 33 34 #[allow(dead_code)] 35 #[inline(always)] 36 pub fn serio_device_manager() -> &'static SerioDeviceManager { 37 &SerioDeviceManager 38 } 39 40 pub struct SerioDeviceManager; 41 42 #[allow(dead_code)] 43 impl SerioDeviceManager { 44 /// # 函数功能 45 /// 注册Serio设备 46 /// 47 /// ## 参数 48 /// - device 待注册的设备 49 /// 50 /// ## 返回值 51 /// 无 52 pub fn register_port(&self, device: Arc<dyn SerioDevice>) -> Result<(), SystemError> { 53 self.init_port(device) 54 } 55 56 /// # 函数功能 57 /// 初始化Serio设备 58 /// 59 /// ## 参数 60 /// - device 待初始化的Serio设备 61 /// 62 /// ## 返回值 63 /// 无 64 /// 65 /// todo:https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/input/serio/serio.c#494 66 pub fn init_port(&self, device: Arc<dyn SerioDevice>) -> Result<(), SystemError> { 67 device.set_bus(Some(Arc::downgrade(&(serio_bus() as Arc<dyn Bus>)))); 68 Ok(()) 69 } 70 } 71