usb_phy_hal.c 1.9 KB

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