Advertisement
Geometrian

controller_ps2.h

Jul 10th, 2013
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.10 KB | None | 0 0
  1. #define MOSS_MAX_PS2_ATTEMPTS 3
  2.  
  3.  
  4. namespace MOSS { namespace Input { namespace Devices {
  5.  
  6.  
  7. //This class encapsulates the PS/2 controller, (sometimes referred to elsewhere as "keyboard controller"; a
  8. //misnomer since the PS/2 controller controls up to two devices).  This is a good diagram of the setup:
  9. //http://wiki.osdev.org/%228042%22_PS/2_Controller#Overview.
  10.  
  11.  
  12. class DevicePS2Keyboard;
  13. class DevicePS2Mouse;
  14.  
  15. //http://wiki.osdev.org/%228042%22_PS/2_Controller
  16. class ControllerPS2 {
  17.     private:
  18.         enum ControllerIO {
  19.             DataPort        = 0x0060u,
  20.             StatusRegister  = 0x0064u,
  21.             CommandRegister = 0x0064u
  22.         };
  23.         class StatusByte { public:  //"Compaq status byte" (not actually Compaq-specific (anymore).
  24.             union {
  25.                 struct {
  26.                     bool                output_buffer_full : 1;
  27.                     bool                 input_buffer_full : 1;
  28.                     uint8_t                    system_flag : 1;
  29.                     uint8_t input_for_device_or_controller : 1; //Writes to input buffer for 0=PS/2 device, 1=PS/2 controller
  30.                     uint8_t                        unknown : 1; //May be keyboard locked
  31.                     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)
  32.                     bool                     timeout_error : 1;
  33.                     uint8_t                   parity_error : 1;
  34.                 };
  35.                 uint8_t data_byte;
  36.             };
  37.         };
  38.         class ConfigurationByte { public:
  39.             union {
  40.                 struct {
  41.                     bool  first_port_interrupts_enabled : 1;
  42.                     bool second_port_interrupts_enabled : 1;
  43.                     bool                    system_flag : 1;
  44.                     uint8_t                       zero1 : 1;
  45.                     bool      first_port_clock_disabled : 1;
  46.                     bool     second_port_clock_disabled : 1;
  47.                     bool         first_port_translation : 1; //from scan code set n to scan code set 1?
  48.                     uint8_t                       zero2 : 1;
  49.                 };
  50.                 uint8_t data_byte;
  51.             };
  52.         };
  53.     public:
  54.         DevicePS2Keyboard* keyboard;
  55.         DevicePS2Mouse* mouse;
  56.  
  57.     public:
  58.         ControllerPS2(void);
  59.         ~ControllerPS2(void);
  60.  
  61.     public:
  62.         void send_command(uint8_t command);
  63.         void send_data(uint8_t data);
  64.         bool recv_data(uint8_t* data, int timeout_counter=-1);
  65.  
  66.         bool is_inputbuffer_full(void) const;
  67.         bool is_outputbuffer_full(void) const;
  68.         void wait_for_inputbuffer_clear(void) const;
  69.         void wait_for_outputbuffer_full(void) const;
  70.  
  71.     private:
  72.         StatusByte _get_status_byte(void) const;
  73.  
  74.         ConfigurationByte _get_configuration_byte(void);
  75.         void _set_configuration_byte(const ConfigurationByte& config_byte);
  76. };
  77.  
  78.  
  79. }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement