]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/USBHost/USBHost/USBHALHost.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / USBHost / USBHost / USBHALHost.h
1 /* mbed USBHost Library
2 * Copyright (c) 2006-2013 ARM Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef USBHALHOST_H
18 #define USBHALHOST_H
19
20 #include "USBHostTypes.h"
21 #include "USBHostConf.h"
22
23 class USBHostHub;
24
25 /**
26 * USBHALHost class
27 */
28 class USBHALHost {
29 protected:
30
31 /**
32 * Constructor
33 * init variables and memory where will be stored HCCA, ED and TD
34 */
35 USBHALHost();
36
37 /**
38 * Initialize host controller. Enable USB interrupts. This part is not in the constructor because,
39 * this function calls a virtual method if a device is already connected
40 */
41 void init();
42
43 /**
44 * reset the root hub
45 */
46 void resetRootHub();
47
48 /**
49 * return the value contained in the control HEAD ED register
50 *
51 * @returns address of the control Head ED
52 */
53 uint32_t controlHeadED();
54
55 /**
56 * return the value contained in the bulk HEAD ED register
57 *
58 * @returns address of the bulk head ED
59 */
60 uint32_t bulkHeadED();
61
62 /**
63 * return the value of the head interrupt ED contained in the HCCA
64 *
65 * @returns address of the head interrupt ED contained in the HCCA
66 */
67 uint32_t interruptHeadED();
68
69 /**
70 * Update the head ED for control transfers
71 */
72 void updateControlHeadED(uint32_t addr);
73
74 /**
75 * Update the head ED for bulk transfers
76 */
77 void updateBulkHeadED(uint32_t addr);
78
79 /**
80 * Update the head ED for interrupt transfers
81 */
82 void updateInterruptHeadED(uint32_t addr);
83
84 /**
85 * Enable List for the specified endpoint type
86 *
87 * @param type enable the list of ENDPOINT_TYPE type
88 */
89 void enableList(ENDPOINT_TYPE type);
90
91 /**
92 * Disable List for the specified endpoint type
93 *
94 * @param type disable the list of ENDPOINT_TYPE type
95 */
96 bool disableList(ENDPOINT_TYPE type);
97
98 /**
99 * Virtual method called when a device has been connected
100 *
101 * @param hub hub number of the device
102 * @param port port number of the device
103 * @param lowSpeed 1 if low speed, 0 otherwise
104 * @param hub_parent reference to the hub where the device is connected (NULL if the hub parent is the root hub)
105 */
106 virtual void deviceConnected(int hub, int port, bool lowSpeed, USBHostHub * hub_parent = NULL) = 0;
107
108 /**
109 * Virtual method called when a device has been disconnected
110 *
111 * @param hub hub number of the device
112 * @param port port number of the device
113 * @param hub_parent reference to the hub where the device is connected (NULL if the hub parent is the root hub)
114 * @param addr list of the TDs which have been completed to dequeue freed TDs
115 */
116 virtual void deviceDisconnected(int hub, int port, USBHostHub * hub_parent, volatile uint32_t addr) = 0;
117
118 /**
119 * Virtual method called when a transfer has been completed
120 *
121 * @param addr list of the TDs which have been completed
122 */
123 virtual void transferCompleted(volatile uint32_t addr) = 0;
124
125 /**
126 * Find a memory section for a new ED
127 *
128 * @returns the address of the new ED
129 */
130 volatile uint8_t * getED();
131
132 /**
133 * Find a memory section for a new TD
134 *
135 * @returns the address of the new TD
136 */
137 volatile uint8_t * getTD();
138
139 /**
140 * Release a previous memory section reserved for an ED
141 *
142 * @param ed address of the ED
143 */
144 void freeED(volatile uint8_t * ed);
145
146 /**
147 * Release a previous memory section reserved for an TD
148 *
149 * @param td address of the TD
150 */
151 void freeTD(volatile uint8_t * td);
152
153 private:
154 static void _usbisr(void);
155 void UsbIrqhandler();
156
157 void memInit();
158
159 HCCA volatile * usb_hcca; //256 bytes aligned
160 uint8_t volatile * usb_edBuf; //4 bytes aligned
161 uint8_t volatile * usb_tdBuf; //4 bytes aligned
162
163 static USBHALHost * instHost;
164
165 bool volatile edBufAlloc[MAX_ENDPOINT];
166 bool volatile tdBufAlloc[MAX_TD];
167 };
168
169 #endif
Imprint / Impressum