Added TARGET_DISCO_F469NI in USBHOST\USBHost\TARGET_STM\USBHALHost_STM_TARGET.h

Dependents:   DISCO-F469NI_USB_Disk STM32F4xx_USB_Memory

Fork of USBHOST by ST

Committer:
kenjiArai
Date:
Sat Jan 04 23:30:59 2020 +0000
Revision:
8:3e7a33f81048
Parent:
5:fc157e6bd5a5
updated for STM32F4xx

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1 /* mbed USBHost Library
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 2 * Copyright (c) 2006-2013 ARM Limited
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 3 *
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 4 * Licensed under the Apache License, Version 2.0 (the "License");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 5 * you may not use this file except in compliance with the License.
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 6 * You may obtain a copy of the License at
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 7 *
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 8 * http://www.apache.org/licenses/LICENSE-2.0
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 9 *
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 10 * Unless required by applicable law or agreed to in writing, software
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 11 * distributed under the License is distributed on an "AS IS" BASIS,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 13 * See the License for the specific language governing permissions and
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 14 * limitations under the License.
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 15 */
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 16
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 17 #include "USBHostMouse.h"
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 18
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 19 #if USBHOST_MOUSE
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 20
kenjiArai 8:3e7a33f81048 21 USBHostMouse::USBHostMouse()
kenjiArai 8:3e7a33f81048 22 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 23 host = USBHost::getHostInst();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 24 init();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 25 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 26
kenjiArai 8:3e7a33f81048 27 void USBHostMouse::init()
kenjiArai 8:3e7a33f81048 28 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 29 dev = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 30 int_in = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 31 onUpdate = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 32 onButtonUpdate = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 33 onXUpdate = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 34 onYUpdate = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 35 onZUpdate = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 36 report_id = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 37 dev_connected = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 38 mouse_device_found = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 39 mouse_intf = -1;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 40
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 41 buttons = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 42 x = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 43 y = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 44 z = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 45 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 46
kenjiArai 8:3e7a33f81048 47 bool USBHostMouse::connected()
kenjiArai 8:3e7a33f81048 48 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 49 return dev_connected;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 50 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 51
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 52 bool USBHostMouse::connect()
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 53 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 54 int len_listen;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 55
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 56 if (dev_connected) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 57 return true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 58 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 59
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 60 for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 61 if ((dev = host->getDevice(i)) != NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 62
kenjiArai 8:3e7a33f81048 63 if(host->enumerate(dev, this)) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 64 break;
kenjiArai 8:3e7a33f81048 65 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 66 if (mouse_device_found) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 67 {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 68 /* As this is done in a specific thread
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 69 * this lock is taken to avoid to process the device
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 70 * disconnect in usb process during the device registering */
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 71 USBHost::Lock Lock(host);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 72 int_in = dev->getEndpoint(mouse_intf, INTERRUPT_ENDPOINT, IN);
kenjiArai 8:3e7a33f81048 73 if (!int_in) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 74 break;
kenjiArai 8:3e7a33f81048 75 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 76
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 77 USB_INFO("New Mouse device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, mouse_intf);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 78 dev->setName("Mouse", mouse_intf);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 79 host->registerDriver(dev, mouse_intf, this, &USBHostMouse::init);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 80
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 81 int_in->attach(this, &USBHostMouse::rxHandler);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 82 len_listen = int_in->getSize();
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 83 if (len_listen > sizeof(report)) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 84 len_listen = sizeof(report);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 85 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 86 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 87 int ret=host->interruptRead(dev, int_in, report, len_listen, false);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 88 MBED_ASSERT((ret==USB_TYPE_OK) || (ret ==USB_TYPE_PROCESSING) || (ret == USB_TYPE_FREE));
kenjiArai 8:3e7a33f81048 89 if ((ret==USB_TYPE_OK) || (ret ==USB_TYPE_PROCESSING)) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 90 dev_connected = true;
kenjiArai 8:3e7a33f81048 91 }
kenjiArai 8:3e7a33f81048 92 if (ret == USB_TYPE_FREE) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 93 dev_connected = false;
kenjiArai 8:3e7a33f81048 94 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 95 return true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 96 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 97 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 98 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 99 init();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 100 return false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 101 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 102
kenjiArai 8:3e7a33f81048 103 void USBHostMouse::rxHandler()
kenjiArai 8:3e7a33f81048 104 {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 105 int len_listen = int_in->getLengthTransferred();
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 106 if (len_listen !=0) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 107
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 108 if (onUpdate) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 109 (*onUpdate)(report[0] & 0x07, report[1], report[2], report[3]);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 110 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 111
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 112 if (onButtonUpdate && (buttons != (report[0] & 0x07))) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 113 (*onButtonUpdate)(report[0] & 0x07);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 114 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 115
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 116 if (onXUpdate && (x != report[1])) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 117 (*onXUpdate)(report[1]);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 118 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 119
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 120 if (onYUpdate && (y != report[2])) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 121 (*onYUpdate)(report[2]);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 122 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 123
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 124 if (onZUpdate && (z != report[3])) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 125 (*onZUpdate)(report[3]);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 126 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 127
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 128 // update mouse state
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 129 buttons = report[0] & 0x07;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 130 x = report[1];
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 131 y = report[2];
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 132 z = report[3];
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 133 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 134 /* set again the maximum value */
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 135 len_listen = int_in->getSize();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 136
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 137 if (len_listen > sizeof(report)) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 138 len_listen = sizeof(report);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 139 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 140
kenjiArai 8:3e7a33f81048 141 if (dev) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 142 host->interruptRead(dev, int_in, report, len_listen, false);
kenjiArai 8:3e7a33f81048 143 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 144 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 145
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 146 /*virtual*/ void USBHostMouse::setVidPid(uint16_t vid, uint16_t pid)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 147 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 148 // we don't check VID/PID for mouse driver
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 149 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 150
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 151 /*virtual*/ bool USBHostMouse::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 152 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 153 if ((mouse_intf == -1) &&
kenjiArai 8:3e7a33f81048 154 (intf_class == HID_CLASS) &&
kenjiArai 8:3e7a33f81048 155 (intf_subclass == 0x01) &&
kenjiArai 8:3e7a33f81048 156 (intf_protocol == 0x02)) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 157 mouse_intf = intf_nb;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 158 return true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 159 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 160 return false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 161 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 162
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 163 /*virtual*/ bool USBHostMouse::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 164 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 165 if (intf_nb == mouse_intf) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 166 if (type == INTERRUPT_ENDPOINT && dir == IN) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 167 mouse_device_found = true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 168 return true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 169 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 170 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 171 return false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 172 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 173
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 174 #endif