use crate::device::bus::UsbBus;
use crate::device::class::hid::{HidDevice, HidSpec, hid_protocol, hid_subclass};
pub const MOUSE_REPORT_DESCRIPTOR: &[u8] = &[
0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01, 0xA1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x03, 0x81, 0x02, 0x75, 0x05, 0x95, 0x01, 0x81, 0x01, 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x15, 0x81, 0x25, 0x7F, 0x75, 0x08, 0x95, 0x02, 0x81, 0x06, 0x09, 0x38, 0x15, 0x81, 0x25, 0x7F, 0x75, 0x08, 0x95, 0x01, 0x81, 0x06, 0xC0, 0xC0, ];
#[derive(Clone, Copy, PartialEq, Eq, Default, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct MouseReport {
pub buttons: u8,
pub x: i8,
pub y: i8,
pub wheel: i8,
}
impl MouseReport {
pub const BUTTON_LEFT: u8 = 0x01;
pub const BUTTON_RIGHT: u8 = 0x02;
pub const BUTTON_MIDDLE: u8 = 0x04;
pub fn to_bytes(self) -> [u8; 4] {
[self.buttons, self.x as u8, self.y as u8, self.wheel as u8]
}
}
pub struct Mouse;
impl Mouse {
pub const fn new() -> Self {
Self
}
}
impl Default for Mouse {
fn default() -> Self {
Self::new()
}
}
impl<B: UsbBus> HidDevice<B> for Mouse {
fn spec(&self) -> HidSpec {
HidSpec::new(MOUSE_REPORT_DESCRIPTOR, 4)
.subclass(hid_subclass::BOOT)
.protocol(hid_protocol::MOUSE)
.poll_interval_ms(8)
}
}