FAQ
I sent this to modules@perl.org, but didn't get a response. So, I'm trying here.

My day job has me manually creating descriptors for USB devices more often than I care to, so I've created a module for auto-generating said descriptors. The resulting object tree can then be output as a structure suitable for compiling, or assembling, into a device's firmware. Where in the namespace hierarchy should I put these objects?

For the moment I'm using USB::Descriptor::Device, USB::Descriptor::Interface and so on. Eventually I'll also have USB::HID::Descriptor::Device, etc. But, it seems there is no USB namespace in CPAN. I see that packages that represent, or interface with, specific devices live under Device::, and Device::USB in particular. However, that doesn't seem like a proper home for a module that deals with concepts at the specification level, as opposed to interacting with a particular connected device. That, and Device::USB::Descriptor::Device seems a little silly.

Suggestions? Thoughts? Any problems with me creating a top level USB namespace?

Search Discussions

  • David Cantrell at Aug 3, 2011 at 10:24 am

    On Mon, Aug 01, 2011 at 10:59:35AM -0700, Brandon Fosdick wrote:

    My day job has me manually creating descriptors for USB devices more often than I care to, so I've created a module for auto-generating said descriptors. The resulting object tree can then be output as a structure suitable for compiling, or assembling, into a device's firmware. Where in the namespace hierarchy should I put these objects?

    For the moment I'm using USB::Descriptor::Device, USB::Descriptor::Interface and so on. Eventually I'll also have USB::HID::Descriptor::Device, etc. But, it seems there is no USB namespace in CPAN. I see that packages that represent, or interface with, specific devices live under Device::, and Device::USB in particular. However, that doesn't seem like a proper home for a module that deals with concepts at the specification level, as opposed to interacting with a particular connected device. That, and Device::USB::Descriptor::Device seems a little silly.

    Suggestions? Thoughts? Any problems with me creating a top level USB namespace?
    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.

    --
    David Cantrell | Nth greatest programmer in the world

    The children now love luxury; they have bad manners, contempt for
    authority; they show disrespect for elders and love chatter in place
    of exercise. Children are now tyrants, not the servants of their
    households. They no longer rise when elders enter the room. They
    contradict their parents, chatter before company, gobble up dainties
    at the table, cross their legs, and tyrannize their teachers.
    -- attributed by Plato to Socrates
  • Brandon Fosdick at Aug 5, 2011 at 9:17 pm

    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?

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupmodule-authors @
categoriesperl
postedAug 1, '11 at 5:59p
activeAug 5, '11 at 9:17p
posts3
users2
websitecpan.org...

2 users in discussion

Brandon Fosdick: 2 posts David Cantrell: 1 post

People

Translate

site design / logo © 2021 Grokbase