2021-10-27 03:50:21 -04:00
|
|
|
/*
|
2021-11-17 13:07:53 -05:00
|
|
|
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
2021-10-27 03:50:21 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
2021-11-17 13:07:53 -05:00
|
|
|
#include "esp_err.h"
|
|
|
|
#include "hal/usb_phy_types.h"
|
|
|
|
#include "esp_private/usb_phy.h"
|
2021-10-27 03:50:21 -04:00
|
|
|
#include "test_usb_common.h"
|
|
|
|
|
2021-11-17 13:07:53 -05:00
|
|
|
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
|
2022-10-06 03:04:53 -04:00
|
|
|
.ext_io_conf = NULL,
|
|
|
|
.otg_io_conf = NULL,
|
2021-11-17 13:07:53 -05:00
|
|
|
};
|
|
|
|
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)
|
2021-10-27 03:50:21 -04:00
|
|
|
{
|
|
|
|
if (delay_ticks > 0) {
|
|
|
|
//Delay of 0 ticks causes a yield. So skip if delay_ticks is 0.
|
|
|
|
vTaskDelay(delay_ticks);
|
|
|
|
}
|
2021-11-17 13:07:53 -05:00
|
|
|
ESP_ERROR_CHECK(usb_phy_action(phy_hdl, (connected) ? USB_PHY_ACTION_HOST_ALLOW_CONN : USB_PHY_ACTION_HOST_FORCE_DISCONN));
|
2021-10-27 03:50:21 -04:00
|
|
|
}
|