The Pedigree Project  0.1
Ps2Mouse.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef _PS2_MOUSE_H
21 #define _PS2_MOUSE_H
22 
23 #include "pedigree/kernel/Spinlock.h"
24 #include "pedigree/kernel/compiler.h"
25 #include "pedigree/kernel/machine/Device.h"
26 #include "pedigree/kernel/process/Semaphore.h"
27 #include "pedigree/kernel/processor/types.h"
28 #include "pedigree/kernel/utilities/String.h"
29 
30 class Ps2Controller;
31 
32 extern class Ps2Mouse *g_Ps2Mouse WEAK;
33 
34 class Ps2Mouse : public Device
35 {
36  public:
37  typedef void (*MouseHandlerFunction)(void *, const void *, size_t);
38 
39  Ps2Mouse(Device *pDev);
40  virtual ~Ps2Mouse();
41 
42  virtual bool initialise(Ps2Controller *pController);
43 
44  virtual void getName(String &str)
45  {
46  str = "mouse";
47  }
48 
49  EXPORTED_PUBLIC void write(const char *bytes, size_t len);
50 
51  // subscribe to the raw bus protocol
52  EXPORTED_PUBLIC void subscribe(MouseHandlerFunction handler, void *param);
53 
54  private:
55  Ps2Controller *m_pController;
56 
57  enum WaitType
58  {
59  Data,
60  Signal
61  };
62 
63  enum Ps2Ports
64  {
65  KbdStat = 0x64,
66  KbdCommand = 0x60
67  };
68 
69  enum Ps2Commands
70  {
71  EnablePS2 = 0xA8,
72  DisableKbd = 0xAD,
73  EnableKbd = 0xAE,
74  Mouse = 0xD4,
75  MouseStream = 0xF4,
76  MouseDisable = 0xF5,
77  SetDefaults = 0xF6,
78  MouseAck = 0xFA
79  };
80 
81  static int readerThreadTrampoline(void *) NORETURN;
82  void readerThread() NORETURN;
83 
84  void updateSubscribers(const void *buffer, size_t len);
85 
87  uint8_t m_Buffer[3];
88 
90  size_t m_BufferIndex;
91 
94 
97 
98  Ps2Mouse(const Ps2Mouse &);
99  void operator=(const Ps2Mouse &);
100 
101  static const size_t m_nHandlers = 32;
102  MouseHandlerFunction m_Handlers[m_nHandlers];
103  void *m_HandlerParams[m_nHandlers];
104 };
105 
106 #endif
size_t m_BufferIndex
Index into the data buffer.
Definition: Ps2Mouse.h:90
virtual bool initialise(Ps2Controller *pController)
Definition: Ps2Mouse.cc:47
Definition: String.h:49
Semaphore m_IrqWait
IRQ wait semaphore.
Definition: Ps2Mouse.h:96
Definition: Device.h:43
virtual void getName(String &str)
Definition: Ps2Mouse.h:44
Spinlock m_BufferLock
Lock for the mouse data buffer.
Definition: Ps2Mouse.h:93
uint8_t m_Buffer[3]
Mouse data buffer.
Definition: Ps2Mouse.h:87