use crate::device::bus::UsbBus;
use crate::device::class::hid::{hid_protocol, hid_subclass};
use crate::device::endpoint::EndpointIn;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum ReportType {
Input,
Output,
Feature,
}
impl ReportType {
pub(crate) fn from_w_value(value: u16) -> Option<Self> {
match (value >> 8) as u8 {
1 => Some(Self::Input),
2 => Some(Self::Output),
3 => Some(Self::Feature),
_ => None,
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct HidSpec {
pub report_descriptor: &'static [u8],
pub in_report_size: u16,
pub out_report_size: u16,
pub subclass: u8,
pub protocol: u8,
pub poll_interval_ms: u8,
pub report_ids: bool,
}
impl HidSpec {
pub const fn new(report_descriptor: &'static [u8], in_report_size: u16) -> Self {
Self {
report_descriptor,
in_report_size,
out_report_size: 0,
subclass: hid_subclass::NONE,
protocol: hid_protocol::NONE,
poll_interval_ms: 10,
report_ids: false,
}
}
pub const fn subclass(mut self, subclass: u8) -> Self {
self.subclass = subclass;
self
}
pub const fn protocol(mut self, protocol: u8) -> Self {
self.protocol = protocol;
self
}
pub const fn out_report_size(mut self, size: u16) -> Self {
self.out_report_size = size;
self
}
pub const fn poll_interval_ms(mut self, interval: u8) -> Self {
self.poll_interval_ms = interval;
self
}
pub const fn report_ids(mut self, report_ids: bool) -> Self {
self.report_ids = report_ids;
self
}
}
pub trait HidDevice<B: UsbBus> {
fn spec(&self) -> HidSpec;
fn get_report(
&mut self,
_report_type: ReportType,
_report_id: u8,
_buf: &mut [u8],
) -> Option<usize> {
None
}
fn set_report(&mut self, _report_type: ReportType, _report_id: u8, _data: &[u8]) -> bool {
false
}
fn output_report(&mut self, _report_id: u8, _data: &[u8]) {}
fn reset(&mut self) {}
fn configure(&mut self) {}
fn deconfigure(&mut self) {}
fn poll(&mut self, _input: &EndpointIn<'_, B>) {}
}