diff --git a/embassy-usb/src/class/msc/subclass/scsi/bitfield.rs b/embassy-usb/src/class/msc/subclass/scsi/bitfield.rs deleted file mode 100644 index 8bed7228..00000000 --- a/embassy-usb/src/class/msc/subclass/scsi/bitfield.rs +++ /dev/null @@ -1,132 +0,0 @@ -use core::marker::PhantomData; - -pub trait Packet { - fn data(&self) -> &[u8]; - fn data_mut(&mut self) -> &mut [u8]; - - #[inline] - fn get(&self, field: &F) -> F::T { - field.get(self.data()) - } - - #[inline] - fn set(&mut self, field: &F, val: F::T) { - field.set(self.data_mut(), val) - } -} - -pub trait AsPacketField { - type T; - - fn get(&self, data: &[u8]) -> Self::T; - fn set(&self, data: &mut [u8], val: Self::T); -} - -pub struct BitField { - pub byte: usize, - pub bit: u8, - pub mask: u8, -} - -impl BitField { - pub const fn new(byte: usize, bit: u8, size: u8) -> Self { - let mask = (0xFF >> size) << bit; - Self { byte, bit, mask } - } -} - -impl AsPacketField for BitField { - type T = u8; - - #[inline] - fn get(&self, data: &[u8]) -> Self::T { - (data[self.byte] & self.mask) >> self.bit - } - - #[inline] - fn set(&self, data: &mut [u8], val: Self::T) { - data[self.byte] = (val << self.bit) | (data[self.byte] & !self.mask) - } -} - -pub struct BoolField { - pub byte: usize, - pub bit: u8, -} - -impl BoolField { - pub const fn new(byte: usize, bit: u8) -> Self { - Self { byte, bit } - } -} - -impl AsPacketField for BoolField { - type T = bool; - - #[inline] - fn get(&self, data: &[u8]) -> Self::T { - data[self.byte] & (1 << self.bit) != 0 - } - - #[inline] - fn set(&self, data: &mut [u8], val: Self::T) { - data[self.byte] = ((val as u8) << self.bit) | (data[self.byte] & !(1 << self.bit)) - } -} - -pub struct Field { - pub byte: usize, - _phantom: PhantomData, -} - -impl Field { - pub const fn new(byte: usize) -> Self { - Self { - byte, - _phantom: PhantomData, - } - } -} - -impl AsPacketField for Field { - type T = T; - - #[inline] - fn get(&self, data: &[u8]) -> Self::T { - unsafe { core::ptr::read(data.as_ptr().offset(self.byte as _) as *const T) } - } - - #[inline] - fn set(&self, data: &mut [u8], val: Self::T) { - unsafe { core::ptr::write(data.as_mut_ptr().offset(self.byte as _) as *mut T, val) } - } -} - -#[cfg(test)] -mod tests { - use super::{AsPacketField, BitField, BoolField}; - - #[test] - fn bitfield() { - let field = BitField::new(0, 4, 3); - - let mut data = [0b1111_1111]; - assert_eq!(field.get(&data), 0b111); - - field.set(&mut data, 0b000); - assert_eq!(field.get(&data), 0b000); - assert_eq!(data, [0b1000_1111]); - } - - #[test] - fn boolfield() { - let field = BoolField::new(0, 5); - - let mut data = [0b1111_1111]; - assert_eq!(field.get(&data), true); - - field.set(&mut data, false); - assert_eq!(field.get(&data), false); - assert_eq!(data, [0b1101_1111]); - } -} diff --git a/embassy-usb/src/class/msc/subclass/scsi/commands/control.rs b/embassy-usb/src/class/msc/subclass/scsi/commands/control.rs index 0aeb2683..806fac8f 100644 --- a/embassy-usb/src/class/msc/subclass/scsi/commands/control.rs +++ b/embassy-usb/src/class/msc/subclass/scsi/commands/control.rs @@ -1,14 +1,3 @@ -// #[bitfield(bytes = 1)] -// #[derive(BitfieldSpecifier)] -// pub struct Control { -// pub vendor_specific: B2, -// #[skip] -// __: B3, -// pub naca: B1, -// #[skip] -// __: B2, -// } - use crate::packed_struct; packed_struct! { diff --git a/embassy-usb/src/class/msc/subclass/scsi/commands/inquiry.rs b/embassy-usb/src/class/msc/subclass/scsi/commands/inquiry.rs index 59165d19..ac557d0d 100644 --- a/embassy-usb/src/class/msc/subclass/scsi/commands/inquiry.rs +++ b/embassy-usb/src/class/msc/subclass/scsi/commands/inquiry.rs @@ -1,21 +1,3 @@ -// use super::control::Control; - -// #[bitfield(bytes = 6)] -// pub struct InquiryCommand { -// /// Always 0x12 -// pub op_code: B8, -// #[skip] -// __: B7, -// /// If set, return vital data related to the page_code field -// pub enable_vital_product_data: B1, -// /// What kind of vital data to return -// pub page_code: B8, -// /// Amount of bytes allocation for data-in transfer -// pub allocation_length: B16, -// /// Control byte -// pub control: Control, -// } - use super::Control; use crate::class::msc::subclass::scsi::enums::{ PeripheralDeviceType, PeripheralQualifier, ResponseDataFormat, SpcVersion, TargetPortGroupSupport, diff --git a/embassy-usb/src/class/msc/subclass/scsi/commands/mod.rs b/embassy-usb/src/class/msc/subclass/scsi/commands/mod.rs index e679e7bd..a0670d73 100644 --- a/embassy-usb/src/class/msc/subclass/scsi/commands/mod.rs +++ b/embassy-usb/src/class/msc/subclass/scsi/commands/mod.rs @@ -1,6 +1,3 @@ -// `bytes` in `#[bitfield(bytes = 6)]` causes a warning -#![allow(redundant_semicolons)] - mod control; pub use control::*;