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 #include "USBHost.h"
va009039 0:148fca6fd246 2
va009039 0:148fca6fd246 3 #define PORT_CONNECTION 0
va009039 0:148fca6fd246 4 #define PORT_ENABLE 1
va009039 0:148fca6fd246 5 #define PORT_SUSPEND 2
va009039 0:148fca6fd246 6 #define PORT_OVER_CURRENT 3
va009039 0:148fca6fd246 7 #define PORT_RESET 4
va009039 0:148fca6fd246 8 #define PORT_POWER 8
va009039 0:148fca6fd246 9 #define PORT_LOW_SPEED 9
va009039 0:148fca6fd246 10
va009039 0:148fca6fd246 11 #define C_PORT_CONNECTION 16
va009039 0:148fca6fd246 12 #define C_PORT_ENABLE 17
va009039 0:148fca6fd246 13 #define C_PORT_SUSPEND 18
va009039 0:148fca6fd246 14 #define C_PORT_OVER_CURRENT 19
va009039 0:148fca6fd246 15 #define C_PORT_RESET 20
va009039 0:148fca6fd246 16
va009039 0:148fca6fd246 17 bool USBHost::Hub(USBDeviceConnected* dev) {
va009039 0:148fca6fd246 18 USB_INFO("New HUB: VID:%04x PID:%04x [dev: %p]", dev->getVid(), dev->getPid(), dev);
va009039 0:148fca6fd246 19 HubDescriptor hubdesc;
va009039 0:148fca6fd246 20 // get HUB descriptor
va009039 0:148fca6fd246 21 int rc = controlRead(dev,
va009039 0:148fca6fd246 22 USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS,
va009039 0:148fca6fd246 23 GET_DESCRIPTOR,
va009039 0:148fca6fd246 24 0x29 << 8, 0, reinterpret_cast<uint8_t*>(&hubdesc),
va009039 0:148fca6fd246 25 sizeof(HubDescriptor));
va009039 0:148fca6fd246 26 USB_TEST_ASSERT(rc == USB_TYPE_OK);
va009039 0:148fca6fd246 27 if (rc != USB_TYPE_OK) {
va009039 0:148fca6fd246 28 return false;
va009039 0:148fca6fd246 29 }
va009039 0:148fca6fd246 30 USB_DBG_HEX((uint8_t*)&hubdesc, sizeof(hubdesc));
va009039 0:148fca6fd246 31
va009039 0:148fca6fd246 32 uint32_t status;
va009039 0:148fca6fd246 33 rc = controlRead( dev,
va009039 0:148fca6fd246 34 0xa0, 0, 0, 0, reinterpret_cast<uint8_t*>(&status), 4);
va009039 0:148fca6fd246 35 USB_TEST_ASSERT(rc == USB_TYPE_OK);
va009039 0:148fca6fd246 36 if (rc != USB_TYPE_OK) {
va009039 0:148fca6fd246 37 return false;
va009039 0:148fca6fd246 38 }
va009039 0:148fca6fd246 39 USB_DBG("HUB STATUS: %08X\n", status);
va009039 0:148fca6fd246 40
va009039 0:148fca6fd246 41 for(int i = 1; i <= hubdesc.bNbrPorts; i++) {
va009039 0:148fca6fd246 42 SetPortPower(dev, i); // power on
va009039 0:148fca6fd246 43 wait_ms(hubdesc.bPwrOn2PwrGood*2);
va009039 0:148fca6fd246 44 uint32_t status;
va009039 0:148fca6fd246 45 GetPortStatus(dev, i, &status);
va009039 0:148fca6fd246 46 USB_DBG("port: %d status: %08X\n", i, status);
va009039 0:148fca6fd246 47 if (status & 0x010000) { // Connect Status Change, has changed
va009039 0:148fca6fd246 48 USB_TEST_ASSERT(status & 0x000001);
va009039 0:148fca6fd246 49 ClearPortFeature(dev, C_PORT_CONNECTION, i);
va009039 0:148fca6fd246 50 int lowSpeed = 0;
va009039 0:148fca6fd246 51 if (status & 0x0200) {
va009039 0:148fca6fd246 52 lowSpeed = 1;
va009039 0:148fca6fd246 53 }
va009039 0:148fca6fd246 54 PortReset(dev, i);
va009039 0:148fca6fd246 55 if (!addDevice(dev, i, lowSpeed)) {
va009039 0:148fca6fd246 56 ClearPortPower(dev, i); // power off
va009039 0:148fca6fd246 57 }
va009039 0:148fca6fd246 58 } else {
va009039 0:148fca6fd246 59 ClearPortPower(dev, i); // power off
va009039 0:148fca6fd246 60 }
va009039 0:148fca6fd246 61 }
va009039 0:148fca6fd246 62 return false;
va009039 0:148fca6fd246 63 }
va009039 0:148fca6fd246 64
va009039 0:148fca6fd246 65
va009039 0:148fca6fd246 66 int USBHost::SetPortPower(USBDeviceConnected* dev, int port)
va009039 0:148fca6fd246 67 {
va009039 0:148fca6fd246 68 return SetPortFeature(dev, PORT_POWER, port);
va009039 0:148fca6fd246 69 }
va009039 0:148fca6fd246 70
va009039 0:148fca6fd246 71 int USBHost::ClearPortPower(USBDeviceConnected* dev, int port)
va009039 0:148fca6fd246 72 {
va009039 0:148fca6fd246 73 return ClearPortFeature(dev, PORT_POWER, port);
va009039 0:148fca6fd246 74 }
va009039 0:148fca6fd246 75
va009039 0:148fca6fd246 76 int USBHost::SetPortFeature(USBDeviceConnected* dev, int feature, int index)
va009039 0:148fca6fd246 77 {
va009039 0:148fca6fd246 78 return controlWrite(dev, 0x23, SET_FEATURE,feature,index,0,0);
va009039 0:148fca6fd246 79 }
va009039 0:148fca6fd246 80
va009039 0:148fca6fd246 81 int USBHost::ClearPortFeature(USBDeviceConnected* dev, int feature, int index)
va009039 0:148fca6fd246 82 {
va009039 0:148fca6fd246 83 return controlWrite(dev, 0x23, CLEAR_FEATURE,feature,index,0,0);
va009039 0:148fca6fd246 84 }
va009039 0:148fca6fd246 85
va009039 0:148fca6fd246 86 int USBHost::SetPortReset(USBDeviceConnected* dev, int port)
va009039 0:148fca6fd246 87 {
va009039 0:148fca6fd246 88 return SetPortFeature(dev, PORT_RESET, port);
va009039 0:148fca6fd246 89 }
va009039 0:148fca6fd246 90
va009039 0:148fca6fd246 91 int USBHost::GetPortStatus(USBDeviceConnected* dev, int port, uint32_t* status)
va009039 0:148fca6fd246 92 {
va009039 0:148fca6fd246 93 return controlRead(dev, 0xa3, GET_STATUS, 0, port, (uint8_t*)status, 4);
va009039 0:148fca6fd246 94 }
va009039 0:148fca6fd246 95
va009039 0:148fca6fd246 96 int USBHost::PortReset(USBDeviceConnected* dev, int port)
va009039 0:148fca6fd246 97 {
va009039 0:148fca6fd246 98 USB_DBG("%p port=%d\n", this, port);
va009039 0:148fca6fd246 99 USB_TEST_ASSERT(port >= 1);
va009039 0:148fca6fd246 100 SetPortReset(dev, port);
va009039 0:148fca6fd246 101 // wait reset
va009039 0:148fca6fd246 102 for(int i = 0; i < 100; i++) {
va009039 0:148fca6fd246 103 uint32_t status;
va009039 0:148fca6fd246 104 GetPortStatus(dev, port, &status);
va009039 0:148fca6fd246 105 USB_DBG("RESET port: %d status: %08X\n", port, status);
va009039 0:148fca6fd246 106 if (status & 0x100000) { // Reset change , Reset complete
va009039 0:148fca6fd246 107 return USB_TYPE_OK;
va009039 0:148fca6fd246 108 }
va009039 0:148fca6fd246 109 wait_ms(5);
va009039 0:148fca6fd246 110 }
va009039 0:148fca6fd246 111 return USB_TYPE_ERROR;
va009039 0:148fca6fd246 112 }