IBM Personal Computer/2 ports.
More...
|
| enum | ps2_port_t {
PS2_PORT_DATA = 0x60
,
PS2_PORT_STATUS = 0x64
,
PS2_PORT_CMD = 0x64
} |
| | PS/2 controller I/O ports. More...
|
| |
| enum | ps2_cmd_t {
PS2_CMD_CFG_READ = 0x20
,
PS2_CMD_CFG_WRITE = 0x60
,
PS2_CMD_SECOND_DISABLE = 0xA7
,
PS2_CMD_SECOND_ENABLE = 0xA8
,
PS2_CMD_FIRST_DISABLE = 0xAD
,
PS2_CMD_FIRST_ENABLE = 0xAE
,
PS2_CMD_SECOND_TEST = 0xA9
,
PS2_CMD_SELF_TEST = 0xAA
,
PS2_CMD_FIRST_TEST = 0xAB
,
PS2_CMD_DUMP = 0xAC
,
PS2_CMD_SECOND_WRITE = 0xD4
} |
| | PS/2 controller commands. More...
|
| |
| enum | ps2_status_bits_t {
PS2_STATUS_OUT_FULL = (1 << 0)
,
PS2_STATUS_IN_FULL = (1 << 1)
,
PS2_STATUS_SYSTEM_FLAG = (1 << 2)
,
PS2_STATUS_CMD_DATA = (1 << 3)
,
PS2_STATUS_TIMEOUT_ERROR = (1 << 6)
,
PS2_STATUS_PARITY_ERROR = (1 << 7)
} |
| | PS/2 controller status register bits. More...
|
| |
| enum | ps2_config_bits_t {
PS2_CFG_FIRST_IRQ = (1 << 0)
,
PS2_CFG_SECOND_IRQ = (1 << 1)
,
PS2_CFG_SYSTEM_FLAG = (1 << 2)
,
PS2_CFG_RESERVED_3 = (1 << 3)
,
PS2_CFG_FIRST_CLOCK_DISABLE = (1 << 4)
,
PS2_CFG_SECOND_CLOCK_DISABLE = (1 << 5)
,
PS2_CFG_FIRST_TRANSLATION = (1 << 6)
,
PS2_CFG_RESERVED_7 = (1 << 7)
} |
| | PS/2 controller configuration bits. More...
|
| |
| enum | ps2_device_cmd_t {
PS2_DEV_CMD_ECHO = 0xEE
,
PS2_DEV_CMD_SET_LEDS = 0xED
,
PS2_DEV_CMD_SET_SCANCODE_SET = 0xF0
,
PS2_DEV_CMD_IDENTIFY = 0xF2
,
PS2_DEV_CMD_SET_TYPEMATIC = 0xF3
,
PS2_DEV_CMD_ENABLE_SCANNING = 0xF4
,
PS2_DEV_CMD_DISABLE_SCANNING = 0xF5
,
PS2_DEV_CMD_SET_DEFAULTS = 0xF6
,
PS2_DEV_CMD_RESEND = 0xFE
,
PS2_DEV_CMD_RESET = 0xFF
} |
| | PS/2 device commands. More...
|
| |
| enum | ps2_device_t {
PS2_DEV_NONE = -1
,
PS2_DEV_FIRST = 0
,
PS2_DEV_SECOND = 1
,
PS2_DEV_COUNT = 2
} |
| | PS/2 device identifiers. More...
|
| |
| enum | ps2_device_type_t {
PS2_DEV_TYPE_UNKNOWN
,
PS2_DEV_TYPE_KEYBOARD
,
PS2_DEV_TYPE_MOUSE_STANDARD
,
PS2_DEV_TYPE_MOUSE_SCROLL
,
PS2_DEV_TYPE_MOUSE_5BUTTON
} |
| | PS/2 device types. More...
|
| |
| enum | ps2_self_test_response_t {
PS2_SELF_TEST_PASS = 0x55
,
PS2_SELF_TEST_FAIL = 0xFC
} |
| | PS/2 controller self-test responses. More...
|
| |
| enum | ps2_device_test_response_t {
PS2_DEV_TEST_PASS = 0x00
,
PS2_DEV_TEST_CLOCK_STUCK_LOW = 0x01
,
PS2_DEV_TEST_CLOCK_STUCK_HIGH = 0x02
,
PS2_DEV_TEST_DATA_STUCK_LOW = 0x03
,
PS2_DEV_TEST_DATA_STUCK_HIGH = 0x04
} |
| | PS/2 device test responses. More...
|
| |
| enum | ps2_device_response_t {
PS2_DEV_RESPONSE_ACK = 0xFA
,
PS2_DEV_RESPONSE_RESEND = 0xFE
,
PS2_DEV_RESPONSE_BAT_OK = 0xAA
,
PS2_DEV_RESPONSE_KBD_EXTENDED = 0xE0
,
PS2_DEV_RESPONSE_KBD_RELEASE = 0xF0
} |
| | PS/2 device command responses. More...
|
| |
IBM Personal Computer/2 ports.
- See also
- https://wiki.osdev.org/I8042_PS/2_Controller
-
https://www-ug.eecg.toronto.edu/msl/nios_devices/datasheets/PS2%20Keyboard%20Protocol.htm
◆ PS2_CMD
| #define PS2_CMD |
( |
|
command | ) |
|
Value: ({ \
result; \
})
uint64_t ps2_send_cmd(ps2_cmd_t command)
Send a command to the PS/2 controller.
Send a command to the PS/2 controller without reading response.
- Parameters
-
- Returns
- On success,
0. On failure, ERR and errno is set to ETIMEOUT if timeout occurs.
Definition at line 221 of file ps2.h.
◆ PS2_CMD_AND_READ
| #define PS2_CMD_AND_READ |
( |
|
command, |
|
|
|
data |
|
) |
| |
Value: ({ \
{ \
} \
result; \
})
#define ERR
Integer error value.
#define PS2_READ(data)
Read data from PS/2 controller.
Send a command to the PS/2 controller and read response.
- Parameters
-
| command | Command to send. |
| data | Pointer to store the response byte |
- Returns
- On success,
0. On failure, ERR and errno is set to ETIMEOUT if timeout occurs.
Definition at line 234 of file ps2.h.
◆ PS2_CMD_AND_WRITE
| #define PS2_CMD_AND_WRITE |
( |
|
command, |
|
|
|
data |
|
) |
| |
Value: ({ \
{ \
} \
result; \
})
#define PS2_WRITE(data)
Write data to PS/2 controller.
Send a command to the PS/2 controller and write data.
- Parameters
-
| command | Command to send. |
| data | Data to write. |
- Returns
- On success,
0. On failure, ERR and errno is set to ETIMEOUT if timeout occurs.
Definition at line 251 of file ps2.h.
◆ PS2_COMMAND_RETRIES
| #define PS2_COMMAND_RETRIES 10 |
Number of retries for commands.
Definition at line 36 of file ps2.h.
◆ PS2_DEV_CMD
| #define PS2_DEV_CMD |
( |
|
device, |
|
|
|
command |
|
) |
| |
Value: ({ \
result; \
})
uint64_t ps2_send_device_cmd(ps2_device_t device, ps2_device_cmd_t command)
Send a command to a PS/2 device.
Send a command to a PS/2 device without reading response.
- Parameters
-
| device | Device to send command to, specified by its port. |
| command | Command to send. |
- Returns
- On success,
0. On failure, ERR and errno is set to ETIMEOUT if timeout occurs.
Definition at line 268 of file ps2.h.
◆ PS2_DEV_CMD_AND_READ
| #define PS2_DEV_CMD_AND_READ |
( |
|
device, |
|
|
|
command, |
|
|
|
data |
|
) |
| |
Value: ({ \
{ \
} \
result; \
})
Send a command to a PS/2 device and read response.
- Parameters
-
| device | Device to send command to, specified by its port. |
| command | Command to send. |
| data | Pointer to store the response byte |
- Returns
- On success,
0. On failure, ERR and errno is set to ETIMEOUT if timeout occurs.
Definition at line 282 of file ps2.h.
◆ PS2_DEV_SUB_CMD
| #define PS2_DEV_SUB_CMD |
( |
|
device, |
|
|
|
command, |
|
|
|
subCommand |
|
) |
| |
Value: ({ \
{ \
} \
result; \
})
#define PS2_DEV_CMD(device, command)
Send a command to a PS/2 device without reading response.
Send a command and a subcommand to a PS/2 device.
- Parameters
-
| device | Device to send command to, specified by its port. |
| command | Command to send. |
| subCommand | Subcommand to send. |
- Returns
- On success,
0. On failure, ERR and errno is set to ETIMEOUT if timeout occurs.
Definition at line 300 of file ps2.h.
◆ PS2_LARGE_DELAY
Large delay for various operations.
Definition at line 31 of file ps2.h.
◆ PS2_READ
Value: ({ \
{ \
} \
result; \
})
static uint8_t port_inb(uint16_t port)
uint64_t ps2_wait_until_set(ps2_status_bits_t status)
Wait until status bit(s) is set.
@ PS2_STATUS_OUT_FULL
Output buffer status (0 = empty, 1 = full)
Read data from PS/2 controller.
Waits for the output buffer to be full, then reads a byte from the data port.
- Parameters
-
| data | Pointer to store the read byte. |
- Returns
- On success,
0. On failure, ERR and errno is set to ETIMEOUT if timeout occurs.
Definition at line 187 of file ps2.h.
◆ PS2_SMALL_DELAY
Small delay for various operations.
Definition at line 26 of file ps2.h.
◆ PS2_WAIT_TIMEOUT
Wait timeout for PS/2 controller.
Definition at line 21 of file ps2.h.
◆ PS2_WRITE
| #define PS2_WRITE |
( |
|
data | ) |
|
Value: ({ \
{ \
} \
result; \
})
uint64_t ps2_wait_until_clear(ps2_status_bits_t status)
Wait until status bit(s) is clear.
@ PS2_STATUS_IN_FULL
Input buffer status (0 = empty, 1 = full)
Write data to PS/2 controller.
Waits for the input buffer to be empty, then writes a byte to the data port.
- Parameters
-
- Returns
- On success,
0. On failure, ERR and errno is set to ETIMEOUT if timeout occurs.
Definition at line 205 of file ps2.h.
◆ ps2_cmd_t
PS/2 controller commands.
| Enumerator |
|---|
| PS2_CMD_CFG_READ | |
| PS2_CMD_CFG_WRITE | |
| PS2_CMD_SECOND_DISABLE | |
| PS2_CMD_SECOND_ENABLE | |
| PS2_CMD_FIRST_DISABLE | |
| PS2_CMD_FIRST_ENABLE | |
| PS2_CMD_SECOND_TEST | |
| PS2_CMD_SELF_TEST | |
| PS2_CMD_FIRST_TEST | |
| PS2_CMD_DUMP | |
| PS2_CMD_SECOND_WRITE | |
Definition at line 51 of file ps2.h.
◆ ps2_config_bits_t
PS/2 controller configuration bits.
| Enumerator |
|---|
| PS2_CFG_FIRST_IRQ | First PS/2 port interrupt enable.
|
| PS2_CFG_SECOND_IRQ | Second PS/2 port interrupt enable.
|
| PS2_CFG_SYSTEM_FLAG | System flag (POST passed)
|
| PS2_CFG_RESERVED_3 | Should be zero.
|
| PS2_CFG_FIRST_CLOCK_DISABLE | First PS/2 port clock disable.
|
| PS2_CFG_SECOND_CLOCK_DISABLE | Second PS/2 port clock disable.
|
| PS2_CFG_FIRST_TRANSLATION | First PS/2 port translation enable.
|
| PS2_CFG_RESERVED_7 | Should be zero.
|
Definition at line 82 of file ps2.h.
◆ ps2_device_cmd_t
PS/2 device commands.
| Enumerator |
|---|
| PS2_DEV_CMD_ECHO | |
| PS2_DEV_CMD_SET_LEDS | |
| PS2_DEV_CMD_SET_SCANCODE_SET | |
| PS2_DEV_CMD_IDENTIFY | |
| PS2_DEV_CMD_SET_TYPEMATIC | |
| PS2_DEV_CMD_ENABLE_SCANNING | |
| PS2_DEV_CMD_DISABLE_SCANNING | |
| PS2_DEV_CMD_SET_DEFAULTS | |
| PS2_DEV_CMD_RESEND | |
| PS2_DEV_CMD_RESET | |
Definition at line 97 of file ps2.h.
◆ ps2_device_response_t
PS/2 device command responses.
| Enumerator |
|---|
| PS2_DEV_RESPONSE_ACK | |
| PS2_DEV_RESPONSE_RESEND | |
| PS2_DEV_RESPONSE_BAT_OK | |
| PS2_DEV_RESPONSE_KBD_EXTENDED | Indicates that the following byte is an extended scancode.
|
| PS2_DEV_RESPONSE_KBD_RELEASE | Indicates that the following byte is a key release code.
|
Definition at line 170 of file ps2.h.
◆ ps2_device_t
PS/2 device identifiers.
| Enumerator |
|---|
| PS2_DEV_NONE | No device.
|
| PS2_DEV_FIRST | First PS/2 port.
|
| PS2_DEV_SECOND | Second PS/2 port.
|
| PS2_DEV_COUNT | Total number of ports.
|
Definition at line 114 of file ps2.h.
◆ ps2_device_test_response_t
PS/2 device test responses.
| Enumerator |
|---|
| PS2_DEV_TEST_PASS | |
| PS2_DEV_TEST_CLOCK_STUCK_LOW | |
| PS2_DEV_TEST_CLOCK_STUCK_HIGH | |
| PS2_DEV_TEST_DATA_STUCK_LOW | |
| PS2_DEV_TEST_DATA_STUCK_HIGH | |
Definition at line 158 of file ps2.h.
◆ ps2_device_type_t
PS/2 device types.
| Enumerator |
|---|
| PS2_DEV_TYPE_UNKNOWN | |
| PS2_DEV_TYPE_KEYBOARD | |
| PS2_DEV_TYPE_MOUSE_STANDARD | |
| PS2_DEV_TYPE_MOUSE_SCROLL | |
| PS2_DEV_TYPE_MOUSE_5BUTTON | |
Definition at line 125 of file ps2.h.
◆ ps2_port_t
PS/2 controller I/O ports.
| Enumerator |
|---|
| PS2_PORT_DATA | |
| PS2_PORT_STATUS | |
| PS2_PORT_CMD | |
Definition at line 41 of file ps2.h.
◆ ps2_self_test_response_t
PS/2 controller self-test responses.
| Enumerator |
|---|
| PS2_SELF_TEST_PASS | |
| PS2_SELF_TEST_FAIL | |
Definition at line 149 of file ps2.h.
◆ ps2_status_bits_t
PS/2 controller status register bits.
| Enumerator |
|---|
| PS2_STATUS_OUT_FULL | Output buffer status (0 = empty, 1 = full)
|
| PS2_STATUS_IN_FULL | Input buffer status (0 = empty, 1 = full)
|
| PS2_STATUS_SYSTEM_FLAG | |
| PS2_STATUS_CMD_DATA | Command(1) or Data(0)
|
| PS2_STATUS_TIMEOUT_ERROR | |
| PS2_STATUS_PARITY_ERROR | |
Definition at line 69 of file ps2.h.
◆ ps2_drain()
◆ ps2_send_cmd()
◆ ps2_send_device_cmd()
Send a command to a PS/2 device.
- Parameters
-
| device | Device to send command to, specified by its port. |
| command | Command to send. |
- Returns
- On success,
0. On failure, ERR and errno is set to ETIMEOUT if timeout occurs.
Definition at line 481 of file ps2.c.
References ERR, LOG_ERR, LOG_WARN, PS2_CMD_SECOND_WRITE, PS2_COMMAND_RETRIES, PS2_DEV_RESPONSE_ACK, PS2_DEV_RESPONSE_RESEND, PS2_DEV_SECOND, ps2_device_to_string(), PS2_READ, ps2_send_cmd(), and PS2_WRITE.
◆ ps2_wait_until_clear()
◆ ps2_wait_until_set()