Make keyboard repeat mask run-time configurable.
authorbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Sat, 3 Jun 2006 13:57:36 +0000 (13:57 +0000)
committerbernie <bernie@38d2e660-2303-0410-9eaa-f027e97ec537>
Sat, 3 Jun 2006 13:57:36 +0000 (13:57 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@659 38d2e660-2303-0410-9eaa-f027e97ec537

drv/kbd.c
drv/kbd.h

index a051edc73a63695d8e626097c542dfeb72bf598c..4dabd3b3b942931931d0cfed67ed388e19c95851 100755 (executable)
--- a/drv/kbd.c
+++ b/drv/kbd.c
@@ -17,6 +17,9 @@
 
 /*#*
  *#* $Log$
+ *#* Revision 1.7  2006/06/03 13:57:36  bernie
+ *#* Make keyboard repeat mask run-time configurable.
+ *#*
  *#* Revision 1.6  2006/03/20 17:50:17  bernie
  *#* Add FreeRTOS and Observers support.
  *#*
@@ -79,6 +82,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 keymask_t kbd_rpt_mask;     /**< Mask of repeatable keys. */
 
 #if CONFIG_KBD_POLL == KBD_POLL_SOFTINT
 static Timer kbd_timer;            /*!< Keyboard softtimer */
@@ -326,27 +330,35 @@ static keymask_t kbd_debHandlerFunc(keymask_t key)
 }
 
 #ifdef  K_LNG_MASK
-/*!
- * Handle long pression keys
+/**
+ * Handle long pression keys.
  */
 static keymask_t kbd_lngHandlerFunc(keymask_t key)
 {
-       static ticks_t stop;
+       static ticks_t start;
        ticks_t now = timer_clock();
 
        if (key & K_LNG_MASK)
        {
-               if (now - stop > 0)
-                       key &= K_LNG_MASK;
-               else
-                       key &= ~K_LNG_MASK;
+               if (now - start > ms_to_ticks(KBD_LNG_DELAY))
+                       key |= K_LONG;
        }
        else
-               stop = now + ms_to_ticks(KBD_LNG_DELAY);
+               start = now;
        return key;
 }
 #endif
 
+/**
+ * Set current mask of repeatable keys.
+ */
+keymask_t kbd_setRepeatMask(keymask_t mask)
+{
+       keymask_t oldmask = kbd_rpt_mask;
+       ATOMIC(kbd_rpt_mask = mask);
+       return oldmask;
+}
+
 /*!
  * Handle keyboard repeat
  */
@@ -363,7 +375,7 @@ static keymask_t kbd_rptHandlerFunc(keymask_t key)
        switch (kbd_rptStatus)
        {
                case KS_IDLE:
-                       if (key & K_RPT_MASK)
+                       if (key & kbd_rpt_mask)
                        {
                                repeat_time = now;
                                kbd_rptStatus = KS_REPDELAY;
@@ -371,11 +383,11 @@ static keymask_t kbd_rptHandlerFunc(keymask_t key)
                        break;
 
                case KS_REPDELAY:
-                       if (key & K_RPT_MASK)
+                       if (key & kbd_rpt_mask)
                        {
                                if (now - repeat_time > ms_to_ticks(KBD_REPEAT_DELAY))
                                {
-                                       key = (key & K_RPT_MASK) | K_REPEAT;
+                                       key = (key & kbd_rpt_mask) | K_REPEAT;
                                        repeat_time = now;
                                        repeat_rate = ms_to_ticks(KBD_REPEAT_RATE);
                                        kbd_rptStatus = KS_REPEAT;
@@ -388,12 +400,12 @@ static keymask_t kbd_rptHandlerFunc(keymask_t key)
                        break;
 
                case KS_REPEAT:
-                       if (key & K_RPT_MASK)
+                       if (key & kbd_rpt_mask)
                        {
                                if (now - repeat_time > repeat_rate)
                                {
                                        /* Enqueue a new event in the buffer */
-                                       key = (key & K_RPT_MASK) | K_REPEAT;
+                                       key = (key & kbd_rpt_mask) | K_REPEAT;
                                        repeat_time = now;
 
                                        /* Repeat rate acceleration */
index 307cf5e20a924f28f15bfa75e5bda7a0793494e7..b9a253c3effbc38664c76435540055a5677737d5 100755 (executable)
--- a/drv/kbd.h
+++ b/drv/kbd.h
@@ -16,6 +16,9 @@
 
 /*#*
  *#* $Log$
+ *#* Revision 1.5  2006/06/03 13:57:36  bernie
+ *#* Make keyboard repeat mask run-time configurable.
+ *#*
  *#* Revision 1.4  2006/03/20 17:50:17  bernie
  *#* Add FreeRTOS and Observers support.
  *#*
@@ -68,6 +71,7 @@ keymask_t kbd_get(void);
 keymask_t kbd_get_timeout(mtime_t timeout);
 void kbd_addHandler(struct KbdHandler *handler);
 void kbd_remHandler(struct KbdHandler *handler);
+keymask_t kbd_setRepeatMask(keymask_t mask);
 
 #if CONFIG_KBD_OBSERVER
        struct Subject;