how to make usb composite device

hds2g
Member
posted October 18, 2006 10:09 AM     Click Here to See the Profile for hds2g   Click Here to Email hds2g     Edit/Delete Message
hello..

I want to make two function usb device..

one function is HID mouse
the other function is specific application(64bytes interrupt transter)

Is it possible with only one device(C8051F321)??


and..


Is it possible usb composite device with C8051F321?

If possible, how to make composite device?

thank you..

[This message has been edited by hds2g (edited October 18, 2006).]

IP: Logged

Tsuneo
Member
posted October 18, 2006 11:17 AM     Click Here to See the Profile for Tsuneo   Click Here to Email Tsuneo     Edit/Delete Message
"Is it possible usb composite device with C8051F321?"

Yes, it is realized by a combination of two HID class.
HID mouse + vender-specific HID

Start with the SiLabs mouse example
c:\SiLabs\MCU\Examples\C8051F32x\USB_HID\MouseExample

- Add another Interface + HID class + Endpoint(s) descriptor for vender-specific HID.
- Add another report descriptor for vender-specific HID
- Modify these request
- - Set_Configuration - Add endpoint(s) initialization for additional endpoint(s)
- - Get_Descriptor - Add handling for additional HID class and report descriptor
- - Get_Interface and Set_Interface to support additional interface.
- - Get_Report - mandatory for HID, but may not used by the application.
- Add handling for the endpoint of vender-specific HID

See this SiLabs former HID example for simple vender specific HID
HID_Example_1_0.zip

It's a good exercise to implement a HID class

Tsuneo

[This message has been edited by Tsuneo (edited October 18, 2006).]

IP: Logged

hds2g
Member
posted October 18, 2006 08:40 PM     Click Here to See the Profile for hds2g   Click Here to Email hds2g     Edit/Delete Message
thanks for your reply..

I implement vendor-specific firmware.
and..
also implement mouse..

not exist two HID device?

and..

one function is HID

other function is not HID(I/O device)

Is it possible?

only two HID device?

IP: Logged

Tsuneo
Member
posted October 19, 2006 01:57 AM     Click Here to See the Profile for Tsuneo   Click Here to Email Tsuneo     Edit/Delete Message
Use of HID protocol is not limited to human interface, like mouse and keyboard.
HID is also applied to I/O device.
For example, SiLabs USB debug adapter is established on HID.
Did you run SiLabs former HID_Example?
What it's doing is just I/O device.

If you don't apply HID, you should write a custom device driver.

Tsuneo

[This message has been edited by Tsuneo (edited October 19, 2006).]

IP: Logged

hds2g
Member
posted October 19, 2006 07:47 AM     Click Here to See the Profile for hds2g   Click Here to Email hds2g     Edit/Delete Message
- Add another Interface + HID class + Endpoint(s) descriptor for vender-specific HID.
- Add another report descriptor for vender-specific HID
- Modify these request
- - Set_Configuration - Add endpoint(s) initialization for additional endpoint(s)
- - Get_Descriptor - Add handling for additional HID class and report descriptor
- - Get_Interface and Set_Interface to support additional interface.
- - Get_Report - mandatory for HID, but may not used by the application.
- Add handling for the endpoint of vender-specific HID


I'don't know modify..

how to modify..?

not exist example?

IP: Logged

Tsuneo
Member
posted October 19, 2006 02:42 PM     Click Here to See the Profile for Tsuneo   Click Here to Email Tsuneo     Edit/Delete Message
Is this a commercial product development or your personal project?
I remember you are working on USB_INT example.

The reason I ask you this question is,

a) commercial product development
I recommend you HID (mouse) + vendor-specific HID

- You can use Windows built-in HID device driver and default INF file for both functions. Therefore, no need to develop / distribute / install / maintain the device driver.
- As the result, you don't need to pass your driver/INF to WHQL certification, to avoid the infamous 'Not Certified' warning dialog on the installation.

- The code amount increases in both of the firmware and the host application. I suppose the difference is 100-150 lines or so, in both side.
- You must learn HID handling on both side.


b) personal project
I recommend you HID (mouse) + USB_INT

- I suppose you've finished your project based on USB_INT. Then, it is easier to combine it to SiLabs HID mouse example, than a) option.

