mikroSDK Reference Manual
dwc2_esp32.h
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2021, Ha Thach (tinyusb.org)
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 * This file is part of the TinyUSB stack.
25 */
26
27
28#ifndef _DWC2_ESP32_H_
29#define _DWC2_ESP32_H_
30
31#ifdef __cplusplus
32 extern "C" {
33#endif
34
35#include "esp_intr_alloc.h"
36#include "soc/periph_defs.h"
37//#include "soc/usb_periph.h"
38
39#define DWC2_REG_BASE 0x60080000UL
40#define DWC2_EP_MAX 6 // USB_OUT_EP_NUM. TODO ESP32Sx only has 5 tx fifo (5 endpoint IN)
41
42static const dwc2_controller_t _dwc2_controller[] =
43{
44 { .reg_base = DWC2_REG_BASE, .irqnum = 0, .ep_count = DWC2_EP_MAX, .ep_fifo_size = 1024 }
45};
46
47static intr_handle_t usb_ih;
48
49static void dcd_int_handler_wrap(void* arg)
50{
51 (void) arg;
52 dcd_int_handler(0);
53}
54
55TU_ATTR_ALWAYS_INLINE
56static inline void dwc2_dcd_int_enable (uint8_t rhport)
57{
58 (void) rhport;
59 esp_intr_alloc(ETS_USB_INTR_SOURCE, ESP_INTR_FLAG_LOWMED, dcd_int_handler_wrap, NULL, &usb_ih);
60}
61
62TU_ATTR_ALWAYS_INLINE
63static inline void dwc2_dcd_int_disable (uint8_t rhport)
64{
65 (void) rhport;
66 esp_intr_free(usb_ih);
67}
68
69static inline void dwc2_remote_wakeup_delay(void)
70{
71 vTaskDelay(pdMS_TO_TICKS(1));
72}
73
74// MCU specific PHY init, called BEFORE core reset
75static inline void dwc2_phy_init(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
76{
77 (void) dwc2;
78 (void) hs_phy_type;
79
80 // nothing to do
81}
82
83// MCU specific PHY update, it is called AFTER init() and core reset
84static inline void dwc2_phy_update(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
85{
86 (void) dwc2;
87 (void) hs_phy_type;
88
89 // nothing to do
90}
91
92#ifdef __cplusplus
93}
94#endif
95
96#endif /* _DWC2_ESP32_H_ */
Definition dwc2_type.h:28
Definition dwc2_type.h:191