greatscottgadgets / facedancer

Implement your own USB device in Python, supported by a hardware peripheral such as Cynthion or GreatFET
BSD 3-Clause "New" or "Revised" License
785 stars 119 forks source link

Revise the descriptor API #126

Closed martinling closed 1 week ago

martinling commented 2 weeks ago

An attempt to fix #125.

The key change here is the new include_in_config property of USBDescriptor, which specifies whether the descriptor should be included in a GET_CONFIGURATION response.

Descriptors with this property set to True will appear following their parent in the GET_CONFIGURATION response, in the same order in which they were added with the add_descriptor() method. They will not be fetchable with a GET_DESCRIPTOR request, and do not require the number property to be set.

Descriptors with this property set to False will not be included in a GET_CONFIGURATION response. They can be fetched with a GET_DESCRIPTOR request, and must have the number property set to an integer value, so that they can be retrieved by the identifying tuple of (type_number, number).

The USBClassDescriptor class is deprecated, but retained for backwards compatibility. It now simply sets include_in_config to True.

Stacked on #122 for now.

martinling commented 1 week ago

This is dependent on #122 but otherwise ready to go.

martinling commented 1 week ago

Rebased now that #122 is merged.