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.

m0110.c 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. /*
  2. Copyright 2011,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. /* M0110A Support was contributed by skagon@github */
  31. #include <stdbool.h>
  32. #include <avr/io.h>
  33. #include <avr/interrupt.h>
  34. #include <util/delay.h>
  35. #include "m0110.h"
  36. #include "debug.h"
  37. static inline uint8_t raw2scan(uint8_t raw);
  38. static inline uint8_t inquiry(void);
  39. static inline uint8_t instant(void);
  40. static inline void clock_lo(void);
  41. static inline void clock_hi(void);
  42. static inline bool clock_in(void);
  43. static inline void data_lo(void);
  44. static inline void data_hi(void);
  45. static inline bool data_in(void);
  46. static inline uint16_t wait_clock_lo(uint16_t us);
  47. static inline uint16_t wait_clock_hi(uint16_t us);
  48. static inline uint16_t wait_data_lo(uint16_t us);
  49. static inline uint16_t wait_data_hi(uint16_t us);
  50. static inline void idle(void);
  51. static inline void request(void);
  52. #define WAIT_US(stat, us, err) do { \
  53. if (!wait_##stat(us)) { \
  54. m0110_error = err; \
  55. goto ERROR; \
  56. } \
  57. } while (0)
  58. #define WAIT_MS(stat, ms, err) do { \
  59. uint16_t _ms = ms; \
  60. while (_ms) { \
  61. if (wait_##stat(1000)) { \
  62. break; \
  63. } \
  64. _ms--; \
  65. } \
  66. if (_ms == 0) { \
  67. m0110_error = err; \
  68. goto ERROR; \
  69. } \
  70. } while (0)
  71. #define KEY(raw) ((raw) & 0x7f)
  72. #define IS_BREAK(raw) (((raw) & 0x80) == 0x80)
  73. uint8_t m0110_error = 0;
  74. void m0110_init(void)
  75. {
  76. uint8_t data;
  77. idle();
  78. _delay_ms(1000);
  79. m0110_send(M0110_MODEL);
  80. data = m0110_recv();
  81. print("m0110_init model: "); phex(data); print("\n");
  82. m0110_send(M0110_TEST);
  83. data = m0110_recv();
  84. print("m0110_init test: "); phex(data); print("\n");
  85. }
  86. uint8_t m0110_send(uint8_t data)
  87. {
  88. m0110_error = 0;
  89. request();
  90. WAIT_MS(clock_lo, 250, 1); // keyboard may block long time
  91. for (uint8_t bit = 0x80; bit; bit >>= 1) {
  92. WAIT_US(clock_lo, 250, 3);
  93. if (data&bit) {
  94. data_hi();
  95. } else {
  96. data_lo();
  97. }
  98. WAIT_US(clock_hi, 200, 4);
  99. }
  100. _delay_us(100); // hold last bit for 80us
  101. idle();
  102. return 1;
  103. ERROR:
  104. print("m0110_send err: "); phex(m0110_error); print("\n");
  105. _delay_ms(500);
  106. idle();
  107. return 0;
  108. }
  109. uint8_t m0110_recv(void)
  110. {
  111. uint8_t data = 0;
  112. m0110_error = 0;
  113. WAIT_MS(clock_lo, 250, 1); // keyboard may block long time
  114. for (uint8_t i = 0; i < 8; i++) {
  115. data <<= 1;
  116. WAIT_US(clock_lo, 200, 2);
  117. WAIT_US(clock_hi, 200, 3);
  118. if (data_in()) {
  119. data |= 1;
  120. }
  121. }
  122. idle();
  123. return data;
  124. ERROR:
  125. print("m0110_recv err: "); phex(m0110_error); print("\n");
  126. _delay_ms(500);
  127. idle();
  128. return 0xFF;
  129. }
  130. /*
  131. Handling for exceptional case of key combinations for M0110A
  132. Shift and Calc/Arrow key could be operated simultaneously:
  133. Case Shift Arrow Events Interpret
  134. -------------------------------------------------------------------
  135. 1 Down Down 71, 79, DD Calc(d)*a *b
  136. 2 Down Up 71, 79, UU Arrow&Calc(u)*a
  137. 3 Up Down F1, 79, DD Shift(u) *c
  138. 4 Up Up F1, 79, UU Shift(u) and Arrow&Calc(u)*a
  139. Case Shift Calc Events Interpret
  140. -------------------------------------------------------------------
  141. 5(1) Down Down 71, 71, 79, DD Shift(d) and Cacl(d)
  142. 6(2) Down Up F1, 71, 79, UU Shift(u) and Arrow&Calc(u)*a
  143. 7(1) Up Down F1, 71, 79, DD Shift(u) and Calc(d)
  144. 8(4) Up Up F1, F1, 79, UU Shift(ux2) and Arrow&Calc(u)*a
  145. During Calc key is hold:
  146. Case Shift Arrow Events Interpret
  147. -------------------------------------------------------------------
  148. A(3) ---- Down F1, 79, DD Shift(u) *c
  149. B ---- Up 79, UU Arrow&Calc(u)*a
  150. C Down ---- F1, 71 Shift(u) and Shift(d)
  151. D Up ---- F1 Shift(u)
  152. E Hold Down 79, DD Normal
  153. F Hold Up 79, UU Arrow&Calc(u)*a
  154. G(1) Down Down F1, 71, 79, DD Shift(u)*b and Calc(d)*a
  155. H(2) Down Up F1, 71, 79, UU Shift(u) and Arrow&Calc(u)*a
  156. I(3) Up Down F1, F1, 79, DD Shift(ux2) *c
  157. J(4) Up Up F1, 79, UU Shift(u) and Arrow&Calc(u)*a
  158. Case Shift Calc Events Interpret
  159. -------------------------------------------------------------------
  160. K(1) ---- Down 71, 79, DD Calc(d)*a
  161. L(4) ---- Up F1, 79, UU Shift(u) and Arrow&Calc(u)*a
  162. M(1) Hold Down 71, 79, DD Calc(d)*a
  163. N Hold Up 79, UU Arrow&Calc(u)*a
  164. Where DD/UU indicates part of Keypad Down/Up event.
  165. *a: Impossible to distinguish btween Arrow and Calc event.
  166. *b: Shift(d) event is ignored.
  167. *c: Arrow/Calc(d) event is ignored.
  168. */
  169. uint8_t m0110_recv_key(void)
  170. {
  171. static uint8_t keybuf = 0x00;
  172. static uint8_t keybuf2 = 0x00;
  173. static uint8_t rawbuf = 0x00;
  174. uint8_t raw, raw2, raw3;
  175. if (keybuf) {
  176. raw = keybuf;
  177. keybuf = 0x00;
  178. return raw;
  179. }
  180. if (keybuf2) {
  181. raw = keybuf2;
  182. keybuf2 = 0x00;
  183. return raw;
  184. }
  185. if (rawbuf) {
  186. raw = rawbuf;
  187. rawbuf = 0x00;
  188. } else {
  189. raw = instant(); // Use INSTANT for better response. Should be INQUIRY ?
  190. }
  191. switch (KEY(raw)) {
  192. case M0110_KEYPAD:
  193. raw2 = instant();
  194. switch (KEY(raw2)) {
  195. case M0110_ARROW_UP:
  196. case M0110_ARROW_DOWN:
  197. case M0110_ARROW_LEFT:
  198. case M0110_ARROW_RIGHT:
  199. if (IS_BREAK(raw2)) {
  200. // Case B,F,N:
  201. keybuf = (raw2scan(raw2) | M0110_CALC_OFFSET); // Calc(u)
  202. return (raw2scan(raw2) | M0110_KEYPAD_OFFSET); // Arrow(u)
  203. }
  204. break;
  205. }
  206. // Keypad or Arrow
  207. return (raw2scan(raw2) | M0110_KEYPAD_OFFSET);
  208. break;
  209. case M0110_SHIFT:
  210. raw2 = instant();
  211. switch (KEY(raw2)) {
  212. case M0110_SHIFT:
  213. // Case: 5-8,C,G,H
  214. rawbuf = raw2;
  215. return raw2scan(raw); // Shift(d/u)
  216. break;
  217. case M0110_KEYPAD:
  218. // Shift + Arrow, Calc, or etc.
  219. raw3 = instant();
  220. switch (KEY(raw3)) {
  221. case M0110_ARROW_UP:
  222. case M0110_ARROW_DOWN:
  223. case M0110_ARROW_LEFT:
  224. case M0110_ARROW_RIGHT:
  225. if (IS_BREAK(raw)) {
  226. if (IS_BREAK(raw3)) {
  227. // Case 4:
  228. print("(4)\n");
  229. keybuf2 = raw2scan(raw); // Shift(u)
  230. keybuf = (raw2scan(raw3) | M0110_CALC_OFFSET); // Calc(u)
  231. return (raw2scan(raw3) | M0110_KEYPAD_OFFSET); // Arrow(u)
  232. } else {
  233. // Case 3:
  234. print("(3)\n");
  235. return (raw2scan(raw)); // Shift(u)
  236. }
  237. } else {
  238. if (IS_BREAK(raw3)) {
  239. // Case 2:
  240. print("(2)\n");
  241. keybuf = (raw2scan(raw3) | M0110_CALC_OFFSET); // Calc(u)
  242. return (raw2scan(raw3) | M0110_KEYPAD_OFFSET); // Arrow(u)
  243. } else {
  244. // Case 1:
  245. print("(1)\n");
  246. return (raw2scan(raw3) | M0110_CALC_OFFSET); // Calc(d)
  247. }
  248. }
  249. break;
  250. default:
  251. // Shift + Keypad
  252. keybuf = (raw2scan(raw3) | M0110_KEYPAD_OFFSET);
  253. return raw2scan(raw); // Shift(d/u)
  254. break;
  255. }
  256. break;
  257. default:
  258. // Shift + Normal keys
  259. keybuf = raw2scan(raw2);
  260. return raw2scan(raw); // Shift(d/u)
  261. break;
  262. }
  263. break;
  264. default:
  265. // Normal keys
  266. return raw2scan(raw);
  267. break;
  268. }
  269. }
  270. static inline uint8_t raw2scan(uint8_t raw) {
  271. return (raw == M0110_NULL) ? M0110_NULL : (
  272. (raw == M0110_ERROR) ? M0110_ERROR : (
  273. ((raw&0x80) | ((raw&0x7F)>>1))
  274. )
  275. );
  276. }
  277. static inline uint8_t inquiry(void)
  278. {
  279. m0110_send(M0110_INQUIRY);
  280. return m0110_recv();
  281. }
  282. static inline uint8_t instant(void)
  283. {
  284. m0110_send(M0110_INSTANT);
  285. uint8_t data = m0110_recv();
  286. if (data != M0110_NULL) {
  287. phex(data); print(" ");
  288. }
  289. return data;
  290. }
  291. static inline void clock_lo()
  292. {
  293. M0110_CLOCK_PORT &= ~(1<<M0110_CLOCK_BIT);
  294. M0110_CLOCK_DDR |= (1<<M0110_CLOCK_BIT);
  295. }
  296. static inline void clock_hi()
  297. {
  298. /* input with pull up */
  299. M0110_CLOCK_DDR &= ~(1<<M0110_CLOCK_BIT);
  300. M0110_CLOCK_PORT |= (1<<M0110_CLOCK_BIT);
  301. }
  302. static inline bool clock_in()
  303. {
  304. M0110_CLOCK_DDR &= ~(1<<M0110_CLOCK_BIT);
  305. M0110_CLOCK_PORT |= (1<<M0110_CLOCK_BIT);
  306. _delay_us(1);
  307. return M0110_CLOCK_PIN&(1<<M0110_CLOCK_BIT);
  308. }
  309. static inline void data_lo()
  310. {
  311. M0110_DATA_PORT &= ~(1<<M0110_DATA_BIT);
  312. M0110_DATA_DDR |= (1<<M0110_DATA_BIT);
  313. }
  314. static inline void data_hi()
  315. {
  316. /* input with pull up */
  317. M0110_DATA_DDR &= ~(1<<M0110_DATA_BIT);
  318. M0110_DATA_PORT |= (1<<M0110_DATA_BIT);
  319. }
  320. static inline bool data_in()
  321. {
  322. M0110_DATA_DDR &= ~(1<<M0110_DATA_BIT);
  323. M0110_DATA_PORT |= (1<<M0110_DATA_BIT);
  324. _delay_us(1);
  325. return M0110_DATA_PIN&(1<<M0110_DATA_BIT);
  326. }
  327. static inline uint16_t wait_clock_lo(uint16_t us)
  328. {
  329. while (clock_in() && us) { asm(""); _delay_us(1); us--; }
  330. return us;
  331. }
  332. static inline uint16_t wait_clock_hi(uint16_t us)
  333. {
  334. while (!clock_in() && us) { asm(""); _delay_us(1); us--; }
  335. return us;
  336. }
  337. static inline uint16_t wait_data_lo(uint16_t us)
  338. {
  339. while (data_in() && us) { asm(""); _delay_us(1); us--; }
  340. return us;
  341. }
  342. static inline uint16_t wait_data_hi(uint16_t us)
  343. {
  344. while (!data_in() && us) { asm(""); _delay_us(1); us--; }
  345. return us;
  346. }
  347. static inline void idle(void)
  348. {
  349. clock_hi();
  350. data_hi();
  351. }
  352. static inline void request(void)
  353. {
  354. clock_hi();
  355. data_lo();
  356. }
  357. /*
  358. Primitive M0110 Library for AVR
  359. ==============================
  360. Signaling
  361. ---------
  362. CLOCK is always from KEYBOARD. DATA are sent with MSB first.
  363. 1) IDLE: both lines are high.
  364. CLOCK ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  365. DATA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  366. 2) KEYBOARD->HOST: HOST reads bit on rising edge.
  367. CLOCK ~~~~~~~~~~~~|__|~~~|__|~~~|__|~~~|__|~~~|__|~~~|__|~~~|__|~~~|__|~~~~~~~~~~~
  368. DATA ~~~~~~~~~~~~X777777X666666X555555X444444X333333X222222X111111X000000X~~~~~~~
  369. <--> 160us(clock low)
  370. <---> 180us(clock high)
  371. 3) HOST->KEYBOARD: HOST asserts bit on falling edge.
  372. CLOCK ~~~~~~~~~~~~|__|~~~|__|~~~|__|~~~|__|~~~|__|~~~|__|~~~|__|~~~|__|~~~~~~~~~~~
  373. DATA ~~~~~~|_____X777777X666666X555555X444444X333333X222222X111111X000000X~~~~~~~
  374. <----> 840us(request to send by host) <---> 80us(hold DATA)
  375. <--> 180us(clock low)
  376. <---> 220us(clock high)
  377. Protocol
  378. --------
  379. COMMAND:
  380. Inquiry 0x10 get key event with block
  381. Instant 0x12 get key event
  382. Model 0x14 get model number(M0110 responds with 0x09)
  383. bit 7 1 if another device connected(used when keypad exists?)
  384. bit4-6 next device model number
  385. bit1-3 keyboard model number
  386. bit 0 always 1
  387. Test 0x16 test(ACK:0x7D/NAK:0x77)
  388. KEY EVENT:
  389. bit 7 key state(0:press 1:release)
  390. bit 6-1 scan code(see below)
  391. bit 0 always 1
  392. To get scan code use this: ((bits&(1<<7)) | ((bits&0x7F))>>1).
  393. Note: On the M0110A, Keypad keys and Arrow keys are preceded by 0x79.
  394. Moreover, some Keypad keys(=, /, * and +) are preceded by 0x71 on press and 0xF1 on release.
  395. ARROW KEYS:
  396. Arrow keys and Calc keys(+,*,/,= on keypad) share same byte sequence and preceding byte of
  397. Calc keys(0x71 and 0xF1) means press and release event of SHIFT. This causes a very confusing situation,
  398. it is difficult or impossible to tell Calc key from Arrow key plus SHIFT in some cases.
  399. Raw key events:
  400. press release
  401. ---------------- ----------------
  402. Left: 0x79, 0x0D 0x79, 0x8D
  403. Right: 0x79, 0x05 0x79, 0x85
  404. Up: 0x79, 0x1B 0x79, 0x9B
  405. Down: 0x79, 0x11 0x79, 0x91
  406. Pad+: 0x71, 0x79, 0x0D 0xF1, 0x79, 0x8D
  407. Pad*: 0x71, 0x79, 0x05 0xF1, 0x79, 0x85
  408. Pad/: 0x71, 0x79, 0x1B 0xF1, 0x79, 0x9B
  409. Pad=: 0x71, 0x79, 0x11 0xF1, 0x79, 0x91
  410. RAW CODE:
  411. M0110A
  412. ,---------------------------------------------------------. ,---------------.
  413. | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Bcksp| |Clr| =| /| *|
  414. |---------------------------------------------------------| |---------------|
  415. |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| | | 7| 8| 9| -|
  416. |-----------------------------------------------------' | |---------------|
  417. |CapsLo| A| S| D| F| G| H| J| K| L| ;| '|Return| | 4| 5| 6| +|
  418. |---------------------------------------------------------| |---------------|
  419. |Shift | Z| X| C| V| B| N| M| ,| ,| /|Shft|Up | | 1| 2| 3| |
  420. |---------------------------------------------------------' |-----------|Ent|
  421. |Optio|Mac | Space | \|Lft|Rgt|Dn | | 0| .| |
  422. `---------------------------------------------------------' `---------------'
  423. ,---------------------------------------------------------. ,---------------.
  424. | 65| 25| 27| 29| 2B| 2F| 2D| 35| 39| 33| 3B| 37| 31| 67| |+0F|*11|*1B|*05|
  425. |---------------------------------------------------------| |---------------|
  426. | 61| 19| 1B| 1D| 1F| 23| 21| 41| 45| 3F| 47| 43| 3D| | |+33|+37|+39|+1D|
  427. |-----------------------------------------------------' | |---------------|
  428. | 73| 01| 03| 05| 07| 0B| 09| 4D| 51| 4B| 53| 4F| 49| |+2D|+2F|+31|*0D|
  429. |---------------------------------------------------------| |---------------|
  430. | 71| 0D| 0F| 11| 13| 17| 5B| 5D| 27| 5F| 59| 71|+1B| |+27|+29|+2B| |
  431. |---------------------------------------------------------' |-----------|+19|
  432. | 75| 6F| 63 | 55|+0D|+05|+11| | +25|+03| |
  433. `---------------------------------------------------------' `---------------'
  434. + 0x79, 0xDD / 0xF1, 0xUU
  435. * 0x71, 0x79,DD / 0xF1, 0x79, 0xUU
  436. MODEL NUMBER:
  437. M0110: 0x09 00001001 : model number 4 (100)
  438. M0110A: 0x0B 00001011 : model number 5 (101)
  439. M0110 & M0120: ???
  440. Scan Code
  441. ---------
  442. m0110_recv_key() function returns following scan codes instead of raw key events.
  443. Scan codes are 1 byte long and MSB(bit7) is set when key is released.
  444. M0110
  445. ,---------------------------------------------------------.
  446. | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backs|
  447. |---------------------------------------------------------|
  448. |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \|
  449. |---------------------------------------------------------|
  450. |CapsLo| A| S| D| F| G| H| J| K| L| ;| '|Return|
  451. |---------------------------------------------------------|
  452. |Shift | Z| X| C| V| B| N| M| ,| ,| /| |
  453. `---------------------------------------------------------'
  454. |Opt|Mac | Space |Enter|Opt|
  455. `------------------------------------------------'
  456. ,---------------------------------------------------------.
  457. | 32| 12| 13| 14| 15| 17| 16| 1A| 1C| 19| 1D| 1B| 18| 33|
  458. |---------------------------------------------------------|
  459. | 30| 0C| 0D| 0E| 0F| 10| 11| 20| 22| 1F| 23| 21| 1E| 2A|
  460. |---------------------------------------------------------|
  461. | 39| 00| 01| 02| 03| 05| 04| 26| 28| 25| 29| 27| 24|
  462. |---------------------------------------------------------|
  463. | 38| 06| 07| 08| 09| 0B| 2D| 2E| 2B| 2F| 2C| 38|
  464. `---------------------------------------------------------'
  465. | 3A| 37| 31 | 34| 3A|
  466. `------------------------------------------------'
  467. M0110A
  468. ,---------------------------------------------------------. ,---------------.
  469. | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Bcksp| |Clr| =| /| *|
  470. |---------------------------------------------------------| |---------------|
  471. |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| | | 7| 8| 9| -|
  472. |-----------------------------------------------------' | |---------------|
  473. |CapsLo| A| S| D| F| G| H| J| K| L| ;| '|Return| | 4| 5| 6| +|
  474. |---------------------------------------------------------| |---------------|
  475. |Shift | Z| X| C| V| B| N| M| ,| ,| /|Shft|Up | | 1| 2| 3| |
  476. |---------------------------------------------------------' |-----------|Ent|
  477. |Optio|Mac | Space | \|Lft|Rgt|Dn | | 0| .| |
  478. `---------------------------------------------------------' `---------------'
  479. ,---------------------------------------------------------. ,---------------.
  480. | 32| 12| 13| 14| 15| 17| 16| 1A| 1C| 19| 1D| 1B| 18| 33| | 47| 68| 6D| 62|
  481. |---------------------------------------------------------| |---------------|
  482. | 30| 0C| 0D| 0E| 0F| 10| 11| 20| 22| 1F| 23| 21| 1E| | | 59| 5B| 5C| 4E|
  483. |-----------------------------------------------------' | |---------------|
  484. | 39| 00| 01| 02| 03| 05| 04| 26| 28| 25| 29| 27| 24| | 56| 57| 58| 66|
  485. |---------------------------------------------------------| |---------------|
  486. | 38| 06| 07| 08| 09| 0B| 2D| 2E| 2B| 2F| 2C| 38| 4D| | 53| 54| 55| |
  487. |---------------------------------------------------------' |-----------| 4C|
  488. | 3A| 37| 31 | 2A| 46| 42| 48| | 52| 41| |
  489. `---------------------------------------------------------' `---------------'
  490. References
  491. ----------
  492. Technical Info for 128K/512K and Plus
  493. ftp://ftp.apple.asimov.net/pub/apple_II/documentation/macintosh/Mac%20Hardware%20Info%20-%20Mac%20128K.pdf
  494. ftp://ftp.apple.asimov.net/pub/apple_II/documentation/macintosh/Mac%20Hardware%20Info%20-%20Mac%20Plus.pdf
  495. Protocol:
  496. Page 20 of Tech Info for 128K/512K
  497. http://www.mac.linux-m68k.org/devel/plushw.php
  498. Connector:
  499. Page 20 of Tech Info for 128K/512K
  500. http://www.kbdbabel.org/conn/kbd_connector_macplus.png
  501. Signaling:
  502. http://www.kbdbabel.org/signaling/kbd_signaling_mac.png
  503. http://typematic.blog.shinobi.jp/Entry/14/
  504. Scan Codes:
  505. Page 22 of Tech Info for 128K/512K
  506. Page 07 of Tech Info for Plus
  507. http://m0115.web.fc2.com/m0110.jpg
  508. http://m0115.web.fc2.com/m0110a.jpg
  509. */