USBHost library with fixes

Dependencies:   mbed-rtos FATFileSystem

Dependents:   mbedica

Committer:
zrussell3
Date:
Thu Dec 13 19:24:21 2018 +0000
Revision:
0:b176d95bb38f
Modified USBHost library to fix modifier input

Who changed what in which revision?

UserRevisionLine numberNew contents of line
zrussell3 0:b176d95bb38f 1 /* mbed USBHost Library
zrussell3 0:b176d95bb38f 2 * Copyright (c) 2006-2013 ARM Limited
zrussell3 0:b176d95bb38f 3 *
zrussell3 0:b176d95bb38f 4 * Licensed under the Apache License, Version 2.0 (the "License");
zrussell3 0:b176d95bb38f 5 * you may not use this file except in compliance with the License.
zrussell3 0:b176d95bb38f 6 * You may obtain a copy of the License at
zrussell3 0:b176d95bb38f 7 *
zrussell3 0:b176d95bb38f 8 * http://www.apache.org/licenses/LICENSE-2.0
zrussell3 0:b176d95bb38f 9 *
zrussell3 0:b176d95bb38f 10 * Unless required by applicable law or agreed to in writing, software
zrussell3 0:b176d95bb38f 11 * distributed under the License is distributed on an "AS IS" BASIS,
zrussell3 0:b176d95bb38f 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
zrussell3 0:b176d95bb38f 13 * See the License for the specific language governing permissions and
zrussell3 0:b176d95bb38f 14 * limitations under the License.
zrussell3 0:b176d95bb38f 15 */
zrussell3 0:b176d95bb38f 16
zrussell3 0:b176d95bb38f 17 #ifndef USBHALHOST_H
zrussell3 0:b176d95bb38f 18 #define USBHALHOST_H
zrussell3 0:b176d95bb38f 19
zrussell3 0:b176d95bb38f 20 #include "USBHostTypes.h"
zrussell3 0:b176d95bb38f 21 #include "USBHostConf.h"
zrussell3 0:b176d95bb38f 22
zrussell3 0:b176d95bb38f 23 class USBHostHub;
zrussell3 0:b176d95bb38f 24
zrussell3 0:b176d95bb38f 25 /**
zrussell3 0:b176d95bb38f 26 * USBHALHost class
zrussell3 0:b176d95bb38f 27 */
zrussell3 0:b176d95bb38f 28 class USBHALHost {
zrussell3 0:b176d95bb38f 29 protected:
zrussell3 0:b176d95bb38f 30
zrussell3 0:b176d95bb38f 31 /**
zrussell3 0:b176d95bb38f 32 * Constructor
zrussell3 0:b176d95bb38f 33 * init variables and memory where will be stored HCCA, ED and TD
zrussell3 0:b176d95bb38f 34 */
zrussell3 0:b176d95bb38f 35 USBHALHost();
zrussell3 0:b176d95bb38f 36
zrussell3 0:b176d95bb38f 37 /**
zrussell3 0:b176d95bb38f 38 * Initialize host controller. Enable USB interrupts. This part is not in the constructor because,
zrussell3 0:b176d95bb38f 39 * this function calls a virtual method if a device is already connected
zrussell3 0:b176d95bb38f 40 */
zrussell3 0:b176d95bb38f 41 void init();
zrussell3 0:b176d95bb38f 42
zrussell3 0:b176d95bb38f 43 /**
zrussell3 0:b176d95bb38f 44 * reset the root hub
zrussell3 0:b176d95bb38f 45 */
zrussell3 0:b176d95bb38f 46 void resetRootHub();
zrussell3 0:b176d95bb38f 47
zrussell3 0:b176d95bb38f 48 /**
zrussell3 0:b176d95bb38f 49 * return the value contained in the control HEAD ED register
zrussell3 0:b176d95bb38f 50 *
zrussell3 0:b176d95bb38f 51 * @returns address of the control Head ED
zrussell3 0:b176d95bb38f 52 */
zrussell3 0:b176d95bb38f 53 uint32_t controlHeadED();
zrussell3 0:b176d95bb38f 54
zrussell3 0:b176d95bb38f 55 /**
zrussell3 0:b176d95bb38f 56 * return the value contained in the bulk HEAD ED register
zrussell3 0:b176d95bb38f 57 *
zrussell3 0:b176d95bb38f 58 * @returns address of the bulk head ED
zrussell3 0:b176d95bb38f 59 */
zrussell3 0:b176d95bb38f 60 uint32_t bulkHeadED();
zrussell3 0:b176d95bb38f 61
zrussell3 0:b176d95bb38f 62 /**
zrussell3 0:b176d95bb38f 63 * return the value of the head interrupt ED contained in the HCCA
zrussell3 0:b176d95bb38f 64 *
zrussell3 0:b176d95bb38f 65 * @returns address of the head interrupt ED contained in the HCCA
zrussell3 0:b176d95bb38f 66 */
zrussell3 0:b176d95bb38f 67 uint32_t interruptHeadED();
zrussell3 0:b176d95bb38f 68
zrussell3 0:b176d95bb38f 69 /**
zrussell3 0:b176d95bb38f 70 * Update the head ED for control transfers
zrussell3 0:b176d95bb38f 71 */
zrussell3 0:b176d95bb38f 72 void updateControlHeadED(uint32_t addr);
zrussell3 0:b176d95bb38f 73
zrussell3 0:b176d95bb38f 74 /**
zrussell3 0:b176d95bb38f 75 * Update the head ED for bulk transfers
zrussell3 0:b176d95bb38f 76 */
zrussell3 0:b176d95bb38f 77 void updateBulkHeadED(uint32_t addr);
zrussell3 0:b176d95bb38f 78
zrussell3 0:b176d95bb38f 79 /**
zrussell3 0:b176d95bb38f 80 * Update the head ED for interrupt transfers
zrussell3 0:b176d95bb38f 81 */
zrussell3 0:b176d95bb38f 82 void updateInterruptHeadED(uint32_t addr);
zrussell3 0:b176d95bb38f 83
zrussell3 0:b176d95bb38f 84 /**
zrussell3 0:b176d95bb38f 85 * Enable List for the specified endpoint type
zrussell3 0:b176d95bb38f 86 *
zrussell3 0:b176d95bb38f 87 * @param type enable the list of ENDPOINT_TYPE type
zrussell3 0:b176d95bb38f 88 */
zrussell3 0:b176d95bb38f 89 void enableList(ENDPOINT_TYPE type);
zrussell3 0:b176d95bb38f 90
zrussell3 0:b176d95bb38f 91 /**
zrussell3 0:b176d95bb38f 92 * Disable List for the specified endpoint type
zrussell3 0:b176d95bb38f 93 *
zrussell3 0:b176d95bb38f 94 * @param type disable the list of ENDPOINT_TYPE type
zrussell3 0:b176d95bb38f 95 */
zrussell3 0:b176d95bb38f 96 bool disableList(ENDPOINT_TYPE type);
zrussell3 0:b176d95bb38f 97
zrussell3 0:b176d95bb38f 98 /**
zrussell3 0:b176d95bb38f 99 * Virtual method called when a device has been connected
zrussell3 0:b176d95bb38f 100 *
zrussell3 0:b176d95bb38f 101 * @param hub hub number of the device
zrussell3 0:b176d95bb38f 102 * @param port port number of the device
zrussell3 0:b176d95bb38f 103 * @param lowSpeed 1 if low speed, 0 otherwise
zrussell3 0:b176d95bb38f 104 * @param hub_parent reference to the hub where the device is connected (NULL if the hub parent is the root hub)
zrussell3 0:b176d95bb38f 105 */
zrussell3 0:b176d95bb38f 106 virtual void deviceConnected(int hub, int port, bool lowSpeed, USBHostHub * hub_parent = NULL) = 0;
zrussell3 0:b176d95bb38f 107
zrussell3 0:b176d95bb38f 108 /**
zrussell3 0:b176d95bb38f 109 * Virtual method called when a device has been disconnected
zrussell3 0:b176d95bb38f 110 *
zrussell3 0:b176d95bb38f 111 * @param hub hub number of the device
zrussell3 0:b176d95bb38f 112 * @param port port number of the device
zrussell3 0:b176d95bb38f 113 * @param hub_parent reference to the hub where the device is connected (NULL if the hub parent is the root hub)
zrussell3 0:b176d95bb38f 114 * @param addr list of the TDs which have been completed to dequeue freed TDs
zrussell3 0:b176d95bb38f 115 */
zrussell3 0:b176d95bb38f 116 virtual void deviceDisconnected(int hub, int port, USBHostHub * hub_parent, volatile uint32_t addr) = 0;
zrussell3 0:b176d95bb38f 117
zrussell3 0:b176d95bb38f 118 /**
zrussell3 0:b176d95bb38f 119 * Virtual method called when a transfer has been completed
zrussell3 0:b176d95bb38f 120 *
zrussell3 0:b176d95bb38f 121 * @param addr list of the TDs which have been completed
zrussell3 0:b176d95bb38f 122 */
zrussell3 0:b176d95bb38f 123 virtual void transferCompleted(volatile uint32_t addr) = 0;
zrussell3 0:b176d95bb38f 124
zrussell3 0:b176d95bb38f 125 /**
zrussell3 0:b176d95bb38f 126 * Find a memory section for a new ED
zrussell3 0:b176d95bb38f 127 *
zrussell3 0:b176d95bb38f 128 * @returns the address of the new ED
zrussell3 0:b176d95bb38f 129 */
zrussell3 0:b176d95bb38f 130 volatile uint8_t * getED();
zrussell3 0:b176d95bb38f 131
zrussell3 0:b176d95bb38f 132 /**
zrussell3 0:b176d95bb38f 133 * Find a memory section for a new TD
zrussell3 0:b176d95bb38f 134 *
zrussell3 0:b176d95bb38f 135 * @returns the address of the new TD
zrussell3 0:b176d95bb38f 136 */
zrussell3 0:b176d95bb38f 137 volatile uint8_t * getTD();
zrussell3 0:b176d95bb38f 138
zrussell3 0:b176d95bb38f 139 /**
zrussell3 0:b176d95bb38f 140 * Release a previous memory section reserved for an ED
zrussell3 0:b176d95bb38f 141 *
zrussell3 0:b176d95bb38f 142 * @param ed address of the ED
zrussell3 0:b176d95bb38f 143 */
zrussell3 0:b176d95bb38f 144 void freeED(volatile uint8_t * ed);
zrussell3 0:b176d95bb38f 145
zrussell3 0:b176d95bb38f 146 /**
zrussell3 0:b176d95bb38f 147 * Release a previous memory section reserved for an TD
zrussell3 0:b176d95bb38f 148 *
zrussell3 0:b176d95bb38f 149 * @param td address of the TD
zrussell3 0:b176d95bb38f 150 */
zrussell3 0:b176d95bb38f 151 void freeTD(volatile uint8_t * td);
zrussell3 0:b176d95bb38f 152
zrussell3 0:b176d95bb38f 153 private:
zrussell3 0:b176d95bb38f 154 static void _usbisr(void);
zrussell3 0:b176d95bb38f 155 void UsbIrqhandler();
zrussell3 0:b176d95bb38f 156
zrussell3 0:b176d95bb38f 157 void memInit();
zrussell3 0:b176d95bb38f 158
zrussell3 0:b176d95bb38f 159 HCCA volatile * usb_hcca; //256 bytes aligned
zrussell3 0:b176d95bb38f 160 uint8_t volatile * usb_edBuf; //4 bytes aligned
zrussell3 0:b176d95bb38f 161 uint8_t volatile * usb_tdBuf; //4 bytes aligned
zrussell3 0:b176d95bb38f 162
zrussell3 0:b176d95bb38f 163 static USBHALHost * instHost;
zrussell3 0:b176d95bb38f 164
zrussell3 0:b176d95bb38f 165 bool volatile edBufAlloc[MAX_ENDPOINT];
zrussell3 0:b176d95bb38f 166 bool volatile tdBufAlloc[MAX_TD];
zrussell3 0:b176d95bb38f 167 };
zrussell3 0:b176d95bb38f 168
zrussell3 0:b176d95bb38f 169 #endif