Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 522 → Rev 523

/shark/trunk/drivers/input/shark/shark_mouse.c
35,7 → 35,8
*
*/
 
#define __MOUSE_DEBUG__
//#define __MOUSE_DEBUG__
//#define MOUSE_TASK
 
#include <kernel/kern.h>
 
50,54 → 51,244
extern int mouse_init(void);
extern void mouse_exit(void);
 
/* Functions */
extern int mouse_get(int *dx, int *dy, int *dz, unsigned long *buttons);
 
extern int input_installed;
 
/* Mouse driver currently installed */
/* Mouse driver currently installed/actived */
static int mouse_installed = FALSE;
static int mouse_enabled = FALSE;
 
/*static short int mouse_lim_x1 = 0;
static short int mouse_lim_y1 = 0;
static short int mouse_lim_x2 = 79;
static short int mouse_lim_y2 = 24;
static short int mouse_x = 40;
static short int mouse_x_mick = 0;
static short int mouse_y = 12;
static short int mouse_y_mick = 0;
static short int mouse_buttons = 0;
static short int mouse_thresholdlim = 5;
static int mouse_xmin_tick;
static int mouse_ymin_tick;
static int mouse_xmax_tick;
static int mouse_ymax_tick;
 
#define MOUSE_DEF_THRESHOLD 10
static int mouse_threshold;
 
static int mouse_x = 0;
static int mouse_y = 0;
static int mouse_x_tick = 0;
static int mouse_y_tick = 0;
static int mouse_z = 0;
static unsigned long mouse_buttons = 0;
 
static MOUSE_HANDLER mouse_handler = NULL;
static MOUSE_HANDLER user_mouse_handler = NULL;
 
static int autocursormode=DISABLE;
#ifdef MOUSE_TASK
/* mouse task PID */
static PID mousepid = NIL;
#else
void mouseProc(void);
#endif
 
static PID mouse_pid = NIL;*/
 
 
/*
* Start mouseProc Task
*/
void shark_mouse_task(void)
void shark_mouse_exec(void)
{
//task_activate(mousebpid);
#ifdef MOUSE_TASK
task_activate(mousepid);
#else
mouseProc();
#endif
}
 
#ifdef MOUSE_TASK
TASK mouseProc(void)
#else
void mouseProc(void)
#endif
{
static MOUSE_EVT ev;
unsigned long dbuttons;
int dx, dy, dz;
int res;
#ifdef MOUSE_TASK
while (1) {
#endif
if (mouse_enabled) {
res = mouse_get(&dx, &dy, &dz, &dbuttons);
if (res >= 0) {
mouse_x_tick += dx;
if (mouse_x_tick < mouse_xmin_tick)
mouse_x_tick = mouse_xmin_tick;
if (mouse_x_tick > mouse_xmax_tick)
mouse_x_tick = mouse_xmax_tick;
mouse_x = (mouse_x_tick + (mouse_threshold/2)) / mouse_threshold;
ev.x = mouse_x;
ev.dx = dx;
 
mouse_y_tick -= dy;
if (mouse_y_tick < mouse_ymin_tick)
mouse_y_tick = mouse_ymin_tick;
if (mouse_y_tick > mouse_ymax_tick)
mouse_y_tick = mouse_ymax_tick;
mouse_y = (mouse_y_tick + (mouse_threshold/2)) / mouse_threshold;
ev.y = mouse_y;
ev.dy = dy;
 
mouse_z += dz;
ev.z = mouse_z;
ev.dz = dz;
 
mouse_buttons = dbuttons;
ev.buttons = mouse_buttons;
#ifdef __MOUSE_DEBUG__
printk(KERN_DEBUG "shark_mouse.c: delta ( %3d %3d %3d - %6x) -> ( %3d %3d %3d - %6x)\n",
dx, dy, dz, (int)dbuttons, mouse_x, mouse_y, mouse_z, (int)mouse_buttons);
#endif
/* mouse handler */
if (mouse_handler!=NULL) mouse_handler(&ev);
}
}
#ifdef MOUSE_TASK
task_endcycle();
}
#endif
}
 
/**** Start User Functions ****/
 
