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

IBMPC: Send Command - Zenith Z-150 AT beige #661

Closed
tmk opened this issue Nov 15, 2020 · 5 comments
Closed

IBMPC: Send Command - Zenith Z-150 AT beige #661

tmk opened this issue Nov 15, 2020 · 5 comments

Comments

@tmk
Copy link
Owner

tmk commented Nov 15, 2020

Stop bit(ACK) Error on sending command

ERR:17 means error occurs after stop bit.

Debug output from the converter when plugin and capslock key is pressed, tested with firmware beased on commit 19853b4 probably.

Waiting for new device:..............
Listening:

ERR:F0 ISR:FFE0
PRT:23 ISR:0000 [CHG] I65401 wFF A868
ERR:17 ISR:6A90
PRT:11 ISR:0000 X1370 rAA W1813 wF2 R2315
ID:FFFF(1)
ERR:17 ISR:6A90 S2316 L2316 r58 rF0 r58


This was reported by email at 2020-11-14.

ISR:6A90 means 0xAA which received from the keyboard. The keyboard seems to reset when sending command fails with ERR:17?

It seems that Zenith Z-150 is not compatible to AT protocol and it lacks 11th clock when host sends a command.
https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-AT-Keyboard-Protocol#zenith-z-150-beige

Fix 1

The converter doesn't wait for 11th clock after it recoginized protocol for Z-150 AT.
This should work but won't before the protocol recognition.

Commit 7e268c8

diff --git a/tmk_core/protocol/ibmpc.c b/tmk_core/protocol/ibmpc.c
index 0e94e301..0f093f80 100644
--- a/tmk_core/protocol/ibmpc.c
+++ b/tmk_core/protocol/ibmpc.c
@@ -136,6 +136,7 @@ int16_t ibmpc_host_send(uint8_t data)
     wait_us(15);
     data_hi();
     WAIT(clock_hi, 50, 6);
+    // Zenith Z-150 AT doesn't have 11th clock for ACK.
+    if (ibmpc_protocol == IBMPC_PROTOCOL_AT_Z150) { goto RECV; }
     WAIT(clock_lo, 50, 7);
 
@@ -156,6 +157,11 @@ RECV:
     return ibmpc_host_recv_response();
 ERROR:
     ibmpc_error |= IBMPC_ERR_SEND;
+
+    // This error can happen before protocol recognition of Zenith Z-150 AT.
+    // https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-AT-Keyboard-Protocol#zenith-z-150-beige
+    if (!ibmpc_protocol && ibmpc_error == 7) { goto RECV; }
+
     idle();
     IBMPC_INT_ON();
     return -1;

Fix 2

This works as well, instead of Fix 1. Fix 1 seems to be preferable though.

When ERR:17 happens at startup converter tries to receive response for Z-150 AT.

diff --git a/converter/ibmpc_usb/ibmpc_usb.c b/converter/ibmpc_usb/ibmpc_usb.c
index 6d22ad73..ef35e5a5 100644
--- a/converter/ibmpc_usb/ibmpc_usb.c
+++ b/converter/ibmpc_usb/ibmpc_usb.c
@@ -201,7 +201,12 @@ uint8_t matrix_scan(void)
             if (0xFA == ibmpc_host_send(0xFF)) {
                 state = WAIT_AA;
             } else {
-                state = XT_RESET;
+                // With Zenith Z-150 AT stop bit error occurs before recognized
+                if (0x17 == ibmpc_error && 0xFA == ibmpc_host_recv_response()) {
+                    state = WAIT_AA;
+                } else {
+                    state = XT_RESET;
+                }
             }
             xprintf("A%u ", timer_read());
             break;

Fix signal check for ACK

2021-05-25

Original PC/AT Keyboard Controller doesn't check clock pulse for ACK, probably Z-150 AT works with the original controller without problem. Both fixes above are not needed in the end.

With seeing ROM dump list of the keyboard controller it checks only DATA line with longer timeout on ACK. (0277, 027B)

http://halicery.com/8042/8042_1503033.TXT

Before fix:

