Simple USBHost WebCam for EA LPC4088 QSB/LPC1768 test program
Dependencies: LPC4088-USBHost mbed
EA LPC4088 QSB/LPC1768をUSBホストにしてWebカメラからJPEG画像を読み取るテストプログラムです。
The usage is the same as KL46Z-USBHostC270_example.
使い方はKL46Z-USBHostC270_exampleと同じです。
動作確認: Logitech C270,Logitech Q200R(Qcam Orbit AF)
LPC4088-USBHost/USBHost/USBEndpoint.h@0:c972ee42b455, 2014-04-24 (annotated)
- Committer:
- va009039
- Date:
- Thu Apr 24 05:38:45 2014 +0000
- Revision:
- 0:c972ee42b455
first commit,sync rev.29.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:c972ee42b455 | 1 | /* mbed USBHost Library |
va009039 | 0:c972ee42b455 | 2 | * Copyright (c) 2006-2013 ARM Limited |
va009039 | 0:c972ee42b455 | 3 | * |
va009039 | 0:c972ee42b455 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
va009039 | 0:c972ee42b455 | 5 | * you may not use this file except in compliance with the License. |
va009039 | 0:c972ee42b455 | 6 | * You may obtain a copy of the License at |
va009039 | 0:c972ee42b455 | 7 | * |
va009039 | 0:c972ee42b455 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
va009039 | 0:c972ee42b455 | 9 | * |
va009039 | 0:c972ee42b455 | 10 | * Unless required by applicable law or agreed to in writing, software |
va009039 | 0:c972ee42b455 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
va009039 | 0:c972ee42b455 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
va009039 | 0:c972ee42b455 | 13 | * See the License for the specific language governing permissions and |
va009039 | 0:c972ee42b455 | 14 | * limitations under the License. |
va009039 | 0:c972ee42b455 | 15 | */ |
va009039 | 0:c972ee42b455 | 16 | |
va009039 | 0:c972ee42b455 | 17 | #pragma once |
va009039 | 0:c972ee42b455 | 18 | #include "rtos.h" |
va009039 | 0:c972ee42b455 | 19 | #include "FunctionPointer.h" |
va009039 | 0:c972ee42b455 | 20 | #include "USBHostTypes.h" |
va009039 | 0:c972ee42b455 | 21 | #include "USBDeviceConnected.h" |
va009039 | 0:c972ee42b455 | 22 | |
va009039 | 0:c972ee42b455 | 23 | class USBDeviceConnected; |
va009039 | 0:c972ee42b455 | 24 | |
va009039 | 0:c972ee42b455 | 25 | #define HCTD_QUEUE_SIZE 3 |
va009039 | 0:c972ee42b455 | 26 | |
va009039 | 0:c972ee42b455 | 27 | struct HCTD; |
va009039 | 0:c972ee42b455 | 28 | struct HCED; |
va009039 | 0:c972ee42b455 | 29 | struct HCITD; |
va009039 | 0:c972ee42b455 | 30 | class USBHost; |
va009039 | 0:c972ee42b455 | 31 | |
va009039 | 0:c972ee42b455 | 32 | /** |
va009039 | 0:c972ee42b455 | 33 | * USBEndpoint class |
va009039 | 0:c972ee42b455 | 34 | */ |
va009039 | 0:c972ee42b455 | 35 | class USBEndpoint { |
va009039 | 0:c972ee42b455 | 36 | public: |
va009039 | 0:c972ee42b455 | 37 | /** |
va009039 | 0:c972ee42b455 | 38 | * Constructor |
va009039 | 0:c972ee42b455 | 39 | */ |
va009039 | 0:c972ee42b455 | 40 | USBEndpoint(USBDeviceConnected* _dev) { |
va009039 | 0:c972ee42b455 | 41 | init(CONTROL_ENDPOINT, IN, 8, 0); |
va009039 | 0:c972ee42b455 | 42 | dev = _dev; |
va009039 | 0:c972ee42b455 | 43 | } |
va009039 | 0:c972ee42b455 | 44 | |
va009039 | 0:c972ee42b455 | 45 | /** |
va009039 | 0:c972ee42b455 | 46 | * Initialize an endpoint |
va009039 | 0:c972ee42b455 | 47 | * |
va009039 | 0:c972ee42b455 | 48 | * @param type endpoint type |
va009039 | 0:c972ee42b455 | 49 | * @param dir endpoint direction |
va009039 | 0:c972ee42b455 | 50 | * @param size endpoint size |
va009039 | 0:c972ee42b455 | 51 | * @param ep_number endpoint number |
va009039 | 0:c972ee42b455 | 52 | */ |
va009039 | 0:c972ee42b455 | 53 | void init(ENDPOINT_TYPE _type, ENDPOINT_DIRECTION _dir, uint32_t size, uint8_t ep_number) { |
va009039 | 0:c972ee42b455 | 54 | setType(_type); |
va009039 | 0:c972ee42b455 | 55 | dir = _dir; |
va009039 | 0:c972ee42b455 | 56 | MaxPacketSize = size; |
va009039 | 0:c972ee42b455 | 57 | address = ep_number; |
va009039 | 0:c972ee42b455 | 58 | m_pED = NULL; |
va009039 | 0:c972ee42b455 | 59 | //data01_toggle = DATA0; // for KL46Z |
va009039 | 0:c972ee42b455 | 60 | } |
va009039 | 0:c972ee42b455 | 61 | |
va009039 | 0:c972ee42b455 | 62 | /** |
va009039 | 0:c972ee42b455 | 63 | * Attach a member function to call when a transfer is finished |
va009039 | 0:c972ee42b455 | 64 | * |
va009039 | 0:c972ee42b455 | 65 | * @param tptr pointer to the object to call the member function on |
va009039 | 0:c972ee42b455 | 66 | * @param mptr pointer to the member function to be called |
va009039 | 0:c972ee42b455 | 67 | */ |
va009039 | 0:c972ee42b455 | 68 | template<typename T> |
va009039 | 0:c972ee42b455 | 69 | void attach(T* tptr, void (T::*mptr)(void)) { |
va009039 | 0:c972ee42b455 | 70 | if((mptr != NULL) && (tptr != NULL)) { |
va009039 | 0:c972ee42b455 | 71 | rx.attach(tptr, mptr); |
va009039 | 0:c972ee42b455 | 72 | } |
va009039 | 0:c972ee42b455 | 73 | } |
va009039 | 0:c972ee42b455 | 74 | |
va009039 | 0:c972ee42b455 | 75 | /** |
va009039 | 0:c972ee42b455 | 76 | * Attach a callback called when a transfer is finished |
va009039 | 0:c972ee42b455 | 77 | * |
va009039 | 0:c972ee42b455 | 78 | * @param fptr function pointer |
va009039 | 0:c972ee42b455 | 79 | */ |
va009039 | 0:c972ee42b455 | 80 | void attach(void (*fptr)(void)) { |
va009039 | 0:c972ee42b455 | 81 | if(fptr != NULL) { |
va009039 | 0:c972ee42b455 | 82 | rx.attach(fptr); |
va009039 | 0:c972ee42b455 | 83 | } |
va009039 | 0:c972ee42b455 | 84 | } |
va009039 | 0:c972ee42b455 | 85 | |
va009039 | 0:c972ee42b455 | 86 | /** |
va009039 | 0:c972ee42b455 | 87 | * Call the handler associted to the end of a transfer |
va009039 | 0:c972ee42b455 | 88 | */ |
va009039 | 0:c972ee42b455 | 89 | void call() { |
va009039 | 0:c972ee42b455 | 90 | rx.call(); |
va009039 | 0:c972ee42b455 | 91 | }; |
va009039 | 0:c972ee42b455 | 92 | |
va009039 | 0:c972ee42b455 | 93 | void irqWdhHandler(HCTD* td) {m_queue.put(td);} // WDH |
va009039 | 0:c972ee42b455 | 94 | HCTD* get_queue_HCTD(uint32_t millisec=osWaitForever); |
va009039 | 0:c972ee42b455 | 95 | HCED* m_pED; |
va009039 | 0:c972ee42b455 | 96 | // report |
va009039 | 0:c972ee42b455 | 97 | uint8_t m_ConditionCode; |
va009039 | 0:c972ee42b455 | 98 | int m_report_queue_error; |
va009039 | 0:c972ee42b455 | 99 | |
va009039 | 0:c972ee42b455 | 100 | void setType(ENDPOINT_TYPE _type) { type = _type; }; |
va009039 | 0:c972ee42b455 | 101 | void setState(uint8_t st){}; // dummy |
va009039 | 0:c972ee42b455 | 102 | void setLengthTransferred(int len) { transferred = len; }; |
va009039 | 0:c972ee42b455 | 103 | void setBuffer(uint8_t* buf, int size) { buf_start = buf, buf_size = size; } |
va009039 | 0:c972ee42b455 | 104 | void setSize(int size) { MaxPacketSize = size; } |
va009039 | 0:c972ee42b455 | 105 | void setNextEndpoint(USBEndpoint* ep) { nextEp = ep; }; |
va009039 | 0:c972ee42b455 | 106 | |
va009039 | 0:c972ee42b455 | 107 | USBDeviceConnected* getDevice() { return dev; } |
va009039 | 0:c972ee42b455 | 108 | ENDPOINT_TYPE getType() { return type; }; |
va009039 | 0:c972ee42b455 | 109 | int getLengthTransferred() { return transferred; } |
va009039 | 0:c972ee42b455 | 110 | uint8_t *getBufStart() { return buf_start; } |
va009039 | 0:c972ee42b455 | 111 | int getBufSize() { return buf_size; } |
va009039 | 0:c972ee42b455 | 112 | uint8_t getAddress(){ return address; }; |
va009039 | 0:c972ee42b455 | 113 | int getSize() { return MaxPacketSize; } |
va009039 | 0:c972ee42b455 | 114 | ENDPOINT_DIRECTION getDir() { return dir; } |
va009039 | 0:c972ee42b455 | 115 | USBEndpoint* nextEndpoint() { return nextEp; }; |
va009039 | 0:c972ee42b455 | 116 | |
va009039 | 0:c972ee42b455 | 117 | private: |
va009039 | 0:c972ee42b455 | 118 | ENDPOINT_TYPE type; |
va009039 | 0:c972ee42b455 | 119 | ENDPOINT_DIRECTION dir; |
va009039 | 0:c972ee42b455 | 120 | USBDeviceConnected* dev; |
va009039 | 0:c972ee42b455 | 121 | uint8_t address; |
va009039 | 0:c972ee42b455 | 122 | int transferred; |
va009039 | 0:c972ee42b455 | 123 | uint8_t * buf_start; |
va009039 | 0:c972ee42b455 | 124 | int buf_size; |
va009039 | 0:c972ee42b455 | 125 | FunctionPointer rx; |
va009039 | 0:c972ee42b455 | 126 | int MaxPacketSize; |
va009039 | 0:c972ee42b455 | 127 | USBEndpoint* nextEp; |
va009039 | 0:c972ee42b455 | 128 | |
va009039 | 0:c972ee42b455 | 129 | protected: |
va009039 | 0:c972ee42b455 | 130 | Queue<HCTD, HCTD_QUEUE_SIZE> m_queue; // TD done queue |
va009039 | 0:c972ee42b455 | 131 | int m_td_queue_count; |
va009039 | 0:c972ee42b455 | 132 | }; |
va009039 | 0:c972ee42b455 | 133 | |
va009039 | 0:c972ee42b455 | 134 | class EndpointQueue { |
va009039 | 0:c972ee42b455 | 135 | public: |
va009039 | 0:c972ee42b455 | 136 | EndpointQueue():head(NULL),tail(NULL) {} |
va009039 | 0:c972ee42b455 | 137 | void push(USBEndpoint* ep) { |
va009039 | 0:c972ee42b455 | 138 | if (head) { |
va009039 | 0:c972ee42b455 | 139 | tail->setNextEndpoint(ep); |
va009039 | 0:c972ee42b455 | 140 | } else { |
va009039 | 0:c972ee42b455 | 141 | head = ep; |
va009039 | 0:c972ee42b455 | 142 | } |
va009039 | 0:c972ee42b455 | 143 | tail = ep; |
va009039 | 0:c972ee42b455 | 144 | ep->setNextEndpoint(NULL); |
va009039 | 0:c972ee42b455 | 145 | } |
va009039 | 0:c972ee42b455 | 146 | USBEndpoint* pop() { |
va009039 | 0:c972ee42b455 | 147 | USBEndpoint* ep = head; |
va009039 | 0:c972ee42b455 | 148 | if (ep) { |
va009039 | 0:c972ee42b455 | 149 | head = ep->nextEndpoint(); |
va009039 | 0:c972ee42b455 | 150 | } |
va009039 | 0:c972ee42b455 | 151 | return ep; |
va009039 | 0:c972ee42b455 | 152 | } |
va009039 | 0:c972ee42b455 | 153 | bool empty() { return head == NULL; } |
va009039 | 0:c972ee42b455 | 154 | |
va009039 | 0:c972ee42b455 | 155 | private: |
va009039 | 0:c972ee42b455 | 156 | USBEndpoint* head; |
va009039 | 0:c972ee42b455 | 157 | USBEndpoint* tail; |
va009039 | 0:c972ee42b455 | 158 | }; |
va009039 | 0:c972ee42b455 | 159 | |
va009039 | 0:c972ee42b455 | 160 |