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.

133 lines
6.1 KiB

  1. /* Copyright 2017-2019 Nikolaus Wittenstein <nikolaus.wittenstein@gmail.com>
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  8. * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9. * FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  12. * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. * PERFORMANCE OF THIS SOFTWARE.
  14. */
  15. #pragma once
  16. #include "quantum.h"
  17. /* This a shortcut to help you visually see your layout.
  18. * The first section contains all of the arguements; the second converts the arguments into a two-dimensional array.
  19. */
  20. /* Each code is three letters
  21. * l or r - left or right hand
  22. * p, r, m, i, t - pinky, ring finger, middle finger, index finger, thumb
  23. * fingers: n, s, e, w, c - north, south, east, west, and center (manual calls this "well" but we already have "west")
  24. * thumb: p, n, c, l, u, k - pad, nail, center, lock (harder center), up, knuckle
  25. */
  26. #define LAYOUT( \
  27. lpn, lrn, lmn, lin, rin, rmn, rrn, rpn, \
  28. lpw, lpc, lpe, lrw, lrc, lre, lmw, lmc, lme, liw, lic, lie, riw, ric, rie, rmw, rmc, rme, rrw, rrc, rre, rpw, rpc, rpe, \
  29. lps, lrs, lms, lis, ris, rms, rrs, rps, \
  30. ltp, ltn, rtn, rtp, \
  31. ltc, rtc, \
  32. ltl, rtl, \
  33. ltu, ltk, rtk, rtu) \
  34. { \
  35. {riw, rin, lpw, lpn},\
  36. {ric, rie, lpc, lpe},\
  37. {ris, rms, lps, lrs},\
  38. {rmw, rmn, lrw, lrn},\
  39. {rmc, rme, lrc, lre},\
  40. {rrw, rrn, lmw, lmn},\
  41. {rrc, rre, lmc, lme},\
  42. {rrs, rps, lms, lis},\
  43. {rpw, rpn, liw, lin},\
  44. {rpc, rpe, lic, lie},\
  45. {rtk, rtn, ltk, ltn},\
  46. {rtc, rtl, ltc, ltl},\
  47. {rtp, rtu, ltp, ltu},\
  48. }
  49. /* Mode LEDs are active-low on Port B on the Teensy. */
  50. #define LED_MODE_PORT PORTB
  51. #define LED_TENKEY (1<<3)
  52. #define LED_FN (1<<4)
  53. #define LED_NORMAL (1<<5)
  54. #define LED_NAS (1<<6)
  55. /* Lock LEDs are active-low on Port F on the Teensy. */
  56. #define LED_LOCK_PORT PORTF
  57. #define LED_CAPS_LOCK (1<<4)
  58. #define LED_MOUSE_LOCK (1<<5)
  59. #define LED_NUM_LOCK (1<<6)
  60. #define LED_SCROLL_LOCK (1<<7)
  61. /* Appendix:
  62. * Table based on https://geekhack.org/index.php?topic=12212.msg2059319#msg2059319
  63. * Some pin assignments (e.g. for PS/2 I/O) have been fixed.
  64. *
  65. * Teensy Datahand 8051 pin pin 8051 Datahand Teensy
  66. * ------ -------- ---- --- --- ---- -------- ------
  67. * GND Mtrx send A P1.0 1 40 VCC VCC VCC
  68. * PB7 Mtrx send B P1.1 2 39 P0.0 LED RH NAS PB6
  69. * PD0 Mtrx send C P1.2 3 38 P0.1 LED RH NORM PB5
  70. * PD1 Mtrx send D P1.3 4 37 P0.2 LED RH FCTN PB4
  71. * PD2 RH rcv 0 P1.4 5 36 P0.3 LED RH 10K PB3
  72. * PD3 RH rcv 1 P1.5 6 35 P0.4 LED RH unused PB2
  73. * PD4 LH rcv 0 P1.6 7 34 P0.5 LED RH unused PE1
  74. * PD5 LH rcv 1 P1.7 8 33 P0.6 LED RH unused PE0
  75. * PD6 Reset button RST 9 32 P0.7 ? PE7
  76. * PD7 ? P3.0 10 31 VPP - PE6
  77. * PE0 ? P3.1 11 30 ALE - GND
  78. * PE1 kbd data P3.2 12 29 PSEN - AREF
  79. * PC0 ? P3.3 13 28 P2.7 ? PF0
  80. * PC1 kbd clk P3.4 14 27 P2.6 ? PF1
  81. * PC2 ? P3.5 15 26 P2.5 ? PF2
  82. * PC3 RAM P3.6 16 25 P2.4 ? PF3
  83. * PC4 RAM P3.7 17 24 P2.3 LED D15 LH (CAPLK) PF4
  84. * PC5 XTAL2 XTAL2 18 23 P2.2 LED D13 LH (MSELK) PF5
  85. * PC6 XTAL1 XTAL1 19 22 P2.1 LED D6 LH (NUMLK) PF6
  86. * PC7 GND GND 20 21 P2.0 LED D14 LH (SCRLK) PF7
  87. *
  88. * JP3 Pinout
  89. * 2 - keyboard data
  90. * 3 - keyboard clock
  91. *
  92. * In order to get the Teensy to work, we need to move pin 1 to a different pin. This is
  93. * because on the Teensy pin 1 is ground, but we need to write to pin 1 in order to read
  94. * the keyboard matrix. An ideal pin to move it to is VPP (pin 31), because this pin tells
  95. * the 8051 whether it should read from external or internal memory. The Teensy doesn't
  96. * care about that.
  97. *
  98. * The easiest way to reassign the pin is to use standoffs. You can check out this thread:
  99. * https://geekhack.org/index.php?topic=12212.msg235382#msg235382 for a picture of what
  100. * this looks like. Note that in the picture the pin has been reassigned to pin 12. We
  101. * don't want to do that because we're going to use that pin to send data over PS/2.
  102. *
  103. * We could if we wanted also reassign the PS/2 pins to Teensy hardware UART pins, but
  104. * that's more work. Instead we'll just bit-bang PS/2 because it's an old, slow protocol
  105. * (and because there's already a bit-banged PS/2 host implementation in QMK - we just
  106. * need to add the device side).
  107. *
  108. * So overall, we want the following inputs and outputs:
  109. * Outputs:
  110. * Matrix:
  111. * PB7
  112. * PD0
  113. * PD1
  114. * PE6 (moved from pin1, GND)
  115. * LEDs:
  116. * PB3-6
  117. * PF4-7
  118. * Inputs:
  119. * Matrix:
  120. * PD2-5
  121. * I/Os (start up as inputs):
  122. * PS/2:
  123. * PC1
  124. * PE1
  125. */