Keyboard firmwares for Atmel AVR and Cortex-M
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.

LEDs.h 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2014.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2014 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 LED driver header for the Atmel XMEGA A3BU Xplained.
  28. * \copydetails Group_LEDs_A3BU_XPLAINED
  29. *
  30. * \note This file should not be included directly. It is automatically included as needed by the LEDs driver
  31. * dispatch header located in LUFA/Drivers/Board/LEDs.h.
  32. */
  33. /** \ingroup Group_LEDs
  34. * \defgroup Group_LEDs_A3BU_XPLAINED A3BU_XPLAINED
  35. * \brief Board specific LED driver header for the Atmel XMEGA A3BU Xplained.
  36. *
  37. * Board specific LED driver header for the Atmel XMEGA A3BU Xplained.
  38. *
  39. * <table>
  40. * <tr><th>Name</th><th>Color</th><th>Info</th><th>Active Level</th><th>Port Pin</th></tr>
  41. * <tr><td>LEDS_LED1</td><td>Yellow</td><td>LED0 LED</td><td>Low</td><td>PORTR.0</td></tr>
  42. * <tr><td>LEDS_LED2</td><td>Yellow</td><td>LED1 LED</td><td>Low</td><td>PORTR.1</td></tr>
  43. * <tr><td>LEDS_LED3</td><td>Red</td><td>Status Bicolour Red LED</td><td>Low</td><td>PORTD.4</td></tr>
  44. * <tr><td>LEDS_LED4</td><td>Green</td><td>Status Bicolour Green LED</td><td>High</td><td>PORTD.5</td></tr>
  45. * </table>
  46. *
  47. * @{
  48. */
  49. #ifndef __LEDS_A3BU_XPLAINED_H__
  50. #define __LEDS_A3BU_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_LEDS_H)
  59. #error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
  60. #endif
  61. /* Private Interface - For use in library only: */
  62. #if !defined(__DOXYGEN__)
  63. /* Macros: */
  64. #define LEDS_PORTR_LEDS (LEDS_LED1 | LEDS_LED2)
  65. #define LEDS_PORTD_LEDS (LEDS_LED3 | LEDS_LED4)
  66. #endif
  67. /* Public Interface - May be used in end-application: */
  68. /* Macros: */
  69. /** LED mask for the first LED on the board. */
  70. #define LEDS_LED1 (1 << 0)
  71. /** LED mask for the second LED on the board. */
  72. #define LEDS_LED2 (1 << 1)
  73. /** LED mask for the third LED on the board. */
  74. #define LEDS_LED3 (1 << 4)
  75. /** LED mask for the fourth LED on the board. */
  76. #define LEDS_LED4 (1 << 5)
  77. /** LED mask for all the LEDs on the board. */
  78. #define LEDS_ALL_LEDS (LEDS_LED1 | LEDS_LED2 | LEDS_LED3 | LEDS_LED4)
  79. /** LED mask for none of the board LEDs. */
  80. #define LEDS_NO_LEDS 0
  81. /* Inline Functions: */
  82. #if !defined(__DOXYGEN__)
  83. static inline void LEDs_Init(void)
  84. {
  85. PORTR.DIRSET = LEDS_PORTR_LEDS;
  86. PORTR.OUTCLR = LEDS_PORTR_LEDS;
  87. PORTCFG.MPCMASK = LEDS_PORTR_LEDS;
  88. PORTR.PIN0CTRL = PORT_INVEN_bm;
  89. PORTD.DIRSET = LEDS_PORTD_LEDS;
  90. PORTD.OUTCLR = LEDS_PORTD_LEDS;
  91. PORTD.PIN4CTRL = PORT_INVEN_bm;
  92. }
  93. static inline void LEDs_Disable(void)
  94. {
  95. PORTR.DIRCLR = LEDS_PORTR_LEDS;
  96. PORTR.OUTCLR = LEDS_PORTR_LEDS;
  97. PORTCFG.MPCMASK = 0;
  98. PORTR.PIN0CTRL = LEDS_PORTR_LEDS;
  99. PORTD.DIRCLR = LEDS_PORTD_LEDS;
  100. PORTD.OUTCLR = LEDS_PORTD_LEDS;
  101. PORTD.PIN4CTRL = 0;
  102. }
  103. static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
  104. {
  105. PORTR_OUTSET = LEDMask & LEDS_PORTR_LEDS;
  106. PORTD_OUTSET = LEDMask & LEDS_PORTD_LEDS;
  107. }
  108. static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
  109. {
  110. PORTR_OUTCLR = LEDMask & LEDS_PORTR_LEDS;
  111. PORTD_OUTCLR = LEDMask & LEDS_PORTD_LEDS;
  112. }
  113. static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
  114. {
  115. PORTR_OUTCLR = LEDS_PORTR_LEDS;
  116. PORTD_OUTCLR = LEDS_PORTD_LEDS;
  117. PORTR_OUTSET = (LEDMask & LEDS_PORTR_LEDS);
  118. PORTD_OUTSET = (LEDMask & LEDS_PORTD_LEDS);
  119. }
  120. static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
  121. const uint8_t ActiveMask)
  122. {
  123. PORTR_OUTCLR = (LEDMask & LEDS_PORTR_LEDS);
  124. PORTD_OUTCLR = (LEDMask & LEDS_PORTD_LEDS);
  125. PORTR_OUTSET = (ActiveMask & LEDS_PORTR_LEDS);
  126. PORTD_OUTSET = (ActiveMask & LEDS_PORTD_LEDS);
  127. }
  128. static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
  129. {
  130. PORTR_OUTTGL = (LEDMask & LEDS_PORTR_LEDS);
  131. PORTD_OUTTGL = (LEDMask & LEDS_PORTD_LEDS);
  132. }
  133. static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
  134. static inline uint8_t LEDs_GetLEDs(void)
  135. {
  136. return ((PORTR_OUT & LEDS_PORTR_LEDS) | (PORTD_OUT & LEDS_PORTD_LEDS));
  137. }
  138. #endif
  139. /* Disable C linkage for C++ Compilers: */
  140. #if defined(__cplusplus)
  141. }
  142. #endif
  143. #endif
  144. /** @} */