Keyboard firmwares for Atmel AVR and Cortex-M
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.

news.c 5.2KB

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