Opencv 3.1 project on GR-PEACH board

Fork of gr-peach-opencv-project by the do

Committer:
thedo
Date:
Thu Jun 29 11:00:41 2017 +0000
Revision:
166:3a9487d57a5c
This is Opencv 3.1 project on GR-PEACH board

Who changed what in which revision?

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