embox

Форк
0
135 строк · 3.6 Кб
1
/**
2
 * @file
3
 *
4
 * @date Apr 28, 2021
5
 * @author Anton Bondarev
6
 */
7
#include <util/log.h>
8

9
#include <stdint.h>
10

11
#include <kernel/irq.h>
12

13
#include <drivers/input/input_dev.h>
14
#include <drivers/ps_keyboard.h>
15
#include <drivers/common/memory.h>
16

17
#include <drivers/pl050.h>
18

19
#include <embox/unit.h>
20

21
#define BASE_ADDR		OPTION_GET(NUMBER,base_addr)
22
#define IRQ_NUM			OPTION_GET(NUMBER,irq_num)
23
#define TRANSLATE_TO_SET1	OPTION_GET(BOOLEAN,translate_to_set1)
24

25
EMBOX_UNIT_INIT(pl050_keyboard_init);
26

27

28
struct pl050_keyboard_indev {
29
	struct input_dev input_dev;
30
	struct pl050 *pl050_dev;
31
};
32

33
static int pl050_keyboard_stop(struct input_dev *dev) {
34

35
	/* TODO */
36
	return 0;
37
}
38

39
static const struct input_dev_ops kbd_input_ops = {
40
		/*.start = keyboard_start,*/
41
		.stop = pl050_keyboard_stop,
42
};
43

44
static struct pl050_keyboard_indev keyboard_dev = {
45
	.input_dev = {
46
		.ops = &kbd_input_ops,
47
		.name = "ps-keyboard",
48
		.type = INPUT_DEV_KBD,
49
	},
50
};
51

52
#if (TRANSLATE_TO_SET1 == 1)
53
static const uint32_t set2_to_set1_table[]={
54
/*	0	1	2	3	4	5	6	7	8	9	A	B	C	D	E	F
55
0*/	0,	0x43,	0,	0x3F,	0x3D,	0x3B,	0x3C,	0x58,	0x64,	0x44,	0x42,	0x40,	0x3E,	0x0F,	0x29,	0x59,	/*
56
1*/	0x65,	0x38,	0x2A,	0x70,	0x1D,	0x10,	0x02,	0,	0x66,	0x71,	0x2C,	0x1F,	0x1E,	0x11,	0x03,	0x5B,	/*
57
2*/	0x67,	0x2E,	0x2D,	0x20,	0x12,	0x05,	0x04,	0x5C,	0x68,	0x39,	0x2F,	0x21,	0x14,	0x13,	0x06,	0x5D,	/*
58
3*/	0x69,	0x31,	0x30,	0x23,	0x22,	0x15,	0x07,	0x5E,	0x6A,	0x72,	0x32,	0x24,	0x16,	0x08,	0x09,	0x5F,	/*
59
4*/	0x6B,	0x33,	0x25,	0x17,	0x18,	0x0B,	0x0A,	0x60,	0x6C,	0x34,	0x35,	0x26,	0x27,	0x19,	0x0C,	0x61,	/*
60
5*/	0x6D,	0x73,	0x28,	0x74,	0x1A,	0x0D,	0x62,	0x6E,	0x3A,	0x36,	0x1C,	0x1B,	0x75,	0x2B,	0x63,	0x76,	/*
61
6*/	0,	0x56,	0x77,	0x78,	0x79,	0x7A,	0x0E,	0x7B,	0x7C,	0x4F,	0x7D,	0x4B,	0x47,	0x7E,	0x7F,	0x6F,	/*
62
7*/	0x52,	0x53,	0x50,	0x4C,	0x4D,	0x48,	0x01,	0x45,	0x57,	0x4E,	0x51,	0x4A,	0x37,	0x49,	0x46,	0,	/*
63
8*/	0,	0,	0,	0x41,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	/*
64
9*/	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	/*
65
A*/	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	/*
66
B*/	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	/*
67
C*/	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	/*
68
D*/	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	/*
69
E*/	0xE0,	0xE1
70
};
71
static int break_flag=0; // indicates that next key is up, depressed
72

73
static uint32_t translate_set2_to_set1(uint32_t c) {
74
	if (c==0xF0) {
75
		break_flag=1;
76
		return 0xF0;
77
	}
78
	if (c>sizeof(set2_to_set1_table)/sizeof(uint32_t)) return 0;
79
	c=set2_to_set1_table[c];
80
	if (break_flag) {
81
		break_flag=0;
82
		c|=0x80;
83
	}
84
	return c;
85
}
86
#endif	// TRANSLATE_TO_SET1
87

88
static irq_return_t pl050_keyboard_irq_hnd(unsigned int irq_nr, void *data) {
89
	struct pl050_keyboard_indev *pl050_keyboard_indev;
90
	struct pl050 *pl050;
91
	uint32_t rx_data;
92
	struct input_event event;
93
	struct input_dev *indev;
94

95
	pl050_keyboard_indev = (struct pl050_keyboard_indev *)data;
96
	pl050 = pl050_keyboard_indev->pl050_dev;
97
	indev = &pl050_keyboard_indev->input_dev;
98

99
	rx_data = pl050->data;
100

101
	if (rx_data == KEYBOARD_SCAN_CODE_EXT) {
102
		goto out;
103
	}
104

105
#if (TRANSLATE_TO_SET1 == 1)
106
	rx_data=translate_set2_to_set1(rx_data);
107

108
	if (rx_data == 0xF0) {
109
		goto out;
110
	}
111
#endif	// TRANSLATE_TO_SET1
112

113
	keyboard_scan_code_to_event(rx_data, &event);
114
	input_dev_report_event(indev, &event);
115

116
out:
117
	return IRQ_HANDLED;
118
}
119

120
static int pl050_keyboard_init(void) {
121
	int res;
122

123
	res = irq_attach(IRQ_NUM, pl050_keyboard_irq_hnd, 0,
124
					 &keyboard_dev, "ps keyboard");
125
	if (res < 0) {
126
		return res;
127
	}
128
	keyboard_dev.pl050_dev = (void*)(uintptr_t)BASE_ADDR;
129

130
	pl050_init(keyboard_dev.pl050_dev);
131

132
	return input_dev_register(&keyboard_dev.input_dev);
133
}
134

135
PERIPH_MEMORY_DEFINE(pl050_keyboard, BASE_ADDR, 0x1000);
136

137

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.