From: asterix Date: Wed, 11 Jan 2012 14:40:26 +0000 (+0000) Subject: Add kbd_peekMask() and kbd_getMask() functions. X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=12a865a058c2c3da0e4da685158f3a506ffad876;p=bertos.git Add kbd_peekMask() and kbd_getMask() functions. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@5247 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/drv/kbd.c b/bertos/drv/kbd.c index 402e07d7..b75db360 100644 --- a/bertos/drv/kbd.c +++ b/bertos/drv/kbd.c @@ -176,6 +176,12 @@ static void kbd_softint(UNUSED_ARG(iptr_t, arg)) * */ keymask_t kbd_peek(void) +{ + return kbd_peekMask((keymask_t)0xFFFFFFFFFFFFFFFFULL); +} + + +keymask_t kbd_peekMask(keymask_t mask) { keymask_t key = 0; @@ -187,10 +193,12 @@ keymask_t kbd_peek(void) /* 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; @@ -203,14 +211,23 @@ 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; #if CONFIG_KBD_POLL == KBD_POLL_SOFTINT - event_wait(&key_pressed); - key = kbd_peek(); + do + { + event_wait(&key_pressed); + key = kbd_peekMask(mask); + } + while (!key); #else - while (!(key = kbd_peek())) + while (!(key = kbd_peekMask(mask))) cpu_relax(); #endif diff --git a/bertos/drv/kbd.h b/bertos/drv/kbd.h index 989ebf7f..eb699602 100644 --- a/bertos/drv/kbd.h +++ b/bertos/drv/kbd.h @@ -85,7 +85,9 @@ typedef struct KbdHandler void kbd_init(void); keymask_t kbd_peek(void); +keymask_t kbd_peekMask(keymask_t mask); keymask_t kbd_get(void); +keymask_t kbd_getMask(keymask_t mask); keymask_t kbd_get_timeout(mtime_t timeout); void kbd_addHandler(struct KbdHandler *handler); void kbd_remHandler(struct KbdHandler *handler);