teensy 2.0 with HID

Status
Not open for further replies.

mike

Member
aloha everyone!

i got a teensy 2.0 and am trying to port my project from a adafruit trinket (attiny85) to a atmega32u4. the attiny85 does not have USB support so i was using VUSB to do it in software. since the atmega32u4 does support USB, i was planning to try and use/learn about that. i downloaded the usb_rawhid example and configured my USB device so it appears correctly when plugged in. the next step was to appropriately respond to messages, but i don't see where the buffer(s) are in the example. can anyone point me in the right direction?

my scenario: when i plug in the device, a third party application detects the device was plugged in and tries to communicate with it. where is the data buffer(s) the in usb_rawhid.c that can be manipulated to send responses back to the host and application over usb? i don't have control over the third party application so i've just been using wireshark to capture the USB data and am trying to match up the data that way.
 
EXAMPLE.C
The "buffer" is defined in example.c on line 34.
Line 34: uint8_t buffer[64];
You can change it to any length up to 64. A 64 byte report buffer is the largest that a "Full Speed USB" will support.
There is only one buffer defined in this program, and it supports both input and output.
There's nothing to prevent you from having separate input and output buffers...defined as the same length.
Example:
uint8_t input_buffer[64];
uint8_t output_buffer[64];
If you do this you must fix up the "send" and "receive" functions. And anywhere else "buffer" is used.

EXAMPLE.C
A "receive" and "send" of the current buffer happens in example.c on lines 63 and 90.
Line 63: r = usb_rawhid_recv(buffer, 0);
Line 90: usb_rawhid_send(buffer, 50);

USB_RAW_HID.C
The "receive" and "send" functions are found usb_rawhid.c starting on lines 269 and 489 respectively.
Note that the reading and writing of the buffer is not done in a "for loop" but is actually "in-lined" as single instruction for each byte going into or coming out of the buffer. This is what may be throwing you off. If your buffer is defined as 64 bytes in length, the #if/#endif conditional compile will generate 64 separate lines of c-code...adding single bytes to the buffer, or reading single bytes from the buffer.

RECEIVE.
Line 269: int8_t usb_rawhid_recv(uint8_t *buffer, uint8_t timeout)
...
Line 290: #if (RAWHID_RX_SIZE >= 64)
Line 291: *buffer++ = UEDATX;
Line 292: #endif
Line 293: #if (RAWHID_RX_SIZE >= 63)
Line 294: *buffer++ = UEDATX;
Line 295: #endif
...
yada...yada....yada...

SEND
Line 489: int8_t usb_rawhid_send(const uint8_t *buffer, uint8_t timeout)
...
Line 510: #if (RAWHID_TX_SIZE >= 64)
Line 511: UEDATX = *buffer++;
Line 512: #endif
Line 513: #if (RAWHID_TX_SIZE >= 63)
Line 514: UEDATX = *buffer++;
Line 515: #endif
...
yada...yada....yada...
 
Last edited:
Thank you for the detailed explanation Burly!! I will try this tonight and i'm guessing it'll be "on to the next hurdle" :)
 
Status
Not open for further replies.
Back
Top