1010
1111#include "soc/soc.h"
1212#include "soc/efuse_reg.h"
13+ #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
1314#include "soc/rtc_cntl_reg.h"
1415#include "soc/usb_struct.h"
1516#include "soc/usb_reg.h"
1617#include "soc/usb_wrap_reg.h"
1718#include "soc/usb_wrap_struct.h"
1819#include "soc/usb_periph.h"
20+ #endif
21+
1922#include "soc/periph_defs.h"
2023#include "soc/timer_group_struct.h"
2124#include "soc/system_reg.h"
3437
3538#include "esp32-hal.h"
3639#include "esp32-hal-periman.h"
37-
3840#include "esp32-hal-tinyusb.h"
41+
3942#if CONFIG_IDF_TARGET_ESP32S2
4043#include "esp32s2/rom/usb/usb_persist.h"
4144#include "esp32s2/rom/usb/usb_dc.h"
5053#include "esp32s3/rom/usb/usb_persist.h"
5154#include "esp32s3/rom/usb/usb_dc.h"
5255#include "esp32s3/rom/usb/chip_usb_dw_wrapper.h"
56+ #elif CONFIG_IDF_TARGET_ESP32P4
5357#endif
5458
5559typedef enum {
@@ -467,8 +471,10 @@ __attribute__((weak)) void tud_network_init_cb(void) {}
467471/*
468472 * Private API
469473 * */
474+ #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
470475static bool usb_persist_enabled = false;
471476static restart_type_t usb_persist_mode = RESTART_NO_PERSIST ;
477+ #endif
472478
473479#if CONFIG_IDF_TARGET_ESP32S3
474480
@@ -549,6 +555,7 @@ static void usb_switch_to_cdc_jtag() {
549555}
550556#endif
551557
558+ #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
552559static void IRAM_ATTR usb_persist_shutdown_handler (void ) {
553560 if (usb_persist_mode != RESTART_NO_PERSIST ) {
554561 if (usb_persist_enabled ) {
@@ -580,8 +587,10 @@ static void IRAM_ATTR usb_persist_shutdown_handler(void) {
580587 }
581588 }
582589}
590+ #endif
583591
584592void usb_persist_restart (restart_type_t mode ) {
593+ #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
585594 if (mode < RESTART_TYPE_MAX && esp_register_shutdown_handler (usb_persist_shutdown_handler ) == ESP_OK ) {
586595 usb_persist_mode = mode ;
587596#if CONFIG_IDF_TARGET_ESP32S3
@@ -591,6 +600,7 @@ void usb_persist_restart(restart_type_t mode) {
591600#endif
592601 esp_restart ();
593602 }
603+ #endif
594604}
595605
596606static bool tinyusb_reserve_in_endpoint (uint8_t endpoint ) {
@@ -674,8 +684,13 @@ static inline char nibble_to_hex_char(uint8_t b) {
674684
675685static void set_usb_serial_num (void ) {
676686 /* Get the MAC address */
687+ #if CONFIG_IDF_TARGET_ESP32P4
688+ const uint32_t mac0 = REG_GET_FIELD (EFUSE_RD_MAC_SYS_0_REG , EFUSE_MAC_0 );
689+ const uint32_t mac1 = REG_GET_FIELD (EFUSE_RD_MAC_SYS_0_REG , EFUSE_MAC_1 );
690+ #else
677691 const uint32_t mac0 = REG_GET_FIELD (EFUSE_RD_MAC_SPI_SYS_0_REG , EFUSE_MAC_0 );
678692 const uint32_t mac1 = REG_GET_FIELD (EFUSE_RD_MAC_SPI_SYS_1_REG , EFUSE_MAC_1 );
693+ #endif
679694 uint8_t mac_bytes [6 ];
680695 memcpy (mac_bytes , & mac0 , 4 );
681696 memcpy (mac_bytes + 4 , & mac1 , 2 );
@@ -794,6 +809,7 @@ esp_err_t tinyusb_init(tinyusb_device_config_t *config) {
794809 return ESP_FAIL ;
795810 }
796811
812+ #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
797813 bool usb_did_persist = (USB_WRAP .date .val == USBDC_PERSIST_ENA );
798814
799815 //if(usb_did_persist && usb_persist_enabled){
@@ -806,7 +822,8 @@ esp_err_t tinyusb_init(tinyusb_device_config_t *config) {
806822 periph_ll_reset (PERIPH_USB_MODULE );
807823 periph_ll_enable_clk_clear_rst (PERIPH_USB_MODULE );
808824 }
809-
825+ #endif
826+
810827 tinyusb_config_t tusb_cfg = {
811828 .external_phy = false // In the most cases you need to use a `false` value
812829 };
0 commit comments