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