diff --git a/README.md b/README.md index 389c3ab..a8c9b67 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ If you want to update the SMC firmware, please read this [guide](doc/update-guid | 0x18 | Master read | 1 byte | Get keyboard command status | | 0x19 | Master write | 1 byte | Send keyboard command | | 0x1a | Master write | 2 bytes | Send keyboard command | +| 0x1b | Master read | 1 byte | Get keyboard ready state | | 0x20 | Master write | 1 byte | Set requested mouse device ID | | 0x21 | Master read | 1, 3 or 4 bytes | Get mouse movement | | 0x22 | Master read | 1 byte | Get mouse device ID | @@ -118,6 +119,13 @@ I2CPOKE $42,$19,$f5 Offset 0x1a sends a command that expects a command number and one data byte. This can't be done with the I2CPOKE command. +## Keyboard ready state (0x1b) + +Returns keyboard ready state. + +The return value 0x01 indicates that the keyboard is ready. Any other value means that the keyboard is not yet initialized. +The exact meaning of other return values than 0x01 is subject to change. + ## Set requested mouse device ID (0x20) By default the SMC tries to initialize the mouse with support for a scroll wheel and two extra buttons, in total five buttons (device ID 4). diff --git a/ps2.h b/ps2.h index 228afdd..a5188d1 100644 --- a/ps2.h +++ b/ps2.h @@ -1,4 +1,5 @@ #pragma once + #include #include "setup_ps2.h" #include "optimized_gpio.h" @@ -466,7 +467,7 @@ class PS2KeyboardPort : public PS2Port */ void processByteReceived(uint8_t value) { // Handle BAT success (0xaa) or fail (0xfc) code - if (!keyboardIsReady() && (value == 0xaa || value == 0xfc)) { + if (getKeyboardState() != KBD_STATE_READY && (value == 0xaa || value == 0xfc)) { bat = value; return; } diff --git a/setup_keyboard.cpp b/setup_keyboard.cpp index 0fe4b28..666ff3e 100644 --- a/setup_keyboard.cpp +++ b/setup_keyboard.cpp @@ -1,24 +1,7 @@ -#pragma once - #include "ps2.h" #include "smc_pins.h" #include "setup_ps2.h" -/* - State Machine -*/ - -// Setup -#define KBD_STATE_OFF 0x00 -#define KBD_STATE_BAT 0x01 -#define KBD_STATE_SET_LEDS 0x02 -#define KBD_STATE_SET_LEDS_ACK 0x03 -#define KBD_STATE_READY 0x04 - -// Reset -#define KBD_STATE_RESET 0x10 -#define KBD_STATE_RESET_ACK 0x11 - /* Watchdog */ @@ -124,6 +107,6 @@ void keyboardReset() { kbd_init_state = KBD_STATE_RESET; } -bool keyboardIsReady() { - return kbd_init_state == KBD_STATE_READY; +uint8_t getKeyboardState() { + return kbd_init_state; } diff --git a/setup_ps2.h b/setup_ps2.h index b286758..1c45a3c 100644 --- a/setup_ps2.h +++ b/setup_ps2.h @@ -1,5 +1,6 @@ #pragma once + // Mouse void mouseTick(); void mouseReset(); void mouseSetRequestedId(uint8_t); @@ -7,6 +8,15 @@ uint8_t getMouseId(); bool mouseIsReady(); uint8_t getMousePacketSize(); +// Keyboard +#define KBD_STATE_OFF 0x00 +#define KBD_STATE_READY 0x01 +#define KBD_STATE_BAT 0x02 +#define KBD_STATE_SET_LEDS 0x03 +#define KBD_STATE_SET_LEDS_ACK 0x04 +#define KBD_STATE_RESET 0x10 +#define KBD_STATE_RESET_ACK 0x11 + void keyboardTick(); void keyboardReset(); -bool keyboardIsReady(); +uint8_t getKeyboardState(); diff --git a/version.h b/version.h index d35922f..c1cce86 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ #define version_major 47 #define version_minor 2 -#define version_patch 4 +#define version_patch 5 diff --git a/x16-smc.ino b/x16-smc.ino index cee0f1e..42caf3d 100644 --- a/x16-smc.ino +++ b/x16-smc.ino @@ -75,6 +75,7 @@ #define I2C_CMD_GET_KBD_STATUS 0x18 #define I2C_CMD_KBD_CMD1 0x19 #define I2C_CMD_KBD_CMD2 0x1a +#define I2C_CMD_KBD_INIT_STATE 0x1b #define I2C_CMD_SET_MOUSE_ID 0x20 #define I2C_CMD_GET_MOUSE_MOV 0x21 #define I2C_CMD_GET_MOUSE_ID 0x22 @@ -587,6 +588,10 @@ void I2C_Send() { smcWire.write(Keyboard.getCommandStatus()); break; + case I2C_CMD_KBD_INIT_STATE: + smcWire.write(getKeyboardState()); + break; + case I2C_CMD_GET_MOUSE_ID: smcWire.write(getMouseId()); break;