gpio.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * buttons handler
  3. *
  4. * Copyright (c) 2009 Openmoko Inc.
  5. *
  6. * Authors Daniel Mack <daniel@caiaq.de>
  7. * Christopher Hall <hsw@openmoko.com>
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. #include <stdio.h>
  23. #include <input.h>
  24. #include <regs.h>
  25. #include <samo.h>
  26. #include <wikilib.h>
  27. #include <button.h>
  28. #include "gpio.h"
  29. #if BOARD_SAMO_Ax || BOARD_SAMO_Vx
  30. static const int keymap[] = {
  31. WL_INPUT_KEY_RANDOM,
  32. WL_INPUT_KEY_SEARCH,
  33. WL_INPUT_KEY_HISTORY,
  34. WL_INPUT_KEY_POWER,
  35. };
  36. #else
  37. static const int keymap[] = {
  38. WL_INPUT_KEY_SEARCH,
  39. WL_INPUT_KEY_HISTORY,
  40. WL_INPUT_KEY_RANDOM,
  41. WL_INPUT_KEY_POWER,
  42. };
  43. #endif
  44. static ButtonType button;
  45. static bool pressed;
  46. static bool event_cached;
  47. bool gpio_event_pending(void)
  48. {
  49. if (event_cached || Button_get(&button, &pressed))
  50. {
  51. event_cached = true;
  52. }
  53. return event_cached;
  54. }
  55. bool gpio_get_event(struct wl_input_event *ev)
  56. {
  57. if (!event_cached && !Button_get(&button, &pressed)) {
  58. return false;
  59. }
  60. event_cached = false;
  61. ev->type = WL_INPUT_EV_TYPE_KEYBOARD;
  62. ev->key_event.keycode = keymap[button];
  63. ev->key_event.value = pressed;
  64. return true;
  65. }
  66. void gpio_init(void)
  67. {
  68. event_cached = false;
  69. Button_initialise();
  70. }