input.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Keyboard input helper functions (too small to be called a layer)
  3. *
  4. * Copyright (c) 2011 The Chromium OS Authors.
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #ifndef _INPUT_H
  9. #define _INPUT_H
  10. enum {
  11. INPUT_MAX_MODIFIERS = 4,
  12. INPUT_BUFFER_LEN = 16,
  13. };
  14. enum {
  15. /* Keyboard LEDs */
  16. INPUT_LED_SCROLL = 1 << 0,
  17. INPUT_LED_CAPS = 1 << 1,
  18. INPUT_LED_NUM = 1 << 2,
  19. };
  20. /*
  21. * This table translates key codes to ASCII. Most of the entries are ASCII
  22. * codes, but entries after KEY_FIRST_MOD indicate that this key is a
  23. * modifier key, like shift, ctrl. KEY_FIRST_MOD + MOD_SHIFT is the shift
  24. * key, for example.
  25. */
  26. struct input_key_xlate {
  27. /* keycode of the modifiers which select this table, -1 if none */
  28. int left_keycode;
  29. int right_keycode;
  30. const uchar *xlate; /* keycode to ASCII table */
  31. int num_entries; /* number of entries in this table */
  32. };
  33. struct input_config {
  34. uchar fifo[INPUT_BUFFER_LEN];
  35. int fifo_in, fifo_out;
  36. /* Which modifiers are active (1 bit for each MOD_... value) */
  37. uchar modifiers;
  38. uchar flags; /* active state keys (FLAGS_...) */
  39. uchar leds; /* active LEDS (INPUT_LED_...) */
  40. uchar num_tables; /* number of modifier tables */
  41. int prev_keycodes[INPUT_BUFFER_LEN]; /* keys held last time */
  42. int num_prev_keycodes; /* number of prev keys */
  43. struct input_key_xlate table[INPUT_MAX_MODIFIERS];
  44. /**
  45. * Function the input helper calls to scan the keyboard
  46. *
  47. * @param config Input state
  48. * @return 0 if no keys read, otherwise number of keys read, or 1 if
  49. * unknown
  50. */
  51. int (*read_keys)(struct input_config *config);
  52. unsigned int next_repeat_ms; /* Next time we repeat a key */
  53. unsigned int repeat_delay_ms; /* Time before autorepeat starts */
  54. unsigned int repeat_rate_ms; /* Autorepeat rate in ms */
  55. };
  56. struct stdio_dev;
  57. /**
  58. * Convert a list of key codes into ASCII and send them
  59. *
  60. * @param config Input state
  61. * @param keycode List of key codes to examine
  62. * @param num_keycodes Number of key codes
  63. * @return number of ascii characters sent, or 0 if none, or -1 for an
  64. * internal error
  65. */
  66. int input_send_keycodes(struct input_config *config, int keycode[], int count);
  67. /**
  68. * Add a new key translation table to the input
  69. *
  70. * @param config Input state
  71. * @param left_keycode Key to hold to get into this table
  72. * @param right_keycode Another key to hold to get into this table
  73. * @param xlate Conversion table from key codes to ASCII
  74. * @param num_entries Number of entries in xlate table
  75. */
  76. int input_add_table(struct input_config *config, int left_keycode,
  77. int right_keycode, const uchar *xlate, int num_entries);
  78. /**
  79. * Test if keys are available to be read
  80. *
  81. * @param config Input state
  82. * @return 0 if no keys available, 1 if keys are available
  83. */
  84. int input_tstc(struct input_config *config);
  85. /**
  86. * Read a key
  87. *
  88. * TODO: U-Boot wants 0 for no key, but Ctrl-@ is a valid key...
  89. *
  90. * @param config Input state
  91. * @return key, or 0 if no key, or -1 if error
  92. */
  93. int input_getc(struct input_config *config);
  94. /**
  95. * Register a new device with stdio and switch to it if wanted
  96. *
  97. * @param dev Pointer to device
  98. * @return 0 if ok, -1 on error
  99. */
  100. int input_stdio_register(struct stdio_dev *dev);
  101. /**
  102. * Set up the keyboard autorepeat delays
  103. *
  104. * @param repeat_delay_ms Delay before key auto-repeat starts (in ms)
  105. * @param repeat_rate_ms Delay between successive key repeats (in ms)
  106. */
  107. void input_set_delays(struct input_config *config, int repeat_delay_ms,
  108. int repeat_rate_ms);
  109. /**
  110. * Set up the input handler with basic key maps.
  111. *
  112. * @param config Input state
  113. * @param leds Initial LED value (INPUT_LED_ mask), 0 suggested
  114. * @return 0 if ok, -1 on error
  115. */
  116. int input_init(struct input_config *config, int leds);
  117. #ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
  118. extern int overwrite_console(void);
  119. #define OVERWRITE_CONSOLE overwrite_console()
  120. #else
  121. #define OVERWRITE_CONSOLE 0
  122. #endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */
  123. #endif