Added to LPC4088-USBHost the USBHostMidi class. Plugin an usb midi interface to the usb host of lpc4088 allows to send midi event to the midi interface. For the moment I can not be able to get event from the interface by using the attacheNoteOn or other triggers...

Dependencies:   FATFileSystem mbed-rtos

Fork of LPC4088-USBHost by Norimasa Okamoto

Committer:
Grag38
Date:
Mon Apr 06 12:46:58 2015 +0000
Revision:
1:d652de69bd1a
Parent:
0:148fca6fd246
Added USBHostMidi to drive midi interface.; ; Tested to send Midi messages from LPC4088. This works.; ; Need to test with incomming events.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 0:148fca6fd246 1 /* mbed USBHost Library
va009039 0:148fca6fd246 2 * Copyright (c) 2006-2013 ARM Limited
va009039 0:148fca6fd246 3 *
va009039 0:148fca6fd246 4 * Licensed under the Apache License, Version 2.0 (the "License");
va009039 0:148fca6fd246 5 * you may not use this file except in compliance with the License.
va009039 0:148fca6fd246 6 * You may obtain a copy of the License at
va009039 0:148fca6fd246 7 *
va009039 0:148fca6fd246 8 * http://www.apache.org/licenses/LICENSE-2.0
va009039 0:148fca6fd246 9 *
va009039 0:148fca6fd246 10 * Unless required by applicable law or agreed to in writing, software
va009039 0:148fca6fd246 11 * distributed under the License is distributed on an "AS IS" BASIS,
va009039 0:148fca6fd246 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
va009039 0:148fca6fd246 13 * See the License for the specific language governing permissions and
va009039 0:148fca6fd246 14 * limitations under the License.
va009039 0:148fca6fd246 15 */
va009039 0:148fca6fd246 16
va009039 0:148fca6fd246 17 #pragma once
va009039 0:148fca6fd246 18 #include "rtos.h"
va009039 0:148fca6fd246 19 #include "FunctionPointer.h"
va009039 0:148fca6fd246 20 #include "USBHostTypes.h"
va009039 0:148fca6fd246 21 #include "USBDeviceConnected.h"
va009039 0:148fca6fd246 22
va009039 0:148fca6fd246 23 class USBDeviceConnected;
va009039 0:148fca6fd246 24
va009039 0:148fca6fd246 25 #define HCTD_QUEUE_SIZE 3
va009039 0:148fca6fd246 26
va009039 0:148fca6fd246 27 struct HCTD;
va009039 0:148fca6fd246 28 struct HCED;
va009039 0:148fca6fd246 29 struct HCITD;
va009039 0:148fca6fd246 30 class USBHost;
va009039 0:148fca6fd246 31
va009039 0:148fca6fd246 32 /**
va009039 0:148fca6fd246 33 * USBEndpoint class
va009039 0:148fca6fd246 34 */
va009039 0:148fca6fd246 35 class USBEndpoint {
va009039 0:148fca6fd246 36 public:
va009039 0:148fca6fd246 37 /**
va009039 0:148fca6fd246 38 * Constructor
va009039 0:148fca6fd246 39 */
va009039 0:148fca6fd246 40 USBEndpoint(USBDeviceConnected* _dev) {
va009039 0:148fca6fd246 41 init(CONTROL_ENDPOINT, IN, 8, 0);
va009039 0:148fca6fd246 42 dev = _dev;
va009039 0:148fca6fd246 43 }
va009039 0:148fca6fd246 44
va009039 0:148fca6fd246 45 /**
va009039 0:148fca6fd246 46 * Initialize an endpoint
va009039 0:148fca6fd246 47 *
va009039 0:148fca6fd246 48 * @param type endpoint type
va009039 0:148fca6fd246 49 * @param dir endpoint direction
va009039 0:148fca6fd246 50 * @param size endpoint size
va009039 0:148fca6fd246 51 * @param ep_number endpoint number
va009039 0:148fca6fd246 52 */
va009039 0:148fca6fd246 53 void init(ENDPOINT_TYPE _type, ENDPOINT_DIRECTION _dir, uint32_t size, uint8_t ep_number) {
va009039 0:148fca6fd246 54 setState(USB_TYPE_FREE);
va009039 0:148fca6fd246 55 setType(_type);
va009039 0:148fca6fd246 56 dir = _dir;
va009039 0:148fca6fd246 57 MaxPacketSize = size;
va009039 0:148fca6fd246 58 address = ep_number;
va009039 0:148fca6fd246 59 m_pED = NULL;
va009039 0:148fca6fd246 60 //data01_toggle = DATA0; // for KL46Z
va009039 0:148fca6fd246 61 }
va009039 0:148fca6fd246 62
va009039 0:148fca6fd246 63 /**
va009039 0:148fca6fd246 64 * Attach a member function to call when a transfer is finished
va009039 0:148fca6fd246 65 *
va009039 0:148fca6fd246 66 * @param tptr pointer to the object to call the member function on
va009039 0:148fca6fd246 67 * @param mptr pointer to the member function to be called
va009039 0:148fca6fd246 68 */
va009039 0:148fca6fd246 69 template<typename T>
va009039 0:148fca6fd246 70 void attach(T* tptr, void (T::*mptr)(void)) {
va009039 0:148fca6fd246 71 if((mptr != NULL) && (tptr != NULL)) {
va009039 0:148fca6fd246 72 rx.attach(tptr, mptr);
va009039 0:148fca6fd246 73 }
va009039 0:148fca6fd246 74 }
va009039 0:148fca6fd246 75
va009039 0:148fca6fd246 76 /**
va009039 0:148fca6fd246 77 * Attach a callback called when a transfer is finished
va009039 0:148fca6fd246 78 *
va009039 0:148fca6fd246 79 * @param fptr function pointer
va009039 0:148fca6fd246 80 */
va009039 0:148fca6fd246 81 void attach(void (*fptr)(void)) {
va009039 0:148fca6fd246 82 if(fptr != NULL) {
va009039 0:148fca6fd246 83 rx.attach(fptr);
va009039 0:148fca6fd246 84 }
va009039 0:148fca6fd246 85 }
va009039 0:148fca6fd246 86
va009039 0:148fca6fd246 87 /**
va009039 0:148fca6fd246 88 * Call the handler associted to the end of a transfer
va009039 0:148fca6fd246 89 */
va009039 0:148fca6fd246 90 void call() {
va009039 0:148fca6fd246 91 rx.call();
va009039 0:148fca6fd246 92 };
va009039 0:148fca6fd246 93
va009039 0:148fca6fd246 94 void irqWdhHandler(HCTD* td) {m_queue.put(td);} // WDH
va009039 0:148fca6fd246 95 HCTD* get_queue_HCTD(uint32_t millisec=osWaitForever);
va009039 0:148fca6fd246 96 HCED* m_pED;
va009039 0:148fca6fd246 97 // report
va009039 0:148fca6fd246 98 uint8_t m_ConditionCode;
va009039 0:148fca6fd246 99 int m_report_queue_error;
va009039 0:148fca6fd246 100
va009039 0:148fca6fd246 101 void setType(ENDPOINT_TYPE _type) { type = _type; };
va009039 0:148fca6fd246 102 void setState(USB_TYPE st){ state = st; };
va009039 0:148fca6fd246 103 void setLengthTransferred(int len) { transferred = len; };
va009039 0:148fca6fd246 104 void setBuffer(uint8_t* buf, int size) { buf_start = buf, buf_size = size; }
va009039 0:148fca6fd246 105 void setSize(int size) { MaxPacketSize = size; }
va009039 0:148fca6fd246 106 void setNextEndpoint(USBEndpoint* ep) { nextEp = ep; };
va009039 0:148fca6fd246 107
va009039 0:148fca6fd246 108 USBDeviceConnected* getDevice() { return dev; }
va009039 0:148fca6fd246 109 ENDPOINT_TYPE getType() { return type; };
va009039 0:148fca6fd246 110 USB_TYPE getState() { return state; }
va009039 0:148fca6fd246 111 int getLengthTransferred() { return transferred; }
va009039 0:148fca6fd246 112 uint8_t *getBufStart() { return buf_start; }
va009039 0:148fca6fd246 113 int getBufSize() { return buf_size; }
va009039 0:148fca6fd246 114 uint8_t getAddress(){ return address; };
va009039 0:148fca6fd246 115 int getSize() { return MaxPacketSize; }
va009039 0:148fca6fd246 116 ENDPOINT_DIRECTION getDir() { return dir; }
va009039 0:148fca6fd246 117 USBEndpoint* nextEndpoint() { return nextEp; };
va009039 0:148fca6fd246 118
va009039 0:148fca6fd246 119 private:
va009039 0:148fca6fd246 120 ENDPOINT_TYPE type;
va009039 0:148fca6fd246 121 USB_TYPE state;
va009039 0:148fca6fd246 122 ENDPOINT_DIRECTION dir;
va009039 0:148fca6fd246 123 USBDeviceConnected* dev;
va009039 0:148fca6fd246 124 uint8_t address;
va009039 0:148fca6fd246 125 int transferred;
va009039 0:148fca6fd246 126 uint8_t * buf_start;
va009039 0:148fca6fd246 127 int buf_size;
va009039 0:148fca6fd246 128 FunctionPointer rx;
va009039 0:148fca6fd246 129 int MaxPacketSize;
va009039 0:148fca6fd246 130 USBEndpoint* nextEp;
va009039 0:148fca6fd246 131
va009039 0:148fca6fd246 132 protected:
va009039 0:148fca6fd246 133 Queue<HCTD, HCTD_QUEUE_SIZE> m_queue; // TD done queue
va009039 0:148fca6fd246 134 int m_td_queue_count;
va009039 0:148fca6fd246 135 };
va009039 0:148fca6fd246 136
va009039 0:148fca6fd246 137 class EndpointQueue {
va009039 0:148fca6fd246 138 public:
va009039 0:148fca6fd246 139 EndpointQueue():head(NULL),tail(NULL) {}
va009039 0:148fca6fd246 140 void push(USBEndpoint* ep) {
va009039 0:148fca6fd246 141 if (head) {
va009039 0:148fca6fd246 142 tail->setNextEndpoint(ep);
va009039 0:148fca6fd246 143 } else {
va009039 0:148fca6fd246 144 head = ep;
va009039 0:148fca6fd246 145 }
va009039 0:148fca6fd246 146 tail = ep;
va009039 0:148fca6fd246 147 ep->setNextEndpoint(NULL);
va009039 0:148fca6fd246 148 }
va009039 0:148fca6fd246 149 USBEndpoint* pop() {
va009039 0:148fca6fd246 150 USBEndpoint* ep = head;
va009039 0:148fca6fd246 151 if (ep) {
va009039 0:148fca6fd246 152 head = ep->nextEndpoint();
va009039 0:148fca6fd246 153 }
va009039 0:148fca6fd246 154 return ep;
va009039 0:148fca6fd246 155 }
va009039 0:148fca6fd246 156 bool empty() { return head == NULL; }
va009039 0:148fca6fd246 157
va009039 0:148fca6fd246 158 private:
va009039 0:148fca6fd246 159 USBEndpoint* head;
va009039 0:148fca6fd246 160 USBEndpoint* tail;
va009039 0:148fca6fd246 161 };
va009039 0:148fca6fd246 162
va009039 0:148fca6fd246 163