1 /*
2 * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include "hal/usb_phy_ll.h"
8 #include "hal/usb_phy_hal.h"
9
usb_phy_hal_init(usb_phy_hal_context_t * hal)10 void usb_phy_hal_init(usb_phy_hal_context_t *hal)
11 {
12 hal->wrap_dev = &USB_WRAP;
13 #if SOC_USB_SERIAL_JTAG_SUPPORTED
14 hal->jtag_dev = &USB_SERIAL_JTAG;
15 #endif
16 }
17
usb_phy_hal_otg_conf(usb_phy_hal_context_t * hal,usb_phy_target_t phy_target)18 void usb_phy_hal_otg_conf(usb_phy_hal_context_t *hal, usb_phy_target_t phy_target)
19 {
20 if (phy_target == USB_PHY_TARGET_EXT) {
21 usb_phy_ll_ext_otg_enable(hal->wrap_dev);
22 } else if (phy_target == USB_PHY_TARGET_INT) {
23 usb_phy_ll_int_otg_enable(hal->wrap_dev);
24 }
25 }
26
27 #if SOC_USB_SERIAL_JTAG_SUPPORTED
usb_phy_hal_jtag_conf(usb_phy_hal_context_t * hal,usb_phy_target_t phy_target)28 void usb_phy_hal_jtag_conf(usb_phy_hal_context_t *hal, usb_phy_target_t phy_target)
29 {
30 if (phy_target == USB_PHY_TARGET_EXT) {
31 usb_phy_ll_ext_jtag_enable(hal->jtag_dev);
32 } else if (phy_target == USB_PHY_TARGET_INT) {
33 usb_phy_ll_int_jtag_enable(hal->jtag_dev);
34 }
35 }
36 #endif
37
usb_phy_hal_int_load_conf_host(usb_phy_hal_context_t * hal)38 void usb_phy_hal_int_load_conf_host(usb_phy_hal_context_t *hal)
39 {
40 // HOST - upstream: dp_pd = 1, dm_pd = 1
41 usb_phy_ll_int_load_conf(hal->wrap_dev, false, true, false, true);
42 }
43
usb_phy_hal_int_load_conf_dev(usb_phy_hal_context_t * hal,usb_priv_speed_t speed)44 void usb_phy_hal_int_load_conf_dev(usb_phy_hal_context_t *hal, usb_priv_speed_t speed)
45 {
46 // DEVICE - downstream
47 if (speed == USB_PRIV_SPEED_LOW) {
48 // LS: dm_pu = 1
49 usb_phy_ll_int_load_conf(hal->wrap_dev, false, false, true, false);
50 } else {
51 // FS: dp_pu = 1
52 usb_phy_ll_int_load_conf(hal->wrap_dev, true, false, false, false);
53 }
54 }
55
usb_phy_hal_int_mimick_disconn(usb_phy_hal_context_t * hal,bool disconn)56 void usb_phy_hal_int_mimick_disconn(usb_phy_hal_context_t *hal, bool disconn)
57 {
58 /*
59 We mimick a disconnect by enabling the internal PHY's test mode, then forcing the output_enable to HIGH. This will:
60 A HIGH output_enable will cause the received VP and VM to be zero, thus mimicking a disconnection.
61 */
62 usb_phy_ll_int_enable_test_mode(hal->wrap_dev, disconn);
63 }
64