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,13 +830,14 @@ 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) {
poll_ms = timer_read();
do {
addr %= 16; addr %= 16;
// Ignore Address 0 // Ignore Address 0
if (addr == 0) continue; if (addr == 0) continue;
poll_ms = timer_read();
switch (device_table[addr].addr_default) { switch (device_table[addr].addr_default) {
case ADB_ADDR_KEYBOARD: case ADB_ADDR_KEYBOARD:
busy = keyboard_proc(addr); busy = keyboard_proc(addr);
@ -862,7 +849,8 @@ void hook_main_loop(void)
busy = appliance_proc(addr); busy = appliance_proc(addr);
break; break;
case 0: case 0:
// No device entry but 'dumb' device may exist #733 // No device
// but 'dumb' device may exist at 2, 3 and 7 #733
switch (addr) { switch (addr) {
case ADB_ADDR_KEYBOARD: case ADB_ADDR_KEYBOARD:
busy = keyboard_proc(addr); busy = keyboard_proc(addr);
@ -889,13 +877,28 @@ void hook_main_loop(void)
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); } while (++addr != active_addr);
active_addr = addr % 16; 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;
}
}
}
// Address Resolution // Address Resolution
if (!busy) { if (!busy) {
if (timer_elapsed(detect_ms) >= 1000) { if (timer_elapsed(detect_ms) >= 1000) {