ibmpc_usb: Update Overrun and buffer full handling(00, FF)
This commit is contained in:
parent
53d10fe247
commit
0661ef8a56
1 changed files with 43 additions and 67 deletions
|
|
@ -33,9 +33,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
static void matrix_make(uint8_t code);
|
static void matrix_make(uint8_t code);
|
||||||
static void matrix_break(uint8_t code);
|
static void matrix_break(uint8_t code);
|
||||||
|
|
||||||
static int8_t process_cs1(void);
|
static int8_t process_cs1(uint8_t code);
|
||||||
static int8_t process_cs2(void);
|
static int8_t process_cs2(uint8_t code);
|
||||||
static int8_t process_cs3(void);
|
static int8_t process_cs3(uint8_t code);
|
||||||
|
|
||||||
|
|
||||||
static uint8_t matrix[MATRIX_ROWS];
|
static uint8_t matrix[MATRIX_ROWS];
|
||||||
|
|
@ -302,18 +302,45 @@ uint8_t matrix_scan(void)
|
||||||
state = LOOP;
|
state = LOOP;
|
||||||
xprintf("L%u ", timer_read());
|
xprintf("L%u ", timer_read());
|
||||||
case LOOP:
|
case LOOP:
|
||||||
switch (keyboard_kind) {
|
{
|
||||||
case PC_XT:
|
uint16_t code = ibmpc_host_recv();
|
||||||
if (process_cs1() == -1) state = INIT;
|
if (code == -1) {
|
||||||
|
// no code
|
||||||
break;
|
break;
|
||||||
case PC_AT:
|
}
|
||||||
if (process_cs2() == -1) state = INIT;
|
|
||||||
break;
|
// Keyboard Error/Overrun([3]p.26) or Buffer full
|
||||||
case PC_TERMINAL:
|
// Scan Code Set 1: 0xFF
|
||||||
if (process_cs3() == -1) state = INIT;
|
// Scan Code Set 2 and 3: 0x00
|
||||||
break;
|
// Buffer full(IBMPC_ERR_FULL): 0xFF
|
||||||
default:
|
if (code == 0x00 || code == 0xFF) {
|
||||||
|
xprintf("\n!OVERRUN![");
|
||||||
|
|
||||||
|
// read and ignore data
|
||||||
|
do {
|
||||||
|
wait_ms(10);
|
||||||
|
} while ((code = ibmpc_host_recv()) != -1);
|
||||||
|
xprintf("]\n");
|
||||||
|
|
||||||
|
// clear stuck keys
|
||||||
|
matrix_clear();
|
||||||
|
clear_keyboard();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (keyboard_kind) {
|
||||||
|
case PC_XT:
|
||||||
|
if (process_cs1(code) == -1) state = INIT;
|
||||||
|
break;
|
||||||
|
case PC_AT:
|
||||||
|
if (process_cs2(code) == -1) state = INIT;
|
||||||
|
break;
|
||||||
|
case PC_TERMINAL:
|
||||||
|
if (process_cs3(code) == -1) state = INIT;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
@ -458,7 +485,7 @@ static uint8_t cs1_e0code(uint8_t code) {
|
||||||
return 0x00;
|
return 0x00;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int8_t process_cs1(void)
|
static int8_t process_cs1(uint8_t code)
|
||||||
{
|
{
|
||||||
static enum {
|
static enum {
|
||||||
INIT,
|
INIT,
|
||||||
|
|
@ -469,11 +496,6 @@ static int8_t process_cs1(void)
|
||||||
E1_9D,
|
E1_9D,
|
||||||
} state = INIT;
|
} state = INIT;
|
||||||
|
|
||||||
uint16_t code = ibmpc_host_recv();
|
|
||||||
if (code == -1) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check invalid codes; 0x59-7F won't be used in real XT keyboards probably
|
// Check invalid codes; 0x59-7F won't be used in real XT keyboards probably
|
||||||
// 0x62 is used to handle escape code E0 and E1
|
// 0x62 is used to handle escape code E0 and E1
|
||||||
if ((code & 0x7F) >= 0x62) {
|
if ((code & 0x7F) >= 0x62) {
|
||||||
|
|
@ -485,11 +507,6 @@ static int8_t process_cs1(void)
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case INIT:
|
case INIT:
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 0x00:
|
|
||||||
case 0xFF: // Error/Overrun [3]p.26
|
|
||||||
xprintf("!CS1_ERR!\n");
|
|
||||||
return -1;
|
|
||||||
break;
|
|
||||||
case 0xE0:
|
case 0xE0:
|
||||||
state = E0;
|
state = E0;
|
||||||
break;
|
break;
|
||||||
|
|
@ -683,7 +700,7 @@ static uint8_t cs2_e0code(uint8_t code) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int8_t process_cs2(void)
|
static int8_t process_cs2(uint8_t code)
|
||||||
{
|
{
|
||||||
// scan code reading states
|
// scan code reading states
|
||||||
static enum {
|
static enum {
|
||||||
|
|
@ -699,25 +716,9 @@ static int8_t process_cs2(void)
|
||||||
E1_F0_14_F0,
|
E1_F0_14_F0,
|
||||||
} state = INIT;
|
} state = INIT;
|
||||||
|
|
||||||
uint16_t code = ibmpc_host_recv();
|
|
||||||
if (code == -1) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case INIT:
|
case INIT:
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 0x00: // Error/Overrun [3]p.26
|
|
||||||
xprintf("!CS2_OVR!\n");
|
|
||||||
matrix_clear();
|
|
||||||
clear_keyboard();
|
|
||||||
break;
|
|
||||||
case 0xFF:
|
|
||||||
matrix_clear();
|
|
||||||
xprintf("!CS2_ERR!\n");
|
|
||||||
state = INIT;
|
|
||||||
return -1;
|
|
||||||
break;
|
|
||||||
case 0xE0:
|
case 0xE0:
|
||||||
state = E0;
|
state = E0;
|
||||||
break;
|
break;
|
||||||
|
|
@ -874,7 +875,7 @@ static int8_t process_cs2(void)
|
||||||
* See [3], [7] and
|
* See [3], [7] and
|
||||||
* https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-AT-Keyboard-Protocol#scan-code-set-3
|
* https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-AT-Keyboard-Protocol#scan-code-set-3
|
||||||
*/
|
*/
|
||||||
static int8_t process_cs3(void)
|
static int8_t process_cs3(uint8_t code)
|
||||||
{
|
{
|
||||||
static enum {
|
static enum {
|
||||||
READY,
|
READY,
|
||||||
|
|
@ -886,23 +887,9 @@ static int8_t process_cs3(void)
|
||||||
#endif
|
#endif
|
||||||
} state = READY;
|
} state = READY;
|
||||||
|
|
||||||
uint16_t code = ibmpc_host_recv();
|
|
||||||
if (code == -1) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case READY:
|
case READY:
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 0x00: // Error/Overrun [3]p.26
|
|
||||||
xprintf("!CS3_OVR!\n");
|
|
||||||
matrix_clear();
|
|
||||||
clear_keyboard();
|
|
||||||
break;
|
|
||||||
case 0xFF:
|
|
||||||
xprintf("!CS3_ERR!\n");
|
|
||||||
return -1;
|
|
||||||
break;
|
|
||||||
case 0xF0:
|
case 0xF0:
|
||||||
state = F0;
|
state = F0;
|
||||||
break;
|
break;
|
||||||
|
|
@ -946,17 +933,6 @@ static int8_t process_cs3(void)
|
||||||
break;
|
break;
|
||||||
case F0: // Break code
|
case F0: // Break code
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 0x00:
|
|
||||||
xprintf("!CS3_F0_OVR!\n");
|
|
||||||
matrix_clear();
|
|
||||||
clear_keyboard();
|
|
||||||
state = READY;
|
|
||||||
break;
|
|
||||||
case 0xFF:
|
|
||||||
xprintf("!CS3_F0_ERR!\n");
|
|
||||||
state = READY;
|
|
||||||
return -1;
|
|
||||||
break;
|
|
||||||
case 0x83: // PrintScreen
|
case 0x83: // PrintScreen
|
||||||
matrix_break(0x02);
|
matrix_break(0x02);
|
||||||
state = READY;
|
state = READY;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue