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.

93 lines
3.1 KiB

  1. /* gc_n64_usb : Gamecube or N64 controller to USB firmware
  2. Copyright (C) 2007-2013 Raphael Assenat <raph@raphnet.net>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <avr/pgmspace.h>
  15. #include "gc_kb.h"
  16. #include "hid_keycodes.h"
  17. #include "gcn64_protocol.h"
  18. // http://www2d.biglobe.ne.jp/~msyk/keyboard/layout/usbkeycode.html
  19. static const unsigned char gc_to_hid_table[] PROGMEM = {
  20. GC_KEY_RESERVED, HID_KB_NOEVENT,
  21. GC_KEY_HOME, HID_KB_HOME,
  22. GC_KEY_END, HID_KB_END,
  23. GC_KEY_PGUP, HID_KB_PGUP,
  24. GC_KEY_PGDN, HID_KB_PGDN,
  25. GC_KEY_SCROLL_LOCK, HID_KB_SCROLL_LOCK,
  26. GC_KEY_DASH_UNDERSCORE, HID_KB_DASH_UNDERSCORE,
  27. GC_KEY_PLUS_EQUAL, HID_KB_EQUAL_PLUS,
  28. GC_KEY_YEN, HID_KB_INTERNATIONAL3,
  29. GC_KEY_OPEN_BRKT_BRACE, HID_KB_OPEN_BRKT_BRACE,
  30. GC_KEY_SEMI_COLON_COLON,HID_KB_SEMI_COLON_COLON,
  31. GC_KEY_QUOTES, HID_KB_QUOTES,
  32. GC_KEY_CLOSE_BRKT_BRACE,HID_KB_CLOSE_BRKT_BRACE,
  33. GC_KEY_BRACKET_MU, HID_KB_NONUS_HASH_TILDE,
  34. GC_KEY_COMMA_ST, HID_KB_COMMA_SMALLER_THAN,
  35. GC_KEY_PERIOD_GT, HID_KB_PERIOD_GREATER_THAN,
  36. GC_KEY_SLASH_QUESTION, HID_KB_SLASH_QUESTION,
  37. GC_KEY_INTERNATIONAL1, HID_KB_INTERNATIONAL1,
  38. GC_KEY_ESC, HID_KB_ESCAPE,
  39. GC_KEY_INSERT, HID_KB_INSERT,
  40. GC_KEY_DELETE, HID_KB_DELETE_FORWARD,
  41. GC_KEY_HANKAKU, HID_KB_GRAVE_ACCENT_AND_TILDE,
  42. GC_KEY_BACKSPACE, HID_KB_BACKSPACE,
  43. GC_KEY_TAB, HID_KB_TAB,
  44. GC_KEY_CAPS_LOCK, HID_KB_CAPS_LOCK,
  45. GC_KEY_MUHENKAN, HID_KB_INTERNATIONAL5,
  46. GC_KEY_SPACE, HID_KB_SPACE,
  47. GC_KEY_HENKAN, HID_KB_INTERNATIONAL4,
  48. GC_KEY_KANA, HID_KB_INTERNATIONAL2,
  49. GC_KEY_LEFT, HID_KB_LEFT_ARROW,
  50. GC_KEY_DOWN, HID_KB_DOWN_ARROW,
  51. GC_KEY_UP, HID_KB_UP_ARROW,
  52. GC_KEY_RIGHT, HID_KB_RIGHT_ARROW,
  53. GC_KEY_ENTER, HID_KB_ENTER,
  54. /* "shift" keys */
  55. GC_KEY_LEFT_SHIFT, HID_KB_LEFT_SHIFT,
  56. GC_KEY_RIGHT_SHIFT, HID_KB_RIGHT_SHIFT,
  57. GC_KEY_LEFT_CTRL, HID_KB_LEFT_CONTROL,
  58. /* This keyboard only has a left alt key. But as right alt is required to access some
  59. * functions on japanese keyboards, I map the key to right alt.
  60. *
  61. * eg: RO-MAJI on the hiragana/katakana key */
  62. GC_KEY_LEFT_ALT, HID_KB_RIGHT_ALT,
  63. };
  64. unsigned char gcKeycodeToHID(unsigned char gc_code)
  65. {
  66. int i;
  67. if (gc_code >= GC_KEY_A && gc_code <= GC_KEY_0) {
  68. // Note: This works since A-Z, 1-9, 0 have consecutive keycode values.
  69. return (gc_code - GC_KEY_A) + HID_KB_A;
  70. }
  71. if (gc_code >= GC_KEY_F1 && gc_code <= GC_KEY_F12) {
  72. return (gc_code - GC_KEY_F1) + HID_KB_F1;
  73. }
  74. for (i=0; i<sizeof(gc_to_hid_table); i++) {
  75. if (pgm_read_byte(gc_to_hid_table + i*2) == gc_code) {
  76. return pgm_read_byte(gc_to_hid_table + i*2 + 1);
  77. }
  78. }
  79. return 0x38; // HID /? key for unknown keys
  80. }