Skip to content

Commit

Permalink
moondancer: add microsoft os 1.0 descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinevg committed Aug 16, 2024
1 parent 64e03a2 commit bd7aa29
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 13 deletions.
34 changes: 24 additions & 10 deletions firmware/moondancer/src/bin/moondancer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,27 @@ impl<'a> Firmware<'a> {
let usb2_control = Control::<_, LIBGREAT_MAX_COMMAND_SIZE>::new(
0,
Descriptors {
// required
device_speed: DEVICE_SPEED,
device_descriptor: smolusb::descriptor::DeviceDescriptor {
bcdDevice: bcd_device,
..moondancer::usb::DEVICE_DESCRIPTOR
},
configuration_descriptor: moondancer::usb::CONFIGURATION_DESCRIPTOR_0,
string_descriptor_zero: moondancer::usb::STRING_DESCRIPTOR_0,
string_descriptors,
// optional
device_qualifier_descriptor: Some(moondancer::usb::DEVICE_QUALIFIER_DESCRIPTOR),
other_speed_configuration_descriptor: Some(
moondancer::usb::OTHER_SPEED_CONFIGURATION_DESCRIPTOR_0,
),
device_qualifier_descriptor: Some(moondancer::usb::DEVICE_QUALIFIER_DESCRIPTOR),
string_descriptor_zero: moondancer::usb::STRING_DESCRIPTOR_0,
//string_descriptors: unsafe { &*core::ptr::addr_of!(STRING_DESCRIPTORS) },
string_descriptors,
microsoft10: Some(smolusb::descriptor::microsoft10::Descriptors {
string_descriptor: moondancer::usb::STRING_DESCRIPTOR_0XEE,
compat_id_feature_descriptor:
moondancer::usb::MS_OS_10_COMPATIBLE_ID_FEATURE_DESCRIPTOR,
extended_properties_feature_descriptor:
moondancer::usb::MS_OS_10_EXTENDED_PROPERTIES_FEATURE_DESCRIPTOR,
}),
},
);

Expand Down Expand Up @@ -343,9 +351,13 @@ impl<'a> Firmware<'a> {
let vendor_request = VendorRequest::from(setup_packet.request);
let vendor_value = VendorValue::from(setup_packet.value);

debug!(
log::debug!(
"handle_vendor_request: {:?} {:?} {:?} {:?} {:?}",
request_type, recipient, direction, vendor_request, vendor_value
request_type,
recipient,
direction,
vendor_request,
vendor_value
);

match (&request_type, &recipient, &vendor_request) {
Expand Down Expand Up @@ -504,11 +516,13 @@ impl<'a> Firmware<'a> {
Ok(())
}

fn dispatch_libgreat_response(&mut self, _setup_packet: SetupPacket) -> GreatResult<()> {
fn dispatch_libgreat_response(&mut self, setup_packet: SetupPacket) -> GreatResult<()> {
let requested_length = setup_packet.length as usize;

// do we have a response ready?
if let Some(response) = &mut self.libgreat_response {
// send response
self.usb2.write(0, response);
self.usb2.write_requested(0, requested_length, response);

// clear cached response
self.libgreat_response = None;
Expand Down Expand Up @@ -536,8 +550,6 @@ impl<'a> Firmware<'a> {
}

fn dispatch_libgreat_abort(&mut self, _setup_packet: SetupPacket) -> GreatResult<()> {
error!("dispatch_libgreat_response abort");

// send an arbitrary error code if we're aborting mid-response
if let Some(_response) = &self.libgreat_response {
// prime to receive host zlp - TODO should control do this in send_complete?
Expand All @@ -551,6 +563,8 @@ impl<'a> Firmware<'a> {
self.libgreat_response = None;
self.libgreat_response_last_error = None;

error!("dispatch_libgreat_response abort");

Ok(())
}
}
30 changes: 27 additions & 3 deletions firmware/moondancer/src/usb.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::hal::smolusb;

use smolusb::descriptor::{
ConfigurationDescriptor, ConfigurationDescriptorHeader, DescriptorType, DeviceDescriptor,
DeviceQualifierDescriptor, EndpointDescriptor, InterfaceDescriptor, InterfaceDescriptorHeader,
LanguageId, StringDescriptor, StringDescriptorZero,
microsoft10, ConfigurationDescriptor, ConfigurationDescriptorHeader, DescriptorType,
DeviceDescriptor, DeviceQualifierDescriptor, EndpointDescriptor, InterfaceDescriptor,
InterfaceDescriptorHeader, LanguageId, StringDescriptor, StringDescriptorZero,
};

// - vendor request -----------------------------------------------------------
Expand Down Expand Up @@ -200,6 +200,26 @@ pub static OTHER_SPEED_CONFIGURATION_DESCRIPTOR_0: ConfigurationDescriptor =
],
);

pub const COMPATIBLE_ID: [u8; 8] = *b"WINUSB\0\0";

pub const MS_OS_10_COMPATIBLE_ID_FEATURE_DESCRIPTOR: microsoft10::CompatibleIdFeatureDescriptor =
microsoft10::CompatibleIdFeatureDescriptor::new(&[
microsoft10::CompatibleIdFeatureDescriptorFunction {
bFirstInterfaceNumber: 0,
aCompatibleId: COMPATIBLE_ID,
..microsoft10::CompatibleIdFeatureDescriptorFunction::new()
},
microsoft10::CompatibleIdFeatureDescriptorFunction {
bFirstInterfaceNumber: 1,
aCompatibleId: COMPATIBLE_ID,
..microsoft10::CompatibleIdFeatureDescriptorFunction::new()
},
]);

pub const MS_OS_10_EXTENDED_PROPERTIES_FEATURE_DESCRIPTOR:
microsoft10::ExtendedPropertiesFeatureDescriptor =
microsoft10::ExtendedPropertiesFeatureDescriptor::new();

pub static STRING_DESCRIPTOR_0: StringDescriptorZero =
StringDescriptorZero::new(&[LanguageId::EnglishUnitedStates]);

Expand All @@ -226,6 +246,10 @@ pub static STRING_DESCRIPTOR_8: StringDescriptor = StringDescriptor::new("other
// interface #1
pub static STRING_DESCRIPTOR_9: StringDescriptor = StringDescriptor::new("other interface1");

// microsoft os 1.0 string descriptor
pub static STRING_DESCRIPTOR_0XEE: microsoft10::StringDescriptor =
microsoft10::StringDescriptor::new(microsoft10::VendorRequest::Microsoft);

pub static STRING_DESCRIPTORS: &[&StringDescriptor] = &[
&STRING_DESCRIPTOR_1,
&STRING_DESCRIPTOR_2,
Expand Down

0 comments on commit bd7aa29

Please sign in to comment.