PlatformIO Community

Library don't see definitions from Arduino.h

I am an absolute noob about c++ and Platformio projects. I am trying to run an example of Adafruit TinyUSB library. What I understand is that compiler should see definitions in platform libs (Espressif ESP32-s2) for TinyUSB for in Adafruit TinyUSB lib. Eg. identifier CFG_TUD_HID is defined in tools/sdk/esp32s2/include/arduino_tinyusb/include/tusb_config.h:104. This identifier is used inside Adafruit lib, but the compiler return an error because the definition of classes and types are hidden under #ifdef CFG_TUD_HID clause.

At the beginning I have

#include "Arduino.h"
#include "Adafruit_TinyUSB.h"

Arduino.h (espressif implementation) should contain identifiers definitions for Adafruit_TinyUSB.h, or am I wrong?

So where is problem? I am using lastest Platformio with settings for Lolin S2 Mini (ESP32-s2 board). It is in settings of compier, setting of platformio or not including some library?

[env:lolin_s2_mini]
platform = espressif32
board = lolin_s2_mini
framework = arduino
lib_deps =
    FS
    SD
    adafruit/Adafruit TinyUSB Library@^1.10.3

Edit:
Compiler message

====================[ Build | Production | lolin_s2_mini ]======================
C:\Users\jakub\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\222.2889.11\bin\cmake\win\bin\cmake.exe --build C:\Users\jakub\CLionProjects\macropad\cmake-build-lolin_s2_mini --target Production -j 3
[1/1] cmd.exe /C "cd /D C:\Users\jakub\CLionProjects\macropad && platformio -c clion run -elolin_s2_mini"
FAILED: CMakeFiles/Production C:/Users/jakub/CLionProjects/macropad/cmake-build-lolin_s2_mini/CMakeFiles/Production 
cmd.exe /C "cd /D C:\Users\jakub\CLionProjects\macropad && platformio -c clion run -elolin_s2_mini"
Processing lolin_s2_mini (platform: espressif32; board: lolin_s2_mini; framework: arduino)
--------------------------------------------------------------------------------
Removing unused dependencies...
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/lolin_s2_mini.html
PLATFORM: Espressif 32 (4.4.0) > WEMOS LOLIN S2 Mini
HARDWARE: ESP32S2 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 @ 3.20003.0 (2.0.3) 
 - tool-esptoolpy @ 1.30300.0 (3.3.0) 
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch3 
 - toolchain-xtensa-esp32s2 @ 8.4.0+2021r2-patch3
LDF Modes: Finder ~ chain, Compatibility ~ soft
Library Manager: Installing Adafruit_I2CDevice
Warning! Could not find the package with 'Adafruit_I2CDevice' requirements for your system 'windows_amd64'
Found 65 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Adafruit SSD1306 @ 2.5.3
|   |-- Adafruit GFX Library @ 1.11.1
|   |   |-- Adafruit BusIO @ 1.11.6
|   |   |   |-- Wire @ 2.0.0
|   |   |   |-- SPI @ 2.0.0
|   |   |-- Wire @ 2.0.0
|   |   |-- SPI @ 2.0.0
|   |-- SPI @ 2.0.0
|   |-- Wire @ 2.0.0
|-- Adafruit GFX Library @ 1.11.1
|   |-- Adafruit BusIO @ 1.11.6
|   |   |-- Wire @ 2.0.0
|   |   |-- SPI @ 2.0.0
|   |-- Wire @ 2.0.0
|   |-- SPI @ 2.0.0
|-- Keypad @ 3.1.1
|-- FS @ 2.0.0
|-- SD @ 2.0.0
|   |-- FS @ 2.0.0
|   |-- SPI @ 2.0.0
|-- tcMenu @ 2.3.1
|   |-- IoAbstraction @ 2.3.1
|   |   |-- Wire @ 2.0.0
|   |   |-- SimpleCollections @ 1.2.0
|   |   |-- TaskManagerIO @ 1.3.3
|   |   |   |-- ESP32 BLE Arduino @ 2.0.0
|   |   |-- EEPROM @ 2.0.0
|   |-- SimpleCollections @ 1.2.0
|-- IoAbstraction @ 2.3.1
|   |-- Wire @ 2.0.0
|   |-- SimpleCollections @ 1.2.0
|   |-- TaskManagerIO @ 1.3.3
|   |   |-- ESP32 BLE Arduino @ 2.0.0
|   |-- EEPROM @ 2.0.0
|-- U8g2 @ 2.33.4
|   |-- SPI @ 2.0.0
|   |-- Wire @ 2.0.0
|-- SimpleCLI @ 1.1.3
|-- Regexp @ 0.1.0
|-- Adafruit TinyUSB Library @ 1.10.3
|-- Preferences @ 2.0.0
|-- Adafruit BusIO @ 1.11.6
|   |-- Wire @ 2.0.0
|   |-- SPI @ 2.0.0
|-- EEPROM @ 2.0.0
|-- Wire @ 2.0.0
Building in release mode
Compiling .pio\build\lolin_s2_mini\src\MacroKeypad.cpp.o
Compiling .pio\build\lolin_s2_mini\src\cli.cpp.o
Compiling .pio\build\lolin_s2_mini\src\hidHandler.cpp.o
Compiling .pio\build\lolin_s2_mini\src\keyAction.cpp.o
In file included from .pio/libdeps/lolin_s2_mini/Adafruit TinyUSB Library/src/tusb_option.h:176,
                 from .pio/libdeps/lolin_s2_mini/Adafruit TinyUSB Library/src/Adafruit_TinyUSB.h:34,
                 from src/hidHandler.cpp:3:
