1
1
Форкнуть 0

Драйверы devi-[egalax/hid] из состава ЗОСРВ "Нейтрино" редакции 2020

Этот коммит содержится в:
Коммит 4346965cdc
80 изменённых файлов: 4695 добавлений и 0 удалений

3
Makefile Обычный файл
Просмотреть файл

@ -0,0 +1,3 @@
LIST=hardware
EARLY_DIRS=devu
include recurse.mk

318
README.md Обычный файл
Просмотреть файл

@ -0,0 +1,318 @@
## Предостережение
Предоставленный исходный код драйвера [devi-hid](https://help.kpda.ru/help/topic/ru.kpda.doc.os_ru/html/utils/system/devi-hid.html) рекомендуется использовать **только для отладочных целей** при разработке HID-драйверов. Для всех остальных задач следует использовать штатный системный драйвер [devi-hid](https://help.kpda.ru/help/topic/ru.kpda.doc.os_ru/html/utils/system/devi-hid.html). В общем случае **не существует задач**, которые требуется решать в этом драйвере при поддержке нового оборудования (для этого должен быть написан/модифицирован отдельный драйвер ввода или HID-драйвер).
## Общая структура подсистемы ввода
```
┌───────────────────────────┐
│ │
│ Устройство ввода ◂───────────────────────┐
│ │ │
└─────────────▴─────────────┘ │
│ │
┌─────────────┴─────────────┐ │ Не HID-совместимое
│ │ │ устройство
│ HID-драйвер (devh-*) │ │
│ │ │
└─────────────▴─────────────┘ │
│ │
┌─────────────┴─────────────┐ ┌─────────────┴─────────────┐
│ │ │ │
│ HID-менеджер (io-hid) ◂─── * ───┤ Драйвер ввода (devi-*) ◂───▸ /dev/??? (standalone-режим)
│ │ │ │
└───────────────────────────┘ ▲ └─────────────▴─────────────┘
│ │
│ ┌─────────────▾─────────────┐
Интерфейс libhiddi ─────┘ │ │
│ Оконная оболочка Photon │
│ │
└───────────────────────────┘
```
## Дерево исходных кодов
```
|- devi/
| |- egalax/ - Исходный код драйвера поддержки тачскринов egalax, подключаемых по PS/2
| |- hid/ - Исходный код драйвера HID-совместимых устройств (только для отладочных целей)
| |- include/ - Заголовочные файлы библиотек
| |- keymap/ - Библиотека трансляции символов (libkeymap)
| |- lib/ - Библиотека менеджера ресурсов драйвера (libinput)
| |- public/ - Публичные интерфейсы драйвера
| |- Makefile - Правила сборки дерева исходников
| `- common.mk - Параметры сборки драйверов и библиотек
|
`- Makefile - Правила сборки дерева исходников
```
## Сборка драйвера
- Установить и настроить [комплект разработчика](https://help.kpda.ru/help/topic/ru.kpda.doc.dev_tools_ru/html/devkit/devkit.html) для [ЗОСРВ "Нейтрино" редакции 2020](https://help.kpda.ru/help/index.jsp).
- Выполнить команду:
```
make
```
## Запуск драйвера
Общая схема запуска драйвера:
```
devi-* <опции_драйвера> <протокол> <опции протокола> [<устройство> <опции_устройства>] [<фильтр> <опции_фильтра>]
```
Примеры:
```
devi-hirun -b kbd fd -d /dev/kbd ps2 mousedev
└───┬────┘ └───┬───┘ └───┬────┘ └────┬─────┘ └───────┬────────┘ └───┬────┘ └────┬─────┘
│ │ │ │ │ │ │
│ │ │ │ Опции устройства │ │
│ │ │ Устройство │ Устройство
│ │ Протокол Протокол
│ Опции
Драйвер
devi-hid -b touch mouse kbd
└───┬───┘ └───┬───┘ └───────┬───────┘
│ │ │
│ │ Протоколы
│ Опции
Драйвер
```
## События ввода (events)
**Маршрутизация событий:**
```
Hardware → Device → Protocol → Filter → Photon или /dev/???
```
**Виды событий ввода:**
- Относительные - содержат информирмацию об изменении координат на некоторую величину (мышь, touchpad)
- Абсолютные - содержащие координаты в контекста собственного разрешения устройства ввода (touchscreen)
- Клавиатурные - содержат сведения об изменении состояния клавиатуры (состояние клавиш, сканкоды и статусные флаги)
(!) Устройства с абсолютным позиционированием необходимо [калибровать](https://help.kpda.ru/help/topic/ru.kpda.doc.os_ru/html/utils/photon/calib.html) перед использованием. Это позволяет установить соответствие между пространством координат устройства ввода и координатами дисплея.
## Интерфейсы и взаимодействие
Пример чтения ctrl-структуры в клиентском приложении:
```
#include <sys/dcmd_input.h>
...
int main()
{
struct _keyboard_ctrl kbctrl;
int fd = open( "/dev/keyboard0", O_RDWR );
...
/* Инициализация */
...
if ( devctl( fd, _KEYBOARDGETCTRL, &kbctrl, sizeof( kbctrl ), NULL ) != EOK )
{
/* Обработка ошибок */
} else {
/* Структура контроля клавиатуры считана в переменную kbctrl. Можно приступать к ее анализу. */
}
}
```
## Разработка драйвера
**Дескриптор модуля:**
```
struct _input_module
{
/* Module parameters */
input_module_t *up; /* Up module in the bus line */
input_module_t *down; /* Down module in the bus line */
struct Line *line; /* Bus line */
int flags; /* flags */
int type; /* type of module */
char name[12]; /* Module name */
char date[12]; /* Date of compilation */
const char *args; /* Module arguments */
void *data; /* Private module data */
/* Callbacks */
int (*init)( input_module_t *module );
int (*reset)( input_module_t *module );
int (*input)( input_module_t *module, int num, void *data );
int (*output)( input_module_t *module, void *data, int num );
int (*pulse)( message_context_t *ctx, int code, unsigned flags, void *data );
int (*parm)( input_module_t *module, int code, char *optarg );
int (*devctrl)( input_module_t *module, int event, void *data );
int (*shutdown)( input_module_t *module, int delay );
}
```
**Инициализация драйвера:**
- Заполнить структуру дескриптора модуля
- Заполнить структуру `_common_callbacks` (см. ниже):
- Выполнить инициализацию библиотеки `libinput`, вызвав функцию: `devi_init( (struct _common_callbacks *)&ptr );`
- Выполнить всю необходимую инициализацию прочих библиотек и ресурсов
- Передать управление библиотеке `libinput`, вызвав функцию: `begin( (int)argc, (char**)argv );`
Структура `_common_callbacks`:
```
struct _common_callbacks {
int nCallbacks;
int (*pre_init)();
int (*post_init)();
int (*pre_shutdown)();
int (*post_shutdown)();
}
```
Диаграмма последовательности инициализации:
```
┌──────────────────────────┐ ┌──────────────────────┐ ┌──────────────────────────┐
│ Драйвер ввода (devi-*) │ │ Библиотека libinput │ │ Модуль │
└────────────┬─────────────┘ └──────────┬───────────┘ └────────────┬─────────────┘
│ │ │
│ devi_init() │ │
├──────────────────────────▸│ │
│ │ │
│ begin() │ │
├──────────────────────────▸│ │
│ │ │
│ pre_init_callbacks() │ │
│◂──────────────────────────┤ │
│ ├──┐ │
│ │ │ Разбор опций, иницализация │
│ │ │ структур модуля │
│ │◂─┘ │
│ │ │
│ │ init callback │
│ ├───────────────────────────────▸│
│ │ │
│ │ param callback │
│ ├───────────────────────────────▸│
│ │ │
│ │ reset callback │
│ ├───────────────────────────────▸│
│ │ │
│ post_init_callbacks() │ │
│◂──────────────────────────┤ │
│ ├──┐ │
│ │ │ Иницализация интерфейсов │
│ │◂─┘ │
│ ├──┐ │
│ │ │ Иницализация пула потоков │
│ │◂─┘ │
│ ├──┐ │
│ │ │ Запуск менеджера ресурсов │
│ │◂─┘ │
│ │ │
```
**Обработка событий (pulse):**
- Вызывается в ответ на возникновение события
- Обычно реализуется в модулях устройств
- Выполняет сбор данных из устройства
- Возможные способы регистрации обработчика: `devi_register_interrupt()`, `devi_register_pulse()` или `devi_register_timer()`
- Для передачи данных далее по Busline используется функция `module->up->input()`
**Ввод данных (input) – передача данных клиенту:**
- Вызывается в моменты, когда модуль более низкого уровня готов к передаче данных
- Модуль устройства:
- Выполнить сбор данных
- Упаковать их в согласованный с модулем протокола формат
- Передать их на уровень модуля-протокола, используя функцию `module->up->input()`
- Модуль протокола:
- Преобразовать данные в стандартную структуру пакета, соответствующего обслуживаемому устройству (`packet_kbd`, `packet_abs`, `packet_rel`)
- Передать их на уровень модуля-протокола, используя функцию `module->up->input()`
- Модуль фильтра:
- Выполнить необходимую коррекцию принятых данных
- Передать данные на реализуемые интерфейсы, используя функцию `devi_enqueue_packet()`
Диаграмма последовательности ввода данных:
```
┌────────────┐ ┌────────────┐ ┌──────────┐ ┌────────────┐ ┌──────────┐ ┌──────────┐
│ Hardware │ │ libinput │ │ Device │ │ Protocol │ │ Filter │ │ Клиент │
└─────┬──────┘ └──────┬─────┘ └─────┬────┘ └──────┬─────┘ └─────┬────┘ └─────┬────┘
│ │ │ │ │ │
│ │ devi_interrupt_attach() │ │ │ │
│ │◂──────────────────────────┤ │ │ │
│ Прерывание │ │ │ │ │
├───────────────▸│ pulse_callback() │ │ │ │
│ ├──────────────────────────▸│ │ │ │
│ │ │ │ │ │
│ │ read() │ │ │ │
│◂───────────────────────────────────────────┤ │ │ │
│ │ │ │ │ │
│ Данные │ │ input │ │ │
├───────────────────────────────────────────▸│ callback │ input │ │
│ │ ├─────────────▸│ callback │ │
│ │ │ ├─────────────▸│ devi_enqueue_packet() │
│ │ │ │ ├────────────────────────▸│
│ │ │ │ │ │
```
**Управление устройством (devctl):**
- Реализует управление модулем и реакцию на внешние [devctl()](https://help.kpda.ru/help/topic/ru.kpda.doc.os_ru/html/libraries/libc/d/devctl.html) команды
- Собственные [devctl()](https://help.kpda.ru/help/topic/ru.kpda.doc.os_ru/html/libraries/libc/d/devctl.html) команды можно зарегистрировать, используя константы из заголовочного файла `include/const.h`
- Модуль устройства:
- Если тип события известен – выполнить обработку
- Если тип события не известен – вернуть значение `-1` и установить переменную [errno](https://help.kpda.ru/help/topic/ru.kpda.doc.os_ru/html/libraries/libc/e/errno.html) в значение `EINVAL`;
- Модуль протокола:
- Если тип события известен – выполнить обработку
- Если тип события не известен и имеется связанный модуль нижнего уровня – передать событие далее
## Обзор API библиотеки libinput
- Работа с циклическими буферами (см. функции семейства `buff_*()`)
- Системные функции:
- `clk_get()`
- `devi_request_iorange()`
- Передача данных на/от реализуемых интерфейсов:
- `devi_enqueue_packet()`
- Регистрация обработчиков событий (см. `devi_register_*()`)
- Доступ к данным менеджера ресурсов:
- `devi_get_coid()`
- `devi_get_dispatch_handle()` / `devi_set_dispatch_handle()`
- Работа с менеджером [io-hid](https://help.kpda.ru/help/topic/ru.kpda.doc.os_ru/html/services/io-hid.html):
- `devi_hid_init()`
- `devi_hid_register_client()` / `devi_hid_unregister_client()`
- `devi_hid_server_connect()` / `devi_hid_server_disconnect()`
- `devi_scan_to_usb()` / `devi_usb_to_scan()`

3
devi/Makefile Обычный файл
Просмотреть файл

@ -0,0 +1,3 @@
EARLY_DIRS=keymap lib
LIST=DEVI
include recurse.mk

61
devi/common.mk Обычный файл
Просмотреть файл

@ -0,0 +1,61 @@
#
# (c) 2010-2018, SWD Embedded Systems Limited, http://www.kpda.ru
#
ifndef QCONFIG
QCONFIG=qconfig.mk
endif
include $(QCONFIG)
INSTALLDIR=usr/photon/bin
define PINFO
PINFO DESCRIPTION=
endef
USEFILE=$(PROJECT_ROOT)/$(SECTION)/devi-$(SECTION).use
EXTRA_SILENT_VARIANTS = $(subst -, ,$(SECTION))
NAME=$(PROJECT)-$(SECTION)
LIBPREF_ph = -Bstatic
LIBPOST_ph = -Bdynamic
LIBS += input keymap ph gf cache
CCFLAGS += -w0 -D__DATE__=\"$(PINFO_DATE)\" -D__TIME__=\"\"
#PUBLIC_INCVPATH+=$(PROJECT_ROOT)/private $(PROJECT_ROOT)/public
PUBLIC_INCVPATH+=$(PROJECT_ROOT)/public
SERVICES_ROOT=$(PRODUCT_ROOT)/../services
LIB_VARIANT=$(subst dll,o,$(COMPOUND_VARIANT))
# Local modifications of make environment
-include ../../../private.mk
include $(MKFILES_ROOT)/qmacros.mk
include $(PROJECT_ROOT)/$(SECTION)/pinfo.mk
-include $(PROJECT_ROOT)/roots.mk
ifndef DEVILIB_ROOT
DEVILIB_ROOT=$(PROJECT_ROOT)/lib
endif
ifndef KEYMAP_ROOT
KEYMAP_ROOT=$(PROJECT_ROOT)/keymap
endif
EXTRA_INCVPATH+=$(PROJECT_ROOT)/private/sys $(PROJECT_ROOT)/private
EXTRA_INCVPATH+=$(PROJECT_ROOT)/public/sys
EXTRA_LIBVPATH+=$(SERVICES_ROOT)/usb/usbdi/$(subst x86/so.,x86/so,$(CPU)/so.$(filter le be,$(subst ., ,$(VARIANTS))))
EXTRA_LIBVPATH+=$(SERVICES_ROOT)/hid/hiddi/$(subst x86/so.,x86/so,$(CPU)/so.$(filter le be,$(subst ., ,$(VARIANTS))))
EXTRA_INCVPATH+=$(PROJECT_ROOT)/include $(PROJECT_ROOT)/../../lib/ph
EXTRA_LIBVPATH+=$(DEVILIB_ROOT)/$(OS)/$(CPU)/a.$(COMPOUND_VARIANT) $(KEYMAP_ROOT)/$(OS)/$(CPU)/a.$(COMPOUND_VARIANT)
EXTRA_LIBVPATH+=$(DEVILIB_ROOT)/$(OS)/$(CPU)/a.$(COMPOUND_VARIANT).shared $(KEYMAP_ROOT)/$(OS)/$(CPU)/a.$(COMPOUND_VARIANT).shared
include $(MKFILES_ROOT)/qtargets.mk
infoinfo:
echo $(VARIANT1) $(COMPOUND_VARIANT)

2
devi/egalax/Makefile Обычный файл
Просмотреть файл

@ -0,0 +1,2 @@
LIST=OS
include recurse.mk

46
devi/egalax/devi-egalax.use Обычный файл
Просмотреть файл

@ -0,0 +1,46 @@
%C [general_opts] protocol* [protocol_opts]*
%C : EETI eGalaxTouch (PS/2) Input Manager for Photon
ATTENTION! Manager is incompatible with any ps2 hid modules
General opts:
-P disable photon interface (default start Photon interface)
-r start resource manager interface (only use if not using Photon)
-b prevent CASB exit (default allow CASB)
-G presence of grafx driver is not required when
starting up a touchscreen driver; useful in debug mode
-g input group (default 1)
-v increment verbosity (default 0)
-l list List the internal modules. Modules are listed in
the following format:
module name | date last compiled | revision | class
where: class is comprised of (D)evice and/or
(P)rotocol and/or (F)ilter
Protocol and protocol_opts:
egalaxtouch [egalaxtouch_opts] [uart uart_opts]
protocol modules and their options:
egalax Elographics smartset protocol
-R Don't reset device (default reset device)
filter modules and their options:
abs Transform and compresses absolute coordinate "touch" events
-b Touching the screen is a right mouse button (default left)
-c Calibrate mode - don't transform coordinates
-f filename Calibration file name
-o x,y Origin of display region (default, origin of graphics region)
-s x,y Coordinates of lower right corner of display region
(default, width and height of graphics region)
-x Reverse X
-y Reverse Y
Examples
--------
%C egalax

495
devi/egalax/egalax.c Обычный файл
Просмотреть файл

@ -0,0 +1,495 @@
/*
* (c) 2016, SWD Embedded Systems Limited, http://www.kpda.ru
*/
/*
* smarttest.c
*
* Elographics touch screen protocol.
*
*/
#include "devi.h"
#include <time.h>
#include <pthread.h>
#define TRUE 1
#define FALSE !TRUE
#define DEBOUNCE 80000L
#define TRY_LIMIT (100000)
#define TIME_DELAY (10000)
#define IN_BUFF_FULL (0x2)
#define OUT_BUFF_FULL (0x1)
#define AUX_IRQ 12 /* default aux irq */
#define PS2_DATA_PORT 0x60
#define PS2_STATUS_REGISTER 0x64
#define PS2_COMMAND_REGISTER 0x64
#define PS2_TEST_CONTROLLER 0xAA
#define PS2_SELFTEST_SUCCESS 0x55
#define PS2_READ_CONFBYTE 0x20
#define PS2_WRITE_CONFBYTE 0x60
#define PS2_AUX_TEST 0xA9
#define PS2_AUX_WRITE 0xD4
#define AUX_DISABLE 0xA7 /* disable the aux device */
#define AUX_ENABLE 0xA8 /* enable the aux device */
#define AUX_ENABLE_XFER 0xf4 /* enable stream mode transfer */
#define AUX_DISABLE_XFER 0xf5 /* disable stream mode transfer */
#define AUX_RESET 0xFF /* RESET mouse */
#define AUX_COMPLETE 0xaa /* Mouse complete */
#define AUX_GET_STATUS 0xe9 /* get mouse state */
#define AUX_DEV_ID 0xf2 /* get device ID */
#define AUX_STREAM_MODE 0xea /* Set stream mode */
// Mouse replies
#define RESEND (0xfe) /* resend */
#define ACK (0xfa)
#define NUM_OF_RETRIES (5)
#define TRY_LIMIT (100000)
#define TIME_DELAY (10000)
#define IN_BUFF_FULL (0x2)
#define OUT_BUFF_FULL (0x1)
#define DATA_PACKAGE_SIZE (5)
#define FLAG_INIT 0x1000
#define FLAG_RESET 0x2000
struct data {
int flags;
struct sigevent event;
struct packet_abs tp;
int state; /* current state (see smart_input for details) */
};
extern struct sigevent event;
static int egalax_init(input_module_t *module);
static int egalax_devctrl(input_module_t *module,int event,void *ptr);
static int egalax_reset(input_module_t *module);
static int egalax_input(input_module_t *module, int num, void *ptr);
static int egalax_parm(input_module_t *module,int opt,char *optarg);
static int egalax_shutdown(input_module_t *module, int delay);
static int egalax_pulse(message_context_t *ctp, int code, unsigned flags, void *data);
void* inter_wait_cycle( input_module_t *module );
int ps2_init( void );
int aux_reset( void );
input_module_t egalax = {
NULL,
NULL,
NULL,
0,
DEVI_CLASS_ABS | DEVI_MODULE_TYPE_DEVICE | DEVI_MODULE_TYPE_PROTO,
"egalax",
__DATE__,
"R",
NULL, // data
egalax_init,
egalax_reset,
egalax_input,
NULL,
NULL, //egalax_pulse,
egalax_parm,
egalax_devctrl,
egalax_shutdown,
};
/* Description: callback initialisation function; it is called when input module */
/* initializes input system */
/* Input : input_module_t * module - pointer to module descriptor */
/* Output : None */
/* Return : 0 if OK, otherwise - (-1) */
int egalax_init(input_module_t *module)
{
struct data *dp = module->data;
ThreadCtl( _NTO_TCTL_IO, 0 );
if( !module->data ) {
if( !(dp = module->data = calloc(sizeof *dp, 1)) ) {
return (-1);
}
SIGEV_INTR_INIT( &(dp->event) );
dp->flags = ABSOLUTE | ABS_UNCALIBRATED | FLAG_RESET;
dp->state = 0;
}
ps2_init();
return (0);
}
void* inter_wait_cycle( input_module_t *module )
{
int id;
struct data *dp = module->data;
id = InterruptAttachEvent( AUX_IRQ, &dp->event, _NTO_INTR_FLAGS_END );
if ( id == -1 ) {
fprintf(stderr, "Mouse interrupt attach failed\n" );
exit ( -1 );
}
uint8_t data[DATA_PACKAGE_SIZE];
int count = 0;
for (;;)
{
InterruptWait( 0, NULL );
data[count++] = in8( PS2_DATA_PORT );
InterruptUnmask( AUX_IRQ, id );
if ( count == DATA_PACKAGE_SIZE ) {
(module->input)( module, DATA_PACKAGE_SIZE, data );
count = 0;
}
}
return NULL;
}
int egalax_devctrl(input_module_t *module, int event, void *ptr)
{
struct data *dp = module->data;
input_module_t *down = module->down;
switch(event) {
case DEVCTL_GETDEVFLAGS:
*(unsigned short *)ptr = (dp->flags & FLAGS_GLOBAL);
break;
case DEVCTL_GETPTRBTNS:
*(unsigned long *)ptr = 1L;
break;
case DEVCTL_GETPTRCOORD:
*(unsigned char *)ptr = '\02';
break;
case DEVCTL_GETPTRPRESS:
*(unsigned char *)ptr = (dp->flags & ABS_PRESS_DATA)?1:0;
break;
case DEVCTL_GETCOORDRNG: {
struct devctl_coord_range *range = ptr;
// TODO: look for coord range
range->min = 0;
range->max = 4095;
break;
}
case DEVCTL_GETPRESSRNG: {
// for all smartset devices at present the range is 0-255
struct devctl_coord_range *range = ptr;
range->min = 0;
range->max = 255;
break;
}
default:
return (-1);
}
return (0);
}
/* Description: this callback funtion is called when the module is linked into the */
/* event bus;it is used to set initial module state on the protocol */
/* level */
/* Input : input_module_t * module - pointer to module descriptor */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
int egalax_reset(input_module_t * module)
{
struct data *dp = module->data;
input_module_t *down = module->down;
if((dp->flags & FLAG_INIT) == 0) { // if not initialized
pthread_attr_t attr;
aux_reset();
pthread_attr_init( &attr );
if ( pthread_create( NULL, &attr, &inter_wait_cycle, module ) != EOK ) {
fprintf(stderr, "Unable to create interrupt handler thread\n" );
exit ( -1 );
}
dp->flags |= FLAG_INIT;
}
// if (dp->flags & FLAG_RESET)
// aux_reset();
dp->state = 0;
return 0;
}
/* Description: main protocol processing function. It will be called by the */
/* device layer to pass it data to process. Its job is to interpret */
/* the data according to the Elographics touch screen protocol, create */
/* a data structure, fill it in and hand it off to the filter layer */
/* module above it. The protocol is processed using simple state */
/* machine. State info is kept in module's private data */
/* Input : input_module_t * module - pointer to module descriptor */
/* int num - number of bytes to process */
/* void * arg - raw data to process */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
int egalax_input( input_module_t *module, int num, void *ptr )
{
int i, enqueue = 0;
uint8_t *p = (uint8_t *)ptr;
struct data *dp = module->data;
input_module_t *up = module->up;
if(verbosity >= 5)
{
fprintf( stderr, "Received : ");
for(i = 0; i < num; ++i)
fprintf( stderr, "%#x ", (int)*((_uint8 *)ptr + i));
fprintf( stderr, "\n");
}
if( p[0] & 0x01 ) dp->tp.buttons = 4L;
if( (p[0] & 0x01) == 0 ) dp->tp.buttons = 0;
dp->tp.y = ( (p[1] & 0x7f) << 7) | (p[2] & 0x7f);
dp->tp.x = ( (p[3] & 0x7f) << 7) | (p[4] & 0x7f);
dp->state = 0;
dp->tp.flags = dp->flags;
clk_get(&dp->tp.timestamp);
int ret = (up->input)(up, 1, &dp->tp); // send data upwards
if(verbosity >= 5)
fprintf( stderr, "Translated: x = %d, y = %d; ret = %d (%s)\n", dp->tp.x, dp->tp.y, ret, up->name );
return (0);
}
/* Description: this is a callback function for command line parameter processing */
/* (all valid parameters for device module are listed in smartset.args)*/
/* Input : input_module_t * module - pointer to module descriptor */
/* int opt - parameter code */
/* char * optarg - optional parameter value */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
int egalax_parm(input_module_t *module, int opt, char *optarg)
{
struct data *dp = module->data;
if(verbosity >= 5)
fprintf(stderr, "(%s): params\n", module->name);
switch (opt) {
case 'R':
dp->flags &= ~FLAG_RESET;
break;
default:
return (-1);
}
return (0);
}
/* Description: this is a callback function which is called when resourse manager */
/* is shutting down */
/* Input : input_module_t * module - pointer to module descriptor */
/* int delay - program doesn't use this parameter */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
/* Comment : Does nothing for the protocol level */
int egalax_shutdown(input_module_t *module, int delay)
{
return (0);
}
int drain_input_buffer()
{
int nTries;
for (nTries = TRY_LIMIT; nTries && ( in8( PS2_STATUS_REGISTER ) & IN_BUFF_FULL); nTries--) {
nanospin_ns( TIME_DELAY );
}
return (nTries == 0);
}
int drain_output_buffer()
{
int nTries;
for (nTries = TRY_LIMIT; nTries && ( in8( PS2_STATUS_REGISTER ) & OUT_BUFF_FULL ); nTries--) {
nanospin_ns( TIME_DELAY );
in8( PS2_DATA_PORT );
}
return (nTries == 0);
}
int ps2_wait_reply()
{
int nTries;
uint8_t status;
int ret = -1;
// Poll bit 0 (0x01 mask) of the Status Register ("Input buffer empty/full")
// until it becomes full, or until your time-out expires
for ( nTries = TRY_LIMIT; nTries; nTries-- )
{
status = in8 ( PS2_STATUS_REGISTER );
if ( (status & OUT_BUFF_FULL) ) {
ret = in8( PS2_DATA_PORT );
break;
}
nanospin_ns( TIME_DELAY );
}
return ret;
}
int ps2_send_command( uint8_t cmd, int n, uint8_t *reply )
{
int i;
drain_output_buffer();
drain_input_buffer();
out8( PS2_COMMAND_REGISTER, cmd );
for ( i = 0; i < n; ++i )
reply[i] = ps2_wait_reply();
return i;
}
int ps2_send_data( uint8_t data, int n, uint8_t *reply )
{
int nTries, i;
uint8_t status;
int ret = -1;
for ( nTries = TRY_LIMIT; nTries; --nTries )
{
status = in8 ( PS2_STATUS_REGISTER );
if ( ( status & IN_BUFF_FULL ) == 0 ) { // Input buffer status (0 = empty, 1 = full)
out8( PS2_DATA_PORT, data );
break;
}
nanospin_ns( TIME_DELAY );
}
if ( nTries == 0 )
return -1;
for ( i = 0; i < n; ++i )
reply[i] = ps2_wait_reply();
return i;
}
int ps2_init( void )
{
uint8_t reply[1];
int ret = 0;
//aux_send_command( AUX_DISABLE_1PORT, 0, NULL );
ps2_send_command( AUX_DISABLE, 0, NULL );
ps2_send_command( PS2_TEST_CONTROLLER, 1, reply );
if ( reply[0] != PS2_SELFTEST_SUCCESS ) {
fprintf( stderr, "PS2 controller selftest failed (0x%x)\n", reply[0] );
ret = -1;
}
ps2_send_command( PS2_AUX_TEST, 1, reply );
if ( reply[0] != 0 ) {
fprintf( stderr, "PS2 second port test failed (0x%x)\n", reply[0] );
ret = -1;
}
ps2_send_command( PS2_READ_CONFBYTE, 1, reply );
reply[0] |= 0x3; // Enable interrupts (two first bits)
ps2_send_command( PS2_WRITE_CONFBYTE, 0, NULL );
ps2_send_data( reply[0], 0, NULL );
// Enable device - we are interested only in mouse
ps2_send_command( AUX_ENABLE, 0, NULL );
return ret;
}
int aux_reset( void )
{
uint8_t egalax_diag[] = { 0x0A, 1, 'A' };
uint8_t reply[4];
int ret = 0, i;
reply[0] = 0;
ps2_send_command( PS2_AUX_WRITE, 0, NULL );
if ( ps2_send_data( AUX_RESET, 1, reply ) == -1 || reply[0] != ACK ) {
fprintf( stderr, "Error while reseting aux device\n" );
ret = -1;
}
reply[0] = 0;
ps2_send_command( PS2_AUX_WRITE, 0, NULL );
ps2_send_data( AUX_STREAM_MODE, 1, reply );
if ( reply[0] != ACK )
fprintf( stderr, "Error transmitting data to aux device\n" );
reply[0] = 0;
ps2_send_command( PS2_AUX_WRITE, 0, NULL );
ps2_send_data( egalax_diag[0], 1, reply );
if ( reply[0] != ACK )
fprintf( stderr, "Error transmitting data to aux device\n" );
reply[0] = 0;
ps2_send_command( PS2_AUX_WRITE, 0, NULL );
ps2_send_data( egalax_diag[1], 1, reply );
if ( reply[0] != ACK )
fprintf( stderr, "Error transmitting data to aux device\n" );
reply[0] = 0;
ps2_send_command( PS2_AUX_WRITE, 0, NULL );
ps2_send_data( egalax_diag[2], 4, reply );
if ( reply[0] != ACK )
fprintf( stderr, "Error transmitting data to aux device\n" );
for ( i = 1; i <= 3; ++i )
if ( reply[i] != egalax_diag[i-1] )
break;
if ( i != 4 ) {
fprintf( stderr, "Error transmitting egalax diag\n" );
ret = -1;
}
reply[0] = 0;
ps2_send_command( PS2_AUX_WRITE, 0, NULL );
ps2_send_data( AUX_ENABLE_XFER, 1, reply );
if ( reply[0] != ACK )
fprintf( stderr, "Error transmitting data to aux device\n" );
/* ps2_send_command( PS2_AUX_WRITE, 0, NULL );
ps2_send_data( 0xE9, 4, reply );
if ( reply[0] == ACK )
fprintf( stderr, "status = %#x,%#x,%#x\n", reply[1], reply[2], reply[3] );*/
return ret;
}

17
devi/egalax/main.c Обычный файл
Просмотреть файл

@ -0,0 +1,17 @@
/*
* (c) 2016, SWD Embedded Systems Limited, http://www.kpda.ru
*/
#include "devi.h"
extern input_module_t egalax;
input_module_t *modules[] = {
&egalax,
NULL
};
int main(int argc, char *argv[])
{
return begin(argc, argv);
}

2
devi/egalax/nto/Makefile Обычный файл
Просмотреть файл

@ -0,0 +1,2 @@
LIST=CPU
include recurse.mk

2
devi/egalax/nto/x86/Makefile Обычный файл
Просмотреть файл

@ -0,0 +1,2 @@
LIST=VARIANT
include recurse.mk

1
devi/egalax/nto/x86/o/Makefile Обычный файл
Просмотреть файл

@ -0,0 +1 @@
include ../../../../common.mk

7
devi/egalax/pinfo.mk Обычный файл
Просмотреть файл

@ -0,0 +1,7 @@
#
# (c) 2016, SWD Embedded Systems Limited, http://www.kpda.ru
#
define PINFO
PINFO DESCRIPTION=Elographics input manager for Photon
endef

9
devi/egalax/private.mk Обычный файл
Просмотреть файл

@ -0,0 +1,9 @@
#
# (c) 2016, SWD Embedded Systems Limited, http://www.kpda.ru
#
EXTRA_LIBVPATH+=$(PROJECT_ROOT)/lib/$(OS)/$(CPU)/a.$(LIB_VARIANT).shared $(PROJECT_ROOT)/keymap/$(OS)/$(CPU)/a.$(LIB_VARIANT).shared
LIBS=inputS keymapS ph gf
CCFLAGS += $(CCFLAGS_$(TYPE))
EXTRA_DEPS=$(PROJECT_ROOT)/lib/$(OS)/$(CPU)/a.$(LIB_VARIANT).shared/libinputS.a $(PROJECT_ROOT)/keymap/$(OS)/$(CPU)/a.$(LIB_VARIANT).shared/libkeymapS.a

2
devi/hid/Makefile Обычный файл
Просмотреть файл

@ -0,0 +1,2 @@
LIST=OS
include recurse.mk

253
devi/hid/control.c Обычный файл
Просмотреть файл

@ -0,0 +1,253 @@
/*
* (c) 2010, SWD Embedded Systems Limited, http://www.kpda.ru
*/
/*
* Предостережение:
*
* Предоставленный исходный код драйвера devi-hid рекомендуется использовать
* только для отладочных целей при разработке HID-драйверов. Для всех остальных
* задач следует использовать штатный системный драйвер devi-hid.
*
* В общем случае не существует задач, которые требуется решать в этом драйвере
* при поддержке нового оборудования (для этого должен быть написан/модифицирован
* отдельный драйвер ввода или HID-драйвер).
*/
/*
* control.c
*
* The HID USB control combined device/protocol module.
*
*/
#include <sys/devi.h>
#include "hid.h"
#include <assert.h>
#define FLAG_INIT 0x0100
#define FLAG_RESET 0x0200
#define FLAG_KIOSK_MODE 0x0400
#define controlED 1
#define RELEASED 0
/* Protocol module private data */
struct private_data {
int flags; /* see valid values before */
int nDev; /* USB device number */
int state;
void * hid_module_handle; /* HID module_handle */
};
/* forward declarations */
static int control_init(input_module_t *module);
static int control_devctrl(input_module_t *module, int event, void *ptr);
static int control_reset(input_module_t *module);
static int control_input(input_module_t *module, int num, void *arg);
static int control_parm(input_module_t *module, int opt, char *optarg);
static int control_shutdown(input_module_t *module, int delay);
/* Our protocol module is represented by the following input_module_t data structure */
input_module_t control = {
NULL,
NULL,
NULL,
0,
DEVI_CLASS_CONTROL | DEVI_MODULE_TYPE_PROTO | DEVI_MODULE_TYPE_DEVICE,
"control",
__DATE__,
"Ku:",
NULL,
control_init,
control_reset,
control_input,
NULL,
NULL,
control_parm,
control_devctrl,
control_shutdown
};
/* Description: callback initialisation function; it is called when input module is */
/* initialising the input system */
/* Input : input_module_t * module - pointer to module descriptor */
/* Output : None */
/* Return : 0 if OK, otherwise - (-1) */
int control_init(input_module_t *module)
{
struct private_data *dp = module->data;
if(!module->data)
{
if(!(dp = module->data = _scalloc(sizeof *dp)))
{
return (-1);
}
}
dp -> nDev = HIDD_CONNECT_WILDCARD;
dp->state = RELEASED;
return (0);
}
/* Description: this is a callback function for DEVCTRL command processing */
/* Input : input_module_t * module - pointer to module descriptor */
/* int event - DEVCTRL command code */
/* void * ptr - pointer to data exchange block */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
int control_devctrl(input_module_t *module, int event, void *ptr)
{
struct private_data *dp = module->data;
int rc = 0;
switch(event)
{
case DEVCTL_GETDEVFLAGS:
*(unsigned short *)ptr = (dp->flags & FLAGS_GLOBAL);
break;
case DEVCTL_GETPTRBTNS:
*(unsigned long *)ptr = 5L;
break;
case DEVCTL_GETPTRCOORD:
*(unsigned char *)ptr='\02';
break;
default:
rc = devi_hid_devctrl(dp -> hid_module_handle, event, ptr, HIDD_CONNECT_WILDCARD );
break;
}
return (rc);
}
/* Description: this callback funtion is called when the module is linked into the */
/* event bus;it is used to set initial module state on the protocol */
/* level */
/* Input : input_module_t * module - pointer to module descriptor */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
int control_reset(input_module_t *module)
{
struct private_data *dp = module->data;
if(!(dp->flags & FLAG_INIT))
{
if(NULL == (dp -> hid_module_handle = devi_hid_register_client(module, dp -> nDev)))
return (-1);
}
dp->flags |= FLAG_INIT;
return (0);
}
/* Description: main protocol processing function. It will be called by the */
/* device layer to pass it data to process. Its job is to interpret */
/* the data according to the MS wheel control protocol, create a */
/* data structure, fill it in and hand it off to the filter layer */
/* module above it. The protocol is processed using simple state */
/* machine. State info is kept in module's private data */
/* Input : input_module_t * module - pointer to module descriptor */
/* int num - number of bytes to process */
/* void * arg - raw data to process */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
/* Comment : driver uses one of two input modules depending on device data */
/* protocol */
int control_input(input_module_t *module, int num, void *arg)
{
pControl_raw_data_t control_raw_data = (pControl_raw_data_t)arg;
struct packet_control mp;
struct private_data *dp = module->data;
input_module_t *up = module->up;
assert(num == sizeof(control_raw_data_t)); // Desynchronized exchange format
if(dp->flags & FLAG_INIT)
{
mp.Rx = control_raw_data->Rx;
mp.Ry = control_raw_data->Ry;
mp.Rz = control_raw_data->Rz;
mp.button_state = control_raw_data->button_state;
}
if (verbosity > 1)
fprintf (stderr, "Device Module Level: Rx:%d, Ry:%d, Rz:%d, Buttons %x\n", mp.Rx, mp.Ry, mp.Rz, mp.button_state);
(up->input)(up, 1, &mp);
return (0);
}
/* Description: this is a callback function for command line parameter processing */
/* (all valid parameters for device module are listed in control.args) */
/* Input : input_module_t * module - pointer to module descriptor */
/* int opt - parameter code */
/* char * optarg - optional parameter value */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
/* Comment : we don't accept any parameter for this module at the protocol level */
int control_parm(input_module_t *module, int opt, char *optarg)
{
/* Now empty */
struct private_data *dp = module->data;
switch (opt)
{
case 'u':
{
if(NULL != optarg)
dp->nDev = atoi(optarg);
break;
}
case 'K':
{
dp->flags |= FLAG_KIOSK_MODE;
break;
}
default:
break;
}
return (0);
}
/* Description: this is a callback function which is called when resourse manager */
/* is shutting down */
/* Input : input_module_t * module - pointer to module descriptor */
/* int ms - program doesn't use this parameter */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
/* Comment : Does nothing for the protocol level */
int control_shutdown(input_module_t *module, int delay)
{
struct private_data *dp = module->data;
if( (NULL != dp) && (NULL != dp -> hid_module_handle))
devi_unregister_hid_client(dp -> hid_module_handle);
return (0);
}

104
devi/hid/devi-hid.use Обычный файл
Просмотреть файл

@ -0,0 +1,104 @@
%C [general_opts] protocol* [protocol_opts]* filter* [filter_opts]*
%C : HID input manager
This driver doesn't care about physical interfaces of real devices.
It just relies on io-hid resource manager and supplementary input
modules service.
(!!!) Do not use this source code to modify default devi-hid driver.
General opts:
-b prevent CASB exit (default allow CASB)
-d photon device (default /dev/photon | PHOTON env var)
-g input group (default 1)
-l list List the internal modules. Modules are listed in
the following format:
module name | date last compiled | revision | class
where: class is comprised of (P)rotocol and/or (F)ilter
-P disable photon interface (default start Photon interface)
-r start resource manager interface (only use if not using Photon)
-v increment verbosity (default 0)
protocol modules and their options:
kbd HID compliant keyboard
-k rate[,delay] Keyboard rate(Hz)/delay(ms) (default 150Hz, 500ms)
-u device optional: USB device number
mouse HID compliant mouse
touch HID compliant touch screen
-K Kiosk Mode (cursor does not drag).
-m size Touchscreen Matrix size (default 1023). This is used for
calculated transformation points.
-u device optional: USB device number
filter modules and their options:
keyboard Translate scan codes to UNICODE
-k kbd_file File to use for keyboard mapping
-L [N][C][S]
Set the initial state of the keyboard and its LEDs (default all off):
- C turn CapsLock on.
- N turn NumLock on.
- S turn ScrollLock on.
rel Filters and compresses relative coordinate "mouse" events
-a wheel acceleration parameter (default 10); the more this
value, the more mouse wheel acceleration effect
-G gain Motion multiplier (default 1)
-l Swap right and left buttons around
-T threshold Speed doubling threshold in mickeys (100)
-x Reverse X
-y Reverse Y
abs Transform and compresses absolute coordinate "touch" events
-a {3/4} Transformation algorithm, available algorithms 3 point and
4 point (default 3 point).
-b Touching the screen is a right mouse button (default left)
-c Calibrate mode - don't transform coordinates
-f filename Calibration file name
(default /etc/system/config/calib.{hostname}).
Note: If You want use vmware mouse, your calibration file need
has size 0
-o x,y Origin of display region (default, origin of graphics region)
-s x,y Coordinates of lower right corner of display region
(default, width and height of graphics region)
-x Reverse X
-y Reverse Y
-D pixels Differential filter that will filter out packets that are
within a number of pixels of the last touch. This prevents
sending repeat coordinates.
-N pixels Noise filter that will filter out packets that are outside
the max number of pixels. This filters out jittery events
from some touchscreens.
-S ms Soft Button release, emulates a release event after X ms of
inactivity from the touch controller. This is helpful for
screens that are not very sensitive, so every event received
before X number of ms expire is treated as a pen down event.
-O origin Touch screen origin (0,0). This is used for the calibration
free transformation. If no calibration file is specified
the driver will attempt to calculate the X,Y position based
on screen resolution and touch screen matrix size (if known).
Possible values are:
Upper Left = 0
Lower Left = 1
Lower Right = 2
Upper Right = 3
Example:
-------
%C kbd mouse
Start the HID driver with a keyboard and mouse
%C kbd touch abs -a4
Start the HID driver keyboard and touchscreen and tell the touchscreen to use the
older, four point calibration algorithm.

257
devi/hid/joystick.c Обычный файл
Просмотреть файл

@ -0,0 +1,257 @@
/*
* (c) 2010, SWD Embedded Systems Limited, http://www.kpda.ru
*/
/*
* Предостережение:
*
* Предоставленный исходный код драйвера devi-hid рекомендуется использовать
* только для отладочных целей при разработке HID-драйверов. Для всех остальных
* задач следует использовать штатный системный драйвер devi-hid.
*
* В общем случае не существует задач, которые требуется решать в этом драйвере
* при поддержке нового оборудования (для этого должен быть написан/модифицирован
* отдельный драйвер ввода или HID-драйвер).
*/
/*
* joystick.c
*
* The HID USB joystick combined device/protocol module.
*
*/
#include <sys/devi.h>
#include "hid.h"
#include <assert.h>
#define FLAG_INIT 0x0100
#define FLAG_RESET 0x0200
#define FLAG_KIOSK_MODE 0x0400
#define joystickED 1
#define RELEASED 0
/* Protocol module private data */
struct private_data {
int flags; /* see valid values before */
int nDev; /* USB device number */
int state;
void * hid_module_handle; /* HID module_handle */
};
/* forward declarations */
static int joystick_init(input_module_t *module);
static int joystick_devctrl(input_module_t *module, int event, void *ptr);
static int joystick_reset(input_module_t *module);
static int joystick_input(input_module_t *module, int num, void *arg);
static int joystick_parm(input_module_t *module, int opt, char *optarg);
static int joystick_shutdown(input_module_t *module, int delay);
/* Our protocol module is represented by the following input_module_t data structure */
input_module_t joystick = {
NULL,
NULL,
NULL,
0,
DEVI_CLASS_JOYSTICK | DEVI_MODULE_TYPE_PROTO | DEVI_MODULE_TYPE_DEVICE,
"joystick",
__DATE__,
"u:",
NULL,
joystick_init,
joystick_reset,
joystick_input,
NULL,
NULL,
joystick_parm,
joystick_devctrl,
joystick_shutdown
};
/* Description: callback initialisation function; it is called when input module is */
/* initialising the input system */
/* Input : input_module_t * module - pointer to module descriptor */
/* Output : None */
/* Return : 0 if OK, otherwise - (-1) */
int joystick_init(input_module_t *module)
{
struct private_data *dp = module->data;
if(!module->data)
{
if(!(dp = module->data = _scalloc(sizeof *dp)))
{
return (-1);
}
}
dp -> nDev = HIDD_CONNECT_WILDCARD;
dp->state = RELEASED;
return (0);
}
/* Description: this is a callback function for DEVCTRL command processing */
/* Input : input_module_t * module - pointer to module descriptor */
/* int event - DEVCTRL command code */
/* void * ptr - pointer to data exchange block */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
int joystick_devctrl(input_module_t *module, int event, void *ptr)
{
struct private_data *dp = module->data;
int rc = 0;
switch(event)
{
case DEVCTL_GETDEVFLAGS:
*(unsigned short *)ptr = (dp->flags & FLAGS_GLOBAL);
break;
case DEVCTL_GETPTRBTNS:
*(unsigned long *)ptr = 5L;
break;
case DEVCTL_GETPTRCOORD:
*(unsigned char *)ptr='\02';
break;
default:
rc = devi_hid_devctrl(dp -> hid_module_handle, event, ptr, HIDD_CONNECT_WILDCARD );
break;
}
return (rc);
}
/* Description: this callback funtion is called when the module is linked into the */
/* event bus;it is used to set initial module state on the protocol */
/* level */
/* Input : input_module_t * module - pointer to module descriptor */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
int joystick_reset(input_module_t *module)
{
struct private_data *dp = module->data;
if(!(dp->flags & FLAG_INIT))
{
if(NULL == (dp -> hid_module_handle = devi_hid_register_client(module, dp -> nDev)))
return (-1);
}
dp->flags |= FLAG_INIT;
return (0);
}
/* Description: main protocol processing function. It will be called by the */
/* device layer to pass it data to process. Its job is to interpret */
/* the data according to the MS wheel joystick protocol, create a */
/* data structure, fill it in and hand it off to the filter layer */
/* module above it. The protocol is processed using simple state */
/* machine. State info is kept in module's private data */
/* Input : input_module_t * module - pointer to module descriptor */
/* int num - number of bytes to process */
/* void * arg - raw data to process */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
/* Comment : driver uses one of two input modules depending on device data */
/* protocol */
int joystick_input(input_module_t *module, int num, void *arg)
{
pJoystick_raw_data_t pjoystickRawData = (pJoystick_raw_data_t)arg;
struct packet_joystick jp;
struct private_data *dp = module->data;
input_module_t *up = module->up;
assert(num == sizeof(joystick_raw_data_t)); // Desynchronized exchange format
if(dp->flags & FLAG_INIT)
{
jp.x = pjoystickRawData->x;
jp.y = pjoystickRawData->y;
jp.z = pjoystickRawData->z;
jp.Rx = pjoystickRawData->Rx;
jp.Ry = pjoystickRawData->Ry;
jp.Rz = pjoystickRawData->Rz;
jp.slider = pjoystickRawData->slider;
jp.hat_switch = pjoystickRawData->hat_switch;
jp.button_state = pjoystickRawData->button_state;
}
if (verbosity > 1)
fprintf (stderr, "Device Level: x:%d, y:%d, z:%d, Buttons:%x, Rx:%d, Ry:%d, Rz:%d, Slider:%d, Hat Switch:%d\n",
jp.x, jp.y, jp.z, jp.button_state, jp.Rx, jp.Ry, jp.Rz, jp.slider, jp.hat_switch);
(up->input)(up, 1, &jp);
return (0);
}
/* Description: this is a callback function for command line parameter processing */
/* (all valid parameters for device module are listed in joystick.args) */
/* Input : input_module_t * module - pointer to module descriptor */
/* int opt - parameter code */
/* char * optarg - optional parameter value */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
/* Comment : we don't accept any parameter for this module at the protocol level */
int joystick_parm(input_module_t *module, int opt, char *optarg)
{
/* Now empty */
struct private_data *dp = module->data;
switch (opt)
{
case 'u':
{
if(NULL != optarg)
dp->nDev = atoi(optarg);
break;
}
default:
break;
}
return (0);
}
/* Description: this is a callback function which is called when resourse manager */
/* is shutting down */
/* Input : input_module_t * module - pointer to module descriptor */
/* int ms - program doesn't use this parameter */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
/* Comment : Does nothing for the protocol level */
int joystick_shutdown(input_module_t *module, int delay)
{
struct private_data *dp = module->data;
if( (NULL != dp) && (NULL != dp -> hid_module_handle))
devi_unregister_hid_client(dp -> hid_module_handle);
return (0);
}

332
devi/hid/kbd.c Обычный файл
Просмотреть файл

@ -0,0 +1,332 @@
/*
* (c) 2010, SWD Embedded Systems Limited, http://www.kpda.ru
*/
/*
* Предостережение:
*
* Предоставленный исходный код драйвера devi-hid рекомендуется использовать
* только для отладочных целей при разработке HID-драйверов. Для всех остальных
* задач следует использовать штатный системный драйвер devi-hid.
*
* В общем случае не существует задач, которые требуется решать в этом драйвере
* при поддержке нового оборудования (для этого должен быть написан/модифицирован
* отдельный драйвер ввода или HID-драйвер).
*/
/*
* kbd.c
*
* The HID USB keyboard combined protocol/device module.
*
*/
#include <sys/devi.h>
#include "hid.h"
#include "pthread.h"
/* forward declarations */
static int kbd_init(input_module_t *module);
static int kbd_devctrl(input_module_t *module, int event, void *ptr);
static int kbd_reset(input_module_t *module);
static int kbd_input(input_module_t *module, int num, void *arg);
static int kbd_parm(input_module_t *module, int opt, char *optarg);
static int kbd_shutdown(input_module_t *module, int delay);
/* Our protocol module is represented by the following input_module_t data structure */
input_module_t kbd = {
NULL,
NULL,
NULL,
0,
DEVI_CLASS_KBD | DEVI_MODULE_TYPE_PROTO | DEVI_MODULE_TYPE_DEVICE,
"Kbd",
__DATE__,
"k:f:p:u:",
NULL, /* initialized by us (in init) */
kbd_init,
kbd_reset,
kbd_input,
NULL,
NULL,
kbd_parm,
kbd_devctrl,
kbd_shutdown
};
#define FLAG_INIT 0x1000
#define FLAG_SYM 0x8000 /* DEvice level supplies valid symbols */
/* Protocol module private data */
struct data {
int flags;
int rate; /* kbd delay */
int delay; /* kbd rate */
void * hid_module_handle; /* HID module_handle */
int nDev; /* USB device number */
int fId; /* For debug mode (-f parameter) - write input to file */
int fifo; /* For debug mode (-p parameter) - write input to FIFO file */
char fifo_name[100];
};
void * open_pipe(void * parm)
{
struct data * dp = (struct data *)parm;
int pipe_no;
dp -> fifo = 0;
// Block until O_RDONLY pipe will be opened
pipe_no = open(dp -> fifo_name, O_WRONLY );
close(pipe_no);
// Wait a peer process re-opens pipe
sleep(1);
// Open non-blocked pipe
dp -> fifo = open(dp -> fifo_name, O_WRONLY | O_NONBLOCK );
return 0;
}
/* Description: callback initialisation function; it is called when input module is */
/* initialising the input system */
/* Input : input_module_t * module - pointer to module descriptor */
/* Output : None */
/* Return : 0 if OK, otherwise - (-1) */
int kbd_init(input_module_t *module)
{
struct data *dp=module->data;
if(!module->data) {
if(!(dp = module->data = calloc(sizeof *dp, 1))) {
return -1;
}
dp->flags = 0;
dp->fId = 0;
dp -> fifo = 0;
dp -> rate = 33; /* In times per second * 10 */
dp -> delay= 500; /* In milliseconds */
signal(SIGPIPE, SIG_IGN);
}
dp -> nDev = HIDD_CONNECT_WILDCARD;
return(0);
}
/* Description: this is a callback function for DEVCTRL command processing */
/* Input : input_module_t * module - pointer to module descriptor */
/* int event - DEVCTRL command code */
/* void * ptr - pointer to data exchange block */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
int kbd_devctrl(input_module_t *module,int event,void *ptr)
{
struct data *dp=module->data;
int rc = EOK;
switch(event)
{
case DEVCTL_RESET_KBD:
rc = ENOTSUP;
break;
case DEVCTL_GETKBD:
if(NULL != ptr)
{ // Get keyboard parameters - delay & rate
struct devctl_getkbd * pDevctl = (struct devctl_getkbd *)ptr;
pDevctl -> rate = dp -> rate;
pDevctl -> delay = dp -> delay;
}
break;
case DEVCTL_SETKBD:
if(NULL != ptr)
{
struct devctl_setkbd * pDevctl = (struct devctl_setkbd *)ptr;
dp -> delay = pDevctl -> delay;
dp -> rate = pDevctl -> rate;
}
default:
if(dp -> hid_module_handle)
rc = devi_hid_devctrl(dp -> hid_module_handle, event, ptr, HIDD_CONNECT_WILDCARD);
break;
}
return rc;
}
/* Description: this callback funtion is called when the module is linked into the */
/* event bus; it is used to set initial module state on the protocol */
/* level */
/* Input : input_module_t * module - pointer to module descriptor */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
int kbd_reset(input_module_t *module)
{
struct data *dp = module->data;
struct devctl_setkbd devctl;
int rc = EOK;
if((dp->flags & FLAG_INIT) == 0)
{
if(NULL == (dp -> hid_module_handle = devi_hid_register_client(module, dp -> nDev)))
{
return (-1);
}
dp->flags |= FLAG_INIT;
}
else
{
if(module -> up)
rc = module -> up -> reset(module -> up);
if(EOK != rc)
return rc;
}
devctl.delay = dp -> delay;
devctl.rate = dp -> rate;
kbd_devctrl(module, DEVCTL_SETKBD, &devctl);
return rc;
}
/* Description: main protocol processing function. It will be called by the */
/* device layer to pass it data to process. Its job is very simple: */
/* just to hand data off to the filter layer module above it. */
/* Input : input_module_t * module - pointer to module descriptor */
/* int num - number of bytes to process */
/* void * arg - raw data to process */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
int kbd_input(input_module_t *module, int num, void *ptr)
{
struct data *dp=module->data;
input_module_t *up=module->up;
struct packet_kbd kbuf;
USBKCode *tmp=ptr;
_uint8 buf[10]; // Buffer for scan codes
int nLen;
int i, j;
if(dp->flags & FLAG_INIT)
{
kbuf.bMakeBreak = *tmp++;
clk_get(&kbuf.timestamp);
for(i = 1; i < (num / sizeof(USBKCode)); i++)
{
memset(&kbuf.key, 0x00, sizeof kbuf.key);
if(0 < dp -> fId)
write(dp -> fId, tmp, sizeof(USBKCode));
if(0 < dp -> fifo)
{
if(0 > write(dp -> fifo, tmp, sizeof(USBKCode)))
{
dp -> fifo = 0;
pthread_create(NULL, NULL, open_pipe, dp);
}
}
/* The device level supplies USB usages */
/* get scan codes for them */
kbuf.nUSBCode = 0;
nLen = sizeof(buf);
if(EOK == devi_usb_to_scan(*tmp, kbuf.bMakeBreak, buf, &nLen))
for(j = 0; j < nLen; ++j)
{
kbuf.key.key_scan = buf[j];
kbuf.key.flags = KEY_SCAN_VALID;
if(j == (nLen - 1)) // Last package carries USB code as well
kbuf.nUSBCode = *tmp;
(up->input)(up, 1, &kbuf);
}
else {
kbuf.nUSBCode = *tmp;
(up->input)(up, 1, &kbuf);
}
++tmp;
}
}
return(0);
}
/* Description: this is a callback function for command line parameter processing */
/* (all valid parameters for device module are listed in kbd.args) */
/* Input : input_module_t * module - pointer to module descriptor */
/* int opt - parameter code */
/* char * optarg - optional parameter value */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
int kbd_parm(input_module_t *module,int opt,char *optarg)
{
struct data *dp=module->data;
switch(opt) {
case 'k': /* specify key repeat rate and delay */
dp->rate = strtol(optarg, (char **)&optarg, 10) * 10;
if(*optarg == '.' && *++optarg >= '0' && *optarg <= '9') {
dp->rate += *optarg++ - '0';
}
if ( dp->rate )
dp->rate = 10000/dp->rate; /* convert to ms delay between succesive reports */
if(*optarg == ',') {
dp->delay = strtol(++optarg, 0, 10);
}
break;
case 'f':
dp -> fId = open(optarg, O_CREAT | O_WRONLY | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
break;
case 'p':
if(access(optarg, F_OK))
{
if(mkfifo(optarg, S_IRUSR | S_IWUSR))
{
printf("Cannot open FIFO (%s), error = %i\n", optarg, errno);
break;
}
printf ("Pipe %s has been created\n", optarg);
}
strcpy(dp -> fifo_name, optarg);
pthread_create(NULL, NULL, open_pipe, dp);
break;
case 'u':
if(NULL != optarg)
dp -> nDev = atoi(optarg);
break;
default:
return -1;
}
return(0);
}
/* Description: this is a callback function which is called when resourse manager */
/* is shutting down */
/* Input : input_module_t * module - pointer to module descriptor */
/* int ms - program doesn't use this parameter */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
int kbd_shutdown(input_module_t *module, int delay)
{
struct data *dp = module->data;
if(NULL != dp)
{
if(0 < dp -> fId) /* if debug output file was created - close it */
close(dp -> fId);
if(0 < dp -> fifo) /* if debug output file was created - close it */
close(dp -> fifo);
if( NULL != dp -> hid_module_handle)
devi_unregister_hid_client(dp -> hid_module_handle);
}
return(0);
}

85
devi/hid/main.c Обычный файл
Просмотреть файл

@ -0,0 +1,85 @@
/*
* (c) 2010, SWD Embedded Systems Limited, http://www.kpda.ru
*/
/*
* Предостережение:
*
* Предоставленный исходный код драйвера devi-hid рекомендуется использовать
* только для отладочных целей при разработке HID-драйверов. Для всех остальных
* задач следует использовать штатный системный драйвер devi-hid.
*
* В общем случае не существует задач, которые требуется решать в этом драйвере
* при поддержке нового оборудования (для этого должен быть написан/модифицирован
* отдельный драйвер ввода или HID-драйвер).
*/
/*
* main.c
*
* Main resourse manager module.
*
*/
#include <sys/devi.h>
#include "hid.h"
extern input_module_t mouse;
extern input_module_t kbd;
extern input_module_t touch;
extern input_module_t joystick;
extern input_module_t control;
static int post_init();
static int post_shutdown();
input_module_t *modules[] = {
&kbd,
&mouse,
&touch,
&joystick,
&control,
NULL
};
common_callbacks_t callbacks = {
4,
NULL, // Pre-init
post_init, // Post-init
NULL, // Pre-shutdown
post_shutdown // Post-shutdown
};
int
main(int argc, char *argv[])
{
devi_init(&callbacks); // Set driver callback function
devi_hid_init(); // Initialize USB interface
pServ_name = NULL; // Optional HID server name ( may be reassign in command line)
return begin(argc, argv);
}
int post_init()
{
// We cannot connect to USB stack until initialization is finished
// because as soon as connection established, input data may come to
// input channel, and processing bus must be ready to this event.
devi_hid_server_connect(pServ_name); // Connect to USB server
return 0;
}
int post_shutdown()
{
devi_hid_server_disconnect();
return 0;
}

261
devi/hid/mouse.c Обычный файл
Просмотреть файл

@ -0,0 +1,261 @@
/*
* (c) 2010, SWD Embedded Systems Limited, http://www.kpda.ru
*/
/*
* Предостережение:
*
* Предоставленный исходный код драйвера devi-hid рекомендуется использовать
* только для отладочных целей при разработке HID-драйверов. Для всех остальных
* задач следует использовать штатный системный драйвер devi-hid.
*
* В общем случае не существует задач, которые требуется решать в этом драйвере
* при поддержке нового оборудования (для этого должен быть написан/модифицирован
* отдельный драйвер ввода или HID-драйвер).
*/
/*
* mouse.c
*
* The HID USB mouse combined device/protocol module.
*
*/
#include <sys/devi.h>
#include "hid.h"
#include <assert.h>
#define FLAG_INIT 0x0100
#define FLAG_RESET 0x0200
/* Protocol module private data */
struct private_data {
int flags; /* see valid values before */
int nDev; /* USB device number */
void * hid_module_handle; /* HID module_handle */
};
/* forward declarations */
static int mouse_init(input_module_t *module);
static int mouse_devctrl(input_module_t *module, int event, void *ptr);
static int mouse_reset(input_module_t *module);
static int mouse_input(input_module_t *module, int num, void *arg);
static int mouse_parm(input_module_t *module, int opt, char *optarg);
static int mouse_shutdown(input_module_t *module, int delay);
/* Our protocol module is represented by the following input_module_t data structure */
input_module_t mouse = {
NULL,
NULL,
NULL,
0,
DEVI_CLASS_REL | DEVI_MODULE_TYPE_PROTO | DEVI_MODULE_TYPE_DEVICE,
"mouse",
__DATE__,
"u:",
NULL,
mouse_init,
mouse_reset,
mouse_input,
NULL,
NULL,
mouse_parm,
mouse_devctrl,
mouse_shutdown
};
/* Description: callback initialisation function; it is called when input module is */
/* initialising the input system */
/* Input : input_module_t * module - pointer to module descriptor */
/* Output : None */
/* Return : 0 if OK, otherwise - (-1) */
int mouse_init(input_module_t *module)
{
struct private_data *dp = module->data;
if(!module->data)
{
if(!(dp = module->data = _scalloc(sizeof *dp)))
{
return (-1);
}
}
dp -> nDev = HIDD_CONNECT_WILDCARD;
return (0);
}
/* Description: this is a callback function for DEVCTRL command processing */
/* Input : input_module_t * module - pointer to module descriptor */
/* int event - DEVCTRL command code */
/* void * ptr - pointer to data exchange block */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
int mouse_devctrl(input_module_t *module, int event, void *ptr)
{
struct private_data *dp = module->data;
unsigned wheel;
int rc = 0;
switch(event)
{
case DEVCTL_GETDEVFLAGS:
*(unsigned short *)ptr = (dp->flags & FLAGS_GLOBAL);
break;
case DEVCTL_GETPTRBTNS:
*(unsigned long *)ptr = 5L;
break;
case DEVCTL_GETPTRCOORD:
*(unsigned char *)ptr='\02';
break;
case DEVCTL_GETWHEEL:
if(NULL != ptr)
{
struct devctl_mouse_types devctl;
if(EOK == (rc = devi_hid_devctrl(dp -> hid_module_handle, DEVCTL_GETMOUSETYPE, &devctl, HIDD_CONNECT_WILDCARD)))
{
if(devctl.curtype == NO_WHEEL_MOUSE)
wheel = 2;
else
wheel = 3;
*(unsigned *)ptr= wheel;
}
}
else
rc = EINVAL;
break;
case DEVCTL_SETWHEEL:
if(NULL != ptr) {
struct devctl_mouse_types devctl;
devctl.type = devctl.curtype = *(unsigned *)ptr;
if(EOK == (rc = devi_hid_devctrl(dp -> hid_module_handle, DEVCTL_SETMOUSETYPE, &devctl, HIDD_CONNECT_WILDCARD)))
{
}
}
break;
case DEVCTL_SETMOUSETYPE: // Could be NO_WHEEL_MOUSE, WHEEL_3B_MOUSE or WHEEL_5B_MOUSE
case DEVCTL_GETMOUSETYPE:
default:
rc = devi_hid_devctrl(dp -> hid_module_handle, event, ptr, HIDD_CONNECT_WILDCARD );
break;
}
return (rc);
}
/* Description: this callback funtion is called when the module is linked into the */
/* event bus;it is used to set initial module state on the protocol */
/* level */
/* Input : input_module_t * module - pointer to module descriptor */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
int mouse_reset(input_module_t *module)
{
struct private_data *dp = module->data;
if(!(dp->flags & FLAG_INIT))
{
if(NULL == (dp -> hid_module_handle = devi_hid_register_client(module, dp -> nDev)))
return (-1);
}
dp->flags |= FLAG_INIT;
return (0);
}
/* Description: main protocol processing function. It will be called by the */
/* device layer to pass it data to process. Its job is to interpret */
/* the data according to the MS wheel mouse protocol, create a */
/* data structure, fill it in and hand it off to the filter layer */
/* module above it. The protocol is processed using simple state */
/* machine. State info is kept in module's private data */
/* Input : input_module_t * module - pointer to module descriptor */
/* int num - number of bytes to process */
/* void * arg - raw data to process */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
/* Comment : driver uses one of two input modules depending on device data */
/* protocol */
int mouse_input(input_module_t *module, int num, void *arg)
{
pMouse_raw_data_t pMouseRawData = (pMouse_raw_data_t)arg;
struct packet_rel mp; /* data buffer */
struct private_data *dp = module->data;
input_module_t *up = module->up;
assert(num == sizeof(mouse_raw_data_t)); // Desynchronized exchange format
if(dp->flags & FLAG_INIT)
{
mp.flags = PTR_Z_DATA; // Set it inall cases. If there are no wheel, z always == 0
mp.dx = pMouseRawData -> x;
mp.dy = -(pMouseRawData -> y); // '-' because HID specifies down as '+' and up as '-'
mp.dz = -(pMouseRawData -> z); // '-' because HID specifies down as '+' and up as '-'
mp.buttons = pMouseRawData -> btnStates;
( up->input)(up, 1, &mp);
}
return (0);
}
/* Description: this is a callback function for command line parameter processing */
/* (all valid parameters for device module are listed in mouse.args) */
/* Input : input_module_t * module - pointer to module descriptor */
/* int opt - parameter code */
/* char * optarg - optional parameter value */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
/* Comment : we don't accept any parameter for this module at the protocol level */
int mouse_parm(input_module_t *module, int opt, char *optarg)
{
/* Now empty */
struct private_data *dp = module->data;
switch (opt)
{
case 'u':
if(NULL != optarg)
dp -> nDev = atoi(optarg);
default:
break;
}
return (0);
}
/* Description: this is a callback function which is called when resourse manager */
/* is shutting down */
/* Input : input_module_t * module - pointer to module descriptor */
/* int ms - program doesn't use this parameter */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
/* Comment : Does nothing for the protocol level */
int mouse_shutdown(input_module_t *module, int delay)
{
struct private_data *dp = module->data;
if( (NULL != dp) && (NULL != dp -> hid_module_handle))
devi_unregister_hid_client(dp -> hid_module_handle);
return (0);
}

2
devi/hid/nto/Makefile Обычный файл
Просмотреть файл

@ -0,0 +1,2 @@
LIST=CPU
include recurse.mk

2
devi/hid/nto/arm/Makefile Обычный файл
Просмотреть файл

@ -0,0 +1,2 @@
LIST=VARIANT
include recurse.mk

1
devi/hid/nto/arm/o.le.v7/Makefile Обычный файл
Просмотреть файл

@ -0,0 +1 @@
include ../../../../common.mk

1
devi/hid/nto/arm/o.le/Makefile Обычный файл
Просмотреть файл

@ -0,0 +1 @@
include ../../../../common.mk

2
devi/hid/nto/e2k/Makefile Обычный файл
Просмотреть файл

@ -0,0 +1,2 @@
LIST=VARIANT
include recurse.mk

1
devi/hid/nto/e2k/o.le/Makefile Обычный файл
Просмотреть файл

@ -0,0 +1 @@
include ../../../../common.mk

2
devi/hid/nto/mips/Makefile Обычный файл
Просмотреть файл

@ -0,0 +1,2 @@
LIST=VARIANT
include recurse.mk

1
devi/hid/nto/mips/o.be/Makefile Обычный файл
Просмотреть файл

@ -0,0 +1 @@
include ../../../../common.mk

2
devi/hid/nto/ppc/Makefile Обычный файл
Просмотреть файл

@ -0,0 +1,2 @@
LIST=VARIANT
include recurse.mk

1
devi/hid/nto/ppc/o.be.spe/Makefile Обычный файл
Просмотреть файл

@ -0,0 +1 @@
include ../../../../common.mk

1
devi/hid/nto/ppc/o.be/Makefile Обычный файл
Просмотреть файл

@ -0,0 +1 @@
include ../../../../common.mk

2
devi/hid/nto/x86/Makefile Обычный файл
Просмотреть файл

@ -0,0 +1,2 @@
LIST=VARIANT
include recurse.mk

1
devi/hid/nto/x86/o/Makefile Обычный файл
Просмотреть файл

@ -0,0 +1 @@
include ../../../../common.mk

7
devi/hid/pinfo.mk Обычный файл
Просмотреть файл

@ -0,0 +1,7 @@
#
# (c) 2010, SWD Embedded Systems Limited, http://www.kpda.ru
#
define PINFO
PINFO DESCRIPTION=Generic Photon input driver\; This driver supports all devices that have intervace to HID/USB service
endef

5
devi/hid/private.mk Обычный файл
Просмотреть файл

@ -0,0 +1,5 @@
#
# (c) 2010, SWD Embedded Systems Limited, http://www.kpda.ru
#
LIBS+=hiddi

295
devi/hid/touch.c Обычный файл
Просмотреть файл

@ -0,0 +1,295 @@
/*
* (c) 2010-2018, SWD Embedded Systems Limited, http://www.kpda.ru
*/
/*
* Предостережение:
*
* Предоставленный исходный код драйвера devi-hid рекомендуется использовать
* только для отладочных целей при разработке HID-драйверов. Для всех остальных
* задач следует использовать штатный системный драйвер devi-hid.
*
* В общем случае не существует задач, которые требуется решать в этом драйвере
* при поддержке нового оборудования (для этого должен быть написан/модифицирован
* отдельный драйвер ввода или HID-драйвер).
*/
/*
* touch.c
*
* The HID USB touch combined device/protocol module.
*
*/
#include <sys/devi.h>
#include "hid.h"
#include <assert.h>
#define FLAG_INIT 0x0100
#define FLAG_RESET 0x0200
#define FLAG_KIOSK_MODE 0x0400
#define TOUCHED 1
#define RELEASED 0
/* Protocol module private data */
struct private_data {
int flags; /* see valid values before */
int nDev; /* USB device number */
int state;
int max_matrix_val; /* Max value touchscreen can send */
void * hid_module_handle; /* HID module_handle */
};
/* forward declarations */
static int touch_init(input_module_t *module);
static int touch_devctrl(input_module_t *module, int event, void *ptr);
static int touch_reset(input_module_t *module);
static int touch_input(input_module_t *module, int num, void *arg);
static int touch_parm(input_module_t *module, int opt, char *optarg);
static int touch_shutdown(input_module_t *module, int delay);
/* Our protocol module is represented by the following input_module_t data structure */
input_module_t touch = {
NULL,
NULL,
NULL,
0,
DEVI_CLASS_ABS | DEVI_MODULE_TYPE_PROTO | DEVI_MODULE_TYPE_DEVICE,
"touch",
__DATE__,
"Km:u:",
NULL,
touch_init,
touch_reset,
touch_input,
NULL,
NULL,
touch_parm,
touch_devctrl,
touch_shutdown
};
/* Description: callback initialisation function; it is called when input module is */
/* initialising the input system */
/* Input : input_module_t * module - pointer to module descriptor */
/* Output : None */
/* Return : 0 if OK, otherwise - (-1) */
int touch_init(input_module_t *module)
{
struct private_data *dp = module->data;
if(!module->data)
{
if(!(dp = module->data = _scalloc(sizeof *dp)))
{
return (-1);
}
}
dp -> nDev = HIDD_CONNECT_WILDCARD;
dp->state = RELEASED;
dp->max_matrix_val = 1023;
return (0);
}
/* Description: this is a callback function for DEVCTRL command processing */
/* Input : input_module_t * module - pointer to module descriptor */
/* int event - DEVCTRL command code */
/* void * ptr - pointer to data exchange block */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
int touch_devctrl(input_module_t *module, int event, void *ptr)
{
struct private_data *dp = module->data;
int rc = 0;
switch(event)
{
case DEVCTL_GETDEVFLAGS:
*(unsigned short *)ptr = (dp->flags & FLAGS_GLOBAL);
break;
case DEVCTL_GETPTRBTNS:
*(unsigned long *)ptr = 5L;
break;
case DEVCTL_GETPTRCOORD:
*(unsigned char *)ptr='\02';
break;
case DEVCTL_GETCOORDRNG: {
struct devctl_coord_range *range = ptr;
range->min = 0;
range->max = dp->max_matrix_val;
break;
}
default:
rc = devi_hid_devctrl(dp -> hid_module_handle, event, ptr, HIDD_CONNECT_WILDCARD );
break;
}
return (rc);
}
/* Description: this callback funtion is called when the module is linked into the */
/* event bus;it is used to set initial module state on the protocol */
/* level */
/* Input : input_module_t * module - pointer to module descriptor */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
int touch_reset(input_module_t *module)
{
struct private_data *dp = module->data;
if(!(dp->flags & FLAG_INIT))
{
if(NULL == (dp -> hid_module_handle = devi_hid_register_client(module, dp -> nDev)))
return (-1);
}
dp->flags |= FLAG_INIT;
return (0);
}
/* Description: main protocol processing function. It will be called by the */
/* device layer to pass it data to process. Its job is to interpret */
/* the data according to the MS wheel touch protocol, create a */
/* data structure, fill it in and hand it off to the filter layer */
/* module above it. The protocol is processed using simple state */
/* machine. State info is kept in module's private data */
/* Input : input_module_t * module - pointer to module descriptor */
/* int num - number of bytes to process */
/* void * arg - raw data to process */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
/* Comment : driver uses one of two input modules depending on device data */
/* protocol */
int touch_input(input_module_t *module, int num, void *arg)
{
pTouch_raw_data_t pTouchRawData = (pTouch_raw_data_t)arg;
struct packet_abs mp;
struct private_data *dp = module->data;
input_module_t *up = module->up;
assert(num == sizeof(touch_raw_data_t)); // Desynchronized exchange format
if(dp->flags & FLAG_INIT)
{
mp.flags = ABS_PRESS_DATA;
mp.x = pTouchRawData -> x;
mp.y = pTouchRawData -> y;
mp.z = (_int8)pTouchRawData -> z;
mp.buttons = pTouchRawData -> touched;
}
if (verbosity)
fprintf (stderr, "Device Level: X:%u, Y:%u, Z:%u, Buttons %d\n", mp.x, mp.y, mp.z, mp.buttons);
if (dp->flags & FLAG_KIOSK_MODE)
{
if ((mp.buttons == _POINTER_BUTTON_LEFT) && (dp->state != TOUCHED))
{
/* Emit a Touch Event */
(up->input)(up, 1, &mp);
mp.buttons = RELEASED;
dp->state = TOUCHED;
/* Right After Emit a Release Event */
(up->input)(up, 1, &mp);
}
else if (mp.buttons == RELEASED)
{
dp->state = RELEASED;
}
}
else
{
(up->input)(up, 1, &mp);
}
return (0);
}
/* Description: this is a callback function for command line parameter processing */
/* (all valid parameters for device module are listed in touch.args) */
/* Input : input_module_t * module - pointer to module descriptor */
/* int opt - parameter code */
/* char * optarg - optional parameter value */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
/* Comment : we don't accept any parameter for this module at the protocol level */
int touch_parm(input_module_t *module, int opt, char *optarg)
{
/* Now empty */
struct private_data *dp = module->data;
switch (opt)
{
case 'u':
{
if(NULL != optarg)
dp->nDev = atoi(optarg);
break;
}
case 'K':
{
dp->flags |= FLAG_KIOSK_MODE;
break;
}
case 'm':
{
int tmp = dp->max_matrix_val;
dp->max_matrix_val = atoi (optarg);
if (dp->max_matrix_val < 0)
dp->max_matrix_val = tmp;
break;
}
default:
break;
}
return (0);
}
/* Description: this is a callback function which is called when resourse manager */
/* is shutting down */
/* Input : input_module_t * module - pointer to module descriptor */
/* int ms - program doesn't use this parameter */
/* Output : None */
/* Return : 0 if OK, otherwise -1 */
/* Comment : Does nothing for the protocol level */
int touch_shutdown(input_module_t *module, int delay)
{
struct private_data *dp = module->data;
if( (NULL != dp) && (NULL != dp -> hid_module_handle))
devi_unregister_hid_client(dp -> hid_module_handle);
return (0);
}

144
devi/include/const.h Обычный файл
Просмотреть файл

@ -0,0 +1,144 @@
/*
* (c) 2010, SWD Embedded Systems Limited, http://www.kpda.ru
*/
#ifndef CONST_H_INCLUDED
#define CONST_H_INCLUDED
/* photon options */
#define INP_REG_DISABLE_CASB 0x00000001
#define INP_REG_NO_GRAFX 0x00000002
/* general options */
#define OPT_NO_PHOTON 0x0001
#define OPT_RESMGR 0x0002
/* flags for devi lib calls */
#define DEVI_SHARE_RSRC (1 << 0)
#define DEVI_PULSE_ALLOC -1
#define MSEC(_t) ((unsigned long)(((_t).tv_sec * 1000) + ((_t).tv_nsec / 1000000)))
/* Mouse types */
#define NO_WHEEL_MOUSE 0x00
#define WHEEL_3B_MOUSE 0x03
#define WHEEL_5B_MOUSE 0x04
/* serial port config flags */
#define DEVCTL_CFLAG_MASK (CSIZE | CSTOPB | PARENB | PARODD)
#define PODD (PARENB | PARODD)
#define PNONE 0
#define PEVEN PARENB
#define STOP1 0
#define STOP2 CSTOPB
/* global flags mask */
#define FLAGS_GLOBAL 0x00FF
/* absolute (touchscreen) flags */
#define ABS_MAX 16383 /* Calibrated max */
#define ABSOLUTE 0x0008 /* Direct coordinates */
#define ABS_SCREEN 0x0009 /* Touch screen */
#define ABS_WORLD 0x000A /* Digitizing tablet */
#define ABS_TYPE_MASK 0x000F /* Type mask */
#define ABS_UNCALIBRATED 0x0010 /* Raw coordinates */
#define ABS_PRESS_DATA 0x0020 /* touch screen pressure */
#define ABS_RAW_MODE 0x0040 /* operate in raw mode */
#define ABS_XLATE_MODE 0x0080 /* operate in translation mode */
#define PTR_BUT_SWAP 0x0001 /* swap status of buttons */
#define PTR_X_SWAP 0x0002
#define PTR_Y_SWAP 0x0004
#define PTR_Z_SWAP 0x0008
/* devctls -- */
#define DEVCTL_SETBAUD 0x0010 /* change the baud rate */
#define DEVCTL_RESET 0x0020 /* reset */
#define DEVCTL_LED 0x0030 /* set keyboard leds */
#define DEVCTL_GETKBD 0x0040 /* get keyboard rate and delay */
#define DEVCTL_SETKBD 0x0050 /* set keyboard rate and delay */
#define DEVCTL_RESET_KBD 0x0060 /* reset keyboard device */
#define DEVCTL_RESET_PS2MOUSE 0x0070 /* reset ps2 controller */
#define DEVCTL_ISKBD 0x0080 /* device emitting real scancodes? */
#define DEVCTL_RESCHG 0x0090 /* establish new display resolution */
#define DEVCTL_GETDEVFLAGS 0x00a0 /* get the device flags */
#define DEVCTL_GETKEYF 0x00b0 /* get keymap file name */
#define DEVCTL_SETKEYF 0x00c0 /* set keymap file name */
#define DEVCTL_GETPTRBTNS 0x00d0 /* get available buttons mask */
#define DEVCTL_GETPTRCOORD 0x00e0 /* get number of device coordinates */
#define DEVCTL_GETPTRPRESS 0x00f0 /* get number of device pressures */
#define DEVCTL_GETCOORDRNG 0x0100 /* get the range of a coordinate */
#define DEVCTL_GETPRESSRNG 0x0110 /* get the range of a pressure */
#define DEVCTL_GETDEVTYPE 0x0120 /* get the range of a pressure */
#define DEVCTL_COORDCHG 0x0130 /* change the device coordinates */
#define DEVCTL_BELL 0x0140 /* sound the bell */
#define DEVCTL_GETBELLPARM 0x0150 /* get bell parameters */
#define DEVCTL_SETBELLPARM 0x0160 /* set bell parameters */
#define DEVCTL_GETLED 0x0170 /* get LED status */
#define DEVCTL_SETLED 0x0180 /* set LED status */
#define DEVCTL_GETLEDMASK 0x0190 /* get the LED's present on device */
#define DEVCTL_SETTRIG 0x01c0 /* set trigger level */
#define DEVCTL_GETLOADKBDS 0x01d0 /* get list of loaded keyboards */
#define DEVCTL_SEL_KBD 0x01d1 /* select keyboard */
#define DEVCTL_GET_SEL_KBD 0x01d2 /* get selected keyboard */
#define DEVCTL_ADD_KBD 0x01d3 /* add new keyboard */
#define DEVCTL_REMOVE_KBD 0x01d4 /* remove kbd */
#define DEVCTL_RELOAD_KBDS 0x01d5 /* reload keyboards from scratch */
#define DEVCTL_SET_CALIB_MATRIX 0x01d6 /* Set the 3 Point Calibration Matrix */
#define DEVCTL_SET_STATE 0x01d7 /* Set the Device State */
#define DEVCTL_SET_KBD_STATE 0x01d8 /* Set the KBD device State */
#define DEVCTL_SET_REL_STATE 0x01d9 /* Set the REL device State */
#define DEVCTL_SET_ABS_STATE 0x01da /* Set the ABS device State */
/* signalled on lower layers once reset complete */
#define DEVCTL_CHECKPOINT 0x01d0
#define DEVCTL_SETACCEL 0x01f00 /* change relative filter parms */
#define DEVCTL_GETACCEL 0x02000
#define DEVCTL_GETSWAP 0x02100
#define DEVCTL_SETSWAP 0x02200
#define DEVCTL_ABS_MODE 0x02400
#define DEVCTL_GETWHEEL 0x02600
#define DEVCTL_SETWHEEL 0x02700
#define DEVCTL_GETWHEEL_ACCEL 0x02800
#define DEVCTL_SETWHEEL_ACCEL 0x02900
#define DEVCTL_GETZMODE 0x02a00 /* I mouse has a wheel, how to deal with it ? */
#define DEVCTL_SETZMODE 0x02b00 /* See constants below */
#define DEVCTL_GETSAMPLE_RATE 0x02c00 /* Number of samples per second */
#define DEVCTL_SETSAMPLE_RATE 0x02d00
#define DEVCTL_GET_RESOLUTION 0x02e00
#define DEVCTL_SET_RESOLUTION 0x02f00 /* Value sets power of two counts per mm */
#define DEVCTL_GETMOUSETYPE 0x04000 /* get mouse type: returns in buffer struct devctl_mouse_types; types - see before */
#define DEVCTL_SETMOUSETYPE 0x04100 /* send in buffer int value (new mouse type); types - see before */
#define DEVCTL_RESET_COMPOSESTATE 0x01e0
/* Z-modes (see DEVCTL_SET(GET)ZMODE */
#define ZMODE_KEY_UPDOWN 1 /* Transform z-move to key UP and DOWN; this is a default value */
#define ZMODE_PAGE_UP_DOWN 2 /* Transform z-move to key PgUP and PgDOWN */
#define ZMODE_SEND_CLIENT_ONLY 3 /* Send z-move information to client only */
#define scalloc(a) calloc((a),1)
#define smalloc(a) malloc(a)
#define srealloc(a,b,c) realloc(a,c)
#endif

65
devi/include/errdbg.h Обычный файл
Просмотреть файл

@ -0,0 +1,65 @@
/*
* (c) 2010, SWD Embedded Systems Limited, http://www.kpda.ru
*/
#ifndef _ERRDBG_H_INCLUDED
#define _ERRDBG_H_INCLUDED
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/*
* examples of the DEBUG macro in action
*
* DBG(printf("This val should be: %d\n", val););
*
* DBG(assert(x == someval););
*
* DBG(if (x == someval)
print("Oops");
else
x = newval;
);
*
*
*/
#ifdef DEBUG
#define DBG(code_fragment) do { code_fragment } while (0)
#else
#define DBG(code_fragment) // debug: do nothing
#endif
#define VBOSE(a) if(verbose) printf("%s\n",(a))
#define err_abort(code, text) do { \
fprintf (stderr, "%s at \"%s\":%d %s\n", \
text, __FILE__, __LINE__, strerror(code)); \
abort(); \
} while (0)
#define errno_abort(text) do { \
fprintf (stderr, "%s at \"%s\":%d: %s\n", \
text, __FILE__, __LINE__, strerror(errno)); \
abort(); \
} while (0)
#define errno_exit(text) do { \
fprintf (stderr, "%s at \"%s\":%d: %s\n", \
text, __FILE__, __LINE__, strerror(errno)); \
exit(EXIT_FAILURE); \
} while (0)
#define errno_print(text) do { \
fprintf (stderr, "%s at \"%s\":%d: %s\n", \
text, __FILE__, __LINE__, strerror(errno)); \
} while (0)
#endif

36
devi/include/externs.h Обычный файл
Просмотреть файл

@ -0,0 +1,36 @@
/*
* (c) 2010, SWD Embedded Systems Limited, http://www.kpda.ru
*/
#ifndef EXTERN_H_INCLUDED
#ifndef EXT
#define EXT extern
#endif
#define EXTERN_H_INCLUDED
#include <sys/devi.h>
extern int optind, opterr, optopt;
extern char *optarg;
EXT int verbosity;
EXT event_bus_line_t *Bus; /* pointer to list of event bus lines
managed by devi */
EXT int IpGroup; /* input group (used by photon i/f) */
EXT char *IpTargetDev; /* name of photon device to open */
EXT unsigned int OptFlags; /* global options */
EXT int IpCurrentFd; /* fd used to send messages via photon */
EXT input_module_t *ModuleTable[MODULE_TABLE_SIZE]; /* table of currently
supported modules */
EXT common_callbacks_t commonCallbacks; /* Global callback functions */
EXT char *pServ_name;
EXT char *pFull_process_name; // Full process name
EXT int loopPlayback;
EXT FILE *playFile;
EXT FILE *logFile;
EXT int delayMsec;
#endif

125
devi/include/hid.h Обычный файл
Просмотреть файл

@ -0,0 +1,125 @@
/*
* (c) 2010-2019, SWD Embedded Systems Limited, http://www.kpda.ru
*/
#ifndef __HID_H_INCLUDED__
#define __HID_H_INCLUDED__
#include <sys/hidut.h>
#include <sys/hiddi.h>
#include <sys/devi.h>
#define MAX_SLIDER 16
#define MAX_HAT 16
#define HID_MOUSE_HAS_WHEEL (0x01)
#define HID_MOUSE_WHEEL_ON (0x02)
/*******************************************************************************
*
* Keyboard Data Structures
*
*******************************************************************************/
typedef struct _hid_keyboard_data {
_uint16 nLeds; /* Number of leds */
_uint16 nKeys; /* Size of keyboard array */
_uint16 nRate; /* Time interval to repeat (in msecs) */
_uint16 nDelay; /* Delay time interval (in msecs) */
} hid_keyboard_data_t, *pHid_keyboard_data_t;
/*******************************************************************************
*
* Mouse Data Structures
*
*******************************************************************************/
typedef struct _mouse_data {
_uint16 nButtons; /* Number of buttons */
_uint8 flags; /* Flags */
} mouse_data_t, *pMouse_data_t;
typedef struct _mouse_raw_data {
_uint8 btnStates; /* Buttons states (each bit == 1 corresponds to pressed button */
_int16 x; /* pointer x-movement */
_int16 y; /* pointer y-movement */
_int16 z; /* wheel movement (if wheel exists) */
} mouse_raw_data_t, *pMouse_raw_data_t;
/*******************************************************************************
*
* Joystick Data Structures
*
*******************************************************************************/
typedef struct _joystick_attrib {
_uint16 nButtons; /* Number of buttons */
_uint16 nButtons2; /* Number of buttons */
_uint8 flags; /* Flags */
} joystick_attrib_t, *pJoystick_attrib_t;
typedef struct _joystick_data {
// _uint16 nButtons_1; /* Number of buttons */
_uint8 btnStates_1; /* Buttons states (each bit == 1 corresponds to pressed button */
_uint64 button_state;
// _uint16 nButtons_2; /* Number of buttons */
_uint8 btnStates_2; /* Buttons states (each bit == 1 corresponds to pressed button */
/* Pointer */
_uint32 x;
_uint32 y;
_uint32 z;
/* Hat switch */
_uint32 hat_switch;
/* Slider */
_uint32 slider;
/* Rotational */
_uint32 Rx;
_uint32 Ry;
_uint32 Rz;
} joystick_raw_data_t, * pJoystick_raw_data_t;
/*******************************************************************************
*
* Touchscreen Data Structures
*
*******************************************************************************/
typedef struct _touch_attrib {
_uint16 nButtons; /* Number of buttons */
_uint8 flags; /* Flags */
} touch_attrib_t, *pTouch_attrib_t;
typedef struct _touch_raw_data {
_uint8 touched; /* 1 if screen yes, otherwise 0 */
_int16 x; /* Absolute x-position */
_int16 y; /* Absolute y-position */
_int16 z; /* wheel movement (if wheel exists) */
} touch_raw_data_t, *pTouch_raw_data_t;
/*******************************************************************************
*
* Consumer Control Data Structures
*
*******************************************************************************/
typedef struct _control_attrib {
_uint16 nButtons; /* Number of buttons */
_uint8 flags; /* Flags */
} control_attrib_t, *pControl_attrib_t;
typedef struct _control_raw_data {
_uint32 button_state;
_int16 Rx;
_int16 Ry;
_int16 Rz;
} control_raw_data_t, *pControl_raw_data_t;
#endif

83
devi/include/photon.h Обычный файл
Просмотреть файл

@ -0,0 +1,83 @@
/*
* (c) 2010, SWD Embedded Systems Limited, http://www.kpda.ru
*/
#ifndef __PHOTON_H_INCLUDED__
#define __PHOTON_H_INCLUDED__
#include <Ph.h>
#include <photon/PhT.h>
#include <photon/PhSystem.h>
#include <photon/PhService.h>
extern struct _Ph_ctrl *_Ph_;
#define MAX_QUERY_RIDS 100
/* injection constants */
#define INJECTED 1
#define NOT_INJECTED ~INJECTED
#define MAX_COORD 50
#define SIG_INPUT_EVENT SIGRTMIN
#define SIG_PH_EVENT SIGRTMIN+1
typedef struct _input_data {
struct {
unsigned char type;
unsigned char flags;
long reply_pid;
} hdr;
union {
struct packet_kbd kbd;
struct packet_rel rel;
struct packet_abs abs;
char data[1];
} u;
} input_data_t;
typedef struct {
int flags;
PhRid_t rid;
PhRect_t rect;
PhRegion_t region;
int throttle;
} input_region_data_t;
typedef struct {
unsigned millisec;
unsigned abs_max;
union {
PhRawPtrEvent_t ptr;
char padding[offsetof(PhRawPtrEvent_t, coord) +
MAX_COORD * sizeof(PhRawPtrCoord_t)];
} u;
} inject_event_t;
/* Protos */
int photon_connect(char *, input_region_data_t *);
void inject(buffer_t *, input_data_t *, input_region_data_t *);
void trig_ptr(PhRawPtrEvent_t *, unsigned, PhRid_t);
void trig_kbd(PhRawKeyEvent_t *, unsigned, PhRid_t);
void * ph_thread(void *);
void injector_specific_destroy(void *);
int photon_input_pulse(input_region_data_t *);
int query_grafx_region(int, PhRect_t *);
void slay_photon(unsigned);
pid_t photon_pid(void);
int gfi_emit_ptr(PhRawPtrEvent_t const *ptr_ev);
int gfi_emit_kbd(PhRawKeyEvent_t const *key_ev);
#endif

143
devi/include/proto.h Обычный файл
Просмотреть файл

@ -0,0 +1,143 @@
/*
* (c) 2010, SWD Embedded Systems Limited, http://www.kpda.ru
*/
#ifndef PROTO_H_INCLUDED
#define PROTO_H_INCLUDED
#include <sys/devi.h>
#include "usb.h"
void devi_init(pCommon_callbacks_t pCallbacks);
int begin(int, char**);
/* buffer */
buffer_t * buff_create(unsigned, unsigned);
int buff_append(buffer_t *, char *, int );
int buff_delete(buffer_t *, char *, int );
int buff_flush(buffer_t *);
int buff_putc(buffer_t *, char );
int buff_getc(buffer_t *, char *);
int buff_waiting(buffer_t *);
/* Event Bus */
event_bus_line_t *bus_create(void);
int bus_add(event_bus_line_t *, input_module_t *);
int bus_complete(event_bus_line_t *line);
void bus_dump(void);
int bus_interrogate(int, input_module_t **);
int bus_reset(void);
/* base */
int options(int argc, char *argv[], uint32_t *, unsigned int *);
/* util */
int devi_get_coid();
void init_sclk(void);
void clk_get(struct timespec *);
/* module */
input_module_t *module_lookup(char *name);
input_module_t *module_filter_lookup(int);
int start_photon_interface(uint32_t);
int resmgr_create_device(event_bus_line_t *line);
void resmgr_init(int);
void resmgr_enqueue_packet(event_bus_line_t *, char *data, int size);
int photon_raw_enqueue(unsigned type, char *dptr, int size);
int gfi_register(int input_group);
/* Dispatch services */
dispatch_t * devi_get_dispatch_handle();
void devi_set_dispatch_handle(dispatch_t * pdp);
/* Initializes USB driver */
void devi_usb_init();
/* Initializes USB client */
int devi_usb_server_connect(char * serv_path_name);
/* Disconnect USB server */
void devi_usb_server_disconnect();
/* This function attach client to USB sub-system. Register your client from
* reset function of device module. If nDev >= 0, it specifies device number.
* Function returns local module handler
*/
void * devi_usb_register_client(input_module_t * pInput_module, int nDev,
_uint32 nVendor, _uint32 nClass, _uint32 nSubClass);
/* Detach input module from USB driver */
void devi_unregister_usb_client(void * h);
/* Get device status (see usb.h) */
int devi_usb_device_status(void * pHandle, _uint8 * pnStatus);
/* Initializes HID driver */
void devi_hid_init();
/* Connects to USB HID server */
int devi_hid_server_connect(char * serv_path_name);
/* Disconnects client from USB HID server */
void devi_hid_server_disconnect();
/* This function attach client to HID USB sub-system. Register your client from
* reset function of each device module. If nDev >= 0, it specifies device number.
* Function returns local module handler
*/
void * devi_hid_register_client(input_module_t *module, int nDev);
/* Detach input module from HID driver */
void devi_unregister_hid_client(void * h);
/* HID devctrl processor */
int devi_hid_devctrl(void * pHandle, int event, void *ptr,
int nDev /*HIDD_CONNECT_WILDCARD if all devices connected to this module*/);
/* Register pulse */
int devi_register_pulse(input_module_t *module, int code,
int (*func)(message_context_t *, int, unsigned, void *));
/* Register interrupt */
int devi_register_interrupt(int intr, int prio, int *code, input_module_t *module, struct sigevent *evp, unsigned);
/* Register timer */
timer_t devi_register_timer(input_module_t *module, int prio, int *code, struct sigevent *evp);
/* Request input/output space mapping */
uintptr_t devi_request_iorange(unsigned start, unsigned len, unsigned flags);
/* Engue data package */
int devi_enqueue_packet(input_module_t *, char *, unsigned);
/* Convert scan code(s) to USB keyboard usage code */
int devi_scan_to_usb(unsigned char * buf, int * pnBytes, USBKCode * usbCodes,
unsigned char * makeBreakes, int * pnLen);
/* Convert USB keyboard usage code to scan code(s) */
int devi_usb_to_scan(USBKCode usbCode, int nMakeBreak, _uint8 * buf, int * pnLen);
// This function sends control data to the device control endpoint
int devi_output_control(void * pHandle, pControlRequest pRequest, void * data, int nLen);
/* from main */
void input_shutdown(void);
#endif

80
devi/include/ps2api.h Обычный файл
Просмотреть файл

@ -0,0 +1,80 @@
/*
* (c) 2010, SWD Embedded Systems Limited, http://www.kpda.ru
*/
/* PS2 controller API specification */
#ifndef _PS2API_H
#define _PS2API_H
/* Controller modes */
#define SET_LEGACY_MODE (1)
#define SET_MULTIPLEX_MODE (2)
/* Initialization flags */
#define INIT_MULTIPLEX_MODE (0x01)
#define INIT_SELF_TEST (0x02)
/* Next two constant - for IRQ parameters in init_contr */
#define SET_DEFAULT (0)
#define SET_NONE (-1)
/* Initialize PS/2 keyboard controller */
int init_contr(int flags, int nIrq_base, int nIrq_aux, int nDataPort, int nStatusPort);
/* default arguments */
#define DEFAULT_DISPHANDLE (NULL)
#define DEFAULT_COID (-1)
/* Register logical device at the PS/2 controller */
int register_device(dispatch_t * dp, int (*pulse)(message_context_t *, int, unsigned, void *),
int coid, int nPortNum, void * data);
/* Reset PS/2 device */
int reset_device(int nPortNum);
/* Disconnect logical device from PS/2 controller */
int unregister_device(int nPortNum);
/* Change scheduling priority for this port processing */
int set_priority(int nPortNum,int nNewPrty);
/* sends command to target device but not
expects ACK (useful for RESET and RESET_WRAP_MODE */
int send_device_command(int nPortNum, unsigned char cmd,
unsigned char * pReply, int nReplyLen);
/* Send device/controller specific command */
int send_command(int nPortNum, unsigned char cmd,
unsigned char * pReply, int nReplyLen);
/* Send sequence of commands to device */
int send_command_set(int nPortNum,
unsigned char * pCmds, int nCmdSetLen,
unsigned char * pReply, int nReplyLen);
/* Extract data comming from interrupt processing program */
unsigned char get_in_data(int blk);
/* Shutdown PS/2 controller */
void shutdown_contr();
/* Switch controller to/from multiplexing mode (now just does nothing) */
int switch_controller_mode(int nNewMode);
/* Prototipes of Controller specific functions */
typedef int (check_data)(int nPortNum, unsigned char nStatus);
typedef int (get_switch_cmd)(int nPortNum);
#define NOT_DEF_IRQ_TYPE (0)
#define KBD_IRQ_TYPE (1)
#define AUX_IRQ_TYPE (2)
#define RET_DATA_ERROR (-1)
#define RET_NO_DATA (-2)
typedef int (validate_data)(int nStatus, int nIrqId);
typedef int (enable_port_cmd)(int nPortNum, unsigned char cmd);
typedef int (switch_mode)(int nNewMode);
/* Replace controller specific callbacks */
void set_callbacks(check_data * f_chdat, get_switch_cmd * f_getsw, validate_data * f_valid,
enable_port_cmd * f_encmd, switch_mode * f_swmode);
#endif // _PS2API_H

287
devi/include/storage.h Обычный файл
Просмотреть файл

@ -0,0 +1,287 @@
/*
* (c) 2010-2017, SWD Embedded Systems Limited, http://www.kpda.ru
*/
/*
* storage.h
*
* This file includes structures that are used by keyboard mapping programs
*/
#ifndef _STORAGE_H
#define _STORAGE_H
#include <_pack1.h>
#include <sys/usbcodes.h>
#define KEYBIN_SIGNATURE "KDEF-RTP"
#define MAX_DEAD_KEYS (20)
/* structure defines virtual modifier declared in keyboard layout description file */
/* Note: first eight modifiers are used for standard modifiers (USB): */
/* - LEFT_CTRL */
/* - LEFT_SHIFT */
/* - LEFT_ALT */
/* - LEFT_GUI */
/* - RIGHT_CTRL */
/* - RIGHT_SHIFT */
/* - RIGHT_ALT */
/* - RIGHT_GUI */
/* All other modifiers are either a key that was assigned to be a modifier */
/* (NUM_LOCK for example) or completely virtual modifiers (SHIFT for example). */
/* All non-default modifiers get initial values and can be changed by actions */
/* As more as 56 virtual modifiers can be declared */
typedef struct _modifier
{
char *pModName; /* global modifier identifier */
USBKCode modKey; /* 0 if no key associated with this modifier */
/* otherwise key USB code (see usbcodes.h) */
} modifier, *pmodifier;
typedef struct _modArray
{
short nOfModifiers;
_uint64 modState; /* up to 64 modifiers; each bit corresponds to one modifier */
modifier aModifiers[1];
} mod_array_t, * pmod_array_t;
typedef struct _action
{
/* state of modifiers before action */
_uint64 modBefore; /* vector of modifiers we test state */
/* before; 1 - test, 0 - ignore */
_uint64 modStateBefore; /* vector of modifiers state before */
_uint64 modAction; /* vector of modifiers that involved in */
/* action; 1 - involved, 0 - ignore */
_uint64 modStateAction; /* how these modifies can be changed */
_uint8 modToDo; /* modifier number we should change */
struct {
#if defined(__BIGENDIAN__)
BYTE reserve : 5; /* reserve */
BYTE newState : 2; /* 0 - press , 1 - release */
/* 2 - up, 3 - down */
/* which modifier and how should be changed */
/* Up & Down changes global state, Press & Release - just temp variabes that */
/* decoder uses as array of curent actions */
#define _ACT_UP_ (0)
#define _ACT_DOWN_ (1)
#define _ACT_PRESS_ (2)
#define _ACT_RELEASE_ (3)
unsigned int bOperation : 1; /* 0 - "OR", 1 - "AND" */
/* Logical operation for before state */
#else
BYTE bOperation : 1; /* 0 - "OR", 1 - "AND" */
/* Logical operation for before state */
/* which modifier and how should be changed */
/* Up & Down changes global state, Press & Release - just temp variabes that */
/* decoder uses as array of curent actions */
#define _ACT_UP_ (0)
#define _ACT_DOWN_ (1)
#define _ACT_PRESS_ (2)
#define _ACT_RELEASE_ (3)
BYTE newState : 2; /* 0 - press , 1 - release */
/* 2 - up, 3 - down */
BYTE reserve : 5; /* reserve */
#endif
} flags;
} action_t, * paction_t;
typedef struct _actArray /* array of actions */
{
short nOfActions;
action_t aActions[1];
} act_array_t, * pact_array_t;
/* Composition sections */
#define COMP_START_DEADKEY (0)
#define COMP_START_CTRL (1)
#define COMP_START_SHIFT (2)
#define COMP_START_ALT (3)
#define COMP_START_GUI (4)
/* We search the table of compositions sequentialy; we selected this implementation*/
/* because of the composed chains are quite short and so the cost of support any */
/* general structure could be much more in comparing with this simple approach */
typedef struct _composeItem
{
#if defined(__BIGENDIAN__)
BYTE lengthOut : 4; /* length of result UNICODE string */
BYTE lengthIn : 4; /* length of composed string */
#else
BYTE lengthIn : 4; /* length of composed string */
BYTE lengthOut : 4; /* length of result UNICODE string */
#endif
wchar_t data[1]; /* first UNICODE comp string, then out string */
} compose_item_t, * pcompose_item_t;
typedef struct _compArea /* area where composition descriptors are stored */
{
wchar_t aDeadKeys[MAX_DEAD_KEYS]; /* Dead keys that were specified for this */
/* keyboard mapping file */
/* four different modifiers can be applied (see comment to composeItem structure */
/* composition descriptors grouped in four different sections for each possible */
/* modifier to expedite search; each section can be empty (nComps == 0) */
/* the last fifth section is created for combinations that can be ignited by */
/* dead keys (see sample.kdef file) */
struct { /* there are five sections */
_uint16 nComps; /* number of compositions in section */
_uint16 nOffset;/* offset of section beginning from the start of pComps */
} sect[5];
BYTE nModState; /* we use this field to monitor compose ignition(sequential */
/* pressing and releasing of any default modifier (from */
/* KS_Control_L to KS_Right_GUI) */
/* If it is a composition state, following variables describe it */
short nCurSect; /* number of active section; -1 if none */
short nCurItemNum; /* Number of compose string we stand on */
short nCurOffset; /* offset of current compose sequence from the start of sect */
short nCurLen; /* current length of compose sequence */
/* End of composition state descriptor */
void * pComps;
} comp_area_t, * pcomp_area_t;
/* In general, map table provides 1-to-n mapping: 1 USB code can be mapped to n */
/* UNICODE characters (about combination see comment later) */
/* array of modification flags is a key to the map table */
/* mapping table is a set of items two main types */
/* - continuous array of map items */
/* - single map item */
/* array is defined using the first item code and its length; each array item */
/* then mapping items follow; */
/* single item is defined just with USB key code */
/* both array item and single item have three main types of mapping */
/* - start of combination of codes (see compose characters in sample map file */
/* - set of UNICODE symbols (if output consists of more than one cha */
/* - single UNICODE code (this modified key should be mapped to just single code */
typedef struct _keyMapItem
{
USBKCode nCode; /* USB code to be remapped (if type == 1 - this */
/* code just corresponds to the first item in array */
union {
struct {
#if defined(__BIGENDIAN__)
BYTE length: 7; /* length of array */
BYTE type : 1; /* 0 - array of codes */
/* This is a mapping array (may be just from 1 item) */
/* In this case nCode corresponds to the first */
/* item in this table. CAP == code */
/* (CAP makes sense only for non-modified USB codes) */
} strArray;
struct {
BYTE length: 4; /* Length of string */
BYTE reserve:1;
BYTE deadKey:1; /* 1 if this is a dead key */
BYTE bHasCAP:1; /* does it has CAP ? */
/* If CAP code exists it is always the last in the */
/* string (if length == 1, CAP == code) */
BYTE type : 1; /* 1 - single code or string of UNICODs */
} strSingle;
#else
BYTE type : 1; /* 0 - array of codes */
/* This is a mapping array (may be just from 1 item) */
/* In this case nCode corresponds to the first */
/* item in this table. CAP == code */
/* (CAP makes sense only for non-modified USB codes) */
BYTE length: 7; /* length of array */
} strArray;
struct {
BYTE type : 1; /* 1 - single code or string of UNICODs */
BYTE bHasCAP:1; /* does it has CAP ? */
/* If CAP code exists it is always the last in the */
/* string (if length == 1, CAP == code) */
BYTE deadKey:1; /* 1 if this is a dead key */
BYTE reserve:1;
BYTE length: 4; /* Length of string */
} strSingle;
#endif
} descriptor;
wchar_t nUNICode[1]; /* string of UNICODEs */
} key_map_item_t, * pkey_map_item_t;
typedef struct _dirItem
{
_uint64 modState; /* the state of modifiers for this map table */
_uint64 modToTest; /* Each '1' s a modifier we have to test */
_uint16 nBlocks; /* number of descriptive blocks in this table */
_uint32 offset; /* offset of map table from the end of directory */
} dir_item_t, * pdir_item_t;
typedef struct _keyMapDir
{
short nOfMapTables;
dir_item_t dirTable[1];
} key_map_dir_t, * pkey_map_dir_t;
/* structure defines keyboard layout description file header */
typedef struct _stHeader
{
_uint8 leds[8]; /* table to get LEDs */
_uint8 stdModArray[32]; /* table to re-map to standard modifiers */
pmod_array_t pMod; /* virtual modifiers */
pact_array_t pAct; /* actions that change modifier state */
pkey_map_dir_t pKMapDir; /* key map directory */
pcomp_area_t pComp; /* area where combinations of codes are located */
/* this area is used for mapping of composed */
/* characters sequences */
} st_header_t, * pst_header_t;
#include <_packpop.h>
#if defined(__MIPS__) && defined(__BIGENDIAN__)
#undef ENDIAN_SWAP16
#undef ENDIAN_SWAP32
#undef ENDIAN_SWAP64
#define ENDIAN_SWAP16(pVal) \
{ \
uint8_t *pswap16 = (uint8_t *)pVal; \
uint8_t aswap16[2]; \
aswap16[0] = pswap16[1]; \
aswap16[1] = pswap16[0]; \
pswap16[0] = aswap16[0]; \
pswap16[1] = aswap16[1]; \
}
#define ENDIAN_SWAP32(pVal) \
{ \
uint8_t *pswap32 = (uint8_t *)pVal; \
uint8_t aswap32[4]; \
aswap32[0] = pswap32[3]; \
aswap32[1] = pswap32[2]; \
aswap32[2] = pswap32[1]; \
aswap32[3] = pswap32[0]; \
pswap32[0] = aswap32[0]; \
pswap32[1] = aswap32[1]; \
pswap32[2] = aswap32[2]; \
pswap32[3] = aswap32[3]; \
}
#define ENDIAN_SWAP64(pVal) \
{ \
uint8_t *pswap64 = (uint8_t *)pVal; \
uint8_t aswap64[8]; \
aswap64[0] = pswap64[7]; \
aswap64[1] = pswap64[6]; \
aswap64[2] = pswap64[5]; \
aswap64[3] = pswap64[4]; \
aswap64[4] = pswap64[3]; \
aswap64[5] = pswap64[2]; \
aswap64[6] = pswap64[1]; \
aswap64[7] = pswap64[0]; \
pswap64[0] = aswap64[0]; \
pswap64[1] = aswap64[1]; \
pswap64[2] = aswap64[2]; \
pswap64[3] = aswap64[3]; \
pswap64[4] = aswap64[4]; \
pswap64[5] = aswap64[5]; \
pswap64[6] = aswap64[6]; \
pswap64[7] = aswap64[7]; \
}
#endif
#endif /*_STORAGE_H*/

27
devi/include/usb.h Обычный файл
Просмотреть файл

@ -0,0 +1,27 @@
/*
* (c) 2010, SWD Embedded Systems Limited, http://www.kpda.ru
*/
#ifndef __USB_H_INCLUDED__
#define __USB_H_INCLUDED__
#include <sys/usbdi.h>
typedef struct _controlRequest
{
_uint8 dir ; /* Direction (URB_DIR_IN or URB_DIR_OUT) */
_uint8 type; /* Type (USB_TYPE_STANDARD, USB_TYPE_CLASS or USB_TYPE_VENDOR) */
_uint8 rec ; /* Recipient (USB_RECIPENT_DEVICE, _INTERFACE, _ENDPOINT, _OTHER) */
_uint8 req ; /* Request - vendor specific or one of standard */
_uint16 value; /* Command parameter */
_uint16 index; /* Command index( request specific */
} controlRequest, * pControlRequest;
/* Device status flags */
#define USB_DEVICE_STATUS_FLAGS (0xff)
#define USB_DEVICE_ON (0x01)
#define USB_DEVICE_PRESENT (0x02)
#endif

Двоичные данные
devi/keymap/nto/arm/a.o.le.shared/libkeymapS.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/keymap/nto/arm/a.o.le.v7.shared/libkeymapS.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/keymap/nto/arm/a.o.le.v7/libkeymap.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/keymap/nto/arm/a.o.le/libkeymap.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/keymap/nto/e2k/a.o.le/libkeymap.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/keymap/nto/mips/a.o.be.shared/libkeymapS.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/keymap/nto/mips/a.o.be/libkeymap.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/keymap/nto/mips/a.o.le.shared/libkeymapS.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/keymap/nto/mips/a.o.le/libkeymap.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/keymap/nto/ppc/a.o.be.shared/libkeymapS.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/keymap/nto/ppc/a.o.be.spe.shared/libkeymapS.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/keymap/nto/ppc/a.o.be.spe/libkeymap.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/keymap/nto/ppc/a.o.be/libkeymap.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/keymap/nto/x86/a.o.shared/libkeymapS.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/keymap/nto/x86/a.o/libkeymap.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/lib/nto/arm/a.o.le.shared/libinputS.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/lib/nto/arm/a.o.le.v7.shared/libinputS.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/lib/nto/arm/a.o.le.v7/libinput.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/lib/nto/arm/a.o.le/libinput.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/lib/nto/e2k/a.o.le/libinput.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/lib/nto/mips/a.o.be.shared/libinputS.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/lib/nto/mips/a.o.be/libinput.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/lib/nto/mips/a.o.le.shared/libinputS.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/lib/nto/mips/a.o.le/libinput.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/lib/nto/ppc/a.o.be.shared/libinputS.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/lib/nto/ppc/a.o.be.spe.shared/libinputS.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/lib/nto/ppc/a.o.be.spe/libinput.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/lib/nto/ppc/a.o.be/libinput.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/lib/nto/x86/a.o.shared/libinputS.a Обычный файл

Двоичный файл не отображается.

Двоичные данные
devi/lib/nto/x86/a.o/libinput.a Обычный файл

Двоичный файл не отображается.

301
devi/public/sys/dcmd_input.h Обычный файл
Просмотреть файл

@ -0,0 +1,301 @@
/*
* (c) 2020, SWD Embedded Systems Limited, http://www.kpda.ru
*/
/*
* dcmd_input.h
*/
#ifndef __DCMD_INPUT_H_INCLUDED
#define __DCMD_INPUT_H_INCLUDED
#ifndef _DEVCTL_H_INCLUDED
#include <devctl.h>
#endif
#ifndef __DCMD_MISC_H_INCLUDED
#include <sys/dcmd_misc.h>
#endif
#ifndef _TIME_H_INCLUDED
#include <time.h>
#endif
#ifndef __PLATFORM_H_INCLUDED
#include <sys/platform.h>
#endif
__BEGIN_DECLS
#include <_pack64.h>
/*--------------------------------------------------------------------------------*/
#define KB_OFFSET 0x10 /* offset of kb devctls in the input space */
struct _keyboard_data {
unsigned int modifiers;
unsigned int flags;
unsigned int key_cap;
unsigned int key_sym;
unsigned int key_scan;
};
struct _keyboard_packet { /* start of struct returned from read() */
struct timespec time;
struct _keyboard_data data;
};
#define _KEYBOARD_MODE_SCAN 0x0000 /* single byte scancodes are returned */
#define _KEYBOARD_MODE_PACKET 0x0001 /* _keyboard_packets are returned */
#define _KEYBOARD_MODE_UNICODE 0x0002 /* unicode (16 bit quantities) are returned */
#define _KEYBOARD_MODE_MASK 0x0003
struct _keyboard_ctrl {
struct _interact_device type; /* Device type */
unsigned int flags; /* Device type flags */
unsigned int mode; /* Mode of currently read packets */
unsigned short rate;
unsigned short delay;
char mapfile[_POSIX_PATH_MAX];
unsigned int zero[9];
};
#define _KEYBOARDGETCTRL __DIOF(_DCMD_INPUT, KB_OFFSET+0, struct _keyboard_ctrl)
#define _KEYBOARDSETCTRL __DIOT(_DCMD_INPUT, KB_OFFSET+1, struct _keyboard_ctrl)
#define _KEYBOARDGETKEYMAPPATH __DIOF(_DCMD_INPUT, KB_OFFSET+2, char[_POSIX_PATH_MAX])
#define _KEYBOARDSETKEYMAPPATH __DIOT(_DCMD_INPUT, KB_OFFSET+3, char[_POSIX_PATH_MAX])
#define _KEYBOARDRELOADCONFIG __DIOT(_DCMD_INPUT, KB_OFFSET+4, struct _interact_device)
/*--------------------------------------------------------------------------------*/
#define PTR_OFFSET 0x20
#define _POINTER_FLAG_PROPERTIES 0x000088ff /* Properties mask */
#define _POINTER_FLAG_ABSOLUTE 0x00000001 /* Absolute co-ordinates (proximity) */
#define _POINTER_FLAG_BUTTON 0x00000002 /* buttons is non-zero */
#define _POINTER_FLAG_COORD 0x00000800 /* num_coord is non-zero */
#define _POINTER_FLAG_PRESSURE 0x00008000 /* num_pressure is non-zero */
#define _POINTER_FLAG_VALUE (_POINTER_FLAG_COORD|_POINTER_FLAG_PRESSURE)
#define _POINTER_FLAG_CSCALE 0x00000700 /* Unit scale mask (for coords) */
#define _POINTER_FLAG_CUNITY 0x00000000 /* Units are not world related */
#define _POINTER_FLAG_CMETRIC 0x00000100 /* each unit is a number of micrometers (meter / 1000000) */
#define _POINTER_FLAG_CIMPERIAL 0x00000200 /* each unit is a number of microns (inch / 1000000) */
#define _POINTER_FLAG_CSCREEN 0x00000300 /* each unit is relitave to screen */
#define _POINTER_FLAG_PSCALE 0x00007000 /* Unit scale mask (for pressure) */
#define _POINTER_FLAG_PUNITY 0x00000000 /* Units are not world related */
#define _POINTER_FLAG_TOUCH (_POINTER_FLAG_ABSOLUTE|_POINTER_FLAG_COORD|_POINTER_FLAG_CSCREEN)
#define _POINTER_FLAG_MOUSE (_POINTER_FLAG_COORD)
#define _POINTER_FLAG_BSWAP 0x00010000
#define _POINTER_FLAG_XSWAP 0x00020000
#define _POINTER_FLAG_YSWAP 0x00040000
#define _POINTER_FLAG_ZSWAP 0x00080000
#define _POINTER_FLAG_SWAP_MASK 0x000f0000
#define _POINTER_FLAG_SWAP_POS 16
#define _POINTER_MODE_COMPRESSED 0x0001 /* Data is compressed */
#define _POINTER_BUTTON_1 0x00000001
#define _POINTER_BUTTON_2 0x00000002
#define _POINTER_BUTTON_3 0x00000004
#define _POINTER_BUTTON_4 0x00000008
#define _POINTER_BUTTON_5 0x00000010
#define _POINTER_BUTTON_6 0x00000020
#define _POINTER_BUTTON_7 0x00000040
#define _POINTER_BUTTON_8 0x00000080
#define _POINTER_BUTTON_RIGHT _POINTER_BUTTON_1
#define _POINTER_BUTTON_MIDDLE _POINTER_BUTTON_2
#define _POINTER_BUTTON_LEFT _POINTER_BUTTON_3
#define _POINTER_IOCTL_MAX_POINTS 6 /* Maximum number of data points available with ioctl(), otherwise use qnx_ioctl() */
struct _pointer_packet_hdr { /* start of struct returned from read() */
struct timespec time;
unsigned int buttons; /* Currently depressed buttons */
};
struct _pointer_packet { /* returned from read() (variable number of data items) */
struct _pointer_packet_hdr hdr;
int data[1]; /* variable amount of data (first coord, then pressure) */
};
struct _mouse_packet { /* common form for "mouse" pointing devices */
struct _pointer_packet_hdr hdr;
int dx; /* num_coord == 2, num_pressure = 0 */
int dy;
int dz;
};
struct _touch1_packet { /* common form for "touch" pointing devices (no pressure) */
struct _pointer_packet_hdr hdr;
int x; /* num_coord = 2, num_pressure = 0 */
int y;
int z;
};
struct _joystick_packet_hdr { /* start of struct returned from read() */
struct timespec time;
#ifndef __64__
unsigned long long button_state; /* Currently depressed buttons */
#else
unsigned long button_state; /* Currently depressed buttons */
#endif
};
struct _joystick_packet {
struct _joystick_packet_hdr hdr;
int x;
int y;
int z;
short Rx;
short Ry;
short Rz;
unsigned short function_count; /* Stores the number of sliders in the low bits, and Hats in the high bits */
//unsigned *slider[MAX_SLIDER];
unsigned slider;
//unsigned *hat[MAX_HAT];
unsigned hat_switch;
struct timespec timestamp;
};
struct _control_packet_hdr { /* start of struct returned from read() */
struct timespec time;
#ifndef __64__
unsigned long long button_state; /* Currently depressed buttons */
#else
unsigned long button_state; /* Currently depressed buttons */
#endif
};
struct _control_packet {
struct _control_packet_hdr hdr;
short Rx;
short Ry;
short Rz;
struct timespec timestamp;
};
struct _pointer_info {
struct _interact_device type; /* Device type */
unsigned int flags; /* Device type flags (read only) */
unsigned char num_coord; /* Number of coordinats (first range values) */
unsigned char num_pressure; /* Number of pressures (after coord values) */
unsigned short mode; /* Mode of currently read packets */
unsigned int buttons; /* Buttons available bitmap */
struct _pointer_range {
int min;
int max;
unsigned int units; /* Microns or micrometer per unit (if used) */
} range[_POINTER_IOCTL_MAX_POINTS];
};
struct _pointer_ctrl {
struct _interact_device type; /* Device type */
unsigned flags;
short gain;
short threshold;
int state;
};
typedef union {
int number; /* number to perform operations on */
struct {
short integer; /* integer component of number */
unsigned short frac; /* fractional component of number */
} component;
} hex_frac_t;
struct _pointer_matrix {
hex_frac_t xscale, xy;
hex_frac_t yx, yscale;
hex_frac_t xoffset, yoffset;
};
struct _three_point_calib_matrix {
long long An, Bn, Cn, Dn, En, Fn, Divider;
};
struct _pointer_transform {
struct _interact_device type;
struct _pointer_matrix xy_coord; /* Only the first two coordinats are transformed */
struct _pointer_scale {
int min;
int max;
} pressure[_POINTER_IOCTL_MAX_POINTS];
};
#define _POINTERGETINFO __DIOF(_DCMD_INPUT, PTR_OFFSET+0, struct _pointer_info)
#define _POINTERSETCTRL __DIOT(_DCMD_INPUT, PTR_OFFSET+1, struct _pointer_ctrl)
#define _POINTERGETMATRIX __DIOF(_DCMD_INPUT, PTR_OFFSET+2, struct _pointer_matrix)
#define _POINTERSETMATRIX __DIOT(_DCMD_INPUT, PTR_OFFSET+3, struct _pointer_matrix)
#define _POINTERGETCTRL __DIOF(_DCMD_INPUT, PTR_OFFSET+4, struct _pointer_ctrl)
/*--------------------------------------------------------------------------------*/
#define FB_OFFSET 0x30
#define _FEEDBACK_LED_1 0x00000001
#define _FEEDBACK_LED_2 0x00000002
#define _FEEDBACK_LED_3 0x00000004
#define _FEEDBACK_LED_4 0x00000008
#define _FEEDBACK_LED_SCROLL _FEEDBACK_LED_1
#define _FEEDBACK_LED_NUM _FEEDBACK_LED_2
#define _FEEDBACK_LED_CAPS _FEEDBACK_LED_3
struct _feedback_led {
struct _interact_device type;
int value;
int mask;
};
struct _feedback_bell {
struct _interact_device type;
unsigned short flags; /* Flags */
unsigned short frequency; /* In Hz, zero is rest */
unsigned short duration; /* duration in ms */
unsigned short volume; /* USHRT_MAX is full volume */
};
#define _FEEDBACK_BELL_FLAG_FREQ 0x0004
#define _FEEDBACK_BELL_FLAG_DURATION 0x0002
#define _FEEDBACK_BELL_FLAG_VOLUME 0x0001
#define _FEEDBACK_BELL_FLAG_FLUSH 0x0001 /* Flush pending bells */
#define _FEEDBACK_BELL_VOLUME_DFLT (USHRT_MAX/2)
#define _FEEDBACK_STRING_MAX 255
#define _FEEDBACKSETLED __DIOT(_DCMD_INPUT, FB_OFFSET+1, struct _feedback_led)
#define _FEEDBACKGETLED __DIOF(_DCMD_INPUT, FB_OFFSET+2, struct _feedback_led)
#define _FEEDBACKGETLEDMASK __DIOF(_DCMD_INPUT, FB_OFFSET+3, struct _feedback_led)
#define _FEEDBACKBELL __DIOT(_DCMD_INPUT, FB_OFFSET+5, struct _feedback_bell)
#define _FEEDBACKINTEGER __DIOF(_DCMD_INPUT, FB_OFFSET+0xA, int)
#define _FEEDBACKSTRING __DIOT(_DCMD_INPUT, FB_OFFSET+0xF, char[_FEEDBACK_STRING_MAX])
/*--------------------------------------------------------------------------------*/
#define DEVICE_OFFSET 0x40 /* offset of device devctls in the input space */
struct _device_state {
struct _interact_device type;
int state;
};
#define _SETDEVICESTATE __DIOT(_DCMD_INPUT, DEVICE_OFFSET+0, struct _device_state)
#include <_packpop.h>
__END_DECLS
#endif

350
devi/public/sys/devi.h Обычный файл
Просмотреть файл

@ -0,0 +1,350 @@
/*
* (c) 2020, SWD Embedded Systems Limited, http://www.kpda.ru
*/
#ifndef __DEVI_H_INCLUDED__
#define __DEVI_H_INCLUDED__
#include "errdbg.h"
#include <arpa/inet.h>
#include <devctl.h>
#include <errno.h>
#include <fcntl.h>
#include <hw/inout.h>
#include <malloc.h>
#include <process.h>
#include <pthread.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/dcmd_chr.h>
#include <sys/dcmd_input.h>
#include <sys/dcmd_misc.h>
#include <sys/mman.h>
#include <sys/netmgr.h>
#include <sys/neutrino.h>
#include <sys/procfs.h>
#include <sys/procmgr.h>
#include <sys/rsrcdbmgr.h>
#include <sys/rsrcdbmsg.h>
#include <sys/slog.h>
#include <sys/slogcodes.h>
#include <sys/socket.h>
#include <termios.h>
#include <time.h>
#include <unistd.h>
#include <sys/keycodes.h>
#include <sys/keytable.h>
#include <sys/usbcodes.h>
#include <photon/PhT.h>
#define MODULE_TABLE_SIZE 32
#define RESMGR_Q_SIZE 100
#define MAX_SLIDER 16
#define MAX_HAT 16
typedef struct _input_module input_module_t;
typedef struct _devi_attr devi_attr_t;
typedef struct _devi_ocb devi_ocb_t;
typedef _uint8 BYTE;
typedef struct Line {
int flags;
#define DEVI_LINE_HAVE_DEVICE (1 << 0)
#define DEVI_LINE_HAVE_PROTO (1 << 1)
#define DEVI_LINE_HAVE_FILTER (1 << 2)
int type;
/* DEVI_CLASS_* */
struct Line *next;
input_module_t *bottom; /* device layer */
input_module_t *top; /* filter layer (typically) */
pthread_mutex_t mutex;
pthread_cond_t cond;
union {
struct _keyboard_packet *kq;
struct _mouse_packet *mq;
struct _touch1_packet *tq;
struct _joystick_packet *jq;
struct _control_packet *cq;
} u;
int elem_size;
int head;
devi_attr_t *attr;
} event_bus_line_t;
#ifndef IOFUNC_ATTR_T
#define IOFUNC_ATTR_T devi_attr_t
#endif
#ifndef IOFUNC_OCB_T
#define IOFUNC_OCB_T devi_ocb_t
#endif
#ifndef THREAD_POOL_PARAM_T
#define THREAD_POOL_PARAM_T dispatch_context_t
#endif
#include <sys/iofunc.h>
struct _devi_ocb {
iofunc_ocb_t ocb;
uint32_t flags;
#define OCB_UNBLOCK_WANTED (1 << 0)
int read_ptr;
};
struct _ocb_list {
devi_ocb_t *ocb;
struct _ocb_list *prev;
struct _ocb_list *next;
};
struct _devi_attr {
iofunc_attr_t attr;
int ocb_size;
uint32_t flags;
#define DEVI_NOTIFICATION_ARMED (1 << 0)
event_bus_line_t *line;
struct _ocb_list *ocb_list;
struct _wait_q *wait_queue;
iofunc_notify_t notify[3];
};
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
#include <sys/resmgr.h>
#include <sys/dispatch.h>
struct _input_module {
input_module_t *up;
input_module_t *down;
struct Line *line;
int flags;
#define MODULE_FLAG_INUSE (1 << 0)
int type;
#define DEVI_CLASS_MASK 0x000000ff
#define DEVI_CLASS_NONE 0x00000001
#define DEVI_CLASS_KBD 0x00000002
#define DEVI_CLASS_REL 0x00000004
#define DEVI_CLASS_ABS 0x00000008
#define DEVI_CLASS_JOYSTICK 0x00000010
#define DEVI_CLASS_GAMEPAD 0x00000020
#define DEVI_CLASS_CONTROL 0x00000040
#define DEVI_MODULE_TYPE_MASK 0x0000ff00
#define DEVI_MODULE_TYPE_FILTER 0x00000100
#define DEVI_MODULE_TYPE_PROTO 0x00000200
#define DEVI_MODULE_TYPE_DEVICE 0x00000400
char name[12], date[12];
const char *args;
void *data;
int (*init)(input_module_t *);
int (*reset)(input_module_t *);
int (*input)(input_module_t *, int, void *);
int (*output)(input_module_t *, void *, int);
int (*pulse)(message_context_t *, int, unsigned, void *);
int (*parm)(input_module_t *, int, char *);
int (*devctrl)(input_module_t *, int, void *);
int (*shutdown)(input_module_t *, int);
};
/* Common callbacks */
typedef struct _common_callbacks {
int nCallbacks;
int (*pre_init)();
int (*post_init)();
int (*pre_shutdown)();
int (*post_shutdown)();
} common_callbacks_t, * pCommon_callbacks_t;
struct _wait_q {
devi_ocb_t *ocb;
int rcvid;
int nbytes;
struct _wait_q *prev;
struct _wait_q *next;
};
typedef struct _buffer {
char *head;
char *tail;
char *buff;
int cnt;
int bufsize;
int recsize;
pthread_mutex_t mutex;
} buffer_t;
struct packet_rel {
unsigned flags;
#define PTR_TYPE_MASK 0x0f00 /* general flags (all pointing devs) */
#define PTR_Z_DATA 0x0100 /* Z coordinate data available */
int dx;
int dy;
int dz;
unsigned buttons;
/* typically _POINTER_BUTTON_RIGHT, _POINTER_BUTTON_MIDDLE or
* _POINTER_BUTTON_LEFT
*/
struct timespec timestamp;
};
struct packet_abs {
unsigned flags;
/* see const.h, set it to ABSOLUTE|ABS_UNCALIBRATED in the proto module */
unsigned x;
unsigned y;
unsigned z;
unsigned buttons; /* _POINTER_BUTTON_LEFT */
struct timespec timestamp;
};
struct packet_kbd {
struct timespec timestamp;
USBKCode nUSBCode;
unsigned char bMakeBreak;
/* See /usr/include/sys/dcmd_input.h for the format of this field. */
struct _keyboard_data key;
};
struct packet_joystick {
_uint32 x;
_uint32 y;
_uint32 z;
int Rx;
int Ry;
int Rz;
uint16_t function_count; /* Stores the number of sliders in the low bits, and Hats in the high bits */
//unsigned *slider[MAX_SLIDER];
unsigned slider;
//unsigned *hat[MAX_HAT];
unsigned hat_switch;
_uint64 button_state;
struct timespec timestamp;
};
struct packet_control {
_uint64 button_state;
int16_t Rx;
int16_t Ry;
int16_t Rz;
struct timespec timestamp;
};
struct devctl_setbaud {
unsigned baud;
tcflag_t cflag; /* from termios.h */
};
struct devctl_settrig {
int trigger_level;
};
struct devctl_getkbd {
short rate; /* 0 to 31 where 0 is 30Hz */
short delay; /* 0 to 3 where 0 is 250ms, and 3 is 1s */
};
struct devctl_setkbd {
short rate; /* 0 to 31 where 0 is 30Hz */
short delay; /* 0 to 3 where 0 is 250ms, and 3 is 1s */
};
struct devctl_disparea_res {
long xl,xh;
long yl,yh;
};
struct devctl_devcoord {
int swap;
long xl,xh;
long yl,yh;
};
struct devctl_coord_range {
int which;
long min;
long max;
};
struct devctl_led {
int value;
int mask;
};
struct devctl_bell {
unsigned short flags; /* Flags */
unsigned short frequency; /* In Hz, zero is rest */
unsigned short duration; /* duration in ms */
unsigned short volume; /* USHRT_MAX is full volume */
};
struct devctl_rel_accel {
int gain;
int threshold;
};
struct devctl_wheel_accel {
int step;
int accel;
};
struct devctl_abs_mode {
int mode;
};
struct devctl_mouse_types
{
unsigned char type ; /* max level */
unsigned char curtype; /* current level */
};
#define LIST_FIRST_ITEM(head) ((head) -> lh_first)
#define LIST_NEXT_ITEM(elm, field) ((elm == NULL) ? NULL : (elm) -> field.le_next)
#define LIST_PREV_ITEM(elm, field) ((elm == NULL) ? NULL : (elm) -> field.le_prev)
/* Device States */
#define STATE_START 1
#define STATE_STOP 2
#define STATE_RESTART 3
#define STATE_ENABLE 4
#define STATE_DISABLE 5
#define STATE_STANDBY 6
#include "const.h"
#include "externs.h"
#include "proto.h"
#endif

95
devi/public/sys/gfi_iomsg.h Обычный файл
Просмотреть файл

@ -0,0 +1,95 @@
/*
* (c) 2020, SWD Embedded Systems Limited, http://www.kpda.ru
*/
#ifndef __GFI_IOMSG_H_INCLUDED
#define __GFI_IOMSG_H_INCLUDED
#ifndef __IOMSG_H_INCLUDED
#include <sys/iomsg.h>
#endif
#ifndef _GF_GFI_H_INCLUDED
#include <gf/gfi.h>
#endif
#ifndef _IOMGR_INPUT
#define _IOMGR_INPUT 0x16
#endif
/*
* This version number is used to detect version mismatches between the
* GF lib and devi drivers. At every incompatible release, the number should
* be incremented.
*/
#define GFI_VERSION 0x00000001
#define GFI_IOMSG_SIZEOF(u_type) (sizeof (io_msg_t) + sizeof (u_type))
#define GFI_IOMSG_REP_SIZEOF(u_type) (sizeof (int) + sizeof (u_type))
#define GFI_GET_EVENT_MAX 32
typedef struct {
io_msg_t iomsg;
union {
#define GFI_REGISTER_LAYER 0x0001
struct {
_Uint32t gfi_version;
_Int32t z_pos;
} reg;
#define GFI_UNREGISTER_LAYER 0x0002
struct {
_Int32t z_pos;
} unreg;
#define GFI_SET_ATTRS 0x0003
struct {
_Int32t z_pos;
_Int32t x1, y1, x2, y2;
_Uint32t flags; /* See gfi_attr */
} set_attrs;
#define GFI_GET_EVENT 0x0004
struct {
_Int32t nlayers;
_Int32t layer_z_pos[GFI_GET_EVENT_MAX];
_Int32t block;
} get_event;
#define GFI_SET_FOCUS 0x0005
struct {
_Int32t z_pos;
} set_focus;
#define GFI_EMIT_EVENT 0x0006
struct {
_Int32t z_pos;
gfi_event_t ev;
} emit_event;
#define GFI_SET_PTR_CTRL 0x0007
struct {
_Int32t flags;
} set_ptr_ctrl;
#define GFI_SET_PTR_MATRIX4 0x0008
struct {
_Int32t swap;
_Int32t scr_xoffset, scr_yoffset, scr_xscale, scr_yscale;
_Int32t coord_xoffset, coord_yoffset, coord_xscale, coord_yscale;
} set_ptr_matrix4;
#define GFI_SET_PTR_MATRIX3 0x0009
struct {
int64_t An, Bn, Cn, Dn, En, Fn, Divider;
} set_ptr_matrix3;
} u;
} gfi_iomsg_t;
typedef struct {
union {
struct {
} reg;
struct {
gfi_event_t ev;
int got_event;
} get_event;
struct {
} dummy;
} u;
} gfi_iomsg_reply_t;
#endif /* __GFI_IOMSG_H_INCLUDED */

128
devi/public/sys/keymap.h Обычный файл
Просмотреть файл

@ -0,0 +1,128 @@
/*
* (c) 2020, SWD Embedded Systems Limited, http://www.kpda.ru
*/
#ifndef __KEYMAP_H_INCLUDED__
#define __KEYMAP_H_INCLUDED__
#ifndef _STDDEF_H_INCLUDED
#include <stddef.h>
#endif
/* #include "storage.h" */
#include <sys/usbcodes.h>
#define KEY_PRESS (1)
#define KEY_RELEASE (0)
#define IGNORE_COMP 0x01
#define IGNORE_ACTIONS 0x02
#define DONT_NEED_CAP 0
#define NEED_CAP 1
/* Keyboard switchers */
#define KBDMAP_SWITCH_LEFT_ALT_SHIFT (1)
#define KBDMAP_SWITCH_ANY_CTRL_SHIFT (2)
#define KBDMAP_SWITCH_NONE (0)
#define KBDMAP_SWITCH_DEFAULT (KBDMAP_SWITCH_LEFT_ALT_SHIFT)
#ifndef _STORAGE_H
/* struct _modArray; */
typedef struct _modArray * pmod_array_t;
/* struct _actArray; */
typedef struct _actArray * pact_array_t;
/* struct _compArea; */
typedef struct _compArea * pcomp_area_t;
/* struct _keyMapDir; */
typedef struct _keyMapDir * pkey_map_dir_t;
/* structure defines keyboard layout description file header */
typedef struct _stHeader
{
_Uint8t leds[8]; /* table to get LEDs */
_Uint8t stdModArray[32]; /* table to re-map to standard modifiers */
pmod_array_t pMod; /* virtual modifiers */
pact_array_t pAct; /* actions that change modifier state */
pkey_map_dir_t pKMapDir; /* key map directory */
pcomp_area_t pComp; /* area where combinations of codes are located */
/* this area is used for mapping of composed */
/* characters sequences */
} st_header_t, * pst_header_t;
#endif
typedef struct _kmap_data {
struct _stHeader header;
USBKCode lastKey;
char *name;
} kmap_data, * p_kmap_data;
/* Using USB code and current modifiers state, function resolves UNICODE string */
void kmap_get_unicode(pst_header_t pHeader,USBKCode code, int bNeedCAP, wchar_t * pCodes, int * pnLen, int * pIsDeadKey);
/* function processes keyboard activity */
void kmap_process_key_event(pst_header_t pHeader, USBKCode code, int nMakeBreak,
wchar_t * pBuf, int * pnBufLen, int * pFlags);
/* These are processing flags. pFlags is an input/output parameter
* For now we have only one output flag */
#define PFLAG_O_DEAD_KEY 0x01
/* function checks if this is a deadkey code */
int kmap_is_dead_key(pst_header_t pHeader, wchar_t cDeadKeyCode);
/* function returns bit array of standard modifiers */
_Uint32t kmap_get_std_modifiers(pst_header_t pHeader);
/* function returns bit array of LEDs */
_Uint8t kmap_get_leds(pst_header_t pHeader);
/* function sets modifiers' state using new LED state */
void kmap_set_leds(pst_header_t pHeader, _Uint8t leds);
/* function copies keyboard state */
void kmap_copy_keyboard_state(pst_header_t pFrom, pst_header_t pTo);
/* function reset keyboard state */
void kmap_reset_keyboard_state(pst_header_t pHeader);
/* function loads new keyboard definition file */
int kmap_load_kbd_file(const char * fname, pst_header_t pHeader);
/* free allocated memory we don't need more */
int kmap_free_memory(pst_header_t pHeader);
/* load keyboard mapping files */
int kmap_load_keyboards(p_kmap_data * ppData, char * proc_path);
/* Load new mapping file */
int kmap_add_new_keyboard( char * name, p_kmap_data * ppData);
/* Remove keyboard mapping file from memory */
int kmap_remove_keyboard(char * name);
/* Remove keyboard mapping file from memory */
int kmap_remove_all_keyboards();
/* Make another mapping file active */
int kmap_switch_to_keyboard(char * name, p_kmap_data * ppData);
/* Switch to next keyboard */
void kmap_switch_to_next(p_kmap_data * ppData);
/* Number of loaded keyboards */
int kmap_get_num_of_loaded_keyboards();
/* Get keymap descriptor */
int kmap_get_kmap_data_by_name(char * name, p_kmap_data * ppData);
/* Get keymap descriptor */
int kmap_get_kmap_data_by_number(int nKbd, p_kmap_data * ppData);
/* Get current switcher (see constants in the beginning of this file */
int kmap_get_active_switcher();
#endif /* __KEYMAP_H_INCLUDED */

245
devi/public/sys/usbcodes.h Обычный файл
Просмотреть файл

@ -0,0 +1,245 @@
/*
* (c) 2020, SWD Embedded Systems Limited, http://www.kpda.ru
*/
/*
* usbcodes.h
*
* This file includes USB usages (Usb page 0x07 - keyboard/keypad)
*/
#ifndef _USBCODES_H
#define _USBCODES_H
#ifndef __PLATFORM_H_INCLUDED
#include <sys/platform.h>
#endif
typedef _Uint16t USBKCode; /* USB key code */
#define KS_None 0x00
#define KS_a 0x04
#define KS_b 0x05
#define KS_c 0x06
#define KS_d 0x07
#define KS_e 0x08
#define KS_f 0x09
#define KS_g 0x0a
#define KS_h 0x0b
#define KS_i 0x0c
#define KS_j 0x0d
#define KS_k 0x0e
#define KS_l 0x0f
#define KS_m 0x10
#define KS_n 0x11
#define KS_o 0x12
#define KS_p 0x13
#define KS_q 0x14
#define KS_r 0x15
#define KS_s 0x16
#define KS_t 0x17
#define KS_u 0x18
#define KS_v 0x19
#define KS_w 0x1a
#define KS_x 0x1b
#define KS_y 0x1c
#define KS_z 0x1d
#define KS_1 0x1e
#define KS_exclam (KS_1) /* upper case */
#define KS_2 0x1f
#define KS_at (KS_2) /* upper case */
#define KS_3 0x20
#define KS_numbersign (KS_3) /* upper case */
#define KS_4 0x21
#define KS_dollar (KS_4) /* upper case */
#define KS_5 0x22
#define KS_percent (KS_5) /* upper case */
#define KS_6 0x23
#define KS_asciicircum (KS_6) /* upper case */
#define KS_7 0x24
#define KS_ampersand (KS_6) /* upper case */
#define KS_8 0x25
#define KS_asterisk (KS_8) /* upper case */
#define KS_9 0x26
#define KS_parenleft (KS_9) /* upper case */
#define KS_0 0x27
#define KS_parenright (KS_0) /* upper case */
#define KS_Enter 0x28
#define KS_Cmd_Debugger (KS_6) /* upper case */
#define KS_Escape 0x29
#define KS_BackSpace 0x2a
#define KS_Tab 0x2b
#define KS_space 0x2c
#define KS_minus 0x2d
#define KS_underscore (KS_minus) /* upper case */
#define KS_equal 0x2e
#define KS_plus (KS_equal) /* upper case */
#define KS_bracketleft 0x2f
#define KS_braceleft (KS_bracketleft) /* upper case */
#define KS_bracketright 0x30
#define KS_braceright (KS_bracketright) /* upper case */
#define KS_backslash 0x31
#define KS_bar (KS_backslash) /* upper case */
#define KS_NonUSNumsign 0x32
#define KS_asciitilde (KS_NonUSNumsign) /* upper case */
#define KS_semicolon 0x33
#define KS_colon (KS_semicolumn) /* upper case */
#define KS_apostrophe 0x34
#define KS_quotedbl (KS_apostrophe) /* upper case */
#define KS_grave 0x35
#define KS_tilde (KS_grave) /* upper case */
#define KS_comma 0x36
#define KS_less (KS_comma) /* upper case */
#define KS_period 0x37
#define KS_greater (KS_period) /* upper case */
#define KS_slash 0x38
#define KS_question (KS_slash) /* upper case */
#define KS_Caps_Lock 0x39
#define KS_Cmd_Screen0 (KS_Caps_Lock) /* upper case */
#define KS_f1 0x3a
#define KS_Cmd_Screen1 (KS_f1) /* upper case */
#define KS_f2 0x3b
#define KS_Cmd_Screen2 (KS_f2) /* upper case */
#define KS_f3 0x3c
#define KS_Cmd_Screen3 (KS_f3) /* upper case */
#define KS_f4 0x3d
#define KS_Cmd_Screen4 (KS_f4) /* upper case */
#define KS_f5 0x3e
#define KS_Cmd_Screen5 (KS_f5) /* upper case */
#define KS_f6 0x3f
#define KS_Cmd_Screen6 (KS_f6) /* upper case */
#define KS_f7 0x40
#define KS_Cmd_Screen7 (KS_f7) /* upper case */
#define KS_f8 0x41
#define KS_Cmd_Screen8 (KS_f8) /* upper case */
#define KS_f9 0x42
#define KS_Cmd_Screen9 (KS_f9) /* upper case */
#define KS_f10 0x43
#define KS_f11 0x44
#define KS_f12 0x45
#define KS_Print_Screen 0x46
#define KS_Hold_Screen 0x47
#define KS_Pause 0x48
#define KS_Insert 0x49
#define KS_Home 0x4a
#define KS_PgUp 0x4b
#define KS_Delete 0x4c
#define KS_End 0x4d
#define KS_PgDn 0x4e
#define KS_Right 0x4f
#define KS_Left 0x50
#define KS_Down 0x51
#define KS_Up 0x52
#define KS_Num_Lock 0x53
#define KS_KP_Divide 0x54
#define KS_KP_Multiply 0x55
#define KS_KP_Subtract 0x56
#define KS_KP_Add 0x57
#define KS_KP_Enter 0x58
#define KS_KP_End 0x59
#define KS_KP_1 (KS_KP_End) /* Num Lock ON */
#define KS_KP_Down 0x5a
#define KS_KP_2 (KS_KP_Down) /* Num Lock ON */
#define KS_KP_Next 0x5b
#define KS_KP_3 (KS_KP_Next) /* Num Lock ON */
#define KS_KP_Left 0x5c
#define KS_KP_4 (KS_KP_Left) /* Num Lock ON */
#define KS_KP_Begin 0x5d
#define KS_KP_5 (KS_KP_Begin) /* Num Lock ON */
#define KS_KP_Right 0x5e
#define KS_KP_6 (KS_KP_right) /* Num Lock ON */
#define KS_KP_Home 0x5f
#define KS_KP_7 (KS_KP_Home) /* Num Lock ON */
#define KS_KP_Up 0x60
#define KS_KP_8 (KS_KP_Up) /* Num Lock ON */
#define KS_KP_Prior 0x61
#define KS_KP_9 (KS_KP_Prior) /* Num Lock ON */
#define KS_KP_Insert 0x62
#define KS_KP_0 (KS_KP_Insert) /* Num Lock ON */
#define KS_KP_Delete 0x63
#define KS_KP_Decimal (KS_KP_Delete) /* Num Lock ON */
#define KS_NonUSSlash 0x64
#define KS_NonUSBar (KS_NonUSSlash) /* upper case */
#define KS_Application 0x65
#define KS_Power 0x66
#define KS_Keypad_Eq 0x67
#define KS_f13 0x68
#define KS_f14 0x69
#define KS_f15 0x6a
#define KS_f16 0x6b
#define KS_f17 0x6c
#define KS_f18 0x6d
#define KS_f19 0x6e
#define KS_f20 0x6f
#define KS_f21 0x70
#define KS_f22 0x71
#define KS_f23 0x72
#define KS_f24 0x73
#define KS_Execute 0x74
#define KS_Help 0x75
#define KS_Menu 0x76
#define KS_Select 0x77
#define KS_Stop 0x78
#define KS_Again 0x79
#define KS_Undo 0x7a
#define KS_Cut 0x7b
#define KS_Copy 0x7c
#define KS_Paste 0x7d
#define KS_Find 0x7e
#define KS_Mute 0x7f
#define KS_Volume_Up 0x80
#define KS_Volume_Down 0x81
#define KS_LockCpsLock 0x82
#define KS_LockNumLock 0x83
#define KS_LockScrLock 0x84
#define KS_KP_Comma 0x85
#define KS_KP_Equal 0x86
#define KS_Internat1 0x87
#define KS_Internat2 0x88
#define KS_Internat3 0x89
#define KS_Internat4 0x8a
#define KS_Internat5 0x8b
#define KS_Internat6 0x8c
#define KS_Internat7 0x8d
#define KS_Internat8 0x8e
#define KS_Internat9 0x8f
#define KS_Lang1 0x90
#define KS_Lang2 0x91
#define KS_Lang3 0x92
#define KS_Lang4 0x93
#define KS_Lang5 0x94
#define KS_Lang6 0x95
#define KS_Lang7 0x96
#define KS_Lang8 0x97
#define KS_Lang9 0x98
#define KS_AltErase 0x99
#define KS_SysReq 0x9a
#define KS_Cancel 0x9b
#define KS_Clear 0x9c
#define KS_Prior 0x9d
#define KS_Return 0x9e /* Don't confuse with Enter ! */
#define KS_Separator 0x9f
#define KS_Out 0xa0
#define KS_Oper 0xa1
#define KS_ClearAgain 0xa2
#define KS_CrSel_Props 0xa3
#define KS_ExSel 0xa4
/* 0xa5 - 0xdf : reserved */
/* ... many unmapped keys ... */
#define KS_Control_L 0xe0
#define KS_Cmd1 (KS_Control_L)
#define KS_Shift_L 0xe1
#define KS_Alt_L 0xe2
#define KS_Cmd2 (KS_Alt_L)
#define KS_LeftGUI 0xe3
#define KS_Meta_L (KS_LeftGUI)
#define KS_Control_R 0xe4
#define KS_Shift_R 0xe5
#define KS_Alt_R 0xe6
#define KS_Multi_key (KS_Alt_R)
#define KS_RightGUI 0xe7
#define KS_Meta_R (KS_RightGUI)
/* 0xe8-0xffff : reserved */
#endif /* _USBCODES_H */