input.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_wait(struct wl_input_event *ev, int sleep)
  44. {
  45. /* wl_input_wait() is called from the wikilib mainloop and we will
  46. * get here regularily when the system has no other duty. Hence,
  47. * the only thing we want to do here is go to sleep - the interrupt
  48. * sources are set up and will bring us back to life at some point
  49. */
  50. while (1) {
  51. if (serial_get_event(ev)) {
  52. break;
  53. }
  54. if (touchscreen_get_event(ev)) {
  55. break;
  56. }
  57. if (gpio_get_event(ev)) {
  58. if (ev->key_event.value) {
  59. CTP_flush(); // flush and reset the CTP
  60. }
  61. break;
  62. }
  63. /* no power saving return */
  64. if (!sleep) {
  65. ev->type = -1;
  66. break;
  67. }
  68. /* the timers needed for profiling don't work with suspend enabled */
  69. #if !PROFILER_ON
  70. suspend(TIMEOUT_VALUE);
  71. #endif
  72. // Temperature_control();
  73. }
  74. }