MentOS  0.8.0
The Mentoring Operating System
Macros | Functions
ps2.c File Reference

PS/2 drivers. More...

Macros

#define __DEBUG_HEADER__   "[PS/2 ]"
 Change header.
 
#define __DEBUG_LEVEL__   LOGLEVEL_NOTICE
 Set log level.
 
#define PS2_DATA   0x60
 Data signal line.
 
#define PS2_STATUS   0x64
 Status and command signal line.
 
#define PS2_CTRL_TEST_CONTROLLER   0xAA
 Command to test the PS/2 controller; returns 0x55 for pass, 0xFC for fail.
 
#define PS2_CTRL_P1_ENABLE   0xAE
 Command to enable the first PS/2 port; does not return a response.
 
#define PS2_CTRL_P1_DISABLE   0xAD
 Command to disable the first PS/2 port; does not return a response.
 
#define PS2_CTRL_P1_TEST   0xAB
 Command to test the first PS/2 port; returns status results.
 
#define PS2_CTRL_P2_ENABLE   0xA8
 Command to enable the second PS/2 port; does not return a response.
 
#define PS2_CTRL_P2_DISABLE   0xA7
 Command to disable the second PS/2 port; does not return a response.
 
#define PS2_CTRL_P2_TEST   0xA9
 Command to test the second PS/2 port; applicable only if both ports are supported.
 
#define PS2_CTRL_READ_OUTPUT_PORT   0xD0
 Reads the current state of the output port.
 
#define PS2_CTRL_WRITE_OUTPUT_PORT   0xD1
 Writes to the output port, controls system reset line and other signals.
 
#define PS2_CTRL_READ_RAM_BYTE_0   0x20
 Reads the configuration byte from PS/2 controller RAM.
 
#define PS2_CTRL_WRITE_RAM_BYTE_0   0x60
 Writes to the configuration byte in PS/2 controller RAM.
 
#define PS2_CTRL_P1_RESET   0xFE
 Resets the first PS/2 port.
 
#define PS2_DEV_RESET   0xFF
 Resets the device (keyboard or mouse), triggers self-test.
 
#define PS2_DEV_DISABLE_SCAN   0xF5
 Disables scanning, stops the device from sending scancodes.
 
#define PS2_DEV_ENABLE_SCAN   0xF4
 Enables scanning, allowing the device to send scancodes.
 
#define PS2_DEV_SET_DEFAULTS   0xF6
 Sets the device to its default settings.
 
#define PS2_DEV_SET_LED   0xED
 Sets the keyboard LED state (Caps Lock, Num Lock, Scroll Lock).
 
#define PS2_DEV_SCAN_CODE_SET   0xF0
 Selects the scancode set (requires additional byte to specify the set).
 
#define PS2_DEV_SELF_TEST_PASS   0xAA
 Self-test passed (sent after a reset or power-up).
 
#define PS2_DEV_SET_TYPEMATIC_ACK   0xFA
 Acknowledges the Set Typematic Rate/Delay command.
 
#define PS2_DEV_OVERRUN   0xFF
 Indicates a buffer overrun during communication.
 
#define PS2_ECHO_RES   0xEE
 Response indicating the controller received an "echo" command (0xEE).
 
#define PS2_TEST_FAIL1   0xFC
 Response indicating self-test failure (after 0xFF reset command or power-up).
 
#define PS2_TEST_FAIL2   0xFD
 Response indicating self-test failure (after 0xFF reset command or power-up).
 
#define PS2_RESEND   0xFE
 Response requesting the controller to resend the last command sent.
 
#define PS2_STATUS_OUTPUT_FULL   0x01
 Output buffer is full, data is available to be read.
 
#define PS2_STATUS_INPUT_FULL   0x02
 Input buffer is full, cannot send another command until it's clear.
 
#define PS2_STATUS_SYSTEM   0x04
 "System" flag, distinguishes between system and non-system events.
 
#define PS2_STATUS_COMMAND   0x08
 1 if data in input buffer is a command, 0 if it's data.
 
