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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 PJRC Teensy 1.x/2.x boards.
  28. * \copydetails Group_LEDs_TEENSY
  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_TEENSY2 TEENSY2
  35. * \brief Board specific LED driver header for the PJRC Teensy 2 boards.
  36. *
  37. * See \ref Group_LEDs_TEENSY for more details.
  38. */
  39. /** \ingroup Group_LEDs
  40. * \defgroup Group_LEDs_TEENSY TEENSY
  41. * \brief Board specific LED driver header for the PJRC Teensy 1.x/2.x boards.
  42. *
  43. * \note For version 2 Teensy boards, compile with <code>BOARD = TEENSY2</code>.
  44. *
  45. * Board specific LED driver header for the PJRC Teensy boards (http://www.pjrc.com/teensy/index.html).
  46. *
  47. * <b>TEENSY</b>:
  48. * <table>
  49. * <tr><th>Name</th><th>Color</th><th>Info</th><th>Active Level</th><th>Port Pin</th></tr>
  50. * <tr><td>LEDS_LED1</td><td>Green</td><td>General Indicator</td><td>High</td><td>PORTD.6</td></tr>
  51. * </table>
  52. *
  53. * <b>TEENSY2</b>:
  54. * <table>
  55. * <tr><th>Name</th><th>Color</th><th>Info</th><th>Active Level</th><th>Port Pin</th></tr>
  56. * <tr><td>LEDS_LED1</td><td>Green</td><td>General Indicator</td><td>Low</td><td>PORTD.6</td></tr>
  57. * </table>
  58. *
  59. * @{
  60. */
  61. #ifndef __LEDS_TEENSY_H__
  62. #define __LEDS_TEENSY_H__
  63. /* Includes: */
  64. #include "../../../../Common/Common.h"
  65. /* Enable C linkage for C++ Compilers: */
  66. #if defined(__cplusplus)
  67. extern "C" {
  68. #endif
  69. /* Preprocessor Checks: */
  70. #if !defined(__INCLUDE_FROM_LEDS_H)
  71. #error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
  72. #endif
  73. /* Public Interface - May be used in end-application: */
  74. /* Macros: */
  75. /** LED mask for the first LED on the board. */
  76. #define LEDS_LED1 (1 << 6)
  77. /** LED mask for all the LEDs on the board. */
  78. #define LEDS_ALL_LEDS LEDS_LED1
  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. DDRD |= LEDS_ALL_LEDS;
  86. #if (BOARD == BOARD_TEENSY2)
  87. PORTD &= ~LEDS_ALL_LEDS;
  88. #else
  89. PORTD |= LEDS_ALL_LEDS;
  90. #endif
  91. }
  92. static inline void LEDs_Disable(void)
  93. {
  94. DDRD &= ~LEDS_ALL_LEDS;
  95. PORTD &= ~LEDS_ALL_LEDS;
  96. }
  97. static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
  98. {
  99. #if (BOARD == BOARD_TEENSY2)
  100. PORTD |= LEDMask;
  101. #else
  102. PORTD &= ~LEDMask;
  103. #endif
  104. }
  105. static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
  106. {
  107. #if (BOARD == BOARD_TEENSY2)
  108. PORTD &= ~LEDMask;
  109. #else
  110. PORTD |= LEDMask;
  111. #endif
  112. }
  113. static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
  114. {
  115. #if (BOARD == BOARD_TEENSY2)
  116. PORTD = ((PORTD & ~LEDS_ALL_LEDS) | LEDMask);
  117. #else
  118. PORTD = ((PORTD | LEDS_ALL_LEDS) & ~LEDMask);
  119. #endif
  120. }
  121. static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
  122. const uint8_t ActiveMask)
  123. {
  124. #if (BOARD == BOARD_TEENSY2)
  125. PORTD = ((PORTD & ~LEDMask) | ActiveMask);
  126. #else
  127. PORTD = ((PORTD | LEDMask) & ~ActiveMask);
  128. #endif
  129. }
  130. static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
  131. {
  132. PIND = LEDMask;
  133. }
  134. static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
  135. static inline uint8_t LEDs_GetLEDs(void)
  136. {
  137. #if (BOARD == BOARD_TEENSY2)
  138. return (PORTD & LEDS_ALL_LEDS);
  139. #else
  140. return (~PORTD & LEDS_ALL_LEDS);
  141. #endif
  142. }
  143. #endif
  144. /* Disable C linkage for C++ Compilers: */
  145. #if defined(__cplusplus)
  146. }
  147. #endif
  148. #endif
  149. /** @} */