You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

xt_interrupt.c 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. Copyright 2010,2011,2012,2013 Jun WAKO <[email protected]>
  3. This software is licensed with a Modified BSD License.
  4. All of this is supposed to be Free Software, Open Source, DFSG-free,
  5. GPL-compatible, and OK to use in both free and proprietary applications.
  6. Additions and corrections to this file are welcome.
  7. Redistribution and use in source and binary forms, with or without
  8. modification, are permitted provided that the following conditions are met:
  9. * Redistributions of source code must retain the above copyright
  10. notice, this list of conditions and the following disclaimer.
  11. * Redistributions in binary form must reproduce the above copyright
  12. notice, this list of conditions and the following disclaimer in
  13. the documentation and/or other materials provided with the
  14. distribution.
  15. * Neither the name of the copyright holders nor the names of
  16. contributors may be used to endorse or promote products derived
  17. from this software without specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  22. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. /*
  31. * PS/2 protocol Pin interrupt version
  32. */
  33. #include <stdbool.h>
  34. #include <avr/interrupt.h>
  35. #include <util/delay.h>
  36. #include "pbuff.h"
  37. #include "xt.h"
  38. #include "xt_io.h"
  39. #include "wait.h"
  40. #include "print.h"
  41. void xt_host_init(void)
  42. {
  43. XT_INT_INIT();
  44. XT_INT_ON();
  45. }
  46. /* get data received by interrupt */
  47. uint8_t xt_host_recv(void)
  48. {
  49. if (pbuf_has_data()) {
  50. return pbuf_dequeue();
  51. } else {
  52. return 0;
  53. }
  54. }
  55. ISR(XT_INT_VECT)
  56. {
  57. static uint8_t state = 0;
  58. static uint8_t data = 0;
  59. if (state == 0) {
  60. if (data_in())
  61. state++;
  62. } else if (state >= 1 && state <= 8) {
  63. wait_clock_lo(20);
  64. data >>= 1;
  65. if (data_in())
  66. data |= 0x80;
  67. if (state == 8)
  68. goto END;
  69. state++;
  70. } else {
  71. goto DONE;
  72. }
  73. goto RETURN;
  74. END:
  75. pbuf_enqueue(data);
  76. DONE:
  77. state = 0;
  78. data = 0;
  79. RETURN:
  80. return;
  81. }