Simple USBHost MSD(USB flash drive) for EA LPC4088 QSB test program

Dependencies:   LPC4088-USBHost mbed

EA LPC4088をUSBホストにしてUSBフラッシュメモリ(USB flash drive)を読み書きするテストプログラムです。
/media/uploads/va009039/lpc4088-msd-1.jpg
/media/uploads/va009039/lpc4088-msd-2.png

https://bitbucket.org/va009039/lpc4088_usbhost

Committer:
va009039
Date:
Tue Apr 22 10:54:52 2014 +0000
Revision:
0:11152e69fc05
first commit,sync rev.25.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 0:11152e69fc05 1 /* mbed USBHost Library
va009039 0:11152e69fc05 2 * Copyright (c) 2006-2013 ARM Limited
va009039 0:11152e69fc05 3 *
va009039 0:11152e69fc05 4 * Licensed under the Apache License, Version 2.0 (the "License");
va009039 0:11152e69fc05 5 * you may not use this file except in compliance with the License.
va009039 0:11152e69fc05 6 * You may obtain a copy of the License at
va009039 0:11152e69fc05 7 *
va009039 0:11152e69fc05 8 * http://www.apache.org/licenses/LICENSE-2.0
va009039 0:11152e69fc05 9 *
va009039 0:11152e69fc05 10 * Unless required by applicable law or agreed to in writing, software
va009039 0:11152e69fc05 11 * distributed under the License is distributed on an "AS IS" BASIS,
va009039 0:11152e69fc05 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
va009039 0:11152e69fc05 13 * See the License for the specific language governing permissions and
va009039 0:11152e69fc05 14 * limitations under the License.
va009039 0:11152e69fc05 15 */
va009039 0:11152e69fc05 16
va009039 0:11152e69fc05 17 #include "USBDeviceConnected.h"
va009039 0:11152e69fc05 18 #include "dbg.h"
va009039 0:11152e69fc05 19
va009039 0:11152e69fc05 20 USBDeviceConnected::USBDeviceConnected() {
va009039 0:11152e69fc05 21 init();
va009039 0:11152e69fc05 22 }
va009039 0:11152e69fc05 23
va009039 0:11152e69fc05 24 void USBDeviceConnected::init() {
va009039 0:11152e69fc05 25 port = 0;
va009039 0:11152e69fc05 26 vid = 0;
va009039 0:11152e69fc05 27 pid = 0;
va009039 0:11152e69fc05 28 nb_interf = 0;
va009039 0:11152e69fc05 29 enumerated = false;
va009039 0:11152e69fc05 30 device_class = 0;
va009039 0:11152e69fc05 31 device_subclass = 0;
va009039 0:11152e69fc05 32 proto = 0;
va009039 0:11152e69fc05 33 lowSpeed = false;
va009039 0:11152e69fc05 34 hub_parent = NULL;
va009039 0:11152e69fc05 35 }
va009039 0:11152e69fc05 36
va009039 0:11152e69fc05 37 bool USBDeviceConnected::addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) {
va009039 0:11152e69fc05 38 USB_DBG("intf_nb=%d", intf_nb);
va009039 0:11152e69fc05 39 if (intf.count(intf_nb) > 0) {
va009039 0:11152e69fc05 40 return false;
va009039 0:11152e69fc05 41 }
va009039 0:11152e69fc05 42 intf[intf_nb] = new INTERFACE(intf_class, intf_subclass, intf_protocol);
va009039 0:11152e69fc05 43 return true;
va009039 0:11152e69fc05 44 }
va009039 0:11152e69fc05 45
va009039 0:11152e69fc05 46 bool USBDeviceConnected::addEndpoint(uint8_t intf_nb, USBEndpoint * ept) {
va009039 0:11152e69fc05 47 if (intf.count(intf_nb) > 0) {
va009039 0:11152e69fc05 48 intf[intf_nb]->ep.push_back(ept);
va009039 0:11152e69fc05 49 return true;
va009039 0:11152e69fc05 50 }
va009039 0:11152e69fc05 51 return false;
va009039 0:11152e69fc05 52 }
va009039 0:11152e69fc05 53
va009039 0:11152e69fc05 54 void USBDeviceConnected::init(USBDeviceConnected* parent, uint8_t port_, bool lowSpeed_) {
va009039 0:11152e69fc05 55 USB_DBG("init dev: %p", this);
va009039 0:11152e69fc05 56 init();
va009039 0:11152e69fc05 57 hub_parent = parent;
va009039 0:11152e69fc05 58 port = port_;
va009039 0:11152e69fc05 59 lowSpeed = lowSpeed_;
va009039 0:11152e69fc05 60 }
va009039 0:11152e69fc05 61
va009039 0:11152e69fc05 62 void USBDeviceConnected::disconnect() {
va009039 0:11152e69fc05 63 //for(int i = 0; i < MAX_INTF; i++) {
va009039 0:11152e69fc05 64 // intf[i].detach.call();
va009039 0:11152e69fc05 65 //}
va009039 0:11152e69fc05 66 //init();
va009039 0:11152e69fc05 67 }
va009039 0:11152e69fc05 68
va009039 0:11152e69fc05 69
va009039 0:11152e69fc05 70 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index) {
va009039 0:11152e69fc05 71 USB_DBG("intf_nb=%d", intf_nb);
va009039 0:11152e69fc05 72 USB_TEST_ASSERT(intf.count(intf_nb) > 0);
va009039 0:11152e69fc05 73 INTERFACE* inter = intf[intf_nb];
va009039 0:11152e69fc05 74 for (int i = 0; i < inter->ep.size(); i++) {
va009039 0:11152e69fc05 75 if ((inter->ep[i]->getType() == type) && (inter->ep[i]->getDir() == dir)) {
va009039 0:11152e69fc05 76 if(index) {
va009039 0:11152e69fc05 77 index--;
va009039 0:11152e69fc05 78 } else {
va009039 0:11152e69fc05 79 return inter->ep[i];
va009039 0:11152e69fc05 80 }
va009039 0:11152e69fc05 81 }
va009039 0:11152e69fc05 82 }
va009039 0:11152e69fc05 83 return NULL;
va009039 0:11152e69fc05 84 }
va009039 0:11152e69fc05 85
va009039 0:11152e69fc05 86 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, uint8_t index) {
va009039 0:11152e69fc05 87 USB_TEST_ASSERT(intf.count(intf_nb) > 0);
va009039 0:11152e69fc05 88 return intf[intf_nb]->ep[index];
va009039 0:11152e69fc05 89 }