DaveBoulden
Member
I am attempting to create a MIDI controller project that also requires use of the Keyboard class to send keystrokes to the USB host alongside MIDI messages.
I have already read many posts on here and elsewhere across the internet on how to edit usb_desc.h in order to change the endpoints declared within a project. Everything I have read so far seems to apply to Teensy 3.x though, and so I don't know if the correct procedure is still the same on a Teensy 4.x board. I am currently building projects in VS Code using Platform.IO to target a Teensy 4.0 and using the MIDI+Serial USB type as there is currently no MIDI/Keyboard/Serial USB type. To avoid editing core module code, I have added a names.c code file to my project with the intention of overriding the USB product name, MIDI port name and to include KEYBOARD_INTERFACE and KEYMEDIA_INTERFACE endpoints to achieve the mixed USB type I require by way of supplementing the USB_MIDI_SERIAL USB type. The code I currently have in my names.c file is:
This is successfully changing the MIDI port name and the USB product name, but does not seem to allow me to use the Keyboard object in my man .cpp code. Including something like Keyboard.print("A") in my main loop produces a compile error:
Should I be directly including usb_keyboard.h or instantiating usb_keyboard_class in some other way, or is it that my endpoint config is not overriding the declarations in core and so not invoking the Keyboard object as it would when choosing a Keyboard oriented USB type? I did try the USB_EVERYTHING USB type, but it does not seem to compile cleanly on my Teensy 4.0
Does anyone have any pointers that apply specifically to achieving this on a Teensy 4.x?
I have already read many posts on here and elsewhere across the internet on how to edit usb_desc.h in order to change the endpoints declared within a project. Everything I have read so far seems to apply to Teensy 3.x though, and so I don't know if the correct procedure is still the same on a Teensy 4.x board. I am currently building projects in VS Code using Platform.IO to target a Teensy 4.0 and using the MIDI+Serial USB type as there is currently no MIDI/Keyboard/Serial USB type. To avoid editing core module code, I have added a names.c code file to my project with the intention of overriding the USB product name, MIDI port name and to include KEYBOARD_INTERFACE and KEYMEDIA_INTERFACE endpoints to achieve the mixed USB type I require by way of supplementing the USB_MIDI_SERIAL USB type. The code I currently have in my names.c file is:
Code:
#include "usb_names.h"
#define MANUFACTURER_NAME {'B','O','U','L','D','E','N','d','i','g','i','t','a','l'}
#define MANUFACTURER_NAME_LEN 14
#define PRODUCT_NAME {'B','d','i','g','i','t','a','l','C','t','r','l','-','1'}
#define PRODUCT_NAME_LEN 14
#define SERIAL_NUMBER { 'B', 'D', '-', 'B', 'D', '1', '-', '0', '0', '1' }
#define SERIAL_NUMBER_LEN 10
// override endpoints config of USB_MIDI_SERIAL to add KEYBOARD and KEYMEDIA
#define NUM_ENDPOINTS 7
#define NUM_USB_BUFFERS 40
#define NUM_INTERFACE 5
#define KEYBOARD_INTERFACE 4 // Keyboard
#define KEYBOARD_ENDPOINT 6
#define KEYBOARD_SIZE 8
#define KEYBOARD_INTERVAL 1
#define KEYMEDIA_INTERFACE 5 // Keyboard Media Keys
#define KEYMEDIA_ENDPOINT 7
#define KEYMEDIA_SIZE 8
#define KEYMEDIA_INTERVAL 4
#define ENDPOINT6_CONFIG ENDPOINT_TRANSIMIT_ONLY
#define ENDPOINT7_CONFIG ENDPOINT_TRANSIMIT_ONLY
struct usb_string_descriptor_struct usb_string_manufacturer_name = {
2 + MANUFACTURER_NAME_LEN * 2,
3,
MANUFACTURER_NAME};
struct usb_string_descriptor_struct usb_string_product_name = {
2 + PRODUCT_NAME_LEN * 2,
3,
PRODUCT_NAME};
struct usb_string_descriptor_struct usb_string_serial_number = {
2 + SERIAL_NUMBER_LEN * 2,
3,
SERIAL_NUMBER};
This is successfully changing the MIDI port name and the USB product name, but does not seem to allow me to use the Keyboard object in my man .cpp code. Including something like Keyboard.print("A") in my main loop produces a compile error:
Code:
src\button-matrix.cpp: In function 'void loop()':
src\button-matrix.cpp:546:17: error: 'Keyboard' was not declared in this scope
Keyboard.print("G");
^
*** [.pio\build\teensy40\src\button-matrix.cpp.o] Error 1
Should I be directly including usb_keyboard.h or instantiating usb_keyboard_class in some other way, or is it that my endpoint config is not overriding the declarations in core and so not invoking the Keyboard object as it would when choosing a Keyboard oriented USB type? I did try the USB_EVERYTHING USB type, but it does not seem to compile cleanly on my Teensy 4.0
Does anyone have any pointers that apply specifically to achieving this on a Teensy 4.x?