- You can use the USB_INT device driver as it is. but you must modify INF file. The INF file modification is simple. Replace the device ID to this format.
USB\VID_vvvv&PID_pppp&MI_mm (vvvv: VID, pppp: PID, mm: interface number)

In this case, the modification of firmware is simplified as follows.
- Add another Interface + Endpoint(s) descriptor from the modified USB_INT.
- Modify these request
- - Set_Configuration - Add endpoint(s) initialization for additional endpoint(s)
- - Get_Interface and Set_Interface to support additional interface.
- Copy handling for the additional endpoint from the modified USB_INT.

And host application will run without any modification.


Which one do you choose?

Tsuneo

IP: Logged

hds2g
Member
posted October 19, 2006 08:15 PM     Click Here to See the Profile for hds2g   Click Here to Email hds2g     Edit/Delete Message
thank you for your reply always..

My project is commercial project..

I already work USB_INT(finished)

so.. HID mouse + USB_INT

and HID mouse + vendor-specific HID(modify my USB_INT) possible..

but I have no time..

I chose HID mose + USB_INT.

later HID mouse + vendor-specific HID..

I have no material..

thanks..

[This message has been edited by hds2g (edited October 19, 2006).]

IP: Logged

hds2g
Member
posted October 20, 2006 12:02 AM     Click Here to See the Profile for hds2g   Click Here to Email hds2g     Edit/Delete Message
my USB_INT descriptor is..

//---------------------------
// Descriptor Declarations
//---------------------------
const device_descriptor DeviceDesc =
{
18, // bLength
0x01, // bDescriptorType
0x1001, // bcdUSB
0xFF, // bDeviceClass
0xFF, // bDeviceSubClass
0xFF, // bDeviceProtocol
EP0_PACKET_SIZE, // bMaxPacketSize0
0x020e, // idVendor
0x0081, // idProduct
0x0000, // bcdDevice
0x01, // iManufacturer
0x02, // iProduct
0x01, // iSerialNumber
0x01 // bNumConfigurations
}; //end of DeviceDesc

const configuration_descriptor ConfigDesc =
{
0x09, // Length
0x02, // Type
0x2000, // Totallength
0x01, // NumInterfaces
0x01, // bConfigurationValue
0x00, // iConfiguration
0x80, // bmAttributes
0x0F // MaxPower
}; //end of ConfigDesc

const interface_descriptor InterfaceDesc =
{
0x09, // bLength
0x04, // bDescriptorType
0x00, // bInterfaceNumber
0x00, // bAlternateSetting
0x02, // bNumEndpoints
0xFF, // bInterfaceClass
0xFF, // bInterfaceSubClass
0x00, // bInterfaceProcotol
0x00 // iInterface
}; //end of InterfaceDesc

const endpoint_descriptor Endpoint1Desc =
{
0x07, // bLength
0x05, // bDescriptorType
0x81, // bEndpointAddress
0x03, // bmAttributes
EP1_PACKET_SIZE_LE, // MaxPacketSize (LITTLE ENDIAN)
0x01 // bInterval
}; //end of Endpoint1Desc

const endpoint_descriptor Endpoint2Desc =
{
0x07, // bLength
0x05, // bDescriptorType
0x02, // bEndpointAddress
0x03, // bmAttributes
EP2_PACKET_SIZE_LE, // MaxPacketSize (LITTLE ENDIAN)
10 // bInterval
}; //end of Endpoint2Desc

#define STR0LEN 4

code const BYTE String0Desc[STR0LEN] =
{
STR0LEN, 0x03, 0x09, 0x04
}; //end of String0Desc
....

If I want to two interface..

in configuration descriptor
0x01, // NumInterfaces
-->0x02

and modify totallength in config desc

and add new interface, endpoint desc..

like this?

const interface_descriptor newInterfaceDesc =
{
0x09, // bLength
0x04, // bDescriptorType
-> 0x01, // bInterfaceNumber
-> 0x01, // bAlternateSetting
-> 0x01, // bNumEndpoints
-> 0x03, // bInterfaceClass
-> 0x01 // bInterfaceSubClass
0x00, // bInterfaceProcotol
0x00 // iInterface
}; //end of InterfaceDesc

and new endpoint

const endpoint_descriptor Endpoint3Desc =
{
0x07, // bLength
0x05, // bDescriptorType
0x83, // bEndpointAddress
0x03, // bmAttributes
EP3_PACKET_SIZE_LE, // MaxPacketSize (LITTLE ENDIAN)
0x10 // bInterval
}; //end of Endpoint3Desc