/* Stop bit */
wait_us(15);
data_hi();
WAIT(clock_hi, 50, 6);
WAIT(clock_lo, 50, 7);
/* Ack */
WAIT(data_lo, 50, 8);
/* wait for idle state */
WAIT(clock_hi, 50, 9);
WAIT(data_hi, 50, 10);

With fix:

    /* Stop bit */
    wait_us(15);
    data_hi();

    /* Ack */
    WAIT(data_lo, 300, 6);
    WAIT(data_hi, 300, 7);

    // this is optional?
    WAIT(clock_hi, 300, 8);

Z-150 AT seems to be slow for clock pulse for ACK, or no pluse at all.(Not confirmed)

    Z-150 AT:
        __      _ 1 _ 2 _ 3 _ 4 _ 5 _ 6 _ 7 _ 8 _ 9 _ A ________
    CLK   \____/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ XXXXX
        ______     ___ ___ ___ ___ ___ ___ ___ ___ ______     ____
    DAT       \___/___X___X___X___X___X___X___X___X___/  \___/
           I    S   0   1   2   3   4   5   6   7   P   S ACK

Fixed repo at: 0a1dcac
2021-06-03

@tmk
Copy link
Owner Author

tmk commented Feb 3, 2021

Start bit Error

ERR:11 can happen irregularly but not so often?

TMK:05dc12ae/LUFA


USB configured.

Keyboard start.
I350 wFF A1388
ERR:11 ISR:0000 X1889
ERR:F0 ISR:FFE0
PRT:23 ISR:0000 !FF! rFF W1890
PRT:11 ISR:7E90 rFA W1891 rAA W2123 R2123
ID:FFFD(AT_Z150) S2123 L2123

https://deskthority.net/viewtopic.php?p=477748#p477748

The log shows that the converter misses clock for start bit and stops sending data but keyboard still continues to clock pulsing. In the result:
a. The keyboard receives command FF in the end and responds with FA and AA afterwards.(ISR:7E90, rFA, rAA)
b. The converter receives FF with the clock pulses, its signal is recognized wrongly as IBMPC_PROTOCOL_XT_ERROR (ISR:FFE0, PRT:23).

Z-150 AT:
    __      ____ 1 _ 2 _ 3 _ 4 _ 5 _ 6 _ 7 _ 8 _ 9 _ A _____
CLK   \____/    \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
    ______     _____________________________________________
DAT       \___/
              +  S   0   1   2   3   4   5   6   7   P   S  
+ Converter cancels before 1st clock for start bit

https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-AT-Keyboard-Protocol#zenith-z-150-beige

Fix 1.

It should wait for 'start bit clock' longer than usual 10ms for the Zenith.

WAIT(clock_lo, 10000, 1); // [5]p.53, -10ms [5]p.50

60ms?

The keyboard checks the state of the 'clock' line at intervals of
no less than 60 milliseconds. If a request-to-send is detected, the
keyboard counts 11 bits.

p.4-16
http://bitsavers.org/pdf/ibm/pc/at/6183355_PC_AT_Technical_Reference_Mar86.pdf

diff --git a/tmk_core/protocol/ibmpc.c b/tmk_core/protocol/ibmpc.c
index 0e94e301..6b452f16 100644
--- a/tmk_core/protocol/ibmpc.c
+++ b/tmk_core/protocol/ibmpc.c
@@ -111,7 +111,7 @@ int16_t ibmpc_host_send(uint8_t data)
     data_lo();
     wait_us(100);
     clock_hi();     // [5]p.54 [clock low]>100us [5]p.50
