Skip to content

Commit

Permalink
Clean-up keyboard and mouse init. Bump version to 47.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-b-jakobsson committed Feb 22, 2024
1 parent a46d82e commit a2eb113
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 30 deletions.
4 changes: 2 additions & 2 deletions setup_keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/*
Watchdog
*/
#define WATCHDOG_ARM 65535
#define WATCHDOG_ARM 255
#define WATCHDOG_DISABLE 0

/*
Expand All @@ -49,7 +49,7 @@ static volatile uint8_t kbd_init_state = 0;


void keyboardTick() {
static uint16_t watchdog = WATCHDOG_DISABLE;
static uint8_t watchdog = WATCHDOG_DISABLE;

// Return to OFF state if system powered down
if (!SYSTEM_POWERED && kbd_init_state != KBD_STATE_OFF) {
Expand Down
36 changes: 9 additions & 27 deletions setup_mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@
#define MOUSE_STATE_INTELLI_GET_ID 0x28

// Setup
#define MOUSE_STATE_SET_RESOLUTION 0x30
#define MOUSE_STATE_SET_RESOLUTION_ACK 0x31
#define MOUSE_STATE_SET_SAMPLERATE 0x32
#define MOUSE_STATE_SET_SAMPLERATE_ACK 0x33
#define MOUSE_STATE_SET_SCALING 0x34
#define MOUSE_STATE_SET_SCALING_ACK 0x35
#define MOUSE_STATE_ENABLE 0x36
#define MOUSE_STATE_ENABLE_ACK 0x37
#define MOUSE_STATE_READY 0x38
#define MOUSE_STATE_SET_SAMPLERATE 0x30
#define MOUSE_STATE_SET_SAMPLERATE_ACK 0x31
#define MOUSE_STATE_ENABLE 0x32
#define MOUSE_STATE_ENABLE_ACK 0x33
#define MOUSE_STATE_READY 0x34

#define MOUSE_STATE_FAILED 0x40

Expand All @@ -44,7 +40,7 @@
/*
Watchdog
*/
#define WATCHDOG_ARM 1023
#define WATCHDOG_ARM 255
#define WATCHDOG_DISABLE 0

/*
Expand Down Expand Up @@ -76,7 +72,7 @@ static volatile uint8_t watchdogExpiryState = MOUSE_STATE_OFF;


void mouseTick() {
static uint16_t watchdog = WATCHDOG_DISABLE;
static uint8_t watchdog = WATCHDOG_DISABLE;

// Return to OFF state if system powered down
if (!SYSTEM_POWERED && state != MOUSE_STATE_OFF) {
Expand Down Expand Up @@ -124,7 +120,7 @@ void mouseTick() {
state = MOUSE_STATE_INTELLI_1;
}
else {
state = MOUSE_STATE_SET_RESOLUTION;
state = MOUSE_STATE_SET_SAMPLERATE;
}
watchdog = WATCHDOG_ARM;
}
Expand Down Expand Up @@ -165,7 +161,7 @@ void mouseTick() {
mouse_id = Mouse.next();
if (mouse_id == requestedmouse_id || (mouse_id == 0 && requestedmouse_id == 3)) {
// Setup succeded, or accept downgrade from mouse ID 3 to mouse ID 0
state = MOUSE_STATE_SET_RESOLUTION;
state = MOUSE_STATE_SET_SAMPLERATE;
}
else if (mouse_id == 0 && requestedmouse_id == 4) {
// Setup failed, try to downgrade to mouse ID 3
Expand All @@ -181,24 +177,12 @@ void mouseTick() {
}
break;

case MOUSE_STATE_SET_RESOLUTION:
Mouse.sendPS2Command(PS2_CMD_SET_RESOLUTION, 0x00);
state = MOUSE_STATE_SET_RESOLUTION_ACK;
watchdog = WATCHDOG_ARM;
break;

case MOUSE_STATE_SET_SAMPLERATE:
Mouse.sendPS2Command(PS2_CMD_SET_SAMPLE_RATE, 60);
state = MOUSE_STATE_SET_SAMPLERATE_ACK;
watchdog = WATCHDOG_ARM;
break;

case MOUSE_STATE_SET_SCALING:
Mouse.sendPS2Command(PS2_CMD_SET_SCALING);
state = MOUSE_STATE_SET_SCALING_ACK;
watchdog = WATCHDOG_ARM;
break;

case MOUSE_STATE_ENABLE:
Mouse.sendPS2Command(PS2_CMD_ENABLE);
state = MOUSE_STATE_ENABLE_ACK;
Expand Down Expand Up @@ -234,9 +218,7 @@ void mouseTick() {
// case MOUSE_STATE_INTELLI_2_ACK:
// case MOUSE_STATE_INTELLI_3_ACK:
// case MOUSE_STATE_INTELLI_REQ_ID_ACK
// case MOUSE_STATE_SET_RESOLUTION_ACK:
// case MOUSE_STATE_SET_SAMPLERATE_ACK:
// case MOUSE_STATE_SET_SCALING_ACK
// case MOUSE_STATE_ENABLE_ACK:
if (Mouse.available()) {
if (Mouse.next() == PS2_ACK) {
Expand Down
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 45
#define version_major 47
#define version_minor 1
#define version_patch 1

0 comments on commit a2eb113

Please sign in to comment.