diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commands.rs | 2 | ||||
-rw-r--r-- | src/device.rs | 14 |
2 files changed, 9 insertions, 7 deletions
diff --git a/src/commands.rs b/src/commands.rs index 3a7d16a..d05423e 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -8,8 +8,6 @@ use serde::{Deserialize, Serialize}; use crate::device::CommandStatus; -pub const COMMAND_LEN: usize = 53; - enum_cmd! { #[derive(Clone, Copy, Debug, PartialEq)] pub enum CommandId { diff --git a/src/device.rs b/src/device.rs index fc119d5..b25cfb7 100644 --- a/src/device.rs +++ b/src/device.rs @@ -6,7 +6,7 @@ use serde_big_array::big_array; use usb_device::bus::{UsbBus, UsbBusAllocator}; use usb_device::device::{UsbDevice, UsbDeviceBuilder, UsbVidPid}; -use crate::commands::{CommandId, COMMAND_LEN}; +use crate::commands::CommandId; use crate::crc::Crc; use crate::hid::{HidDevice, Protocol, ReportType, Subclass}; use crate::util::TryFrom; @@ -16,6 +16,7 @@ const PID_NITROKEY_PRO: u16 = 0x4108; const REPORT_LEN: usize = 64; const REQUEST_DATA_LEN: usize = REPORT_LEN - 5; +const RESPONSE_DATA_LEN: usize = REPORT_LEN - 11; const REPORT_DESCRIPTOR: &[u8] = &[ 0x05, 0x01, 0x09, 0x06, 0xA1, 0x01, 0x05, 0x07, 0x19, 0xE0, 0x29, 0xE7, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 0x81, 0x02, 0x95, 0x01, 0x75, 0x08, 0x81, 0x03, 0x95, 0x05, 0x75, 0x01, @@ -24,7 +25,10 @@ const REPORT_DESCRIPTOR: &[u8] = &[ 0x75, 0x08, 0x95, 0x40, 0xB1, 0x02, 0xC0, ]; -big_array! { BigArray; COMMAND_LEN, REQUEST_DATA_LEN, } +pub type RequestData = [u8; REQUEST_DATA_LEN]; +pub type ResponseData = [u8; RESPONSE_DATA_LEN]; + +big_array! { BigArray; RESPONSE_DATA_LEN, REQUEST_DATA_LEN, } enum_u8! { #[derive(Clone, Copy, Debug, PartialEq)] @@ -57,7 +61,7 @@ enum_u8! { struct Request { pub command_id: u8, #[serde(with = "BigArray")] - pub data: [u8; REQUEST_DATA_LEN], + pub data: RequestData, pub crc: u32, } @@ -68,7 +72,7 @@ struct Response { pub last_crc: u32, pub command_status: CommandStatus, #[serde(with = "BigArray")] - pub data: [u8; COMMAND_LEN], + pub data: ResponseData, pub crc: u32, } @@ -79,7 +83,7 @@ impl Response { command_id, last_crc, command_status: CommandStatus::NotSupported, - data: [0; COMMAND_LEN], + data: [0; RESPONSE_DATA_LEN], crc: 0, } } |