mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
feat(usb_device): Update examples to esp_tinyusb v2.0.0
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
## IDF Component Manager Manifest File
|
||||
dependencies:
|
||||
espressif/esp_tinyusb: "^1"
|
||||
espressif/esp_tinyusb:
|
||||
version: "^2.0.0"
|
||||
idf: "^5.0"
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
|
||||
// DESCRIPTION:
|
||||
// This example contains minimal code to make ESP32-S2 based device
|
||||
// recognizable by USB-host devices as a USB Serial Device printing output from
|
||||
// the application.
|
||||
// This example contains minimal code to make a USB device, recognizable by USB-host as
|
||||
// a USB Serial Device printing output from the application.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -16,8 +15,9 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "tinyusb.h"
|
||||
#include "tusb_cdc_acm.h"
|
||||
#include "tusb_console.h"
|
||||
#include "tinyusb_default_config.h"
|
||||
#include "tinyusb_cdc_acm.h"
|
||||
#include "tinyusb_console.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
static const char *TAG = "example";
|
||||
@@ -27,23 +27,11 @@ void app_main(void)
|
||||
/* Setting TinyUSB up */
|
||||
ESP_LOGI(TAG, "USB initialization");
|
||||
|
||||
const tinyusb_config_t tusb_cfg = {
|
||||
.device_descriptor = NULL,
|
||||
.string_descriptor = NULL,
|
||||
.external_phy = false, // In the most cases you need to use a `false` value
|
||||
#if (TUD_OPT_HIGH_SPEED)
|
||||
.fs_configuration_descriptor = NULL,
|
||||
.hs_configuration_descriptor = NULL,
|
||||
.qualifier_descriptor = NULL,
|
||||
#else
|
||||
.configuration_descriptor = NULL,
|
||||
#endif // TUD_OPT_HIGH_SPEED
|
||||
};
|
||||
|
||||
const tinyusb_config_t tusb_cfg = TINYUSB_DEFAULT_CONFIG();
|
||||
ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));
|
||||
|
||||
tinyusb_config_cdcacm_t acm_cfg = { 0 }; // the configuration uses default values
|
||||
ESP_ERROR_CHECK(tusb_cdc_acm_init(&acm_cfg));
|
||||
ESP_ERROR_CHECK(tinyusb_cdcacm_init(&acm_cfg));
|
||||
|
||||
ESP_LOGI(TAG, "USB initialization DONE");
|
||||
while (1) {
|
||||
@@ -54,13 +42,13 @@ void app_main(void)
|
||||
fprintf(stderr, "example: print -> stderr\n");
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
|
||||
esp_tusb_init_console(TINYUSB_CDC_ACM_0); // log to usb
|
||||
ESP_ERROR_CHECK(tinyusb_console_init(TINYUSB_CDC_ACM_0)); // log to usb
|
||||
ESP_LOGI(TAG, "log -> USB");
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
fprintf(stdout, "example: print -> stdout\n");
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
fprintf(stderr, "example: print -> stderr\n");
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
esp_tusb_deinit_console(TINYUSB_CDC_ACM_0); // log to uart
|
||||
ESP_ERROR_CHECK(tinyusb_console_deinit(TINYUSB_CDC_ACM_0)); // log to uart
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user