test
Dependents: Production_version1_0 Production_ver1_0 USBHost_TEST USBHost_Test5 ... more
Fork of USBHost by
USBHost/USBEndpoint.h@37:f1e388e7b752, 2017-07-20 (annotated)
- Committer:
- Kojto
- Date:
- Thu Jul 20 10:13:56 2017 +0100
- Revision:
- 37:f1e388e7b752
- Parent:
- 24:868cbfe611a7
Update libraries (ed9d1da)
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 | |
Kojto | 37:f1e388e7b752 | 20 | #include "Callback.h" |
mbed_official | 0:a554658735bf | 21 | #include "USBHostTypes.h" |
samux | 9:7671b6a8c363 | 22 | #include "rtos.h" |
mbed_official | 0:a554658735bf | 23 | |
mbed_official | 0:a554658735bf | 24 | class USBDeviceConnected; |
mbed_official | 0:a554658735bf | 25 | |
samux | 9:7671b6a8c363 | 26 | /** |
samux | 8:93da8ea2708b | 27 | * USBEndpoint class |
samux | 8:93da8ea2708b | 28 | */ |
mbed_official | 0:a554658735bf | 29 | class USBEndpoint |
mbed_official | 0:a554658735bf | 30 | { |
mbed_official | 0:a554658735bf | 31 | public: |
mbed_official | 0:a554658735bf | 32 | /** |
mbed_official | 0:a554658735bf | 33 | * Constructor |
mbed_official | 0:a554658735bf | 34 | */ |
mbed_official | 0:a554658735bf | 35 | USBEndpoint() { |
Kojto | 37:f1e388e7b752 | 36 | #ifdef USBHOST_OTHER |
Kojto | 37:f1e388e7b752 | 37 | speed = false; |
Kojto | 37:f1e388e7b752 | 38 | #endif |
mbed_official | 0:a554658735bf | 39 | state = USB_TYPE_FREE; |
mbed_official | 0:a554658735bf | 40 | nextEp = NULL; |
mbed_official | 0:a554658735bf | 41 | }; |
mbed_official | 0:a554658735bf | 42 | |
mbed_official | 0:a554658735bf | 43 | /** |
mbed_official | 0:a554658735bf | 44 | * Initialize an endpoint |
mbed_official | 0:a554658735bf | 45 | * |
mbed_official | 0:a554658735bf | 46 | * @param hced hced associated to the endpoint |
mbed_official | 0:a554658735bf | 47 | * @param type endpoint type |
mbed_official | 0:a554658735bf | 48 | * @param dir endpoint direction |
mbed_official | 0:a554658735bf | 49 | * @param size endpoint size |
mbed_official | 0:a554658735bf | 50 | * @param ep_number endpoint number |
mbed_official | 0:a554658735bf | 51 | * @param td_list array of two allocated transfer descriptors |
mbed_official | 0:a554658735bf | 52 | */ |
Kojto | 37:f1e388e7b752 | 53 | |
mbed_official | 0:a554658735bf | 54 | 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 | 55 | |
mbed_official | 0:a554658735bf | 56 | /** |
samux | 8:93da8ea2708b | 57 | * Set next token. Warning: only useful for the control endpoint |
mbed_official | 0:a554658735bf | 58 | * |
mbed_official | 0:a554658735bf | 59 | * @param token IN, OUT or SETUP token |
mbed_official | 0:a554658735bf | 60 | */ |
mbed_official | 0:a554658735bf | 61 | void setNextToken(uint32_t token); |
mbed_official | 0:a554658735bf | 62 | |
mbed_official | 0:a554658735bf | 63 | /** |
mbed_official | 0:a554658735bf | 64 | * Queue an endpoint |
mbed_official | 0:a554658735bf | 65 | * |
samux | 8:93da8ea2708b | 66 | * @param endpoint endpoint which will be queued in the linked list |
mbed_official | 0:a554658735bf | 67 | */ |
mbed_official | 0:a554658735bf | 68 | void queueEndpoint(USBEndpoint * endpoint); |
mbed_official | 0:a554658735bf | 69 | |
mbed_official | 0:a554658735bf | 70 | |
mbed_official | 0:a554658735bf | 71 | /** |
mbed_official | 0:a554658735bf | 72 | * Queue a transfer on the endpoint |
mbed_official | 0:a554658735bf | 73 | */ |
Kojto | 37:f1e388e7b752 | 74 | USB_TYPE queueTransfer(); |
mbed_official | 0:a554658735bf | 75 | |
mbed_official | 0:a554658735bf | 76 | /** |
mbed_official | 0:a554658735bf | 77 | * Unqueue a transfer from the endpoint |
mbed_official | 0:a554658735bf | 78 | * |
mbed_official | 0:a554658735bf | 79 | * @param td hctd which will be unqueued |
mbed_official | 0:a554658735bf | 80 | */ |
mbed_official | 0:a554658735bf | 81 | void unqueueTransfer(volatile HCTD * td); |
mbed_official | 0:a554658735bf | 82 | |
mbed_official | 0:a554658735bf | 83 | /** |
mbed_official | 0:a554658735bf | 84 | * Attach a member function to call when a transfer is finished |
mbed_official | 0:a554658735bf | 85 | * |
mbed_official | 0:a554658735bf | 86 | * @param tptr pointer to the object to call the member function on |
mbed_official | 0:a554658735bf | 87 | * @param mptr pointer to the member function to be called |
mbed_official | 0:a554658735bf | 88 | */ |
mbed_official | 0:a554658735bf | 89 | template<typename T> |
mbed_official | 0:a554658735bf | 90 | inline void attach(T* tptr, void (T::*mptr)(void)) { |
mbed_official | 0:a554658735bf | 91 | if((mptr != NULL) && (tptr != NULL)) { |
mbed_official | 0:a554658735bf | 92 | rx.attach(tptr, mptr); |
mbed_official | 0:a554658735bf | 93 | } |
mbed_official | 0:a554658735bf | 94 | } |
mbed_official | 0:a554658735bf | 95 | |
mbed_official | 0:a554658735bf | 96 | /** |
mbed_official | 0:a554658735bf | 97 | * Attach a callback called when a transfer is finished |
mbed_official | 0:a554658735bf | 98 | * |
mbed_official | 0:a554658735bf | 99 | * @param fptr function pointer |
mbed_official | 0:a554658735bf | 100 | */ |
samux | 8:93da8ea2708b | 101 | inline void attach(void (*fptr)(void)) { |
samux | 8:93da8ea2708b | 102 | if(fptr != NULL) { |
samux | 8:93da8ea2708b | 103 | rx.attach(fptr); |
mbed_official | 0:a554658735bf | 104 | } |
mbed_official | 0:a554658735bf | 105 | } |
mbed_official | 0:a554658735bf | 106 | |
mbed_official | 0:a554658735bf | 107 | /** |
mbed_official | 0:a554658735bf | 108 | * Call the handler associted to the end of a transfer |
mbed_official | 0:a554658735bf | 109 | */ |
mbed_official | 0:a554658735bf | 110 | inline void call() { |
Kojto | 37:f1e388e7b752 | 111 | if (rx) |
Kojto | 37:f1e388e7b752 | 112 | rx.call(); |
mbed_official | 0:a554658735bf | 113 | }; |
mbed_official | 0:a554658735bf | 114 | |
mbed_official | 0:a554658735bf | 115 | |
mbed_official | 0:a554658735bf | 116 | // setters |
Kojto | 37:f1e388e7b752 | 117 | #ifdef USBHOST_OTHER |
Kojto | 37:f1e388e7b752 | 118 | void setState(USB_TYPE st); |
Kojto | 37:f1e388e7b752 | 119 | #else |
mbed_official | 0:a554658735bf | 120 | inline void setState(USB_TYPE st) { state = st; } |
Kojto | 37:f1e388e7b752 | 121 | #endif |
mbed_official | 0:a554658735bf | 122 | void setState(uint8_t st); |
mbed_official | 0:a554658735bf | 123 | void setDeviceAddress(uint8_t addr); |
mbed_official | 0:a554658735bf | 124 | inline void setLengthTransferred(int len) { transferred = len; }; |
mbed_official | 0:a554658735bf | 125 | void setSpeed(uint8_t speed); |
mbed_official | 0:a554658735bf | 126 | void setSize(uint32_t size); |
mbed_official | 0:a554658735bf | 127 | inline void setDir(ENDPOINT_DIRECTION d) { dir = d; } |
samux | 4:b320d68e98e7 | 128 | inline void setIntfNb(uint8_t intf_nb_) { intf_nb = intf_nb_; }; |
mbed_official | 0:a554658735bf | 129 | |
mbed_official | 0:a554658735bf | 130 | // getters |
mbed_official | 0:a554658735bf | 131 | const char * getStateString(); |
mbed_official | 0:a554658735bf | 132 | inline USB_TYPE getState() { return state; } |
mbed_official | 0:a554658735bf | 133 | inline ENDPOINT_TYPE getType() { return type; }; |
Kojto | 37:f1e388e7b752 | 134 | #ifdef USBHOST_OTHER |
Kojto | 37:f1e388e7b752 | 135 | inline uint8_t getDeviceAddress() { return device_address; }; |
Kojto | 37:f1e388e7b752 | 136 | inline uint32_t getSize() { return size; }; |
Kojto | 37:f1e388e7b752 | 137 | #else |
mbed_official | 0:a554658735bf | 138 | inline uint8_t getDeviceAddress() { return hced->control & 0x7f; }; |
Kojto | 37:f1e388e7b752 | 139 | inline uint32_t getSize() { return (hced->control >> 16) & 0x3ff; }; |
Kojto | 37:f1e388e7b752 | 140 | inline volatile HCTD * getHeadTD() { return (volatile HCTD*) ((uint32_t)hced->headTD & ~0xF); }; |
Kojto | 37:f1e388e7b752 | 141 | #endif |
mbed_official | 0:a554658735bf | 142 | inline int getLengthTransferred() { return transferred; } |
mbed_official | 0:a554658735bf | 143 | inline uint8_t * getBufStart() { return buf_start; } |
mbed_official | 0:a554658735bf | 144 | inline uint8_t getAddress(){ return address; }; |
mbed_official | 0:a554658735bf | 145 | inline volatile HCTD** getTDList() { return td_list; }; |
mbed_official | 0:a554658735bf | 146 | inline volatile HCED * getHCED() { return hced; }; |
mbed_official | 0:a554658735bf | 147 | inline ENDPOINT_DIRECTION getDir() { return dir; } |
mbed_official | 0:a554658735bf | 148 | inline volatile HCTD * getProcessedTD() { return td_current; }; |
mbed_official | 0:a554658735bf | 149 | inline volatile HCTD* getNextTD() { return td_current; }; |
mbed_official | 0:a554658735bf | 150 | inline bool isSetup() { return setup; } |
mbed_official | 0:a554658735bf | 151 | inline USBEndpoint * nextEndpoint() { return (USBEndpoint*)nextEp; }; |
samux | 4:b320d68e98e7 | 152 | inline uint8_t getIntfNb() { return intf_nb; }; |
mbed_official | 24:868cbfe611a7 | 153 | |
mbed_official | 0:a554658735bf | 154 | USBDeviceConnected * dev; |
mbed_official | 24:868cbfe611a7 | 155 | |
samux | 9:7671b6a8c363 | 156 | Queue<uint8_t, 1> ep_queue; |
mbed_official | 0:a554658735bf | 157 | |
mbed_official | 0:a554658735bf | 158 | private: |
mbed_official | 0:a554658735bf | 159 | ENDPOINT_TYPE type; |
mbed_official | 0:a554658735bf | 160 | volatile USB_TYPE state; |
mbed_official | 0:a554658735bf | 161 | ENDPOINT_DIRECTION dir; |
Kojto | 37:f1e388e7b752 | 162 | #ifdef USBHOST_OTHER |
Kojto | 37:f1e388e7b752 | 163 | uint32_t size; |
Kojto | 37:f1e388e7b752 | 164 | uint32_t ep_number; |
Kojto | 37:f1e388e7b752 | 165 | uint32_t speed; |
Kojto | 37:f1e388e7b752 | 166 | uint8_t device_address; |
Kojto | 37:f1e388e7b752 | 167 | #endif |
mbed_official | 0:a554658735bf | 168 | bool setup; |
mbed_official | 0:a554658735bf | 169 | |
mbed_official | 0:a554658735bf | 170 | uint8_t address; |
mbed_official | 0:a554658735bf | 171 | |
mbed_official | 0:a554658735bf | 172 | int transfer_len; |
mbed_official | 0:a554658735bf | 173 | int transferred; |
mbed_official | 0:a554658735bf | 174 | uint8_t * buf_start; |
mbed_official | 0:a554658735bf | 175 | |
Kojto | 37:f1e388e7b752 | 176 | Callback<void()> rx; |
mbed_official | 0:a554658735bf | 177 | |
mbed_official | 0:a554658735bf | 178 | USBEndpoint* nextEp; |
mbed_official | 0:a554658735bf | 179 | |
mbed_official | 0:a554658735bf | 180 | // USBEndpoint descriptor |
mbed_official | 0:a554658735bf | 181 | volatile HCED * hced; |
mbed_official | 0:a554658735bf | 182 | |
mbed_official | 0:a554658735bf | 183 | volatile HCTD * td_list[2]; |
mbed_official | 0:a554658735bf | 184 | volatile HCTD * td_current; |
mbed_official | 0:a554658735bf | 185 | volatile HCTD * td_next; |
mbed_official | 24:868cbfe611a7 | 186 | |
samux | 4:b320d68e98e7 | 187 | uint8_t intf_nb; |
mbed_official | 0:a554658735bf | 188 | |
mbed_official | 0:a554658735bf | 189 | }; |
mbed_official | 0:a554658735bf | 190 | |
mbed_official | 0:a554658735bf | 191 | #endif |