Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

USBHostKeyboard.h 2.4KB

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