Skip to content

Commit

Permalink
Minor renaming of PS2 interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
coderarjob committed Dec 2, 2024
1 parent 8c7a169 commit f1f563c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 29 deletions.
6 changes: 3 additions & 3 deletions include/drivers/x86/pc/8042_ps2.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
bool ps2_init();
bool ps2_wait_read (UINT ioport, U8* data);
bool ps2_wait_write (UINT ioport, U8 data);
void ps2_write_device_data (UINT device_id, U8 data);
bool ps2_write_device_cmd (UINT device_id, U8 cmd);
bool ps2_configuration (U8 enabled, U8 disabled, U8 *original_config);
void ps2_write_device_data_no_ack (UINT device_id, U8 data);
bool ps2_write_device_data_wait_ack (UINT device_id, U8 cmd);
bool ps2_configuration (U8 enabled, U8 disabled, U8* original_config);
INT ps2_identify_device (UINT device_id);

static inline U8 ps2_no_wait_read (UINT ioport)
Expand Down
6 changes: 3 additions & 3 deletions include/drivers/x86/pc/ps2_devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ typedef struct MousePositionData {
bool middle_button;
} MousePositionData;

bool ps2mouse_init();
bool ps2kb_init();
MousePositionData mouse_get_packet();
bool ps2_mouse_init();
bool ps2_kb_init();
MousePositionData ps2_mouse_get_packet();
10 changes: 5 additions & 5 deletions src/kernel/drivers/x86/pc/8042_ps2.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ bool ps2_wait_write (UINT ioport, U8 data)
return true;
}

void ps2_write_device_data (UINT device_id, U8 data)
void ps2_write_device_data_no_wait (UINT device_id, U8 data)
{
k_assert (device_id < DEVICE_COUNT, "Device ID is invalid.");

Expand All @@ -84,12 +84,12 @@ void ps2_write_device_data (UINT device_id, U8 data)
ps2_wait_write (PS2_DATA_PORT, data);
}

