Emulate specific keyboard model

illera88

Member
Hi,

When I use my teensy as USBHost I can get information from the connected device as:
Code:
	uint16_t idVendor();
	uint16_t idProduct();
	const uint8_t *manufacturer();
	const uint8_t *product();
	const uint8_t *serialNumber();

I was wondering how can I instruct the Keyboard class so when I use the USB as a device I can set those same properties to the host I'm connected the Teensy to.

Thank you
 
Simple Answer is in a generic way you probably can not.

That is if you want it to on each run if you have a different keyboard plugged in, you wish for these values to mimic it.
That is that data is built into the Teensy image when your program is compiled.

If however there is one specific one that you are building for, then you can probably build it
with updating the usb_desc.h and usb_desc.c within the teensy sources. Again location of these files depends on what Teensy you are building for.
But looking the the .../cores/teensy4 directory

If you are building for usb type: Keyboard

If you look in usb_desc.h you will see:
Code:
#elif defined(USB_KEYBOARDONLY)
  #define VENDOR_ID		0x16C0
  #define PRODUCT_ID		0x04D0
  #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
...
As for Serial number... not sure. Probably could change code in usb_desc.c for this...
 
Thank you for your response.

For what you say and what I've checked in the code, there is no restriction other than the software on being able to dynamically register a different USB with different characteristics every time right?

Those values you share are used in a variable called:
Code:
// USB Device Descriptor.  The USB host reads this first, to learn
// what type of device is connected.
static uint8_t device_descriptor[] = {

which is later use in:
Code:
// This table provides access to all the descriptor data above.

const usb_descriptor_list_t usb_descriptor_list[] = {
	//wValue, wIndex, address,          length
	{0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},

which ends up being used by the function
Code:
static void endpoint0_setup(uint64_t setupdata)
{
	setup_t setup;
	uint32_t endpoint, dir, ctrl;
	const usb_descriptor_list_t *list;

which is called by usb_init().

I'm not saying that it's easy to change the code to implement the capabilities to set the vendor, product, manufacturer... but if I'm not wrong is a software problem of implementing the APIs in the library to set it up, right?

Thank you
 
Back
Top