final

Dependencies:   mbed FATFileSystem

Fork of KL46Z-USBHostMSD_HelloWorld by Norimasa Okamoto

Committer:
homzovam
Date:
Sat Apr 04 20:16:39 2015 +0000
Revision:
4:77d6450f34d7
prijimac-funkcni final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
homzovam 4:77d6450f34d7 1 /* mbed USBHost Library
homzovam 4:77d6450f34d7 2 * Copyright (c) 2006-2013 ARM Limited
homzovam 4:77d6450f34d7 3 *
homzovam 4:77d6450f34d7 4 * Licensed under the Apache License, Version 2.0 (the "License");
homzovam 4:77d6450f34d7 5 * you may not use this file except in compliance with the License.
homzovam 4:77d6450f34d7 6 * You may obtain a copy of the License at
homzovam 4:77d6450f34d7 7 *
homzovam 4:77d6450f34d7 8 * http://www.apache.org/licenses/LICENSE-2.0
homzovam 4:77d6450f34d7 9 *
homzovam 4:77d6450f34d7 10 * Unless required by applicable law or agreed to in writing, software
homzovam 4:77d6450f34d7 11 * distributed under the License is distributed on an "AS IS" BASIS,
homzovam 4:77d6450f34d7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
homzovam 4:77d6450f34d7 13 * See the License for the specific language governing permissions and
homzovam 4:77d6450f34d7 14 * limitations under the License.
homzovam 4:77d6450f34d7 15 */
homzovam 4:77d6450f34d7 16 #pragma once
homzovam 4:77d6450f34d7 17
homzovam 4:77d6450f34d7 18 #include "USBEndpoint.h"
homzovam 4:77d6450f34d7 19 #include "USBHostConf.h"
homzovam 4:77d6450f34d7 20 #include "myvector.h"
homzovam 4:77d6450f34d7 21 #include "mymap.h"
homzovam 4:77d6450f34d7 22
homzovam 4:77d6450f34d7 23 class USBEndpoint;
homzovam 4:77d6450f34d7 24
homzovam 4:77d6450f34d7 25 struct INTERFACE {
homzovam 4:77d6450f34d7 26 INTERFACE(uint8_t _class, uint8_t _subclass, uint8_t _protocol) {
homzovam 4:77d6450f34d7 27 intf_class = _class;
homzovam 4:77d6450f34d7 28 intf_subclass = _subclass;
homzovam 4:77d6450f34d7 29 intf_protocol = _protocol;
homzovam 4:77d6450f34d7 30 }
homzovam 4:77d6450f34d7 31 uint8_t intf_class;
homzovam 4:77d6450f34d7 32 uint8_t intf_subclass;
homzovam 4:77d6450f34d7 33 uint8_t intf_protocol;
homzovam 4:77d6450f34d7 34 myvector<USBEndpoint*>ep;
homzovam 4:77d6450f34d7 35 };
homzovam 4:77d6450f34d7 36
homzovam 4:77d6450f34d7 37 /**
homzovam 4:77d6450f34d7 38 * USBDeviceConnected class
homzovam 4:77d6450f34d7 39 */
homzovam 4:77d6450f34d7 40 class USBDeviceConnected {
homzovam 4:77d6450f34d7 41 public:
homzovam 4:77d6450f34d7 42
homzovam 4:77d6450f34d7 43 /**
homzovam 4:77d6450f34d7 44 * Constructor
homzovam 4:77d6450f34d7 45 */
homzovam 4:77d6450f34d7 46 USBDeviceConnected();
homzovam 4:77d6450f34d7 47
homzovam 4:77d6450f34d7 48 /**
homzovam 4:77d6450f34d7 49 * Attach an USBEndpoint to this device
homzovam 4:77d6450f34d7 50 *
homzovam 4:77d6450f34d7 51 * @param intf_nb interface number
homzovam 4:77d6450f34d7 52 * @param ep pointeur on the USBEndpoint which will be attached
homzovam 4:77d6450f34d7 53 * @returns true if successful, false otherwise
homzovam 4:77d6450f34d7 54 */
homzovam 4:77d6450f34d7 55 bool addEndpoint(uint8_t intf_nb, USBEndpoint * ep);
homzovam 4:77d6450f34d7 56
homzovam 4:77d6450f34d7 57 /**
homzovam 4:77d6450f34d7 58 * Retrieve an USBEndpoint by its TYPE and DIRECTION
homzovam 4:77d6450f34d7 59 *
homzovam 4:77d6450f34d7 60 * @param intf_nb the interface on which to lookup the USBEndpoint
homzovam 4:77d6450f34d7 61 * @param type type of the USBEndpoint looked for
homzovam 4:77d6450f34d7 62 * @param dir direction of the USBEndpoint looked for
homzovam 4:77d6450f34d7 63 * @param index the index of the USBEndpoint whitin the interface
homzovam 4:77d6450f34d7 64 * @returns pointer on the USBEndpoint if found, NULL otherwise
homzovam 4:77d6450f34d7 65 */
homzovam 4:77d6450f34d7 66 USBEndpoint * getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index = 0);
homzovam 4:77d6450f34d7 67
homzovam 4:77d6450f34d7 68 /**
homzovam 4:77d6450f34d7 69 * Retrieve an USBEndpoint by its index
homzovam 4:77d6450f34d7 70 *
homzovam 4:77d6450f34d7 71 * @param intf_nb interface number
homzovam 4:77d6450f34d7 72 * @param index index of the USBEndpoint
homzovam 4:77d6450f34d7 73 * @returns pointer on the USBEndpoint if found, NULL otherwise
homzovam 4:77d6450f34d7 74 */
homzovam 4:77d6450f34d7 75 USBEndpoint * getEndpoint(uint8_t intf_nb, uint8_t index);
homzovam 4:77d6450f34d7 76
homzovam 4:77d6450f34d7 77 /**
homzovam 4:77d6450f34d7 78 * Add a new interface to this device
homzovam 4:77d6450f34d7 79 *
homzovam 4:77d6450f34d7 80 * @param intf_nb interface number
homzovam 4:77d6450f34d7 81 * @param intf_class interface class
homzovam 4:77d6450f34d7 82 * @param intf_subclass interface subclass
homzovam 4:77d6450f34d7 83 * @param intf_protocol interface protocol
homzovam 4:77d6450f34d7 84 * @returns true if successful, false otherwise
homzovam 4:77d6450f34d7 85 */
homzovam 4:77d6450f34d7 86 bool addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol);
homzovam 4:77d6450f34d7 87
homzovam 4:77d6450f34d7 88 /**
homzovam 4:77d6450f34d7 89 * Disconnect the device by calling a callback function registered by a driver
homzovam 4:77d6450f34d7 90 */
homzovam 4:77d6450f34d7 91 void disconnect();
homzovam 4:77d6450f34d7 92
homzovam 4:77d6450f34d7 93 void init(USBDeviceConnected* parent, uint8_t _port, bool _lowSpeed);
homzovam 4:77d6450f34d7 94 void setAddress(uint8_t addr_) { addr = addr_; };
homzovam 4:77d6450f34d7 95 void setVid(uint16_t vid_) { vid = vid_; };
homzovam 4:77d6450f34d7 96 void setPid(uint16_t pid_) { pid = pid_; };
homzovam 4:77d6450f34d7 97 void setClass(uint8_t device_class_) { device_class = device_class_; }
homzovam 4:77d6450f34d7 98 void setSubClass(uint8_t device_subclass_) { device_subclass = device_subclass_; };
homzovam 4:77d6450f34d7 99 void setProtocol(uint8_t pr) { proto = pr; };
homzovam 4:77d6450f34d7 100 void setEnumerated() { enumerated = true; };
homzovam 4:77d6450f34d7 101 void setNbIntf(uint8_t nb_intf) {nb_interf = nb_intf; };
homzovam 4:77d6450f34d7 102 void setSpeed(bool _lowSpeed) { lowSpeed = _lowSpeed; }
homzovam 4:77d6450f34d7 103 void setName(const char * name_, uint8_t intf_nb) { return; };
homzovam 4:77d6450f34d7 104 void setEpCtl(USBEndpoint* ep) { ep_ctl = ep; }
homzovam 4:77d6450f34d7 105
homzovam 4:77d6450f34d7 106 static int getNewAddress() {
homzovam 4:77d6450f34d7 107 static int addr = 1;
homzovam 4:77d6450f34d7 108 return addr++;
homzovam 4:77d6450f34d7 109 }
homzovam 4:77d6450f34d7 110 uint8_t getAddress() { return addr; };
homzovam 4:77d6450f34d7 111 uint16_t getVid() { return vid; };
homzovam 4:77d6450f34d7 112 uint16_t getPid() { return pid; };
homzovam 4:77d6450f34d7 113 uint8_t getClass() { return device_class; };
homzovam 4:77d6450f34d7 114 bool getSpeed() { return lowSpeed; }
homzovam 4:77d6450f34d7 115 bool isEnumerated() { return enumerated; };
homzovam 4:77d6450f34d7 116 USBEndpoint* getEpCtl() { return ep_ctl; }
homzovam 4:77d6450f34d7 117
homzovam 4:77d6450f34d7 118 private:
homzovam 4:77d6450f34d7 119 USBDeviceConnected* hub_parent;
homzovam 4:77d6450f34d7 120 mymap<int,INTERFACE*>intf;
homzovam 4:77d6450f34d7 121 uint8_t port;
homzovam 4:77d6450f34d7 122 uint16_t vid;
homzovam 4:77d6450f34d7 123 uint16_t pid;
homzovam 4:77d6450f34d7 124 uint8_t addr;
homzovam 4:77d6450f34d7 125 uint8_t device_class;
homzovam 4:77d6450f34d7 126 uint8_t device_subclass;
homzovam 4:77d6450f34d7 127 uint8_t proto;
homzovam 4:77d6450f34d7 128 bool lowSpeed;
homzovam 4:77d6450f34d7 129 bool enumerated;
homzovam 4:77d6450f34d7 130 uint8_t nb_interf;
homzovam 4:77d6450f34d7 131 USBEndpoint* ep_ctl;
homzovam 4:77d6450f34d7 132 void init();
homzovam 4:77d6450f34d7 133 };