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.

161 lines
5.2 KiB

  1. /*
  2. Copyright 2012 Jun WAKO <wakojun@gmail.com>
  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. #include <stdbool.h>
  31. #include <avr/io.h>
  32. #include <avr/interrupt.h>
  33. #include "news.h"
  34. void news_init(void) { NEWS_KBD_RX_INIT(); }
  35. // RX ring buffer
  36. #define RBUF_SIZE 8
  37. static uint8_t rbuf[RBUF_SIZE];
  38. static uint8_t rbuf_head = 0;
  39. static uint8_t rbuf_tail = 0;
  40. uint8_t news_recv(void) {
  41. uint8_t data = 0;
  42. if (rbuf_head == rbuf_tail) {
  43. return 0;
  44. }
  45. data = rbuf[rbuf_tail];
  46. rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
  47. return data;
  48. }
  49. // USART RX complete interrupt
  50. ISR(NEWS_KBD_RX_VECT) {
  51. uint8_t next = (rbuf_head + 1) % RBUF_SIZE;
  52. if (next != rbuf_tail) {
  53. rbuf[rbuf_head] = NEWS_KBD_RX_DATA;
  54. rbuf_head = next;
  55. }
  56. }
  57. /*
  58. SONY NEWS Keyboard Protocol
  59. ===========================
  60. Resources
  61. ---------
  62. Mouse protocol of NWA-5461(Japanese)
  63. http://groups.google.com/group/fj.sys.news/browse_thread/thread/a01b3e3ac6ae5b2d
  64. SONY NEWS Info(Japanese)
  65. http://katsu.watanabe.name/doc/sonynews/
  66. Pinouts
  67. -------
  68. EIA 232 male connector from NWP-5461
  69. -------------
  70. \ 1 2 3 4 5 /
  71. \ 6 7 8 9 /
  72. ---------
  73. 1 VCC
  74. 2 BZ(Speaker)
  75. 3 Keyboard Data(from keyboard MCU TxD)
  76. 4 NC
  77. 5 GND
  78. 6 Unknown Input(to keyboard MCU RxD via schmitt trigger)
  79. 7 Mouse Data(from Mouse Ext connector)
  80. 8 Unknown Input(to Keyboard MCU Input via diode and buffer)
  81. 9 FG
  82. NOTE: Two LED on keyboard are controlled by pin 6,8?
  83. EIA 232 male connector from NWP-411A
  84. -------------
  85. \ 1 2 3 4 5 /
  86. \ 6 7 8 9 /
  87. ---------
  88. 1 VCC
  89. 2 BZ(Speaker)
  90. 3 Keyboard Data(from keyboard MCU TxD)
  91. 4 NC
  92. 5 GND
  93. 6 NC
  94. 7 Mouse Data(from Mouse Ext connector)
  95. 8 NC
  96. 9 FG
  97. NOTE: These are just from my guess and not confirmed.
  98. Signaling
  99. ---------
  100. ~~~~~~~~~~ ____XOO0X111X222X333X444X555X666X777~~~~ ~~~~~~~
  101. Idle Start LSB MSB Stop Idle
  102. Idle: High
  103. Start bit: Low
  104. Stop bit: High
  105. Bit order: LSB first
  106. Baud rate: 9600
  107. Interface: TTL level(5V) UART
  108. NOTE: This is observed on NWP-5461 with its DIP switch all OFF.
  109. Format
  110. ------
  111. MSB LSB
  112. 7 6 5 4 3 2 1 0 bit
  113. | | | | | | | |
  114. | +-+-+-+-+-+-+-- scan code(00-7F)
  115. +---------------- break flag: sets when released
  116. Scan Codes
  117. ----------
  118. SONY NEWS NWP-5461
  119. ,---. ,------------------------, ,------------------------. ,---------.
  120. | 7A| | 01 | 02 | 03 | 04 | 05 | | 06 | 07 | 08 | 09 | 0A | | 68 | 69 | ,-----------.
  121. `---' `------------------------' `------------------------' `---------' | 64| 65| 52|
  122. ,-------------------------------------------------------------. ,---. ,---------------|
  123. | 0B| 0C| 0D| 0E| 0F| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19 | | 6A| | 4B| 4C| 4D| 4E|
  124. |-------------------------------------------------------------| |---| |---------------|
  125. | 1A | 1B| 1C| 1D| 1E| 1F| 20| 21| 22| 23| 24| 25| 26| 27| | | 6B| | 4F| 50| 51| 56|
  126. |---------------------------------------------------------' | |---| |---------------|
  127. | 28 | 29| 2A| 2B| 2C| 2D| 2E| 2F| 30| 31| 32| 33| 34| 35 | | 6C| | 53| 54| 55| |
  128. |-------------------------------------------------------------| |---| |-----------| 5A|
  129. | 36 | 37| 38| 39| 3A| 3B| 3C| 3D| 3E| 3F| 40| 41| 42 | | 6D| | 57| 59| 58| |
  130. |-------------------------------------------------------------| |---| |---------------|
  131. | 43 | 44 | 45 | 46 | 47 | 48| 49| 4A | | 6E| | 66| 5B| 5C| 5D|
  132. `-------------------------------------------------------------' `---' `---------------'
  133. */