1 /* mbed USBHost Library
2 * Copyright (c) 2006-2013 ARM Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "USBDeviceConnected.h"
20 USBDeviceConnected::USBDeviceConnected() {
24 void USBDeviceConnected::init() {
32 sizeControlEndpoint
= 8;
37 for (int i
= 0; i
< MAX_INTF
; i
++) {
38 memset((void *)&intf
[i
], 0, sizeof(INTERFACE
));
39 intf
[i
].in_use
= false;
40 for (int j
= 0; j
< MAX_ENDPOINT_PER_INTERFACE
; j
++) {
42 strcpy(intf
[i
].name
, "Unknown");
50 INTERFACE
* USBDeviceConnected::getInterface(uint8_t index
) {
51 if (index
>= MAX_INTF
)
54 if (intf
[index
].in_use
)
60 bool USBDeviceConnected::addInterface(uint8_t intf_nb
, uint8_t intf_class
, uint8_t intf_subclass
, uint8_t intf_protocol
) {
61 if ((intf_nb
>= MAX_INTF
) || (intf
[intf_nb
].in_use
)) {
64 intf
[intf_nb
].in_use
= true;
65 intf
[intf_nb
].intf_class
= intf_class
;
66 intf
[intf_nb
].intf_subclass
= intf_subclass
;
67 intf
[intf_nb
].intf_protocol
= intf_protocol
;
68 intf
[intf_nb
].nb_endpoint
= 0;
72 bool USBDeviceConnected::addEndpoint(uint8_t intf_nb
, USBEndpoint
* ept
) {
73 if ((intf_nb
>= MAX_INTF
) || (intf
[intf_nb
].in_use
== false) || (intf
[intf_nb
].nb_endpoint
>= MAX_ENDPOINT_PER_INTERFACE
)) {
76 intf
[intf_nb
].nb_endpoint
++;
78 for (int i
= 0; i
< MAX_ENDPOINT_PER_INTERFACE
; i
++) {
79 if (intf
[intf_nb
].ep
[i
] == NULL
) {
80 intf
[intf_nb
].ep
[i
] = ept
;
87 void USBDeviceConnected::init(uint8_t hub_
, uint8_t port_
, bool lowSpeed_
) {
88 USB_DBG("init dev: %p", this);
95 void USBDeviceConnected::disconnect() {
96 for(int i
= 0; i
< MAX_INTF
; i
++) {
97 intf
[i
].detach
.call();
103 USBEndpoint
* USBDeviceConnected::getEndpoint(uint8_t intf_nb
, ENDPOINT_TYPE type
, ENDPOINT_DIRECTION dir
, uint8_t index
) {
104 if (intf_nb
>= MAX_INTF
) {
107 for (int i
= 0; i
< MAX_ENDPOINT_PER_INTERFACE
; i
++) {
108 if ((intf
[intf_nb
].ep
[i
]->getType() == type
) && (intf
[intf_nb
].ep
[i
]->getDir() == dir
)) {
112 return intf
[intf_nb
].ep
[i
];
119 USBEndpoint
* USBDeviceConnected::getEndpoint(uint8_t intf_nb
, uint8_t index
) {
120 if ((intf_nb
>= MAX_INTF
) || (index
>= MAX_ENDPOINT_PER_INTERFACE
)) {
123 return intf
[intf_nb
].ep
[index
];