Re-write keyboard functionality.

This commit is contained in:
Enrico Fraccaroli
2022-01-12 11:23:34 +01:00
parent ac9b627fad
commit 4a29a27204
8 changed files with 504 additions and 177 deletions
-89
View File
@@ -1,89 +0,0 @@
Key Normal Shifted Ctrl Alt (DONE)
A 1E61 1E41 1E01 1E00
B 3062 3042 3002 3000
C 2E63 2E42 2E03 2E00
D 2064 2044 2004 2000
E 1265 1245 1205 1200
F 2166 2146 2106 2100
G 2267 2247 2207 2200
H 2368 2348 2308 2300
I 1769 1749 1709 1700
J 246A 244A 240A 2400
K 256B 254B 250B 2500
L 266C 264C 260C 2600
M 326D 324D 320D 3200
N 316E 314E 310E 3100
O 186F 184F 180F 1800
P 1970 1950 1910 1900
Q 1071 1051 1011 1000
R 1372 1352 1312 1300
S 1F73 1F53 1F13 1F00
T 1474 1454 1414 1400
U 1675 1655 1615 1600
V 2F76 2F56 2F16 2F00
W 1177 1157 1117 1100
X 2D78 2D58 2D18 2D00
Y 1579 1559 1519 1500
Z 2C7A 2C5A 2C1A 2C00
Key Normal Shifted Ctrl Alt (DONE)
1 0231 0221 7800
2 0332 0340 0300 7900
3 0433 0423 7A00
4 0534 0524 7B00
5 0635 0625 7C00
6 0736 075E 071E 7D00
7 0837 0826 7E00
8 0938 092A 7F00
9 0A39 0A28 8000
0 0B30 0B29 8100
Key Normal Shifted Ctrl Alt
- 0C2D 0C5F 0C1F 8200
= 0D3D 0D2B 8300
[ 1A5B 1A7B 1A1B 1A00
] 1B5D 1B7D 1B1D 1B00
; 273B 273A 2700
' 2827 2822
` 2960 297E
\ 2B5C 2B7C 2B1C 2600 (same as Alt L)
, 332C 333C
. 342E 343E
/ 352F 353F
Key Normal Shifted Ctrl Alt (DONE)
F1 3B00 5400 5E00 6800
F2 3C00 5500 5F00 6900
F3 3D00 5600 6000 6A00
F4 3E00 5700 6100 6B00
F5 3F00 5800 6200 6C00
F6 4000 5900 6300 6D00
F7 4100 5A00 6400 6E00
F8 4200 5B00 6500 6F00
F9 4300 5C00 6600 7000
F10 4400 5D00 6700 7100
F11 5700 5900 5B00 5D00
F12 5800 5A00 5C00 5E00
Key Normal Shifted Ctrl Alt
BackSpace 0E08 0E08 0E7F 0E00
Del 5300 532E 9300 A300
Down Arrow 5000 5032 9100 A000
End 4F00 4F31 7500 9F00
Enter 1C0D 1C0D 1C0A A600
Esc 011B 011B 011B 0100
Home 4700 4737 7700 9700
Ins 5200 5230 9200 A200
Keypad 5 4C35 8F00
Keypad * 372A 9600 3700
Keypad - 4A2D 4A2D 8E00 4A00
Keypad + 4E2B 4E2B 4E00
Keypad / 352F 352F 9500 A400
Left Arrow 4B00 4B34 7300 9B00
PgDn 5100 5133 7600 A100
PgUp 4900 4939 8400 9900
PrtSc 7200
Right Arrow 4D00 4D36 7400 9D00
SpaceBar 3920 3920 3920 3920
Tab 0F09 0F00 9400 A500
Up Arrow 4800 4838 8D00 9800
+105
View File
@@ -0,0 +1,105 @@
#define KEY_LEFT_WIN 0xE05b
#define KEY_RIGHT_WIN 0xE05c
Normal Shifted Ctrl Alt
KEY_A 0x001E A 0x1E61 0x1E41 0x1E01 0x1E00
KEY_B 0x0030 B 0x3062 0x3042 0x3002 0x3000
KEY_C 0x002E C 0x2E63 0x2E42 0x2E03 0x2E00
KEY_D 0x0020 D 0x2064 0x2044 0x2004 0x2000
KEY_E 0x0012 E 0x1265 0x1245 0x1205 0x1200
KEY_F 0x0021 F 0x2166 0x2146 0x2106 0x2100
KEY_G 0x0022 G 0x2267 0x2247 0x2207 0x2200
KEY_H 0x0023 H 0x2368 0x2348 0x2308 0x2300
KEY_I 0x0017 I 0x1769 0x1749 0x1709 0x1700
KEY_J 0x0024 J 0x246A 0x244A 0x240A 0x2400
KEY_K 0x0025 K 0x256B 0x254B 0x250B 0x2500
KEY_L 0x0026 L 0x266C 0x264C 0x260C 0x2600
KEY_M 0x0032 M 0x326D 0x324D 0x320D 0x3200
KEY_N 0x0031 N 0x316E 0x314E 0x310E 0x3100
KEY_O 0x0018 O 0x186F 0x184F 0x180F 0x1800
KEY_P 0x0019 P 0x1970 0x1950 0x1910 0x1900
KEY_Q 0x0010 Q 0x1071 0x1051 0x1011 0x1000
KEY_R 0x0013 R 0x1372 0x1352 0x1312 0x1300
KEY_S 0x001F S 0x1F73 0x1F53 0x1F13 0x1F00
KEY_T 0x0014 T 0x1474 0x1454 0x1414 0x1400
KEY_U 0x0016 U 0x1675 0x1655 0x1615 0x1600
KEY_V 0x002F V 0x2F76 0x2F56 0x2F16 0x2F00
KEY_W 0x0011 W 0x1177 0x1157 0x1117 0x1100
KEY_X 0x002D X 0x2D78 0x2D58 0x2D18 0x2D00
KEY_Y 0x0015 Y 0x1579 0x1559 0x1519 0x1500
KEY_Z 0x002C Z 0x2C7A 0x2C5A 0x2C1A 0x2C00
KEY_1 0x0002 1 ! 0x0231 0x0221 0x0000 0x7800
KEY_2 0x0003 2 " 0x0332 0x0322 0x0300 0x7900
KEY_3 0x0004 3 £ 0x0433 0x049C 0x0000 0x7A00
KEY_4 0x0005 4 $ 0x0534 0x0524 0x0000 0x7B00
KEY_5 0x0006 5 % 0x0635 0x0625 0x0000 0x7C00
KEY_6 0x0007 6 & 0x0736 0x075E 0x071E 0x7D00
KEY_7 0x0008 7 / 0x0837 0x0826 0x0000 0x7E00
KEY_8 0x0009 8 ( 0x0938 0x0928 0x0000 0x7F00
KEY_9 0x000A 9 ) 0x0A39 0x0A29 0x0000 0x8000
KEY_0 0x000B 0 = 0x0B30 0x0B3D 0x0000 0x8100
KEY_GRAVE 0x0029 \ | 0x295C 0x297C 0x0000 0x2900
KEY_APOSTROPHE 0x000C ' ? 0x0C27 0x0C3F 0x0000 0x8200
KEY_I_ACC 0x000D ì ^ 0x0D8D 0x0D5E 0x0000 0x8300
KEY_LEFT_BRAKET 0x001A è é [ 0x1A8A 0x1A82 0x0000 0x1A5B
KEY_RIGHT_BRAKET 0x001B + * ] 0x1B2B 0x1B2A 0x0000 0x1B5D
KEY_SEMICOLON 0x0027 ò ç @ 0x2795 0x2780 0x0000 0x2740
KEY_DOUBLE_QUOTES 0x0028 à ° # 0x2885 0x28A7 0x0000 0x2823
KEY_BACKSLASH 0x002B ù § 0x2B97 0x2BA7 0x0000 0x2B00
KEY_KP_LESS 0x0056 < > 0x563C 0x563E 0x0000 0x5600
KEY_COMMA 0x0033 , ; 0x332C 0x333B 0x0000 0x3300
KEY_PERIOD 0x0034 . : 0x342E 0x343A 0x0000 0x3400
KEY_MINUS 0x0035 - _ 0x352D 0x355F 0x0000 0x3500
KEY_F1 0x003B F1 0x3B00 0x5400 0x5E00 0x6800
KEY_F2 0x003C F2 0x3C00 0x5500 0x5F00 0x6900
KEY_F3 0x003D F3 0x3D00 0x5600 0x6000 0x6A00
KEY_F4 0x003E F4 0x3E00 0x5700 0x6100 0x6B00
KEY_F5 0x003F F5 0x3F00 0x5800 0x6200 0x6C00
KEY_F6 0x0040 F6 0x4000 0x5900 0x6300 0x6D00
KEY_F7 0x0041 F7 0x4100 0x5A00 0x6400 0x6E00
KEY_F8 0x0042 F8 0x4200 0x5B00 0x6500 0x6F00
KEY_F9 0x0043 F9 0x4300 0x5C00 0x6600 0x7000
KEY_F10 0x0044 F10 0x4400 0x5D00 0x6700 0x7100
KEY_F11 0x0057 F11 0x5700 0x5900 0x5B00 0x5D00
KEY_F12 0x0058 F12 0x5800 0x5A00 0x5C00 0x5E00
KEY_BACKSPACE 0x000E BackSpace 0x0E08 0x0E08 0x0E7F 0x0E00
KEY_ENTER 0x001C Enter 0x1C0D 0x1C0D 0x1C0A 0xA600
KEY_ESCAPE 0x0001 Esc 0x011B 0x011B 0x011B 0x0100
KEY_TAB 0x000F Tab 0x0F09 0x0F00 0x9400 0xA500
KEY_SPACE 0x0039 SpaceBar 0x3920 0x3920 0x3920 0x3920
KEY_INSERT 0xE052 Ins 0x5200 0x5230 0x9200 0xA200
KEY_HOME 0xE047 Home 0x4700 0x4737 0x7700 0x9700
KEY_PAGE_UP 0xE049 PgUp 0x4900 0x4939 0x8400 0x9900
KEY_DELETE 0xE053 Del 0x5300 0x532E 0x9300 0xA300
KEY_END 0xE04F End 0x4F00 0x4F31 0x7500 0x9F00
KEY_PAGE_DOWN 0xE051 PgDn 0x5100 0x5133 0x7600 0xA100
KEY_UP_ARROW 0xE048 Up Arrow 0x4800 0x4838 0x8D00 0x9800
KEY_DOWN_ARROW 0xE050 Down Arrow 0x5000 0x5032 0x9100 0xA000
KEY_LEFT_ARROW 0xE04B Left Arrow 0x4B00 0x4B34 0x7300 0x9B00
KEY_RIGHT_ARROW 0xE04D Right Arrow 0x4D00 0x4D36 0x7400 0x9D00
KEY_KP_DIV 0xE035 Kp.Div 0xE035 0xE035 0x3500 0x3500
KEY_KP_MUL 0x0037 Kp.Mul 0x372A 0x372A 0x3700 0x3700
KEY_KP_SUB 0x004A Kp.Sub 0x4A2D 0x4A2D 0x4A00 0x4A00
KEY_KP_ADD 0x004E Kp.Add 0x4E2B 0x4E2B 0x4E00 0x4E00
KEY_KP_RETURN 0xE01C Kp.Enter 0xE01C 0xE01C 0x1C00 0x1C00
KEY_KP7 0x0047 0x4737 0x4737 0x4700 0x4700
KEY_KP8 0x0048 0x4838 0x4838 0x4800 0x4800
KEY_KP9 0x0049 0x4939 0x4939 0x4900 0x4900
KEY_KP4 0x004B 0x4B34 0x4B34 0x4B00 0x4B00
KEY_KP5 0x004C 0x4C35 0x4C35 0x4C00 0x4C00
KEY_KP6 0x004D 0x4D36 0x4D36 0x4D00 0x4D00
KEY_KP1 0x004F 0x4F31 0x4F31 0x4F00 0x4F00
KEY_KP2 0x0050 0x5032 0x5032 0x5000 0x5000
KEY_KP3 0x0051 0x5133 0x5133 0x5100 0x5100
KEY_KP0 0x0052 0x5230 0x5230 0x5200 0x5200
KEY_KP_DEC 0x0053 0x532E 0x532E 0x5300 0x5300
+40
View File
@@ -0,0 +1,40 @@
/// @file array.h
/// @brief
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#pragma once
#ifdef __KERNEL__
#define DECLARE_ARRAY(type, name) \
typedef struct arr_##name##_t { \
const unsigned size; \
type *buffer; \
} arr_##name##_t; \
arr_##name##_t alloc_arr_##name(unsigned len) \
{ \
arr_##name##_t a = { len, len > 0 ? kmalloc(sizeof(type) * len) : NULL }; \
memset(a.buffer, 0, sizeof(type) * len); \
return a; \
} \
static inline void free_arr_##name(arr_##name##_t *arr) \
{ \
kfree(arr->buffer); \
}
#else
#define DECLARE_ARRAY(type, name) \
typedef struct arr_##name##_t { \
const unsigned size; \
type *buffer; \
} arr_##name##_t; \
arr_##name##_t alloc_arr_##name(unsigned len) \
{ \
arr_##name##_t a = { len, len > 0 ? malloc(sizeof(type) * len) : NULL }; \
memset(a.buffer, 0, sizeof(type) * len); \
return a; \
} \
static inline void free_arr_##name(arr_##name##_t *arr) \
{ \
free(arr->buffer); \
}
#endif
+133
View File
@@ -0,0 +1,133 @@
/// @file ring_buffer.h
/// @brief
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#pragma once
#define DECLARE_FS_RING_BUFFER(type, name, length, init) \
typedef struct rb_##name##_t { \
unsigned size, read, write; \
type buffer[length]; \
} rb_##name##_t; \
static inline void init_rb_##name(rb_##name##_t *rb) \
{ \
rb->size = length; \
rb->read = rb->write = 0; \
memset(rb->buffer, init, sizeof(type) * length); \
} \
static inline void free_rb_##name(rb_##name##_t *rb) \
{ \
kfree(rb->buffer); \
} \
static inline unsigned step_rb_##name(rb_##name##_t *rb, unsigned index) \
{ \
return (index == (rb->size - 1)) ? 0 : index + 1; \
} \
static inline void push_rb_##name(rb_##name##_t *rb, type item) \
{ \
if (step_rb_##name(rb, rb->write) == rb->read) \
rb->read = step_rb_##name(rb, rb->read); \
rb->buffer[rb->write] = item; \
rb->write = step_rb_##name(rb, rb->write); \
} \
static inline type pop_rb_##name(rb_##name##_t *rb) \
{ \
type item = init; \
if (rb->write != rb->read) { \
item = rb->buffer[rb->read]; \
rb->read = step_rb_##name(rb, rb->read); \
} \
return item; \
} \
static inline void get_rb_##name(rb_##name##_t *rb, unsigned index, type *item) \
{ \
if (index < rb->size) \
*item = rb->buffer[index]; \
}
#ifdef __KERNEL__
#define DECLARE_RING_BUFFER(type, name, init) \
typedef struct rb_##name##_t { \
const unsigned size; \
unsigned read, write; \
type *buffer; \
} rb_##name##_t; \
static inline rb_##name##_t alloc_rb_##name(unsigned len) \
{ \
rb_##name##_t rb = { len, 0U, 0U, len > 0 ? kmalloc(sizeof(type) * len) : NULL }; \
memset(rb.buffer, init, sizeof(type) * len); \
return rb; \
} \
static inline void free_rb_##name(rb_##name##_t *rb) \
{ \
kfree(rb->buffer); \
} \
static inline unsigned step_rb_##name(rb_##name##_t *rb, unsigned index) \
{ \
return (index == (rb->size - 1)) ? 0 : index + 1; \
} \
static inline void push_rb_##name(rb_##name##_t *rb, type item) \
{ \
if (step_rb_##name(rb, rb->write) == rb->read) \
rb->read = step_rb_##name(rb, rb->read); \
rb->buffer[rb->write] = item; \
rb->write = step_rb_##name(rb, rb->write); \
} \
static inline void pop_rb_##name(rb_##name##_t *rb, type *item) \
{ \
*item = init; \
if (rb->write != rb->read) { \
*item = rb->buffer[rb->read]; \
rb->read = step_rb_##name(rb, rb->read); \
} \
} \
static inline void get_rb_##name(rb_##name##_t *rb, unsigned index, type *item) \
{ \
if (index < rb->size) \
*item = rb->buffer[index]; \
}
#else
#define DECLARE_RING_BUFFER(type, name) \
typedef struct rb_##name##_t { \
const unsigned size; \
unsigned read, write; \
type *buffer; \
} rb_##name##_t; \
static inline rb_##name##_t alloc_rb_##name(unsigned len) \
{ \
rb_##name##_t rb = { len, 0U, 0U, len > 0 ? malloc(sizeof(type) * len) : NULL }; \
memset(rb.buffer, 0, sizeof(type) * len); \
return rb; \
} \
static inline void free_rb_##name(rb_##name##_t *rb) \
{ \
free(rb->buffer); \
} \
static inline unsigned step_rb_##name(rb_##name##_t *rb, unsigned index) \
{ \
return (index == (rb->size - 1)) ? 0 : index + 1; \
} \
static inline void push_rb_##name(rb_##name##_t *rb, type item) \
{ \
if (step_rb_##name(rb, rb->write) == rb->read) \
rb->read = step_rb_##name(rb, rb->read); \
rb->buffer[rb->write] = item; \
rb->write = step_rb_##name(rb, rb->write); \
} \
static inline void pop_rb_##name(rb_##name##_t *rb, type *item) \
{ \
if (rb->write != rb->read) { \
*item = rb->buffer[rb->read]; \
rb->read = step_rb_##name(rb, rb->read); \
} \
} \
static inline void get_rb_##name(rb_##name##_t *rb, unsigned index, type *item) \
{ \
if (index < rb->size) \
*item = rb->buffer[index]; \
}
#endif
+20 -20
View File
@@ -18,18 +18,18 @@ typedef enum {
KEYMAP_TYPE_MAX ///< The delimiter for the keyboard types.
} keymap_type_t;
/// @brief Defines a set of arrays used to map key to characters.
/// @brief Defines the mapping of a single scancode towards a set of characters.
typedef struct keymap_t {
/// The basic mapping.
int32_t base[65536];
int normal;
/// The mapping when shifted.
int32_t shift[65536];
int shift;
/// The mapping when ctrl is pressed.
int32_t ctrl[65536];
/// The mapping when right alt is pressed.
int32_t alt[65536];
int ctrl;
/// The mapping when alt is pressed.
int alt;
/// The mapping when numlock is active.
uint32_t numlock[65536];
int numlock;
} keymap_t;
/// @brief Returns the current keymap type.
@@ -42,7 +42,7 @@ void set_keymap_type(keymap_type_t type);
/// @brief Returns the current keymap.
/// @return Pointer to the current keymap.
const keymap_t *get_keymap();
const keymap_t *get_keymap(int scancode);
/// @brief Initializes the supported keymaps.
void init_keymaps();
@@ -52,16 +52,16 @@ void init_keymaps();
/// @{
#define KEY_ESCAPE 0x0001U ///< Escape character
#define KEY_ONE 0x0002U ///< 1
#define KEY_TWO 0x0003U ///< 2
#define KEY_THREE 0x0004U ///< 3
#define KEY_FOUR 0x0005U ///< 4
#define KEY_FIVE 0x0006U ///< 5
#define KEY_SIX 0x0007U ///< 6
#define KEY_SEVEN 0x0008U ///< 7
#define KEY_EIGHT 0x0009U ///< 8
#define KEY_NINE 0x000AU ///< 9
#define KEY_ZERO 0x000BU ///< 0
#define KEY_1 0x0002U ///< 1
#define KEY_2 0x0003U ///< 2
#define KEY_3 0x0004U ///< 3
#define KEY_4 0x0005U ///< 4
#define KEY_5 0x0006U ///< 5
#define KEY_6 0x0007U ///< 6
#define KEY_7 0x0008U ///< 7
#define KEY_8 0x0009U ///< 8
#define KEY_9 0x000AU ///< 9
#define KEY_0 0x000BU ///< 0
#define KEY_APOSTROPHE 0x000CU ///< '
#define KEY_I_ACC 0x000DU ///< i'
#define KEY_BACKSPACE 0x000EU ///< Backspace
@@ -135,12 +135,12 @@ void init_keymaps();
#define KEY_KP0 0x0052U ///< NP - Ins
#define KEY_KP_DEC 0x0053U ///< NP - Del
#define KEY_KP_LESS 0x0056U ///< NP - Del
#define KEY_F11 0x0057U ///< F11 57431
#define KEY_F12 0x0058U ///< F12 57432
#define KEY_KP_RETURN 0xE01cU ///< NP - Enter 57372
#define KEY_RIGHT_CONTROL 0xE01DU ///< Right Ctrl 57373
#define KEY_KP_DIV 0xE035U ///< Divide 57397
#define KEY_RIGHT_ALT 0xE038U ///< Right Alt 57400
#define KEY_F11 0xE057U ///< F11 57431
#define KEY_F12 0xE058U ///< F12 57432
#define KEY_LEFT_WIN 0xE05bU ///< Left Winkey 57435
#define KEY_RIGHT_WIN 0xE05cU ///< Right Winkey 57436
#define KEY_INSERT 0xE052U ///< Ins 57426
+94 -60
View File
@@ -24,6 +24,8 @@
#include "ctype.h"
#include "descriptor_tables/isr.h"
#include "process/scheduler.h"
#include "ring_buffer.h"
#include "string.h"
/// The dimension of the circular buffer used to store video history.
#define BUFSIZE 256
@@ -32,7 +34,7 @@
#define STEP(x) (((x) == BUFSIZE - 1) ? 0 : ((x) + 1))
/// Circular Buffer where the pressed keys are stored.
static int32_t circular_buffer[BUFSIZE] = { 0 };
static int circular_buffer[BUFSIZE] = { 0 };
/// Index inside the buffer...
static long buf_r = 0;
/// Index inside the buffer...
@@ -52,14 +54,14 @@ static uint32_t kflags = 0;
#define KBD_LEFT_ALT (1 << 7) ///< Flag which identifies the left alt.
#define KBD_RIGHT_ALT (1 << 8) ///< Flag which identifies the right alt.
static inline void push_character(uint16_t c)
static inline void push_character(int c)
{
// Update buffer.
if (STEP(buf_w) == buf_r) {
buf_r = STEP(buf_r);
}
circular_buffer[buf_w] = c;
circular_buffer[buf_w] = c & 0x00FF;
buf_w = STEP(buf_w);
}
@@ -74,6 +76,31 @@ static inline int read_character()
return c;
}
static inline bool_t get_keypad_number(int scancode)
{
if (scancode == KEY_KP0)
return 0;
if (scancode == KEY_KP1)
return 1;
if (scancode == KEY_KP2)
return 2;
if (scancode == KEY_KP3)
return 3;
if (scancode == KEY_KP4)
return 4;
if (scancode == KEY_KP5)
return 5;
if (scancode == KEY_KP6)
return 6;
if (scancode == KEY_KP7)
return 7;
if (scancode == KEY_KP8)
return 8;
if (scancode == KEY_KP9)
return 9;
return -1;
}
void keyboard_isr(pt_regs *f)
{
unsigned int scancode;
@@ -89,6 +116,9 @@ void keyboard_isr(pt_regs *f)
scancode = (scancode << 8U) | ps2_read();
}
// Get the keypad number, of num-lock is disabled. Otherwise, initialize to -1;
int keypad_fun_number = !bitmask_check(kflags, KBD_NUM_LOCK) ? get_keypad_number(scancode) : -1;
// If the key has just been released.
if (scancode == KEY_LEFT_SHIFT) {
bitmask_set_assign(kflags, KBD_LEFT_SHIFT);
@@ -149,67 +179,72 @@ void keyboard_isr(pt_regs *f)
} else if ((scancode == KEY_ENTER) || (scancode == KEY_KP_RETURN)) {
push_character('\n');
pr_debug("Press(KEY_ENTER)\n");
} else if (scancode == KEY_PAGE_UP) {
} else if ((scancode == KEY_PAGE_UP) || (keypad_fun_number == 9)) {
push_character(scancode);
pr_debug("Toggle(KEY_PAGE_UP)\n");
} else if (scancode == KEY_PAGE_DOWN) {
pr_debug("Press(KEY_PAGE_UP)\n");
} else if ((scancode == KEY_PAGE_DOWN) || (keypad_fun_number == 2)) {
push_character(scancode);
pr_debug("Toggle(KEY_PAGE_DOWN)\n");
pr_debug("Press(KEY_PAGE_DOWN)\n");
} else if ((scancode == KEY_UP_ARROW) || (keypad_fun_number == 8)) {
pr_debug("Press(KEY_UP_ARROW)\n");
push_character('\033');
push_character('[');
push_character('A');
} else if ((scancode == KEY_DOWN_ARROW) || (keypad_fun_number == 2)) {
pr_debug("Press(KEY_DOWN_ARROW)\n");
push_character('\033');
push_character('[');
push_character('B');
} else if ((scancode == KEY_RIGHT_ARROW) || (keypad_fun_number == 6)) {
pr_debug("Press(KEY_RIGHT_ARROW)\n");
push_character('\033');
push_character('[');
push_character('C');
} else if ((scancode == KEY_LEFT_ARROW) || (keypad_fun_number == 4)) {
pr_debug("Press(KEY_LEFT_ARROW)\n");
push_character('\033');
push_character('[');
push_character('D');
} else if ((scancode == KEY_HOME) || (keypad_fun_number == 7)) {
pr_debug("Press(KEY_HOME)\n");
push_character('\033');
push_character('[');
push_character('H');
} else if ((scancode == KEY_END) || (keypad_fun_number == 1)) {
pr_debug("Press(KEY_END)\n");
push_character('\033');
push_character('[');
push_character('F');
} else if (scancode == KEY_ESCAPE) {
// Nothing to do.
} else if (!(scancode & CODE_BREAK)) {
pr_debug("scancode : %04x\n", scancode);
// Get the current keymap.
const keymap_t *keymap = get_keymap(scancode);
// Get the specific keymap.
#if 0
pr_debug("%04x '%c' (%04x) '%c' (%04x) '%c' (%04x) '%c' (%04x))\n",
scancode,
((0x00ff & keymap->normal) >= 32) ? keymap->normal : ' ', keymap->normal,
((0x00ff & keymap->shift) >= 32) ? keymap->shift : ' ', keymap->shift,
((0x00ff & keymap->ctrl) >= 32) ? keymap->ctrl : ' ', keymap->ctrl,
((0x00ff & keymap->alt) >= 32) ? keymap->alt : ' ', keymap->alt);
#endif
int character = 0;
if (!bitmask_check(kflags, KBD_LEFT_SHIFT | KBD_RIGHT_SHIFT) != !bitmask_check(kflags, KBD_CAPS_LOCK)) {
push_character(keymap->shift);
} else if ((get_keymap_type() == KEYMAP_IT) && bitmask_check(kflags, KBD_RIGHT_ALT) && (bitmask_check(kflags, KBD_LEFT_SHIFT | KBD_RIGHT_SHIFT))) {
push_character(keymap->alt);
} else if (bitmask_check(kflags, KBD_RIGHT_ALT)) {
push_character(keymap->alt);
} else if (get_keypad_number(scancode) && bitmask_check(kflags, KBD_NUM_LOCK)) {
push_character(keymap->normal);
} else {
push_character(keymap->normal);
}
// Parse the key.
switch (scancode) {
case KEY_ESCAPE:
break;
case KEY_UP_ARROW:
push_character('\033');
push_character('[');
push_character('A');
break;
case KEY_DOWN_ARROW:
push_character('\033');
push_character('[');
push_character('B');
break;
case KEY_RIGHT_ARROW:
push_character('\033');
push_character('[');
push_character('C');
break;
case KEY_LEFT_ARROW:
push_character('\033');
push_character('[');
push_character('D');
break;
case KEY_HOME:
push_character('\033');
push_character('[');
push_character('H');
break;
case KEY_END:
push_character('\033');
push_character('[');
push_character('F');
break;
default: {
// Get the current keymap.
const keymap_t *keymap = get_keymap();
if (!bitmask_check(kflags, KBD_LEFT_SHIFT | KBD_RIGHT_SHIFT) != !bitmask_check(kflags, KBD_CAPS_LOCK)) {
character = keymap->shift[scancode];
} else if ((get_keymap_type() == KEYMAP_IT) && bitmask_check(kflags, KBD_RIGHT_ALT) && (bitmask_check(kflags, KBD_LEFT_SHIFT | KBD_RIGHT_SHIFT))) {
if (scancode == KEY_LEFT_BRAKET) {
character = '{';
} else if (scancode == KEY_RIGHT_BRAKET) {
character = '}';
}
} else if (bitmask_check(kflags, KBD_NUM_LOCK)) {
character = keymap->numlock[scancode];
} else if (bitmask_check(kflags, KBD_RIGHT_ALT)) {
/*
else if () {
character = keymap->alt[scancode];
} else {
character = keymap->base[scancode];
}
// We have failed to retrieve the character.
if (character <= 0) {
@@ -222,8 +257,7 @@ void keyboard_isr(pt_regs *f)
}
// Update buffer.
push_character(character);
}
}
*/
}
pic8259_send_eoi(IRQ_KEYBOARD);
}
+108 -4
View File
@@ -11,7 +11,7 @@
/// Identifies the current keymap type.
keymap_type_t keymap_type = KEYMAP_IT;
/// Contains the different keymaps.
keymap_t keymaps[KEYMAP_TYPE_MAX];
keymap_t keymaps[KEYMAP_TYPE_MAX][65536];
keymap_type_t get_keymap_type()
{
@@ -24,9 +24,9 @@ void set_keymap_type(keymap_type_t type)
keymap_type = type;
}
const keymap_t *get_keymap()
const keymap_t *get_keymap(int scancode)
{
return &keymaps[keymap_type];
return &keymaps[keymap_type][scancode];
}
void init_keymaps()
@@ -35,6 +35,110 @@ void init_keymaps()
memset(&keymaps[i], -1, sizeof(keymap_t));
// == ITALIAN KEY MAPPING =================================================
// Keys Normal Shifted Ctrl Alt
keymaps[KEYMAP_IT][KEY_A] = (keymap_t){ 0x1E61, 0x1E41, 0x1E01, 0x1E00 }; // 0x001E A
keymaps[KEYMAP_IT][KEY_B] = (keymap_t){ 0x3062, 0x3042, 0x3002, 0x3000 }; // 0x0030 B
keymaps[KEYMAP_IT][KEY_C] = (keymap_t){ 0x2E63, 0x2E43, 0x2E03, 0x2E00 }; // 0x002E C
keymaps[KEYMAP_IT][KEY_D] = (keymap_t){ 0x2064, 0x2044, 0x2004, 0x2000 }; // 0x0020 D
keymaps[KEYMAP_IT][KEY_E] = (keymap_t){ 0x1265, 0x1245, 0x1205, 0x1200 }; // 0x0012 E
keymaps[KEYMAP_IT][KEY_F] = (keymap_t){ 0x2166, 0x2146, 0x2106, 0x2100 }; // 0x0021 F
keymaps[KEYMAP_IT][KEY_G] = (keymap_t){ 0x2267, 0x2247, 0x2207, 0x2200 }; // 0x0022 G
keymaps[KEYMAP_IT][KEY_H] = (keymap_t){ 0x2368, 0x2348, 0x2308, 0x2300 }; // 0x0023 H
keymaps[KEYMAP_IT][KEY_I] = (keymap_t){ 0x1769, 0x1749, 0x1709, 0x1700 }; // 0x0017 I
keymaps[KEYMAP_IT][KEY_J] = (keymap_t){ 0x246A, 0x244A, 0x240A, 0x2400 }; // 0x0024 J
keymaps[KEYMAP_IT][KEY_K] = (keymap_t){ 0x256B, 0x254B, 0x250B, 0x2500 }; // 0x0025 K
keymaps[KEYMAP_IT][KEY_L] = (keymap_t){ 0x266C, 0x264C, 0x260C, 0x2600 }; // 0x0026 L
keymaps[KEYMAP_IT][KEY_M] = (keymap_t){ 0x326D, 0x324D, 0x320D, 0x3200 }; // 0x0032 M
keymaps[KEYMAP_IT][KEY_N] = (keymap_t){ 0x316E, 0x314E, 0x310E, 0x3100 }; // 0x0031 N
keymaps[KEYMAP_IT][KEY_O] = (keymap_t){ 0x186F, 0x184F, 0x180F, 0x1800 }; // 0x0018 O
keymaps[KEYMAP_IT][KEY_P] = (keymap_t){ 0x1970, 0x1950, 0x1910, 0x1900 }; // 0x0019 P
keymaps[KEYMAP_IT][KEY_Q] = (keymap_t){ 0x1071, 0x1051, 0x1011, 0x1000 }; // 0x0010 Q
keymaps[KEYMAP_IT][KEY_R] = (keymap_t){ 0x1372, 0x1352, 0x1312, 0x1300 }; // 0x0013 R
keymaps[KEYMAP_IT][KEY_S] = (keymap_t){ 0x1F73, 0x1F53, 0x1F13, 0x1F00 }; // 0x001F S
keymaps[KEYMAP_IT][KEY_T] = (keymap_t){ 0x1474, 0x1454, 0x1414, 0x1400 }; // 0x0014 T
keymaps[KEYMAP_IT][KEY_U] = (keymap_t){ 0x1675, 0x1655, 0x1615, 0x1600 }; // 0x0016 U
keymaps[KEYMAP_IT][KEY_V] = (keymap_t){ 0x2F76, 0x2F56, 0x2F16, 0x2F00 }; // 0x002F V
keymaps[KEYMAP_IT][KEY_W] = (keymap_t){ 0x1177, 0x1157, 0x1117, 0x1100 }; // 0x0011 W
keymaps[KEYMAP_IT][KEY_X] = (keymap_t){ 0x2D78, 0x2D58, 0x2D18, 0x2D00 }; // 0x002D X
keymaps[KEYMAP_IT][KEY_Y] = (keymap_t){ 0x1579, 0x1559, 0x1519, 0x1500 }; // 0x0015 Y
keymaps[KEYMAP_IT][KEY_Z] = (keymap_t){ 0x2C7A, 0x2C5A, 0x2C1A, 0x2C00 }; // 0x002C Z
keymaps[KEYMAP_IT][KEY_1] = (keymap_t){ 0x0231, 0x0221, 0x0000, 0x7800 }; // 0x0002 1 !
keymaps[KEYMAP_IT][KEY_2] = (keymap_t){ 0x0332, 0x0322, 0x0300, 0x7900 }; // 0x0003 2 "
keymaps[KEYMAP_IT][KEY_3] = (keymap_t){ 0x0433, 0x049C, 0x0000, 0x7A00 }; // 0x0004 3 £
keymaps[KEYMAP_IT][KEY_4] = (keymap_t){ 0x0534, 0x0524, 0x0000, 0x7B00 }; // 0x0005 4 $
keymaps[KEYMAP_IT][KEY_5] = (keymap_t){ 0x0635, 0x0625, 0x0000, 0x7C00 }; // 0x0006 5 %
keymaps[KEYMAP_IT][KEY_6] = (keymap_t){ 0x0736, 0x0726, 0x071E, 0x7D00 }; // 0x0007 6 &
keymaps[KEYMAP_IT][KEY_7] = (keymap_t){ 0x0837, 0x082F, 0x0000, 0x7E00 }; // 0x0008 7 /
keymaps[KEYMAP_IT][KEY_8] = (keymap_t){ 0x0938, 0x0928, 0x0000, 0x7F00 }; // 0x0009 8 (
keymaps[KEYMAP_IT][KEY_9] = (keymap_t){ 0x0A39, 0x0A29, 0x0000, 0x8000 }; // 0x000A 9 )
keymaps[KEYMAP_IT][KEY_0] = (keymap_t){ 0x0B30, 0x0B3D, 0x0000, 0x8100 }; // 0x000B 0 =
keymaps[KEYMAP_IT][KEY_GRAVE] = (keymap_t){ 0x295C, 0x297C, 0x0000, 0x2900 }; // 0x0029 \ |
keymaps[KEYMAP_IT][KEY_APOSTROPHE] = (keymap_t){ 0x0C27, 0x0C3F, 0x0000, 0x8200 }; // 0x000C ' ?
keymaps[KEYMAP_IT][KEY_I_ACC] = (keymap_t){ 0x0D8D, 0x0D5E, 0x0000, 0x8300 }; // 0x000D ì ^
keymaps[KEYMAP_IT][KEY_LEFT_BRAKET] = (keymap_t){ 0x1A8A, 0x1A82, 0x0000, 0x1A5B }; // 0x001A è é [
keymaps[KEYMAP_IT][KEY_RIGHT_BRAKET] = (keymap_t){ 0x1B2B, 0x1B2A, 0x0000, 0x1B5D }; // 0x001B + * ]
keymaps[KEYMAP_IT][KEY_SEMICOLON] = (keymap_t){ 0x2795, 0x2780, 0x0000, 0x2740 }; // 0x0027 ò ç @
keymaps[KEYMAP_IT][KEY_DOUBLE_QUOTES] = (keymap_t){ 0x2885, 0x28A7, 0x0000, 0x2823 }; // 0x0028 à ° #
keymaps[KEYMAP_IT][KEY_BACKSLASH] = (keymap_t){ 0x2B97, 0x2BA7, 0x0000, 0x2B00 }; // 0x002B ù §
keymaps[KEYMAP_IT][KEY_KP_LESS] = (keymap_t){ 0x563C, 0x563E, 0x0000, 0x5600 }; // 0x0056 < >
keymaps[KEYMAP_IT][KEY_COMMA] = (keymap_t){ 0x332C, 0x333B, 0x0000, 0x3300 }; // 0x0033 , ;
keymaps[KEYMAP_IT][KEY_PERIOD] = (keymap_t){ 0x342E, 0x343A, 0x0000, 0x3400 }; // 0x0034 . :
keymaps[KEYMAP_IT][KEY_MINUS] = (keymap_t){ 0x352D, 0x355F, 0x0000, 0x3500 }; // 0x0035 - _
keymaps[KEYMAP_IT][KEY_F1] = (keymap_t){ 0x3B00, 0x5400, 0x5E00, 0x6800 }; // 0x003B F1
keymaps[KEYMAP_IT][KEY_F2] = (keymap_t){ 0x3C00, 0x5500, 0x5F00, 0x6900 }; // 0x003C F2
keymaps[KEYMAP_IT][KEY_F3] = (keymap_t){ 0x3D00, 0x5600, 0x6000, 0x6A00 }; // 0x003D F3
keymaps[KEYMAP_IT][KEY_F4] = (keymap_t){ 0x3E00, 0x5700, 0x6100, 0x6B00 }; // 0x003E F4
keymaps[KEYMAP_IT][KEY_F5] = (keymap_t){ 0x3F00, 0x5800, 0x6200, 0x6C00 }; // 0x003F F5
keymaps[KEYMAP_IT][KEY_F6] = (keymap_t){ 0x4000, 0x5900, 0x6300, 0x6D00 }; // 0x0040 F6
keymaps[KEYMAP_IT][KEY_F7] = (keymap_t){ 0x4100, 0x5A00, 0x6400, 0x6E00 }; // 0x0041 F7
keymaps[KEYMAP_IT][KEY_F8] = (keymap_t){ 0x4200, 0x5B00, 0x6500, 0x6F00 }; // 0x0042 F8
keymaps[KEYMAP_IT][KEY_F9] = (keymap_t){ 0x4300, 0x5C00, 0x6600, 0x7000 }; // 0x0043 F9
keymaps[KEYMAP_IT][KEY_F10] = (keymap_t){ 0x4400, 0x5D00, 0x6700, 0x7100 }; // 0x0044 F10
keymaps[KEYMAP_IT][KEY_F11] = (keymap_t){ 0x5700, 0x5900, 0x5B00, 0x5D00 }; // 0x0057 F11
keymaps[KEYMAP_IT][KEY_F12] = (keymap_t){ 0x5800, 0x5A00, 0x5C00, 0x5E00 }; // 0x0058 F12
keymaps[KEYMAP_IT][KEY_BACKSPACE] = (keymap_t){ 0x0E08, 0x0E08, 0x0E7F, 0x0E00 }; // 0x000E BackSpace
keymaps[KEYMAP_IT][KEY_ENTER] = (keymap_t){ 0x1C0D, 0x1C0D, 0x1C0A, 0xA600 }; // 0x001C Enter
keymaps[KEYMAP_IT][KEY_ESCAPE] = (keymap_t){ 0x011B, 0x011B, 0x011B, 0x0100 }; // 0x0001 Esc
keymaps[KEYMAP_IT][KEY_TAB] = (keymap_t){ 0x0F09, 0x0F00, 0x9400, 0xA500 }; // 0x000F Tab
keymaps[KEYMAP_IT][KEY_SPACE] = (keymap_t){ 0x3920, 0x3920, 0x3920, 0x3920 }; // 0x0039 SpaceBar
keymaps[KEYMAP_IT][KEY_INSERT] = (keymap_t){ 0x5200, 0x5230, 0x9200, 0xA200 }; // 0xE052 Ins
keymaps[KEYMAP_IT][KEY_HOME] = (keymap_t){ 0x4700, 0x4737, 0x7700, 0x9700 }; // 0xE047 Home
keymaps[KEYMAP_IT][KEY_PAGE_UP] = (keymap_t){ 0x4900, 0x4939, 0x8400, 0x9900 }; // 0xE049 PgUp
keymaps[KEYMAP_IT][KEY_DELETE] = (keymap_t){ 0x5300, 0x532E, 0x9300, 0xA300 }; // 0xE053 Del
keymaps[KEYMAP_IT][KEY_END] = (keymap_t){ 0x4F00, 0x4F31, 0x7500, 0x9F00 }; // 0xE04F End
keymaps[KEYMAP_IT][KEY_PAGE_DOWN] = (keymap_t){ 0x5100, 0x5133, 0x7600, 0xA100 }; // 0xE051 PgDn
keymaps[KEYMAP_IT][KEY_UP_ARROW] = (keymap_t){ 0x4800, 0x4838, 0x8D00, 0x9800 }; // 0xE048 Up Arrow
keymaps[KEYMAP_IT][KEY_DOWN_ARROW] = (keymap_t){ 0x5000, 0x5032, 0x9100, 0xA000 }; // 0xE050 Down Arrow
keymaps[KEYMAP_IT][KEY_LEFT_ARROW] = (keymap_t){ 0x4B00, 0x4B34, 0x7300, 0x9B00 }; // 0xE04B Left Arrow
keymaps[KEYMAP_IT][KEY_RIGHT_ARROW] = (keymap_t){ 0x4D00, 0x4D36, 0x7400, 0x9D00 }; // 0xE04D Right Arrow
keymaps[KEYMAP_IT][KEY_KP_DIV] = (keymap_t){ 0x352F, 0x352F, 0x3500, 0x3500 }; // 0xE035 Kp.Div
keymaps[KEYMAP_IT][KEY_KP_MUL] = (keymap_t){ 0x372A, 0x372A, 0x3700, 0x3700 }; // 0x0037 Kp.Mul
keymaps[KEYMAP_IT][KEY_KP_SUB] = (keymap_t){ 0x4A2D, 0x4A2D, 0x4A00, 0x4A00 }; // 0x004A Kp.Sub
keymaps[KEYMAP_IT][KEY_KP_ADD] = (keymap_t){ 0x4E2B, 0x4E2B, 0x4E00, 0x4E00 }; // 0x004E Kp.Add
keymaps[KEYMAP_IT][KEY_KP_RETURN] = (keymap_t){ 0xE01C, 0xE01C, 0x1C00, 0x1C00 }; // 0xE01C Kp.Enter
keymaps[KEYMAP_IT][KEY_KP7] = (keymap_t){ 0x4737, 0x4737, 0x4700, 0x4700 }; // 0x0047
keymaps[KEYMAP_IT][KEY_KP8] = (keymap_t){ 0x4838, 0x4838, 0x4800, 0x4800 }; // 0x0048
keymaps[KEYMAP_IT][KEY_KP9] = (keymap_t){ 0x4939, 0x4939, 0x4900, 0x4900 }; // 0x0049
keymaps[KEYMAP_IT][KEY_KP4] = (keymap_t){ 0x4B34, 0x4B34, 0x4B00, 0x4B00 }; // 0x004B
keymaps[KEYMAP_IT][KEY_KP5] = (keymap_t){ 0x4C35, 0x4C35, 0x4C00, 0x4C00 }; // 0x004C
keymaps[KEYMAP_IT][KEY_KP6] = (keymap_t){ 0x4D36, 0x4D36, 0x4D00, 0x4D00 }; // 0x004D
keymaps[KEYMAP_IT][KEY_KP1] = (keymap_t){ 0x4F31, 0x4F31, 0x4F00, 0x4F00 }; // 0x004F
keymaps[KEYMAP_IT][KEY_KP2] = (keymap_t){ 0x5032, 0x5032, 0x5000, 0x5000 }; // 0x0050
keymaps[KEYMAP_IT][KEY_KP3] = (keymap_t){ 0x5133, 0x5133, 0x5100, 0x5100 }; // 0x0051
keymaps[KEYMAP_IT][KEY_KP0] = (keymap_t){ 0x5230, 0x5230, 0x5200, 0x5200 }; // 0x0052
keymaps[KEYMAP_IT][KEY_KP_DEC] = (keymap_t){ 0x532E, 0x532E, 0x5300, 0x5300 }; // 0x0053
#if 0
keymaps[KEYMAP_IT].base[KEY_ESCAPE] = 27;
keymaps[KEYMAP_IT].base[KEY_ONE] = '1';
keymaps[KEYMAP_IT].base[KEY_TWO] = '2';
@@ -63,7 +167,6 @@ void init_keymaps()
keymaps[KEYMAP_IT].base[KEY_LEFT_BRAKET] = 138;
keymaps[KEYMAP_IT].base[KEY_RIGHT_BRAKET] = '+';
keymaps[KEYMAP_IT].base[KEY_ENTER] = 13;
keymaps[KEYMAP_IT].base[KEY_A] = 'a';
keymaps[KEYMAP_IT].base[KEY_S] = 's';
keymaps[KEYMAP_IT].base[KEY_D] = 'd';
keymaps[KEYMAP_IT].base[KEY_F] = 'f';
@@ -287,6 +390,7 @@ void init_keymaps()
keymaps[KEYMAP_US].numlock[KEY_KP7] = '7';
keymaps[KEYMAP_US].numlock[KEY_KP8] = '8';
keymaps[KEYMAP_US].numlock[KEY_KP9] = '9';
#endif
}
/// @}
+4 -4
View File
@@ -29,8 +29,6 @@ static ssize_t procv_read(vfs_file_t *file, char *buf, off_t offset, size_t nbyt
if (buf == NULL) {
return -1;
}
// Get the currently running process.
task_struct *process = scheduler_get_current_process();
// Read the character from the keyboard.
int c = keyboard_getc();
if (c < 0)
@@ -42,15 +40,17 @@ static ssize_t procv_read(vfs_file_t *file, char *buf, off_t offset, size_t nbyt
video_shift_one_page_up();
return 0;
} else {
// Get the currently running process.
task_struct *process = scheduler_get_current_process();
// Return the character.
*((char *)buf) = c;
*((char *)buf) = c & 0x00FF;
if (bitmask_check(process->termios.c_lflag, ECHO)) {
if ((c == '\b') &&
(!bitmask_check(process->termios.c_lflag, ICANON) || !bitmask_check(process->termios.c_lflag, ECHOE))) {
return 1;
}
// Echo the character to video.
video_putc(c);
video_putc(c & 0x00FF);
}
}
return 1;