0

My development environment consists of a Teensy 3.5, PlatformIO, and CLion. How can I make use of the standard Arduino Keyboard library?

I'm working on a project to convert a previously RS422-based device to USB. Earlier on, I used the (sadly rather horrible) Arduino IDE so I know that my code for when to send which keystrokes should work; the problem is getting the new IDE and compiler to understand the dependencies.

All along, I've been using the Serial interface to provide debug output, so I know that Serial works just fine. Ditto for using the Keyboard library from within the Arduino IDE.

However, after switching to CLion and adapting to the PlatformIO framework, I ran into problems when it came time to include the Keyboard library.

The line

#include <Arduino.h>

resolves to the file ~/.platformio/packages/framework-arduinoteensy/cores/teensy3/Arduino.h which itself seems to simply be a shim for ~/.platformio/packages/framework-arduinoteensy/cores/teensy3/WProgram.h which implements the expected Arduino functionality.

However, the line

#include <Keyboard.h>

resolves to the file ~/.platformio/packages/framework-arduinoteensy/cores/teensy3/Keyboard.h which quite frankly states that it is an empty Keyboard.h file, for compability with Arduino's Keyboard examples and does not implement anything.

I have been trying to find ways of importing the original Arduino library (by way of platformio.ini, but it seems to depend on HID and PluggableUSB that I simply cannot find.

Here is my current platformio.ini file:

[env:teensy35]
platform = teensy
board = teensy35
framework = arduino

; Avoid the Teensy loader gui app
upload_protocol = teensy-cli

lib_deps =
    Keyboard

and this is the build output I am getting:

====================[ Build | Production | teensy35 ]===========================
~/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/223.8617.54/bin/cmake/linux/x64/bin/cmake --build ~/code/teensy-axial/cmake-build-teensy35 --target Production -j 6
[1/1] cd ~/code/teensy-axial && platformio -c clion run -eteensy35
FAILED: CMakeFiles/Production ~/code/teensy-axial/cmake-build-teensy35/CMakeFiles/Production
cd ~/code/teensy-axial && platformio -c clion run -eteensy35
Processing teensy35 (platform: teensy; board: teensy35; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy35.html
PLATFORM: Teensy (4.17.0) > Teensy 3.5
HARDWARE: MK64FX512 120MHz, 255.99KB RAM, 512KB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES:
- framework-arduinoteensy @ 1.157.220801 (1.57)
- toolchain-gccarmnoneeabi @ 1.50401.190816 (5.4.1)
LDF: Library Dependency Finder -> [redacted for StackExchange]
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 94 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Keyboard @ 1.0.4
Building in release mode
Compiling .pio/build/teensy35/src/AxialKeyboard.cpp.o
Compiling .pio/build/teensy35/src/main.cpp.o
Compiling .pio/build/teensy35/lib882/Keyboard/Keyboard.cpp.o
Compiling .pio/build/teensy35/lib882/Keyboard/KeyboardLayout_da_DK.cpp.o
Compiling .pio/build/teensy35/lib882/Keyboard/KeyboardLayout_de_DE.cpp.o
In file included from .pio/libdeps/teensy35/Keyboard/src/Keyboard.cpp:22:0:
.pio/libdeps/teensy35/Keyboard/src/Keyboard.h:25:17: fatal error: HID.h: No such file or directory

*************************************************************
* Looking for HID.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:HID.h"
* Web  > https://registry.platformio.org/search?q=header:HID.h
*
*************************************************************

compilation terminated.
[...]

I have obviously visited the registry as suggested and tried to implement both mitchman631/HID and levi--g/USBLibrarySTM32 but still I end up missing either HID or PluggableUSB dependencies, and I cannot find a PluggableUSB.h file anywhere. Surely, there must be something fundamental I am not seeing?

Amending platformio.ini with the path to the Arduino libraries did not resolve the error.

lib_extra_dirs =
    /usr/share/arduino/libraries

so I removed these lines again.

I have also tried enabling the --verbose option by copying the command from the above output:

~/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/223.8617.54/bin/cmake/linux/x64/bin/cmake --verbose --build ~/code/teensy-axial/cmake-build-teensy35

but oddly that results in

CMake Error: Unknown argument --build

even though it should know it:

~/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/223.8617.54/bin/cmake/linux/x64/bin/cmake --help | grep build
  cmake [options] <path-to-existing-build>
  cmake [options] -S <path-to-source> -B <path-to-build>
Specify a source directory to (re-)generate a build system for it in the
current working directory.  Specify an existing build directory to
re-generate its build system.
  -B <path-to-build>           = Explicitly specify a build directory.
  -G <generator-name>          = Specify a build system generator.
  --build <dir>                = Build a CMake-generated project binary tree.

I suspect my question is similar to this one, although my problem is with adding any library.

noughtnaut
  • 99
  • 5

0 Answers0