only for STM32F769NI-DISCOVERY, porting from mbed OS5 unsupport functions
USBHost/USBDeviceConnected.cpp@0:dae1ac0c0a7b, 2019-08-07 (annotated)
- Committer:
- kenjiArai
- Date:
- Wed Aug 07 05:33:53 2019 +0000
- Revision:
- 0:dae1ac0c0a7b
only for STM32F769NI-DISCOVERY, porting from mbed OS5 unsupport functions
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 0:dae1ac0c0a7b | 1 | /* mbed USBHost Library |
kenjiArai | 0:dae1ac0c0a7b | 2 | * Copyright (c) 2006-2013 ARM Limited |
kenjiArai | 0:dae1ac0c0a7b | 3 | * |
kenjiArai | 0:dae1ac0c0a7b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kenjiArai | 0:dae1ac0c0a7b | 5 | * you may not use this file except in compliance with the License. |
kenjiArai | 0:dae1ac0c0a7b | 6 | * You may obtain a copy of the License at |
kenjiArai | 0:dae1ac0c0a7b | 7 | * |
kenjiArai | 0:dae1ac0c0a7b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kenjiArai | 0:dae1ac0c0a7b | 9 | * |
kenjiArai | 0:dae1ac0c0a7b | 10 | * Unless required by applicable law or agreed to in writing, software |
kenjiArai | 0:dae1ac0c0a7b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kenjiArai | 0:dae1ac0c0a7b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kenjiArai | 0:dae1ac0c0a7b | 13 | * See the License for the specific language governing permissions and |
kenjiArai | 0:dae1ac0c0a7b | 14 | * limitations under the License. |
kenjiArai | 0:dae1ac0c0a7b | 15 | */ |
kenjiArai | 0:dae1ac0c0a7b | 16 | |
kenjiArai | 0:dae1ac0c0a7b | 17 | #include "USBDeviceConnected.h" |
kenjiArai | 0:dae1ac0c0a7b | 18 | #include "dbg.h" |
kenjiArai | 0:dae1ac0c0a7b | 19 | |
kenjiArai | 0:dae1ac0c0a7b | 20 | USBDeviceConnected::USBDeviceConnected() { |
kenjiArai | 0:dae1ac0c0a7b | 21 | init(); |
kenjiArai | 0:dae1ac0c0a7b | 22 | } |
kenjiArai | 0:dae1ac0c0a7b | 23 | |
kenjiArai | 0:dae1ac0c0a7b | 24 | void USBDeviceConnected::init() { |
kenjiArai | 0:dae1ac0c0a7b | 25 | hub_nb = 0; |
kenjiArai | 0:dae1ac0c0a7b | 26 | port = 0; |
kenjiArai | 0:dae1ac0c0a7b | 27 | vid = 0; |
kenjiArai | 0:dae1ac0c0a7b | 28 | pid = 0; |
kenjiArai | 0:dae1ac0c0a7b | 29 | nb_interf = 0; |
kenjiArai | 0:dae1ac0c0a7b | 30 | enumerated = false; |
kenjiArai | 0:dae1ac0c0a7b | 31 | activeAddr = false; |
kenjiArai | 0:dae1ac0c0a7b | 32 | sizeControlEndpoint = 8; |
kenjiArai | 0:dae1ac0c0a7b | 33 | device_class = 0; |
kenjiArai | 0:dae1ac0c0a7b | 34 | device_subclass = 0; |
kenjiArai | 0:dae1ac0c0a7b | 35 | proto = 0; |
kenjiArai | 0:dae1ac0c0a7b | 36 | speed = false; |
kenjiArai | 0:dae1ac0c0a7b | 37 | for (int i = 0; i < MAX_INTF; i++) { |
kenjiArai | 0:dae1ac0c0a7b | 38 | memset((void *)&intf[i], 0, sizeof(INTERFACE)); |
kenjiArai | 0:dae1ac0c0a7b | 39 | intf[i].in_use = false; |
kenjiArai | 0:dae1ac0c0a7b | 40 | for (int j = 0; j < MAX_ENDPOINT_PER_INTERFACE; j++) { |
kenjiArai | 0:dae1ac0c0a7b | 41 | intf[i].ep[j] = NULL; |
kenjiArai | 0:dae1ac0c0a7b | 42 | strcpy(intf[i].name, "Unknown"); |
kenjiArai | 0:dae1ac0c0a7b | 43 | } |
kenjiArai | 0:dae1ac0c0a7b | 44 | } |
kenjiArai | 0:dae1ac0c0a7b | 45 | hub_parent = NULL; |
kenjiArai | 0:dae1ac0c0a7b | 46 | hub = NULL; |
kenjiArai | 0:dae1ac0c0a7b | 47 | nb_interf = 0; |
kenjiArai | 0:dae1ac0c0a7b | 48 | } |
kenjiArai | 0:dae1ac0c0a7b | 49 | |
kenjiArai | 0:dae1ac0c0a7b | 50 | INTERFACE * USBDeviceConnected::getInterface(uint8_t index) { |
kenjiArai | 0:dae1ac0c0a7b | 51 | if (index >= MAX_INTF) |
kenjiArai | 0:dae1ac0c0a7b | 52 | return NULL; |
kenjiArai | 0:dae1ac0c0a7b | 53 | |
kenjiArai | 0:dae1ac0c0a7b | 54 | if (intf[index].in_use) |
kenjiArai | 0:dae1ac0c0a7b | 55 | return &intf[index]; |
kenjiArai | 0:dae1ac0c0a7b | 56 | |
kenjiArai | 0:dae1ac0c0a7b | 57 | return NULL; |
kenjiArai | 0:dae1ac0c0a7b | 58 | } |
kenjiArai | 0:dae1ac0c0a7b | 59 | |
kenjiArai | 0:dae1ac0c0a7b | 60 | bool USBDeviceConnected::addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) { |
kenjiArai | 0:dae1ac0c0a7b | 61 | if ((intf_nb >= MAX_INTF) || (intf[intf_nb].in_use)) { |
kenjiArai | 0:dae1ac0c0a7b | 62 | return false; |
kenjiArai | 0:dae1ac0c0a7b | 63 | } |
kenjiArai | 0:dae1ac0c0a7b | 64 | intf[intf_nb].in_use = true; |
kenjiArai | 0:dae1ac0c0a7b | 65 | intf[intf_nb].intf_class = intf_class; |
kenjiArai | 0:dae1ac0c0a7b | 66 | intf[intf_nb].intf_subclass = intf_subclass; |
kenjiArai | 0:dae1ac0c0a7b | 67 | intf[intf_nb].intf_protocol = intf_protocol; |
kenjiArai | 0:dae1ac0c0a7b | 68 | intf[intf_nb].nb_endpoint = 0; |
kenjiArai | 0:dae1ac0c0a7b | 69 | return true; |
kenjiArai | 0:dae1ac0c0a7b | 70 | } |
kenjiArai | 0:dae1ac0c0a7b | 71 | |
kenjiArai | 0:dae1ac0c0a7b | 72 | bool USBDeviceConnected::addEndpoint(uint8_t intf_nb, USBEndpoint * ept) { |
kenjiArai | 0:dae1ac0c0a7b | 73 | if ((intf_nb >= MAX_INTF) || (intf[intf_nb].in_use == false) || (intf[intf_nb].nb_endpoint >= MAX_ENDPOINT_PER_INTERFACE)) { |
kenjiArai | 0:dae1ac0c0a7b | 74 | return false; |
kenjiArai | 0:dae1ac0c0a7b | 75 | } |
kenjiArai | 0:dae1ac0c0a7b | 76 | intf[intf_nb].nb_endpoint++; |
kenjiArai | 0:dae1ac0c0a7b | 77 | |
kenjiArai | 0:dae1ac0c0a7b | 78 | for (int i = 0; i < MAX_ENDPOINT_PER_INTERFACE; i++) { |
kenjiArai | 0:dae1ac0c0a7b | 79 | if (intf[intf_nb].ep[i] == NULL) { |
kenjiArai | 0:dae1ac0c0a7b | 80 | intf[intf_nb].ep[i] = ept; |
kenjiArai | 0:dae1ac0c0a7b | 81 | return true; |
kenjiArai | 0:dae1ac0c0a7b | 82 | } |
kenjiArai | 0:dae1ac0c0a7b | 83 | } |
kenjiArai | 0:dae1ac0c0a7b | 84 | return false; |
kenjiArai | 0:dae1ac0c0a7b | 85 | } |
kenjiArai | 0:dae1ac0c0a7b | 86 | |
kenjiArai | 0:dae1ac0c0a7b | 87 | void USBDeviceConnected::init(uint8_t hub_, uint8_t port_, bool lowSpeed_) { |
kenjiArai | 0:dae1ac0c0a7b | 88 | USB_DBG("init dev: %p", this); |
kenjiArai | 0:dae1ac0c0a7b | 89 | init(); |
kenjiArai | 0:dae1ac0c0a7b | 90 | hub_nb = hub_; |
kenjiArai | 0:dae1ac0c0a7b | 91 | port = port_; |
kenjiArai | 0:dae1ac0c0a7b | 92 | speed = lowSpeed_; |
kenjiArai | 0:dae1ac0c0a7b | 93 | } |
kenjiArai | 0:dae1ac0c0a7b | 94 | |
kenjiArai | 0:dae1ac0c0a7b | 95 | void USBDeviceConnected::disconnect() { |
kenjiArai | 0:dae1ac0c0a7b | 96 | for(int i = 0; i < MAX_INTF; i++) { |
kenjiArai | 0:dae1ac0c0a7b | 97 | if (intf[i].detach) intf[i].detach.call(); |
kenjiArai | 0:dae1ac0c0a7b | 98 | } |
kenjiArai | 0:dae1ac0c0a7b | 99 | init(); |
kenjiArai | 0:dae1ac0c0a7b | 100 | } |
kenjiArai | 0:dae1ac0c0a7b | 101 | |
kenjiArai | 0:dae1ac0c0a7b | 102 | |
kenjiArai | 0:dae1ac0c0a7b | 103 | USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index) { |
kenjiArai | 0:dae1ac0c0a7b | 104 | if (intf_nb >= MAX_INTF) { |
kenjiArai | 0:dae1ac0c0a7b | 105 | return NULL; |
kenjiArai | 0:dae1ac0c0a7b | 106 | } |
kenjiArai | 0:dae1ac0c0a7b | 107 | for (int i = 0; i < MAX_ENDPOINT_PER_INTERFACE; i++) { |
kenjiArai | 0:dae1ac0c0a7b | 108 | if ((intf[intf_nb].ep[i]->getType() == type) && (intf[intf_nb].ep[i]->getDir() == dir)) { |
kenjiArai | 0:dae1ac0c0a7b | 109 | if(index) { |
kenjiArai | 0:dae1ac0c0a7b | 110 | index--; |
kenjiArai | 0:dae1ac0c0a7b | 111 | } else { |
kenjiArai | 0:dae1ac0c0a7b | 112 | return intf[intf_nb].ep[i]; |
kenjiArai | 0:dae1ac0c0a7b | 113 | } |
kenjiArai | 0:dae1ac0c0a7b | 114 | } |
kenjiArai | 0:dae1ac0c0a7b | 115 | } |
kenjiArai | 0:dae1ac0c0a7b | 116 | return NULL; |
kenjiArai | 0:dae1ac0c0a7b | 117 | } |
kenjiArai | 0:dae1ac0c0a7b | 118 | |
kenjiArai | 0:dae1ac0c0a7b | 119 | USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, uint8_t index) { |
kenjiArai | 0:dae1ac0c0a7b | 120 | if ((intf_nb >= MAX_INTF) || (index >= MAX_ENDPOINT_PER_INTERFACE)) { |
kenjiArai | 0:dae1ac0c0a7b | 121 | return NULL; |
kenjiArai | 0:dae1ac0c0a7b | 122 | } |
kenjiArai | 0:dae1ac0c0a7b | 123 | return intf[intf_nb].ep[index]; |
kenjiArai | 0:dae1ac0c0a7b | 124 | } |