adb_usb: Check PSW pin at polling rate for debounce

This commit is contained in:
tmk 2022-05-29 14:26:09 +09:00
parent 3d6e5cd570
commit 4a22b732ae

View file

@ -169,6 +169,10 @@ static uint8_t keyboard_proc(uint8_t addr)
register_key(0x7F); register_key(0x7F);
} else if (codes == 0xFFFF) { // power key release } else if (codes == 0xFFFF) { // power key release
register_key(0xFF); register_key(0xFF);
// for debug
device_scan();
print_device_table();
} else { } else {
// Macally keyboard sends keys inversely against ADB protocol // Macally keyboard sends keys inversely against ADB protocol
// https://deskthority.net/workshop-f7/macally-mk96-t20116.html // https://deskthority.net/workshop-f7/macally-mk96-t20116.html
@ -818,25 +822,7 @@ void hook_main_loop(void)
static uint16_t poll_ms; static uint16_t poll_ms;
static uint16_t detect_ms; static uint16_t detect_ms;
static uint8_t active_addr = 3; static uint8_t active_addr = 3;
// Check PSW pin
// https://github.com/tmk/tmk_keyboard/issues/735
static bool psw_state = false; static bool psw_state = false;
if (!psw_state) {
if (!adb_host_psw()) {
register_key(0x7F); // power key press
psw_state = true;
}
} else {
if (adb_host_psw()) {
register_key(0xFF); // power key release
psw_state = false;
// for debug
device_scan();
print_device_table();
}
}
uint8_t len; uint8_t len;
uint8_t buf[8]; uint8_t buf[8];
@ -844,26 +830,15 @@ void hook_main_loop(void)
uint8_t busy = 0; uint8_t busy = 0;
// Polling with 11ms interval // Polling with 11ms interval
if (timer_elapsed(poll_ms) >= 11) do { if (timer_elapsed(poll_ms) >= 11) {
addr %= 16;
// Ignore Address 0
if (addr == 0) continue;
poll_ms = timer_read(); poll_ms = timer_read();
switch (device_table[addr].addr_default) { do {
case ADB_ADDR_KEYBOARD: addr %= 16;
busy = keyboard_proc(addr);
break; // Ignore Address 0
case ADB_ADDR_MOUSE: if (addr == 0) continue;
busy = mouse_proc(addr);
break; switch (device_table[addr].addr_default) {
case ADB_ADDR_APPLIANCE:
busy = appliance_proc(addr);
break;
case 0:
// No device entry but 'dumb' device may exist #733
switch (addr) {
case ADB_ADDR_KEYBOARD: case ADB_ADDR_KEYBOARD:
busy = keyboard_proc(addr); busy = keyboard_proc(addr);
break; break;
@ -873,28 +848,56 @@ void hook_main_loop(void)
case ADB_ADDR_APPLIANCE: case ADB_ADDR_APPLIANCE:
busy = appliance_proc(addr); busy = appliance_proc(addr);
break; break;
} case 0:
break; // No device
default: // but 'dumb' device may exist at 2, 3 and 7 #733
// Unsupported device switch (addr) {
len = adb_host_talk_buf(addr, ADB_REG_0, buf, sizeof(buf)); case ADB_ADDR_KEYBOARD:
if (len) { busy = keyboard_proc(addr);
xprintf("$%X R0: [ ", addr); break;
for (uint8_t i = 0; i < len; i++) { case ADB_ADDR_MOUSE:
xprintf("%02X ", buf[i]); busy = mouse_proc(addr);
break;
case ADB_ADDR_APPLIANCE:
busy = appliance_proc(addr);
break;
} }
xprintf("]\n"); break;
busy = 1; default:
// Unsupported device
len = adb_host_talk_buf(addr, ADB_REG_0, buf, sizeof(buf));
if (len) {
xprintf("$%X R0: [ ", addr);
for (uint8_t i = 0; i < len; i++) {
xprintf("%02X ", buf[i]);
}
xprintf("]\n");
busy = 1;
}
break;
} }
break;
}
// Scan next device when Service Request(SRQ) is asserted // Poll next device when Service Request(SRQ) is asserted
if (!adb_service_request()) { if (!adb_service_request()) {
break; break;
}
} while (++addr != active_addr);
active_addr = addr % 16;
// Check PSW pin for NeXT keyboard
// https://github.com/tmk/tmk_keyboard/issues/735
if (!psw_state) {
if (!adb_host_psw()) {
register_key(0x7F); // power key press
psw_state = true;
}
} else {
if (adb_host_psw()) {
register_key(0xFF); // power key release
psw_state = false;
}
} }
} while (++addr != active_addr); }
active_addr = addr % 16;
// Address Resolution // Address Resolution
if (!busy) { if (!busy) {