60 lines
2.0 KiB
C
60 lines
2.0 KiB
C
/* SPDX-License-Identifier: GPL-3.0-or-later
|
|
* 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"
|
|
#include "tusb_cdc_acm.h"
|
|
#include "tusb_dfu_rt.h"
|
|
#include "tusb_console.h"
|
|
#include "sdkconfig.h"
|
|
|
|
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");
|
|
// 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
|
|
ESP_ERROR_CHECK( tusb_dfu_rf_init() ); // configure DFU runtime (ensures we can use it)
|
|
esp_tusb_init_console(TINYUSB_CDC_ACM_0); // log to USB
|
|
ESP_LOGI(TAG, "USB initialized");
|
|
|
|
ESP_LOGI(TAG, "application ready");
|
|
while (1) {
|
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
|
}
|
|
}
|