Skip to content
Permalink
Browse files

Added test Arduino sketch.

Updated docs.
  • Loading branch information...
thejpster committed Feb 4, 2019
1 parent 09a06bd commit c5ec1109ed8c9199d2ea761df2676e7a16433b2b
Showing with 81 additions and 1 deletion.
  1. +9 −1 README.md
  2. +3 −0 avr_kb/README.md
  3. +69 −0 avr_kb/keyboard/keyboard.ino
@@ -344,6 +344,13 @@ On the [Monotron PCB](#monotron-pcb) I work around this issue by adding an
Atmel AtMega48 microcontroller as an I/O expander, connected to [UART](#uart)
7. Look in the [`avr_kb`](./avr_kb) folder for more information.

__Note:__ There's a bug in the 0.7.0 PCB where both PS/2 connector pinouts are
mirror image, compared to how they should be. It happened because although the
connector drawings said "Bottom View" quite clearly, I didn't pay enough
attention and assumed they were viewed from above! To use the PS/2 connectors,
they must be fitted to the underside of the PCB (i.e. opposite to all the
other connectors). This will be fixed in the next PCB revision.

### MIDI

The [Monotron PCB](#monotron-pcb) has three 5-pin DIN MIDI ports: In, Out and
@@ -354,7 +361,8 @@ Through. These are connected to UART 3.
The 25-pin Parallel Printer Port is connected to the Monotron PCB's AtMega48
I/O controller. You send commands to the AtMega to get it to drive the printer
port. Currently only SPP (classic mono-directional support as found on the
original IBM PC). Support for the fancier EPP and ECP modes is TBD.
original IBM PC) is planned for support. Support for the fancier EPP and ECP
modes is TBD.

## Monotron PCB

@@ -12,6 +12,9 @@ Atmega48, and it controls the:
It talks to the main Monotron MCU over a serial link at 115,200 bps (8-data
bits, no parity, 1 stop bit).

NB: As an interim test, there's an Arduino sketch in the `keyboard` folder
which just emits raw scan-codes over the UART at 19,200 baud.

## Compilation

This firmware builds with `avr-gcc` and `meson`.
@@ -0,0 +1,69 @@
/**
* Monotron I/O Controller.
*
* Copyright (c) Jonathan 'theJPster' Pallant 2019
*
* Licensed under the MIT or Apache 2.0 licences, at your option.
*
* Note that Arduino libraries are licensed under the LGPL, and so anyone
* in receipt of a binary version of this firmware must also receive this
* file as either source code or a .o file suitable for re-linking.
*/

// The Keyboard Clock pin (PC0)
const int KB_CLK = A0;
// The Mouse Clock pin (PC1)
const int MS_CLK = A1;
// The Keyboard Data pin (PC2)
const int KB_DATA = A2;
// The Mouse Data pin (PC2)
const int MS_DATA = A3;

/**
* Executed once on startup.
*/
void setup(void) {
// Configure the pins
pinMode(KB_CLK, INPUT_PULLUP);
pinMode(KB_DATA, INPUT_PULLUP);
pinMode(MS_CLK, INPUT_PULLUP);
pinMode(MS_DATA, INPUT_PULLUP);
// Communication with the MCU
Serial.begin(19200);
}

/**
* Main execution loop.
*
* Checks for falling edges on the clock pins. When a falling edge is seen,
* data bits are clocked in. When enough data bits have been seen PS/2 communication
* is prevented (by holding CLK low) while we send the received data over the UART.
*/
void loop(void) {
static bool old_kb_clk_pin = true;
static uint16_t kb_word = 0;
static uint8_t kb_num_bits = 0;

bool kb_clk_pin = digitalRead(KB_CLK);
// capture data on falling edge
if (old_kb_clk_pin && !kb_clk_pin) {
if (digitalRead(KB_DATA)) {
kb_word |= (1 << kb_num_bits);
}
kb_num_bits++;
if (kb_num_bits == 11) {
// Shut the keyboard and mouse down for a moment
pinMode(KB_CLK, OUTPUT);
digitalWrite(KB_CLK, LOW);
// Print the word we just read. We shift by one to trim the start bit (0)
// and mask with 0xFF to trim the stop and parity bits.
Serial.print((char) ((kb_word >> 1) & 0xFF));
// Clear the word we just read
kb_word = 0;
kb_num_bits = 0;
// Release the keyboard
pinMode(KB_CLK, INPUT_PULLUP);
}
}
old_kb_clk_pin = kb_clk_pin;
}

0 comments on commit c5ec110

Please sign in to comment.
You can’t perform that action at this time.