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

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