Route keyboard commands to a USB handler when USB keyboard is active.
Add a GETID handler for USB keyboards.
#include "util.h" // debug_enter
#include "config.h" // CONFIG_*
#include "bregs.h" // struct bregs
-#include "ps2port.h" // kbd_command
+#include "ps2port.h" // ps2_kbd_command
+#include "usb-hid.h" // usb_kbd_command
// Bit definitions for BDA kbd_flag[012]
#define KF0_RSHIFT (1<<0)
SET_BDA(kbd_buf_head, buffer_head);
}
+static inline int
+kbd_command(int command, u8 *param)
+{
+ if (usb_kbd_active())
+ return usb_kbd_command(command, param);
+ return ps2_kbd_command(command, param);
+}
+
// read keyboard input
static void
handle_1600(struct bregs *regs)
#include "util.h" // debug_isr
#include "pic.h" // eoi_pic2
#include "bregs.h" // struct bregs
-#include "ps2port.h" // aux_command
+#include "ps2port.h" // ps2_mouse_command
void
mouse_setup(void)
SETBITS_BDA(equipment_list_flags, 0x04);
}
+static inline int
+mouse_command(int command, u8 *param)
+{
+ return ps2_mouse_command(command, param);
+}
+
#define RET_SUCCESS 0x00
#define RET_EINVFUNCTION 0x01
#define RET_EINVINPUT 0x02
ps2ctr &= ~I8042_CTR_AUXINT;
SET_EBDA2(ebda_seg, ps2ctr, ps2ctr);
- return aux_command(PSMOUSE_CMD_DISABLE, NULL);
+ return mouse_command(PSMOUSE_CMD_DISABLE, NULL);
}
// Disable Mouse
ps2ctr |= I8042_CTR_AUXINT;
SET_EBDA2(ebda_seg, ps2ctr, ps2ctr);
- int ret = aux_command(PSMOUSE_CMD_ENABLE, NULL);
+ int ret = mouse_command(PSMOUSE_CMD_ENABLE, NULL);
if (ret)
set_code_invalid(regs, RET_ENEEDRESEND);
else
mouse_15c201(struct bregs *regs)
{
u8 param[2];
- int ret = aux_command(PSMOUSE_CMD_RESET_BAT, param);
+ int ret = mouse_command(PSMOUSE_CMD_RESET_BAT, param);
if (ret) {
set_code_invalid(regs, RET_ENEEDRESEND);
return;
return;
}
u8 mouse_data1 = GET_GLOBAL(sample_rates[regs->bh]);
- int ret = aux_command(PSMOUSE_CMD_SETRATE, &mouse_data1);
+ int ret = mouse_command(PSMOUSE_CMD_SETRATE, &mouse_data1);
if (ret)
set_code_invalid(regs, RET_ENEEDRESEND);
else
return;
}
u8 param = regs->bh;
- int ret = aux_command(PSMOUSE_CMD_SETRES, ¶m);
+ int ret = mouse_command(PSMOUSE_CMD_SETRES, ¶m);
if (ret)
set_code_invalid(regs, RET_ENEEDRESEND);
else
mouse_15c204(struct bregs *regs)
{
u8 param[2];
- int ret = aux_command(PSMOUSE_CMD_GETID, param);
+ int ret = mouse_command(PSMOUSE_CMD_GETID, param);
if (ret) {
set_code_invalid(regs, RET_ENEEDRESEND);
return;
mouse_15c20600(struct bregs *regs)
{
u8 param[3];
- int ret = aux_command(PSMOUSE_CMD_GETINFO, param);
+ int ret = mouse_command(PSMOUSE_CMD_GETINFO, param);
if (ret) {
set_code_invalid(regs, RET_ENEEDRESEND);
return;
static void
mouse_15c20601(struct bregs *regs)
{
- int ret = aux_command(PSMOUSE_CMD_SETSCALE11, NULL);
+ int ret = mouse_command(PSMOUSE_CMD_SETSCALE11, NULL);
if (ret)
set_code_invalid(regs, RET_ENEEDRESEND);
else
static void
mouse_15c20602(struct bregs *regs)
{
- int ret = aux_command(PSMOUSE_CMD_SETSCALE21, NULL);
+ int ret = mouse_command(PSMOUSE_CMD_SETSCALE21, NULL);
if (ret)
set_code_invalid(regs, RET_ENEEDRESEND);
else
#include "ioport.h" // inb
#include "util.h" // dprintf
#include "biosvar.h" // GET_EBDA
-#include "ps2port.h" // kbd_command
+#include "ps2port.h" // ps2_kbd_command
#include "pic.h" // eoi_pic1
}
static int
-ps2_command(int aux, int command, u8 *param)
+__ps2_command(int aux, int command, u8 *param)
{
int ret2;
int receive = (command >> 8) & 0xf;
return ret;
}
-int
-kbd_command(int command, u8 *param)
+static int
+ps2_command(int aux, int command, u8 *param)
{
- dprintf(7, "kbd_command cmd=%x\n", command);
- int ret = ps2_command(0, command, param);
+ dprintf(7, "ps2_command aux=%d cmd=%x\n", aux, command);
+ int ret = __ps2_command(aux, command, param);
if (ret)
- dprintf(2, "keyboard command %x failed\n", command);
+ dprintf(2, "ps2 command %x failed (aux=%d)\n", command, aux);
return ret;
}
int
-aux_command(int command, u8 *param)
+ps2_kbd_command(int command, u8 *param)
{
- dprintf(7, "aux_command cmd=%x\n", command);
- int ret = ps2_command(1, command, param);
- if (ret)
- dprintf(2, "mouse command %x failed\n", command);
- return ret;
+ return ps2_command(0, command, param);
+}
+
+int
+ps2_mouse_command(int command, u8 *param)
+{
+ return ps2_command(1, command, param);
}
/* ------------------- keyboard side ------------------------*/
/* reset keyboard and self test (keyboard side) */
- ret = kbd_command(ATKBD_CMD_RESET_BAT, param);
+ ret = ps2_kbd_command(ATKBD_CMD_RESET_BAT, param);
if (ret)
return;
if (param[0] != 0xaa) {
}
/* Disable keyboard */
- ret = kbd_command(ATKBD_CMD_RESET_DIS, NULL);
+ ret = ps2_kbd_command(ATKBD_CMD_RESET_DIS, NULL);
if (ret)
return;
// Set scancode command (mode 2)
param[0] = 0x02;
- ret = kbd_command(ATKBD_CMD_SSCANSET, param);
+ ret = ps2_kbd_command(ATKBD_CMD_SSCANSET, param);
if (ret)
return;
SET_EBDA(ps2ctr, I8042_CTR_AUXDIS | I8042_CTR_XLATE | I8042_CTR_KBDINT);
/* Enable keyboard */
- ret = kbd_command(ATKBD_CMD_ENABLE, NULL);
+ ret = ps2_kbd_command(ATKBD_CMD_ENABLE, NULL);
if (ret)
return;
// functions
int i8042_flush(void);
int i8042_command(int command, u8 *param);
-int kbd_command(int command, u8 *param);
-int aux_command(int command, u8 *param);
+int ps2_kbd_command(int command, u8 *param);
+int ps2_mouse_command(int command, u8 *param);
void ps2port_setup(void);
#endif // ps2port.h
#include "config.h" // CONFIG_*
#include "usb.h" // usb_ctrlrequest
#include "biosvar.h" // GET_GLOBAL
+#include "ps2port.h" // ATKBD_CMD_GETID
struct usb_pipe *keyboard_pipe VAR16VISIBLE;
handle_key(&data);
}
}
+
+// Test if USB keyboard is active.
+inline int
+usb_kbd_active(void)
+{
+ return GET_GLOBAL(keyboard_pipe) != NULL;
+}
+
+// Handle a ps2 style keyboard command.
+inline int
+usb_kbd_command(int command, u8 *param)
+{
+ switch (command) {
+ case ATKBD_CMD_GETID:
+ // Return the id of a standard AT keyboard.
+ param[0] = 0xab;
+ param[1] = 0x83;
+ return 0;
+ default:
+ return -1;
+ }
+}
int usb_keyboard_init(struct usb_pipe *pipe
, struct usb_interface_descriptor *iface, int imax);
void usb_keyboard_setup(void);
+inline int usb_kbd_active(void);
void usb_check_key(void);
+inline int usb_kbd_command(int command, u8 *param);
/****************************************************************