void mouse_enable(void)
{
mouse_enabled = TRUE; /* TODO */
}
 
void mouse_disable(void)
{
mouse_enabled = FALSE; /* TODO */
}
 
void mouse_getpos(int *x,int *y,int *z, unsigned long *buttons)
{
*x = mouse_x;
*y = mouse_y;
*z = mouse_z;
*buttons = mouse_buttons;
}
 
void mouse_setpos(int x,int y, int z)
{
mouse_enabled = FALSE;
mouse_x = x;
if (x < (mouse_xmin_tick / mouse_threshold))
mouse_x = mouse_xmin_tick / mouse_threshold;
if (x > (mouse_xmax_tick / mouse_threshold))
mouse_x = mouse_xmax_tick / mouse_threshold;
mouse_y = y;
if (y < (mouse_ymin_tick / mouse_threshold))
mouse_y = mouse_ymin_tick / mouse_threshold;
if (y > (mouse_ymax_tick / mouse_threshold))
mouse_y = mouse_ymax_tick / mouse_threshold;
 
mouse_z = z;
 
mouse_enabled = TRUE;
}
 
void mouse_getlimit(int *xmin, int *ymin, int *xmax, int *ymax)
{
*xmin = mouse_xmin_tick / mouse_threshold;
*ymin = mouse_ymin_tick / mouse_threshold;
*xmax = mouse_xmax_tick / mouse_threshold;
*ymax = mouse_ymax_tick / mouse_threshold;
}
 
int mouse_setlimit(int xmin, int ymin, int xmax, int ymax)
{
if ((xmin < 0) && (ymin < 0) && (xmax < xmin) && (ymax < ymin))
return -1;
 
mouse_xmin_tick = xmin * mouse_threshold;
mouse_ymin_tick = ymin * mouse_threshold;
mouse_xmax_tick = xmax * mouse_threshold;
mouse_ymax_tick = ymax * mouse_threshold;
return 0;
}
 
void mouse_hook(MOUSE_HANDLER h)
{
mouse_handler = h;
}
 
int mouse_getthreshold(void)
{
return mouse_threshold;
}
 
int mouse_setthreshold(int t)
{
mouse_enabled = FALSE;
 
if ((t>0) && (t<=200)) {
mouse_xmin_tick = (mouse_xmin_tick * t) / mouse_threshold;
mouse_ymin_tick = (mouse_ymin_tick * t) / mouse_threshold;
mouse_xmax_tick = (mouse_xmax_tick * t) / mouse_threshold;
mouse_ymax_tick = (mouse_ymax_tick * t) / mouse_threshold;
mouse_threshold = t;
return 0;
} else {
return -1;
}
 
mouse_enabled = TRUE;
}
 
/**** End User Functions ****/
 
/* Init the Linux Speaker Driver */
/*int MOUSE26_init(MOUSE_PARMS *s)*/
int MOUSE26_init(void)
int MOUSE26_init(MOUSE_PARMS *s)
{
/*MOUSE_PARMS mparms=BASE_MOUSE;
TASK_MODEL *m;
SOFT_TASK_MODEL base_m;*/
MOUSE_PARMS mparms = BASE_MOUSE;
int status = 0;
 
#ifdef MOUSE_TASK
TASK_MODEL *m;
SOFT_TASK_MODEL base_m;
#endif
 
if (mouse_installed == TRUE) return 0;
 
/* if a NULL is passed */
/*if (s == NULL)
if (s == NULL)
s = &mparms;
 
/* set mouse threshold */
if (s->threshold == (int) MOUSE_DEFAULT)
mouse_threshold = MOUSE_DEF_THRESHOLD;
else
mouse_threshold = s->threshold;
 
/* set mouse limits */
if ((s->xmin == (int) MOUSE_DEFAULT) || (s->xmin < 0))
mouse_xmin_tick = 0;
else
mouse_xmin_tick = s->xmin * mouse_threshold;
if ((s->ymin == (int) MOUSE_DEFAULT) || (s->ymin < 0))
mouse_ymin_tick = 0;
else
mouse_ymin_tick = s->ymin * mouse_threshold;
if ((s->xmax == (int) MOUSE_DEFAULT) || ((s->xmax * mouse_threshold) < mouse_xmin_tick))
mouse_xmax_tick = 79 * mouse_threshold;
else
mouse_xmax_tick = s->xmax * mouse_threshold;
if ((s->ymax == (int) MOUSE_DEFAULT) || ((s->ymax * mouse_threshold) < mouse_ymin_tick))
mouse_ymax_tick = 24 * mouse_threshold;
else
mouse_ymax_tick = s->ymax * mouse_threshold;
 
#ifdef MOUSE_TASK
if (s->tm == (TASK_MODEL *)MOUSE_DEFAULT) {
soft_task_default_model(base_m);
soft_task_def_wcet(base_m,2000);
108,11 → 299,18
soft_task_def_aperiodic(base_m);
m = (TASK_MODEL *)&base_m;
} else
m = parms->tm;*/
m = s->tm;
 
mousepid = task_create ("MouseTask", mouseProc, m, NULL);
if (mousepid == -1) {
return -1;
}
#endif
 
if (input_installed == FALSE) {
status = INPUT26_init();
if (status) {
printk(KERN_ERR "shark_mouse.c: Unable to open Input SubSystem.\n");
return -1;
}
131,6 → 329,7
}
mouse_installed = TRUE;
mouse_enabled = TRUE;
return status;
}
137,12 → 336,29
 
