329e003d2f8d6ed224a2c65af1072788b7cfbd58
[tpg/acess2.git] / AcessNative / acesskernel_src / keyboard.c
1 /*
2  * Acess2 Native Kernel
3  * 
4  * Keyboard Driver
5  */
6 #include <acess.h>
7 #include <modules.h>
8 #include <fs_devfs.h>
9 #include <api_drv_keyboard.h>
10 #include "ui.h"
11
12 // === PROTOTYPES ===
13  int    NativeKeyboard_Install(char **Arguments);
14  int    NativeKeyboard_IOCtl(tVFS_Node *Node, int Id, void *Data);
15
16 // === GLOBALS ===
17 MODULE_DEFINE(0, 0x0100, NativeKeyboard, NativeKeyboard_Install, NULL, NULL);
18 tDevFS_Driver   gKB_DevInfo = {
19         NULL, "NativeKeyboard",
20         {
21         .NumACLs = 0,
22         .Size = 0,
23         .IOCtl = NativeKeyboard_IOCtl
24         }
25 };
26
27 // === CODE ===
28 /**
29  * \brief Install the keyboard driver
30  */
31 int NativeKeyboard_Install(char **Arguments)
32 {
33         DevFS_AddDevice( &gKB_DevInfo );
34         return MODULE_ERR_OK;
35 }
36
37 static const char * csaIOCTL_NAMES[] = {
38         DRV_IOCTLNAMES,
39         DRV_KEYBAORD_IOCTLNAMES,
40         NULL
41 };
42
43 /**
44  * \fn int KB_IOCtl(tVFS_Node *Node, int Id, void *Data)
45  * \brief Calls an IOCtl Command
46  */
47 int NativeKeyboard_IOCtl(tVFS_Node *Node, int Id, void *Data)
48 {
49         switch(Id)
50         {
51         BASE_IOCTLS(DRV_TYPE_KEYBOARD, "NativeKeyboard", 0x10000, csaIOCTL_NAMES);
52
53         // Sets the Keyboard Callback
54         case KB_IOCTL_SETCALLBACK:
55                 // Sanity Check
56                 if(Threads_GetUID() != 0)
57                         return 0;
58                 // Can only be set once
59                 if(gUI_KeyboardCallback != NULL)        return 0;
60                 // Set Callback
61                 gUI_KeyboardCallback = Data;
62                 return 1;
63
64         default:
65                 return 0;
66         }
67 }

UCC git Repository :: git.ucc.asn.au