]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/USBHost/USBHost/USBEndpoint.h
1 /* mbed USBHost Library
2 * Copyright (c) 2006-2013 ARM Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include "FunctionPointer.h"
21 #include "USBHostTypes.h"
24 class USBDeviceConnected
;
36 state
= USB_TYPE_FREE
;
41 * Initialize an endpoint
43 * @param hced hced associated to the endpoint
44 * @param type endpoint type
45 * @param dir endpoint direction
46 * @param size endpoint size
47 * @param ep_number endpoint number
48 * @param td_list array of two allocated transfer descriptors
50 void init(HCED
* hced
, ENDPOINT_TYPE type
, ENDPOINT_DIRECTION dir
, uint32_t size
, uint8_t ep_number
, HCTD
* td_list
[2]);
53 * Set next token. Warning: only useful for the control endpoint
55 * @param token IN, OUT or SETUP token
57 void setNextToken(uint32_t token
);
62 * @param endpoint endpoint which will be queued in the linked list
64 void queueEndpoint(USBEndpoint
* endpoint
);
68 * Queue a transfer on the endpoint
73 * Unqueue a transfer from the endpoint
75 * @param td hctd which will be unqueued
77 void unqueueTransfer(volatile HCTD
* td
);
80 * Attach a member function to call when a transfer is finished
82 * @param tptr pointer to the object to call the member function on
83 * @param mptr pointer to the member function to be called
86 inline void attach(T
* tptr
, void (T::*mptr
)(void)) {
87 if((mptr
!= NULL
) && (tptr
!= NULL
)) {
88 rx
.attach(tptr
, mptr
);
93 * Attach a callback called when a transfer is finished
95 * @param fptr function pointer
97 inline void attach(void (*fptr
)(void)) {
104 * Call the handler associted to the end of a transfer
112 inline void setState(USB_TYPE st
) { state
= st
; }
113 void setState(uint8_t st
);
114 void setDeviceAddress(uint8_t addr
);
115 inline void setLengthTransferred(int len
) { transferred
= len
; };
116 void setSpeed(uint8_t speed
);
117 void setSize(uint32_t size
);
118 inline void setDir(ENDPOINT_DIRECTION d
) { dir
= d
; }
119 inline void setIntfNb(uint8_t intf_nb_
) { intf_nb
= intf_nb_
; };
122 const char * getStateString();
123 inline USB_TYPE
getState() { return state
; }
124 inline ENDPOINT_TYPE
getType() { return type
; };
125 inline uint8_t getDeviceAddress() { return hced
->control
& 0x7f; };
126 inline int getLengthTransferred() { return transferred
; }
127 inline uint8_t * getBufStart() { return buf_start
; }
128 inline uint8_t getAddress(){ return address
; };
129 inline uint32_t getSize() { return (hced
->control
>> 16) & 0x3ff; };
130 inline volatile HCTD
* getHeadTD() { return (volatile HCTD
*) ((uint32_t)hced
->headTD
& ~0xF); };
131 inline volatile HCTD
** getTDList() { return td_list
; };
132 inline volatile HCED
* getHCED() { return hced
; };
133 inline ENDPOINT_DIRECTION
getDir() { return dir
; }
134 inline volatile HCTD
* getProcessedTD() { return td_current
; };
135 inline volatile HCTD
* getNextTD() { return td_current
; };
136 inline bool isSetup() { return setup
; }
137 inline USBEndpoint
* nextEndpoint() { return (USBEndpoint
*)nextEp
; };
138 inline uint8_t getIntfNb() { return intf_nb
; };
140 USBDeviceConnected
* dev
;
142 Queue
<uint8_t, 1> ep_queue
;
146 volatile USB_TYPE state
;
147 ENDPOINT_DIRECTION dir
;
160 // USBEndpoint descriptor
161 volatile HCED
* hced
;
163 volatile HCTD
* td_list
[2];
164 volatile HCTD
* td_current
;
165 volatile HCTD
* td_next
;