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