Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define MOSS_MAX_PS2_ATTEMPTS 3
- namespace MOSS { namespace Input { namespace Devices {
- //This class encapsulates the PS/2 controller, (sometimes referred to elsewhere as "keyboard controller"; a
- //misnomer since the PS/2 controller controls up to two devices). This is a good diagram of the setup:
- //http://wiki.osdev.org/%228042%22_PS/2_Controller#Overview.
- class DevicePS2Keyboard;
- class DevicePS2Mouse;
- //http://wiki.osdev.org/%228042%22_PS/2_Controller
- class ControllerPS2 {
- private:
- enum ControllerIO {
- DataPort = 0x0060u,
- StatusRegister = 0x0064u,
- CommandRegister = 0x0064u
- };
- class StatusByte { public: //"Compaq status byte" (not actually Compaq-specific (anymore).
- union {
- struct {
- bool output_buffer_full : 1;
- bool input_buffer_full : 1;
- uint8_t system_flag : 1;
- uint8_t input_for_device_or_controller : 1; //Writes to input buffer for 0=PS/2 device, 1=PS/2 controller
- uint8_t unknown : 1; //May be keyboard locked
- uint8_t data_from_which_device : 1; //http://wiki.osdev.org/Mouse_Input#Keyboard.2FAux_Data_Bit (0=keyboard, 1=mouse) //May be "receive time-out" or "second PS/2 port output buffer full" (first link implies it is definitely the second)
- bool timeout_error : 1;
- uint8_t parity_error : 1;
- };
- uint8_t data_byte;
- };
- };
- class ConfigurationByte { public:
- union {
- struct {
- bool first_port_interrupts_enabled : 1;
- bool second_port_interrupts_enabled : 1;
- bool system_flag : 1;
- uint8_t zero1 : 1;
- bool first_port_clock_disabled : 1;
- bool second_port_clock_disabled : 1;
- bool first_port_translation : 1; //from scan code set n to scan code set 1?
- uint8_t zero2 : 1;
- };
- uint8_t data_byte;
- };
- };
- public:
- DevicePS2Keyboard* keyboard;
- DevicePS2Mouse* mouse;
- public:
- ControllerPS2(void);
- ~ControllerPS2(void);
- public:
- void send_command(uint8_t command);
- void send_data(uint8_t data);
- bool recv_data(uint8_t* data, int timeout_counter=-1);
- bool is_inputbuffer_full(void) const;
- bool is_outputbuffer_full(void) const;
- void wait_for_inputbuffer_clear(void) const;
- void wait_for_outputbuffer_full(void) const;
- private:
- StatusByte _get_status_byte(void) const;
- ConfigurationByte _get_configuration_byte(void);
- void _set_configuration_byte(const ConfigurationByte& config_byte);
- };
- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement