Skip to content

Commit 3c55daa

Browse files
committed
refactor(hal_usb): move USB Serial JTAG HAL from hal component
1 parent 69a76c5 commit 3c55daa

File tree

16 files changed

+79
-50
lines changed

16 files changed

+79
-50
lines changed

components/esp_driver_usb_serial_jtag/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ endif()
1212
if(${target} STREQUAL "linux")
1313
set(priv_requires esp_ringbuf esp_timer)
1414
else()
15-
set(priv_requires esp_driver_gpio esp_ringbuf esp_pm esp_timer)
15+
set(priv_requires esp_driver_gpio esp_ringbuf esp_pm esp_timer esp_hal_usb)
1616
endif()
1717

1818
idf_component_register(SRCS ${srcs}

components/esp_driver_usb_serial_jtag/test_apps/.build-test-rules.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ components/esp_driver_usb_serial_jtag/test_apps/usb_serial_jtag:
1414
- vfs
1515
- esp_driver_gpio
1616
- esp_driver_usb_serial_jtag
17+
- esp_hal_usb
1718

1819
components/esp_driver_usb_serial_jtag/test_apps/usb_serial_jtag_vfs:
1920
disable:
@@ -28,3 +29,4 @@ components/esp_driver_usb_serial_jtag/test_apps/usb_serial_jtag_vfs:
2829
depends_components:
2930
- vfs
3031
- esp_driver_usb_serial_jtag
32+
- esp_hal_usb

components/esp_hal_usb/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,25 @@ endif()
77
set(includes "include")
88
set(srcs)
99

10+
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${target}/include")
11+
list(APPEND includes "${target}/include")
12+
endif()
13+
1014
# USB-DWC related source files and USB FSLS PHY wrapper
1115
if(CONFIG_SOC_USB_OTG_SUPPORTED)
1216
list(APPEND srcs "usb_dwc_hal.c" "usb_wrap_hal.c" "${target}/usb_dwc_periph.c")
13-
list(APPEND includes "${target}/include")
1417
endif()
1518

1619
# USB UTMI PHY
1720
if(CONFIG_SOC_USB_UTMI_PHY_NUM GREATER 0)
1821
list(APPEND srcs "usb_utmi_hal.c")
1922
endif()
2023

24+
# USB Serial JTAG
25+
if(CONFIG_SOC_USB_SERIAL_JTAG_SUPPORTED)
26+
list(APPEND srcs "usb_serial_jtag_hal.c")
27+
endif()
28+
2129
idf_component_register(SRCS ${srcs}
2230
INCLUDE_DIRS ${includes}
2331
REQUIRES soc hal)

components/esp_hal_usb/README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,16 @@ The USB HAL is structured in two main sub-layers:
1919

2020
This HAL supports various USB controller and PHY types depending on the ESP chip:
2121

22-
- **USB-DWC (DesignWare USB Controller)**: The main USB OTG controller available on:
23-
- ESP32-S2
24-
- ESP32-S3
25-
- ESP32-H4
26-
- ESP32-P4
22+
- **USB-DWC (DesignWare USB Controller)**: The main USB OTG controller supporting USB Host and Device modes
23+
24+
- **USB Serial JTAG**: A special USB peripheral that combines USB CDC-ACM functionality with JTAG debugging capabilities
2725

2826
- **USB WRAP**: A wrapper/peripheral controller that provides additional USB functionality and GPIO matrix integration
2927

3028
- **USB PHY Types**:
3129
- **FSLS (Full Speed/Low Speed) Internal PHY**: Built-in PHY supporting USB Full Speed and Low Speed operation
3230
- **FSLS External PHY**: Support for external FSLS PHY via GPIO matrix
33-
- **UTMI PHY**: UTMI+ compliant PHY interface (available on ESP32-P4)
31+
- **UTMI PHY**: UTMI+ compliant PHY interface for High Speed USB support
3432

3533
## Features
3634

components/hal/esp32c3/include/hal/usb_serial_jtag_ll.h renamed to components/esp_hal_usb/esp32c3/include/hal/usb_serial_jtag_ll.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ typedef enum {
3131
USB_SERIAL_JTAG_INTR_EP1_ZERO_PAYLOAD = (1 << 10),
3232
} usb_serial_jtag_ll_intr_t;
3333

34-
3534
#ifdef __cplusplus
3635
extern "C" {
3736
#endif
@@ -116,7 +115,9 @@ static inline int usb_serial_jtag_ll_read_rxfifo(uint8_t *buf, uint32_t rd_len)
116115
{
117116
int i;
118117
for (i = 0; i < (int)rd_len; i++) {
119-
if (!USB_SERIAL_JTAG.ep1_conf.serial_out_ep_data_avail) break;
118+
if (!USB_SERIAL_JTAG.ep1_conf.serial_out_ep_data_avail) {
119+
break;
120+
}
120121
buf[i] = USB_SERIAL_JTAG.ep1.rdwr_byte;
121122
}
122123
return i;
@@ -135,7 +136,9 @@ static inline int usb_serial_jtag_ll_write_txfifo(const uint8_t *buf, uint32_t w
135136
{
136137
int i;
137138
for (i = 0; i < (int)wr_len; i++) {
138-
if (!USB_SERIAL_JTAG.ep1_conf.serial_in_ep_data_free) break;
139+
if (!USB_SERIAL_JTAG.ep1_conf.serial_in_ep_data_free) {
140+
break;
141+
}
139142
USB_SERIAL_JTAG.ep1.rdwr_byte = buf[i];
140143
}
141144
return i;
@@ -178,7 +181,7 @@ static inline int usb_serial_jtag_ll_txfifo_writable(void)
178181
*/
179182
static inline void usb_serial_jtag_ll_txfifo_flush(void)
180183
{
181-
USB_SERIAL_JTAG.ep1_conf.wr_done=1;
184+
USB_SERIAL_JTAG.ep1_conf.wr_done = 1;
182185
}
183186

184187
/* ---------------------------- USB PHY Control ---------------------------- */
@@ -335,7 +338,6 @@ FORCE_INLINE_ATTR bool usb_serial_jtag_ll_module_is_enabled(void)
335338
usb_serial_jtag_ll_module_is_enabled(__VA_ARGS__); \
336339
})
337340

338-
339341
#ifdef __cplusplus
340342
}
341343
#endif

components/hal/esp32c5/include/hal/usb_serial_jtag_ll.h renamed to components/esp_hal_usb/esp32c5/include/hal/usb_serial_jtag_ll.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ static inline int usb_serial_jtag_ll_read_rxfifo(uint8_t *buf, uint32_t rd_len)
115115
{
116116
int i;
117117
for (i = 0; i < (int)rd_len; i++) {
118-
if (!USB_SERIAL_JTAG.ep1_conf.serial_out_ep_data_avail) break;
118+
if (!USB_SERIAL_JTAG.ep1_conf.serial_out_ep_data_avail) {
119+
break;
120+
}
119121
buf[i] = USB_SERIAL_JTAG.ep1.val;
120122
}
121123
return i;
@@ -134,7 +136,9 @@ static inline int usb_serial_jtag_ll_write_txfifo(const uint8_t *buf, uint32_t w
134136
{
135137
int i;
136138
for (i = 0; i < (int)wr_len; i++) {
137-
if (!USB_SERIAL_JTAG.ep1_conf.serial_in_ep_data_free) break;
139+
if (!USB_SERIAL_JTAG.ep1_conf.serial_in_ep_data_free) {
140+
break;
141+
}
138142
USB_SERIAL_JTAG.ep1.val = buf[i];
139143
}
140144
return i;
@@ -177,7 +181,7 @@ static inline int usb_serial_jtag_ll_txfifo_writable(void)
177181
*/
178182
static inline void usb_serial_jtag_ll_txfifo_flush(void)
179183
{
180-
USB_SERIAL_JTAG.ep1_conf.wr_done=1;
184+
USB_SERIAL_JTAG.ep1_conf.wr_done = 1;
181185
}
182186

183187
/**

components/hal/esp32c6/include/hal/usb_serial_jtag_ll.h renamed to components/esp_hal_usb/esp32c6/include/hal/usb_serial_jtag_ll.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ typedef enum {
3131
USB_SERIAL_JTAG_INTR_EP1_ZERO_PAYLOAD = (1 << 10),
3232
} usb_serial_jtag_ll_intr_t;
3333

34-
3534
#ifdef __cplusplus
3635
extern "C" {
3736
#endif
@@ -116,7 +115,9 @@ static inline int usb_serial_jtag_ll_read_rxfifo(uint8_t *buf, uint32_t rd_len)
116115
{
117116
int i;
118117
for (i = 0; i < (int)rd_len; i++) {
119-
if (!USB_SERIAL_JTAG.ep1_conf.serial_out_ep_data_avail) break;
118+
if (!USB_SERIAL_JTAG.ep1_conf.serial_out_ep_data_avail) {
119+
break;
120+
}
120121
buf[i] = USB_SERIAL_JTAG.ep1.rdwr_byte;
121122
}
122123
return i;
@@ -135,7 +136,9 @@ static inline int usb_serial_jtag_ll_write_txfifo(const uint8_t *buf, uint32_t w
135136
{
136137
int i;
137138
for (i = 0; i < (int)wr_len; i++) {
138-
if (!USB_SERIAL_JTAG.ep1_conf.serial_in_ep_data_free) break;
139+
if (!USB_SERIAL_JTAG.ep1_conf.serial_in_ep_data_free) {
140+
break;
141+
}
139142
USB_SERIAL_JTAG.ep1.rdwr_byte = buf[i];
140143
}
141144
return i;
@@ -178,7 +181,7 @@ static inline int usb_serial_jtag_ll_txfifo_writable(void)
178181
*/
179182
static inline void usb_serial_jtag_ll_txfifo_flush(void)
180183
{
181-
USB_SERIAL_JTAG.ep1_conf.wr_done=1;
184+
USB_SERIAL_JTAG.ep1_conf.wr_done = 1;
182185
}
183186

184187
/**

components/hal/esp32c61/include/hal/usb_serial_jtag_ll.h renamed to components/esp_hal_usb/esp32c61/include/hal/usb_serial_jtag_ll.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ static inline int usb_serial_jtag_ll_read_rxfifo(uint8_t *buf, uint32_t rd_len)
115115
{
116116
int i;
117117
for (i = 0; i < (int)rd_len; i++) {
118-
if (!USB_SERIAL_JTAG.ep1_conf.serial_out_ep_data_avail) break;
118+
if (!USB_SERIAL_JTAG.ep1_conf.serial_out_ep_data_avail) {
119+
break;
120+
}
119121
buf[i] = USB_SERIAL_JTAG.ep1.val;
120122
}
121123
return i;
@@ -134,7 +136,9 @@ static inline int usb_serial_jtag_ll_write_txfifo(const uint8_t *buf, uint32_t w
134136
{
135137
int i;
136138
for (i = 0; i < (int)wr_len; i++) {
137-
if (!USB_SERIAL_JTAG.ep1_conf.serial_in_ep_data_free) break;
139+
if (!USB_SERIAL_JTAG.ep1_conf.serial_in_ep_data_free) {
140+
break;
141+
}
138142
USB_SERIAL_JTAG.ep1.val = buf[i];
139143
}
140144
return i;
@@ -177,7 +181,7 @@ static inline int usb_serial_jtag_ll_txfifo_writable(void)
177181
*/
178182
static inline void usb_serial_jtag_ll_txfifo_flush(void)
179183
{
180-
USB_SERIAL_JTAG.ep1_conf.wr_done=1;
184+
USB_SERIAL_JTAG.ep1_conf.wr_done = 1;
181185
}
182186

183187
/**

components/hal/esp32h2/include/hal/usb_serial_jtag_ll.h renamed to components/esp_hal_usb/esp32h2/include/hal/usb_serial_jtag_ll.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ typedef enum {
3131
USB_SERIAL_JTAG_INTR_EP1_ZERO_PAYLOAD = (1 << 10),
3232
} usb_serial_jtag_ll_intr_t;
3333

34-
3534
#ifdef __cplusplus
3635
extern "C" {
3736
#endif
@@ -116,7 +115,9 @@ static inline int usb_serial_jtag_ll_read_rxfifo(uint8_t *buf, uint32_t rd_len)
116115
{
117116
int i;
118117
for (i = 0; i < (int)rd_len; i++) {
119-
if (!USB_SERIAL_JTAG.ep1_conf.serial_out_ep_data_avail) break;
118+
if (!USB_SERIAL_JTAG.ep1_conf.serial_out_ep_data_avail) {
119+
break;
120+
}
120121
buf[i] = USB_SERIAL_JTAG.ep1.rdwr_byte;
121122
}
122123
return i;
@@ -135,7 +136,9 @@ static inline int usb_serial_jtag_ll_write_txfifo(const uint8_t *buf, uint32_t w
135136
{
136137
int i;
137138
for (i = 0; i < (int)wr_len; i++) {
138-
if (!USB_SERIAL_JTAG.ep1_conf.serial_in_ep_data_free) break;
139+
if (!USB_SERIAL_JTAG.ep1_conf.serial_in_ep_data_free) {
140+
break;
141+
}
139142
USB_SERIAL_JTAG.ep1.rdwr_byte = buf[i];
140143
}
141144
return i;
@@ -178,7 +181,7 @@ static inline int usb_serial_jtag_ll_txfifo_writable(void)
178181
*/
179182
static inline void usb_serial_jtag_ll_txfifo_flush(void)
180183
{
181-
USB_SERIAL_JTAG.ep1_conf.wr_done=1;
184+
USB_SERIAL_JTAG.ep1_conf.wr_done = 1;
182185
}
183186

184187
/**

components/hal/esp32h21/include/hal/usb_serial_jtag_ll.h renamed to components/esp_hal_usb/esp32h21/include/hal/usb_serial_jtag_ll.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ typedef enum {
3131
USB_SERIAL_JTAG_INTR_EP1_ZERO_PAYLOAD = (1 << 10),
3232
} usb_serial_jtag_ll_intr_t;
3333

34-
3534
#ifdef __cplusplus
3635
extern "C" {
3736
#endif
@@ -116,7 +115,9 @@ static inline int usb_serial_jtag_ll_read_rxfifo(uint8_t *buf, uint32_t rd_len)
116115
{
117116
int i;
118117
for (i = 0; i < (int)rd_len; i++) {
119-
if (!USB_SERIAL_JTAG.serial_jtag_ep1_conf.serial_jtag_serial_out_ep_data_avail) break;
118+
if (!USB_SERIAL_JTAG.serial_jtag_ep1_conf.serial_jtag_serial_out_ep_data_avail) {
119+
break;
120+
}
120121
buf[i] = USB_SERIAL_JTAG.serial_jtag_ep1.val;
121122
}
122123
return i;
@@ -135,7 +136,9 @@ static inline int usb_serial_jtag_ll_write_txfifo(const uint8_t *buf, uint32_t w
135136
{
136137
int i;
137138
for (i = 0; i < (int)wr_len; i++) {
138-
if (!USB_SERIAL_JTAG.serial_jtag_ep1_conf.serial_jtag_serial_in_ep_data_free) break;
139+
if (!USB_SERIAL_JTAG.serial_jtag_ep1_conf.serial_jtag_serial_in_ep_data_free) {
140+
break;
141+
}
139142
USB_SERIAL_JTAG.serial_jtag_ep1.val = buf[i];
140143
}
141144
return i;
@@ -178,7 +181,7 @@ static inline int usb_serial_jtag_ll_txfifo_writable(void)
178181
*/
179182
static inline void usb_serial_jtag_ll_txfifo_flush(void)
180183
{
181-
USB_SERIAL_JTAG.serial_jtag_ep1_conf.serial_jtag_wr_done=1;
184+
USB_SERIAL_JTAG.serial_jtag_ep1_conf.serial_jtag_wr_done = 1;
182185
}
183186

184187
/**
@@ -328,8 +331,6 @@ FORCE_INLINE_ATTR bool usb_serial_jtag_ll_module_is_enabled(void)
328331
return (PCR.usb_device_conf.usb_device_clk_en && !PCR.usb_device_conf.usb_device_rst_en);
329332
}
330333

331-
332-
333334
#ifdef __cplusplus
334335
}
335336
#endif

0 commit comments

Comments
 (0)