int MOUSE26_close()
{
#ifdef MOUSE_TASK
int free;
SYS_FLAGS f;
#endif
 
if (!mouse_installed)
return -1;
 
mouse_enabled = FALSE;
mouse_exit();
psmouse_exit();
 
#ifdef MOUSE_TASK
f = kern_fsave();
free = (proc_table[mousepid].status == FREE);
kern_frestore(f);
#ifdef __MOUSE_DEBUG__
printk(KERN_DEBUG "shark_mouse.c: MouseTask is %s.\n", free ? "killed" : "alive");
#endif
if (free)
task_kill (mousepid);
#endif
 
mouse_installed = FALSE;
return 0;
/shark/trunk/drivers/input/shark/shark_keyb.c
39,7 → 39,7
*/
 
//#define __KEYB_DEBUG__
//#define KEYB_TASK
#define KEYB_TASK
 
#include <kernel/kern.h>
#include <signal.h>
56,10 → 56,9
extern int kbd_init(void);
extern int kbd_exit(void);
 
/* Functions */
extern int kbd_enable(void);
extern int kbd_disable(void);
 
/* Functions */
extern int kbd_get(unsigned int *data, BYTE access);
extern void kbd_setleds(unsigned int led);
extern int kbd_rate(unsigned int *delay, unsigned int *period);
113,7 → 112,7
/* keyboard task PID */
static PID keybpid;
#else
void keyProc(void);
static void keyProc(void);
#endif
 
/*
330,7 → 329,7
#ifdef KEYB_TASK
TASK keyProc(void)
#else
void keyProc(void)
static void keyProc(void)
#endif
{
WORD code;
360,14 → 359,18
#endif
found = FALSE;
for (i = 0; i < lastExc; i++)
if ((keyExcTable[i].evt.scan == dt.scan) && (keyExcTable[i].evt.flag == dt.flag) && (keyExcTable[i].evt.status == dt.status)) {
if ((keyExcTable[i].evt.scan == dt.scan) &&
(keyExcTable[i].evt.flag == dt.flag) &&
(keyExcTable[i].evt.status == dt.status)) {
#ifdef __KEYB_DEBUG__
printk("shark_keyb.c: Key_Hook ( %2x - %2x - %1d) -> ( %2x - %2x - %1d)\n", dt.scan, dt.flag, dt.status, keyExcTable[i].evt.scan, keyExcTable[i].evt.flag, keyExcTable[i].evt.status);
printk("shark_keyb.c: Key_Hook ( %2x - %2x - %1d) -> ( %2x - %2x - %1d)\n",
dt.scan, dt.flag, dt.status,
keyExcTable[i].evt.scan, keyExcTable[i].evt.flag, keyExcTable[i].evt.status);
#endif
keyExcTable[i].func(&dt);
if (keyExcTable[i].lock == TRUE)
found = TRUE;
}
}
/* when the port is full, data is lost */
if (!found)
port_send(pkeyPort, (BYTE *) (&dt), NON_BLOCK);
383,9 → 386,8
void default_ctrlChandler(KEY_EVT * k) {
set_active_page(0);
set_visual_page(0);
cputs("Ctrl-C pressed!\n");
//cputs("Ctrl-C pressed!\n");
sys_end();
//exit(1);
}
 
/**** Start User Functions ****/
393,13 → 395,19
/* Function that returns the ascii code */
BYTE keyb_getch(BYTE wait)
{
KEY_EVT c;
KEY_EVT ev;
BYTE fl;
 
fl = port_receive (ukeyPort, &c, wait);
if (fl && !isScanCode(c) && !isReleased(c))
return (c.ascii);
else
fl = port_receive (ukeyPort, &ev, wait);
if (fl) {
#ifdef __KEYB_DEBUG__
printk("shark_keyb.c: GetChar ( %2x - %c - %2x - %1d)\n", ev.scan, ev.ascii, ev.flag, ev.status);
#endif
if (!isScanCode(ev) && !isReleased(ev))
return (ev.ascii);
else
return 0;
} else
return 0;
}
 
423,7 → 431,7
return;
}
 
