X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=tmk_core%2Fprotocol%2Fibm4704.c;h=75e7db12b5e56aad7f8e84be9668735ee67203ae;hb=12e5a3a13eb86852ad58c131e28ba29c5f09bb2d;hp=a2c6700477f97794676e0085c0865c15d4bb0c16;hpb=9a2282157fbdf57ef0a50d4fea7da72505906588;p=max%2Ftmk_keyboard.git diff --git a/tmk_core/protocol/ibm4704.c b/tmk_core/protocol/ibm4704.c index a2c67004..75e7db12 100644 --- a/tmk_core/protocol/ibm4704.c +++ b/tmk_core/protocol/ibm4704.c @@ -21,9 +21,10 @@ uint8_t ibm4704_error = 0; void ibm4704_init(void) { + inhibit(); // keep keyboard from sending IBM4704_INT_INIT(); IBM4704_INT_ON(); - idle(); + idle(); // allow keyboard sending } /* @@ -38,7 +39,7 @@ Data ____|__/ X____X____X____X____X____X____X____X____X____X \___ | Start 0 1 2 3 4 5 6 7 P Stop Request by host -Start bit: can be long as 300-350us. +Start bit: can be long as 300-350us during start up and upto 2500us while key scanning Request: Host pulls Clock line down to request to send a command. Timing: After Request keyboard pull up Data and down Clock line to low for start bit. After request host release Clock line once Data line becomes hi. @@ -57,7 +58,7 @@ uint8_t ibm4704_send(uint8_t data) clock_lo(); /* wait for Start bit(Clock:lo/Data:hi) */ - WAIT(data_hi, 300, 0x30); + WAIT(data_hi, 5000, 0x30); /* Data bit */ for (uint8_t i = 0; i < 8; i++) { @@ -88,7 +89,7 @@ uint8_t ibm4704_send(uint8_t data) return 0; ERROR: idle(); - if (ibm4704_error > 0x30) { + if (ibm4704_error >= 0x30) { xprintf("S:%02X ", ibm4704_error); } IBM4704_INT_ON(); @@ -132,8 +133,8 @@ Stop bit: Keyboard pulls down Data line to lo after 9th clock. ISR(IBM4704_INT_VECT) { static enum { - STOP, BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7, PARITY - } state = STOP; + BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7, PARITY, STOP + } state = BIT0; // LSB first static uint8_t data = 0; // Odd parity @@ -141,11 +142,7 @@ ISR(IBM4704_INT_VECT) ibm4704_error = 0; - switch (state++) { - case STOP: - // Data:Low - WAIT(data_lo, 10, state); - break; + switch (state) { case BIT0: case BIT1: case BIT2: @@ -166,6 +163,10 @@ ISR(IBM4704_INT_VECT) } if (!parity) goto ERROR; + break; + case STOP: + // Data:Low + WAIT(data_lo, 100, state); rbuf_enqueue(data); ibm4704_error = IBM4704_ERR_NONE; goto DONE; @@ -173,13 +174,14 @@ ISR(IBM4704_INT_VECT) default: goto ERROR; } + state++; goto RETURN; ERROR: ibm4704_error = state; while (ibm4704_send(0xFE)) _delay_ms(1); // resend xprintf("R:%02X%02X\n", state, data); DONE: - state = STOP; + state = BIT0; data = 0; parity = false; RETURN: