Skip to content

RawHID API

Nico edited this page Oct 14, 2016 · 19 revisions

Working examples can be found in the example folder. Feature and out reports are both supported.

Useful links:

A patched version of the program linked above can be found inside the extras folder. The example is far away from being perfect. I recommend you to use the hidapi instead. Needs further testing. Should work under windows as well, but not tested.

2.4.2 fixes the 64+ byte RawHID issue. IDE 1.6.8 is required for this patch.

As stated in the links above you need to add a udev rule or need root access (sudo) to open the hid device. A full, more detailed udev.rules file can be found inside the /extras folder of the library. For a quick version use this command:

echo 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", MODE:="0666"' | sudo tee /etc/udev/rules.d/ArduinoRawHID.rules
sudo udevadm control --reload-rules && sudo udevadm trigger

Usage pages (seems to be useless for programs):

  RAWHID_USAGE_PAGE 0xFFC0 // recommended: 0xFF00 to 0xFFFF
  RAWHID_USAGE    0x0C00 // recommended: 0x0100 to 0xFFFF

Teensy rawhid

Here is a quick'n dirty tutorial how to fix the teensy rawhid source for 16u2. All changes are applied in the project below: https://github.com/stahir/tjtag3-0-1_arduiglerHID

The changes stahir made (summarized from him):

in the teensi usb_rawhid.h i added this line for the atmega16u2

#define HW_CONFIG()
#define PLL_CONFIG() (PLLCSR = 0x06)
#define USB_CONFIG() (USBCON = (1<<USBE))
#define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))

in the usb_rawhid.c i changes these linkes

#define RAWHID_TX_SIZE16// transmit packet size
#define RAWHID_TX_INTERVAL2// max # of ms between transmit packets
#define RAWHID_RX_SIZE16// receive packet size
#define RAWHID_RX_INTERVAL8// max # of ms between receive packets

the tx and rx size was 64before, i changed it to 16 and also this

#if defined(__AVR_ATmega16U2__)
#define RAWHID_TX_BUFFEREP_SINGLE_BUFFER
#define RAWHID_RX_BUFFEREP_SINGLE_BUFFER
#else