Mirror of CollapseOS
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

80 linhas
2.9KB

  1. # Interfacing a PS/2 keyboard
  2. Collapse OS needs a way to input commands and keyboards are one
  3. of the most straightforward ways to proceed. The PS/2 protocol
  4. is very widespread and relatively simple.
  5. We explain here how to interface a PS/2 keyboard with a RC2014.
  6. # Gathering parts
  7. * A RC2014 Classic that could install the base recipe
  8. * A PS/2 keyboard. A USB keyboard + adapter also works, if it's
  9. not too recent (if it still speaks PS/2).
  10. * A PS/2 female connector.
  11. * ATtiny85/45/25 (main MCU for the device)
  12. * 74xx595 (shift register)
  13. * 40106 inverter gates
  14. * Diodes for A*, IORQ, RO.
  15. * Proto board, RC2014 header pins, wires, IC sockets, etc.
  16. * AVRA (https://github.com/hsoft/avra). The code for this recipe
  17. hasn't been translated to Collapse OS' AVR assembler yet.
  18. # Building the PS/2 interface
  19. Let's start with the PS/2 connector (see img/ps2-conn.png),
  20. which has two pins.
  21. Both are connected to the ATtiny45, CLK being on PB2 to have
  22. INT0 on it.
  23. The DATA line is multi-use. That is, PB1 is connected both to
  24. the PS/2 data line and to the 595's SER. This saves us a
  25. precious pin.
  26. The ATtiny 45 (img/ps2-t45.png) hooks everything together. CE
  27. comes from the z80 bus (img/ps2-z80.png).
  28. The 595 (img/ps2-595.png) allows us to supply the z80 bus with
  29. data within its 375ns limits. SRCLR is hooked to the CE line so
  30. that whenever a byte is read, the 595 is zeroed out as fast as
  31. possible so that the z80 doesn't read "false doubles".
  32. The 595, to have its SRCLR becoming effective, needs a RCLK
  33. trigger, which doesn't happen immediately. It's the ATtiny45, in
  34. its PCINT interrupt, that takes care of doing that trigger (as
  35. fast as possible).
  36. Our device is read only, on one port. That makes the "Chip
  37. Enable" (CE) selection rather simple. In my design, I chose the
  38. IO port 8, so I inverted A3. I chose a 40106 inverter to do
  39. that, do as you please for your own design.
  40. I wanted to hook CE to a flip flop so that the MCU could relax a
  41. bit more w.r.t. reacting to its PB4 pin changes, but I didn't
  42. have NAND gates that are fast enough in stock, so I went with
  43. this design. But otherwise, I would probably have gone the
  44. flip-flop way. Seems more solid.
  45. Then, all you need to do is to assemble code/ps2ctl.asm and load
  46. it onto your ATtiny.
  47. # Using the PS/2 interface
  48. To use this interface, you have to build a new Collapse OS
  49. binary. This binary needs two things.
  50. First, we need a "(ps2kc)" routine (see doc/protocol.txt). In
  51. this case, it's easy, it's ": (ps2kc) 8 PC@ ;". Then, we can
  52. load PS/2 subsystem. You add "411 414 LOADR". Then, at
  53. initialization, you add "PS2$". You also need to define PS2_MEM
  54. at the top. You can probably use "SYSVARS + 0xaa".
  55. The PS/2 subsystem provides "(key)" from "(ps2kc)".
  56. For debugging purposes, you might not want to go straight to
  57. plugging PS/2 "(key)" into the system. What I did myself was to
  58. load the PS/2 subsystem *before* ACIA (which overrides with its
  59. own "(key)") and added a dummy word in between to access PS/2's
  60. key.