#![no_std]
pub use usb_device::{Result, UsbError};
pub mod hid_class;
pub mod descriptor;
#[cfg(test)]
#[allow(unused_imports)]
mod tests {
use crate::descriptor::gen_hid_descriptor;
use crate::descriptor::SerializedDescriptor;
use crate::descriptor::MouseReport;
#[gen_hid_descriptor(
(collection = 0x01, usage = 0x01, usage_page = 0xff00) = {
f1=input;
f2=output;
}
)]
#[allow(dead_code)]
struct CustomUnaryUnsignedFrame {
f1: u8,
f2: u16,
}
#[test]
fn test_custom_unsigned() {
let expected = &[
6u8, 0u8, 255u8, 9u8, 1u8, 161u8, 1u8, 21u8, 0u8, 38u8, 255u8, 0u8, 117u8, 8u8, 149u8,
1u8, 129u8, 2u8, 39u8, 255u8, 255u8, 0u8, 0u8, 117u8, 16u8, 145u8, 2u8, 192u8,
];
assert_eq!(CustomUnaryUnsignedFrame::desc(), expected);
}
#[gen_hid_descriptor(
(collection = 0x01, usage = 0x01, usage_page = 0xff00) = {
f1=input;
f2=output;
}
)]
#[allow(dead_code)]
struct CustomUnarySignedFrame {
f1: i8,
f2: i16,
}
#[test]
fn test_custom_signed() {
let expected = &[
6u8, 0u8, 255u8, 9u8, 1u8, 161u8, 1u8, 23u8, 129u8, 255u8, 255u8, 255u8, 37u8, 127u8, 117u8, 8u8,
149u8, 1u8, 129u8, 2u8, 23u8, 1u8, 128u8, 255u8, 255u8, 38u8, 255u8, 127u8, 117u8, 16u8, 145u8, 2u8,
192u8,
];
assert_eq!(CustomUnarySignedFrame::desc()[0..32], expected[0..32]);
}
#[gen_hid_descriptor(
(report_id = 0x01,) = {
f1=input
},
(report_id = 0x02,) = {
f2=input
},
)]
#[allow(dead_code)]
struct CustomMultiReport {
f1: u8,
f2: u8,
}
#[test]
fn test_custom_reports() {
let expected: &[u8] = &[
133, 1, 21, 0, 38, 255, 0, 117, 8, 149, 1, 129, 2, 133, 2, 129, 2
];
assert_eq!(CustomMultiReport::desc(), expected);
}
#[gen_hid_descriptor(
(collection = 0x01, usage = 0x01, usage_page = 0xff00) = {
buff=input
},
)]
#[allow(dead_code)]
struct CustomArray {
buff: [u8; 32],
}
#[test]
fn test_array() {
let expected: &[u8] = &[
6, 0, 255, 9, 1, 161, 1, 21, 0, 38, 255, 0, 117, 8, 149, 32, 129, 2, 192
];
assert_eq!(CustomArray::desc(), expected);
}
#[gen_hid_descriptor(
(collection = APPLICATION, usage_page = VENDOR_DEFINED_START, usage = 0x01) = {
(usage_min = BUTTON_1, usage_max = BUTTON_3) = {
#[item_settings data,variable,relative] f1=input;
}
}
)]
#[allow(dead_code)]
struct CustomConst {
f1: u8,
}
#[test]
fn test_custom_const() {
let expected = &[
6u8, 0u8, 255u8, 9u8, 1u8, 161u8, 1u8, 25u8, 1u8, 41u8, 3u8, 21u8, 0u8,
38u8, 255u8, 0u8, 117u8, 8u8, 149u8, 1u8, 129u8, 6u8, 192u8,
];
assert_eq!(CustomConst::desc(), expected);
}
#[gen_hid_descriptor(
(report_id = 0x01,) = {
#[packed_bits 3] f1=input;
#[packed_bits 9] f2=input;
}
)]
#[allow(dead_code)]
struct CustomPackedBits {
f1: u8,
f2: u16,
}
#[test]
fn test_custom_packed_bits() {
let expected = &[
133u8, 1u8, 21u8, 0u8, 37u8, 1u8, 117u8, 1u8, 149u8, 3u8, 129u8, 2u8,
149u8, 5u8, 129u8, 3u8, 149u8, 9u8, 129u8, 2u8, 149u8, 7u8, 129u8, 3u8,
];
assert_eq!(CustomPackedBits::desc(), expected);
}
#[test]
fn test_mouse_descriptor() {
let expected = &[
5u8, 1u8, 9u8, 2u8, 161u8, 1u8, 9u8, 1u8, 161u8, 0u8, 5u8, 9u8, 25u8, 1u8,
41u8, 3u8, 21u8, 0u8, 37u8, 1u8, 117u8, 1u8, 149u8, 3u8, 129u8, 2u8, 149u8,
5u8, 129u8, 3u8, 5u8, 1u8, 9u8, 48u8, 23u8, 129u8, 255u8, 255u8, 255u8, 37u8,
127u8, 117u8, 8u8, 149u8, 1u8, 129u8, 6u8, 9u8, 49u8, 129u8, 6u8, 192u8, 192u8,
];
assert_eq!(MouseReport::desc()[0..32], expected[0..32]);
}
}