Fix dual channel detection

This commit is contained in:
Juhani Krekelä 2022-01-23 16:26:57 +02:00
parent cb8a12eed0
commit b3ee12fcc5
1 changed files with 11 additions and 11 deletions

View File

@ -142,7 +142,7 @@ void write_8042(uint8_t data) {
} }
bool translation_initially; bool translation_initially;
bool single_channel = false; bool dual_channel;
uint8_t read_config_8042(void) { uint8_t read_config_8042(void) {
command_8042(0x20); command_8042(0x20);
@ -166,7 +166,7 @@ void init_8042(void) {
// Read configuration // Read configuration
uint8_t config = read_config_8042(); uint8_t config = read_config_8042();
translation_initially = config & (1<<6); translation_initially = config & (1<<6);
single_channel = !(config & (1<<5)); dual_channel = config & (1<<5);
// Disable IRQ // Disable IRQ
config &= ~(1<<0); config &= ~(1<<0);
@ -187,16 +187,16 @@ void init_8042(void) {
write_8042(config); write_8042(config);
// Determine number of channels // Determine number of channels
if (!single_channel) { if (dual_channel) {
command_8042(0xae); command_8042(0xa8);
single_channel = read_config_8042() & (1<<5); dual_channel = !(read_config_8042() & (1<<5));
if (!single_channel) if (dual_channel)
command_8042(0xa7); command_8042(0xa7);
} }
if (single_channel) if (dual_channel)
terminal_writestring("Single-channel ps/2 controller\n");
else
terminal_writestring("Dual-channel ps/2 controller\n"); terminal_writestring("Dual-channel ps/2 controller\n");
else
terminal_writestring("Single-channel ps/2 controller\n");
// Test channels // Test channels
terminal_writestring("Testing channel 1... "); terminal_writestring("Testing channel 1... ");
@ -205,7 +205,7 @@ void init_8042(void) {
terminal_writestring("failed\n"); terminal_writestring("failed\n");
else else
terminal_writestring("ok\n"); terminal_writestring("ok\n");
if (!single_channel) { if (dual_channel) {
terminal_writestring("Testing channel 2... "); terminal_writestring("Testing channel 2... ");
command_8042(0xa9); command_8042(0xa9);
if (read_8042() != 0) if (read_8042() != 0)
@ -216,7 +216,7 @@ void init_8042(void) {
// Enable devices // Enable devices
command_8042(0xae); command_8042(0xae);
if (!single_channel) if (dual_channel)
command_8042(0xa8); command_8042(0xa8);
} }