USB STACK 4.1.1 HOST HID help

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

USB STACK 4.1.1 HOST HID help

1,669 Views
robertofrechill
Contributor III

Hi! i´m developing a new aplication to communicate TWR-K20M72 with a UPS by USB. TWR must be a HOST and UPS is DEVICE ( HOST sends message and device sends a reply). I´m building a new aplication from mouse/keyboard example of stack and need to know the exactly functions for sends and receive any message by USB. Also i need the function for built my specific message.

Anybody can help me????

Thanks :smileyhappy:

Tags (5)
12 Replies

951 Views
robertofrechill
Contributor III

Hi!! i discovered that my device use 2 endpoints for communications, I´thinking about one is a interrupt pipe IN and one interrupt pipe out. The hid keyboard example use only one interrupt pipe..

how is the way for create a new interrupt pipe out??

I´m trying this way:

              pipe = _usb_hostdev_find_pipe_handle(hid_device.DEV_HANDLE, hid_device.INTF_HANDLE, USB_INTERRUPT_PIPE, USB_RECV);

              pipe_control = _usb_hostdev_find_pipe_handle(hid_device.DEV_HANDLE, hid_device.INTF_HANDLE, USB_CONTROL_PIPE, USB_SEND);

pipe_tx= _usb_hostdev_find_pipe_handle(hid_device.DEV_HANDLE, hid_device.INTF_HANDLE, USB_INTERRUPT_PIPE, USB_SEND); // is corretly???

0 Kudos

951 Views
robertofrechill
Contributor III

I need help for develop my own USB HID protocol... I can't star communications with my UPS, anybody could give me any idea???

It´s my first time with USB communication :smileysad:

0 Kudos

951 Views
DerekLau
Contributor IV

Or  you may do it in PC first. There are some HID communicates examples (search google).  Anyway you have to understand the report descriptor of the UPS and how it works.

0 Kudos

951 Views
robertofrechill
Contributor III

thanks Derek! the UPS manufacturer only gave me these communication information:

-Communication between PC (host) and UPS is Half-duplex. host only can send to the UPS request messages and UPS only send back a response message.

-Default communitacion setting is : 1200 baud, 8 bits, NO PERITY, 1 stop bit

Protocol format: Data to send( not relevant information for USB protocol, i think...)

after, i discovered the communitation is a HID class, subclass=0, protocol=0.

Is enough this information for develop my program?

0 Kudos

951 Views
Kan_Li
NXP TechSupport
NXP TechSupport

The functions used for sending and receiving any message by USB should be usb_hostdev_tr_init() and _usb_host_recv_data(). Please kindly refer to the following for details.

1.PNG

For more details, please refer to USBHOSTAPIRM.pdf and USBHOSTUG.pdf in "C:\Freescale\Freescale USB Stack v4.1.1\Documentation".

Hope that helps,

B.R

Kan

0 Kudos

951 Views
robertofrechill
Contributor III

Thanks Kan, i know this information, now i´m able to read data from device i´m thinking the problem is when i try send a message to device the setup packet is wrong for my device...

In a keyboard example, when host send message for turn on/off leds, before use _usb_host_recv_data() it´s build tr.DEV_REQ_PTR with values like:

                tr.DEV_REQ_PTR = (uchar_ptr)malloc(8);

                tr.DEV_REQ_PTR[0] = 0x21;    // HOST --> DEVICE DIRECTION

                tr.DEV_REQ_PTR[1] = 0x09;    // SET_DESCRIPTOR_REQUEST

                tr.DEV_REQ_PTR[2] = 0x02;    // wValue [byte1]

                tr.DEV_REQ_PTR[3] = 0x00;    // wValue [byte0] -> 1024 (reporte tipo salida?)

                tr.DEV_REQ_PTR[4] = 0x00;    // wIndex [byte1]

                tr.DEV_REQ_PTR[5] = 0x00;    // wIndex [byte0] -> 0

                tr.DEV_REQ_PTR[6] = 0x00;    // number of bytes [byte1]

                tr.DEV_REQ_PTR[7] = 0x08;    // number of bytes [byte0]

**This request was explained in HID specification 1.11**

¿Is this request only valid for Keyboard/mouse? ¿in always necessary for send data?

Thanks a lot!

0 Kudos

951 Views
Kan_Li
NXP TechSupport
NXP TechSupport

This is a Class-Specific Request, and it is a Set_Report Request, which allows the host to send a report to the device, possibly setting the state of input, output, or feature controls. Please kindly refer to http://www.usb.org/developers/devclass_docs/HID1_11.pdf for more details.

Hope that helps,

B.R

Kan

0 Kudos

951 Views
robertofrechill
Contributor III

yes! but the question is... Set_report_rquest with the same valours is valid for another devices (no keyboard and mouse)??? I´m doing a specific protocol for a UPS communication (uninterruptible power supply) and it has a different protocol ( HID (Class=0x03), non-boot(Sub-Class=0x00), non-Protocol (Protocol=0x00).

Thanks again

0 Kudos

951 Views
Kan_Li
NXP TechSupport
NXP TechSupport

I see, but it is a Class-Specific Request, so since the UPS is a HID class device, this type of request is valid even the device uses a protocol other than keyboard / mouse.

Hope that helps,

B.R

Kan

951 Views
robertofrechill
Contributor III

Hi again Kan, i´m thinking i found a possible problem in my code...

the HID examples use the same pipe for pipe_interrupt and pipe_control, this works for keyboard's example... but i´m thinking this is a problem for my UPS-HOST communication... (i suppose to need one pipe for control and one for interrupt).

How is the way for find a differents specific pipes (control and interrupt)??

this is the code for select the same pipe:

pipe = _usb_hostdev_find_pipe_handle(hid_device.DEV_HANDLE, hid_device.INTF_HANDLE, USB_INTERRUPT_PIPE, USB_RECV);

pipe_control = _usb_hostdev_find_pipe_handle(hid_device.DEV_HANDLE, hid_device.INTF_HANDLE, USB_CONTROL_PIPE, USB_SEND);

              if(pipe && pipe_control)

              {

                  printf("Keyboard device ready, try to press the keyboard\n");

                  fflush(stdout);

              }

Thanks a lot

Roberto.

0 Kudos

951 Views
DerekLau
Contributor IV

Some HID devices use control pipe to send and receive data (EP0 only).

Some use control pipe to send and interrupt pipe to receive data (IN EP).

Some use interrupt pipes to send and receive data (IN EP, OUT EP).

There may be some devices use control pipe to receive and interrupt pipe to send data (OUT EP).

For standard keyboards, host uses interrupt pipe to get data from keyboards, and uses control pipe to send data (LED controls) to them.

0 Kudos

951 Views
robertofrechill
Contributor III

thanks Kan :smileyhappy:

0 Kudos