diff options
Diffstat (limited to 'usbh')
-rwxr-xr-x | usbh/src/lib.rs | 12 | ||||
-rw-r--r-- | usbh/src/pipe.rs | 8 | ||||
-rw-r--r-- | usbh/src/usbproto.rs | 20 |
3 files changed, 20 insertions, 20 deletions
diff --git a/usbh/src/lib.rs b/usbh/src/lib.rs index 8f6f0d8..a38ae87 100755 --- a/usbh/src/lib.rs +++ b/usbh/src/lib.rs @@ -401,7 +401,7 @@ where // addr: 0x20007774 let tmp: USBDeviceDescriptor = Default::default(); // addr: 0x20007788 - let vol_descr = ::vcell::VolatileCell::new(tmp); + let mut vol_descr = ::vcell::VolatileCell::new(tmp); self.control_req( 0, 0, @@ -409,7 +409,7 @@ where USBRequest::GetDescriptor, WValue::from((0, USBDescriptor::Device as u8)), 0, - Some(DataBuf::from(&vol_descr)), + Some(DataBuf::from(&mut vol_descr)), )?; let desc = vol_descr.get(); @@ -435,7 +435,7 @@ where info!("getting config with array"); //let tmp: USBConfigurationDescriptor = Default::default(); - let tmp: [u8; 9] = [0; 9]; + let mut tmp: [u8; 9] = [0; 9]; //let vol_descr = ::vcell::VolatileCell::new(tmp); self.control_req( new_address, @@ -444,7 +444,7 @@ where USBRequest::GetConfiguration, WValue::from((0, 0)), 0, - Some(DataBuf::from(&tmp)), + Some(DataBuf::from(&mut tmp)), )?; //let desc = vol_descr.get(); @@ -487,7 +487,7 @@ where /* * Setup stage. */ - let setup_packet = USBSetupPacket { + let mut setup_packet = USBSetupPacket { bm_request_type: bm_request_type, b_request: b_request, w_value: w_value, @@ -500,7 +500,7 @@ where let mut pipe = self.pipe_table.pipe_for(self.usb.host_mut(), addr, ep); pipe.send( USBToken::Setup, - &DataBuf::from(&setup_packet), + &DataBuf::from(&mut setup_packet), NAK_LIMIT, self.millis, )?; diff --git a/usbh/src/pipe.rs b/usbh/src/pipe.rs index 75923ba..e84b898 100644 --- a/usbh/src/pipe.rs +++ b/usbh/src/pipe.rs @@ -345,7 +345,7 @@ pub(crate) enum USBPipeType { } pub(crate) struct DataBuf<'a> { - pub(crate) ptr: *const u8, + pub(crate) ptr: *mut u8, pub(crate) len: usize, _marker: core::marker::PhantomData<&'a ()>, } @@ -363,10 +363,10 @@ impl core::fmt::Debug for DataBuf<'_> { } } -impl<'a, T> From<&'a T> for DataBuf<'a> { - fn from(v: &'a T) -> Self { +impl<'a, T> From<&'a mut T> for DataBuf<'a> { + fn from(v: &'a mut T) -> Self { Self { - ptr: v as *const T as *const u8, + ptr: v as *mut T as *mut u8, len: core::mem::size_of::<T>(), _marker: core::marker::PhantomData, } diff --git a/usbh/src/usbproto.rs b/usbh/src/usbproto.rs index 246a9a4..97d1839 100644 --- a/usbh/src/usbproto.rs +++ b/usbh/src/usbproto.rs @@ -347,7 +347,7 @@ mod test { #[test] fn dev_desc_serialize() { - let desc = USBDeviceDescriptor { + let mut desc = USBDeviceDescriptor { b_length: 18, b_descriptor_type: USBDescriptor::Device, bcd_usb: 0x0110, @@ -363,7 +363,7 @@ mod test { i_serial_number: 0xa2, b_num_configurations: 1, }; - let db = DataBuf::from(&desc); + let db = DataBuf::from(&mut desc); assert_eq!(db.len, 18); let want = [ 0x12, 0x01, 0x10, 0x01, 0x02, 0x03, 0x04, 64, 0xad, 0xde, 0xef, 0xbe, 0x32, 0x54, 0xa0, @@ -375,7 +375,7 @@ mod test { #[test] fn config_desc_serialize() { - let desc = USBConfigurationDescriptor { + let mut desc = USBConfigurationDescriptor { b_length: 18, b_descriptor_type: USBDescriptor::Configuration, w_total_length: 0x20, @@ -385,7 +385,7 @@ mod test { bm_attributes: 0x40, b_max_power: 0xfa, }; - let db = DataBuf::from(&desc); + let db = DataBuf::from(&mut desc); assert_eq!(db.len, 9); let want = [0x12, 0x02, 0x20, 0x00, 0x05, 0x0a, 0x01, 0x40, 0xfa]; let got = unsafe { core::slice::from_raw_parts(db.ptr, db.len) }; @@ -394,7 +394,7 @@ mod test { #[test] fn interface_desc_serialize() { - let desc = USBInterfaceDescriptor { + let mut desc = USBInterfaceDescriptor { b_length: 18, b_descriptor_type: USBDescriptor::Interface, b_interface_number: 2, @@ -405,7 +405,7 @@ mod test { b_interface_protocol: 0x33, i_interface: 10, }; - let db = DataBuf::from(&desc); + let db = DataBuf::from(&mut desc); assert_eq!(db.len, 9); let want = [0x12, 0x04, 0x02, 0xaa, 0x05, 0x11, 0x22, 0x33, 0x0a]; let got = unsafe { core::slice::from_raw_parts(db.ptr, db.len) }; @@ -414,7 +414,7 @@ mod test { #[test] fn endpoint_desc_serialize() { - let desc = USBEndpointDescriptor { + let mut desc = USBEndpointDescriptor { b_length: 18, b_descriptor_type: USBDescriptor::Endpoint, b_endpoint_address: 1, @@ -422,7 +422,7 @@ mod test { w_max_packet_size: 0xdead, b_interval: 0x33, }; - let db = DataBuf::from(&desc); + let db = DataBuf::from(&mut desc); assert_eq!(db.len, 7); let want = [0x12, 0x05, 0x01, 0x22, 0xad, 0xde, 0x33]; let got = unsafe { core::slice::from_raw_parts(db.ptr, db.len) }; @@ -431,14 +431,14 @@ mod test { #[test] fn setup_packet_serialize() { - let setup_packet = USBSetupPacket { + let mut setup_packet = USBSetupPacket { bm_request_type: BMRequestType::get_descr(), b_request: USBRequest::GetDescriptor, w_value: WValue::from((0x00, 0x01)), w_index: 0xbeef, w_length: 18, }; - let db = DataBuf::from(&setup_packet); + let db = DataBuf::from(&mut setup_packet); assert_eq!(db.len, 8); let want = [0x80, 0x06, 0x00, 0x01, 0xef, 0xbe, 0x012, 0x00]; let got = unsafe { core::slice::from_raw_parts(db.ptr, db.len) }; |