and add other HID desc..

It that right?

and..

void Get_Interface(void) // This routine returns 0x00, since only one interface
{ // is supported by this firmware

if ((USB_State != DEV_CONFIGURED) || // If device is not configured
(Setup.bmRequestType != OUT_INTERFACE) || // or recipient is not an interface
Setup.wValue.c[MSB] ||Setup.wValue.c[LSB] ||// or non-zero value or index fields
Setup.wIndex.c[MSB] ||Setup.wIndex.c[LSB] ||// or data length not equal to one
Setup.wLength.c[MSB] ||(Setup.wLength.c[LSB] != 1))
{
Force_Stall(); // Then return stall due to invalid request
}

else
{
DataPtr = (BYTE*)&ZERO_PACKET; // Otherwise, return 0x00 to host
DataSize = 1;
}
if (Ep_Status[0] != EP_STALL)
{
POLL_WRITE_BYTE(E0CSR, rbSOPRDY); // Set Serviced Setup packet, put endpoint in transmit
Ep_Status[0] = EP_TX; // mode and reset Data sent counter
DataSent = 0;
}
}

void Set_Interface(void)
{
if ((Setup.bmRequestType != IN_INTERFACE) ||// Make sure request is directed at interface
Setup.wLength.c[MSB] ||Setup.wLength.c[LSB]||// and all other packet values are set to zero
Setup.wValue.c[MSB] ||Setup.wValue.c[LSB] ||
Setup.wIndex.c[MSB] ||Setup.wIndex.c[LSB])
{
Force_Stall(); // Othewise send a stall to host
}
if (Ep_Status[0] != EP_STALL)
{
POLL_WRITE_BYTE(E0CSR, (rbSOPRDY | rbDATAEND));
// Indicate setup packet has been serviced
}
}

how to modify..

[This message has been edited by hds2g (edited October 20, 2006).]

[This message has been edited by hds2g (edited October 20, 2006).]

IP: Logged

Patryk
Member
posted October 20, 2006 04:15 AM     Click Here to See the Profile for Patryk     Edit/Delete Message
New descriptors: interface, HID, endpoint (in that sequence, as in Mouse Example).
bInterfaceNumber = 1 - OK, but bAlternateSetting = 0, bInterfaceProcotol = 2.
HID descriptor: bcdHID = 0x0100 (first byte of that field -LSB- = 0x00, second -MSB- = 0x01).
Checking wValue field in Get/Set_Interface():
change Setup.wIndex.c[MSB] || Setup.wIndex.c[LSB]
to (Setup.wIndex.i <= 1) // check interface number: 0x00 (USB_INT) or 0x01 (HID).

IP: Logged

Tsuneo
Member
posted October 21, 2006 06:08 AM     Click Here to See the Profile for Tsuneo   Click Here to Email Tsuneo     Edit/Delete Message
I posted a demonstration which shows a composite device combined SiLabs USB_HID\MouseExample and USB_INT

USB_Mouse_INT_01.zip

- When you are asked a device driver, specify the INF folder attached to this zip file.
- USB_INT host application works with this implementation without any change.

Tsuneo

IP: Logged

hds2g
Member
posted October 22, 2006 09:18 PM     Click Here to See the Profile for hds2g   Click Here to Email hds2g     Edit/Delete Message
very much thank you...

thank you..

IP: Logged

Tsuneo
Member
posted October 23, 2006 02:56 AM     Click Here to See the Profile for Tsuneo   Click Here to Email Tsuneo     Edit/Delete Message
Ah, you are just timely.

I've searched on a composite device of CDC recently. In this search, I realized how Windows recognizes composite devices. The idea, a composite device combining a generic bulk / interrupt device driver with built-in class drivers, occurs to me. I confirmed it on a Cypress device first, but I've thought another demonstration to make the idea more certainly.

Your question was a good opportunity to make another demonstration.

Tsuneo

IP: Logged

hds2g
Member
posted October 25, 2006 03:05 AM     Click Here to See the Profile for hds2g   Click Here to Email hds2g     Edit/Delete Message
I have one more question..

my HID mouse has two button..

IN_PACKET[0] => left button(exist)
IN_PACKET[3] => right button(add)

