input.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Event hanndling
  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 <stdlib.h>
  23. #include <guilib.h>
  24. #include <wikilib.h>
  25. #include <input.h>
  26. #include <regs.h>
  27. #include <samo.h>
  28. #include <suspend.h>
  29. //#include <temperature.h>
  30. #include <ctp.h>
  31. #include "serial.h"
  32. #include "touchscreen.h"
  33. #include "gpio.h"
  34. // the / 32 is because the suspend routine operates with MCLK=CLK/32
  35. #define TIMEOUT_VALUE (MCLK / 32 * SUSPEND_AUTO_POWER_OFF_SECONDS)
  36. #if TIMEOUT_VALUE > 0x3fffffff
  37. #error "SUSPEND_AUTO_POWER_OFF_SECONDS is too large"
  38. #endif
  39. bool wl_input_event_pending(void)
  40. {
  41. return serial_event_pending() || touchscreen_event_pending() || gpio_event_pending();
  42. }
  43. void wl_input_reset_random_key(void)
  44. {
  45. struct wl_input_event ev;
  46. while (gpio_peek_event(&ev) && ev.key_event.keycode == WL_INPUT_KEY_RANDOM)
  47. {
  48. gpio_get_event(&ev);
  49. if (ev.key_event.value) {
  50. CTP_flush(); // flush and reset the CTP
  51. }
  52. }
  53. }
  54. void wl_input_wait(struct wl_input_event *ev, int sleep)
  55. {
  56. /* wl_input_wait() is called from the wikilib mainloop and we will
  57. * get here regularily when the system has no other duty. Hence,
  58. * the only thing we want to do here is go to sleep - the interrupt
  59. * sources are set up and will bring us back to life at some point
  60. */
  61. while (1) {
  62. if (serial_get_event(ev)) {
  63. break;
  64. }
  65. if (touchscreen_get_event(ev)) {
  66. break;
  67. }
  68. if (gpio_get_event(ev)) {
  69. if (ev->key_event.value) {
  70. CTP_flush(); // flush and reset the CTP
  71. }
  72. break;
  73. }
  74. /* no power saving return */
  75. if (!sleep) {
  76. ev->type = -1;
  77. break;
  78. }
  79. /* the timers needed for profiling don't work with suspend enabled */
  80. #if !PROFILER_ON
  81. suspend(TIMEOUT_VALUE);
  82. #endif
  83. // Temperature_control();
  84. }
  85. }