Tennsy 3.1 Keyboard only and Mouse only mode

Status
Not open for further replies.

Killberty

New member
Hi community,

i would like to edit the required files to add a keyboard only and a mouse only mode for my Teensy 3.1 in my Arduino IDE.

So i would add something like this to usb_desc.h:
Code:
#elif defined(USB_KEYBOARD)
  #define VENDOR_ID		0x16C0
  #define PRODUCT_ID		0x0482
  #define MANUFACTURER_NAME	{'T','e','e','n','s','y','d','u','i','n','o'}
  #define MANUFACTURER_NAME_LEN	11
  #define PRODUCT_NAME		{'K','e','y','b','o','a','r','d'}
  #define PRODUCT_NAME_LEN	8
  #define EP0_SIZE		64
  #define NUM_ENDPOINTS         2
  #define NUM_USB_BUFFERS	24
  #define NUM_INTERFACE		4
  #define SEREMU_INTERFACE      1	// Serial emulation
  #define SEREMU_TX_ENDPOINT    1
  #define SEREMU_TX_SIZE        64
  #define SEREMU_TX_INTERVAL    1
  #define SEREMU_RX_ENDPOINT    2
  #define SEREMU_RX_SIZE        32
  #define SEREMU_RX_INTERVAL    2
  #define KEYBOARD_INTERFACE    0	// Keyboard
  #define KEYBOARD_ENDPOINT     3
  #define KEYBOARD_SIZE         8
  #define KEYBOARD_INTERVAL     1
  #define KEYBOARD_DESC_OFFSET	(9 + 9)
  #define SEREMU_DESC_OFFSET	(9 + 9+9+7 + 9+9+7 + 9)
  #define CONFIG_DESC_SIZE	(9 + 9+9+7 + 9+9+7 + 9+9+7+7 + 9+9+7)
This part is what i do not understand at all:
Code:
  #define ENDPOINT1_CONFIG	ENDPOINT_TRANSIMIT_ONLY
  #define ENDPOINT2_CONFIG	ENDPOINT_RECEIVE_ONLY

And something like this to boards.txt:
Code:
teensy31.menu.usb.keyboard.name=Keyboard + Mouse + Joystick
teensy31.menu.usb.hid.keyboard.define0=-DUSB_KEYBOARD

usb_inst.cpp
Code:
#ifdef USB_HID
usb_keyboard_class Keyboard;
usb_seremu_class Serial;
#endif

I assume this won't be all i need to do and some of this might be incorrect because i am just a hobby developer with little skill but maybe someone might be able to help me out.

My goal is to speed up the driver installtion process on Windows (and i also might learn something from this which is nice).
Thanks in advance
Pascal
 
Last edited:
Would you believe I recently did quite a bit of work to simplify this?

With either the latest (beta) version, or with 1.20, you start by editing usb_desc.h. Those groups of lines in usb_desc.h correspond to the menu settings in Tools > USB Type.

To make only a keyboard, just edit the one for Keyboard + Mouse + Joystick. Delete the lines for mouse and joystick stuff, and also the seremu stuff. Update NUM_INTERFACE to just 1.

With 1.20, you also have to adjust those computed offset and sizes. Since Keyboard was the first interface, leave it alone. The total size needs to be shortened. The numbers are grouped with spaces between each group for one of the interfaces. In the newer (beta) code, those computations are done automatically, so you don't need to manually update them.
 
Is it possible to ADD an option, as i don't want to touch the modes i have...

Or can we get a "Keyboard", a "Mouse" and a "Keyboard + Mouse Option" in the next Teensyduino Version?
 
Is it possible to ADD an option

Yes, of course it's possible. It's not even particularly difficult. :)

Edit boards.txt to add the new option into the menu, and make up a -DUSB_XYZ name for it.

Then in usb_desc.h, add a new section for your new menu option. If you're using 1.20, you also have to edit the #ifdef stuff near the top of many .h files, to configure whether they are used or now. In the latest code (beta coming in a day or two), those automatically work from the stuff in usb_desc.h. The idea in the latest code is you only have to edit usb_desc.h, which should be much simpler.
 
Paul, may I assume that the #define in line 45 of usb_desc.h should read
Code:
#define ENDPOINT_TRANSMIT_ONLY		0x15
instead of
Code:
#define ENDPOINT_TRANS[U]I[/U]MIT_ONLY		0x15
? It looks as if there is an extraneous letter in "TRANSIMIT". However, as it's used consistently all over the code, it turns out to be just an aesthetic (or orthographic) issue. ;)

Apart from that, nice work. Helps a lot in customizing USB devices
 
I want to present Teensy as a pure-dumb-basic USB keyboard (or mouse, or joystick). I took a stab at the config file, but wanted to verify that this is what I'm doing.

Do I need a serial entry for all devices? I want to present the keyboard, say, and just a Keyboard and nothing else. Not sure if Serial is used by default.
It looks like Interfaces are 0->n and endpoints are 1->N -- true?

Here is my modifed section for boards.txt:

Code:
teensy30.menu.usb.keyboard=Keyboard
teensy30.menu.usb.keyboard.build.usbtype=USB_KBD
teensy30.menu.usb.keyboard.fake_serial=teensy_gateway
teensy30.menu.usb.mouse=Mouse
teensy30.menu.usb.mouse.build.usbtype=USB_MOUSE
teensy30.menu.usb.mouse.fake_serial=teensy_gateway
teensy30.menu.usb.joystick=Joystick
teensy30.menu.usb.joystick.build.usbtype=USB_JOYSTICK
teensy30.menu.usb.joystick.fake_serial=teensy_gateway

and in my usb_desc.h:

