Ensure ps2 interface is always in correct state

This commit is contained in:
Jeremy Soller 2019-11-17 18:37:25 -07:00
parent 49e958fc7d
commit 271b612c57
No known key found for this signature in database
GPG Key ID: E988B49EE78A7FB1
4 changed files with 18 additions and 12 deletions

View File

@ -396,7 +396,7 @@ void touchpad_event(struct Ps2 * ps2) {
if (kbc_second) {
*(ps2->control) = 0x07;
} else {
*(ps2->control) = 0x01;
ps2_reset(ps2);
}
uint8_t status = *(ps2->status);

View File

@ -1,12 +1,7 @@
#include <board/ps2.h>
void ps2_init(void) {
*(PS2_1.control) = 0x11;
*(PS2_1.interrupt) = 0x04;
*(PS2_2.control) = 0x41;
*(PS2_2.interrupt) = 0x04;
*(PS2_3.control) = 0x41;
*(PS2_3.interrupt) = 0x04;
ps2_reset(&PS2_1);
ps2_reset(&PS2_2);
ps2_reset(&PS2_3);
}

View File

@ -14,7 +14,8 @@ extern struct Ps2 __code PS2_1;
extern struct Ps2 __code PS2_2;
extern struct Ps2 __code PS2_3;
int ps2_read(struct Ps2 * ps2, uint8_t * data, int length);
void ps2_reset(struct Ps2 * ps2);
int ps2_read(struct Ps2 * ps2, uint8_t * data, int length);
int ps2_write(struct Ps2 * ps2, uint8_t * data, int length);
volatile uint8_t __xdata __at(0x1700) PSCTL1;

View File

@ -22,6 +22,13 @@ struct Ps2 __code PS2_1 = PS2(1);
struct Ps2 __code PS2_2 = PS2(2);
struct Ps2 __code PS2_3 = PS2(3);
void ps2_reset(struct Ps2 * ps2) {
// Reset interface to defaults
*(ps2->control) = 1;
// Clear status
*(ps2->status) = *(ps2->status);
}
static int ps2_transaction(struct Ps2 * ps2, uint8_t * data, int length, bool read) {
int i;
for (i = 0; i < length; i++) {
@ -43,7 +50,7 @@ static int ps2_transaction(struct Ps2 * ps2, uint8_t * data, int length, bool re
uint8_t status = *(ps2->status);
// If an error happened, clear status and return the error
if (status & PSSTS_ALL_ERR) {
*(ps2->status) = status;
ps2_reset(ps2);
return -(int)status;
}
// If transaction is done, break
@ -53,11 +60,14 @@ static int ps2_transaction(struct Ps2 * ps2, uint8_t * data, int length, bool re
}
// If a timeout happened, return the error
if (timeout == 0) {
return -1;
ps2_reset(ps2);
return -0x1000;
}
if (read) {
data[i] = *(ps2->data);
}
// Set interface to defaults
ps2_reset(ps2);
}
return i;