Simple USBHost library for Nucleo F446RE/F411RE/F401RE FRDM-KL46Z/KL25Z/F64F LPC4088/LPC1768

Dependencies:   FATFileSystem

Dependents:   F401RE-BTstack_example F401RE-USBHostMSD_HelloWorld

Fork of KL46Z-USBHost by Norimasa Okamoto

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBDeviceConnected.h Source File

USBDeviceConnected.h

00001 /* mbed USBHost Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #pragma once
00017 
00018 #include "USBEndpoint.h"
00019 #include "USBHostConf.h"
00020 #include "myvector.h"
00021 #include "mymap.h"
00022 
00023 class USBEndpoint;
00024 
00025 struct INTERFACE {
00026     INTERFACE(uint8_t _class, uint8_t _subclass, uint8_t _protocol) {
00027         intf_class = _class;
00028         intf_subclass = _subclass;
00029         intf_protocol = _protocol;
00030     }
00031     uint8_t intf_class;
00032     uint8_t intf_subclass;
00033     uint8_t intf_protocol;
00034     myvector<USBEndpoint*>ep; 
00035 }; 
00036 
00037 /**
00038 * USBDeviceConnected class
00039 */
00040 class USBDeviceConnected {
00041 public:
00042 
00043     /**
00044     * Constructor
00045     */
00046     USBDeviceConnected();
00047 
00048     /**
00049     * Attach an USBEndpoint to this device
00050     *
00051     * @param intf_nb interface number
00052     * @param ep pointeur on the USBEndpoint which will be attached
00053     * @returns true if successful, false otherwise
00054     */
00055     bool addEndpoint(uint8_t intf_nb, USBEndpoint * ep);
00056 
00057     /**
00058     * Retrieve an USBEndpoint by its TYPE and DIRECTION
00059     *
00060     * @param intf_nb the interface on which to lookup the USBEndpoint
00061     * @param type type of the USBEndpoint looked for
00062     * @param dir direction of the USBEndpoint looked for
00063     * @param index the index of the USBEndpoint whitin the interface
00064     * @returns pointer on the USBEndpoint if found, NULL otherwise
00065     */
00066     USBEndpoint * getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index = 0);
00067 
00068     /**
00069     * Retrieve an USBEndpoint by its index
00070     *
00071     * @param intf_nb interface number
00072     * @param index index of the USBEndpoint
00073     * @returns pointer on the USBEndpoint if found, NULL otherwise
00074     */
00075     USBEndpoint * getEndpoint(uint8_t intf_nb, uint8_t index);
00076 
00077     /**
00078     * Add a new interface to this device
00079     *
00080     * @param intf_nb interface number
00081     * @param intf_class interface class
00082     * @param intf_subclass interface subclass
00083     * @param intf_protocol interface protocol
00084     * @returns true if successful, false otherwise
00085     */
00086     bool addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol);
00087 
00088     /**
00089     * Disconnect the device by calling a callback function registered by a driver
00090     */
00091     void disconnect();
00092 
00093     void init(USBDeviceConnected* parent, uint8_t _port, bool _lowSpeed);
00094     void setAddress(uint8_t addr_) { addr = addr_; };
00095     void setVid(uint16_t vid_) { vid = vid_; };
00096     void setPid(uint16_t pid_) { pid = pid_; };
00097     void setClass(uint8_t device_class_) { device_class = device_class_; }
00098     void setSubClass(uint8_t device_subclass_) { device_subclass = device_subclass_; };
00099     void setProtocol(uint8_t pr) { proto = pr; };
00100     void setEnumerated() { enumerated = true; };
00101     void setNbIntf(uint8_t nb_intf) {nb_interf = nb_intf; };
00102     void setSpeed(bool _lowSpeed) { lowSpeed = _lowSpeed; }
00103     void setName(const char * name_, uint8_t intf_nb) { return; };
00104     void setEpCtl(USBEndpoint* ep) { ep_ctl = ep; }
00105 
00106     static int getNewAddress() {
00107         static int addr = 1;
00108         return addr++;
00109     }
00110     uint8_t getAddress() { return addr; };
00111     uint16_t getVid() { return vid; };
00112     uint16_t getPid() { return pid; };
00113     uint8_t getClass() { return device_class; };
00114     bool getSpeed() { return lowSpeed; }
00115     bool isEnumerated() { return enumerated; };
00116     USBEndpoint* getEpCtl() { return ep_ctl; }
00117 
00118 private:
00119     USBDeviceConnected* hub_parent;
00120     mymap<int,INTERFACE*>intf;
00121     uint8_t port;
00122     uint16_t vid;
00123     uint16_t pid;
00124     uint8_t addr;
00125     uint8_t device_class;
00126     uint8_t device_subclass;
00127     uint8_t proto;
00128     bool lowSpeed;
00129     bool enumerated;
00130     uint8_t nb_interf;
00131     USBEndpoint* ep_ctl;
00132     void init();
00133 };