Buttons.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2017.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2017 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 disclaims 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 Buttons driver header for the Atmel XMEGA B1 Xplained.
  28. * \copydetails Group_Buttons_B1_XPLAINED
  29. *
  30. * \note This file should not be included directly. It is automatically included as needed by the Buttons driver
  31. * dispatch header located in LUFA/Drivers/Board/Buttons.h.
  32. */
  33. /** \ingroup Group_Buttons
  34. * \defgroup Group_Buttons_B1_XPLAINED B1_XPLAINED
  35. * \brief Board specific Buttons driver header for the Atmel XMEGA B1 Xplained.
  36. *
  37. * Board specific Buttons driver header for the Atmel XMEGA B1 Xplained.
  38. *
  39. * <table>
  40. * <tr><th>Name</th><th>Info</th><th>Active Level</th><th>Port Pin</th></tr>
  41. * <tr><td>BUTTONS_BUTTON1</td><td>Touch CS0 Button</td><td>Low</td><td>PORTE.0</td></tr>
  42. * <tr><td>BUTTONS_BUTTON2</td><td>Touch CS1 Button</td><td>Low</td><td>PORTE.1</td></tr>
  43. * <tr><td>BUTTONS_BUTTON3</td><td>Touch CS2 Button</td><td>Low</td><td>PORTE.2</td></tr>
  44. * <tr><td>BUTTONS_BUTTON4</td><td>Touch CS3 Button</td><td>Low</td><td>PORTE.3</td></tr>
  45. * </table>
  46. *
  47. * @{
  48. */
  49. #ifndef __BUTTONS_B1_XPLAINED_H__
  50. #define __BUTTONS_B1_XPLAINED_H__
  51. /* Includes: */
  52. #include <avr/io.h>
  53. /* Enable C linkage for C++ Compilers: */
  54. #if defined(__cplusplus)
  55. extern "C" {
  56. #endif
  57. /* Preprocessor Checks: */
  58. #if !defined(__INCLUDE_FROM_BUTTONS_H)
  59. #error Do not include this file directly. Include LUFA/Drivers/Board/Buttons.h instead.
  60. #endif
  61. /* Public Interface - May be used in end-application: */
  62. /* Macros: */
  63. /** Button mask for the first button on the board. */
  64. #define BUTTONS_BUTTON1 (1 << 0)
  65. /** Button mask for the second button on the board. */
  66. #define BUTTONS_BUTTON2 (1 << 1)
  67. /** Button mask for the third button on the board. */
  68. #define BUTTONS_BUTTON3 (1 << 2)
  69. /** Button mask for the fourth button on the board. */
  70. #define BUTTONS_BUTTON4 (1 << 3)
  71. /* Inline Functions: */
  72. #if !defined(__DOXYGEN__)
  73. static inline void Buttons_Init(void)
  74. {
  75. PORTE.OUTSET = (BUTTONS_BUTTON1 | BUTTONS_BUTTON2 | BUTTONS_BUTTON3 | BUTTONS_BUTTON4);
  76. PORTCFG.MPCMASK = (BUTTONS_BUTTON1 | BUTTONS_BUTTON2 | BUTTONS_BUTTON3 | BUTTONS_BUTTON4);
  77. PORTE.PIN0CTRL = (PORT_INVEN_bm | PORT_OPC_PULLUP_gc);
  78. }
  79. static inline void Buttons_Disable(void)
  80. {
  81. PORTE.OUTCLR = (BUTTONS_BUTTON1 | BUTTONS_BUTTON2 | BUTTONS_BUTTON3 | BUTTONS_BUTTON4);
  82. PORTCFG.MPCMASK = (BUTTONS_BUTTON1 | BUTTONS_BUTTON2 | BUTTONS_BUTTON3 | BUTTONS_BUTTON4);
  83. PORTE.PIN0CTRL = 0;
  84. }
  85. static inline uint8_t Buttons_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
  86. static inline uint8_t Buttons_GetStatus(void)
  87. {
  88. return (PORTE_IN & (BUTTONS_BUTTON1 | BUTTONS_BUTTON2 | BUTTONS_BUTTON3 | BUTTONS_BUTTON4));
  89. }
  90. #endif
  91. /* Disable C linkage for C++ Compilers: */
  92. #if defined(__cplusplus)
  93. }
  94. #endif
  95. #endif
  96. /** @} */