mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-10 04:43:33 +00:00
usb: USB Host stack uses USB PHY driver
This commit updates the USB Host stack to use the USB PHY driver. The USB PHY and the OTG Controller should now both be setup/deleted using usb_new_phy() and usb_del_phy() respectively. - The hcd_install() now expects the USB PHY and OTG Contorller to be already setup before it is called - usb_host_install() now has an option to skip calling usb_del_phy() if the user wants to setup their own USB PHY (e.g., in the case of using and external PHY). - CDC-ACM and MSC examples/test updated to use internal PHY Closes https://github.com/espressif/esp-idf/issues/8061
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -7,27 +7,38 @@
|
||||
#include <stdbool.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "soc/usb_wrap_struct.h"
|
||||
#include "esp_err.h"
|
||||
#include "hal/usb_phy_types.h"
|
||||
#include "esp_private/usb_phy.h"
|
||||
#include "test_usb_common.h"
|
||||
|
||||
void test_usb_force_conn_state(bool connected, TickType_t delay_ticks)
|
||||
static usb_phy_handle_t phy_hdl = NULL;
|
||||
|
||||
void test_usb_init_phy(void)
|
||||
{
|
||||
//Initialize the internal USB PHY to connect to the USB OTG peripheral
|
||||
usb_phy_config_t phy_config = {
|
||||
.controller = USB_PHY_CTRL_OTG,
|
||||
.target = USB_PHY_TARGET_INT,
|
||||
.otg_mode = USB_OTG_MODE_HOST,
|
||||
.otg_speed = USB_PHY_SPEED_UNDEFINED, //In Host mode, the speed is determined by the connected device
|
||||
.gpio_conf = NULL,
|
||||
};
|
||||
ESP_ERROR_CHECK(usb_new_phy(&phy_config, &phy_hdl));
|
||||
}
|
||||
|
||||
void test_usb_deinit_phy(void)
|
||||
{
|
||||
//Deinitialize the internal USB PHY
|
||||
ESP_ERROR_CHECK(usb_del_phy(phy_hdl));
|
||||
phy_hdl = NULL;
|
||||
}
|
||||
|
||||
void test_usb_set_phy_state(bool connected, TickType_t delay_ticks)
|
||||
{
|
||||
if (delay_ticks > 0) {
|
||||
//Delay of 0 ticks causes a yield. So skip if delay_ticks is 0.
|
||||
vTaskDelay(delay_ticks);
|
||||
}
|
||||
usb_wrap_dev_t *wrap = &USB_WRAP;
|
||||
if (connected) {
|
||||
//Disable test mode to return to previous internal PHY configuration
|
||||
wrap->test_conf.test_enable = 0;
|
||||
} else {
|
||||
/*
|
||||
Mimic a disconnection by using the internal PHY's test mode.
|
||||
Force Output Enable to 1 (even if the controller isn't outputting). With test_tx_dp and test_tx_dm set to 0,
|
||||
this will look like a disconnection.
|
||||
*/
|
||||
wrap->test_conf.val = 0;
|
||||
wrap->test_conf.test_usb_wrap_oe = 1;
|
||||
wrap->test_conf.test_enable = 1;
|
||||
}
|
||||
ESP_ERROR_CHECK(usb_phy_action(phy_hdl, (connected) ? USB_PHY_ACTION_HOST_ALLOW_CONN : USB_PHY_ACTION_HOST_FORCE_DISCONN));
|
||||
}
|
||||
|
Reference in New Issue
Block a user