driver/ps2: tell if the system has PS/2 mouse, replate Printfs with WriteConsoles

This commit is contained in:
Edgaru089 2021-10-12 15:02:34 +08:00
parent 8d53812b36
commit 76d62d921b
2 changed files with 30 additions and 9 deletions

View File

@ -9,6 +9,7 @@
#include "../../../../graphics/graphics.h"
bool irq_pic_ps2_HasMouse;
bool irq_pic_ps2_Mouse4Bytes; // the mouse has 4-byte data packages instead of 3
queue irq_pic_ps2_QueueKeyboard, irq_pic_ps2_QueueMouse;
@ -25,20 +26,29 @@ void irq_pic_ps2_Init() {
INTERRUPT_DISABLE;
irq_pic_IRQHandler[IRQ_PIC_PS2_KEYBOARD] = irq_pic_ps2_IRQHandlerK;
irq_pic_IRQHandler[IRQ_PIC_PS2_MOUSE] = irq_pic_ps2_IRQHandlerM;
irq_pic_Mask(IRQ_PIC_PS2_KEYBOARD, false);
irq_pic_Mask(IRQ_PIC_PS2_MOUSE, false);
// enable second PS/2 port
io_Printf("ENABLE_MOUSE... ");
io_WriteConsoleASCII("ENABLE_MOUSE... ");
__ps2_WriteCommand(IRQ_PIC_PS2_CMD_ENABLE_MOUSE);
// write controller mode (EnablePort1Int | EnablePort2Int | SystemPOSTOk | Port1Translation)
io_Printf("CONTROLLER_WRITE_CONFIGBYTE... ");
__ps2_WriteCommandData(IRQ_PIC_PS2_CMD_WRITE_CONFIGBYTE, 0x47);
io_WriteConsoleASCII("CONTROLLER_READ_CONFIGBYTE... ");
__ps2_WriteCommand(IRQ_PIC_PS2_CMD_READ_CONFIGBYTE);
uint8_t config = __ps2_ReadData();
// write controller mode (|= Port1Translation)
io_WriteConsoleASCII("CONTROLLER_WRITE_CONFIGBYTE... ");
__ps2_WriteCommandData(IRQ_PIC_PS2_CMD_WRITE_CONFIGBYTE, config | IRQ_PIC_PS2_CONFIG_PORT1_TRANSLATION);
if (config & IRQ_PIC_PS2_CONFIG_PORT1_CLOCK) { // mouse not present
irq_pic_ps2_HasMouse = false;
io_WriteConsoleASCII("PS/2 Controller has no mouse\n");
INTERRUPT_RESTORE;
return; // early out
}
// initialize the mouse
// reset mouse
io_Printf("DEVICE_RESET... ");
io_WriteConsoleASCII("DEVICE_RESET... ");
__ps2_WriteCommandData(IRQ_PIC_PS2_CMD_SEND_MOUSE, IRQ_PIC_PS2_CMD_DEVICE_RESET);
while ((data = __ps2_ReadData()) != IRQ_PIC_PS2_RESET_OK) {
io_Printf("%X ", data);
@ -47,7 +57,7 @@ void irq_pic_ps2_Init() {
// enable mouse reporting
io_Printf("MOUSE_ENABLE_REPORTING... ");
io_WriteConsoleASCII("MOUSE_ENABLE_REPORTING... ");
__ps2_WriteCommandData(IRQ_PIC_PS2_CMD_SEND_MOUSE, IRQ_PIC_PS2_CMD_DEVICE_MOUSE_ENABLE_REPORTING);
__ps2_ReadACK(); // receive ACK
@ -57,7 +67,7 @@ void irq_pic_ps2_Init() {
__ps2_SetMouseRate(100);
__ps2_SetMouseRate(80);
io_Printf("SEND_MOUSE(PS2_DEVICE_ID)");
io_WriteConsoleASCII("SEND_MOUSE(PS2_DEVICE_ID)");
__ps2_WriteCommandData(IRQ_PIC_PS2_CMD_SEND_MOUSE, 0xf2); // get device ID
__ps2_ReadACK();
uint8_t id = __ps2_ReadData(); // receive device ID
@ -65,6 +75,9 @@ void irq_pic_ps2_Init() {
if (id == 3) // Z-axis is enabled
irq_pic_ps2_Mouse4Bytes = true;
irq_pic_IRQHandler[IRQ_PIC_PS2_MOUSE] = irq_pic_ps2_IRQHandlerM;
irq_pic_Mask(IRQ_PIC_PS2_MOUSE, false);
// set the actual mouse sample rate
__ps2_SetMouseRate(IRQ_PIC_PS2_MOUSE_SAMPLERATE);

View File

@ -26,6 +26,13 @@ extern "C" {
#define IRQ_PIC_PS2_STATUS_TIMEOUT_ERROR (1 << 6)
#define IRQ_PIC_PS2_STATUS_PARITY_ERROR (1 << 7)
#define IRQ_PIC_PS2_CONFIG_PORT1_INTERRUPT (1 << 0) // PS/2 port interrupt (1=Enabled, 0=Disabled)
#define IRQ_PIC_PS2_CONFIG_PORT2_INTERRUPT (1 << 1) // PS/2 port interrupt (1=Enabled, 0=Disabled)
#define IRQ_PIC_PS2_CONFIG_SYSTEM_POST_OK (1 << 2) // If the system have passed POST
#define IRQ_PIC_PS2_CONFIG_PORT1_CLOCK (1 << 4) // PS/2 port clock (1=Disabled, 0=Enabled)
#define IRQ_PIC_PS2_CONFIG_PORT2_CLOCK (1 << 5) // PS/2 port clock (1=Disabled, 0=Enabled)
#define IRQ_PIC_PS2_CONFIG_PORT1_TRANSLATION (1 << 6) // PS/2 keyboard scancode translation (from Set 2 to Set 1)
#define IRQ_PIC_PS2_ACK 0xfa // ACK code for keyboard and mouse (controller cmds have no ack)
#define IRQ_PIC_PS2_RESET_OK 0xaa // the last output byte when a PS/2 device is reset
@ -42,6 +49,7 @@ extern "C" {
void irq_pic_ps2_Init();
extern bool irq_pic_ps2_HasMouse; // does the PS/2 controller have 2 channels?
extern bool irq_pic_ps2_Mouse4Bytes; // the mouse has 4-byte data packages instead of 3; mouse wheel enabled