Advertisement
Geometrian

mouse_ps2.h

Jul 10th, 2013
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | None | 0 0
  1. #include "device.h"
  2.  
  3.  
  4. namespace MOSS { namespace Input { namespace Devices {
  5.  
  6.  
  7. //http://forum.osdev.org/viewtopic.php?t=10247
  8. //http://houbysoft.com/download/ps2mouse.html (essentially the same?)
  9. //http://wiki.osdev.org/Mouse_Input (also see http://wiki.osdev.org/PS/2_Mouse)
  10.  
  11. class ControllerPS2;
  12.  
  13. class DevicePS2Mouse : public DevicePS2Base {
  14.     private:
  15.         int mouse_cycle;
  16.  
  17.         //http://www.computer-engineering.org/ps2mouse/
  18.         union {
  19.             struct {
  20.                 bool      button_left : 1;
  21.                 bool     button_right : 1;
  22.                 bool    button_middle : 1;
  23.                 bool           unused : 1; //Should be 1
  24.                 uint32_t  dx_sign_bit : 1; //Two's complement
  25.                 uint32_t  dy_sign_bit : 1; //Two's complement
  26.                 bool    dx_overflowed : 1;
  27.                 bool    dy_overflowed : 1;
  28.                 uint32_t           dx : 8;
  29.                 uint32_t           dy : 8;
  30.                 //See http://wiki.osdev.org/Mouse_Input#Formats_of_Optional_4th_Packet_Byte
  31.                 int32_t       dwheel : 4; //Only exists and valid for Intellimouse Extensions
  32.                 bool        button_4 : 1; //Only exists and valid for Intellimouse Extensions (and only iff initialized extra)
  33.                 bool        button_5 : 1; //Only exists and valid for Intellimouse Extensions (and only iff initialized extra)
  34.                 uint8_t mostly_zero1 : 1; //Only exists for Intellimouse Extensions
  35.                 uint8_t mostly_zero2 : 1; //Only exists for Intellimouse Extensions
  36.             };
  37.             struct {
  38.                 uint32_t      byte1 : 8;
  39.                 uint32_t      byte2 : 8;
  40.                 uint32_t      byte3 : 8;
  41.                 uint32_t      byte4 : 8; //Only exists for Intellimouse Extensions
  42.             };
  43.         } received_data;
  44.  
  45.     public:
  46.         int x,y;
  47.         int last_x,last_y;
  48.  
  49.     public:
  50.         DevicePS2Mouse(ControllerPS2* controller);
  51.         virtual ~DevicePS2Mouse(void);
  52.  
  53.         void reset(void);
  54.  
  55.         void  enable(void);
  56.         void disable(void);
  57.  
  58.         void send_command_device(uint8_t command);
  59.         void wait_response(uint8_t wait_byte=0xFA);
  60.  
  61.     private:
  62.         void _handle_current_packet(void);
  63.     public:
  64.         void handle_irq(void) override;
  65.  
  66.         void set_position(int x, int y);
  67. };
  68.  
  69.  
  70. }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement