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/compiler.h"
24#include "pedigree/kernel/machine/Device.h"
25#include "pedigree/kernel/process/OwnedThread.h"
26#include "pedigree/kernel/process/Semaphore.h"
27#include "pedigree/kernel/processor/types.h"
28#include "pedigree/kernel/utilities/String.h"
29
30#include "Ps2MouseCallbackRegistry.h"
31#include "Ps2MousePacket.h"
32
33class Ps2Controller;
34
35extern class Ps2Mouse* g_Ps2Mouse WEAK;
36
37class Ps2Mouse : public Device {
38 public:
39 using MouseHandlerFunction = Ps2MouseCallbackRegistry::Handler;
41
42 Ps2Mouse(Device* pDev);
43 virtual ~Ps2Mouse();
44
45 virtual bool initialise(Ps2Controller* pController);
46
47 virtual void getName(String& str) {
48 str.assign("mouse", 6);
49 }
50
51 EXPORTED_PUBLIC void write(const char* bytes, size_t len);
52
53 // subscribe to the raw bus protocol
54 EXPORTED_PUBLIC MUST_USE_RESULT bool subscribe(MouseHandlerFunction handler, void* param,
55 Registration& registration);
56
57 private:
58 Ps2Controller* m_pController;
59
60 enum WaitType { Data, Signal };
61
62 enum Ps2Ports { KbdStat = 0x64, KbdCommand = 0x60 };
63
64 enum Ps2Commands {
65 EnablePS2 = 0xA8,
66 DisableKbd = 0xAD,
67 EnableKbd = 0xAE,
68 Mouse = 0xD4,
69 MouseStream = 0xF4,
70 MouseDisable = 0xF5,
71 SetDefaults = 0xF6,
72 MouseAck = 0xFA
73 };
74
75 static int readerThreadTrampoline(void*);
76 void readerThread();
77
78 void updateSubscribers(const void* buffer, size_t len);
79
80 Ps2MousePacketDecoder m_PacketDecoder;
81
84
85 Ps2Mouse(const Ps2Mouse&);
86 void operator=(const Ps2Mouse&);
87
88 OwnedThread m_ReaderThread;
89 Ps2MouseCallbackRegistry m_Callbacks;
90};
91
92#endif
Semaphore m_IrqWait
IRQ wait semaphore.
Definition Ps2Mouse.h:83
virtual void getName(String &str)
Definition Ps2Mouse.h:47