#include "base/logging.hh"
#include "debug/PS2.hh"
+#include "dev/ps2.hh"
#include "params/PS2Keyboard.hh"
const uint8_t PS2Keyboard::ID[] = {0xab, 0x83};
PS2Keyboard::PS2Keyboard(const PS2KeyboardParams *p)
: PS2Device(p),
- lastCommand(NoCommand)
+ lastCommand(NoCommand),
+ shiftDown(false),
+ enabled(false)
{
+ if (p->vnc)
+ p->vnc->setKeyboard(this);
}
void
{
PS2Device::serialize(cp);
SERIALIZE_SCALAR(lastCommand);
+ SERIALIZE_SCALAR(shiftDown);
+ SERIALIZE_SCALAR(enabled);
}
void
{
PS2Device::unserialize(cp);
UNSERIALIZE_SCALAR(lastCommand);
+ UNSERIALIZE_SCALAR(shiftDown);
+ UNSERIALIZE_SCALAR(enabled);
}
void
break;
case Enable:
DPRINTF(PS2, "Enabling the keyboard.\n");
+ enabled = true;
sendAck();
break;
case Disable:
DPRINTF(PS2, "Disabling the keyboard.\n");
+ enabled = false;
sendAck();
break;
case DefaultsAndDisable:
DPRINTF(PS2, "Disabling and resetting the keyboard.\n");
+ enabled = false;
sendAck();
break;
case AllKeysToTypematic:
}
}
+void
+PS2Keyboard::keyPress(uint32_t key, bool down)
+{
+ std::list<uint8_t> keys;
+
+ // convert the X11 keysym into ps2 codes and update the shift
+ // state (shiftDown)
+ Ps2::keySymToPs2(key, down, shiftDown, keys);
+
+ // Drop key presses if the keyboard hasn't been enabled by the
+ // host. We do that after translating the key code to ensure that
+ // we keep track of the shift state.
+ if (!enabled)
+ return;
+
+ // Insert into our queue of characters
+ for (uint8_t c : keys)
+ send(c);
+}
+
+
PS2Keyboard *
PS2KeyboardParams::create()
{
#ifndef __DEV_PS2_KEYBOARD_HH__
#define __DEV_PS2_KEYBOARD_HH__
+#include "base/vnc/vncinput.hh"
#include "dev/ps2/device.hh"
struct PS2KeyboardParams;
-class PS2Keyboard : public PS2Device
+class PS2Keyboard : public PS2Device, VncKeyboard
{
protected:
static const uint8_t ID[];
uint16_t lastCommand;
+ /** is the shift key currently down */
+ bool shiftDown;
+
+ /** Is the device enabled? */
+ bool enabled;
+
public:
PS2Keyboard(const PS2KeyboardParams *p);
protected: // PS2Device
void recv(uint8_t data) override;
+
+ public: // VncKeyboard
+ void keyPress(uint32_t key, bool down) override;
};
#endif // __DEV_PS2_KEYBOARD_hH__
keyboard_int_pin = Param.X86IntSourcePin(X86IntSourcePin(),
'Pin to signal the keyboard has data')
- keyboard = Param.PS2Device(PS2Keyboard(), "PS/2 keyboard device")
+ keyboard = Param.PS2Device(PS2Keyboard(vnc=NULL), "PS/2 keyboard device")
mouse = Param.PS2Device(PS2Mouse(), "PS/2 mouse device")