/* MG: this function disable the keyboard */
/* This function disable the keyboard */
int keyb_disable(void)
{
kbd_disable();
430,7 → 438,7
return 0;
}
 
/* MG: this function enable the keyboard */
/* This function enable the keyboard */
int keyb_enable(void)
{
kbd_enable();
437,7 → 445,7
return 0;
}
 
/**** End Functions ****/
/**** End User Functions ****/
 
int KEYB26_init(KEYB_PARMS *s)
{
466,11 → 474,10
if (s->keymap == (unsigned char)KEYB_DEFAULT) s->keymap = KEYMAP_US;
keyb_set_map(s->keymap);
 
/* MG: changed RECEIVE to STREAM port - added a failure test */
pkeyPort = port_create ("KeybPort", 3, 20, STREAM, WRITE);
pkeyPort = port_create ("KeybPort", sizeof(KEY_EVT), 20, STREAM, WRITE);
if (pkeyPort == -1)
return -2;
ukeyPort = port_connect ("KeybPort", 3, STREAM, READ);
ukeyPort = port_connect ("KeybPort", sizeof(KEY_EVT), STREAM, READ);
if (ukeyPort == -1) {
port_delete (pkeyPort);
return -3;
484,11 → 491,12
s->ctrlcfunc = (void *) default_ctrlChandler;
if (s->ctrlcfunc != NULL) {
KEY_EVT emerg;
emerg.ascii = 'c';
emerg.scan = KEY_C;
emerg.flag = CNTL_BIT;
emerg.ascii = 'c';
emerg.scan = KEY_C;
emerg.status = KEY_PRESSED;
emerg.flag = CNTL_BIT;
keyb_hook (emerg, s->ctrlcfunc, TRUE);
emerg.flag = CNTR_BIT;
emerg.flag = CNTR_BIT;
keyb_hook (emerg, s->ctrlcfunc, TRUE);
}
 
520,31 → 528,28
 
if (input_installed == FALSE)
if (INPUT26_init()) {
#ifdef __KEYB_DEBUG__
printk(KERN_ERR "shark_keyb.c: Unable to open Input SubSystem.\n");
#endif
port_delete (pkeyPort);
port_delete (ukeyPort);
task_kill (keybpid);
return -1;
}
 
status = atkbd_init();
if (status) {
#ifdef __KEYB_DEBUG__
printk(KERN_ERR "shark_keyb.c: AtKbd_Init return: %d\n", status);
#endif
port_delete (pkeyPort);
port_delete (ukeyPort);
task_kill (keybpid);
return -1;
}
status = kbd_init();
if (status) {
#ifdef __KEYB_DEBUG__
printk(KERN_ERR "shark_keyb.c: Kbd_Init return: %d\n", status);
#endif
port_delete (pkeyPort);
port_delete (ukeyPort);
task_kill (keybpid);
return -1;
}