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