main: set USB serial

This commit is contained in:
King Kévin 2023-01-07 01:43:01 +01:00
parent a83b498255
commit f97bdff491
1 changed files with 27 additions and 2 deletions

View File

@ -1,10 +1,11 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright 2022 King Kévin <kingkevin@cuvoodoo.info>
* Copyright 2022-2023 King Kévin <kingkevin@cuvoodoo.info>
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/reent.h>
#include "esp_log.h"
#include "esp_mac.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "tinyusb.h"
@ -15,11 +16,35 @@
static const char *TAG = "main";
/**
* @brief USB string descriptor
*/
static const char* usb_str_desc[USB_STRING_DESCRIPTOR_ARRAY_SIZE] = {
(char[]){0x09, 0x04}, // 0: language: English
CONFIG_TINYUSB_DESC_MANUFACTURER_STRING, // 1: Manufacturer
CONFIG_TINYUSB_DESC_PRODUCT_STRING, // 2: Product
CONFIG_TINYUSB_DESC_SERIAL_STRING, // 3: Serials, should use chip ID
CONFIG_TINYUSB_DESC_CDC_STRING, // 4: CDC Interface
"", // 5: MSC Interface
"DFU (runtime mode)" // 6: DFU RT
};
void app_main(void)
{
// setup USB CDC ACM for printing
ESP_LOGI(TAG, "USB initialization");
tinyusb_config_t tusb_cfg = { 0 }; // the configuration uses default values
// get MAC
uint8_t mac[6];
esp_read_mac(mac, ESP_MAC_ETH);
static char usb_serial[13] = {0};
snprintf(usb_serial, sizeof(usb_serial), "%02X%02X%02X%02X%02X%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
usb_str_desc[3] = usb_serial;
const tinyusb_config_t tusb_cfg = {
.device_descriptor = NULL, // use default USB descriptor
.string_descriptor = usb_str_desc, // use custom string description to set serial
.external_phy = false, // use integrated phy
.configuration_descriptor = NULL,
};
ESP_ERROR_CHECK( tinyusb_driver_install(&tusb_cfg) ); // configure USB
tinyusb_config_cdcacm_t amc_cfg = { 0 }; // the configuration uses default values
ESP_ERROR_CHECK( tusb_cdc_acm_init(&amc_cfg) ); // configure CDC ACM