Volume UP/DOWN with USB_SERIAL_HID

Hi Community,
I’m developing some sort of hybrid keyboard with a Teensy++ 2.0, I really like PlatformIO because it gives me a lot of possibilities but I’m still a noob with it.
I’ve just created a keyboard volume knob with a rotary encoder, basically the code below is perfectly valid:

#include <usb_private.h>
#include <Arduino.h>

...

    switch (Action) {
    case GAUGE_UP:
        Keyboard.press(KEY_MEDIA_VOLUME_DEC);
        delay(100);
        Keyboard.release(KEY_MEDIA_VOLUME_DEC);
        break;
    case GAUGE_DOWN:
        Keyboard.press(KEY_MEDIA_VOLUME_INC);
        delay(100);
        Keyboard.release(KEY_MEDIA_VOLUME_INC);
        break;
    }

I can compile it and runs fine with this platformio.ini file:

[env:teensy2pp]
platform = teensy
board = teensy2pp
framework = arduino
build_flags = -D USB_HID
extra_scripts = buildHooks.py

But in my case I also need to use a Serial Port so I switched it to:

[env:teensy2pp]
platform = teensy
board = teensy2pp
framework = arduino
build_flags = -D USB_SERIAL_HID
extra_scripts = buildHooks.py

It’s slightly different, I can still compile the whole project without troubles but it doesn’t work.
With the latest config (-D USB_SERIAL_HID) the code above doesn’t send Vol Up/Down anymore. If I use a different key (for example: KEY_A) I can see it working, but in my case I really need to use Multimedia Volume Keys (like logitech or other manufacturers do).

Do you have any hints on it ? I need a Mouse, a Keyboard and a Serial port so using USB_SERIAL_HID seems to be the right one.
Thank you in advance for your reply

Regards
Ben

This seems to be a limitation / error in the libraries you’re using rather than PlatformIO. (Double check by compiling in Arudino IDE too, but I don’t think it’ll change…)

In such a case the author of the Arduino core in its repo is the best way to get support: Issues · PaulStoffregen/cores · GitHub

1 Like

I’ve already solved but I’d like to link the solution here as well for the forum community.
Paul replied to me as Max already predicted before: this is not a PlatformIO error nor something related to Arduino libs but seems to be a limit with older boards (8bit teensy) related to maximum endpoints available.

https://forum.pjrc.com/threads/61296-Keyboard-press-problems-with-Serial-Keyboard-Mouse-Joystick-profile?p=242737

Serial+Keyboard+Mouse+Joystick fill number of available endpoints and it seems media keys require an additional endpoint too. I didn’t knew that and I guess I’ll try to avoid Serial as soon as possible and do something with /dev/hidraw (on host side) and simulate transmission on that just like Serial Monitor does.

1 Like