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