bool ps2_write_device_cmd (UINT device_id, U8 cmd)
bool ps2_write_device_data_wait_ack (UINT device_id, U8 cmd)
{
U8 ack, retrycount = 0;

do {
ps2_write_device_data (device_id, cmd);
ps2_write_device_data_no_wait (device_id, cmd);
if (!ps2_wait_read (PS2_DATA_PORT, &ack)) {
RETURN_ERROR (ERROR_PASSTHROUGH, false); // Possible timeout
}
Expand Down Expand Up @@ -142,11 +142,11 @@ INT ps2_identify_device (UINT device_id)
PS2_CONFIG_FIRST_PORT_TRANSLATION_ENABLE,
&config);

if (!ps2_write_device_cmd (device_id, PS2_DEV_CMD_DISABLE_SCANNING)) {
if (!ps2_write_device_data_wait_ack (device_id, PS2_DEV_CMD_DISABLE_SCANNING)) {
RETURN_ERROR (ERROR_PASSTHROUGH, KERNEL_EXIT_FAILURE);
}

if (!ps2_write_device_cmd (device_id, PS2_DEV_CMD_IDENTIFY)) {
if (!ps2_write_device_data_wait_ack (device_id, PS2_DEV_CMD_IDENTIFY)) {
RETURN_ERROR (ERROR_PASSTHROUGH, KERNEL_EXIT_FAILURE);
}

Expand Down
6 changes: 3 additions & 3 deletions src/kernel/drivers/x86/pc/ps2kb.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static bool iskeyboard()
return true;
}

bool ps2kb_init()
bool ps2_kb_init()
{
FUNC_ENTRY();

Expand All @@ -51,12 +51,12 @@ bool ps2kb_init()
}

// Set defaults
if (!ps2_write_device_cmd (PS2_FIRST_DEVICE, PS2_DEV_CMD_SET_TO_DEFAULT)) {
if (!ps2_write_device_data_wait_ack (PS2_FIRST_DEVICE, PS2_DEV_CMD_SET_TO_DEFAULT)) {
RETURN_ERROR (ERROR_PASSTHROUGH, false);
}

// Interrupt when keys are pressed
if (!ps2_write_device_cmd (PS2_FIRST_DEVICE, PS2_DEV_CMD_ENABLE_SCANNING)) {
if (!ps2_write_device_data_wait_ack (PS2_FIRST_DEVICE, PS2_DEV_CMD_ENABLE_SCANNING)) {
RETURN_ERROR (ERROR_PASSTHROUGH, false);
}

Expand Down
24 changes: 12 additions & 12 deletions src/kernel/drivers/x86/pc/ps2mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ typedef struct MouseStatus {
U8 sample_rate;
} MouseStatus;

void mouse_interrupt_asm_handler();
void ps2_mouse_interrupt_asm_handler();
static bool ismouse();
static MouseStatus get_mouse_state();

Expand Down Expand Up @@ -57,18 +57,18 @@ static MouseStatus get_mouse_state()
{
MouseStatus status = { 0 };

ps2_write_device_cmd (PS2_SECOND_DEVICE, PS2_MOUSE_CMD_GET_ID);
ps2_write_device_data_wait_ack (PS2_SECOND_DEVICE, PS2_MOUSE_CMD_GET_ID);
ps2_wait_read (PS2_DATA_PORT, &status.id);

ps2_write_device_cmd (PS2_SECOND_DEVICE, PS2_MOUSE_CMD_STATUS_REQ);
ps2_write_device_data_wait_ack (PS2_SECOND_DEVICE, PS2_MOUSE_CMD_STATUS_REQ);
ps2_wait_read (PS2_DATA_PORT, &status.status);
ps2_wait_read (PS2_DATA_PORT, &status.resolution);
ps2_wait_read (PS2_DATA_PORT, &status.sample_rate);

return status;
}

bool ps2mouse_init()
bool ps2_mouse_init()
{
FUNC_ENTRY();

Expand All @@ -81,20 +81,20 @@ bool ps2mouse_init()
}

// Set defaults
if (!ps2_write_device_cmd (PS2_SECOND_DEVICE, PS2_DEV_CMD_SET_TO_DEFAULT)) {
if (!ps2_write_device_data_wait_ack (PS2_SECOND_DEVICE, PS2_DEV_CMD_SET_TO_DEFAULT)) {
RETURN_ERROR (ERROR_PASSTHROUGH, false);
}

// Set sample rate
if (!ps2_write_device_cmd (PS2_SECOND_DEVICE, PS2_MOUSE_CMD_SET_SAMPLE_RATE)) {
if (!ps2_write_device_data_wait_ack (PS2_SECOND_DEVICE, PS2_MOUSE_CMD_SET_SAMPLE_RATE)) {
RETURN_ERROR (ERROR_PASSTHROUGH, false);
}
if (!ps2_write_device_cmd (PS2_SECOND_DEVICE, CONFIG_PS2_MOUSE_SAMPLE_RATE)) {
if (!ps2_write_device_data_wait_ack (PS2_SECOND_DEVICE, CONFIG_PS2_MOUSE_SAMPLE_RATE)) {
RETURN_ERROR (ERROR_PASSTHROUGH, false);
}

// Enable scanning by the device
if (!ps2_write_device_cmd (PS2_SECOND_DEVICE, PS2_DEV_CMD_ENABLE_SCANNING)) {
if (!ps2_write_device_data_wait_ack (PS2_SECOND_DEVICE, PS2_DEV_CMD_ENABLE_SCANNING)) {
RETURN_ERROR (ERROR_PASSTHROUGH, false);
}

Expand All @@ -113,7 +113,7 @@ bool ps2mouse_init()
ps2_configuration (PS2_CONFIG_SECOND_PORT_INTERRUPT_ENABLE, 0, NULL);

// Add handlers for keyboard interrupts
kidt_edit (0x2C, mouse_interrupt_asm_handler, GDT_SELECTOR_KCODE,
kidt_edit (0x2C, ps2_mouse_interrupt_asm_handler, GDT_SELECTOR_KCODE,
IDT_DES_TYPE_32_INTERRUPT_GATE, 0);

// Enable Mouse IRQ
Expand All @@ -122,13 +122,13 @@ bool ps2mouse_init()
return true;
}

MousePositionData mouse_get_packet()
MousePositionData ps2_mouse_get_packet()
{
return mouse_position;
}

INTERRUPT_HANDLER (mouse_interrupt)
void mouse_interrupt_handler (InterruptFrame* frame)
INTERRUPT_HANDLER (ps2_mouse_interrupt)
void ps2_mouse_interrupt_handler (InterruptFrame* frame)
{
(void)frame;

Expand Down
2 changes: 1 addition & 1 deletion src/kernel/kgraphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static void arch_waitForNextVerticalRetrace()

static void draw_cursor (const KGraphicsArea* g)
{
MousePositionData mdata = mouse_get_packet();
MousePositionData mdata = ps2_mouse_get_packet();

INT mouse_y = (INT)g->height_px / 2 - mdata.y;
INT mouse_x = (INT)g->width_px / 2 + mdata.x;
Expand Down
3 changes: 1 addition & 2 deletions src/kernel/x86/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,9 @@ void kernel_main ()

ps2_init();

if (!ps2mouse_init()) {
if (!ps2_mouse_init()) {
k_panic ("PS2 Mouse initialization falied");
}

run_root_process();
k_halt();
}
Expand Down

0 comments on commit f1f563c

Please sign in to comment.