On 07/22/64 11:59 , David Cantrell wrote:
> I'd have thought that Device::USB::Descriptor would be a good place, with no 
> need for a further ::Device. Underneath that you could have things like 
> D::U::Descriptor::HID, D::U::Descriptor::Storage or whatever. 

Actually, a USB descriptor set is a tree of objects, so there is a need for 
other objects under ::Descriptor (such as ::Device). In general there can also 
be class-specific descriptors for the different device classes as well as 
class-specific versions of the generic descriptors.

A generic USB device has one ::Device descriptor that can then have one or more 
::Configuration descriptor children. Each ::Configuration descriptor can have 
::Interface descriptor children, each of which can have ::Endpoint descriptors. 
The various device classes can add additional descriptors to the tree. For 
instance, HID appends a ::Class descriptor to the end of the ::Interface 
descriptor, and then requires the ::Interface to indicate the existence of the 
trailing ::Class descriptor. The existence of the HID::Class descriptor 
triggers the host to ask for HID::Report descriptors, which come in a enough 
variety to make a cladist weep. All of these myriad descriptors have fields 
that must be specified by the firmware developer.

Given all of that, my plan is to do something like the following, unless 
someone has a better way of organizing things...

USB::Descriptor::Device              # Device descriptor
USB::Descriptor::Configuration   # Configuration descriptor
USB::Descriptor::Interface           # ...
USB::Descriptor::Endpoint
USB::HID::Descriptor::Interface
USB::HID::Descriptor::Class
USB::HID::Report::*
USB::<DeviceClass>::*
...

With that said, I haven't yet decided if I'd prefer to organize the device 
classes under ::Descriptor or have ::Descriptor under each device class (e.g. 
::Descriptor::HID::* vs ::HID::Descriptor::*.) The HID space could grow rather 
large all by itself and the other classes all have their own sets of descriptor 
objects as well. I'm leaning towards putting ::Descriptor under the device 
classes (::HID::Descriptor::*) because the descriptors for a given device class 
are specific to that class, rather than the device class being specific to the 
descriptors.

In case an example will make things more clear,  here's a descriptor for a 
simple fictional device that I've been using for testing...

use USB::Descriptor::Device;

# Test constructor
my $device =
   USB::Descriptor::Device->new(
       'usb_version'         => '1.2.3',
       'max_packet_size' => 64,
       'configurations'     => [ USB::Descriptor::Configuration->new(
           'description'          => 'Configuration 0',
           'remote_wakeup'   => 1,
           'max_current'        => 100,   # mA
           'interfaces'            => [ USB::Descriptor::Interface->new(
               'description'          => 'Interface 0',
               'endpoints'            => [ USB::Descriptor::Endpoint->new(
                   'direction'          => 'in',
                   'number'            => 1,
                   'max_packet_size'   => 64,
               )],
       )],
       )],
   );

# Test accessors
$device->vendorID(0x0C16);    # Movea
$device->productID(0xFF);       # test product
$device->manufacturer('Movea');
$device->product('Test Product');
$device->serial_number('0');


So, to reiterate, my questions are:
1) Is there a better way to organize all of these objects?
2) Should the descriptor object tree be rooted under Device::USB or should it 
be under USB::?

Any thoughts?

Reply via email to