2018.07.26
Dependencies: FATFileSystem3 mbed-rtos
Fork of USBHost by
USBHost/USBEndpoint.h@8:93da8ea2708b, 2013-03-14 (annotated)
- Committer:
- samux
- Date:
- Thu Mar 14 11:49:53 2013 +0000
- Revision:
- 8:93da8ea2708b
- Parent:
- 4:b320d68e98e7
- Child:
- 9:7671b6a8c363
update doc + license
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 8:93da8ea2708b | 1 | /* mbed USBHost Library |
samux | 8:93da8ea2708b | 2 | * Copyright (c) 2006-2013 ARM Limited |
samux | 8:93da8ea2708b | 3 | * |
samux | 8:93da8ea2708b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
samux | 8:93da8ea2708b | 5 | * you may not use this file except in compliance with the License. |
samux | 8:93da8ea2708b | 6 | * You may obtain a copy of the License at |
samux | 8:93da8ea2708b | 7 | * |
samux | 8:93da8ea2708b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
samux | 8:93da8ea2708b | 9 | * |
samux | 8:93da8ea2708b | 10 | * Unless required by applicable law or agreed to in writing, software |
samux | 8:93da8ea2708b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
samux | 8:93da8ea2708b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
samux | 8:93da8ea2708b | 13 | * See the License for the specific language governing permissions and |
samux | 8:93da8ea2708b | 14 | * limitations under the License. |
samux | 8:93da8ea2708b | 15 | */ |
mbed_official | 0:a554658735bf | 16 | |
mbed_official | 0:a554658735bf | 17 | #ifndef USBENDPOINT_H |
mbed_official | 0:a554658735bf | 18 | #define USBENDPOINT_H |
mbed_official | 0:a554658735bf | 19 | |
mbed_official | 0:a554658735bf | 20 | #include "FunctionPointer.h" |
mbed_official | 0:a554658735bf | 21 | #include "USBHostTypes.h" |
mbed_official | 0:a554658735bf | 22 | |
mbed_official | 0:a554658735bf | 23 | class USBDeviceConnected; |
mbed_official | 0:a554658735bf | 24 | |
samux | 8:93da8ea2708b | 25 | /** |
samux | 8:93da8ea2708b | 26 | * USBEndpoint class |
samux | 8:93da8ea2708b | 27 | */ |
mbed_official | 0:a554658735bf | 28 | class USBEndpoint |
mbed_official | 0:a554658735bf | 29 | { |
mbed_official | 0:a554658735bf | 30 | public: |
mbed_official | 0:a554658735bf | 31 | /** |
mbed_official | 0:a554658735bf | 32 | * Constructor |
mbed_official | 0:a554658735bf | 33 | */ |
mbed_official | 0:a554658735bf | 34 | USBEndpoint() { |
mbed_official | 0:a554658735bf | 35 | state = USB_TYPE_FREE; |
mbed_official | 0:a554658735bf | 36 | nextEp = NULL; |
mbed_official | 0:a554658735bf | 37 | }; |
mbed_official | 0:a554658735bf | 38 | |
mbed_official | 0:a554658735bf | 39 | /** |
mbed_official | 0:a554658735bf | 40 | * Initialize an endpoint |
mbed_official | 0:a554658735bf | 41 | * |
mbed_official | 0:a554658735bf | 42 | * @param hced hced associated to the endpoint |
mbed_official | 0:a554658735bf | 43 | * @param type endpoint type |
mbed_official | 0:a554658735bf | 44 | * @param dir endpoint direction |
mbed_official | 0:a554658735bf | 45 | * @param size endpoint size |
mbed_official | 0:a554658735bf | 46 | * @param ep_number endpoint number |
mbed_official | 0:a554658735bf | 47 | * @param td_list array of two allocated transfer descriptors |
mbed_official | 0:a554658735bf | 48 | */ |
mbed_official | 0:a554658735bf | 49 | void init(HCED * hced, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t ep_number, HCTD* td_list[2]); |
mbed_official | 0:a554658735bf | 50 | |
mbed_official | 0:a554658735bf | 51 | /** |
samux | 8:93da8ea2708b | 52 | * Set next token. Warning: only useful for the control endpoint |
mbed_official | 0:a554658735bf | 53 | * |
mbed_official | 0:a554658735bf | 54 | * @param token IN, OUT or SETUP token |
mbed_official | 0:a554658735bf | 55 | */ |
mbed_official | 0:a554658735bf | 56 | void setNextToken(uint32_t token); |
mbed_official | 0:a554658735bf | 57 | |
mbed_official | 0:a554658735bf | 58 | /** |
mbed_official | 0:a554658735bf | 59 | * Queue an endpoint |
mbed_official | 0:a554658735bf | 60 | * |
samux | 8:93da8ea2708b | 61 | * @param endpoint endpoint which will be queued in the linked list |
mbed_official | 0:a554658735bf | 62 | */ |
mbed_official | 0:a554658735bf | 63 | void queueEndpoint(USBEndpoint * endpoint); |
mbed_official | 0:a554658735bf | 64 | |
mbed_official | 0:a554658735bf | 65 | |
mbed_official | 0:a554658735bf | 66 | /** |
mbed_official | 0:a554658735bf | 67 | * Queue a transfer on the endpoint |
mbed_official | 0:a554658735bf | 68 | */ |
mbed_official | 0:a554658735bf | 69 | void queueTransfer(); |
mbed_official | 0:a554658735bf | 70 | |
mbed_official | 0:a554658735bf | 71 | /** |
mbed_official | 0:a554658735bf | 72 | * Unqueue a transfer from the endpoint |
mbed_official | 0:a554658735bf | 73 | * |
mbed_official | 0:a554658735bf | 74 | * @param td hctd which will be unqueued |
mbed_official | 0:a554658735bf | 75 | */ |
mbed_official | 0:a554658735bf | 76 | void unqueueTransfer(volatile HCTD * td); |
mbed_official | 0:a554658735bf | 77 | |
mbed_official | 0:a554658735bf | 78 | /** |
mbed_official | 0:a554658735bf | 79 | * Attach a member function to call when a transfer is finished |
mbed_official | 0:a554658735bf | 80 | * |
mbed_official | 0:a554658735bf | 81 | * @param tptr pointer to the object to call the member function on |
mbed_official | 0:a554658735bf | 82 | * @param mptr pointer to the member function to be called |
mbed_official | 0:a554658735bf | 83 | */ |
mbed_official | 0:a554658735bf | 84 | template<typename T> |
mbed_official | 0:a554658735bf | 85 | inline void attach(T* tptr, void (T::*mptr)(void)) { |
mbed_official | 0:a554658735bf | 86 | if((mptr != NULL) && (tptr != NULL)) { |
mbed_official | 0:a554658735bf | 87 | rx.attach(tptr, mptr); |
mbed_official | 0:a554658735bf | 88 | } |
mbed_official | 0:a554658735bf | 89 | } |
mbed_official | 0:a554658735bf | 90 | |
mbed_official | 0:a554658735bf | 91 | /** |
mbed_official | 0:a554658735bf | 92 | * Attach a callback called when a transfer is finished |
mbed_official | 0:a554658735bf | 93 | * |
mbed_official | 0:a554658735bf | 94 | * @param fptr function pointer |
mbed_official | 0:a554658735bf | 95 | */ |
samux | 8:93da8ea2708b | 96 | inline void attach(void (*fptr)(void)) { |
samux | 8:93da8ea2708b | 97 | if(fptr != NULL) { |
samux | 8:93da8ea2708b | 98 | rx.attach(fptr); |
mbed_official | 0:a554658735bf | 99 | } |
mbed_official | 0:a554658735bf | 100 | } |
mbed_official | 0:a554658735bf | 101 | |
mbed_official | 0:a554658735bf | 102 | /** |
mbed_official | 0:a554658735bf | 103 | * Call the handler associted to the end of a transfer |
mbed_official | 0:a554658735bf | 104 | */ |
mbed_official | 0:a554658735bf | 105 | inline void call() { |
mbed_official | 0:a554658735bf | 106 | rx.call(); |
mbed_official | 0:a554658735bf | 107 | }; |
mbed_official | 0:a554658735bf | 108 | |
mbed_official | 0:a554658735bf | 109 | |
mbed_official | 0:a554658735bf | 110 | // setters |
mbed_official | 0:a554658735bf | 111 | inline void setState(USB_TYPE st) { state = st; } |
mbed_official | 0:a554658735bf | 112 | void setState(uint8_t st); |
mbed_official | 0:a554658735bf | 113 | void setDeviceAddress(uint8_t addr); |
mbed_official | 0:a554658735bf | 114 | inline void setLengthTransferred(int len) { transferred = len; }; |
mbed_official | 0:a554658735bf | 115 | void setSpeed(uint8_t speed); |
mbed_official | 0:a554658735bf | 116 | void setSize(uint32_t size); |
mbed_official | 0:a554658735bf | 117 | inline void setDir(ENDPOINT_DIRECTION d) { dir = d; } |
samux | 4:b320d68e98e7 | 118 | inline void setIntfNb(uint8_t intf_nb_) { intf_nb = intf_nb_; }; |
mbed_official | 0:a554658735bf | 119 | |
mbed_official | 0:a554658735bf | 120 | // getters |
mbed_official | 0:a554658735bf | 121 | const char * getStateString(); |
mbed_official | 0:a554658735bf | 122 | inline USB_TYPE getState() { return state; } |
mbed_official | 0:a554658735bf | 123 | inline ENDPOINT_TYPE getType() { return type; }; |
mbed_official | 0:a554658735bf | 124 | inline uint8_t getDeviceAddress() { return hced->control & 0x7f; }; |
mbed_official | 0:a554658735bf | 125 | inline int getLengthTransferred() { return transferred; } |
mbed_official | 0:a554658735bf | 126 | inline uint8_t * getBufStart() { return buf_start; } |
mbed_official | 0:a554658735bf | 127 | inline uint8_t getAddress(){ return address; }; |
mbed_official | 0:a554658735bf | 128 | inline uint32_t getSize() { return (hced->control >> 16) & 0x3ff; }; |
mbed_official | 0:a554658735bf | 129 | inline volatile HCTD * getHeadTD() { return (volatile HCTD*) ((uint32_t)hced->headTD & ~0xF); }; |
mbed_official | 0:a554658735bf | 130 | inline volatile HCTD** getTDList() { return td_list; }; |
mbed_official | 0:a554658735bf | 131 | inline volatile HCED * getHCED() { return hced; }; |
mbed_official | 0:a554658735bf | 132 | inline ENDPOINT_DIRECTION getDir() { return dir; } |
mbed_official | 0:a554658735bf | 133 | inline volatile HCTD * getProcessedTD() { return td_current; }; |
mbed_official | 0:a554658735bf | 134 | inline volatile HCTD* getNextTD() { return td_current; }; |
mbed_official | 0:a554658735bf | 135 | inline bool isSetup() { return setup; } |
mbed_official | 0:a554658735bf | 136 | inline USBEndpoint * nextEndpoint() { return (USBEndpoint*)nextEp; }; |
samux | 4:b320d68e98e7 | 137 | inline uint8_t getIntfNb() { return intf_nb; }; |
mbed_official | 0:a554658735bf | 138 | |
mbed_official | 0:a554658735bf | 139 | USBDeviceConnected * dev; |
mbed_official | 0:a554658735bf | 140 | |
mbed_official | 0:a554658735bf | 141 | private: |
mbed_official | 0:a554658735bf | 142 | ENDPOINT_TYPE type; |
mbed_official | 0:a554658735bf | 143 | volatile USB_TYPE state; |
mbed_official | 0:a554658735bf | 144 | ENDPOINT_DIRECTION dir; |
mbed_official | 0:a554658735bf | 145 | bool setup; |
mbed_official | 0:a554658735bf | 146 | |
mbed_official | 0:a554658735bf | 147 | uint8_t address; |
mbed_official | 0:a554658735bf | 148 | |
mbed_official | 0:a554658735bf | 149 | int transfer_len; |
mbed_official | 0:a554658735bf | 150 | int transferred; |
mbed_official | 0:a554658735bf | 151 | uint8_t * buf_start; |
mbed_official | 0:a554658735bf | 152 | |
mbed_official | 0:a554658735bf | 153 | FunctionPointer rx; |
mbed_official | 0:a554658735bf | 154 | |
mbed_official | 0:a554658735bf | 155 | USBEndpoint* nextEp; |
mbed_official | 0:a554658735bf | 156 | |
mbed_official | 0:a554658735bf | 157 | // USBEndpoint descriptor |
mbed_official | 0:a554658735bf | 158 | volatile HCED * hced; |
mbed_official | 0:a554658735bf | 159 | |
mbed_official | 0:a554658735bf | 160 | volatile HCTD * td_list[2]; |
mbed_official | 0:a554658735bf | 161 | volatile HCTD * td_current; |
mbed_official | 0:a554658735bf | 162 | volatile HCTD * td_next; |
samux | 4:b320d68e98e7 | 163 | |
samux | 4:b320d68e98e7 | 164 | uint8_t intf_nb; |
mbed_official | 0:a554658735bf | 165 | |
mbed_official | 0:a554658735bf | 166 | }; |
mbed_official | 0:a554658735bf | 167 | |
mbed_official | 0:a554658735bf | 168 | #endif |