PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
libkbd.c
Go to the documentation of this file.
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
16#include <tamtypes.h>
17#include <fcntl.h>
18#include <unistd.h>
19#include <ps2sdkapi.h>
20#include "libkbd.h"
21
22extern int _iop_reboot_count;
23static int kbd_iop = -1;
24static int kbd_fd = -1;
25static int curr_blockmode = PS2KBD_NONBLOCKING;
26static int curr_readmode = PS2KBD_READMODE_NORMAL;
27
28int PS2KbdInit(void)
29{
30 if (kbd_iop != _iop_reboot_count)
31 {
32 kbd_iop = _iop_reboot_count;
33 kbd_fd = -1;
34 }
35
36 if(kbd_fd >= 0) /* Already initialised */
37 {
38 return 2;
39 }
40
41 kbd_fd = open(PS2KBD_DEVFILE, O_RDONLY);
42 if(kbd_fd < 0)
43 {
44 return 0;
45 }
46
47 return 1;
48}
49
50int PS2KbdRead(char *key)
51{
52 if((kbd_fd >= 0) && (curr_readmode == PS2KBD_READMODE_NORMAL))
53 {
54 return read(kbd_fd, key, 1);
55 }
56
57 return 0;
58}
59
61{
62 if((kbd_fd >= 0) && (curr_readmode == PS2KBD_READMODE_RAW))
63 {
64 return read(kbd_fd, key, 2) / 2;
65 }
66
67 return 0;
68}
69
70int PS2KbdSetReadmode(u32 readmode)
71{
72 if((kbd_fd >= 0) && ((u32)curr_readmode != readmode))
73 {
74 curr_readmode = readmode;
75 return _ps2sdk_ioctl(kbd_fd, PS2KBD_IOCTL_SETREADMODE, &readmode);
76 }
77 return 0;
78}
79
80int PS2KbdSetBlockingMode(u32 blockmode)
81{
82 if((kbd_fd >= 0) && ((u32)curr_blockmode != blockmode))
83 {
84 return _ps2sdk_ioctl(kbd_fd, PS2KBD_IOCTL_SETBLOCKMODE, &blockmode);
85 }
86
87 return 0;
88}
89
90int PS2KbdSetRepeatRate(u32 repeat)
91{
92 if(kbd_fd >= 0)
93 {
94 return _ps2sdk_ioctl(kbd_fd, PS2KBD_IOCTL_SETREPEATRATE, &repeat);
95 }
96 return 0;
97}
98
99int PS2KbdSetLeds(u8 leds)
100{
101 if(kbd_fd >= 0)
102 {
103 return _ps2sdk_ioctl(kbd_fd, PS2KBD_IOCTL_SETLEDS, &leds);
104 }
105 return 0;
106}
107
109{
110 if(kbd_fd >= 0)
111 {
112 return _ps2sdk_ioctl(kbd_fd, PS2KBD_IOCTL_SETKEYMAP, keymaps);
113 }
114 return 0;
115}
116
117int PS2KbdSetCtrlmap(u8 *ctrlmap)
118{
119 if(kbd_fd >= 0)
120 {
121 return _ps2sdk_ioctl(kbd_fd, PS2KBD_IOCTL_SETCTRLMAP, ctrlmap);
122 }
123 return 0;
124}
125
126int PS2KbdSetAltmap(u8 *altmap)
127{
128 if(kbd_fd >= 0)
129 {
130 return _ps2sdk_ioctl(kbd_fd, PS2KBD_IOCTL_SETALTMAP, altmap);
131 }
132 return 0;
133}
134
135int PS2KbdSetSpecialmap(u8 *special)
136{
137 if(kbd_fd >= 0)
138 {
139 return _ps2sdk_ioctl(kbd_fd, PS2KBD_IOCTL_SETSPECIALMAP, special);
140 }
141 return 0;
142}
143
145{
146 int dummy;
147
148 if(kbd_fd >= 0)
149 {
150 return _ps2sdk_ioctl(kbd_fd, PS2KBD_IOCTL_FLUSHBUFFER, &dummy);
151 }
152 return 0;
153}
154
156{
157 int dummy;
158
159 if(kbd_fd >= 0)
160 {
161 return _ps2sdk_ioctl(kbd_fd, PS2KBD_IOCTL_RESETKEYMAP, &dummy);
162 }
163 return 0;
164}
165
166int PS2KbdClose(void)
167{
168 if(kbd_fd >= 0)
169 {
170 close(kbd_fd);
171 kbd_fd = -1;
172 }
173
174 return 1;
175}
#define PS2KBD_IOCTL_SETREPEATRATE
Definition ps2kbd.h:87
#define PS2KBD_IOCTL_SETALTMAP
Definition ps2kbd.h:93
#define PS2KBD_IOCTL_SETLEDS
Definition ps2kbd.h:85
#define PS2KBD_IOCTL_SETKEYMAP
Definition ps2kbd.h:89
#define PS2KBD_IOCTL_SETREADMODE
Definition ps2kbd.h:83
#define PS2KBD_IOCTL_SETSPECIALMAP
Definition ps2kbd.h:95
#define PS2KBD_IOCTL_SETBLOCKMODE
Definition ps2kbd.h:97
#define PS2KBD_IOCTL_SETCTRLMAP
Definition ps2kbd.h:91
#define PS2KBD_IOCTL_FLUSHBUFFER
Definition ps2kbd.h:99
#define PS2KBD_IOCTL_RESETKEYMAP
Definition ps2kbd.h:101
int PS2KbdInit(void)
Definition libkbd.c:28
int PS2KbdSetKeymap(PS2KbdKeyMap *keymaps)
Definition libkbd.c:108
int PS2KbdFlushBuffer(void)
Definition libkbd.c:144
int PS2KbdSetSpecialmap(u8 *special)
Definition libkbd.c:135
int PS2KbdSetAltmap(u8 *altmap)
Definition libkbd.c:126
int PS2KbdSetReadmode(u32 readmode)
Definition libkbd.c:70
int PS2KbdReadRaw(PS2KbdRawKey *key)
Definition libkbd.c:60
int PS2KbdSetRepeatRate(u32 repeat)
Definition libkbd.c:90
int PS2KbdSetCtrlmap(u8 *ctrlmap)
Definition libkbd.c:117
int PS2KbdSetLeds(u8 leds)
Definition libkbd.c:99
int PS2KbdResetKeymap(void)
Definition libkbd.c:155
int PS2KbdSetBlockingMode(u32 blockmode)
Definition libkbd.c:80
int PS2KbdRead(char *key)
Definition libkbd.c:50
int PS2KbdClose(void)
Definition libkbd.c:166