input.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Keyboard input helper functions (too small to be called a layer)
  3. *
  4. * Copyright (c) 2011 The Chromium OS Authors.
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #ifndef _INPUT_H
  24. #define _INPUT_H
  25. enum {
  26. INPUT_MAX_MODIFIERS = 4,
  27. INPUT_BUFFER_LEN = 16,
  28. };
  29. enum {
  30. /* Keyboard LEDs */
  31. INPUT_LED_SCROLL = 1 << 0,
  32. INPUT_LED_CAPS = 1 << 1,
  33. INPUT_LED_NUM = 1 << 2,
  34. };
  35. /*
  36. * This table translates key codes to ASCII. Most of the entries are ASCII
  37. * codes, but entries after KEY_FIRST_MOD indicate that this key is a
  38. * modifier key, like shift, ctrl. KEY_FIRST_MOD + MOD_SHIFT is the shift
  39. * key, for example.
  40. */
  41. struct input_key_xlate {
  42. /* keycode of the modifiers which select this table, -1 if none */
  43. int left_keycode;
  44. int right_keycode;
  45. const uchar *xlate; /* keycode to ASCII table */
  46. int num_entries; /* number of entries in this table */
  47. };
  48. struct input_config {
  49. uchar fifo[INPUT_BUFFER_LEN];
  50. int fifo_in, fifo_out;
  51. /* Which modifiers are active (1 bit for each MOD_... value) */
  52. uchar modifiers;
  53. uchar flags; /* active state keys (FLAGS_...) */
  54. uchar leds; /* active LEDS (INPUT_LED_...) */
  55. uchar num_tables; /* number of modifier tables */
  56. int prev_keycodes[INPUT_BUFFER_LEN]; /* keys held last time */
  57. int num_prev_keycodes; /* number of prev keys */
  58. struct input_key_xlate table[INPUT_MAX_MODIFIERS];
  59. /**
  60. * Function the input helper calls to scan the keyboard
  61. *
  62. * @param config Input state
  63. * @return 0 if no keys read, otherwise number of keys read, or 1 if
  64. * unknown
  65. */
  66. int (*read_keys)(struct input_config *config);
  67. unsigned int next_repeat_ms; /* Next time we repeat a key */
  68. unsigned int repeat_delay_ms; /* Time before autorepeat starts */
  69. unsigned int repeat_rate_ms; /* Autorepeat rate in ms */
  70. };
  71. struct stdio_dev;
  72. /**
  73. * Convert a list of key codes into ASCII and send them
  74. *
  75. * @param config Input state
  76. * @param keycode List of key codes to examine
  77. * @param num_keycodes Number of key codes
  78. * @return number of ascii characters sent, or 0 if none, or -1 for an
  79. * internal error
  80. */
  81. int input_send_keycodes(struct input_config *config, int keycode[], int count);
  82. /**
  83. * Add a new key translation table to the input
  84. *
  85. * @param config Input state
  86. * @param left_keycode Key to hold to get into this table
  87. * @param right_keycode Another key to hold to get into this table
  88. * @param xlate Conversion table from key codes to ASCII
  89. * @param num_entries Number of entries in xlate table
  90. */
  91. int input_add_table(struct input_config *config, int left_keycode,
  92. int right_keycode, const uchar *xlate, int num_entries);
  93. /**
  94. * Test if keys are available to be read
  95. *
  96. * @param config Input state
  97. * @return 0 if no keys available, 1 if keys are available
  98. */
  99. int input_tstc(struct input_config *config);
  100. /**
  101. * Read a key
  102. *
  103. * TODO: U-Boot wants 0 for no key, but Ctrl-@ is a valid key...
  104. *
  105. * @param config Input state
  106. * @return key, or 0 if no key, or -1 if error
  107. */
  108. int input_getc(struct input_config *config);
  109. /**
  110. * Register a new device with stdio and switch to it if wanted
  111. *
  112. * @param dev Pointer to device
  113. * @return 0 if ok, -1 on error
  114. */
  115. int input_stdio_register(struct stdio_dev *dev);
  116. /**
  117. * Set up the keyboard autorepeat delays
  118. *
  119. * @param repeat_delay_ms Delay before key auto-repeat starts (in ms)
  120. * @param repeat_rate_ms Delay between successive key repeats (in ms)
  121. */
  122. void input_set_delays(struct input_config *config, int repeat_delay_ms,
  123. int repeat_rate_ms);
  124. /**
  125. * Set up the input handler with basic key maps.
  126. *
  127. * @param config Input state
  128. * @param leds Initial LED value (INPUT_LED_ mask), 0 suggested
  129. * @return 0 if ok, -1 on error
  130. */
  131. int input_init(struct input_config *config, int leds);
  132. #ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
  133. extern int overwrite_console(void);
  134. #define OVERWRITE_CONSOLE overwrite_console()
  135. #else
  136. #define OVERWRITE_CONSOLE 0
  137. #endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */
  138. #endif