10
10
11
11
#include "soc/soc.h"
12
12
#include "soc/efuse_reg.h"
13
+ #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
13
14
#include "soc/rtc_cntl_reg.h"
14
15
#include "soc/usb_struct.h"
15
16
#include "soc/usb_reg.h"
16
17
#include "soc/usb_wrap_reg.h"
17
18
#include "soc/usb_wrap_struct.h"
18
19
#include "soc/usb_periph.h"
20
+ #endif
21
+
19
22
#include "soc/periph_defs.h"
20
23
#include "soc/timer_group_struct.h"
21
24
#include "soc/system_reg.h"
34
37
35
38
#include "esp32-hal.h"
36
39
#include "esp32-hal-periman.h"
37
-
38
40
#include "esp32-hal-tinyusb.h"
41
+
39
42
#if CONFIG_IDF_TARGET_ESP32S2
40
43
#include "esp32s2/rom/usb/usb_persist.h"
41
44
#include "esp32s2/rom/usb/usb_dc.h"
50
53
#include "esp32s3/rom/usb/usb_persist.h"
51
54
#include "esp32s3/rom/usb/usb_dc.h"
52
55
#include "esp32s3/rom/usb/chip_usb_dw_wrapper.h"
56
+ #elif CONFIG_IDF_TARGET_ESP32P4
53
57
#endif
54
58
55
59
typedef enum {
@@ -467,8 +471,10 @@ __attribute__((weak)) void tud_network_init_cb(void) {}
467
471
/*
468
472
* Private API
469
473
* */
474
+ #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
470
475
static bool usb_persist_enabled = false;
471
476
static restart_type_t usb_persist_mode = RESTART_NO_PERSIST ;
477
+ #endif
472
478
473
479
#if CONFIG_IDF_TARGET_ESP32S3
474
480
@@ -549,6 +555,7 @@ static void usb_switch_to_cdc_jtag() {
549
555
}
550
556
#endif
551
557
558
+ #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
552
559
static void IRAM_ATTR usb_persist_shutdown_handler (void ) {
553
560
if (usb_persist_mode != RESTART_NO_PERSIST ) {
554
561
if (usb_persist_enabled ) {
@@ -580,8 +587,10 @@ static void IRAM_ATTR usb_persist_shutdown_handler(void) {
580
587
}
581
588
}
582
589
}
590
+ #endif
583
591
584
592
void usb_persist_restart (restart_type_t mode ) {
593
+ #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
585
594
if (mode < RESTART_TYPE_MAX && esp_register_shutdown_handler (usb_persist_shutdown_handler ) == ESP_OK ) {
586
595
usb_persist_mode = mode ;
587
596
#if CONFIG_IDF_TARGET_ESP32S3
@@ -591,6 +600,7 @@ void usb_persist_restart(restart_type_t mode) {
591
600
#endif
592
601
esp_restart ();
593
602
}
603
+ #endif
594
604
}
595
605
596
606
static bool tinyusb_reserve_in_endpoint (uint8_t endpoint ) {
@@ -674,8 +684,13 @@ static inline char nibble_to_hex_char(uint8_t b) {
674
684
675
685
static void set_usb_serial_num (void ) {
676
686
/* 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
677
691
const uint32_t mac0 = REG_GET_FIELD (EFUSE_RD_MAC_SPI_SYS_0_REG , EFUSE_MAC_0 );
678
692
const uint32_t mac1 = REG_GET_FIELD (EFUSE_RD_MAC_SPI_SYS_1_REG , EFUSE_MAC_1 );
693
+ #endif
679
694
uint8_t mac_bytes [6 ];
680
695
memcpy (mac_bytes , & mac0 , 4 );
681
696
memcpy (mac_bytes + 4 , & mac1 , 2 );
@@ -794,6 +809,7 @@ esp_err_t tinyusb_init(tinyusb_device_config_t *config) {
794
809
return ESP_FAIL ;
795
810
}
796
811
812
+ #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
797
813
bool usb_did_persist = (USB_WRAP .date .val == USBDC_PERSIST_ENA );
798
814
799
815
//if(usb_did_persist && usb_persist_enabled){
@@ -806,7 +822,8 @@ esp_err_t tinyusb_init(tinyusb_device_config_t *config) {
806
822
periph_ll_reset (PERIPH_USB_MODULE );
807
823
periph_ll_enable_clk_clear_rst (PERIPH_USB_MODULE );
808
824
}
809
-
825
+ #endif
826
+
810
827
tinyusb_config_t tusb_cfg = {
811
828
.external_phy = false // In the most cases you need to use a `false` value
812
829
};
0 commit comments