Adafruit Tiny USB

Platformio.ini

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:esp32-s3-supermini]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
board_build.flash_size = 4MB
board_upload.flash_size = 4MB
board_build.partitions = default.csv
monitor_speed = 115200
build_flags = 
    -D ARDUINO_USB_MODE=1
    -D ARDUINO_USB_CDC_ON_BOOT=1
    -D CFG_TUD_ENABLED=1
    -D USE_TINYUSB
lib_deps = 
    witnessmenow/UniversalTelegramBot@^1.3.0
    bblanchon/ArduinoJson@^7.2.2
    adafruit/Adafruit TinyUSB Library@^3.7.7
#include <Arduino.h>
#include <Adafruit_TinyUSB.h>


uint8_t const desc_boot_keyboard[] = {
  TUD_HID_REPORT_DESC_KEYBOARD()
};
Adafruit_USBD_HID usb_boot_kbd;

void sendKey(uint8_t keycode) {
  uint8_t keys[6] = { keycode, 0, 0, 0, 0, 0 };
  usb_boot_kbd.keyboardReport(0, 0, keys);
  delay(100);
  usb_boot_kbd.keyboardRelease(0);
}
void sendString(const char* str) {
  while (*str) {
    char c = *str;
    uint8_t key = 0;
    if (c >= '0' && c <= '9') {
      key = (c == '0') ? HID_KEY_0 : (HID_KEY_1 + (c - '1'));
    } else if (c >= 'a' && c <= 'z') {
      key = HID_KEY_A + (c - 'a');
    } else if (c >= 'A' && c <= 'Z') {
      key = HID_KEY_A + (c - 'A');
    }
    if (key != 0) {
      sendKey(key);
      delay(50);
    }
    str++;
  }
}

void setup() {

  TinyUSBDevice.begin();


  Serial.begin(115200);

  usb_boot_kbd.setPollInterval(2);
  usb_boot_kbd.setReportDescriptor(desc_boot_keyboard, sizeof(desc_boot_keyboard));
  usb_boot_kbd.setBootProtocol(true);
  usb_boot_kbd.begin();

  Serial.println("USB Mount bekleniyor...");
  unsigned long startMount = millis();
  while (!TinyUSBDevice.mounted() && (millis() - startMount < 60000)) {
    delay(1000);
    Serial.print(".");
  }
  Serial.println("\n"+TinyUSBDevice.mounted());
  

}
void loop() {
}
}

I have a “ESP32 S3 Super Mini”. When I upload this code to board, it prints
“… (57 dot)” and nothing else.
When I add this code to end of setup function :

sendString("Hello, World!");
......................................................

assert failed: xQueueSemaphoreTake queue.c:1545 (( pxQueue ))


Backtrace: 0x403777da:0x3fcebc90 0x4037ac41:0x3fcebcb0 0x403805a9:0x3fcebcd0 0x4037b9a2:0x3fcebe00 0x42001f95:0x3fcebe40 0x42001d11:0x3fcebe60 0x42001c02:0x3fcebe80 0x42001ca7:0x3fcebeb0 0x42001bbb:0x3fcebee0 0x420017c4:0x3fcebf00 0x420017f9:0x3fcebf30 0x420018aa:0x3fcebf50 0x420035e6:0x3fcebf70




ELF file SHA256: 50183c5a88f78d56

Rebooting...
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x2b (SPI_FAST_FLASH_BOOT)
Saved PC:0x42021dee
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x4bc
load:0x403c9700,len:0xbd8
load:0x403cc700,len:0x2a0c
entry 0x403c98d0

when i do -D ARDUINO_USB_MODE=0
I cant compile the code.

I think I cant write this code with another library because I want to start computer with this func:

void triggerWakeup() {
  if (tud_suspended()) {
    tud_remote_wakeup();
    if(wait(250)){
      return; 
    }
  }
  sendKey(HID_KEY_SPACE);
}

How can i fix it…

Use ESP32-S3 TinyUSB OTG mode with ARDUINO_USB_MODE=0. Remove CFG_TUD_ENABLED and USE_TINYUSB definitions. Initialize TinyUSBDevice before configuring the keyboard. Always check usb_boot_kbd.ready() before sending reports.