ST/USBHOST forked to add another HID handler for raw keyboard data to get more detail not available with current handlers (all pressed keys, all releases, and periodic updates)

Dependents:   C64-stm429_discovery

Committer:
frq08711@LMECWL0871.LME.ST.COM
Date:
Wed Feb 15 10:49:44 2017 +0100
Revision:
1:ab240722d7ef
Child:
5:fc157e6bd5a5
update to mbed 5.3.5

Who changed what in which revision?

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