X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fdrv%2Fkbd.c;h=b75db360354c82214de1c2c1550bb02ff0bbb45c;hb=12a865a058c2c3da0e4da685158f3a506ffad876;hp=f54ebf91f06ebf9a2b66f334d950fdcaa1961805;hpb=791e167e053bdd9250d34a9a5ccae6ccde4d6679;p=bertos.git diff --git a/bertos/drv/kbd.c b/bertos/drv/kbd.c index f54ebf91..b75db360 100644 --- a/bertos/drv/kbd.c +++ b/bertos/drv/kbd.c @@ -27,31 +27,33 @@ * the GNU General Public License. * * Copyright 2003, 2004, 2005 Develer S.r.l. (http://www.develer.com/) - * Copyright 1999, 2003 Bernardo Innocenti + * Copyright 1999, 2003 Bernie Innocenti * * --> * - * \version $Id$ + * \brief Keyboard driver (implementation) + * * - * \author Bernardo Innocenti + * \author Bernie Innocenti * \author Stefano Fedrigo * \author Francesco Sacchi * - * \brief Keyboard driver (implementation) */ -#include +#include "hw/hw_kbd.h" + +#include "cfg/cfg_kbd.h" +#include +#include #include +#include #include -#include -#include -#include /* 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 +#if !defined(CONFIG_KBD_POLL) || (CONFIG_KBD_POLL != KBD_POLL_SOFTINT) + #error CONFIG_KBD_POLL must be defined to either KBD_POLL_SOFTINT #endif #if !defined(CONFIG_KBD_BEEP) || (CONFIG_KBD_BEEP != 0 && CONFIG_KBD_BEEP != 1) #error CONFIG_KBD_BEEP must be defined to either 0 or 1 @@ -82,6 +84,8 @@ /** Status for keyboard repeat state machine */ static enum { KS_IDLE, KS_REPDELAY, KS_REPEAT } kbd_rptStatus; +/** Used to notify the occurrence of a key pressed event */ +static Event key_pressed; static volatile keymask_t kbd_buf; /**< Single entry keyboard buffer */ static volatile keymask_t kbd_cnt; /**< Number of keypress events in \c kbd_buf */ @@ -152,19 +156,8 @@ static void kbd_softint(UNUSED_ARG(iptr_t, arg)) timer_add(&kbd_timer); } -#elif CONFIG_KBD_POLL == CONFIG_POLL_FREERTOS - -#include "FreeRTOS.h" -#include "task.h" - -static portTASK_FUNCTION(kbd_task, arg) -{ - for (;;) - { - kbd_poll(); - timer_delay(KBD_CHECK_INTERVAL); - } -} +#else + #error "Define keyboard poll method" #endif /* CONFIG_KBD_POLL */ @@ -183,20 +176,29 @@ static portTASK_FUNCTION(kbd_task, arg) * */ keymask_t kbd_peek(void) +{ + return kbd_peekMask((keymask_t)0xFFFFFFFFFFFFFFFFULL); +} + + +keymask_t kbd_peekMask(keymask_t mask) { keymask_t key = 0; -// FIXME: make it optional +#if CONFIG_KBD_SCHED /* Let other tasks run for a while */ extern void schedule(void); schedule(); +#endif /* Extract an event from the keyboard buffer */ IRQ_DISABLE; - if (kbd_cnt) + if (kbd_cnt && (kbd_buf & mask)) { - --kbd_cnt; - key = kbd_buf; + key = kbd_buf & mask; + kbd_buf &= ~mask; + if (!kbd_buf) + --kbd_cnt; } IRQ_ENABLE; @@ -209,10 +211,25 @@ keymask_t kbd_peek(void) * \note This function is \b not interrupt safe! */ keymask_t kbd_get(void) +{ + return kbd_getMask((keymask_t)0xFFFFFFFFFFFFFFFFULL); +} + +keymask_t kbd_getMask(keymask_t mask) { keymask_t key; - while (!(key = kbd_peek())) {} + #if CONFIG_KBD_POLL == KBD_POLL_SOFTINT + do + { + event_wait(&key_pressed); + key = kbd_peekMask(mask); + } + while (!key); + #else + while (!(key = kbd_peekMask(mask))) + cpu_relax(); + #endif return key; } @@ -225,18 +242,10 @@ keymask_t kbd_get(void) */ keymask_t kbd_get_timeout(mtime_t timeout) { - keymask_t key; - - ticks_t start = timer_clock(); - ticks_t stop = ms_to_ticks(timeout); - do - { - if ((key = kbd_peek())) - return key; - } - while (timer_clock() - start < stop); - - return K_TIMEOUT; + if (event_waitTimeout(&key_pressed, timeout)) + return kbd_peek(); + else + return K_TIMEOUT; } @@ -245,7 +254,7 @@ void kbd_addHandler(struct KbdHandler *handler) KbdHandler *node; List *list; - cpuflags_t flags; + cpu_flags_t flags; IRQ_SAVE_DISABLE(flags); /* Choose between raw and coocked handlers list */ @@ -287,6 +296,9 @@ static keymask_t kbd_defHandlerFunc(keymask_t key) /* Force a single event in kbd buffer */ kbd_buf = key; kbd_cnt = 1; + #if CONFIG_KBD_POLL == KBD_POLL_SOFTINT + event_do(&key_pressed); + #endif #if CONFIG_KBD_OBSERVER observer_notify(&kbd_subject, KBD_EVENT_KEY, &key); @@ -480,20 +492,21 @@ void kbd_init(void) #if CONFIG_KBD_POLL == KBD_POLL_SOFTINT MOD_CHECK(timer); + #if CONFIG_KERN + MOD_CHECK(proc); + #endif + + /* Initialize the keyboard event (key pressed) */ + event_initGeneric(&key_pressed); /* Add kbd handler to soft timers list */ - event_initSoftInt(&kbd_timer.expire, kbd_softint, NULL); + event_initSoftint(&kbd_timer.expire, kbd_softint, NULL); 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_task, "kbd", CONFIG_STACK_KBD, - NULL, CONFIG_PRI_KBD, NULL); - #else #error "Define keyboard poll method" + #endif MOD_INIT(kbd);