-
Notifications
You must be signed in to change notification settings - Fork 25
feat: add input device #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| [package] | ||
| name = "axdriver_input" | ||
| edition.workspace = true | ||
| description = "Common traits and types for input device drivers" | ||
| documentation = "https://arceos-org.github.io/axdriver_crates/axdriver_input" | ||
| keywords = ["arceos", "driver", "input"] | ||
| version.workspace = true | ||
| authors = ["mivik <mivikq@gmail.com>"] | ||
| license.workspace = true | ||
| homepage.workspace = true | ||
| repository.workspace = true | ||
| categories.workspace = true | ||
|
|
||
| [dependencies] | ||
| axdriver_base = { workspace = true } | ||
| strum = { version = "0.27.2", default-features = false, features = ["derive"] } |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,101 @@ | ||||||||||
| //! Common traits and types for graphics display device drivers. | ||||||||||
|
|
||||||||||
| #![no_std] | ||||||||||
|
|
||||||||||
| #[doc(no_inline)] | ||||||||||
| pub use axdriver_base::{BaseDriverOps, DevError, DevResult, DeviceType}; | ||||||||||
| use strum::FromRepr; | ||||||||||
|
|
||||||||||
| #[repr(u8)] | ||||||||||
| #[derive(Debug, Clone, Copy, Eq, PartialEq, FromRepr)] | ||||||||||
| pub enum EventType { | ||||||||||
| Synchronization = 0x00, | ||||||||||
| Key = 0x01, | ||||||||||
| Relative = 0x02, | ||||||||||
| Absolute = 0x03, | ||||||||||
| Misc = 0x04, | ||||||||||
| Switch = 0x05, | ||||||||||
| Led = 0x11, | ||||||||||
| Sound = 0x12, | ||||||||||
| ForceFeedback = 0x15, | ||||||||||
| } | ||||||||||
|
|
||||||||||
| impl EventType { | ||||||||||
|
||||||||||
| impl EventType { | |
| impl EventType { | |
| /// Protocol-defined maximum event type value (matches Linux `EV_MAX` = 0x1f), | |
| /// which may be larger than the largest `EventType` variant. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this function do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eternalcomet marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| use alloc::{borrow::ToOwned, string::String}; | ||
|
|
||
| use axdriver_base::{BaseDriverOps, DevError, DevResult, DeviceType}; | ||
| use axdriver_input::{Event, EventType, InputDeviceId, InputDriverOps}; | ||
| use virtio_drivers::{ | ||
| Hal, | ||
| device::input::{InputConfigSelect, VirtIOInput as InnerDev}, | ||
| transport::Transport, | ||
| }; | ||
|
|
||
| use crate::as_dev_err; | ||
|
|
||
| /// The VirtIO Input device driver. | ||
| pub struct VirtIoInputDev<H: Hal, T: Transport> { | ||
| inner: InnerDev<H, T>, | ||
| device_id: InputDeviceId, | ||
| name: String, | ||
| } | ||
|
|
||
| unsafe impl<H: Hal, T: Transport> Send for VirtIoInputDev<H, T> {} | ||
| unsafe impl<H: Hal, T: Transport> Sync for VirtIoInputDev<H, T> {} | ||
|
|
||
| impl<H: Hal, T: Transport> VirtIoInputDev<H, T> { | ||
| /// Creates a new driver instance and initializes the device, or returns | ||
| /// an error if any step fails. | ||
| pub fn try_new(transport: T) -> DevResult<Self> { | ||
| let mut virtio = InnerDev::new(transport).unwrap(); | ||
eternalcomet marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let name = virtio.name().unwrap_or_else(|_| "<unknown>".to_owned()); | ||
| let device_id = virtio.ids().map_err(as_dev_err)?; | ||
| let device_id = InputDeviceId { | ||
| bus_type: device_id.bustype, | ||
| vendor: device_id.vendor, | ||
| product: device_id.product, | ||
| version: device_id.version, | ||
| }; | ||
|
|
||
| Ok(Self { | ||
| inner: virtio, | ||
| device_id, | ||
| name, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl<H: Hal, T: Transport> BaseDriverOps for VirtIoInputDev<H, T> { | ||
| fn device_name(&self) -> &str { | ||
| &self.name | ||
| } | ||
|
|
||
| fn device_type(&self) -> DeviceType { | ||
| DeviceType::Input | ||
| } | ||
| } | ||
|
|
||
| impl<H: Hal, T: Transport> InputDriverOps for VirtIoInputDev<H, T> { | ||
| fn device_id(&self) -> InputDeviceId { | ||
| self.device_id | ||
| } | ||
|
|
||
| fn physical_location(&self) -> &str { | ||
| // TODO: unique physical location | ||
| "virtio0/input0" | ||
| } | ||
|
|
||
| fn unique_id(&self) -> &str { | ||
| // TODO: unique ID | ||
| "virtio" | ||
| } | ||
|
Comment on lines
+60
to
+68
|
||
|
|
||
| fn get_event_bits(&mut self, ty: EventType, out: &mut [u8]) -> DevResult<bool> { | ||
| let read = self | ||
| .inner | ||
| .query_config_select(InputConfigSelect::EvBits, ty as u8, out); | ||
| Ok(read != 0) | ||
| } | ||
|
|
||
| fn read_event(&mut self) -> DevResult<Event> { | ||
| self.inner.ack_interrupt(); | ||
| self.inner | ||
| .pop_pending_event() | ||
| .map(|e| Event { | ||
| event_type: e.event_type, | ||
| code: e.code, | ||
| value: e.value, | ||
| }) | ||
| .ok_or(DevError::Again) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,11 @@ mod blk; | |
| #[cfg(feature = "gpu")] | ||
| mod gpu; | ||
|
|
||
| #[cfg(feature = "input")] | ||
| mod input; | ||
| #[cfg(feature = "input")] | ||
| pub use self::input::VirtIoInputDev; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put this line near other re-exported virtio devices. |
||
|
|
||
| #[cfg(feature = "net")] | ||
| mod net; | ||
|
|
||
|
|
@@ -84,6 +89,7 @@ const fn as_dev_type(t: VirtIoDevType) -> Option<DeviceType> { | |
| Block => Some(DeviceType::Block), | ||
| Network => Some(DeviceType::Net), | ||
| GPU => Some(DeviceType::Display), | ||
| Input => Some(DeviceType::Input), | ||
| _ => None, | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.