1 /*
2  * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 
9 #include "usb_types_private.h"
10 #include "usb_phy_types.h"
11 #include "soc/soc_caps.h"
12 #include "soc/usb_wrap_struct.h"
13 #if SOC_USB_SERIAL_JTAG_SUPPORTED
14 #include "soc/usb_serial_jtag_struct.h"
15 #endif
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 /**
22  * Context that should be maintained by both the driver and the HAL
23  */
24 typedef struct {
25     usb_wrap_dev_t *wrap_dev;                   /**< Pointer to base address of USB Wrapper registers */
26 #if SOC_USB_SERIAL_JTAG_SUPPORTED
27     usb_serial_jtag_dev_t *jtag_dev;            /**< Pointer to base address of USB Serial JTAG registers */
28 #endif
29 } usb_phy_hal_context_t;
30 
31 /**
32  * @brief Init the USB PHY hal. This function should be called first before other hal layer function is called
33  *
34  * @param hal Context of the HAL layer
35  */
36 void usb_phy_hal_init(usb_phy_hal_context_t *hal);
37 
38 /**
39  * @brief Configure internal/external PHY for USB_OTG
40  *
41  * @param hal Context of the HAL layer
42  * @param phy_target USB PHY target
43  */
44 void usb_phy_hal_otg_conf(usb_phy_hal_context_t *hal, usb_phy_target_t phy_target);
45 
46 #if SOC_USB_SERIAL_JTAG_SUPPORTED
47 /**
48  * @brief Configure internal/external PHY for USB_Serial_JTAG
49  *
50  * @param hal Context of the HAL layer
51  * @param phy_target USB PHY target
52  */
53 void usb_phy_hal_jtag_conf(usb_phy_hal_context_t *hal, usb_phy_target_t phy_target);
54 #endif
55 
56 /**
57  * @brief Configure pullup/pulldown loads for the D+/D- as a host
58  *
59  * @param hal Context of the HAL layer
60  */
61 void usb_phy_hal_int_load_conf_host(usb_phy_hal_context_t *hal);
62 
63 /**
64  * @brief Configure pullup/pulldown loads for the D+/D- as a device
65  *
66  * @param hal Context of the HAL layer
67  * @param speed USB speed
68  */
69 void usb_phy_hal_int_load_conf_dev(usb_phy_hal_context_t *hal, usb_priv_speed_t speed);
70 
71 /**
72  * @brief Enable/Disable test mode for internal PHY to mimick host-device disconnection
73  *
74  * @param hal Context of the HAL layer
75  * @param disconn Whether to disconnect
76  */
77 void usb_phy_hal_int_mimick_disconn(usb_phy_hal_context_t *hal, bool disconn);
78 
79 #ifdef __cplusplus
80 }
81 #endif
82