ST/USBHOST forked to add another HID handler for raw keyboard data to get more detail not available with current handlers (all pressed keys, all releases, and periodic updates)

Dependents:   C64-stm429_discovery

Committer:
davervw
Date:
Mon Apr 13 05:25:10 2020 +0000
Revision:
7:9dc1cb9d5e12
Parent:
1:ab240722d7ef
Added handler to USBHostHID/USBHostKeyboard.cpp:;    void (*onKeyData)(uint8_t len, uint8_t* data);; so can get raw keyboard data for all keys simultaneously pressed, and all releases and periodic data

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 "USBDeviceConnected.h"
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 18 #include "dbg.h"
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 19
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 20 USBDeviceConnected::USBDeviceConnected() {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 21 init();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 22 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 23
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 24 void USBDeviceConnected::init() {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 25 hub_nb = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 26 port = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 27 vid = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 28 pid = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 29 nb_interf = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 30 enumerated = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 31 activeAddr = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 32 sizeControlEndpoint = 8;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 33 device_class = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 34 device_subclass = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 35 proto = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 36 speed = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 37 for (int i = 0; i < MAX_INTF; i++) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 38 memset((void *)&intf[i], 0, sizeof(INTERFACE));
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 39 intf[i].in_use = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 40 for (int j = 0; j < MAX_ENDPOINT_PER_INTERFACE; j++) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 41 intf[i].ep[j] = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 42 strcpy(intf[i].name, "Unknown");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 43 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 44 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 45 hub_parent = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 46 hub = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 47 nb_interf = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 48 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 49
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 50 INTERFACE * USBDeviceConnected::getInterface(uint8_t index) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 51 if (index >= MAX_INTF)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 52 return NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 53
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 54 if (intf[index].in_use)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 55 return &intf[index];
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 56
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 57 return NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 58 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 59
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 60 bool USBDeviceConnected::addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 61 if ((intf_nb >= MAX_INTF) || (intf[intf_nb].in_use)) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 62 return false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 63 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 64 intf[intf_nb].in_use = true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 65 intf[intf_nb].intf_class = intf_class;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 66 intf[intf_nb].intf_subclass = intf_subclass;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 67 intf[intf_nb].intf_protocol = intf_protocol;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 68 intf[intf_nb].nb_endpoint = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 69 return true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 70 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 71
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 72 bool USBDeviceConnected::addEndpoint(uint8_t intf_nb, USBEndpoint * ept) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 73 if ((intf_nb >= MAX_INTF) || (intf[intf_nb].in_use == false) || (intf[intf_nb].nb_endpoint >= MAX_ENDPOINT_PER_INTERFACE)) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 74 return false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 75 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 76 intf[intf_nb].nb_endpoint++;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 77
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 78 for (int i = 0; i < MAX_ENDPOINT_PER_INTERFACE; i++) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 79 if (intf[intf_nb].ep[i] == NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 80 intf[intf_nb].ep[i] = ept;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 81 return true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 82 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 83 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 84 return false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 85 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 86
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 87 void USBDeviceConnected::init(uint8_t hub_, uint8_t port_, bool lowSpeed_) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 88 USB_DBG("init dev: %p", this);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 89 init();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 90 hub_nb = hub_;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 91 port = port_;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 92 speed = lowSpeed_;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 93 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 94
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 95 void USBDeviceConnected::disconnect() {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 96 for(int i = 0; i < MAX_INTF; i++) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 97 if (intf[i].detach) intf[i].detach.call();
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 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 101
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 102
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 103 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 104 if (intf_nb >= MAX_INTF) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 105 return NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 106 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 107 for (int i = 0; i < MAX_ENDPOINT_PER_INTERFACE; i++) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 108 if ((intf[intf_nb].ep[i]->getType() == type) && (intf[intf_nb].ep[i]->getDir() == dir)) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 109 if(index) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 110 index--;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 111 } else {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 112 return intf[intf_nb].ep[i];
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 113 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 114 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 115 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 116 return NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 117 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 118
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 119 USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, uint8_t index) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 120 if ((intf_nb >= MAX_INTF) || (index >= MAX_ENDPOINT_PER_INTERFACE)) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 121 return NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 122 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 123 return intf[intf_nb].ep[index];
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 124 }