2018.07.26

Dependencies:   FATFileSystem3 mbed-rtos

Fork of USBHost by mbed official

Committer:
mbed_official
Date:
Wed Mar 06 16:27:14 2013 +0000
Revision:
0:a554658735bf
Child:
4:b320d68e98e7
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:a554658735bf 1 /* Copyright (c) 2010-2012 mbed.org, MIT License
mbed_official 0:a554658735bf 2 *
mbed_official 0:a554658735bf 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
mbed_official 0:a554658735bf 4 * and associated documentation files (the "Software"), to deal in the Software without
mbed_official 0:a554658735bf 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
mbed_official 0:a554658735bf 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
mbed_official 0:a554658735bf 7 * Software is furnished to do so, subject to the following conditions:
mbed_official 0:a554658735bf 8 *
mbed_official 0:a554658735bf 9 * The above copyright notice and this permission notice shall be included in all copies or
mbed_official 0:a554658735bf 10 * substantial portions of the Software.
mbed_official 0:a554658735bf 11 *
mbed_official 0:a554658735bf 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
mbed_official 0:a554658735bf 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
mbed_official 0:a554658735bf 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
mbed_official 0:a554658735bf 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mbed_official 0:a554658735bf 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
mbed_official 0:a554658735bf 17 */
mbed_official 0:a554658735bf 18
mbed_official 0:a554658735bf 19 #ifndef USBENDPOINT_H
mbed_official 0:a554658735bf 20 #define USBENDPOINT_H
mbed_official 0:a554658735bf 21
mbed_official 0:a554658735bf 22 #include "FunctionPointer.h"
mbed_official 0:a554658735bf 23 #include "USBHostTypes.h"
mbed_official 0:a554658735bf 24
mbed_official 0:a554658735bf 25 class USBDeviceConnected;
mbed_official 0:a554658735bf 26
mbed_official 0:a554658735bf 27 class USBEndpoint
mbed_official 0:a554658735bf 28 {
mbed_official 0:a554658735bf 29 public:
mbed_official 0:a554658735bf 30 /**
mbed_official 0:a554658735bf 31 * Constructor
mbed_official 0:a554658735bf 32 */
mbed_official 0:a554658735bf 33 USBEndpoint() {
mbed_official 0:a554658735bf 34 state = USB_TYPE_FREE;
mbed_official 0:a554658735bf 35 nextEp = NULL;
mbed_official 0:a554658735bf 36 };
mbed_official 0:a554658735bf 37
mbed_official 0:a554658735bf 38 /**
mbed_official 0:a554658735bf 39 * Initialize an endpoint
mbed_official 0:a554658735bf 40 *
mbed_official 0:a554658735bf 41 * @param hced hced associated to the endpoint
mbed_official 0:a554658735bf 42 * @param type endpoint type
mbed_official 0:a554658735bf 43 * @param dir endpoint direction
mbed_official 0:a554658735bf 44 * @param size endpoint size
mbed_official 0:a554658735bf 45 * @param ep_number endpoint number
mbed_official 0:a554658735bf 46 * @param td_list array of two allocated transfer descriptors
mbed_official 0:a554658735bf 47 */
mbed_official 0:a554658735bf 48 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 49
mbed_official 0:a554658735bf 50 /**
mbed_official 0:a554658735bf 51 * Set next token. Warining: only useful for the control endpoint
mbed_official 0:a554658735bf 52 *
mbed_official 0:a554658735bf 53 * @param token IN, OUT or SETUP token
mbed_official 0:a554658735bf 54 */
mbed_official 0:a554658735bf 55 void setNextToken(uint32_t token);
mbed_official 0:a554658735bf 56
mbed_official 0:a554658735bf 57 /**
mbed_official 0:a554658735bf 58 * Queue an endpoint
mbed_official 0:a554658735bf 59 *
mbed_official 0:a554658735bf 60 * endpoint endpoint which will be queued in the linked list
mbed_official 0:a554658735bf 61 */
mbed_official 0:a554658735bf 62 void queueEndpoint(USBEndpoint * endpoint);
mbed_official 0:a554658735bf 63
mbed_official 0:a554658735bf 64
mbed_official 0:a554658735bf 65 /**
mbed_official 0:a554658735bf 66 * Queue a transfer on the endpoint
mbed_official 0:a554658735bf 67 */
mbed_official 0:a554658735bf 68 void queueTransfer();
mbed_official 0:a554658735bf 69
mbed_official 0:a554658735bf 70 /**
mbed_official 0:a554658735bf 71 * Unqueue a transfer from the endpoint
mbed_official 0:a554658735bf 72 *
mbed_official 0:a554658735bf 73 * @param td hctd which will be unqueued
mbed_official 0:a554658735bf 74 */
mbed_official 0:a554658735bf 75 void unqueueTransfer(volatile HCTD * td);
mbed_official 0:a554658735bf 76
mbed_official 0:a554658735bf 77 /**
mbed_official 0:a554658735bf 78 * Attach a member function to call when a transfer is finished
mbed_official 0:a554658735bf 79 *
mbed_official 0:a554658735bf 80 * @param tptr pointer to the object to call the member function on
mbed_official 0:a554658735bf 81 * @param mptr pointer to the member function to be called
mbed_official 0:a554658735bf 82 */
mbed_official 0:a554658735bf 83 template<typename T>
mbed_official 0:a554658735bf 84 inline void attach(T* tptr, void (T::*mptr)(void)) {
mbed_official 0:a554658735bf 85 if((mptr != NULL) && (tptr != NULL)) {
mbed_official 0:a554658735bf 86 rx.attach(tptr, mptr);
mbed_official 0:a554658735bf 87 }
mbed_official 0:a554658735bf 88 }
mbed_official 0:a554658735bf 89
mbed_official 0:a554658735bf 90 /**
mbed_official 0:a554658735bf 91 * Attach a callback called when a transfer is finished
mbed_official 0:a554658735bf 92 *
mbed_official 0:a554658735bf 93 * @param fptr function pointer
mbed_official 0:a554658735bf 94 */
mbed_official 0:a554658735bf 95 inline void attach(void (*fn)(void)) {
mbed_official 0:a554658735bf 96 if(fn != NULL) {
mbed_official 0:a554658735bf 97 rx.attach(fn);
mbed_official 0:a554658735bf 98 }
mbed_official 0:a554658735bf 99 }
mbed_official 0:a554658735bf 100
mbed_official 0:a554658735bf 101 /**
mbed_official 0:a554658735bf 102 * Call the handler associted to the end of a transfer
mbed_official 0:a554658735bf 103 */
mbed_official 0:a554658735bf 104 inline void call() {
mbed_official 0:a554658735bf 105 rx.call();
mbed_official 0:a554658735bf 106 };
mbed_official 0:a554658735bf 107
mbed_official 0:a554658735bf 108
mbed_official 0:a554658735bf 109 // setters
mbed_official 0:a554658735bf 110 inline void setState(USB_TYPE st) { state = st; }
mbed_official 0:a554658735bf 111 void setState(uint8_t st);
mbed_official 0:a554658735bf 112 void setDeviceAddress(uint8_t addr);
mbed_official 0:a554658735bf 113 inline void setLengthTransferred(int len) { transferred = len; };
mbed_official 0:a554658735bf 114 void setSpeed(uint8_t speed);
mbed_official 0:a554658735bf 115 void setSize(uint32_t size);
mbed_official 0:a554658735bf 116 inline void setDir(ENDPOINT_DIRECTION d) { dir = d; }
mbed_official 0:a554658735bf 117
mbed_official 0:a554658735bf 118 // getters
mbed_official 0:a554658735bf 119 const char * getStateString();
mbed_official 0:a554658735bf 120 inline USB_TYPE getState() { return state; }
mbed_official 0:a554658735bf 121 inline ENDPOINT_TYPE getType() { return type; };
mbed_official 0:a554658735bf 122 inline uint8_t getDeviceAddress() { return hced->control & 0x7f; };
mbed_official 0:a554658735bf 123 inline int getLengthTransferred() { return transferred; }
mbed_official 0:a554658735bf 124 inline uint8_t * getBufStart() { return buf_start; }
mbed_official 0:a554658735bf 125 inline uint8_t getAddress(){ return address; };
mbed_official 0:a554658735bf 126 inline uint32_t getSize() { return (hced->control >> 16) & 0x3ff; };
mbed_official 0:a554658735bf 127 inline volatile HCTD * getHeadTD() { return (volatile HCTD*) ((uint32_t)hced->headTD & ~0xF); };
mbed_official 0:a554658735bf 128 inline volatile HCTD** getTDList() { return td_list; };
mbed_official 0:a554658735bf 129 inline volatile HCED * getHCED() { return hced; };
mbed_official 0:a554658735bf 130 inline ENDPOINT_DIRECTION getDir() { return dir; }
mbed_official 0:a554658735bf 131 inline volatile HCTD * getProcessedTD() { return td_current; };
mbed_official 0:a554658735bf 132 inline volatile HCTD* getNextTD() { return td_current; };
mbed_official 0:a554658735bf 133 inline bool isSetup() { return setup; }
mbed_official 0:a554658735bf 134 inline USBEndpoint * nextEndpoint() { return (USBEndpoint*)nextEp; };
mbed_official 0:a554658735bf 135
mbed_official 0:a554658735bf 136 USBDeviceConnected * dev;
mbed_official 0:a554658735bf 137
mbed_official 0:a554658735bf 138 private:
mbed_official 0:a554658735bf 139 ENDPOINT_TYPE type;
mbed_official 0:a554658735bf 140 volatile USB_TYPE state;
mbed_official 0:a554658735bf 141 ENDPOINT_DIRECTION dir;
mbed_official 0:a554658735bf 142 bool setup;
mbed_official 0:a554658735bf 143
mbed_official 0:a554658735bf 144 uint8_t address;
mbed_official 0:a554658735bf 145
mbed_official 0:a554658735bf 146 int transfer_len;
mbed_official 0:a554658735bf 147 int transferred;
mbed_official 0:a554658735bf 148 uint8_t * buf_start;
mbed_official 0:a554658735bf 149
mbed_official 0:a554658735bf 150 FunctionPointer rx;
mbed_official 0:a554658735bf 151
mbed_official 0:a554658735bf 152 USBEndpoint* nextEp;
mbed_official 0:a554658735bf 153
mbed_official 0:a554658735bf 154 // USBEndpoint descriptor
mbed_official 0:a554658735bf 155 volatile HCED * hced;
mbed_official 0:a554658735bf 156
mbed_official 0:a554658735bf 157 volatile HCTD * td_list[2];
mbed_official 0:a554658735bf 158 volatile HCTD * td_current;
mbed_official 0:a554658735bf 159 volatile HCTD * td_next;
mbed_official 0:a554658735bf 160
mbed_official 0:a554658735bf 161 };
mbed_official 0:a554658735bf 162
mbed_official 0:a554658735bf 163 #endif
mbed_official 0:a554658735bf 164