diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2019-02-20 11:32:59 +0000 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2019-02-20 12:50:15 +0100 |
commit | 990063fb3ecfc6baeb51e4f57b3f75ee16bac56e (patch) | |
tree | 7c83c6381210bf5223a13fd43b3731d401bdfd02 /src | |
parent | 1e127de5173e3b8fb62efc79f97651ca22694441 (diff) | |
download | ntw-990063fb3ecfc6baeb51e4f57b3f75ee16bac56e.tar.gz ntw-990063fb3ecfc6baeb51e4f57b3f75ee16bac56e.tar.bz2 |
Rename commands::COMMAND_LEN to device::RESPONSE_DATA_LEN
Previously, we had the device::REQUEST_DATA_LEN constant for the size of
the raw data in the request, and the commands::COMMAND_LEN constant for
the size of the raw data in the response. This patch renames
commands::COMMAND_LEN to device::RESPONSE_DATA_LEN for consistency. It
also introduces the {Request,Response}Data type aliases for [u8;
{REQUEST,RESPONSE}_DATA_LEN].
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, } } |