Teensy 3.1 + RAW HID

Status
Not open for further replies.

bart

New member
Hi everyone,
Firstly sorry for my eng, its not my native lang.
I am working on some project that i wish to use usb communication. I want to send data from PC to Teensy device (X, Y, Z posiotion) x 5000 samples(at least). Single raw hid frame looks great for sending structure with those 3 numbers. I wish that it would it be as easy as possible to implement it. I have started reading USB COMPLETE written by Jan Alexon but it was too complex... or maybe I dont want spend too much time on quick project:rolleyes:. Then I discovered this:
https://www.pjrc.com/teensy/rawhid.html
Fortunately I already have Teensy 3.1. so I run test sketch and "RawHid Test for Linux". Worked well. But after look over on code for teensy 2.0 i saw it has a possibility for change VID / PID. I want to change PID only, to have two maybe three distinguishable devices that could be simultaneously connected to same PC. I could buy Teensy 2 but I am worry it has no enough ram.

Is there any way to run RAW HID on teensyduino (teensy3.1) and have advantages from previous version I was writing about?

Thanks in advance
Bart
 
Hi again.
I did not receive any answer or suggestion at my previous post so I am wonder if I explained clearly what I was mentioned about.

I am trying to adjust RAW HID example on Teensy 3.1 but since this version is supported by Teensyduino example code for RAW HID is written in arduino and it is suggested to use arduino for teensy 3.1 and above:
"USB Raw HID, Version 1.1 -- WARNING: obsolete, use Teensyduino for new projects"

Now I am woder if it is possible to use function like those to adjust some parameters (on teensyduino):

Device (Teensy) Side Functions
void usb_init(void);
Initialize the USB port.
uint8_t usb_configured(void);
Check if the host has configured the USB and is online.
int8_t usb_rawhid_recv(uint8_t *buffer, uint8_t timeout);
Receive a packet. "buffer" must be the size of a full packet. Wait up to "timeout" milliseconds. Return is the number of bytes received, which will always be a full packet, or 0 if timeout, or -1 if the USB is not configured or online. To check if a packet is buffered but avoid waiting, a timeout of 0 may be specified.
int8_t usb_rawhid_send(const uint8_t *buffer, uint8_t timeout);
Transmit a packet. "buffer" must contain the full packet to send. Wait up to "timeout" milliseconds. Return is the number of bytes send, which will always be a full packet, or 0 if timeout, or -1 i f the USB is not configured or online. To transmit only if a buffer is immediately available, a timeout of 0 may be used.

Or to use those more advanced examples from previous versions of the board in Teensy 3.1. If yes, how can I compile them.

Thank you im advance
Bart
 
Rawhid is included out of the box with Teensy 3.x. Just set the 'USB Type' to 'Raw HID' in the IDE. It has the following functions ('arduino/hardware/teensy/avr/cores/teensy3/usb_rawhid.h'):

Code:
int usb_rawhid_recv(void *buffer, uint32_t timeout);
int usb_rawhid_available(void);
int usb_rawhid_send(const void *buffer, uint32_t timeout);

For changing the USB descriptor, look at 'arduino/hardware/teensy/avr/cores/teensy3/usb_desc.h'. There is a lengthy comment at the beginning that explains what to do.
 
Hi Bart,

Sorry I have only played a little with RAWHID.

My take of it is, if you look at the PJRC documentation page for it: https://www.pjrc.com/teensy/rawhid.html

As you mentioned, it says that those parts are obsolete. My take on that is, that the earlier code was specific for Teensy 2.x and probably won't work on Teensy 3.x boards.

However you do have Raw Hid support in Teensyduino. That is if you choose the USB type of Raw Hid, the code will take care of all of the stuff to configure the USB...

When USB is configured for this, the Raw Hid functions are defined for you which are:
Code:
int usb_rawhid_recv(void *buffer, uint32_t timeout);
int usb_rawhid_available(void);
int usb_rawhid_send(const void *buffer, uint32_t timeout);
#ifdef __cplusplus
And likewise there is a simple wrapper C++ class.

Code:
class usb_rawhid_class
{
public:
	int available(void) {return usb_rawhid_available(); }
	int recv(void *buffer, uint16_t timeout) { return usb_rawhid_recv(buffer, timeout); }
	int send(const void *buffer, uint16_t timeout) { return usb_rawhid_send(buffer, timeout); }
};
So the question is, are there any features in the old stuff, that you are trying to emulate?

Do you have some code you are trying to do, that you are having issues that you are not sure how to resolve?

If so, it is best to show an example program that you are trying to do and what issues you are having.

Note: if you are wondering about the internals of this. You can find the sources for current stuff installed as part of Teensyduino.
That is you can find the functions/methods I mentioned up at:
<Arduino install directory>/hardware /avr/cores/teensy3/usb_rawhid.h (and usb_rawhid.c)

You can find more of the information on the how it works and is initialized up in the directory:
<Arduino install directory>/hardware /avr/cores/usb_rawhid
 
Status
Not open for further replies.
Back
Top