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 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 Board specific joystick driver header for the Atmel EVK527.
  28. * \copydetails Group_Joystick_EVK527
  29. *
  30. * \note This file should not be included directly. It is automatically included as needed by the joystick driver
  31. * dispatch header located in LUFA/Drivers/Board/Joystick.h.
  32. */
  33. /** \ingroup Group_Joystick
  34. * \defgroup Group_Joystick_EVK527 EVK527
  35. * \brief Board specific joystick driver header for the Atmel EVK527.
  36. *
  37. * Board specific joystick driver header for the Atmel EVK527.
  38. *
  39. * <table>
  40. * <tr><th>Left Port Pin</th><th>Up Port Pin</th><th>Right Port Pin</th><th>Down Port Pin</th><th>Press Port Pin</th></tr>
  41. * <tr><td>PORTF.4</td><td>PORTF.5</td><td>PORTF.7</td><td>PORTC.6</td><td>PORTF.6</td></tr>
  42. * </table>
  43. *
  44. * @{
  45. */
  46. #ifndef __JOYSTICK_EVK527_H__
  47. #define __JOYSTICK_EVK527_H__
  48. /* Includes: */
  49. #include "../../../../Common/Common.h"
  50. /* Enable C linkage for C++ Compilers: */
  51. #if defined(__cplusplus)
  52. extern "C" {
  53. #endif
  54. /* Preprocessor Checks: */
  55. #if !defined(__INCLUDE_FROM_JOYSTICK_H)
  56. #error Do not include this file directly. Include LUFA/Drivers/Board/Joystick.h instead.
  57. #endif
  58. /* Private Interface - For use in library only: */
  59. #if !defined(__DOXYGEN__)
  60. /* Macros: */
  61. #define JOY_FMASK ((1 << 4) | (1 << 5) | (1 << 6) | (1 << 7))
  62. #define JOY_CMASK (1 << 6)
  63. #define JOY_PORTC_MASK_SHIFT 3
  64. #endif
  65. /* Public Interface - May be used in end-application: */
  66. /* Macros: */
  67. /** Mask for the joystick being pushed in the left direction. */
  68. #define JOY_LEFT (1 << 4)
  69. /** Mask for the joystick being pushed in the right direction. */
  70. #define JOY_RIGHT (1 << 7)
  71. /** Mask for the joystick being pushed in the upward direction. */
  72. #define JOY_UP (1 << 5)
  73. /** Mask for the joystick being pushed in the downward direction. */
  74. #define JOY_DOWN ((1 << 6) >> JOY_PORTC_MASK_SHIFT)
  75. /** Mask for the joystick being pushed inward. */
  76. #define JOY_PRESS (1 << 6)
  77. /* Inline Functions: */
  78. #if !defined(__DOXYGEN__)
  79. static inline void Joystick_Init(void)
  80. {
  81. DDRF &= ~JOY_FMASK;
  82. DDRC &= ~JOY_CMASK;
  83. PORTF |= JOY_FMASK;
  84. PORTC |= JOY_CMASK;
  85. }
  86. static inline void Joystick_Disable(void)
  87. {
  88. DDRF &= ~JOY_FMASK;
  89. DDRC &= ~JOY_CMASK;
  90. PORTF &= ~JOY_FMASK;
  91. PORTC &= ~JOY_CMASK;
  92. }
  93. static inline uint8_t Joystick_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
  94. static inline uint8_t Joystick_GetStatus(void)
  95. {
  96. return (((uint8_t)~PINF & JOY_FMASK) | (((uint8_t)~PINC & JOY_CMASK) >> JOY_PORTC_MASK_SHIFT));
  97. }
  98. #endif
  99. /* Disable C linkage for C++ Compilers: */
  100. #if defined(__cplusplus)
  101. }
  102. #endif
  103. #endif
  104. /** @} */