You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

Joystick.h 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2012.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  9. Permission to use, copy, modify, distribute, and sell this
  10. software and its documentation for any purpose is hereby granted
  11. without fee, provided that the above copyright notice appear in
  12. all copies and that both that the copyright notice and this
  13. permission notice and warranty disclaimer appear in supporting
  14. documentation, and that the name of the author not be used in
  15. advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.
  17. The author disclaim all warranties with regard to this
  18. software, including all implied warranties of merchantability
  19. and fitness. In no event shall the author be liable for any
  20. special, indirect or consequential damages or any damages
  21. whatsoever resulting from loss of use, data or profits, whether
  22. in an action of contract, negligence or other tortious action,
  23. arising out of or in connection with the use or performance of
  24. this software.
  25. */
  26. /** \file
  27. * \brief Digital joystick board hardware driver.
  28. *
  29. * This file is the master dispatch header file for the board-specific Joystick driver, for boards containing a
  30. * digital joystick.
  31. *
  32. * User code should include this file, which will in turn include the correct joystick driver header file for the
  33. * currently selected board.
  34. *
  35. * If the \c BOARD value is set to \c BOARD_USER, this will include the \c /Board/Joystick.h file in the user project
  36. * directory.
  37. *
  38. * For possible \c BOARD makefile values, see \ref Group_BoardTypes.
  39. */
  40. /** \ingroup Group_BoardDrivers
  41. * \defgroup Group_Joystick Joystick Driver - LUFA/Drivers/Board/Joystick.h
  42. * \brief Digital joystick board hardware driver.
  43. *
  44. * \section Sec_Dependencies Module Source Dependencies
  45. * The following files must be built with any user project that uses this module:
  46. * - None
  47. *
  48. * \section Sec_ModDescription Module Description
  49. * Hardware Joystick driver. This module provides an easy to use interface to control the hardware digital Joystick
  50. * located on many boards.
  51. *
  52. * If the \c BOARD value is set to \c BOARD_USER, this will include the \c /Board/Joystick.h file in the user project
  53. * directory. Otherwise, it will include the appropriate built in board driver header file.
  54. *
  55. * For possible \c BOARD makefile values, see \ref Group_BoardTypes.
  56. *
  57. * \section Sec_ExampleUsage Example Usage
  58. * The following snippet is an example of how this module may be used within a typical
  59. * application.
  60. *
  61. * \code
  62. * // Initialize the board Joystick driver before first use
  63. * Joystick_Init();
  64. *
  65. * printf("Waiting for joystick movement...\r\n");
  66. *
  67. * // Loop until a the joystick has been moved
  68. * uint8_t JoystickMovement;
  69. * while (!(JoystickMovement = Joystick_GetStatus())) {};
  70. *
  71. * // Display which direction the joystick was moved in
  72. * printf("Joystick moved:\r\n");
  73. *
  74. * if (JoystickMovement & (JOY_UP | JOY_DOWN))
  75. * printf("%s ", (JoystickMovement & JOY_UP) ? "Up" : "Down");
  76. *
  77. * if (JoystickMovement & (JOY_LEFT | JOY_RIGHT))
  78. * printf("%s ", (JoystickMovement & JOY_LEFT) ? "Left" : "Right");
  79. *
  80. * if (JoystickMovement & JOY_PRESS)
  81. * printf("Pressed");
  82. * \endcode
  83. *
  84. * @{
  85. */
  86. #ifndef __JOYSTICK_H__
  87. #define __JOYSTICK_H__
  88. /* Macros: */
  89. #define __INCLUDE_FROM_JOYSTICK_H
  90. /* Includes: */
  91. #include "../../Common/Common.h"
  92. #if (BOARD == BOARD_NONE)
  93. #error The Board Joystick driver cannot be used if the makefile BOARD option is not set.
  94. #elif (BOARD == BOARD_USBKEY)
  95. #include "AVR8/USBKEY/Joystick.h"
  96. #elif (BOARD == BOARD_STK525)
  97. #include "AVR8/STK525/Joystick.h"
  98. #elif (BOARD == BOARD_STK526)
  99. #include "AVR8/STK526/Joystick.h"
  100. #elif (BOARD == BOARD_BUMBLEB)
  101. #include "AVR8/BUMBLEB/Joystick.h"
  102. #elif (BOARD == BOARD_EVK527)
  103. #include "AVR8/EVK527/Joystick.h"
  104. #elif (BOARD == BOARD_EVK1101)
  105. #include "UC3/EVK1101/Joystick.h"
  106. #elif (BOARD == BOARD_EVK1100)
  107. #include "UC3/EVK1100/Joystick.h"
  108. #else
  109. #include "Board/Joystick.h"
  110. #endif
  111. /* Pseudo-Functions for Doxygen: */
  112. #if defined(__DOXYGEN__)
  113. /** Initializes the joystick driver so that the joystick position can be read. This sets the appropriate
  114. * I/O pins to inputs with their pull-ups enabled.
  115. */
  116. static inline void Joystick_Init(void);
  117. /** Disables the joystick driver, releasing the I/O pins back to their default high-impedance input mode. */
  118. static inline void Joystick_Disable(void);
  119. /** Returns the current status of the joystick, as a mask indicating the direction the joystick is
  120. * currently facing in (multiple bits can be set).
  121. *
  122. * \return Mask indicating the joystick direction - see corresponding board specific Joystick.h file
  123. * for direction masks.
  124. */
  125. static inline uint_reg_t Joystick_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
  126. #endif
  127. #endif
  128. /** @} */