The Pedigree Project  0.1
Ps2Controller.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 MACHINE_X86_PS2CONTROLLER_H
21 #define MACHINE_X86_PS2CONTROLLER_H
22 
23 #include "pedigree/kernel/compiler.h"
24 #include "pedigree/kernel/machine/Controller.h"
25 #include "pedigree/kernel/machine/IrqHandler.h"
26 #include "pedigree/kernel/machine/types.h"
27 #include "pedigree/kernel/processor/state_forward.h"
28 #include "pedigree/kernel/processor/types.h"
29 #include "pedigree/kernel/utilities/Buffer.h"
30 #include "pedigree/kernel/utilities/String.h"
31 
32 class IoBase;
33 
34 class Ps2Controller : public Controller, private IrqHandler
35 {
36  public:
38  Ps2Controller();
39 
40  virtual ~Ps2Controller()
41  {
42  }
43 
44  virtual void getName(String &str)
45  {
46  str = "PS/2 Controller";
47  }
48 
49  virtual void dump(String &str)
50  {
51  str = "PS/2 Controller";
52  }
53 
54  void initialise();
55 
57  void sendCommand(uint8_t command);
58  void sendCommand(uint8_t command, uint8_t data);
60  uint8_t sendCommandWithResponse(uint8_t command);
61  uint8_t sendCommandWithResponse(uint8_t command, uint8_t data);
62 
64  void writeFirstPort(uint8_t byte);
66  EXPORTED_PUBLIC void writeSecondPort(uint8_t byte);
67 
69  bool hasSecondPort() const;
70 
72  EXPORTED_PUBLIC void setIrqEnable(bool firstEnabled, bool secondEnabled);
73 
75  uint8_t readByte();
76  uint8_t readByteNonBlock();
77 
79  bool readFirstPort(uint8_t &byte, bool block = true);
81  EXPORTED_PUBLIC bool readSecondPort(uint8_t &byte, bool block = true);
82 
84  void setDebugState(bool debugState);
85 
87  bool getDebugState() const
88  {
89  return m_bDebugState;
90  }
91 
92  private:
93  virtual bool irq(irq_id_t number, InterruptState &state);
94 
95  void waitForReading();
96  void waitForWriting();
97 
98  IoBase *m_pBase;
99  bool m_bHasSecondPort;
100 
101  Buffer<uint8_t> m_FirstPortBuffer;
102  Buffer<uint8_t> m_SecondPortBuffer;
103 
104  bool m_bFirstIrqEnabled;
105  bool m_bSecondIrqEnabled;
106 
107  irq_id_t m_FirstIrqId;
108  irq_id_t m_SecondIrqId;
109 
110  bool m_bDebugState;
111 
112  uint8_t m_ConfigByte;
113 
114  // used to know which IRQs to enable when leaving debug state
115  bool m_bDebugStateFirstIrqEnabled;
116  bool m_bDebugStateSecondIrqEnabled;
117 };
118 
119 #endif
virtual bool irq(irq_id_t number, InterruptState &state)
bool hasSecondPort() const
Reports whether this PS/2 controller has two ports.
bool getDebugState() const
Gets the debug state.
Definition: Ps2Controller.h:87
uint8_t readByte()
Reads a single byte from the PS/2 controller by polling.
uint8_t sendCommandWithResponse(uint8_t command)
Send a command to the PS/2 controller and report its response.
void writeFirstPort(uint8_t byte)
Send a byte to the first port of the PS/2 controller.
EXPORTED_PUBLIC void setIrqEnable(bool firstEnabled, bool secondEnabled)
Enables/disables IRQs for the first or second ports.
Definition: String.h:49
void setDebugState(bool debugState)
Sets the debug state (blocks IRQs to allow polling).
EXPORTED_PUBLIC bool readSecondPort(uint8_t &byte, bool block=true)
Reads a single byte from the second port.
Abstrace base class for hardware I/O capabilities.
Definition: IoBase.h:31
bool readFirstPort(uint8_t &byte, bool block=true)
Reads a single byte from the first port.
virtual void getName(String &str)
Definition: Ps2Controller.h:44
EXPORTED_PUBLIC void writeSecondPort(uint8_t byte)
Send a byte to the second port of the PS/2 controller.
virtual void dump(String &str)
Definition: Ps2Controller.h:49
void sendCommand(uint8_t command)
Send a command to the PS/2 controller that has no response or data.