11 #include <lib/string.h>
13 #include <sys/trigger.h>
14 #include "drv/input/keyboard.h"
16 #include "sys/timer.h"
22 #define KEY_BUFFER_SIZE 16
23 #define KBD_IS_READDATA (1 << 0)
24 #define KBD_IS_WRITEDATA (1 << 1)
25 #define KBD_IS_RESET (1 << 2)
26 #define KBD_IS_CMD (1 << 3)
27 #define KBD_IS_LOCK (1 << 4)
28 #define KBD_IS_MOUSEDATA (1 << 5)
29 #define KBD_IS_TIMEOUT (1 << 6)
30 #define KBD_IS_ODDERROR (1 << 7)
31 #define KBD_CTRL_REG 0x61
38 bool key_ctrl =
false;
41 volatile char kmode = 0;
42 volatile char* curbuf = 0;
43 volatile uint32_t chartyped = 0;
184 default: b =
"?"; found =
false;
break;
187 return mode?(
char*)key:(found?b:0);
190 uint8_t getPressReleaseKeyboard() {
194 void keyboardctl(uint8_t param,
bool value) {
195 if(param == KEYBOARD_ECHO) {
204 bool is_lctrl_key() {
208 int getIntKeyboardWait(){
218 void* getCharKeyboardWait(
bool ints) {
234 void kbd_add_char(
char *buf,
char* key) {
235 if(kmode == 1 && curbuf != 0) {
248 }
else if(kmode == 2) {
253 void gets(
char *buffer) {
271 int gets_max(
char *buffer,
int length) {
276 if(chartyped >= length) {
308 (
void*)!getPressReleaseKeyboard(),
337 if (key != 0 &&
lastKey < 128){
339 if(!key_ctrl &&
lastKey != 0x0E)
340 tty_printf(
"%s", key);
342 kbd_add_char(curbuf, key);
353 ps2_in_wait_until_empty();
355 outb(PS2_DATA_PORT, 0xf4);
359 qemu_err(
"Keyboard error: Enable fail");
363 ps2_in_wait_until_empty();
365 outb(PS2_DATA_PORT, 0xf0);
369 qemu_err(
"Keyboard error: Scancode set fail");
373 ps2_in_wait_until_empty();
375 outb(PS2_DATA_PORT, 0);
379 qemu_err(
"Keyboard error: Zero fail");
383 size_t scancode = ps2_read() & 0b11;
385 qemu_note(
"SCANCODE SET: %d", scancode);
387 ps2_in_wait_until_empty();
389 outb(PS2_DATA_PORT, 0xf3);
393 qemu_err(
"Keyboard error: Repeat fail");
397 ps2_in_wait_until_empty();
399 outb(PS2_DATA_PORT, 0);
403 qemu_err(
"Keyboard error: Zero fail (phase 2)");
407 uint8_t conf = ps2_read_configuration_byte();
409 qemu_log(
"%d%d%d%d%d%d%d%d", (conf >> 0) & 1, (conf >> 1) & 1, (conf >> 2) & 1, (conf >> 3) & 1, (conf >> 4) & 1, (conf >> 5) & 1, (conf >> 6) & 1, (conf >> 7) & 1);
411 ps2_write_configuration_byte(conf | 0b1000001);
414 void ps2_keyboard_install_irq() {
417 qemu_log(
"Keyboard installed");
uint32_t mode
Режим работы (0 - Обычный | 1 - Режим логирования)
void keyboardHandler(registers_t regs)
Обработчик клавиатуры
char * getCharKeyboard(int key, bool mode)
Выводит символ, в зависимости от кода полученного с клавиатуры
uint8_t kbdstatus
Статус клавиатуры
bool SHIFT
Включен ли SHIFT.
bool echo
Включен ли вывод?
char * __getCharKeyboard(char *en_s, char *en_b, char *ru_s, char *ru_b)
Выводит правильный символ, в зависимости от языка и шифта
void keyboardInit()
Выполняет инициализацию клавиатуры
void tty_backspace()
Удаление последнего символа
volatile int lastKey
Последний индекс клавишы
bool RU
Печатаем русскими?
char * strcat(char *destination, const char *source)
Объединение строк
bool mutex_get(mutex_t *mutex, bool wait)
Получить мьютекс
void mutex_release(mutex_t *mutex)
Получить ближайщий свободный блок
void CallTrigger(int type, void *data1, void *data2, void *data3, void *data4, void *data5)
Функция для вызовов триггеров (Если самостоятельно надо вызвать триггер)