Test.
[bertos.git] / drv / kbd.c
old mode 100755 (executable)
new mode 100644 (file)
index 4dabd3b..f54ebf9
--- a/drv/kbd.c
+++ b/drv/kbd.c
@@ -1,9 +1,34 @@
-/*!
+/**
  * \file
  * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction.  Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License.  This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
  * Copyright 2003, 2004, 2005 Develer S.r.l. (http://www.develer.com/)
  * Copyright 1999, 2003 Bernardo Innocenti
- * This file is part of DevLib - See README.devlib for information.
+ *
  * -->
  *
  * \version $Id$
  * \brief Keyboard driver (implementation)
  */
 
-/*#*
- *#* $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.
- *#*
- *#* Revision 1.5  2006/02/27 22:39:45  bernie
- *#* Misc build and doc fixes from project_grl.
- *#*
- *#* 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.
- *#*
- *#*/
-
 #include <hw_kbd.h>
 
 #include <drv/timer.h>
 #if !defined(CONFIG_KBD_OBSERVER) || (CONFIG_KBD_OBSERVER != 0 && CONFIG_KBD_OBSERVER != 1)
        #error CONFIG_KBD_OBSERVER must be defined to either 0 or 1
 #endif
+#if !defined(CONFIG_KBD_LONGPRESS) || (CONFIG_KBD_LONGPRESS != 0 && CONFIG_KBD_LONGPRESS != 1)
+       #error CONFIG_KBD_LONGPRESS must be defined to either 0 or 1
+#endif
 
 #if CONFIG_KBD_BEEP
        #include <drv/buzzer.h>
 #endif
 
-#define KBD_CHECK_INTERVAL  10  /*!< (ms) Timing for kbd softint */
-#define KBD_DEBOUNCE_TIME   30  /*!< (ms) Debounce time */
-#define KBD_BEEP_TIME        5  /*!< (ms) Duration of keybeep */
+#define KBD_CHECK_INTERVAL  10  /**< (ms) Timing for kbd softint */
+#define KBD_DEBOUNCE_TIME   30  /**< (ms) Debounce time */
+#define KBD_BEEP_TIME        5  /**< (ms) Duration of keybeep */
 
-#define KBD_REPEAT_DELAY   400  /*!< (ms) Keyboard repeat delay for first character */
-#define KBD_REPEAT_RATE    100  /*!< (ms) Initial interchar delay for keyboard repeat */
-#define KBD_REPEAT_MAXRATE  20  /*!< (ms) Minimum delay for keyboard repeat */
-#define KBD_REPEAT_ACCEL     5  /*!< (ms) Keyboard repeat speed increase */
+#define KBD_REPEAT_DELAY   400  /**< (ms) Keyboard repeat delay for first character */
+#define KBD_REPEAT_RATE    100  /**< (ms) Initial interchar delay for keyboard repeat */
+#define KBD_REPEAT_MAXRATE  20  /**< (ms) Minimum delay for keyboard repeat */
+#define KBD_REPEAT_ACCEL     5  /**< (ms) Keyboard repeat speed increase */
 
-#define KBD_LNG_DELAY     1000  /*!< (ms) Keyboard long pression keys delay */
+#define KBD_LNG_DELAY     1000  /**< (ms) Keyboard long pression keys delay */
 
 
-/*! Status for keyboard repeat state machine */
+/** Status for keyboard repeat state machine */
 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 keymask_t kbd_rpt_mask;     /**< Mask of repeatable keys. */
 
 #if CONFIG_KBD_POLL == KBD_POLL_SOFTINT
-static Timer kbd_timer;            /*!< Keyboard softtimer */
+static Timer kbd_timer;            /**< Keyboard softtimer */
 #endif
 
-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 */
+
+static KbdHandler kbd_defHandler;  /**< The default keyboard handler */
+static KbdHandler kbd_debHandler;  /**< The debounce keyboard handler */
+static KbdHandler kbd_rptHandler;  /**< Auto-repeat keyboard handler */
 
-static KbdHandler kbd_defHandler;  /*!< The default keyboard handler */
-static KbdHandler kbd_debHandler;  /*!< The debounce keyboard handler */
-static KbdHandler kbd_rptHandler;  /*!< Auto-repeat keyboard handler */
-#ifdef  K_LNG_MASK
-static KbdHandler kbd_lngHandler;  /*!< Long pression keys handler */
+#if CONFIG_KBD_LONGPRESS
+static KbdHandler kbd_lngHandler;  /**< Long pression keys handler */
 #endif
 
 #if CONFIG_KBD_OBSERVER
@@ -104,7 +108,7 @@ static KbdHandler kbd_lngHandler;  /*!< Long pression keys handler */
 #endif
 
 