.pio/libdeps/lolin_s2_mini/Adafruit TinyUSB Library/src/common/tusb_mcu.h:276:4: warning: #warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8" [-Wcpp]
   #warning "TUP_DCD_ENDPOINT_MAX is not defined for this MCU, default to 8"
    ^~~~~~~
Compiling .pio\build\lolin_s2_mini\src\macroPreferences.cpp.o
src/hidHandler.cpp:9:45: error: 'hid_report_type_t' has not been declared
 void hid_report_callback(uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize) {
                                             ^~~~~~~~~~~~~~~~~
src/hidHandler.cpp: In function 'void hid_report_callback(uint8_t, int, const uint8_t*, uint16_t)':
src/hidHandler.cpp:14:24: error: 'HID_REPORT_TYPE_OUTPUT' was not declared in this scope
     if (report_type != HID_REPORT_TYPE_OUTPUT) return;
                        ^~~~~~~~~~~~~~~~~~~~~~
src/hidHandler.cpp: At global scope:
src/hidHandler.cpp:22:17: error: 'TUD_HID_REPORT_DESC_KEYBOARD' was not declared in this scope
                 TUD_HID_REPORT_DESC_KEYBOARD()
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/hidHandler.cpp:27:1: error: 'Adafruit_USBD_HID' does not name a type
 Adafruit_USBD_HID usb_hid(desc_hid_report, sizeof(desc_hid_report), HID_ITF_PROTOCOL_KEYBOARD, 2, false);
 ^~~~~~~~~~~~~~~~~
src/hidHandler.cpp:30:22: error: 'HID_KEY_ARROW_RIGHT' was not declared in this scope
 uint8_t hidcode[] = {HID_KEY_ARROW_RIGHT, HID_KEY_ARROW_LEFT, HID_KEY_ARROW_DOWN, HID_KEY_ARROW_UP};
                      ^~~~~~~~~~~~~~~~~~~
Compiling .pio\build\lolin_s2_mini\src\main.cpp.o
src/hidHandler.cpp:30:43: error: 'HID_KEY_ARROW_LEFT' was not declared in this scope
 uint8_t hidcode[] = {HID_KEY_ARROW_RIGHT, HID_KEY_ARROW_LEFT, HID_KEY_ARROW_DOWN, HID_KEY_ARROW_UP};
                                           ^~~~~~~~~~~~~~~~~~
src/hidHandler.cpp:30:63: error: 'HID_KEY_ARROW_DOWN' was not declared in this scope
 uint8_t hidcode[] = {HID_KEY_ARROW_RIGHT, HID_KEY_ARROW_LEFT, HID_KEY_ARROW_DOWN, HID_KEY_ARROW_UP};
                                                               ^~~~~~~~~~~~~~~~~~
src/hidHandler.cpp:30:83: error: 'HID_KEY_ARROW_UP' was not declared in this scope
 uint8_t hidcode[] = {HID_KEY_ARROW_RIGHT, HID_KEY_ARROW_LEFT, HID_KEY_ARROW_DOWN, HID_KEY_ARROW_UP};
                                                                                   ^~~~~~~~~~~~~~~~
Compiling .pio\build\lolin_s2_mini\src\menu_menu.cpp.o
src/hidHandler.cpp: In function 'void setupHid()':
src/hidHandler.cpp:46:5: error: 'usb_hid' was not declared in this scope
     usb_hid.setReportCallback(NULL, hid_report_callback);
     ^~~~~~~
src/hidHandler.cpp:51:13: error: 'TinyUSBDevice' was not declared in this scope
     while (!TinyUSBDevice.mounted()) delay(1);
             ^~~~~~~~~~~~~
src/hidHandler.cpp: In function 'void sendKey()':
src/hidHandler.cpp:65:9: error: 'TinyUSBDevice' was not declared in this scope
     if (TinyUSBDevice.suspended() && count) {
         ^~~~~~~~~~~~~
src/hidHandler.cpp:72:10: error: 'usb_hid' was not declared in this scope
     if (!usb_hid.ready()) return;
          ^~~~~~~
src/hidHandler.cpp:81:9: error: 'usb_hid' was not declared in this scope
         usb_hid.keyboardReport(report_id, modifier, keycode);
         ^~~~~~~
src/hidHandler.cpp:88:13: error: 'usb_hid' was not declared in this scope
             usb_hid.keyboardRelease(0);
             ^~~~~~~
*** [.pio\build\lolin_s2_mini\src\hidHandler.cpp.o] Error 1
========================= [FAILED] Took 18.90 seconds =========================
ninja: build stopped: subcommand failed.

I don’t see any mention of Adafruit_TinyUSB.h at all in Search · Adafruit_TinyUSB.h · GitHub? The ore already has TinyUSB built-in (arduino-esp32/tools/sdk/esp32s2/include/arduino_tinyusb at master · espressif/arduino-esp32 · GitHub), so you shouldn’t add it to lib_deps.

Are you sure you don’t want to use the built-in USB library arduino-esp32/libraries/USB/examples at master · espressif/arduino-esp32 · GitHub?