-    WAIT(clock_lo, 10000, 1);   // [5]p.53, -10ms [5]p.50
+    WAIT(clock_lo, 60000, 1);   // [5]p.53, -10ms [5]p.50
 
     /* Data bit[2-9] */
     for (uint8_t i = 0; i < 8; i++) {

This didn't help a lot.

Fix 2.

And it may need to place inhibit state enough time(100us or 1-2ms?) to cancel/ignore clocking for sending process when the error happens.

ERROR:
ibmpc_error |= IBMPC_ERR_SEND;
idle();
IBMPC_INT_ON();
return -1;

diff --git a/tmk_core/protocol/ibmpc.c b/tmk_core/protocol/ibmpc.c                                            [0/1986]
index 0e94e301..54fcdc2e 100644
--- a/tmk_core/protocol/ibmpc.c
+++ b/tmk_core/protocol/ibmpc.c
@@ -156,6 +156,8 @@ RECV:
     return ibmpc_host_recv_response();
 ERROR:
     ibmpc_error |= IBMPC_ERR_SEND;
+    inhibit();
+    wait_ms(2);
     idle();
     IBMPC_INT_ON();
     return -1;

This didn't help a lot also.

Retry

Retry for start bit works well somehow.

https://geekhack.org/index.php?topic=103648.msg3054043#msg3054043

Fixed repo at: 67d37ef
2021-06-03

@tmk tmk added the TODO label Feb 3, 2021
@tmk
Copy link
Owner Author

tmk commented Feb 5, 2021

With Stop bit error Fix 2 above ERR:17 is recovered well.

commit 05dc12aed4fa9163fcbcb6c8881f015b5f7d33e5
Author: tmk <hasu@tmk-kbd.com>
Date:   Mon Jan 25 12:51:00 2021 +0900

    ibmpc_usb: Change init for Zenith Z-150 AT

diff --git a/converter/ibmpc_usb/ibmpc_usb.c b/converter/ibmpc_usb/ibmpc_usb.c
index 6d22ad73..ef35e5a5 100644
--- a/converter/ibmpc_usb/ibmpc_usb.c
+++ b/converter/ibmpc_usb/ibmpc_usb.c
@@ -193,7 +193,7 @@ uint8_t matrix_scan(void)
             ibmpc_host_enable();
             wait_ms(1); // keyboard can't respond to command without this
 
-            // SKIDATA-2-DE(and some other keyboards?) stores 'Code Set' setting in nonvlatile memory
+            // SKIDATA-2-DE(and some other keyboards?) stores 'Code Set' setting in nonvolatile memory
             // and keeps it until receiving reset. Sending reset here may be useful to clear it, perhaps.
             // https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-AT-Keyboard-Protocol#select-alternate-scan-codesf0
 
@@ -201,7 +201,12 @@ uint8_t matrix_scan(void)
             if (0xFA == ibmpc_host_send(0xFF)) {
                 state = WAIT_AA;
             } else {
-                state = XT_RESET;
+                // With Zenith Z-150 AT stop bit error occurs before recognized
+                if (0x17 == ibmpc_error && 0xFA == ibmpc_host_recv_response()) {
+                    state = WAIT_AA;
+                } else {
+                    state = XT_RESET;
+                }
             }
             xprintf("A%u ", timer_read());
             break;

1

ERR:20 ISR:C0000 [RST] I25346
PRT:21 ISR:0000 wFF rFA A26351
PRT:11 ISR:7E90 rAA W26587 R27088
ID:FFFD(AT_Z150) S27088 L27089
Device disconnected.
Waiting for new device:..............
Listening:

TMK:05dc12ae/LUFA


USB configured.

Keyboard start.
I287 wFF rFA A1291
ERR:17 ISR:7E90
PRT:11 ISR:0000 rAA W1527 R2028
ID:FFFD(AT_Z150) S2028 L2028
Device disconnected.
Waiting for new device:..............
Listening:

TMK:05dc12ae/LUFA


USB configured.

Keyboard start.
I288 wFF rFA A1292
ERR:17 ISR:7E90
PRT:11 ISR:0000 rAA W1528 R2029
ID:FFFD(AT_Z150) S2029 L2029 r33 rF0 r33 r24 rF0 r24

https://deskthority.net/viewtopic.php?p=478066#p478066

2

Waiting for new device:..............
Listening:

TMK:05dc12ae/LUFA


USB configured.

Keyboard start.
I320 wFF rFA A1324
PRT:11 ISR:7E90 rAA W1560 R2061
ID:FFFD(AT_Z150) S2096 L2096
Device disconnected.
Waiting for new device:..............
Listening:

TMK:05dc12ae/LUFA


USB configured.

Keyboard start.
I289 wFF rFA A1293
PRT:11 ISR:7E90 rAA W1529 R2030
ID:FFFD(AT_Z150) S2030 L2030
Device disconnected.
Waiting for new device:..............
Listening:

TMK:05dc12ae/LUFA


USB configured.

Keyboard start.
I287 wFF rFA A1292
PRT:11 ISR:7E90 rAA W1528 R2029
ID:FFFD(AT_Z150) S2029 L2029
Device disconnected.
Waiting for new device:..............
Listening:

TMK:05dc12ae/LUFA


USB configured.

Keyboard start.
I350 wFF rFA A1354
PRT:11 ISR:7E90 rAA W1590 R2091
ID:FFFD(AT_Z150) S2091 L2091
Device disconnected.
Waiting for new device:..............
Listening:

TMK:05dc12ae/LUFA


USB configured.

Keyboard start.
I355 wFF rFA A1359
PRT:11 ISR:7E90 rAA W1595 R2096
ID:FFFD(AT_Z150) S2096 L2096

https://deskthority.net/viewtopic.php?p=478067#p478067

ISR:7E90 means FA is received from Zenith Z-150 AT.

The debug logs don't show Start bit error(ERR:11) but it can still happen probably.

tmk added a commit that referenced this issue Feb 6, 2021
ibmpc_host_send() can miss 1st clock from Zenith Z-150 AT sometimes.
#661 (comment)
@tmk tmk changed the title IBMPC converter: Send command - Zenith Z-150 AT beige IBMPC: Send Command - Zenith Z-150 AT beige Feb 6, 2021
@tmk
Copy link
Owner Author

tmk commented Feb 18, 2021

TODO:

  • merge _fix3 branch into master
  • test _fix4 branch

branches

master

Fails to set keyboard_kind for actionmap Code Set

ibmpc_z150at [remove OK]

Fixed: Recover ERR:17 of reset command FF

ibmpc_z150at_fix [remove OK]

Fixed:

  • change start bit wait and error handling
  • Check AA from keyboard after startup
  • Send F2 command to read keyboard ID

Seems like sending 'F2' command goes successfully but there is no response from keyboard within timeout period(25ms).

ibmpc_z150at_fix2 [remove OK]

Fixed: Prevent read_keyboard_id() from sending F2 for Z-150 AT

ibmpc_z150at_fix3 [can be merged]

Fixed: get keyboard_kind value correspond with Code Set(remove PC_AT_Z150)

This looks like work well except for setting Lock indicator at startup.

ibmpc_z150at_fix4 [Wait for test]

  • Firmware version: 3163a11 2021-02-12
  • Identify keyboard:
  • Key type:

Fixed:

  • Get timeout loger(25-> 250ms) for command response.
  • Try reading keyboard ID
  • LED set at startup

Not tested yet

tmk added a commit that referenced this issue Jun 3, 2021
Zenith Z-150 AT doesn't seems to place ACK signaling normally.
#661 (comment)
https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-AT-Keyboard-Protocol#zenith-z-150-beige

IBM genuine PC host checks data line only, not clock on ACK. In this
case Z-150 AT ACK signaling can be handled.
http://www.halicery.com/Hardware/Intel%208042%20and%208048/8042_PS2_INTERN.TEXT (026C:)
http://halicery.com/8042/8042_1503033.TXT (0274:)

Place 'inhibit' on lines for long enough to cancel current state and
recovery from ERROR but not sure this really helps.
tmk added a commit that referenced this issue Jun 3, 2021
This is fix for Zenith Z-150 AT. Root cause is still
not clear but retrying works well somehow.
#661 (comment)

Add checking isr_state and line state before sending data
@tmk tmk removed the TODO label Jun 3, 2021
@tmk
Copy link
Owner Author

tmk commented Jun 3, 2021

Fixed Start bit and ACK error.

As for Start bit it needs retry and reasonable explanation of the cause is still unclear.

@tmk tmk closed this as completed Jun 3, 2021
@tmk
Copy link
Owner Author

tmk commented Oct 28, 2021

Z-150 AT doesn't support F2 ID command at all and doesn't even replay with FA.

https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-AT-Keyboard-Protocol#zenith-z-150-at

To identify the keyboard ibmpc protocol is used. 9c83924

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant