mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-22 17:10:28 +00:00
Merge branch 'feature/usb_new_phy_driver_collective_backport_v5.1' into 'release/v5.1'
refactor(usb/host): PHY driver preqrequisite refacotring collective backport (v5.1) See merge request espressif/esp-idf!29791
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "soc/usb_serial_jtag_struct.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Configures the internal PHY for USB_Serial_JTAG
|
||||
*
|
||||
* @param hw Start address of the USB Serial_JTAG registers
|
||||
*/
|
||||
static inline void usb_fsls_phy_ll_int_jtag_enable(usb_serial_jtag_dev_t *hw)
|
||||
{
|
||||
// USB_Serial_JTAG use internal PHY
|
||||
hw->conf0.phy_sel = 0;
|
||||
// Disable software control USB D+ D- pullup pulldown (Device FS: dp_pullup = 1)
|
||||
hw->conf0.pad_pull_override = 0;
|
||||
// Enable USB D+ pullup
|
||||
hw->conf0.dp_pullup = 1;
|
||||
// Enable USB pad function
|
||||
hw->conf0.usb_pad_enable = 1;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -4,23 +4,18 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
// The LL layer of the USB-serial-jtag controller
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "esp_attr.h"
|
||||
#include "soc/pcr_struct.h"
|
||||
#include "soc/usb_serial_jtag_reg.h"
|
||||
#include "soc/usb_serial_jtag_struct.h"
|
||||
#include "hal/usb_serial_jtag_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* ----------------------------- Macros & Types ----------------------------- */
|
||||
|
||||
//The in and out endpoints are this long.
|
||||
#define USB_SERIAL_JTAG_PACKET_SZ_BYTES 64
|
||||
|
||||
#define USB_SERIAL_JTAG_LL_INTR_MASK (0x7ffff) //All interrupt mask
|
||||
#define USB_SERIAL_JTAG_LL_INTR_MASK (0x7ffff) // All interrupts mask
|
||||
|
||||
// Define USB_SERIAL_JTAG interrupts
|
||||
// Note the hardware has more interrupts, but they're only useful for debugging
|
||||
@@ -34,6 +29,13 @@ typedef enum {
|
||||
USB_SERIAL_JTAG_INTR_EP1_ZERO_PAYLOAD = (1 << 10),
|
||||
} usb_serial_jtag_ll_intr_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* ----------------------------- USJ Peripheral ----------------------------- */
|
||||
|
||||
/**
|
||||
* @brief Enable the USB_SERIAL_JTAG interrupt based on the given mask.
|
||||
*
|
||||
@@ -123,7 +125,7 @@ static inline int usb_serial_jtag_ll_read_rxfifo(uint8_t *buf, uint32_t rd_len)
|
||||
* is room in the buffer.
|
||||
*
|
||||
* @param buf The data buffer.
|
||||
* @param wr_len The data length needs to be writen.
|
||||
* @param wr_len The data length needs to be written.
|
||||
*
|
||||
* @return Amount of bytes actually written. May be less than wr_len.
|
||||
*/
|
||||
@@ -177,35 +179,130 @@ static inline void usb_serial_jtag_ll_txfifo_flush(void)
|
||||
USB_SERIAL_JTAG.ep1_conf.wr_done=1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable USJ JTAG bridge
|
||||
*
|
||||
* If enabled, USJ is disconnected from internal JTAG interface. JTAG interface
|
||||
* is routed through GPIO matrix instead.
|
||||
*
|
||||
* @param enable Enable USJ JTAG bridge
|
||||
*/
|
||||
FORCE_INLINE_ATTR void usb_serial_jtag_ll_phy_set_jtag_bridge(bool enable)
|
||||
{
|
||||
USB_SERIAL_JTAG.conf0.usb_jtag_bridge_en = enable;
|
||||
}
|
||||
|
||||
/* ---------------------------- USB PHY Control ---------------------------- */
|
||||
|
||||
/**
|
||||
* @brief Disable usb serial jtag pad during light sleep to avoid current leakage
|
||||
* @brief Sets PHY defaults
|
||||
*
|
||||
* @return Initial configuration of usb serial jtag pad enable before light sleep
|
||||
* Some PHY register fields/features of the USJ are redundant on the ESP32-C6.
|
||||
* This function those fields are set to the appropriate default values.
|
||||
*
|
||||
* @param hw Start address of the USB Wrap registers
|
||||
*/
|
||||
FORCE_INLINE_ATTR bool usb_serial_jtag_ll_pad_backup_and_disable(void)
|
||||
FORCE_INLINE_ATTR void usb_serial_jtag_ll_phy_set_defaults(void)
|
||||
{
|
||||
bool pad_enabled = USB_SERIAL_JTAG.conf0.usb_pad_enable;
|
||||
|
||||
// Disable USB pad function
|
||||
USB_SERIAL_JTAG.conf0.usb_pad_enable = 0;
|
||||
|
||||
return pad_enabled;
|
||||
// External FSLS PHY is not supported
|
||||
USB_SERIAL_JTAG.conf0.phy_sel = 0;
|
||||
USB_SERIAL_JTAG.conf0.usb_pad_enable = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the internal USJ PHY control to D+/D- pad
|
||||
* @brief Enables/disables exchanging of the D+/D- pins USB PHY
|
||||
*
|
||||
* @param enable_pad Enable the USJ PHY control to D+/D- pad
|
||||
* @param enable Enables pin exchange, disabled otherwise
|
||||
*/
|
||||
FORCE_INLINE_ATTR void usb_serial_jtag_ll_enable_pad(bool enable_pad)
|
||||
FORCE_INLINE_ATTR void usb_serial_jtag_ll_phy_enable_pin_exchg(bool enable)
|
||||
{
|
||||
USB_SERIAL_JTAG.conf0.usb_pad_enable = enable_pad;
|
||||
if (enable) {
|
||||
USB_SERIAL_JTAG.conf0.exchg_pins = 1;
|
||||
USB_SERIAL_JTAG.conf0.exchg_pins_override = 1;
|
||||
} else {
|
||||
USB_SERIAL_JTAG.conf0.exchg_pins_override = 0;
|
||||
USB_SERIAL_JTAG.conf0.exchg_pins = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the bus clock for USB Serial_JTAG module
|
||||
* @param clk_en True if enable the clock of USB Serial_JTAG module
|
||||
* @brief Enables and sets voltage threshold overrides for USB FSLS PHY single-ended inputs
|
||||
*
|
||||
* @param vrefh_step High voltage threshold. 0 to 3 indicating 80mV steps from 1.76V to 2V.
|
||||
* @param vrefl_step Low voltage threshold. 0 to 3 indicating 80mV steps from 0.8V to 1.04V.
|
||||
*/
|
||||
FORCE_INLINE_ATTR void usb_serial_jtag_ll_phy_enable_vref_override(unsigned int vrefh_step, unsigned int vrefl_step)
|
||||
{
|
||||
USB_SERIAL_JTAG.conf0.vrefh = vrefh_step;
|
||||
USB_SERIAL_JTAG.conf0.vrefl = vrefl_step;
|
||||
USB_SERIAL_JTAG.conf0.vref_override = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables voltage threshold overrides for USB FSLS PHY single-ended inputs
|
||||
*/
|
||||
FORCE_INLINE_ATTR void usb_serial_jtag_ll_phy_disable_vref_override(void)
|
||||
{
|
||||
USB_SERIAL_JTAG.conf0.vref_override = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable override of USB FSLS PHY's pull up/down resistors
|
||||
*
|
||||
* @param vals Override values to set
|
||||
*/
|
||||
FORCE_INLINE_ATTR void usb_serial_jtag_ll_phy_enable_pull_override(const usb_serial_jtag_pull_override_vals_t *vals)
|
||||
{
|
||||
USB_SERIAL_JTAG.conf0.dp_pullup = vals->dp_pu;
|
||||
USB_SERIAL_JTAG.conf0.dp_pulldown = vals->dp_pd;
|
||||
USB_SERIAL_JTAG.conf0.dm_pullup = vals->dm_pu;
|
||||
USB_SERIAL_JTAG.conf0.dm_pulldown = vals->dm_pd;
|
||||
USB_SERIAL_JTAG.conf0.pad_pull_override = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable override of USB FSLS PHY pull up/down resistors
|
||||
*/
|
||||
FORCE_INLINE_ATTR void usb_serial_jtag_ll_phy_disable_pull_override(void)
|
||||
{
|
||||
USB_SERIAL_JTAG.conf0.pad_pull_override = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the strength of the pullup resistor
|
||||
*
|
||||
* @param strong True is a ~1.4K pullup, false is a ~2.4K pullup
|
||||
*/
|
||||
FORCE_INLINE_ATTR void usb_serial_jtag_ll_phy_set_pullup_strength(bool strong)
|
||||
{
|
||||
USB_SERIAL_JTAG.conf0.pullup_value = strong;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if USB FSLS PHY pads are enabled
|
||||
*
|
||||
* @return True if enabled, false otherwise
|
||||
*/
|
||||
FORCE_INLINE_ATTR bool usb_serial_jtag_ll_phy_is_pad_enabled(void)
|
||||
{
|
||||
return USB_SERIAL_JTAG.conf0.usb_pad_enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the USB FSLS PHY pads
|
||||
*
|
||||
* @param enable Whether to enable the USB FSLS PHY pads
|
||||
*/
|
||||
FORCE_INLINE_ATTR void usb_serial_jtag_ll_phy_enable_pad(bool enable)
|
||||
{
|
||||
USB_SERIAL_JTAG.conf0.usb_pad_enable = enable;
|
||||
}
|
||||
|
||||
/* ----------------------------- RCC Functions ----------------------------- */
|
||||
|
||||
/**
|
||||
* @brief Enable the bus clock for USJ module
|
||||
* @param clk_en True if enable the clock of USJ module
|
||||
*/
|
||||
FORCE_INLINE_ATTR void usb_serial_jtag_ll_enable_bus_clock(bool clk_en)
|
||||
{
|
||||
@@ -213,7 +310,7 @@ FORCE_INLINE_ATTR void usb_serial_jtag_ll_enable_bus_clock(bool clk_en)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset the usb serial jtag module
|
||||
* @brief Reset the USJ module
|
||||
*/
|
||||
FORCE_INLINE_ATTR void usb_serial_jtag_ll_reset_register(void)
|
||||
{
|
||||
@@ -222,9 +319,9 @@ FORCE_INLINE_ATTR void usb_serial_jtag_ll_reset_register(void)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the enable status USB Serial_JTAG module
|
||||
* Get the enable status of the USJ module
|
||||
*
|
||||
* @return Return true if USB Serial_JTAG module is enabled
|
||||
* @return Return true if USJ module is enabled
|
||||
*/
|
||||
FORCE_INLINE_ATTR bool usb_serial_jtag_ll_module_is_enabled(void)
|
||||
{
|
||||
|
Reference in New Issue
Block a user