test_usb_common.c 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <stdbool.h>
  7. #include "freertos/FreeRTOS.h"
  8. #include "freertos/task.h"
  9. #include "soc/usb_wrap_struct.h"
  10. #include "test_usb_common.h"
  11. void test_usb_force_conn_state(bool connected, TickType_t delay_ticks)
  12. {
  13. if (delay_ticks > 0) {
  14. //Delay of 0 ticks causes a yield. So skip if delay_ticks is 0.
  15. vTaskDelay(delay_ticks);
  16. }
  17. usb_wrap_dev_t *wrap = &USB_WRAP;
  18. if (connected) {
  19. //Disable test mode to return to previous internal PHY configuration
  20. wrap->test_conf.test_enable = 0;
  21. } else {
  22. /*
  23. Mimic a disconnection by using the internal PHY's test mode.
  24. Force Output Enable to 1 (even if the controller isn't outputting). With test_tx_dp and test_tx_dm set to 0,
  25. this will look like a disconnection.
  26. */
  27. wrap->test_conf.val = 0;
  28. wrap->test_conf.test_usb_wrap_oe = 1;
  29. wrap->test_conf.test_enable = 1;
  30. }
  31. }