--- /dev/null
+/*
+ * Acess2
+ * - By thePowersGang (John Hodge)
+ *
+ * 8042 (or comaptible) Driver
+ */
+#include <acess.h>
+#include "common.h"
+
+// === PROTOTYPES ===
+void KBC8042_Init(void);
+void KBC8042_KeyboardHandler(int IRQ);
+void KBC8042_MouseHandler(int IRQ);
+void KBC8042_EnableMouse(void);
+static inline void KBC8042_SendDataAlt(Uint8 data);
+static inline void KBC8042_SendData(Uint8 data);
+static inline Uint8 KBC8042_ReadData(void);
+static void KBC8042_SendMouseCommand(Uint8 cmd);
+
+// === CODE ===
+void KBC8042_Init(void)
+{
+ IRQ_AddHandler(1, KBC8042_KeyboardHandler);
+ IRQ_AddHandler(12, KBC8042_MouseHandler); // Set IRQ
+
+ {
+ Uint8 temp;
+ // Attempt to get around a strange bug in Bochs/Qemu by toggling
+ // the controller on and off
+ temp = inb(0x61);
+ outb(0x61, temp | 0x80);
+ outb(0x61, temp & 0x7F);
+ inb(0x60); // Clear keyboard buffer
+ }
+}
+
+void KBC8042_KeyboardHandler(int IRQ)
+{
+ Uint8 scancode;
+
+ scancode = inb(0x60);
+ KB_HandleScancode( scancode );
+}
+
+void KBC8042_MouseHandler(int IRQ)
+{
+ PS2Mouse_HandleInterrupt( inb(0x60) );
+}
+
+void KBC8042_SetLEDs(Uint8 leds)
+{
+ while( inb(0x64) & 2 ); // Wait for bit 2 to unset
+ outb(0x60, 0xED); // Send update command
+
+ while( inb(0x64) & 2 ); // Wait for bit 2 to unset
+ outb(0x60, leds);
+}
+
+void KBC8042_EnableMouse(void)
+{
+ Uint8 status;
+ Log_Log("8042", "Enabling Mouse...");
+
+ // Enable AUX PS/2
+ KBC8042_SendDataAlt(0xA8);
+
+ // Enable AUX PS/2 (Compaq Status Byte)
+ KBC8042_SendDataAlt(0x20); // Send Command
+ status = KBC8042_ReadData(); // Get Status
+ status &= ~0x20; // Clear "Disable Mouse Clock"
+ status |= 0x02; // Set IRQ12 Enable
+ KBC8042_SendDataAlt(0x60); // Send Command
+ KBC8042_SendData(status); // Set Status
+
+ //mouseSendCommand(0xF6); // Set Default Settings
+ KBC8042_SendMouseCommand(0xF4); // Enable Packets
+}
+
+static inline void KBC8042_SendDataAlt(Uint8 data)
+{
+ int timeout=100000;
+ while( timeout-- && inb(0x64) & 2 ); // Wait for Flag to clear
+ outb(0x64, data); // Send Command
+}
+static inline void KBC8042_SendData(Uint8 data)
+{
+ int timeout=100000;
+ while( timeout-- && inb(0x64) & 2 ); // Wait for Flag to clear
+ outb(0x60, data); // Send Command
+}
+static inline Uint8 KBC8042_ReadData(void)
+{
+ int timeout=100000;
+ while( timeout-- && (inb(0x64) & 1) == 0); // Wait for Flag to set
+ return inb(0x60);
+}
+static inline void KBC8042_SendMouseCommand(Uint8 cmd)
+{
+ KBC8042_SendDataAlt(0xD4);
+ KBC8042_SendData(cmd);
+}
+
#
OBJ = main.o kb.o ps2mouse.o
+OBJ += 8042.o
NAME = PS2KbMouse
-include ../Makefile.tpl
--- /dev/null
+/*
+ * Acess2
+ *
+ * PS2 Keyboard/Mouse Driver
+ *
+ * common.h
+ * - Shared definitions
+ */
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+extern int KB_Install(char **Arguments);
+extern int PS2Mouse_Install(char **Arguments);
+
+extern void KBC8042_Init(void);
+extern void KBC8042_EnableMouse(void);
+
+extern void KB_HandleScancode(Uint8 scancode);
+extern void PS2Mouse_HandleInterrupt(Uint8 InputByte);
+
+#endif
// === PROTOTYPES ===
int KB_Install(char **Arguments);
-void KB_IRQHandler(int IRQNum);
-void KB_AddBuffer(char ch);
-Uint64 KB_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Dest);
+void KB_HandleScancode(Uint8 scancode);
void KB_UpdateLEDs(void);
int KB_IOCtl(tVFS_Node *Node, int Id, void *Data);
{
.NumACLs = 0,
.Size = 0,
- //.Read = KB_Read,
.IOCtl = KB_IOCtl
}
};
*/
int KB_Install(char **Arguments)
{
-
- IRQ_AddHandler(1, KB_IRQHandler);
-
- {
- Uint8 temp;
- // Attempt to get around a strange bug in Bochs/Qemu by toggling
- // the controller on and off
- temp = inb(0x61);
- outb(0x61, temp | 0x80);
- outb(0x61, temp & 0x7F);
- inb(0x60); // Clear keyboard buffer
- }
-
DevFS_AddDevice( &gKB_DevInfo );
//Log("KB_Install: Installed");
return MODULE_ERR_OK;
* \brief Called on a keyboard IRQ
* \param IRQNum IRQ number (unused)
*/
-void KB_IRQHandler(int IRQNum)
+void KB_HandleScancode(Uint8 scancode)
{
- Uint8 scancode;
Uint32 ch;
- // int keyNum;
-
- // Check port 0x64 to tell if this is from the aux port
- //if( inb(0x64) & 0x20 ) return;
- scancode = inb(0x60); // Read from the keyboard's data buffer
//Log_Debug("Keyboard", "scancode = %02x", scancode);
// Ignore ACKs
leds = (gbKB_CapsState ? 4 : 0);
- while( inb(0x64) & 2 ); // Wait for bit 2 to unset
- outb(0x60, 0xED); // Send update command
-
- while( inb(0x64) & 2 ); // Wait for bit 2 to unset
- outb(0x60, leds);
+ // TODO: Update LEDS
+ Log_Warning("Keyboard", "TODO: Update LEDs");
}
static const char *csaIOCTL_NAMES[] = {DRV_IOCTLNAMES, DRV_KEYBAORD_IOCTLNAMES, NULL};
*/
#include <acess.h>
#include <modules.h>
+#include "common.h"
// === IMPORTS ===
-extern int KB_Install(char **Arguments);
-extern int PS2Mouse_Install(char **Arguments);
// === PROTOTYPES ===
int PS2_Install(char **Arguments);
// === CODE ===
int PS2_Install(char **Arguments)
{
-// KB_Install(Arguments);
-// Mouse_Install(Arguments);
+ KBC8042_Init();
return MODULE_ERR_OK;
}
--- /dev/null
+/*
+ * Acess2
+ * - By thePowersGang (John Hodge)
+ *
+ * PL050 (or comaptible) Driver
+ */
+#include <acess.h>
+#include "common.h"
+
+// TODO: Allow runtime/compile-time switching
+// Maybe PCI will have it?
+// Integrator-CP
+#if 0
+#define KEYBOARD_IRQ 3
+#define KEYBOARD_BASE 0x18000000
+#define MOUSE_IRQ 4
+#define MOUSE_BASE 0x19000000
+#endif
+// Realview
+#if 1
+#define KEYBOARD_IRQ 20
+#define KEYBOARD_BASE 0x10006000
+#define MOUSE_IRQ 21
+#define MOUSE_BASE 0x10007000
+#endif
+
+#define PL050_TXBUSY 0x20
+
+// === PROTOTYPES ===
+void PL050_Init(void);
+void PL050_KeyboardHandler(int IRQ);
+void PL050_MouseHandler(int IRQ);
+void PL050_EnableMouse(void);
+static inline void PL050_WriteMouseData(Uint8 data);
+static inline void PL050_WriteKeyboardData(Uint8 data);
+static inline Uint8 PL050_ReadMouseData(void);
+static inline Uint8 PL050_ReadKeyboardData(void);
+
+// === CODE ===
+void PL050_Init(void)
+{
+ IRQ_AddHandler(KEYBOARD_IRQ, PL050_KeyboardHandler);
+ IRQ_AddHandler(MOUSE_IRQ, PL050_MouseHandler); // Set IRQ
+}
+
+void PL050_KeyboardHandler(int IRQ)
+{
+ Uint8 scancode;
+
+ scancode = PL050_ReadKeyboardData(0x60);
+ KB_HandleScancode( scancode );
+}
+
+void PL050_MouseHandler(int IRQ)
+{
+ PS2Mouse_HandleInterrupt( PL050_ReadMouseData(0x60) );
+}
+
+void PL050_SetLEDs(Uint8 leds)
+{
+ PL050_WriteKeyboardData(0xED);
+ PL050_WriteKeyboardData(leds);
+}
+
+void PL050_EnableMouse(void)
+{
+ Uint8 status;
+ Log_Log("8042", "Enabling Mouse...");
+
+
+ //PL050_WriteMouseData(0xD4);
+ //PL050_WriteMouseData(0xF6); // Set Default Settings
+ PL050_WriteMouseData(0xD4);
+ PL050_WriteMouseData(0xF4); // Enable Packets
+}
+
+static inline void PL050_WriteMouseData(Uint8 Data)
+{
+ int timeout = 10000;
+ while( --timeout && *(Uint32*)(MOUSE_BASE+1) & PL050_TXBUSY );
+ if(timeout)
+ *(Uint32*)(MOUSE_BASE+2) = Data;
+ else
+ Log_Error("PL050", "Write to mouse timed out");
+}
+
+static inline Uint8 PL050_ReadMouseData(void)
+{
+ return *(Uint32*)(MOUSE_BASE+2);
+}
+static inline void PL050_WriteKeyboardData(Uint8 data)
+{
+ int timeout = 10000;
+ while( --timeout && *(Uint32*)(KEYBOARD_BASE+1) & PL050_TXBUSY );
+ if(timeout)
+ *(Uint32*)(KEYBOARD_BASE+2) = Data;
+ else
+ Log_Error("PL050", "Write to keyboard timed out");
+}
+static inline Uint8 PL050_ReadKeyboardData(void)
+{
+ return *(Uint32*)(MOUSE_BASE+2);
+}
+
#include <fs_devfs.h>\r
#include <api_drv_common.h>\r
#include <api_drv_joystick.h>\r
+#include "common.h"\r
\r
static inline int MIN(int a, int b) { return (a < b) ? a : b; }\r
static inline int MAX(int a, int b) { return (a > b) ? a : b; }\r
// == CONSTANTS ==\r
#define NUM_AXIES 2 // X+Y\r
#define NUM_BUTTONS 5 // Left, Right, Scroll Click, Scroll Up, Scroll Down\r
-#define PS2_IO_PORT 0x60\r
\r
// == PROTOTYPES ==\r
// - Internal -\r
int PS2Mouse_Install(char **Arguments);\r
-void PS2Mouse_IRQ(int Num);\r
-static void mouseSendCommand(Uint8 cmd);\r
-void PS2Mouse_Enable();\r
+void PS2Mouse_HandleInterrupt(Uint8 InputByte);\r
// - Filesystem -\r
Uint64 PS2Mouse_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);\r
int PS2Mouse_IOCtl(tVFS_Node *Node, int ID, void *Data);\r
gMouse_Buttons = (void*)&gMouse_Axies[NUM_AXIES];\r
\r
// Initialise Mouse Controller\r
- IRQ_AddHandler(12, PS2Mouse_IRQ); // Set IRQ\r
giMouse_Cycle = 0; // Set Current Cycle position\r
- PS2Mouse_Enable(); // Enable the mouse\r
+ KBC8042_EnableMouse();\r
\r
DevFS_AddDevice(&gMouse_DriverStruct);\r
\r
\r
/* Handle Mouse Interrupt\r
*/\r
-void PS2Mouse_IRQ(int Num)\r
+void PS2Mouse_HandleInterrupt(Uint8 InputByte)\r
{\r
Uint8 flags;\r
int d[2], d_accel[2];\r
int i;\r
\r
// Gather mouse data\r
- gaMouse_Bytes[giMouse_Cycle] = inb(0x60);\r
+ gaMouse_Bytes[giMouse_Cycle] = InputByte;\r
LOG("gaMouse_Bytes[%i] = 0x%02x", gMouse_Axies[0].MaxValue);\r
// - If bit 3 of the first byte is not set, it's not a valid packet?\r
if(giMouse_Cycle == 0 && !(gaMouse_Bytes[0] & 0x08) )\r
gMouse_Axies[i].CurValue = d_accel[i];\r
gMouse_Axies[i].CursorPos = newCursor;\r
}\r
- \r
-// Log_Debug("PS2Mouse", "gMouse_Buttons = {0x%x,0x%x,0x%x}, gMouse_Axies={%i,%i}", \r
-// gMouse_Buttons[0], gMouse_Buttons[1], gMouse_Buttons[2],\r
-// gMouse_Axies[0].CursorPos, gMouse_Axies[1].CursorPos);\r
- \r
+\r
+ \r
VFS_MarkAvaliable(&gMouse_DriverStruct.RootNode, 1);\r
}\r
\r
}\r
}\r
\r
-//== Internal Functions ==\r
-static inline void mouseOut64(Uint8 data)\r
-{\r
- int timeout=100000;\r
- while( timeout-- && inb(0x64) & 2 ); // Wait for Flag to clear\r
- outb(0x64, data); // Send Command\r
-}\r
-static inline void mouseOut60(Uint8 data)\r
-{\r
- int timeout=100000;\r
- while( timeout-- && inb(0x64) & 2 ); // Wait for Flag to clear\r
- outb(0x60, data); // Send Command\r
-}\r
-static inline Uint8 mouseIn60(void)\r
-{\r
- int timeout=100000;\r
- while( timeout-- && (inb(0x64) & 1) == 0); // Wait for Flag to set\r
- return inb(0x60);\r
-}\r
-static inline void mouseSendCommand(Uint8 cmd)\r
-{\r
- mouseOut64(0xD4);\r
- mouseOut60(cmd);\r
-}\r
-\r
-void PS2Mouse_Enable(void)\r
-{\r
- Uint8 status;\r
- Log_Log("PS2Mouse", "Enabling Mouse...");\r
- \r
- // Enable AUX PS/2\r
- mouseOut64(0xA8);\r
- \r
- // Enable AUX PS/2 (Compaq Status Byte)\r
- mouseOut64(0x20); // Send Command\r
- status = mouseIn60(); // Get Status\r
- status &= ~0x20; // Clear "Disable Mouse Clock"\r
- status |= 0x02; // Set IRQ12 Enable\r
- mouseOut64(0x60); // Send Command\r
- mouseOut60(status); // Set Status\r
- \r
- //mouseSendCommand(0xF6); // Set Default Settings\r
- mouseSendCommand(0xF4); // Enable Packets\r
-}\r