projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update for new emulator.
[bertos.git]
/
drv
/
kbd.c
diff --git
a/drv/kbd.c
b/drv/kbd.c
index d078418cf1dceae5218413e96cb37d3d23ca489e..f85f897c2b3c48cc60efb49d8374946f168bb78b 100755
(executable)
--- a/
drv/kbd.c
+++ b/
drv/kbd.c
@@
-17,6
+17,15
@@
/*#*
*#* $Log$
/*#*
*#* $Log$
+ *#* Revision 1.4 2006/02/24 00:27:14 bernie
+ *#* Use new naming convention for list macros.
+ *#*
+ *#* Revision 1.3 2006/02/17 21:15:42 bernie
+ *#* Add MOD_CHECK() checks.
+ *#*
+ *#* Revision 1.2 2006/02/10 12:36:20 bernie
+ *#* Add preliminary FreeRTOS support; Enforce CONFIG_* definitions.
+ *#*
*#* Revision 1.1 2005/06/27 21:28:45 bernie
*#* Import generic keyboard driver.
*#*
*#* Revision 1.1 2005/06/27 21:28:45 bernie
*#* Import generic keyboard driver.
*#*
@@
-29,8
+38,12
@@
#include <drv/buzzer.h>
#include <cfg/debug.h>
#include <drv/buzzer.h>
#include <cfg/debug.h>
+#include <cfg/module.h>
-
+/* Configuration sanity checks */
+#if !defined(CONFIG_KBD_POLL) || (CONFIG_KBD_POLL != KBD_POLL_SOFTINT && CONFIG_KBD_POLL != CONFIG_POLL_FREERTOS)
+ #error CONFIG_KBD_POLL must be defined to either KBD_POLL_SOFTINT or CONFIG_POLL_FREERTOS
+#endif
#define KBD_CHECK_INTERVAL 10 /*!< (ms) Timing for kbd softint */
#define KBD_CHECK_INTERVAL 10 /*!< (ms) Timing for kbd softint */
@@
-52,7
+65,7
@@
static enum { KS_IDLE, KS_REPDELAY, KS_REPEAT } kbd_rptStatus;
static volatile keymask_t kbd_buf; /*!< Single entry keyboard buffer */
static volatile keymask_t kbd_cnt; /*!< Number of keypress events in \c kbd_buf */
static volatile keymask_t kbd_buf; /*!< Single entry keyboard buffer */
static volatile keymask_t kbd_cnt; /*!< Number of keypress events in \c kbd_buf */
-static Timer kbd_timer; /*!< Keyboard
KBD_BEEP_TIME
softtimer */
+static Timer kbd_timer; /*!< Keyboard softtimer */
static List kbd_rawHandlers; /*!< Raw keyboard handlers */
static List kbd_handlers; /*!< Cooked keyboard handlers */
static List kbd_rawHandlers; /*!< Raw keyboard handlers */
static List kbd_handlers; /*!< Cooked keyboard handlers */
@@
-67,9
+80,15
@@
static KbdHandler kbd_lngHandler; /*!< Long pression keys handler */
/*!
/*!
- * Keyboard soft-irq handler.
+ * Poll keyboard and dispatch keys to handlers.
+ *
+ * Read the key states and invoke all keyboard
+ * handlers to process the new state.
+ *
+ * Call this function periodically using a software
+ * timer, an interrupt or a process.
*/
*/
-static void kbd_
softint(UNUSED_ARG(iptr_t, arg)
)
+static void kbd_
poll(void
)
{
/*! Currently depressed key */
static keymask_t current_key;
{
/*! Currently depressed key */
static keymask_t current_key;
@@
-78,7
+97,7
@@
static void kbd_softint(UNUSED_ARG(iptr_t, arg))
keymask_t key = kbd_readkeys();
/* Call raw input handlers */
keymask_t key = kbd_readkeys();
/* Call raw input handlers */
- FOREACHNODE(handler, &kbd_rawHandlers)
+ FOREACH
_
NODE(handler, &kbd_rawHandlers)
key = handler->hook(key);
/* If this key was not previously pressed */
key = handler->hook(key);
/* If this key was not previously pressed */
@@
-88,13
+107,37
@@
static void kbd_softint(UNUSED_ARG(iptr_t, arg))
current_key = key;
/* Call cooked input handlers */
current_key = key;
/* Call cooked input handlers */
- FOREACHNODE(handler, &kbd_handlers)
+ FOREACH
_
NODE(handler, &kbd_handlers)
key = handler->hook(key);
}
key = handler->hook(key);
}
+}
+#if CONFIG_KBD_POLL == KBD_POLL_SOFTINT
+
+/*!
+ * Keyboard soft-irq handler.
+ */
+static void kbd_softint(UNUSED_ARG(iptr_t, arg))
+{
+ kbd_poll();
timer_add(&kbd_timer);
}
timer_add(&kbd_timer);
}
+#elif CONFIG_KBD_POLL == CONFIG_POLL_FREERTOS
+
+#include "FreeRTOS.h"
+#include "task.h"
+
+static portTASK_FUNCTION(kbd_poll, arg)
+{
+ for (;;)
+ {
+ kbd_poll(0);
+ timer_delay(KBD_CHECK_INTERVAL);
+ }
+}
+
+#endif /* CONFIG_KBD_POLL */
/*!
* \brief Read a key from the keyboard buffer.
/*!
* \brief Read a key from the keyboard buffer.
@@
-112,6
+155,10
@@
keymask_t kbd_peek(void)
{
keymask_t key = 0;
{
keymask_t key = 0;
+// FIXME
+ extern void schedule(void);
+ schedule();
+
/* Extract an event from the keyboard buffer */
IRQ_DISABLE;
if (kbd_cnt)
/* Extract an event from the keyboard buffer */
IRQ_DISABLE;
if (kbd_cnt)
@@
-177,12
+224,12
@@
void kbd_addHandler(struct KbdHandler *handler)
* Search for the first node whose priority
* is lower than the timer we want to add.
*/
* Search for the first node whose priority
* is lower than the timer we want to add.
*/
- FOREACHNODE(node,list)
+ FOREACH
_
NODE(node,list)
if (node->pri < handler->pri)
break;
/* Enqueue handler in the handlers chain */
if (node->pri < handler->pri)
break;
/* Enqueue handler in the handlers chain */
- INSERTBEFORE(&handler->link, &node->link);
+ INSERT
_
BEFORE(&handler->link, &node->link);
IRQ_RESTORE(flags);
}
IRQ_RESTORE(flags);
}
@@
-209,8
+256,10
@@
static keymask_t kbd_defHandlerFunc(keymask_t key)
kbd_buf = key;
kbd_cnt = 1;
kbd_buf = key;
kbd_cnt = 1;
+#if KBD_BEEP_TIME
if (!(key & K_REPEAT))
buz_beep(KBD_BEEP_TIME);
if (!(key & K_REPEAT))
buz_beep(KBD_BEEP_TIME);
+#endif
}
/* Eat all input */
}
/* Eat all input */
@@
-337,20
+386,17
@@
static keymask_t kbd_rptHandlerFunc(keymask_t key)
}
}
+MOD_DEFINE(kbd)
/*!
* Initialize keyboard ports and softtimer
*/
void kbd_init(void)
{
/*!
* Initialize keyboard ports and softtimer
*/
void kbd_init(void)
{
-
- cpuflags_t flags;
- IRQ_SAVE_DISABLE(flags);
+ MOD_CHECK(buzzer);
KBD_HW_INIT;
KBD_HW_INIT;
- IRQ_RESTORE(flags);
-
/* Init handlers lists */
LIST_INIT(&kbd_handlers);
LIST_INIT(&kbd_rawHandlers);
/* Init handlers lists */
LIST_INIT(&kbd_handlers);
LIST_INIT(&kbd_rawHandlers);
@@
-369,21
+415,35
@@
void kbd_init(void)
kbd_addHandler(&kbd_lngHandler);
#endif
kbd_addHandler(&kbd_lngHandler);
#endif
-
/* Add repeat keyboard handler */
kbd_rptHandler.hook = kbd_rptHandlerFunc;
kbd_rptHandler.pri = 80; /* high priority */
kbd_rptHandler.flags = KHF_RAWKEYS;
kbd_addHandler(&kbd_rptHandler);
/* Add repeat keyboard handler */
kbd_rptHandler.hook = kbd_rptHandlerFunc;
kbd_rptHandler.pri = 80; /* high priority */
kbd_rptHandler.flags = KHF_RAWKEYS;
kbd_addHandler(&kbd_rptHandler);
-
/* Add default keyboard handler */
kbd_defHandler.hook = kbd_defHandlerFunc;
kbd_defHandler.pri = -128; /* lowest priority */
kbd_addHandler(&kbd_defHandler);
/* Add default keyboard handler */
kbd_defHandler.hook = kbd_defHandlerFunc;
kbd_defHandler.pri = -128; /* lowest priority */
kbd_addHandler(&kbd_defHandler);
+#if CONFIG_KBD_POLL == KBD_POLL_SOFTINT
+
+ MOD_CHECK(timer);
+
/* Add kbd handler to soft timers list */
event_initSoftInt(&kbd_timer.expire, kbd_softint, 0);
timer_setDelay(&kbd_timer, ms_to_ticks(KBD_CHECK_INTERVAL));
timer_add(&kbd_timer);
/* Add kbd handler to soft timers list */
event_initSoftInt(&kbd_timer.expire, kbd_softint, 0);
timer_setDelay(&kbd_timer, ms_to_ticks(KBD_CHECK_INTERVAL));
timer_add(&kbd_timer);
+
+#elif CONFIG_KBD_POLL == CONFIG_POLL_FREERTOS
+
+ /* Create a timer specific thread */
+ xTaskCreate(kbd_poll, "kbd_poll", CONFIG_STACK_KBD,
+ NULL, CONFIG_PRI_KBD, NULL);
+
+#else
+ #error "Define keyboard poll method"
+#endif
+
+ MOD_INIT(kbd);
}
}