mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-09 20:41:14 +00:00
fix(esp_hw_support): fix lightsleep current leakage on usb-phy controlled pad
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -7,8 +7,11 @@
|
||||
// The LL layer of the USB-serial-jtag controller
|
||||
|
||||
#pragma once
|
||||
#include <stdbool.h>
|
||||
#include "esp_attr.h"
|
||||
#include "soc/usb_serial_jtag_reg.h"
|
||||
#include "soc/usb_serial_jtag_struct.h"
|
||||
#include "soc/system_struct.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -168,6 +171,65 @@ static inline void usb_serial_jtag_ll_txfifo_flush(void)
|
||||
USB_SERIAL_JTAG.ep1_conf.wr_done=1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable usb serial jtag pad during light sleep to avoid current leakage
|
||||
*
|
||||
* @return Initial configuration of usb serial jtag pad enable before light sleep
|
||||
*/
|
||||
FORCE_INLINE_ATTR bool usb_serial_jtag_ll_pad_backup_and_disable(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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the internal USJ PHY control to D+/D- pad
|
||||
*
|
||||
* @param enable_pad Enable the USJ PHY control to D+/D- pad
|
||||
*/
|
||||
FORCE_INLINE_ATTR void usb_serial_jtag_ll_enable_pad(bool enable_pad)
|
||||
{
|
||||
USB_SERIAL_JTAG.conf0.usb_pad_enable = enable_pad;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the bus clock for USB Serial_JTAG module
|
||||
* @param clk_en True if enable the clock of USB Serial_JTAG module
|
||||
*/
|
||||
FORCE_INLINE_ATTR void usb_serial_jtag_ll_enable_bus_clock(bool clk_en)
|
||||
{
|
||||
SYSTEM.perip_clk_en0.reg_usb_device_clk_en = clk_en;
|
||||
}
|
||||
|
||||
// SYSTEM.perip_clk_enx are shared registers, so this function must be used in an atomic way
|
||||
#define usb_serial_jtag_ll_enable_bus_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; usb_serial_jtag_ll_enable_bus_clock(__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Reset the usb serial jtag module
|
||||
*/
|
||||
FORCE_INLINE_ATTR void usb_serial_jtag_ll_reset_register(void)
|
||||
{
|
||||
SYSTEM.perip_rst_en0.reg_usb_device_rst = 1;
|
||||
SYSTEM.perip_rst_en0.reg_usb_device_rst = 0;
|
||||
}
|
||||
|
||||
// SYSTEM.perip_clk_enx are shared registers, so this function must be used in an atomic way
|
||||
#define usb_serial_jtag_ll_reset_register(...) (void)__DECLARE_RCC_ATOMIC_ENV; usb_serial_jtag_ll_reset_register(__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* Get the enable status USB Serial_JTAG module
|
||||
*
|
||||
* @return Return true if USB Serial_JTAG module is enabled
|
||||
*/
|
||||
FORCE_INLINE_ATTR bool usb_serial_jtag_ll_module_is_enabled(void)
|
||||
{
|
||||
return (SYSTEM.perip_clk_en0.reg_usb_device_clk_en && !SYSTEM.perip_rst_en0.reg_usb_device_rst);
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Reference in New Issue
Block a user