PS2 Controller
description
Transcript of PS2 Controller
![Page 1: PS2 Controller](https://reader036.fdocuments.us/reader036/viewer/2022081801/544f9364b1af9f61588b458f/html5/thumbnails/1.jpg)
PS/2 Core for AlteraDE-Series Boards
For Quartus II 11.0
1 Core Overview
The PS/2 Serial Port on Altera DE2/DE1 boards is intended for connecting a keyboard or a mouse to the board.The PS/2 Core provides a connection to the PS/2 Serial Port and presents an easy-to-use communication interface toPS/2 peripherals.
2 Functional Description
The PS/2 Core handles the timing of the PS/2 Serial Data Transmission Protocol. A device driver can communicatewith it by reading from and writing to its data and control registers.
3 Instantiating the Core in SOPC Builder
Designers can implement a PS/2 Core by using the SOPC Builder. There is no need to configure the core. The corecomes with a 256-word FIFO for storing data received from a PS/2 device.
4 Software Programming Model
4.1 Register Map
Device drivers control and communicate with the PS/2 Core through two 32-bit registers. Communication with thePS/2 peripheral is done by writing or reading the registers through the Avalon Slave Port. Table 1 shows the detailsfor the registers.
Table 1. PS/2 Core register mapOffset Register R/W/C Bit description
in bytes Name 31. . . 16 15 14. . . 11 10 9 8 7. . . 1 00 data R/W RAVAIL RVALID (1) DATA4 control R/C (1) CE (1) RI (1) RE
Notes on Table 1:
(1) Reserved. Read values are undefined. Write zero.
Altera Corporation - University ProgramMay 2011
1
![Page 2: PS2 Controller](https://reader036.fdocuments.us/reader036/viewer/2022081801/544f9364b1af9f61588b458f/html5/thumbnails/2.jpg)
PS/2 CORE FOR ALTERA DE-SERIES BOARDS For Quartus II 11.0
4.1.1 data Register
Table 2. data register bitsBit number Bit name Read/Write/Clear Description
7. . . 0 DATA R/W The value to transfer to/from the PS/2 core. When writ-ing, the DATA field is interpreted as a command to besent to the PS/2 device. When reading, the DATA fieldis data from the PS/2 device.
15 RVALID R Indicates whether the DATA field is valid. IfRVALID=1, then the DATA field is valid, else the DATAis undefined.
31. . . 16 RAVAIL R The number of data items remaining in the read FIFO(including this read).
4.1.2 control Register
Table 3. control register bitsBit number Bit name Read/Write/Clear Description
0 RE R/W Interrupt-enable bit for read interrupts.8 RI R Indicates that a read interrupt is pending.
10 CE C Indicates that an error occurred while trying to send acommand to a PS/2 device.
4.2 Software Functions
The PS/2 Core is packaged with C-language functions accessible through the the hardware abstraction layer (HAL)as listed below. These functions implement common operations that users need for the PS/2 Core.
To use the functions, the C code must include the statement:
#include "altera_up_avalon_ps2.h"
In addition, some sample functions for specific communication with the keyboard or mouse are also provided.They serve as a good starting point if the user wishes to develop more features with the PS/2 Port. To use thekeyboard or mouse communication functions, the corresponding header files, altera_up_ps2_keyboard.hand altera_up_ps2_mouse.h, have to be included. These functions are described below.
2 Altera Corporation - University ProgramMay 2011
![Page 3: PS2 Controller](https://reader036.fdocuments.us/reader036/viewer/2022081801/544f9364b1af9f61588b458f/html5/thumbnails/3.jpg)
PS/2 CORE FOR ALTERA DE-SERIES BOARDS For Quartus II 11.0
4.3 PS/2 Port Documentation
4.3.1 PS2 DEVICE
Prototype:typedef enum {
PS2_MOUSE = 0;PS2_KEYBOARD = 1;PS2_UNKNOWN = 2;
} PS2_DEVICE;
Include: <altera_up_avalon_ps2.h>Fields: PS2_MOUSE — Indicate that the device is a PS/2 Mouse.
PS2_KEYBOARD — Indicate that the device is a PS/2 Keyboard.PS2_UNKNOWN— The program cannot determine what type the deviceis.
4.3.2 alt up ps2 init
Prototype: void alt_up_ps2_init(alt_up_ps2_dev *ps2)Include: <altera_up_avalon_ps2.h>Parameters: ps2 – the PS/2 device structure.Description: Initialize the PS/2 device and detect device type (mouse or keyboard).Notes: The function will set the device_type field of ps2 to PS2_MOUSE
or PS2_KEYBOARD upon successful initialization, otherwise the intial-ization is unsuccessful.
4.3.3 alt up ps2 enable read interrupt
Prototype: void alt_up_ps2_enable_read_interrupt(alt_up_ps2_dev
*ps2)Include: <altera_up_avalon_ps2.h>Parameters: ps2 – the PS/2 device structure.Returns: nothingDescription: Enable read interrupts for the PS/2 port.
4.3.4 alt up ps2 disable read interrupt
Prototype: void alt_up_ps2_disable_read_interrupt(alt_up_ps2_dev
*ps2)Include: <altera_up_avalon_ps2.h>Parameters: ps2 – the PS/2 device structure.Returns: nothingDescription: Diaable read interrupts for the PS/2 port.
Altera Corporation - University ProgramMay 2011
3
![Page 4: PS2 Controller](https://reader036.fdocuments.us/reader036/viewer/2022081801/544f9364b1af9f61588b458f/html5/thumbnails/4.jpg)
PS/2 CORE FOR ALTERA DE-SERIES BOARDS For Quartus II 11.0
4.3.5 alt up ps2 write data byte
Prototype: int alt_up_ps2_write_data_byte(alt_up_ps2_dev
*ps2, unsigned char byte)Include: <altera_up_avalon_ps2.h>Parameters: ps2 – the PS/2 device structure.
byte – the byte to be written to the PS/2 port.Returns: 0 on success, or -EIO on failure.Description: Write a byte to the PS/2 port.
4.3.6 alt up ps2 write data byte with ack
Prototype: int alt_up_ps2_write_data_byte_with_ack(alt_up_ps2_dev
*ps2, unsigned char byte)Include: <altera_up_avalon_ps2.h>Parameters: ps2 – the PS/2 device structure.
byte – the byte to be written to the PS/2 port.Returns: 0 on success, -EIO on write failure, or -ETIMEDOUT on timeout when
waiting for the acknowledgment.Description: Write a byte to the PS/2 port and wait for the acknowledgment.Notes: The timeout value is defined in the PS/2 device structure .
4.3.7 alt up ps2 read data byte
Prototype: int alt_up_ps2_read_data_byte(alt_up_ps2_dev
*ps2, unsigned char *byte)Include: <altera_up_avalon_ps2.h>Parameters: ps2 – the PS/2 device structure.
byte – pointer to the memory location to store the byte.Returns: 0 on success, or -ETIMEDOUT when timeout.Description: Read a byte from the PS/2 port.Notes: User can set disable the timeout by setting the timeout in to 0.
4.3.8 alt up ps2 clear fifo
Prototype: void alt_up_ps2_clear_fifo(alt_up_ps2_dev *ps2)Include: <altera_up_avalon_ps2.h>Parameters: ps2 – the PS/2 device structure.Description: Clear the FIFO for the PS/2 port.
4 Altera Corporation - University ProgramMay 2011
![Page 5: PS2 Controller](https://reader036.fdocuments.us/reader036/viewer/2022081801/544f9364b1af9f61588b458f/html5/thumbnails/5.jpg)
PS/2 CORE FOR ALTERA DE-SERIES BOARDS For Quartus II 11.0
4.3.9 alt up ps2 read fd
Prototype: int alt_up_ps2_read_fd(alt_fd *fd, char *ptr,int len)
Include: <altera_up_avalon_ps2.h>Parameters: fd – the file descriptor for the PS/2 device.
ptr – memory location to store the bytes read.len – number of bytes to be read.
Returns: the number of bytes actually read.Description: Read len bytes from the PS/2 device.
4.3.10 alt up ps2 write fd
Prototype: int alt_up_ps2_write_fd(alt_fd *fd, const char
*ptr, int len)Include: <altera_up_avalon_ps2.h>Parameters: fd – the file descriptor for the PS/2 device.
ptr – memory location storing the bytes to write.len – number of bytes to write.
Returns: the number of bytes actually written.Description: Write len bytes to the PS/2 device from memory location pointed by ptr
.
4.3.11 alt up ps2 open dev
Prototype: alt_up_ps2_dev* alt_up_ps2_open_dev(const char
*name)Include: <altera_up_avalon_ps2.h>Parameters: name the specified name of the device in SOPC BuilderReturns: the PS/2 device structureDescription: Open a PS/2 device structure with name in SOPC Builder.
Altera Corporation - University ProgramMay 2011
5
![Page 6: PS2 Controller](https://reader036.fdocuments.us/reader036/viewer/2022081801/544f9364b1af9f61588b458f/html5/thumbnails/6.jpg)
PS/2 CORE FOR ALTERA DE-SERIES BOARDS For Quartus II 11.0
4.4 PS/2 Keyboard Documentation
4.4.1 KB CODE TYPE
Prototype:typedef enum {
KB_ASCII_MAKE_CODE = 1;KB_BINARY_MAKE_CODE = 2;KB_LONG_BINARY_MAKE_CODE = 3;KB_BREAK_CODE = 4;KB_LONG_BREAK_CODE = 5;KB_INVALID_CODE = 6;
} KB_CODE_TYPE;
Include: <altera_up_ps2_keyboard.h>Fields: KB_ASCII_MAKE_CODE — Make code that corresponds to an ASCII
character. For example, the ASCII make code for key [ A ] is 1C.KB_BINARY_MAKE_CODE — Make code that corresponds to a non-ASCII character. For example, the binary (non-ASCII) make code forkey [Left Alt] is 11.KB_LONG_BINARY_MAKE_CODE — Make code that has two bytes(the first byte is E0). For example, the long binary make code for key[Right Alt] is "E0 11".KB_BREAK_CODE — Break code that has two bytes (the first byte isF0). For example, the break code for key [ A ] is "F0 1C".KB_LONG_BREAK_CODE — Long break code that has three bytes(with the first two bytes "E0 F0"). For example, the long break codefor key [Right Alt] is "E0 F0 11".KB_INVALID_CODE — Scan codes that the decoding FSM is unableto decode.
Description: The enum type for the type of keyboard code received.
6 Altera Corporation - University ProgramMay 2011
![Page 7: PS2 Controller](https://reader036.fdocuments.us/reader036/viewer/2022081801/544f9364b1af9f61588b458f/html5/thumbnails/7.jpg)
PS/2 CORE FOR ALTERA DE-SERIES BOARDS For Quartus II 11.0
4.4.2 decode scancode
Prototype: int decode_scancode(alt_up_ps2_dev *ps2,KB_CODE_TYPE *decode_mode, alt_u8 *buf, char
*ascii)Include: <altera_up_ps2_keyboard.h>Parameters: ps2 – the PS/2 device structure. The actually connected PS/2 device
has to be a keyboard otherwise the function’s behavior is undefined.decode_mode – indicates which type of code (Make Code, BreakCode, etc.) is received from the keyboard when the key is pressed.buf – points to the location that stores the make/break code of the keypressed.ascii – pointer to the memory location to store the pressed ASCIIcharacter. If a non-ASCII key is pressed, ascii will be set to 0
Returns: 0 for success, or negative errno for corresponding errors.Description: Communicate with the PS/2 keyboard and get the make code of the key
when a key is pressed.Notes: For KB_LONG_BINARY_MAKE_CODE and KB_BREAK_CODE , only
the second byte is returned. For KB_LONG_BREAK_CODE , only thethird byte is returned.
4.4.3 set keyboard rate
Prototype: alt_u32 set_keyboard_rate(alt_up_ps2_dev *ps2,alt_u8 rate)
Include: <altera_up_ps2_keyboard.h>Parameters: rate – an 8-bit number that represents the repeat/delay rate of the key-
board.Returns: 0 on success, negative value on error.Description: Set the repeat/delay rate of the keyboard.
4.4.4 translate make code
Prototype: void translate_make_code(KB_CODE_TYPEdecode_mode, alt_u8 makecode, char *str)
Include: <altera_up_ps2_keyboard.h>Parameters: decode_mode – the type of the make code (ASCII, binary, or long
binary)makecode – the last byte of the make code (if the make code has mul-tiple bytes)str – the pointer to the memory location to store the description string
Description: Translate the make code into string description.
Altera Corporation - University ProgramMay 2011
7
![Page 8: PS2 Controller](https://reader036.fdocuments.us/reader036/viewer/2022081801/544f9364b1af9f61588b458f/html5/thumbnails/8.jpg)
PS/2 CORE FOR ALTERA DE-SERIES BOARDS For Quartus II 11.0
4.4.5 reset keyboard
Prototype: alt_u32 reset_keyboard()Include: <altera_up_ps2_keyboard.h>Parameters: –Returns: 0 on passing the BAT (Basic Assurance Test), negative value on error.Description: Send the reset command to the keyboard.
4.5 PS/2 Mouse Documentation
4.5.1 alt up ps2 mouse reset
Prototype: int alt_up_ps2_mouse_reset(alt_up_ps2_dev *ps2)Include: <altera_up_ps2_mouse.h>Parameters: ps2 – the PS/2 mouse device strctureReturns: 0 on BAT is passed, -EINVAL when the PS/2 device is not mouse, or
-EIO if error occurs.Description: Reset the mouse.
4.5.2 alt up ps2 mouse set mode
Prototype: int alt_up_ps2_mouse_set_mode(alt_up_ps2_dev
*ps2, alt_u8 byte)Include: <altera_up_ps2_mouse.h>Parameters: ps2 – the PS/2 mouse device strcture
byte – the byte representing the mode (see macro definitions for de-tails).
Returns: 0 on receiving acknowledgment, or negative number for errors.Description: Set the operation mode of the mouse.See also: PS/2 Mouse document
8 Altera Corporation - University ProgramMay 2011