SmartAudio/package/minigui/libminigui-gpl/patches/003-ial-add-sunxi-keyboard-...

391 lines
9.3 KiB
Diff
Raw Normal View History

2018-07-13 01:31:50 +00:00
--- a/include/common.h
+++ b/include/common.h
@@ -1116,7 +1117,7 @@
* \sa MGUI_NR_KEYS
*/
#ifndef NR_KEYS
-#define NR_KEYS 128
+#define NR_KEYS 135
#endif
/**
@@ -1278,6 +1279,13 @@
#define SCANCODE_RIGHTWIN 126
#define SCANCODE_MENU 127
+#define SCANCODE_SUNXILEFT 128
+#define SCANCODE_SUNXIRIGHT 129
+#define SCANCODE_SUNXIOK 130
+#define SCANCODE_SUNXIMODE 131
+#define SCANCODE_SUNXIPOWER 132
+#define SCANCODE_SUNXIMENU 133
+#define SCANCODE_SUNXIRESET 134
#define SCANCODE_LEFTBUTTON 0x1000
#define SCANCODE_RIGHTBUTTON 0x2000
#define SCANCODE_MIDDLBUTTON 0x4000
--- a/src/ial/Makefile.am
+++ b/src/ial/Makefile.am
@@ -48,6 +48,7 @@
MSTAR_SRCS = mstarial.h mstarial.c
DFB_SRCS = dfb.h dfb.c
+SUNXIKey_SRCS = sunxikey.c sunxikey.h
if MGIAL_CONSOLE
native_libial_la_LIBADD = native/libnative.la
endif
@@ -73,4 +74,5 @@
$(COMMINPUT_SRCS) $(QVFB_SRCS) $(WVFB_SRCS) \
$(QEMU_SRCS) $(IPAQ_H3600_SRCS) $(IPAQ_H5400_SRCS) \
$(TSLIB_SRCS) $(SHANDONG_LIDE_SRCS) $(CISCO_TOUCHPAD_SRCS) \
- $(MSTAR_SRCS) $(DFB_SRCS)
+ $(MSTAR_SRCS) $(DFB_SRCS) \
+ $(SUNXIKey_SRCS)
--- a/src/ial/ial.c
+++ b/src/ial/ial.c
@@ -51,6 +51,7 @@
#ifdef _MGIAL_QVFB
#include "qvfb.h"
#endif
+#include "sunxikey.h"
#ifdef _MGIAL_JZ4740
#include "jz4740.h"
#endif
@@ -124,6 +125,7 @@
#ifdef _MGIAL_QVFB
{"qvfb", InitQVFBInput, TermQVFBInput},
#endif
+ {"sunxikey", InitSUNXIKeyInput, TermSUNXIKeyInput},
#ifdef _MGIAL_JZ4740
{"jz4740", InitJZ4740Input, TermJZ4740Input},
#endif
--- /dev/null
+++ b/src/ial/sunxikey.c
@@ -0,0 +1,226 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <linux/input.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include "common.h"
+#define _MGIAL_SUNXIKEY
+#ifdef _MGIAL_SUNXIKEY
+#include "ial.h"
+#include "sunxikey.h"
+
+#define PRESS_INSISTENTLY 1
+#define PRESS_QUICKLY 0
+
+#define TIME_USE(end, start) \
+(((end.tv_sec-start.tv_sec)*1000000+(end.tv_usec-start.tv_usec))/1000)
+
+/*static struct input_event key;*/
+static int mouse_x, mouse_y, mouse_button;
+static unsigned char state[NR_KEYS];
+static int fd_key;
+static int fd_key_power;
+static int cur_key = -2;
+
+static int mouse_update (void)
+{
+ return 1;
+}
+
+static void mouse_getxy (int* x, int* y)
+{
+ *x = mouse_x;
+ *y = mouse_y;
+}
+
+static int mouse_getbutton(void)
+{
+ return mouse_button;
+}
+
+static int castkey2scancode(void)
+{
+ int i;
+
+ for (i=0; i<SUNXI_KEY_CNT; i++) {
+ if(cur_key == key_set[i].keyCode)
+ return key_set[i].scancode;
+ }
+
+ return -1;
+
+/* switch(cur_key) {
+ case SUNXI_KEY_LEFT:
+ return SCANCODE_SUNXILEFT;
+ case SUNXI_KEY_RIGHT:
+ return SCANCODE_SUNXIRIGHT;
+ case SUNXI_KEY_MODE:
+ return SCANCODE_SUNXIMODE;
+ case SUNXI_KEY_OK:
+ return SCANCODE_SUNXIOK;
+ case SUNXI_KEY_POWER:
+ return SCANCODE_SUNXIPOWER;
+ case SUNXI_KEY_MENU:
+ return SCANCODE_SUNXIMENU;
+ default:
+ return -1;
+ }*/
+}
+static int unknown_key_down = 0;
+static int keyboard_update(void)
+{
+ if (cur_key < 0) {
+ memset(state, 0, sizeof(state));
+ cur_key = -2;
+ } else {
+ int scancode = castkey2scancode();
+ if(scancode < 0) {
+ fprintf(stderr, "IAL: unknown key pressed <%d>\n", cur_key);
+ cur_key = -1;
+ unknown_key_down = 1;
+ return -1;
+ } else {
+ state[scancode] = 1;
+ }
+ }
+
+ return NR_KEYS;
+}
+
+static const char* keyboard_getstate(void)
+{
+ return (char *) state;
+}
+
+static int wait_event (int which, int maxfd, fd_set *in, fd_set *out,
+ fd_set *except, struct timeval *timeout)
+{
+ fd_set rfds;
+ int e;
+ struct input_event key;
+
+ if(which & IAL_KEYEVENT) {
+ if(!in) {
+ in = &rfds;
+ FD_ZERO(in);
+ }
+
+ FD_SET(fd_key, in);
+ if(fd_key > maxfd)
+ maxfd = fd_key;
+ if (fd_key_power > 0) {
+ FD_SET(fd_key_power, in);
+ if(fd_key_power > maxfd)
+ maxfd = fd_key_power;
+ }
+ }
+
+ e = select (maxfd+1, in, out, except, timeout);
+ if (e < 0)
+ return -1;
+
+ if(e > 0) {
+ if(FD_ISSET(fd_key, in)) {
+ FD_CLR(fd_key, in);
+ read(fd_key, &key, sizeof(key));
+ if (0 == key.code)
+ return -1;
+ else if (key.value > 0)
+ cur_key = key.code;
+ else {
+ if (unknown_key_down) {
+ unknown_key_down = 0;
+ return -1;
+ }
+ cur_key = -1;
+ }
+ return IAL_KEYEVENT;
+ }
+ if (fd_key_power > 0) {
+ if(FD_ISSET(fd_key_power, in)) {
+ FD_CLR(fd_key_power, in);
+ read(fd_key_power, &key, sizeof(key));
+ if (0 == key.code)
+ return -1;
+ else if (key.value > 0)
+ cur_key = key.code;
+ else
+ cur_key = -1;
+ return IAL_KEYEVENT;
+ }
+ }
+ }
+ return -1;
+}
+
+#define STREQUAL(str1, str2) (!strcmp(str1, str2))
+
+static int isKeyName(const char *name)
+{
+ int i;
+ for (i=0; i<SUNXI_KEY_CNT; i++) {
+ if(STREQUAL(name, key_set[i].name))
+ return i;
+ }
+
+ return -1;
+}
+
+static void initKeyCode(void)
+{
+ FILE *pRead;
+ char sKey[16];
+ char sName[32];
+ int iCode;
+ int idx;
+
+ pRead = fopen(KEYCODE_FILE,"r");
+ if (pRead == NULL) {
+ return;
+ }
+ while(EOF!=fscanf(pRead, "%s%d%s", sKey, &iCode, sName)) {
+ idx = isKeyName(sName);
+ if (idx >= 0)
+ key_set[idx].keyCode = iCode;
+ }
+ fclose(pRead);
+}
+
+BOOL InitSUNXIKeyInput(INPUT* input, const char* mdev, const char* mtype)
+{
+ fd_key = open(mdev, O_RDONLY);
+ if (fd_key < 0) {
+ _MG_PRINTF ("IAL>%s: Can not open touch screen device: %s!\n", __FILE__, mdev);
+ return FALSE;
+ }
+ fd_key_power = open("/dev/input/event1", O_RDONLY);
+ if (fd_key_power < 0) {
+ _MG_PRINTF ("IAL>%s: Can not open touch screen device: %s!\n",
+ __FILE__, "/dev/input/event1");
+ }
+ input->update_mouse = mouse_update;
+ input->get_mouse_xy = mouse_getxy;
+ input->set_mouse_xy = NULL;
+ input->get_mouse_button = mouse_getbutton;
+ input->set_mouse_range = NULL;
+
+ input->update_keyboard = keyboard_update;
+ input->get_keyboard_state = keyboard_getstate;
+ input->set_leds = NULL;
+
+ input->wait_event = wait_event;
+
+ mouse_x = 0;
+ mouse_y = 0;
+ mouse_button= 0;
+ initKeyCode();
+ return TRUE;
+}
+
+void TermSUNXIKeyInput (void)
+{
+ close(fd_key);
+}
+#endif
--- /dev/null
+++ b/src/ial/sunxikey.h
@@ -0,0 +1,51 @@
+#ifndef GUI_IAL_SUNXIKEY_H
+
+#define GUI_IAL_SUNXIKEY_H
+
+/*
+#define SUNXI_KEY_LEFT 139
+#define SUNXI_KEY_RIGHT 217
+#define SUNXI_KEY_MODE 115
+#define SUNXI_KEY_OK 102
+#define SUNXI_KEY_POWER 116
+#define SUNXI_KEY_MENU 118
+*/
+#define KEYCODE_FILE "/etc/sunxi-keyboard.kl"
+
+#define STR_UP "UP"
+#define STR_DOWN "DOWN"
+#define STR_MENU "MENU"
+#define STR_OK "OK"
+#define STR_POWER "POWER"
+#define STR_MODE "MODE"
+#define STR_RESET "RESET"
+
+#define SUNXI_KEY_CNT 7
+
+typedef struct sunxi_key_t
+{
+ int keyCode;
+ char *name;
+ int scancode;
+}sunxi_key_t;
+
+static sunxi_key_t key_set[SUNXI_KEY_CNT] = {
+ {0, STR_UP, SCANCODE_SUNXILEFT},
+ {0, STR_DOWN, SCANCODE_SUNXIRIGHT},
+ {0, STR_MENU, SCANCODE_SUNXIMENU},
+ {0, STR_OK, SCANCODE_SUNXIOK},
+ {0, STR_POWER, SCANCODE_SUNXIPOWER},
+ {0, STR_MODE, SCANCODE_SUNXIMODE},
+ {0, STR_RESET, SCANCODE_SUNXIRESET}
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+BOOL InitSUNXIKeyInput (INPUT* input, const char* mdev, const char* mtype);
+void TermSUNXIKeyInput (void);
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif
--- a/src/ial/tslibial.c
+++ b/src/ial/tslibial.c
@@ -59,6 +59,9 @@
static int mousey = 0;
static int button = 0;
+static int reversed = 0;
+static int screen_width = 0;
+static int screen_height = 0;
/************************ Low Level Input Operations **********************/
/*
* Mouse operations -- Event
@@ -69,8 +72,13 @@
if (ts_read (ts, &samp, 1) > 0) {
if (samp.pressure > 0) {
+ if (reversed) {
+ mousex = screen_width - samp.x;
+ mousey = screen_height - samp.y;
+ } else {
mousex = samp.x;
mousey = samp.y;
+ }
}
button = (samp.pressure > 0) ? IAL_MOUSE_LEFTBUTTON : 0;
@@ -135,6 +143,7 @@
{
const char* tsdevice;
+ fprintf(stderr, "InitTSLibInput\n");
if ((tsdevice = getenv ("TSLIB_TSDEVICE")) == NULL) {
tsdevice = mdev;
}
@@ -163,6 +172,13 @@
input->set_mouse_range = NULL;
input->wait_event = wait_event;
+ screen_width = __gal_screen->w;
+ screen_height = __gal_screen->h;
+ const char *need_reversed = NULL;
+ if ((need_reversed = getenv ("MG_TS_REVERSED")) != NULL) {
+ reversed = 1;
+ }
+ fprintf(stderr, "InitTSLibInput finish\n");
return TRUE;
}