Skip to content

Commit fccfcf5

Browse files
committed
fix(kernel/api): broken input event api
Signed-off-by: enderice2 <enderice2@protonmail.com>
1 parent 9ac4c86 commit fccfcf5

8 files changed

Lines changed: 119 additions & 74 deletions

File tree

Kernel/core/driver/scancode.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ namespace Driver
318318
{
319319
char GetScanCode(uint8_t ScanCode, bool Upper)
320320
{
321-
ScanCode &= 0x7F; /* Remove KEY_PRESSED bit */
322321
if (ScanCode >= sizeof(ScanCodeConversionTableLower))
323322
{
324323
warn("Unknown scancode %x", ScanCode);
@@ -333,7 +332,6 @@ namespace Driver
333332

334333
char GetControlCharacter(KeyScanCodes ScanCode)
335334
{
336-
ScanCode = static_cast<KeyScanCodes>(static_cast<int>(ScanCode) & 0x7F); /* Remove KEY_PRESSED bit */
337335
switch (ScanCode)
338336
{
339337
case KEY_2:
@@ -407,7 +405,6 @@ namespace Driver
407405

408406
bool IsValidChar(uint8_t ScanCode)
409407
{
410-
ScanCode &= 0x7F; /* Remove KEY_PRESSED bit */
411408
if (ScanCode >= sizeof(ScanCodeConversionTableLower))
412409
return false;
413410

Kernel/drivers/misc/aip/keyboard.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ namespace Driver::AdvancedIntegratedPeripheral
4141
kir.Type = INPUT_TYPE_KEYBOARD;
4242
kir.Device = Device;
4343
kir.Keyboard.Key = (KeyScanCodes)(ScanCode);
44-
kir.Keyboard.Key = (KeyScanCodes)((int)kir.Keyboard.Key | (Pressed ? KEY_PRESSED : 0));
45-
// kir.Keyboard.Key |= Pressed ? KEY_PRESSED : 0;
44+
kir.Keyboard.Pressed = Pressed;
4645
v0::ReportInputEvent(DriverID, &kir);
4746
return 0;
4847
}

Kernel/include/interface/device.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,36 +37,36 @@ typedef enum
3737
DEVICE_TYPE_NETWORK = 0b0000010000000000000000000000000000000000,
3838
DEVICE_TYPE_BLOCK = 0b0000100000000000000000000000000000000000,
3939

40-
INPUT_TYPE_NONE = DEVICE_TYPE_INPUT + 0,
41-
INPUT_TYPE_KEYBOARD = DEVICE_TYPE_INPUT + 2,
42-
INPUT_TYPE_MOUSE = DEVICE_TYPE_INPUT + 4,
43-
INPUT_TYPE_JOYSTICK = DEVICE_TYPE_INPUT + 8,
44-
INPUT_TYPE_TOUCHSCREEN = DEVICE_TYPE_INPUT + 16,
45-
INPUT_TYPE_GAMEPAD = DEVICE_TYPE_INPUT + 32,
46-
INPUT_TYPE_ACCELEROMETER = DEVICE_TYPE_INPUT + 64,
47-
INPUT_TYPE_GYROSCOPE = DEVICE_TYPE_INPUT + 128,
48-
INPUT_TYPE_MAGNETOMETER = DEVICE_TYPE_INPUT + 256,
40+
INPUT_TYPE_NONE = DEVICE_TYPE_INPUT | 0,
41+
INPUT_TYPE_KEYBOARD = DEVICE_TYPE_INPUT | 2,
42+
INPUT_TYPE_MOUSE = DEVICE_TYPE_INPUT | 4,
43+
INPUT_TYPE_JOYSTICK = DEVICE_TYPE_INPUT | 8,
44+
INPUT_TYPE_TOUCHSCREEN = DEVICE_TYPE_INPUT | 16,
45+
INPUT_TYPE_GAMEPAD = DEVICE_TYPE_INPUT | 32,
46+
INPUT_TYPE_ACCELEROMETER = DEVICE_TYPE_INPUT | 64,
47+
INPUT_TYPE_GYROSCOPE = DEVICE_TYPE_INPUT | 128,
48+
INPUT_TYPE_MAGNETOMETER = DEVICE_TYPE_INPUT | 256,
4949

50-
AUDIO_TYPE_NONE = DEVICE_TYPE_AUDIO + 0,
51-
AUDIO_TYPE_PWM = DEVICE_TYPE_AUDIO + 2,
52-
AUDIO_TYPE_DSP = DEVICE_TYPE_AUDIO + 4,
53-
AUDIO_TYPE_PCM = DEVICE_TYPE_AUDIO + 8,
54-
AUDIO_TYPE_MIDI = DEVICE_TYPE_AUDIO + 16,
50+
AUDIO_TYPE_NONE = DEVICE_TYPE_AUDIO | 0,
51+
AUDIO_TYPE_PWM = DEVICE_TYPE_AUDIO | 2,
52+
AUDIO_TYPE_DSP = DEVICE_TYPE_AUDIO | 4,
53+
AUDIO_TYPE_PCM = DEVICE_TYPE_AUDIO | 8,
54+
AUDIO_TYPE_MIDI = DEVICE_TYPE_AUDIO | 16,
5555

56-
NETWORK_TYPE_NONE = DEVICE_TYPE_NETWORK + 0,
57-
NETWORK_TYPE_ETHERNET = DEVICE_TYPE_NETWORK + 2,
58-
NETWORK_TYPE_WIFI = DEVICE_TYPE_NETWORK + 4,
59-
NETWORK_TYPE_BLUETOOTH = DEVICE_TYPE_NETWORK + 8,
60-
NETWORK_TYPE_UART = DEVICE_TYPE_NETWORK + 16,
56+
NETWORK_TYPE_NONE = DEVICE_TYPE_NETWORK | 0,
57+
NETWORK_TYPE_ETHERNET = DEVICE_TYPE_NETWORK | 2,
58+
NETWORK_TYPE_WIFI = DEVICE_TYPE_NETWORK | 4,
59+
NETWORK_TYPE_BLUETOOTH = DEVICE_TYPE_NETWORK | 8,
60+
NETWORK_TYPE_UART = DEVICE_TYPE_NETWORK | 16,
6161

62-
BLOCK_TYPE_NONE = DEVICE_TYPE_BLOCK + 0,
63-
BLOCK_TYPE_SDCARD = DEVICE_TYPE_BLOCK + 2,
64-
BLOCK_TYPE_HDD = DEVICE_TYPE_BLOCK + 4,
65-
BLOCK_TYPE_SSD = DEVICE_TYPE_BLOCK + 8,
66-
BLOCK_TYPE_USB = DEVICE_TYPE_BLOCK + 16,
67-
BLOCK_TYPE_NVME = DEVICE_TYPE_BLOCK + 32,
68-
BLOCK_TYPE_CDROM = DEVICE_TYPE_BLOCK + 64,
69-
BLOCK_TYPE_FLOPPY = DEVICE_TYPE_BLOCK + 128,
62+
BLOCK_TYPE_NONE = DEVICE_TYPE_BLOCK | 0,
63+
BLOCK_TYPE_SDCARD = DEVICE_TYPE_BLOCK | 2,
64+
BLOCK_TYPE_HDD = DEVICE_TYPE_BLOCK | 4,
65+
BLOCK_TYPE_SSD = DEVICE_TYPE_BLOCK | 8,
66+
BLOCK_TYPE_USB = DEVICE_TYPE_BLOCK | 16,
67+
BLOCK_TYPE_NVME = DEVICE_TYPE_BLOCK | 32,
68+
BLOCK_TYPE_CDROM = DEVICE_TYPE_BLOCK | 64,
69+
BLOCK_TYPE_FLOPPY = DEVICE_TYPE_BLOCK | 128,
7070
} DeviceType;
7171

7272
#ifndef __kernel__

Kernel/include/interface/input.h

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@
2828

2929
struct InodeOperations;
3030

31+
#ifdef __cplusplus
32+
typedef enum : int
33+
#else
3134
typedef enum
35+
#endif // __cplusplus
3236
{
33-
KEY_1,
37+
KEY_1 = 0,
3438
KEY_2,
3539
KEY_3,
3640
KEY_4,
@@ -161,70 +165,87 @@ typedef enum
161165
KEY_ACPI_POWER,
162166
KEY_ACPI_SLEEP,
163167
KEY_ACPI_WAKE,
164-
165-
KEY_PRESSED = 0x80,
166168
} KeyScanCodes;
167169

168170
typedef struct
169171
{
172+
#ifdef __cplusplus
170173
KeyScanCodes Key;
174+
#else
175+
int Key;
176+
#endif // __cplusplus
171177

172-
union
173-
{
174-
struct
175-
{
176-
char IsScanCode : 1;
177-
};
178-
char Value;
179-
};
180-
unsigned char Character;
178+
uint8_t Pressed;
181179
} KeyboardReport;
182180

183181
typedef struct
184182
{
185-
long X, Y;
183+
int32_t X, Y;
186184
int8_t Z;
187-
uint8_t Absolute : 1;
188-
uint8_t LeftButton : 1;
189-
uint8_t RightButton : 1;
190-
uint8_t MiddleButton : 1;
191-
uint8_t Button4 : 1;
192-
uint8_t Button5 : 1;
193-
uint8_t Button6 : 1;
194-
uint8_t Button7 : 1;
195-
uint8_t Button8 : 1;
185+
186+
uint8_t Absolute;
187+
188+
uint8_t LeftButton;
189+
uint8_t RightButton;
190+
uint8_t MiddleButton;
191+
192+
uint8_t Button4;
193+
uint8_t Button5;
194+
uint8_t Button6;
195+
uint8_t Button7;
196+
uint8_t Button8;
196197
} MouseReport;
197198

198199
typedef struct
199200
{
201+
/* TODO */
200202
} JoystickReport;
201203

202204
typedef struct
203205
{
204-
uint16_t X, Y;
205-
uint8_t Pressure;
206+
/* TODO */
206207
} TouchScreenReport;
207208

208209
typedef struct
209210
{
211+
int16_t LeftX;
212+
int16_t LeftY;
213+
214+
int16_t RightX;
215+
int16_t RightY;
216+
217+
uint8_t LeftTrigger;
218+
uint8_t RightTrigger;
219+
220+
uint32_t Buttons;
210221
} GamepadReport;
211222

212223
typedef struct
213224
{
225+
int32_t X;
226+
int32_t Y;
227+
int32_t Z;
214228
} AccelerometerReport;
215229

216230
typedef struct
217231
{
232+
int32_t X;
233+
int32_t Y;
234+
int32_t Z;
218235
} GyroscopeReport;
219236

220237
typedef struct
221238
{
239+
int32_t X;
240+
int32_t Y;
241+
int32_t Z;
222242
} MagnetometerReport;
223243

224244
typedef struct
225245
{
226246
DeviceType Type;
227247
dev_t Device;
248+
228249
union
229250
{
230251
KeyboardReport Keyboard;

Kernel/kshell/shell.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ void KShellThread()
154154
}
155155

156156
const KeyScanCodes &sc = scBuf.Key;
157-
switch (sc & ~KEY_PRESSED)
157+
switch (sc)
158158
{
159159
case KEY_LEFT_CTRL:
160160
case KEY_RIGHT_CTRL:
161161
{
162-
if (sc & KEY_PRESSED)
162+
if (scBuf.Pressed)
163163
ctrlDown = true;
164164
else
165165
ctrlDown = false;
@@ -168,15 +168,15 @@ void KShellThread()
168168
case KEY_LEFT_SHIFT:
169169
case KEY_RIGHT_SHIFT:
170170
{
171-
if (sc & KEY_PRESSED)
171+
if (scBuf.Pressed)
172172
upperCase = true;
173173
else
174174
upperCase = false;
175175
continue;
176176
}
177177
case KEY_TAB:
178178
{
179-
if (!(sc & KEY_PRESSED))
179+
if (!(scBuf.Pressed))
180180
continue;
181181

182182
if (!tabDblPress)
@@ -211,7 +211,7 @@ void KShellThread()
211211
}
212212
case KEY_BACKSPACE:
213213
{
214-
if (!(sc & KEY_PRESSED))
214+
if (!(scBuf.Pressed))
215215
continue;
216216

217217
if (bsCount == 0)
@@ -242,7 +242,7 @@ void KShellThread()
242242
}
243243
case KEY_DELETE:
244244
{
245-
if (!(sc & KEY_PRESSED))
245+
if (!(scBuf.Pressed))
246246
continue;
247247

248248
if (bsCount == 0)
@@ -266,7 +266,7 @@ void KShellThread()
266266
}
267267
case KEY_UP_ARROW:
268268
{
269-
if (!(sc & KEY_PRESSED))
269+
if (!(scBuf.Pressed))
270270
continue;
271271

272272
if (history.size() == 0 ||
@@ -291,7 +291,7 @@ void KShellThread()
291291
}
292292
case KEY_DOWN_ARROW:
293293
{
294-
if (!(sc & KEY_PRESSED))
294+
if (!(scBuf.Pressed))
295295
continue;
296296

297297
if (history.size() == 0 ||
@@ -325,7 +325,7 @@ void KShellThread()
325325
}
326326
case KEY_LEFT_ARROW:
327327
{
328-
if (!(sc & KEY_PRESSED))
328+
if (!(scBuf.Pressed))
329329
continue;
330330

331331
if (seekCount == 0)
@@ -359,7 +359,7 @@ void KShellThread()
359359
}
360360
case KEY_RIGHT_ARROW:
361361
{
362-
if (!(sc & KEY_PRESSED))
362+
if (!(scBuf.Pressed))
363363
continue;
364364

365365
if (seekCount == bsCount)
@@ -391,7 +391,7 @@ void KShellThread()
391391
}
392392
case KEY_HOME:
393393
{
394-
if (!(sc & KEY_PRESSED))
394+
if (!(scBuf.Pressed))
395395
continue;
396396

397397
if (homeX == 0 || homeY == 0)
@@ -404,7 +404,7 @@ void KShellThread()
404404
}
405405
case KEY_END:
406406
{
407-
if (!(sc & KEY_PRESSED))
407+
if (!(scBuf.Pressed))
408408
continue;
409409

410410
if (unseekX == 0 || unseekY == 0)
@@ -418,7 +418,7 @@ void KShellThread()
418418
break;
419419
}
420420

421-
if (!(sc & KEY_PRESSED))
421+
if (!(scBuf.Pressed))
422422
continue;
423423

424424
if (!Driver::IsValidChar(sc))

Kernel/subsystem/usb/hid/keyboard.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222

2323
namespace UniversalSerialBus
2424
{
25+
InputReport kir = {};
26+
int ReportKeyboardEvent(uint32_t Key, uint8_t Pressed)
27+
{
28+
kir.Type = INPUT_TYPE_KEYBOARD;
29+
// kir.Device = Device;
30+
kir.Keyboard.Key = (KeyScanCodes)(Key);
31+
kir.Keyboard.Pressed = Pressed;
32+
// v0::ReportInputEvent(DriverID, &kir);
33+
return 0;
34+
}
35+
2536
void OnURBCompleteKeyboard(struct USBRequestBlock *urb)
2637
{
2738
if (urb->Status != USB_REQ_SUCCESS)

Kernel/subsystem/usb/hid/mouse.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@
2222

2323
namespace UniversalSerialBus
2424
{
25+
InputReport mir = {};
26+
int ReportMouseEvent(uint32_t Key, uint8_t Pressed)
27+
{
28+
mir.Type = INPUT_TYPE_MOUSE;
29+
// mir.Device = MouseDevID;
30+
// mir.Mouse.LeftButton = Packet.Base.LeftButton;
31+
// mir.Mouse.RightButton = Packet.Base.RightButton;
32+
// mir.Mouse.MiddleButton = Packet.Base.MiddleButton;
33+
// mir.Mouse.Button4 = Packet.ZMovement.Button4;
34+
// mir.Mouse.Button5 = Packet.ZMovement.Button5;
35+
// mir.Mouse.X = X;
36+
// mir.Mouse.Y = -Y;
37+
// mir.Mouse.Z = Packet.ZMovement.Z;
38+
// v0::ReportInputEvent(DriverID, &mir);
39+
return 0;
40+
}
41+
2542
void OnURBCompleteMouse(struct USBRequestBlock *urb)
2643
{
2744
if (urb->Status != USB_REQ_SUCCESS)

0 commit comments

Comments
 (0)