-/*!
+/**
  * Poll keyboard and dispatch keys to handlers.
  *
  * Read the key states and invoke all keyboard
@@ -115,7 +119,7 @@ static KbdHandler kbd_lngHandler;  /*!< Long pression keys handler */
  */
 static void kbd_poll(void)
 {
-       /*! Currently depressed key */
+       /** Currently depressed key */
        static keymask_t current_key;
 
        struct KbdHandler *handler;
@@ -139,7 +143,7 @@ static void kbd_poll(void)
 
 #if CONFIG_KBD_POLL == KBD_POLL_SOFTINT
 
-/*!
+/**
  * Keyboard soft-irq handler.
  */
 static void kbd_softint(UNUSED_ARG(iptr_t, arg))
@@ -164,13 +168,15 @@ static portTASK_FUNCTION(kbd_task, arg)
 
 #endif /* CONFIG_KBD_POLL */
 
-/*!
+/**
  * \brief Read a key from the keyboard buffer.
  *
  * When a key is kept depressed between calls of this function a value
  * is returned only after the time specified with KBD_REPAT_DELAY to
  * avoid too fast keyboard repeat.
  *
+ * \note Calls \c schedule() internally.
+ *
  * \note This function is \b not interrupt safe!
  *
  * \return The mask of depressed keys or 0 if no keys are depressed.
@@ -180,7 +186,7 @@ keymask_t kbd_peek(void)
 {
        keymask_t key = 0;
 
-// FIXME
+// FIXME: make it optional
        /* Let other tasks run for a while */
        extern void schedule(void);
        schedule();
@@ -197,7 +203,7 @@ keymask_t kbd_peek(void)
        return key;
 }
 
-/*!
+/**
  * Wait for a keypress and return the mask of depressed keys.
  *
  * \note This function is \b not interrupt safe!
@@ -212,7 +218,7 @@ keymask_t kbd_get(void)
 }
 
 
-/*!
+/**
  * Wait up to \c timeout ms for a keypress
  * and return the mask of depressed keys, or K_TIMEOUT
  * if the timeout was reacked.
@@ -268,7 +274,7 @@ void kbd_remHandler(struct KbdHandler *handler)
 }
 
 
-/*!
+/**
  * This is the default key handler, called after
  * all other handlers have had their chance to
  * do their special processing. This handler
@@ -296,18 +302,18 @@ static keymask_t kbd_defHandlerFunc(keymask_t key)
        return 0;
 }
 
-/*!
+/**
  * Handle keyboard debounce
  */
 static keymask_t kbd_debHandlerFunc(keymask_t key)
 {
-       /*! Buffer for debounce */
+       /** Buffer for debounce */
        static keymask_t debounce_key;
 
-       /*! Timer for keyboard debounce */
+       /** Timer for keyboard debounce */
        static ticks_t debounce_time;
 
-       /*! Key aquired after debounce */
+       /** Key aquired after debounce */
        static keymask_t new_key;
 
 
@@ -329,7 +335,7 @@ static keymask_t kbd_debHandlerFunc(keymask_t key)
        return new_key;
 }
 
-#ifdef  K_LNG_MASK
+#if CONFIG_KBD_LONGPRESS
 /**
  * Handle long pression keys.
  */
@@ -359,7 +365,7 @@ keymask_t kbd_setRepeatMask(keymask_t mask)
        return oldmask;
 }
 
-/*!
+/**
  * Handle keyboard repeat
  */
 static keymask_t kbd_rptHandlerFunc(keymask_t key)
@@ -368,7 +374,7 @@ static keymask_t kbd_rptHandlerFunc(keymask_t key)
        static ticks_t repeat_time;
 
        /* Current repeat rate (for acceleration). */
-       static ticks_t repeat_rate; /*! Current repeat rate (for acceleration) */
+       static ticks_t repeat_rate; /** Current repeat rate (for acceleration) */
 
        ticks_t now = timer_clock();
 
@@ -427,7 +433,7 @@ static keymask_t kbd_rptHandlerFunc(keymask_t key)
 
 MOD_DEFINE(kbd)
 
-/*!
+/**
  * Initialize keyboard ports and softtimer
  */
 void kbd_init(void)
@@ -448,7 +454,7 @@ void kbd_init(void)
        kbd_debHandler.flags = KHF_RAWKEYS;
        kbd_addHandler(&kbd_debHandler);
 
-       #ifdef  K_LNG_MASK
+       #if CONFIG_KBD_LONGPRESS
        /* Add long pression keyboard handler */
        kbd_lngHandler.hook = kbd_lngHandlerFunc;
        kbd_lngHandler.pri = 90; /* high priority */
@@ -476,7 +482,7 @@ void kbd_init(void)
        MOD_CHECK(timer);
 
        /* Add kbd handler to soft timers list */
-       event_initSoftInt(&kbd_timer.expire, kbd_softint, 0);
+       event_initSoftInt(&kbd_timer.expire, kbd_softint, NULL);
        timer_setDelay(&kbd_timer, ms_to_ticks(KBD_CHECK_INTERVAL));
        timer_add(&kbd_timer);