Adding RawHID to Teensy 3.0's USB Serial HID

Status
Not open for further replies.

yashinm92

New member
Hi
I've been trying to add RawHID capability to Teensy 3.0's Serial+Keyboard+Mouse+Joystick mode. I hope to add it in such a way that the RawHID replaces the Mouse and Joystick interfaces. I did take a look at http://forum.pjrc.com/threads/18658-Teensyduino-V1-12-and-custom-USB-types and http://forum.pjrc.com/threads/23803-Teensy-3-0-RAW-HID-Keyboard and followed the steps provided in the first thread. Unfortunately when I set the USB type as Serial+Keyboard+Mouse+Joystick and try to compile code which has RawHID functions I get "'RawHID' was not declared in this scope" as an error message. Also when I try to compile a program which does not have RawHID the following error is shown:
Code:
arduino-1.0.5/hardware/teensy/cores/teensy3/usb_inst.cpp:18:1: error: 'usb_rawhid_class' does not name a type

I'm posting the changed portions of usb_desc.h and usb_inst.cpp here:
Code:
#elif defined(USB_SERIAL_HID)
  #define VENDOR_ID		0x16C0
  #define PRODUCT_ID		0x0487
  #define RAWHID_USAGE_PAGE	0xFFAB  // recommended: 0xFF00 to 0xFFFF
  #define RAWHID_USAGE		0x0200  // recommended: 0x0100 to 0xFFFF
  #define DEVICE_CLASS		0xEF
  #define DEVICE_SUBCLASS	0x02
  #define DEVICE_PROTOCOL	0x01
  #define MANUFACTURER_NAME	{'T','e','e','n','s','y','d','u','i','n','o'}
  #define MANUFACTURER_NAME_LEN	11
  #define PRODUCT_NAME		{'S','e','r','i','a','l','/','K','e','y','b','o','a','r','d','/','M','o','u','s','e','/','J','o','y','s','t','i','c','k'}
  #define PRODUCT_NAME_LEN	30
  #define EP0_SIZE		64
  #define NUM_ENDPOINTS		6
  #define NUM_USB_BUFFERS	30
  #define NUM_INTERFACE		5
  #define CDC_IAD_DESCRIPTOR	1
  #define CDC_STATUS_INTERFACE	0
  #define CDC_DATA_INTERFACE	1	// Serial
  #define CDC_ACM_ENDPOINT	2
  #define CDC_RX_ENDPOINT       3
  #define CDC_TX_ENDPOINT       4
  #define CDC_ACM_SIZE          16
  #define CDC_RX_SIZE           64
  #define CDC_TX_SIZE           64
  #define KEYBOARD_INTERFACE    2	// Keyboard
  #define KEYBOARD_ENDPOINT     1
  #define KEYBOARD_SIZE         8
  #define KEYBOARD_INTERVAL     1
  #define RAWHID_INTERFACE      0	// RawHID
  #define RAWHID_TX_ENDPOINT    5
  #define RAWHID_TX_SIZE        64
  #define RAWHID_TX_INTERVAL    1
  #define RAWHID_RX_ENDPOINT    6
  #define RAWHID_RX_SIZE        64
  #define RAWHID_RX_INTERVAL    1
  #define KEYBOARD_DESC_OFFSET	(9+8 + 9+5+5+4+5+7+9+7+7 + 9)
  #define RAWHID_DESC_OFFSET	(9 + 9)
  #define CONFIG_DESC_SIZE	(9+8 + 9+5+5+4+5+7+9+7+7 + 9+9+7 + 9+9+7 + 9+9+7)
  #define ENDPOINT1_CONFIG	ENDPOINT_TRANSIMIT_ONLY
  #define ENDPOINT2_CONFIG	ENDPOINT_TRANSIMIT_ONLY
  #define ENDPOINT3_CONFIG	ENDPOINT_RECEIVE_ONLY
  #define ENDPOINT4_CONFIG	ENDPOINT_TRANSIMIT_ONLY
  #define ENDPOINT5_CONFIG	ENDPOINT_TRANSIMIT_ONLY
  #define ENDPOINT6_CONFIG	ENDPOINT_RECEIVE_ONLY

usb_inst.cpp
Code:
#ifdef USB_SERIAL_HID
usb_serial_class Serial;
usb_keyboard_class Keyboard;
usb_rawhid_class RawHID;
#endif

