1 /*
2  * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 
9 #include <stdbool.h>
10 #include "soc/soc_caps.h"
11 #if SOC_USB_OTG_SUPPORTED
12 #include "soc/usb_wrap_struct.h"
13 #include "hal/usb_wrap_ll.h"
14 #endif
15 #include "hal/usb_wrap_types.h"
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #if SOC_USB_OTG_SUPPORTED
22 
23 /**
24  * @brief HAL context type of USB WRAP driver
25  */
26 typedef struct {
27     usb_wrap_dev_t *dev;
28 } usb_wrap_hal_context_t;
29 
30 /**
31  * @brief Initialize the USB WRAP HAL driver
32  *
33  * @param hal USB WRAP HAL context
34  */
35 void usb_wrap_hal_init(usb_wrap_hal_context_t *hal);
36 
37 /* ---------------------------- USB PHY Control  ---------------------------- */
38 
39 #if USB_WRAP_LL_EXT_PHY_SUPPORTED
40 /**
41  * @brief Configure whether USB WRAP is routed to internal/external FSLS PHY
42  *
43  * @param hal USB WRAP HAL context
44  * @param external True if external, False if internal
45  */
46 void usb_wrap_hal_phy_set_external(usb_wrap_hal_context_t *hal, bool external);
47 #endif // USB_WRAP_LL_EXT_PHY_SUPPORTED
48 
49 /**
50  * @brief Enables and sets override of pull up/down resistors
51  *
52  * @param hal USB WRAP HAL context
53  * @param vals Override values
54  */
usb_wrap_hal_phy_enable_pull_override(usb_wrap_hal_context_t * hal,const usb_wrap_pull_override_vals_t * vals)55 static inline void usb_wrap_hal_phy_enable_pull_override(usb_wrap_hal_context_t *hal, const usb_wrap_pull_override_vals_t *vals)
56 {
57     usb_wrap_ll_phy_enable_pull_override(hal->dev, vals);
58 }
59 
60 /**
61  * @brief Disables pull up/down resistor override
62  *
63  * @param hal USB WRAP HAL context
64  */
usb_wrap_hal_phy_disable_pull_override(usb_wrap_hal_context_t * hal)65 static inline void usb_wrap_hal_phy_disable_pull_override(usb_wrap_hal_context_t *hal)
66 {
67     usb_wrap_ll_phy_disable_pull_override(hal->dev);
68 }
69 
70 /**
71  * @brief Enables/disables the USB FSLS PHY's test mode
72  *
73  * @param hal USB WRAP HAL context
74  * @param enable Whether to enable test mode
75  */
usb_wrap_hal_phy_enable_test_mode(usb_wrap_hal_context_t * hal,bool enable)76 static inline void usb_wrap_hal_phy_enable_test_mode(usb_wrap_hal_context_t *hal, bool enable)
77 {
78     usb_wrap_ll_phy_enable_test_mode(hal->dev, enable);
79 }
80 
81 /**
82  * @brief Set the USB FSLS PHY's signal test values
83  *
84  * @param hal USB WRAP HAL context
85  * @param vals Test values
86  */
usb_wrap_hal_phy_test_mode_set_signals(usb_wrap_hal_context_t * hal,const usb_wrap_test_mode_vals_t * vals)87 static inline void usb_wrap_hal_phy_test_mode_set_signals(usb_wrap_hal_context_t *hal, const usb_wrap_test_mode_vals_t *vals)
88 {
89     usb_wrap_ll_phy_test_mode_set_signals(hal->dev, vals);
90 }
91 
92 #endif // SOC_USB_OTG_SUPPORTED
93 
94 #ifdef __cplusplus
95 }
96 #endif
97