Skip to content

Commit e60ebae

Browse files
Merge branch 'refactor/usb_periph' into 'master'
Refactor: USB peripheral See merge request espressif/esp-idf!33971
2 parents dcc31f8 + c1f5d30 commit e60ebae

File tree

21 files changed

+2421
-152
lines changed

21 files changed

+2421
-152
lines changed

Diff for: components/hal/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ if(NOT BOOTLOADER_BUILD)
271271
list(APPEND srcs "usb_serial_jtag_hal.c")
272272
endif()
273273

274+
if(CONFIG_SOC_USB_UTMI_PHY_NUM GREATER 0)
275+
list(APPEND srcs "usb_utmi_hal.c")
276+
endif()
277+
274278
if(CONFIG_SOC_USB_OTG_SUPPORTED)
275279
list(APPEND srcs
276280
"usb_dwc_hal.c"

Diff for: components/hal/include/hal/usb_dwc_ll.h renamed to components/hal/esp32p4/include/hal/usb_dwc_ll.h

+15-20
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,22 @@
66

77
#pragma once
88

9-
#include "soc/soc_caps.h"
10-
/*
11-
This header is shared across all targets. Resolve to an empty header for targets
12-
that don't support USB OTG.
13-
*/
14-
#if SOC_USB_OTG_SUPPORTED
159
#include <stdint.h>
1610
#include <stdbool.h>
1711
#include "soc/usb_dwc_struct.h"
1812
#include "soc/usb_dwc_cfg.h"
1913
#include "hal/usb_dwc_types.h"
2014
#include "hal/misc.h"
21-
#endif // SOC_USB_OTG_SUPPORTED
2215

2316
#ifdef __cplusplus
2417
extern "C" {
2518
#endif
2619

27-
#if SOC_USB_OTG_SUPPORTED
20+
/* ----------------------------- Helper Macros ------------------------------ */
21+
22+
// Get USB hardware instance
23+
// TODO: extend this macros when we have support for both FS and HS hardware on P4
24+
#define USB_DWC_LL_GET_HW(num) (&USB_DWC_HS)
2825

2926
/* -----------------------------------------------------------------------------
3027
--------------------------------- DWC Constants --------------------------------
@@ -222,14 +219,14 @@ static inline void usb_dwc_ll_gusbcfg_set_timeout_cal(usb_dwc_dev_t *hw, uint8_t
222219
hw->gusbcfg_reg.toutcal = tout_cal;
223220
}
224221

225-
#if (OTG_HSPHY_INTERFACE != 0)
226222
static inline void usb_dwc_ll_gusbcfg_set_utmi_phy(usb_dwc_dev_t *hw)
227223
{
224+
#if (OTG_HSPHY_INTERFACE != 0)
228225
hw->gusbcfg_reg.phyif = 1; // 16 bits interface
229226
hw->gusbcfg_reg.ulpiutmisel = 0; // UTMI+
230227
hw->gusbcfg_reg.physel = 0; // HS PHY
231-
}
232228
#endif // (OTG_HSPHY_INTERFACE != 0)
229+
}
233230

234231
// --------------------------- GRSTCTL Register --------------------------------
235232

@@ -356,9 +353,9 @@ static inline uint32_t usb_dwc_ll_gsnpsid_get_id(usb_dwc_dev_t *hw)
356353
// --------------------------- GHWCFGx Register --------------------------------
357354

358355
/**
359-
* @brief Get the hardware configuration regiters of the DWC_OTG controller
356+
* @brief Get the hardware configuration registers of the DWC_OTG controller
360357
*
361-
* The hardware configuraiton regitsers are read only and indicate the various
358+
* The hardware configuration regitsers are read only and indicate the various
362359
* features of the DWC_OTG core.
363360
*
364361
* @param hw Start address of the DWC_OTG registers
@@ -405,7 +402,7 @@ static inline void usb_dwc_ll_hcfg_dis_perio_sched(usb_dwc_dev_t *hw)
405402
/**
406403
* Sets the length of the frame list
407404
*
408-
* @param num_entires Number of entires in the frame list
405+
* @param num_entires Number of entries in the frame list
409406
*/
410407
static inline void usb_dwc_ll_hcfg_set_num_frame_list_entries(usb_dwc_dev_t *hw, usb_hal_frame_list_len_t num_entries)
411408
{
@@ -903,7 +900,7 @@ static inline usb_dwc_host_chan_regs_t *usb_dwc_ll_chan_get_regs(usb_dwc_dev_t *
903900
// ------------------------------ QTD related ----------------------------------
904901

905902
#define USB_DWC_LL_QTD_STATUS_SUCCESS 0x0 //If QTD was processed, it indicates the data was transmitted/received successfully
906-
#define USB_DWC_LL_QTD_STATUS_PKTERR 0x1 //Data trasnmitted/received with errors (CRC/Timeout/Stuff/False EOP/Excessive NAK).
903+
#define USB_DWC_LL_QTD_STATUS_PKTERR 0x1 //Data transmitted/received with errors (CRC/Timeout/Stuff/False EOP/Excessive NAK).
907904
//Note: 0x2 is reserved
908905
#define USB_DWC_LL_QTD_STATUS_BUFFER 0x3 //AHB error occurred.
909906
#define USB_DWC_LL_QTD_STATUS_NOT_EXECUTED 0x4 //QTD as never processed
@@ -914,7 +911,7 @@ static inline usb_dwc_host_chan_regs_t *usb_dwc_ll_chan_get_regs(usb_dwc_dev_t *
914911
* @param qtd Pointer to the QTD
915912
* @param data_buff Pointer to buffer containing the data to transfer
916913
* @param xfer_len Number of bytes in transfer. Setting 0 will do a zero length IN transfer.
917-
* Non zero length must be mulitple of the endpoint's MPS.
914+
* Non zero length must be multiple of the endpoint's MPS.
918915
* @param hoc Halt on complete (will generate an interrupt and halt the channel)
919916
*/
920917
static inline void usb_dwc_ll_qtd_set_in(usb_dwc_ll_dma_qtd_t *qtd, uint8_t *data_buff, int xfer_len, bool hoc)
@@ -932,7 +929,7 @@ static inline void usb_dwc_ll_qtd_set_in(usb_dwc_ll_dma_qtd_t *qtd, uint8_t *dat
932929
/**
933930
* @brief Set a QTD for a non isochronous OUT transfer
934931
*
935-
* @param qtd Poitner to the QTD
932+
* @param qtd Pointer to the QTD
936933
* @param data_buff Pointer to buffer containing the data to transfer
937934
* @param xfer_len Number of bytes to transfer. Setting 0 will do a zero length transfer.
938935
* For ctrl setup packets, this should be set to 8.
@@ -972,9 +969,9 @@ static inline void usb_dwc_ll_qtd_set_null(usb_dwc_ll_dma_qtd_t *qtd)
972969
/**
973970
* @brief Get the status of a QTD
974971
*
975-
* When a channel get's halted, call this to check whether each QTD was executed successfully
972+
* When a channel gets halted, call this to check whether each QTD was executed successfully
976973
*
977-
* @param qtd Poitner to the QTD
974+
* @param qtd Pointer to the QTD
978975
* @param[out] rem_len Number of bytes ramining in the QTD
979976
* @param[out] status Status of the QTD
980977
*/
@@ -992,8 +989,6 @@ static inline void usb_dwc_ll_qtd_get_status(usb_dwc_ll_dma_qtd_t *qtd, int *rem
992989
qtd->buffer_status_val = 0;
993990
}
994991

995-
#endif // SOC_USB_OTG_SUPPORTED
996-
997992
#ifdef __cplusplus
998993
}
999994
#endif

Diff for: components/hal/esp32p4/include/hal/usb_utmi_ll.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ FORCE_INLINE_ATTR void _usb_utmi_ll_enable_bus_clock(bool clk_en)
5353
/**
5454
* @brief Reset the USB UTMI PHY and USB_DWC_HS controller
5555
*/
56-
FORCE_INLINE_ATTR void usb_utmi_ll_reset_register(void)
56+
FORCE_INLINE_ATTR void _usb_utmi_ll_reset_register(void)
5757
{
5858
// Reset the USB_UTMI and USB_DWC_HS
5959
LP_AON_CLKRST.hp_usb_clkrst_ctrl1.rst_en_usb_otg20 = 1;
@@ -63,7 +63,7 @@ FORCE_INLINE_ATTR void usb_utmi_ll_reset_register(void)
6363
}
6464

6565
// P_AON_CLKRST.hp_usb_clkrst_ctrlx is shared register, so this function must be used in an atomic way
66-
#define usb_utmi_ll_reset_register(...) (void)__DECLARE_RCC_ATOMIC_ENV; usb_utmi_ll_reset_register(__VA_ARGS__)
66+
#define usb_utmi_ll_reset_register(...) (void)__DECLARE_RCC_ATOMIC_ENV; _usb_utmi_ll_reset_register(__VA_ARGS__)
6767

6868
/**
6969
* @brief Enable precise detection of VBUS

0 commit comments

Comments
 (0)