I'm using arduino(1.05) on Ubuntu 13.04.
 
You need to #define USB_RAWHID. The usb_rawhid.h file only works if that symbol is defined. Or just edit usb_rawhid.h and remove the conditional check, so it will always declare all that stuff.
 
Thanks Paul!
I tried adding #define USB_RAWHID to my sketch but there was an error message about multiple "serial" classes defined. So I modified usb_rawhid.h and removed the #if defined(USB_RAWHID) and the corresponding #endif. Right now the code is compiling but the rawhid_test program is not detecting the device as a raw hid device when the teensy is put in the newly modified Serial HID mode. I tried changing the PID to 0x0486 mentioned in the rawhid_test source code but it still does not detect it.
dmesg for Serial HID:
Code:
[ 6721.226694] usb 3-1: Duplicate descriptor for config 1 interface 0 altsetting 0, skipping
[ 6721.238651] usb 3-1: New USB device found, idVendor=16c0, idProduct=0486
[ 6721.238662] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 6721.238668] usb 3-1: Product: Serial/Keyboard/Mouse/Joystick
[ 6721.238672] usb 3-1: Manufacturer: Teensyduino
[ 6721.238676] usb 3-1: SerialNumber: 9864
[ 6721.241852] cdc_acm 3-1:1.0: This device cannot do calls on its own. It is not a modem.
[ 6721.241893] cdc_acm 3-1:1.0: ttyACM0: USB ACM device
[ 6721.256220] input: Teensyduino Serial/Keyboard/Mouse/Joystick as /devices/pci0000:00/0000:00:1c.3/0000:04:00.0/usb3/3-1/3-1:1.2/input/input25
[ 6721.256587] hid-generic 0003:16C0:0486.002A: input,hidraw0: USB HID v1.11 Keyboard [Teensyduino Serial/Keyboard/Mouse/Joystick] on usb-0000:04:00.0-1/input2
 
It says VOTI Teensyduino RawHID.
Relevant section of lsusb -v
Code:
Bus 002 Device 006: ID 16c0:0486 VOTI Teensyduino RawHID
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass          239 Miscellaneous Device
  bDeviceSubClass         2 ?
  bDeviceProtocol         1 Interface Association
  bMaxPacketSize0        64
  idVendor           0x16c0 VOTI
  idProduct          0x0486 Teensyduino RawHID
  bcdDevice            1.00
  iManufacturer           1 Teensyduino
  iProduct                2 Serial/Keyboard/Mouse/Joystick
  iSerial                 3 9864
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength          150
    bNumInterfaces          3
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xc0
      Self Powered
    MaxPower              100mA
    Interface Association:
      bLength                 8
      bDescriptorType        11
      bFirstInterface         0
      bInterfaceCount         2
      bFunctionClass          2 Communications
      bFunctionSubClass       2 Abstract (modem)
      bFunctionProtocol       1 AT-commands (v.25ter)
      iFunction               4 
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         2 Communications
      bInterfaceSubClass      2 Abstract (modem)
      bInterfaceProtocol      1 AT-commands (v.25ter)
      iInterface              0 
      CDC Header:
        bcdCDC               1.10
      CDC Call Management:
        bmCapabilities       0x01
          call management
        bDataInterface          1
      CDC ACM:
        bmCapabilities       0x06
          sends break
          line coding and serial state
      CDC Union:
        bMasterInterface        0
        bSlaveInterface         1 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0010  1x 16 bytes
        bInterval              64
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0 Unused
      bInterfaceProtocol      0 
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x84  EP 4 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        2
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      1 Boot Interface Subclass
      bInterfaceProtocol      1 Keyboard
      iInterface              0 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.11
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      85
         Report Descriptors: 
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval               1
Device Status:     0x0000
  (Bus Powered)

      bInterfaceProtocol      0 Full speed (or root) hub
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0004  1x 4 bytes
        bInterval              12
 
Forget about the human readable strings.

Look at the interfaces! There are 3 interfaces, 2 for CDC and 1 for keyboard. But none for rawhid.
 
Alright, I see it now. Can you please tell me what I should change to make the interface for rawhid show up? Is the problem with my usb_desc.h?
Thanks again!
 
Status
Not open for further replies.
Back
Top