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