#define PS2_STATUS_TIMEOUT   0x40
 Timeout error has occurred.
 
#define PS2_STATUS_PARITY_ERROR   0x80
 Parity error occurred during communication.
 

Functions

void ps2_write_data (unsigned char data)
 Writes a byte of data to the PS/2 device. More...
 
void ps2_write_command (unsigned char command)
 Sends a command to the PS/2 controller. More...
 
unsigned char ps2_read_data (void)
 Reads a byte of data from the PS/2 device. More...
 
static unsigned char __ps2_get_controller_status (void)
 Reads the PS2 controller status. More...
 
static void __ps2_set_controller_status (unsigned char status)
 Sets the PS2 controller status. More...
 
static int __ps2_is_dual_channel (void)
 Checks if the PS2 controller is dual channel. More...
 
static void __ps2_enable_first_port (void)
 Enables the first PS2 port.
 
static void __ps2_enable_second_port (void)
 Enables the second PS2 port.
 
static void __ps2_disable_first_port (void)
 Disables the first PS2 port.
 
static void __ps2_disable_second_port (void)
 Disables the second PS2 port.
 
static void __ps2_write_first_port (unsigned char byte)
 Writes a byte of data to the first PS/2 port (typically for a keyboard). More...
 
static void __ps2_write_second_port (unsigned char byte)
 Writes a byte of data to the second PS/2 port (typically for a mouse). More...
 
static const char * __ps2_get_response_error_message (unsigned response)
 Returns the string describing the received response. More...
 
int ps2_initialize (void)
 Initializes ps2 devices. More...
 

Detailed Description

PS/2 drivers.

Function Documentation

◆ __ps2_get_controller_status()

static unsigned char __ps2_get_controller_status ( void  )
inlinestatic

Reads the PS2 controller status.

Returns
the PS2 controller status.

◆ __ps2_get_response_error_message()

static const char* __ps2_get_response_error_message ( unsigned  response)
static

Returns the string describing the received response.

Parameters
responsethe response received from the PS2 device.
Returns
the string describing the received response.

◆ __ps2_is_dual_channel()

static int __ps2_is_dual_channel ( void  )
inlinestatic

Checks if the PS2 controller is dual channel.

Returns
1 if dual channel, 0 otherwise.

◆ __ps2_set_controller_status()

static void __ps2_set_controller_status ( unsigned char  status)
inlinestatic

Sets the PS2 controller status.

Parameters
statusthe PS2 controller status.

◆ __ps2_write_first_port()

static void __ps2_write_first_port ( unsigned char  byte)
inlinestatic

Writes a byte of data to the first PS/2 port (typically for a keyboard).

Parameters
byteThe value to write to the first PS/2 port.

◆ __ps2_write_second_port()

static void __ps2_write_second_port ( unsigned char  byte)
inlinestatic

Writes a byte of data to the second PS/2 port (typically for a mouse).

Parameters
byteThe value to write to the second PS/2 port.

◆ ps2_initialize()

int ps2_initialize ( void  )

Initializes ps2 devices.

Returns
0 on success, 1 on failure.

◆ ps2_read_data()

unsigned char ps2_read_data ( void  )

Reads a byte of data from the PS/2 device.

This function waits until data is available in the output buffer of the PS/2 controller. Once data is available, it reads and returns the byte from the PS/2 data register.

Returns
The byte of data read from the PS/2 device.

◆ ps2_write_command()

void ps2_write_command ( unsigned char  command)

Sends a command to the PS/2 controller.

This function waits until the input buffer of the PS/2 controller is empty before writing the specified command to the PS/2 command register.

Parameters
commandThe command byte to be sent to the PS/2 controller.

◆ ps2_write_data()

void ps2_write_data ( unsigned char  data)

Writes a byte of data to the PS/2 device.

This function waits until the input buffer of the PS/2 controller is empty before sending the specified data byte to the PS/2 data register.

Parameters
dataThe byte of data to be sent to the PS/2 device.