I'm trying to do a RAWHID test program for TeensyLC

Status
Not open for further replies.

Burly

Member
I'm trying to write a RAWHID program to connect a Windows10 tablet to a TeensyLC.
I've done it successfully for both a Teensy 2.0 and Teensy 2.0+.

But the TeensyLC doesn't work.

There is an old RAWHID example under the Teensy->Code Library tab.
It lists the "Teensy Side Functions" as:
void usb_init(void);
uint8_t usb_configured(void);
int8_t usb_rawhid_recv(uint8_t *buffer, uint8_t timeout);
int8_t usb_rawhid_send(const uint8_t *buffer, uint8_t timeout);

Before getting fancy...I'm just trying to get a simple "send" and "receive" program to work.
The TensyLC will sit in a "while loop"...waiting to receive a packet from the tablet.
The Tablet will sent the first packet.
The TeensyLC will receive it and immediately send it back.
The Tablet will receive it and immediately send it back.
Each USB packet the tablet sees will print out on a log file.
No lines are printing.
We should see approximately 500 packets going to the TeensyLC and 500 packets going to the Tablet per second.

Here's the source:
I'm getting errors in compiling...
The compiler doesn't recognize usb_init() and usb_configured()....they are undefined.
But, the compiler does recognize usb_rawhid_recv() and usb_rawhid_send().

Code:
byte buffer[64];
int count = 0x00;
byte ping = 1;

void setup()
{
	usb_init();                     //THIS FUNCTION THROWS AND UNDEFINED COMPILER ERROR
	pinMode(LED_BUILTIN, OUTPUT);
	for (int i = 0; i < 64; i++)
	{
		buffer[i] = count;
		count++;
	}
	while (usb_configured() != 1);      //THIS FUNCTION THROWS AND UNDEFINED COMPILER ERROR
	digitalWrite(LED_BUILTIN, HIGH);
}
	
void loop()
{
	while(usb_rawhid_recv(buffer, 100) == 0);
	usb_rawhid_send(buffer, 100);
}

I'm using Visual Micro to compile and am using the "USB HID" USB Type.
When the board gets plugged in it already has a RAWHID Session...so I guess usb_init() might not be necessary.
If I comment out the two lines with errors, the code itself still doesn't work

Any help would be appreciated...

Jim K.

PS.
I'm pretty sure it has to do with USB Enumeration.
Looks like the RAWHID USB type has more than HID.
I have a program the lists all the USB devices.
I see something pointing to the usbccgp.sys....and two things pointing to hidusub.sys.
These are all coming from the TeensyLC with the VendorID of 16c0....and the ProductID of 0486.
 
Last edited:
usb_init is called before setup() is called? What do you expect usb_configured to do?

There is a variable "volatile uint8_t usb_configuration = 0;" - but that is used internally for tracking it seems?
 
OK...I've got it fixed...

There is a sample program where Arduino is installed on your C: drive.
Program Files (x86)\arduino\examples\teensy\USB_RawHID\Basic\Basic.pde

I shortened the sample to be minimal code.
I get a little under 1000 packets sent per second...500 in each direction.

Code:
void setup()
{
    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, HIGH);
}

byte buffer[64];
int count = 0;

void loop()
{
    while (RawHID.recv(buffer, 100) == 0);
    RawHID.send(buffer, 100);	
    
    count++;
    if (count > 100 )
    {
        count = 0;
    }
    if (count > 50)
        digitalWrite(LED_BUILTIN, HIGH);
    else
        digitalWrite(LED_BUILTIN, LOW);
 
}

So the RawHID object is already instantiated and ready to use.
 
Last edited:
OK...I've got it fixed...

There is a sample program where Arduino is installed on your C: drive.
Program Files (x86)\arduino\examples\teensy\USB_RawHID\Basic\Basic.pde
...

So the RawHID object is already instantiated and ready to use.

Yep, Paul sells rather small but moderately priced ( by Arduino Standards ) and very capable hardware as the come on - then supplies working software in a ready to run environment that lets it do a great deal - at no charge, a very user friendly business model.
 
Status
Not open for further replies.
Back
Top