modified to compile for me
Fork of F401RE-USBHost by
USBHostHID/USBHostKeyboard.h@28:98551d9289a8, 2017-02-24 (annotated)
- Committer:
- Ownasaurus
- Date:
- Fri Feb 24 02:44:44 2017 +0000
- Revision:
- 28:98551d9289a8
- Parent:
- 24:75435a7ab25b
added print to indicate reason for occasional startup failure
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 9:7f9f64cf5ded | 1 | /* mbed USBHost Library |
va009039 | 9:7f9f64cf5ded | 2 | * Copyright (c) 2006-2013 ARM Limited |
va009039 | 9:7f9f64cf5ded | 3 | * |
va009039 | 9:7f9f64cf5ded | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
va009039 | 9:7f9f64cf5ded | 5 | * you may not use this file except in compliance with the License. |
va009039 | 9:7f9f64cf5ded | 6 | * You may obtain a copy of the License at |
va009039 | 9:7f9f64cf5ded | 7 | * |
va009039 | 9:7f9f64cf5ded | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
va009039 | 9:7f9f64cf5ded | 9 | * |
va009039 | 9:7f9f64cf5ded | 10 | * Unless required by applicable law or agreed to in writing, software |
va009039 | 9:7f9f64cf5ded | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
va009039 | 9:7f9f64cf5ded | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
va009039 | 9:7f9f64cf5ded | 13 | * See the License for the specific language governing permissions and |
va009039 | 9:7f9f64cf5ded | 14 | * limitations under the License. |
va009039 | 9:7f9f64cf5ded | 15 | */ |
va009039 | 9:7f9f64cf5ded | 16 | |
va009039 | 9:7f9f64cf5ded | 17 | #ifndef USBHOSTKEYBOARD_H |
va009039 | 9:7f9f64cf5ded | 18 | #define USBHOSTKEYBOARD_H |
va009039 | 9:7f9f64cf5ded | 19 | |
va009039 | 9:7f9f64cf5ded | 20 | #include "USBHostConf.h" |
va009039 | 9:7f9f64cf5ded | 21 | |
va009039 | 9:7f9f64cf5ded | 22 | #if USBHOST_KEYBOARD |
va009039 | 9:7f9f64cf5ded | 23 | |
va009039 | 9:7f9f64cf5ded | 24 | #include "USBHost.h" |
va009039 | 9:7f9f64cf5ded | 25 | |
va009039 | 9:7f9f64cf5ded | 26 | /** |
va009039 | 9:7f9f64cf5ded | 27 | * A class to communicate a USB keyboard |
va009039 | 9:7f9f64cf5ded | 28 | */ |
va009039 | 9:7f9f64cf5ded | 29 | class USBHostKeyboard : public IUSBEnumerator { |
va009039 | 9:7f9f64cf5ded | 30 | public: |
va009039 | 9:7f9f64cf5ded | 31 | |
va009039 | 9:7f9f64cf5ded | 32 | /** |
va009039 | 9:7f9f64cf5ded | 33 | * Constructor |
va009039 | 9:7f9f64cf5ded | 34 | */ |
va009039 | 9:7f9f64cf5ded | 35 | USBHostKeyboard(); |
va009039 | 9:7f9f64cf5ded | 36 | |
va009039 | 9:7f9f64cf5ded | 37 | /** |
va009039 | 9:7f9f64cf5ded | 38 | * Try to connect a keyboard device |
va009039 | 9:7f9f64cf5ded | 39 | * |
va009039 | 9:7f9f64cf5ded | 40 | * @return true if connection was successful |
va009039 | 9:7f9f64cf5ded | 41 | */ |
va009039 | 9:7f9f64cf5ded | 42 | bool connect(); |
va009039 | 9:7f9f64cf5ded | 43 | |
va009039 | 9:7f9f64cf5ded | 44 | /** |
va009039 | 9:7f9f64cf5ded | 45 | * Check if a keyboard is connected |
va009039 | 9:7f9f64cf5ded | 46 | * |
va009039 | 9:7f9f64cf5ded | 47 | * @returns true if a keyboard is connected |
va009039 | 9:7f9f64cf5ded | 48 | */ |
va009039 | 9:7f9f64cf5ded | 49 | bool connected(); |
va009039 | 9:7f9f64cf5ded | 50 | |
va009039 | 9:7f9f64cf5ded | 51 | /** |
va009039 | 9:7f9f64cf5ded | 52 | * Attach a callback called when a keyboard event is received |
va009039 | 9:7f9f64cf5ded | 53 | * |
va009039 | 9:7f9f64cf5ded | 54 | * @param ptr function pointer |
va009039 | 9:7f9f64cf5ded | 55 | */ |
va009039 | 9:7f9f64cf5ded | 56 | inline void attach(void (*ptr)(uint8_t key)) { |
va009039 | 9:7f9f64cf5ded | 57 | if (ptr != NULL) { |
va009039 | 9:7f9f64cf5ded | 58 | onKey = ptr; |
va009039 | 9:7f9f64cf5ded | 59 | } |
va009039 | 9:7f9f64cf5ded | 60 | } |
va009039 | 9:7f9f64cf5ded | 61 | |
va009039 | 9:7f9f64cf5ded | 62 | /** |
va009039 | 9:7f9f64cf5ded | 63 | * Attach a callback called when a keyboard event is received |
va009039 | 9:7f9f64cf5ded | 64 | * |
va009039 | 9:7f9f64cf5ded | 65 | * @param ptr function pointer |
va009039 | 9:7f9f64cf5ded | 66 | */ |
va009039 | 9:7f9f64cf5ded | 67 | inline void attach(void (*ptr)(uint8_t keyCode, uint8_t modifier)) { |
va009039 | 9:7f9f64cf5ded | 68 | if (ptr != NULL) { |
va009039 | 9:7f9f64cf5ded | 69 | onKeyCode = ptr; |
va009039 | 9:7f9f64cf5ded | 70 | } |
va009039 | 9:7f9f64cf5ded | 71 | } |
Ownasaurus | 24:75435a7ab25b | 72 | |
Ownasaurus | 24:75435a7ab25b | 73 | /** |
Ownasaurus | 24:75435a7ab25b | 74 | * Attach a callback called when a keyboard event is received |
Ownasaurus | 24:75435a7ab25b | 75 | * |
Ownasaurus | 24:75435a7ab25b | 76 | * @param ptr function pointer |
Ownasaurus | 24:75435a7ab25b | 77 | */ |
Ownasaurus | 24:75435a7ab25b | 78 | inline void attach(void (*ptr)(uint8_t rep[9])) { |
Ownasaurus | 24:75435a7ab25b | 79 | if (ptr != NULL) { |
Ownasaurus | 24:75435a7ab25b | 80 | onKeyRaw = ptr; |
Ownasaurus | 24:75435a7ab25b | 81 | } |
Ownasaurus | 24:75435a7ab25b | 82 | } |
va009039 | 9:7f9f64cf5ded | 83 | |
va009039 | 9:7f9f64cf5ded | 84 | protected: |
va009039 | 9:7f9f64cf5ded | 85 | //From IUSBEnumerator |
va009039 | 9:7f9f64cf5ded | 86 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
va009039 | 9:7f9f64cf5ded | 87 | virtual bool 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 |
va009039 | 9:7f9f64cf5ded | 88 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
va009039 | 9:7f9f64cf5ded | 89 | |
va009039 | 9:7f9f64cf5ded | 90 | private: |
va009039 | 9:7f9f64cf5ded | 91 | USBHost * host; |
va009039 | 9:7f9f64cf5ded | 92 | USBDeviceConnected * dev; |
va009039 | 9:7f9f64cf5ded | 93 | USBEndpoint * int_in; |
va009039 | 9:7f9f64cf5ded | 94 | uint8_t report[9]; |
va009039 | 9:7f9f64cf5ded | 95 | int keyboard_intf; |
va009039 | 9:7f9f64cf5ded | 96 | bool keyboard_device_found; |
va009039 | 9:7f9f64cf5ded | 97 | |
va009039 | 9:7f9f64cf5ded | 98 | bool dev_connected; |
va009039 | 9:7f9f64cf5ded | 99 | |
va009039 | 9:7f9f64cf5ded | 100 | void rxHandler(); |
va009039 | 9:7f9f64cf5ded | 101 | |
va009039 | 9:7f9f64cf5ded | 102 | void (*onKey)(uint8_t key); |
va009039 | 9:7f9f64cf5ded | 103 | void (*onKeyCode)(uint8_t key, uint8_t modifier); |
Ownasaurus | 24:75435a7ab25b | 104 | void (*onKeyRaw)(uint8_t rep[9]); |
Ownasaurus | 24:75435a7ab25b | 105 | // TODO: add new callback function to send raw state |
va009039 | 9:7f9f64cf5ded | 106 | |
va009039 | 9:7f9f64cf5ded | 107 | int report_id; |
va009039 | 9:7f9f64cf5ded | 108 | |
va009039 | 9:7f9f64cf5ded | 109 | void init(); |
va009039 | 9:7f9f64cf5ded | 110 | |
va009039 | 9:7f9f64cf5ded | 111 | }; |
va009039 | 9:7f9f64cf5ded | 112 | |
va009039 | 9:7f9f64cf5ded | 113 | #endif |
va009039 | 9:7f9f64cf5ded | 114 | |
va009039 | 9:7f9f64cf5ded | 115 | #endif |