how to modify hid report descriptor..?

IP: Logged

Tsuneo
Member
posted October 25, 2006 06:48 AM     Click Here to See the Profile for Tsuneo   Click Here to Email Tsuneo     Edit/Delete Message
You can find an example of the report descriptor for three button mouse in "6.2.2 Report Descriptor" section (p25) of "Device Class Definition for HID 1.11" from USB.org.
Compare it to SiLabs MouseExample.

You must change three parameters.
- Usage Max
- button bits
- padding bits

Tsuneo

[This message has been edited by Tsuneo (edited October 25, 2006).]

IP: Logged

hds2g
Member
posted October 27, 2006 02:18 AM     Click Here to See the Profile for hds2g   Click Here to Email hds2g     Edit/Delete Message
thank you..

I succeed HID mouse + vendor specific USB_INT..

thank you very much..

I want to modify from HID mouse + vendor specific USB_INT to HID mouse + HID Digitizer(two HID)

so.. only modify int interface descriptor->HID interface descriptor??
and add hid report descriptor?

what I modify ..

[This message has been edited by hds2g (edited October 27, 2006).]

IP: Logged

Tsuneo
Member
posted October 27, 2006 09:04 AM     Click Here to See the Profile for Tsuneo   Click Here to Email Tsuneo     Edit/Delete Message
"so.. only modify int interface descriptor->HID interface descriptor??
and add hid report descriptor?"

a) Change VID/PID in the device descriptor
When even one of the interface class of the device is changed, it should be handled differently by Windows. However, Windows doesn't recognize the modification.

To avoid conflict on Windows,
- Assign another VID/PID to the device
OR
- Delete device instance from driver database (Device Manager)

As you are going to release the device as an commercial product, you should get an unique VID/PID for the device.

See this post to get an unique VID/PID,
"USB for Dummies (one dummy, anyway)"
posted September 26, 2006 12:02 AM by Tsuneo
"a) How to get unique VID/PID"

To delete device instance from driver database,
1) Unplug the device from the PC
2) Open Command (DOS) window and enter as follows,
> set devmgr_show_nonpresent_devices=1
> start devmgmt.msc

"Device Manager" dialog appears.
Select "Show hidden devices"

3) Expand 'USB I/O controlled devices'
- Delete one of the 'SiLabs C8051F320 USB Board'
- - see the 'property' - 'advanced' tab - 'Device instance ID'
- - find 'USB\VID_16C0&PID_06EC&MI_01\.....'
- - Delete this one.

4) Expand 'USB Controller'
- Delete one of 'USB Composite device'
- - see the 'property' - 'advanced' tab - 'Device instance ID'
- - find 'USB\VID_16C0&PID_06EC\.....'
- - Delete this one.


b) Modify Interface descriptor
- bInterfaceClass = 0x03 (HID)
- bInterfaceSubClass: depends on implementation, see below

c) Add HID class descriptor
- Copy HID class descriptor from mouse one and modify wItemLength (number of bytes of the report descriptor for the digitizer)
- Add class_descriptor to the hid_configuration_descriptor structure declaration in F3xx_USB0_Descriptor.h

d) Add HID report descriptor for digitizer
- Depends on implementation, see below

e) Get_Descriptor
- case DSC_HID:
- case DSC_HID_REPORT:
Add handling for digitizer descriptors.
- if (wIndex.i == 0) return mouse descriptor (HID class or report)
- if (wIndex.i == 1) return digitizer descriptor (HID class or report)

f) Get_Report
- Like Get_Descriptor, add the procedure to return report for the digitizer.

g) Digitizer implementation

When you are going to handle the digitizer only in your original application, vendor-specific HID class is enough. However, If you expect for another application to handle your device as 'digitizer', you should implement HID digitizer class.

Of course, the format of report data that is sent/received in the endpoints must follow the selected report descriptor.

g-1) Vendor specific HID class
See this SiLabs former HID example for simple vender specific HID
HID_Example_1_0.zip

g-2) HID digitizer class
You can find an example of the report descriptor for this class here.
"A.7 Desktop Tablet Example" (Hut1_12.pdf p138) from
"HID Usage Table 1.12"


Not only the firmware, but the host application should also be modified.
See HID_Example_1_0.zip for details.

Tsuneo

http://www.cygnal.org/ubb/Forum9/HTML/001042.html

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值