Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of F401RE-USBHost by
USBHostKeyboard.h
00001 /* mbed USBHost Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef USBHOSTKEYBOARD_H 00018 #define USBHOSTKEYBOARD_H 00019 00020 #include "USBHostConf.h" 00021 00022 #if USBHOST_KEYBOARD 00023 00024 #include "USBHost.h" 00025 00026 /** 00027 * A class to communicate a USB keyboard 00028 */ 00029 class USBHostKeyboard : public IUSBEnumerator { 00030 public: 00031 00032 /** 00033 * Constructor 00034 */ 00035 USBHostKeyboard(); 00036 00037 /** 00038 * Try to connect a keyboard device 00039 * 00040 * @return true if connection was successful 00041 */ 00042 bool connect(); 00043 00044 /** 00045 * Check if a keyboard is connected 00046 * 00047 * @returns true if a keyboard is connected 00048 */ 00049 bool connected(); 00050 00051 /** 00052 * Attach a callback called when a keyboard event is received 00053 * 00054 * @param ptr function pointer 00055 */ 00056 inline void attach(void (*ptr)(uint8_t key)) { 00057 if (ptr != NULL) { 00058 onKey = ptr; 00059 } 00060 } 00061 00062 /** 00063 * Attach a callback called when a keyboard event is received 00064 * 00065 * @param ptr function pointer 00066 */ 00067 inline void attach(void (*ptr)(uint8_t keyCode, uint8_t modifier)) { 00068 if (ptr != NULL) { 00069 onKeyCode = ptr; 00070 } 00071 } 00072 00073 /** 00074 * Attach a callback called when a keyboard event is received 00075 * 00076 * @param ptr function pointer 00077 */ 00078 inline void attach(void (*ptr)(uint8_t rep[9])) { 00079 if (ptr != NULL) { 00080 onKeyRaw = ptr; 00081 } 00082 } 00083 00084 protected: 00085 //From IUSBEnumerator 00086 virtual void setVidPid(uint16_t vid, uint16_t pid); 00087 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 00088 virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used 00089 00090 private: 00091 USBHost * host; 00092 USBDeviceConnected * dev; 00093 USBEndpoint * int_in; 00094 uint8_t report[9]; 00095 int keyboard_intf; 00096 bool keyboard_device_found; 00097 00098 bool dev_connected; 00099 00100 void rxHandler(); 00101 00102 void (*onKey)(uint8_t key); 00103 void (*onKeyCode)(uint8_t key, uint8_t modifier); 00104 void (*onKeyRaw)(uint8_t rep[9]); 00105 // TODO: add new callback function to send raw state 00106 00107 int report_id; 00108 00109 void init(); 00110 00111 }; 00112 00113 #endif 00114 00115 #endif
Generated on Wed Jul 13 2022 03:02:45 by
1.7.2
