keys.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #ifndef _KEYS_H_
  2. #define _KEYS_H_
  3. /*
  4. * Copyright (C) 2001-2009 by egnite Software GmbH. All rights reserved.
  5. * Copyright (C) 2009 by Ulrich Prinz (uprinz2@netscape.net)
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the name of the copyright holders nor the names of
  17. * contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  24. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  26. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  27. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  28. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  30. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. * SUCH DAMAGE.
  32. *
  33. * For additional information see http://www.ethernut.de/
  34. *
  35. */
  36. /*
  37. * $Log$
  38. *
  39. * Revision 0.3 2009/09/12 ulrichprinz
  40. * First checkin, new push button driver example
  41. * (currently SAM7X256 is tested only)
  42. *
  43. */
  44. /*!
  45. * \file dev/keys.h
  46. * \brief Key handler definitions.
  47. */
  48. /*!
  49. * \addtogroup xgDevKeys
  50. */
  51. /*@{*/
  52. /*!
  53. * \brief Key state definitions.
  54. *
  55. * The key handler assignes the following states to a key.
  56. *
  57. * The user should only use KEY_IS_DOWN and KEY_PENDING to determine
  58. * what key released his NutEventWait() or if he uses the key functions
  59. * without event handling.
  60. */
  61. /*!
  62. * \brief Key state KEY_NOT_PRESSED.
  63. *
  64. * State used internally.
  65. */
  66. #define KEY_NOT_PRESSED 0x00 /* key is currently not pressed */
  67. /*!
  68. * \brief Key state KEY_IS_DOWN.
  69. *
  70. * User can check if key is pressed by
  71. * if ((NutGetKeyState( key) & KEY_IS_DOWN) == KEY_IS_DOWN)
  72. */
  73. #define KEY_IS_DOWN 0x01 /* key is currently down */
  74. /*!
  75. * \brief Key state KEY_PENDING.
  76. *
  77. * User can check if the action assigned to this key has released the
  78. * event by using the folllowing if sequence:
  79. * if ((NutGetKeyState( key) & KEY_PENDING) == KEY_PENDING)
  80. * This state is reset on every call of NutGetKeyState().
  81. */
  82. #define KEY_PENDING 0x02 /* Key action is pending, reset on NutGetKey() */
  83. /*!
  84. * \brief Key state KEY_NOT_PRESSED.
  85. *
  86. * State used internally for locking a key and prevent pultiple event
  87. * release if the key is pressed longer than any action requires.
  88. */
  89. #define KEY_IS_LOCKED 0x04 /* for preventing double execution */
  90. /*!
  91. * \brief Key state definitions.
  92. *
  93. * The key handler assignes the following states to a key depending
  94. *
  95. * The user should only use KEY_IS_DOWN and KEY_PENDING to determine
  96. * what key released his NutEventWait() or if he uses the key functions
  97. * without event handling.
  98. */
  99. /*!
  100. * \brief Key action KEY_ACTION_DOWN.
  101. *
  102. * By assigning this action to a key, it will release a pending event wait
  103. * if the button is pressed. Timing parameter is ignored.
  104. */
  105. #define KEY_ACTION_DOWN 0x10 /* assign action on key press, no timing possible */
  106. /*!
  107. * \brief Key action KEY_ACTION_UP.
  108. *
  109. * By assigning this action to a key, it will release a pending event wait
  110. * if the button is released. Timing parameter is ignored.
  111. */
  112. #define KEY_ACTION_UP 0x20 /* assign action on key release, no timing possible*/
  113. /*!
  114. * \brief Key action KEY_ACTION_HOLD.
  115. *
  116. * By assigning this action to a key, and givign a timing parameter in ms
  117. * the assigned event will be released if the button was pressed for at
  118. * least the given time.
  119. */
  120. #define KEY_ACTION_HOLD 0x40 /* assign action on time pressed */
  121. /*!
  122. * \brief Key action KEY_ACTION_SHORT.
  123. *
  124. * By assigning this action to a key, and givign a timing parameter in ms
  125. * the assigned event will be released if the button was released before the
  126. * given time elapsed.
  127. */
  128. #define KEY_ACTION_SHORT 0x80 /* assign action on release before given time */
  129. /*@}*/
  130. extern int NutGetKeyState( HANDLE *keyhp);
  131. extern int NutGetKeyTime( HANDLE *keyhp);
  132. int NutRegisterKey( HANDLE *keyhp, int bank, int pin, int fx, uint32_t fxt);
  133. int NutAssignKeyFkt( HANDLE *keyhp, void (*callback)(void));
  134. int NutAssignKeyEvt( HANDLE *keyhp, HANDLE *event);
  135. #endif