Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add I2C offset to get the keyboard init state #57

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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).
Expand Down
3 changes: 2 additions & 1 deletion ps2.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once

#include <Arduino.h>
#include "setup_ps2.h"
#include "optimized_gpio.h"
Expand Down Expand Up @@ -466,7 +467,7 @@ class PS2KeyboardPort : public PS2Port<clkPin, datPin, size>
*/
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;
}
Expand Down
21 changes: 2 additions & 19 deletions setup_keyboard.cpp
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -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;
}
12 changes: 11 additions & 1 deletion setup_ps2.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
#pragma once

// Mouse
void mouseTick();
void mouseReset();
void mouseSetRequestedId(uint8_t);
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();
2 changes: 1 addition & 1 deletion version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define version_major 47
#define version_minor 2
#define version_patch 4
#define version_patch 5
5 changes: 5 additions & 0 deletions x16-smc.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down