On Thursday 04 January 2007 16:14, polly wrote:
> Hello,
> This is a bit of a puzzle, trying to locate decriptors in flas seems to
> result in
> byte swapping ...
>
> typedef unsigned char byte;
> typedef unsigned int word;
> [....]
Hrm, which µC? PIC16 Port?
and what exactly goes wrong?
Here's a code snippet I use for USB-Descriptors on a pic18f2550 with sdcc,
maybe its of use to you:
...
in .h:
typedef struct _DeviceDescriptor
{
uint8_t bLength;
uint8_t bDescriptorType; // == DEVICE_DESCRIPTOR
uint16_t bcdUSB; // Version
uint8_t bDeviceClass;
uint8_t bDeviceSubClass;
uint8_t bDeviceProtocol;
uint8_t bMaxPacketSize;
uint16_t idVendor;
uint16_t idProduct;
uint16_t bcdDevice;
uint8_t iManufacturer;
uint8_t iProduct;
uint8_t iSerial;
uint8_t bNumConfigurations;
} DeviceDescriptor;
typedef struct _ConfigurationDescriptor
{
uint8_t bLength;
uint8_t bDescriptorType; // == CONFIGURATION_DESCRIPTOR
uint16_t wTotalLength;
uint8_t bNumInterfaces;
uint8_t bConfigurationValue;
uint8_t iConfiguration;
uint8_t bmAttributes;
uint8_t bMaxPower;
} ConfigurationDescriptor;
typedef struct _InterfaceDescriptor
{
uint8_t bLength;
uint8_t bDescriptorType; // == INTERFACE_DESCRIPTOR
uint8_t bID;
uint8_t bAlternateSetting;
uint8_t bNumEndpoints;
uint8_t bInterfaceClass;
uint8_t bInterfaceSubClass;
uint8_t bInterfaceProtocol;
uint8_t iInterface;
} InterfaceDescriptor;
typedef struct _EndpointDescriptor
{
uint8_t bLength;
uint8_t bDescriptorType; // == ENDPOINT_DESCRIPTOR
uint8_t bEndpointAddr;
uint8_t bmAttributes;
uint16_t wMaxPacketSize;
uint8_t bInterval;
} EndpointDescriptor;
....
in .c file:
....
code DeviceDescriptor deviceDescriptor =
{
sizeof(deviceDescriptor), // bLength,
DEVICE_DESCRIPTOR, // bDescriptorType
0x0200, // bcdUSB
0x02, 0x00, // bDeviceClass, bDeviceSubClass
0x00, EP0_SIZE, // bDeviceProtocl, bMaxPacketSize
0x6666, // idVendor
0x0815, // idProduct
0x0001, // bcdDevice
0x01, 0x02, // iManufacturer, iProduct
0x03, 0x01 // iSerialNumber (none), bNumConfigurations
};
typedef struct _CounterConfigDesc
{
ConfigurationDescriptor configDesc;
InterfaceDescriptor ctrlInterfaceDesc;
CDC_HeaderFunctionalDescriptor cdcHeaderFunction;
CDC_ACMFunctionalDescriptor cdcAcmFunction;
CDC_UnionFunctionalDescriptor cdcUnionFunction;
CDC_CallManagementFunctionalDescriptor cdcCallFunction;
EndpointDescriptor ep02inDesc;
InterfaceDescriptor dataInterfaceDesc;
EndpointDescriptor ep03outDesc;
EndpointDescriptor ep03inDesc;
} CounterConfigDesc;
code CounterConfigDesc configDescriptor =
{
{
// Configuration descriptor
sizeof(ConfigurationDescriptor), CONFIGURATION_DESCRIPTOR, // bLength,
bDescriptorType (Configuration)
sizeof(configDescriptor), // wTotalLength
0x02, 0x01, // bNumInterfaces, bConfigurationValue
0x04, 0x80, // iConfiguration, bmAttributes ()
0x32 // bMaxPower
},
{
// COMM interface descriptor
sizeof(InterfaceDescriptor), INTERFACE_DESCRIPTOR, // bLength,
bDescriptorType (Interface)
0x00, 0x00, // ID, AlternateSettings
0x01, // # of Endpoints
CDC_COMM_INTERFACE, // class
CDC_ABSTRACT_CONTROL_MODEL, // Subclass
CDC_V25TER, // Protocol
0x05 // iInterface
},
{
// CDC Header Function Desc
sizeof(CDC_HeaderFunctionalDescriptor),
CDC_INTERFACE_DESCRIPTOR, // DescriptorType
CDC_HEADER_FD, // Subtype CDC Header Functional Descriptor
0x0110 // Version of CDC Std document used
},
{
// CDC ACM Function Desc
sizeof(CDC_ACMFunctionalDescriptor),
CDC_INTERFACE_DESCRIPTOR, // DescriptorType
CDC_ACM_FD, // Subtype CDC ACM Functional Descriptor
0x02 // Supported Functions: Set_Line_Coding, Serial State et all.
},
{
// CDC Union Function Desc
sizeof(CDC_UnionFunctionalDescriptor),
CDC_INTERFACE_DESCRIPTOR, // DescriptorType
CDC_UNION_FD, // Subtype CDC UNION Functional Descriptor
0, // Interface 0 (Comm) is Master
1, // Interface 1 (Data) is Slave
},
{
// CDC Call Management Function Desc
sizeof(CDC_CallManagementFunctionalDescriptor),
CDC_INTERFACE_DESCRIPTOR, // DescriptorType
CDC_CALL_MGMT_FD, // Subtype CDC Call Management Functional Descriptor
0x01, // Capabilities: Call management by device
1 // Interface 1 (Data) is used for Calls
},
{
// Endpoint Descriptor EP2_IN (PIC->PC)
sizeof(EndpointDescriptor), ENDPOINT_DESCRIPTOR, // bLength,
bDescriptorType (Endpoint)
0x82, // bEndpointAddr (2, IN)
EP_INT, // bmAttributes
0x08, // EP Size
0x05 // Interval
},
{
// DATA interface descriptor
sizeof(InterfaceDescriptor), INTERFACE_DESCRIPTOR, // bLength,
bDescriptorType (Interface)
0x01, 0x00, // ID, AlternateSettings
0x02, // # of Endpoints
CDC_DATA_INTERFACE, // class
0x00, // Subclass
CDC_NO_PROTOCOL, // protocol
0x06 // iInterface
},
{
// Endpoint Descriptor EP3_IN (PIC->PC)
sizeof(EndpointDescriptor), ENDPOINT_DESCRIPTOR, // bLength,
bDescriptorType (Endpoint)
0x83, // bEndpointAddr (3, IN)
EP_BULK, // bmAttributes
0x08, // EP Size
0x00 // Interval
},
{
// Endpoint Descriptor EP3_OUT (pc->PIC)
sizeof(EndpointDescriptor), ENDPOINT_DESCRIPTOR, // bLength,
bDescriptorType (Endpoint)
0x03, // bEndpointAddr (3, OUT)
EP_BULK, // bmAttributes
0x08, // EP Size
0x00 // Interval
}
};
/Ernst
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user