-
-
Notifications
You must be signed in to change notification settings - Fork 212
/
Copy pathUSBHost.cpp
63 lines (48 loc) · 1.16 KB
/
USBHost.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "USBHost.h"
#include "USB251xB.h"
static rtos::Thread t(osPriorityHigh);
void USBHost::supplyPowerOnVBUS(bool enable){
mbed::DigitalOut otg(PJ_6, enable ? 0 : 1);
}
void USBHost::InternalTask() {
while (1) {
tusbh_msg_loop(mq);
}
}
uint32_t USBHost::Init(uint8_t id, const tusbh_class_reg_t class_table[]) {
mq = tusbh_mq_create();
tusbh_mq_init(mq);
if (id == USB_CORE_ID_FS) {
_fs = tusb_get_host(USB_CORE_ID_FS);
HOST_PORT_POWER_ON_FS();
root_fs.mq = mq;
root_fs.id = "FS";
root_fs.support_classes = class_table;
tusb_host_init(_fs, &root_fs);
tusb_open_host(_fs);
start_hub();
}
if (id == USB_CORE_ID_HS) {
#ifndef CORE_CM4
get_usb_phy()->deinit();
#endif
mbed::DigitalOut otg(PJ_6, 1);
_hs = tusb_get_host(USB_CORE_ID_HS);
HOST_PORT_POWER_ON_HS();
root_hs.mq = mq;
root_hs.id = "HS";
root_hs.support_classes = class_table;
tusb_host_init(_hs, &root_hs);
tusb_open_host(_hs);
}
t.start(mbed::callback(this, &USBHost::InternalTask));
}
uint32_t USBHost::Task() {
}
extern "C" {
// host need accurate delay
void tusb_delay_ms(uint32_t ms)
{
delay(ms);
}
}