Code:
#elif defined(USB_KBD)
  #define VENDOR_ID		0x16C0
  #define PRODUCT_ID		0x048A
  #define MANUFACTURER_NAME	{'T','e','e','n','s','y','d','u','i','n','o'}
  #define MANUFACTURER_NAME_LEN	11
  #define PRODUCT_NAME		{'K','e','y','b','o','a','r','d'}
  #define PRODUCT_NAME_LEN	8
  #define EP0_SIZE		64
  #define NUM_ENDPOINTS         3
  #define NUM_USB_BUFFERS	24
  #define NUM_INTERFACE		2
  #define SEREMU_INTERFACE      1	// Serial emulation
  #define SEREMU_TX_ENDPOINT    1
  #define SEREMU_TX_SIZE        64
  #define SEREMU_TX_INTERVAL    1
  #define SEREMU_RX_ENDPOINT    2
  #define SEREMU_RX_SIZE        32
  #define SEREMU_RX_INTERVAL    2
  #define KEYBOARD_INTERFACE    0	// Keyboard
  #define KEYBOARD_ENDPOINT     3
  #define KEYBOARD_SIZE         8
  #define KEYBOARD_INTERVAL     1
  #define ENDPOINT1_CONFIG	ENDPOINT_TRANSIMIT_ONLY
  #define ENDPOINT2_CONFIG	ENDPOINT_RECEIVE_ONLY
  #define ENDPOINT3_CONFIG	ENDPOINT_TRANSIMIT_ONLY

#elif defined(USB_MOUSE)
  #define VENDOR_ID		0x16C0
  #define PRODUCT_ID		0x048B
  #define MANUFACTURER_NAME	{'T','e','e','n','s','y','d','u','i','n','o'}
  #define MANUFACTURER_NAME_LEN	11
  #define PRODUCT_NAME		{'M','o','u','s','e'}
  #define PRODUCT_NAME_LEN	5
  #define EP0_SIZE		64
  #define NUM_ENDPOINTS         3
  #define NUM_USB_BUFFERS	24
  #define NUM_INTERFACE		2
  #define SEREMU_INTERFACE      1	// Serial emulation
  #define SEREMU_TX_ENDPOINT    1
  #define SEREMU_TX_SIZE        64
  #define SEREMU_TX_INTERVAL    1
  #define SEREMU_RX_ENDPOINT    2
  #define SEREMU_RX_SIZE        32
  #define SEREMU_RX_INTERVAL    2
  #define MOUSE_INTERFACE       0	// Mouse
  #define MOUSE_ENDPOINT        3
  #define MOUSE_SIZE            8
  #define MOUSE_INTERVAL        1
  #define ENDPOINT1_CONFIG	ENDPOINT_TRANSIMIT_ONLY
  #define ENDPOINT2_CONFIG	ENDPOINT_RECEIVE_ONLY
  #define ENDPOINT3_CONFIG	ENDPOINT_TRANSIMIT_ONLY
  
#elif defined(USB_JOYSTICK)
  #define VENDOR_ID		0x16C0
  #define PRODUCT_ID		0x048C
  #define MANUFACTURER_NAME	{'T','e','e','n','s','y','d','u','i','n','o'}
  #define MANUFACTURER_NAME_LEN	11
  #define PRODUCT_NAME		{'J','o','y','s','t','i','c','k'}
  #define PRODUCT_NAME_LEN	8
  #define EP0_SIZE		64
  #define NUM_ENDPOINTS         3
  #define NUM_USB_BUFFERS	24
  #define NUM_INTERFACE		2
  #define SEREMU_INTERFACE      1	// Serial emulation
  #define SEREMU_TX_ENDPOINT    1
  #define SEREMU_TX_SIZE        64
  #define SEREMU_TX_INTERVAL    1
  #define SEREMU_RX_ENDPOINT    2
  #define SEREMU_RX_SIZE        32
  #define SEREMU_RX_INTERVAL    2
  #define JOYSTICK_INTERFACE    0	// Joystick
  #define JOYSTICK_ENDPOINT     3
  #define JOYSTICK_SIZE         16
  #define JOYSTICK_INTERVAL     2
  #define ENDPOINT1_CONFIG	ENDPOINT_TRANSIMIT_ONLY
  #define ENDPOINT2_CONFIG	ENDPOINT_RECEIVE_ONLY
  #define ENDPOINT3_CONFIG	ENDPOINT_TRANSIMIT_ONLY
 
I assume the fake serial is used for programming, and hence necessary. I tried just adding a keyboard only entry and got compilation errors for serial missing.

Code:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\yield.cpp: In function 'void yield()':
C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\yield.cpp:43:6: error: 'Serial' was not declared in this scope
if (Serial.available()) serialEvent();
^
C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\yield.cpp:43:38: error: 'serialEvent' was not declared in this scope
if (Serial.available()) serialEvent();
^
Error compiling.
 
Yeah, that code and perhaps other places depend on having either USB virtual serial or the emulated serial.

I think you're on the right track... you're just running into limitations in Teensyduino, because it was never meant to build a project without either of those options.

You could try just deleting stuff from yield.cpp and other places. If you're really building without those, deleting the code that uses them may feel like an ugly hack, but it's probably the right course. If you're really ambitious, you could document all these dependencies and maybe someday I'll add more #ifdef stuff around those areas, so this will "just work" when/if anyone else tries to make a custom USB config without any "Serial" stuff.
 
5 years later I'm having a what I believe to be a similar issue with keyboard support on the Nintendo Switch. It seems modifying yield.cpp to remove the virtual serial port is all it takes to compile without.
 
Status
Not open for further replies.
Back
Top