LEDs.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. Copyright 2017 Jack Humbert
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /** \file
  15. * \brief General driver header for QMK-powered keyboards.
  16. * \copydetails Group_LEDs_QMK
  17. *
  18. * \note This file should not be included directly. It is automatically included as needed by the LEDs driver
  19. * dispatch header located in LUFA/Drivers/Board/LEDs.h.
  20. */
  21. /** \ingroup Group_LEDs
  22. * \defgroup Group_LEDs_QMK QMK
  23. * \brief General driver header for QMK-powered keyboards.
  24. *
  25. * General driver header for QMK-powered keyboards (http://qmk.fm).
  26. *
  27. * <b>QMK</b>:
  28. * <table>
  29. * <tr><th>Name</th><th>Color</th><th>Info</th><th>Active Level</th><th>Port Pin</th></tr>
  30. * <tr><td>LEDS_LED1</td><td>Green</td><td>General Indicator</td><td>High</td><td>PORT(QMK_LED).6</td></tr>
  31. * </table>
  32. *
  33. * @{
  34. */
  35. #ifndef __LEDS_QMK_H__
  36. #define __LEDS_QMK_H__
  37. /* Includes: */
  38. #include "../../../../Common/Common.h"
  39. /* Enable C linkage for C++ Compilers: */
  40. #if defined(__cplusplus)
  41. extern "C" {
  42. #endif
  43. /* Preprocessor Checks: */
  44. #if !defined(__INCLUDE_FROM_LEDS_H)
  45. #error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
  46. #endif
  47. #define B0 0x30
  48. #define B1 0x31
  49. #define B2 0x32
  50. #define B3 0x33
  51. #define B4 0x34
  52. #define B5 0x35
  53. #define B6 0x36
  54. #define B7 0x37
  55. #define C0 0x60
  56. #define C1 0x61
  57. #define C2 0x62
  58. #define C3 0x63
  59. #define C4 0x64
  60. #define C5 0x65
  61. #define C6 0x66
  62. #define C7 0x67
  63. #define D0 0x90
  64. #define D1 0x91
  65. #define D2 0x92
  66. #define D3 0x93
  67. #define D4 0x94
  68. #define D5 0x95
  69. #define D6 0x96
  70. #define D7 0x97
  71. #define E0 0xC0
  72. #define E1 0xC1
  73. #define E2 0xC2
  74. #define E3 0xC3
  75. #define E4 0xC4
  76. #define E5 0xC5
  77. #define E6 0xC6
  78. #define E7 0xC7
  79. #define F0 0xF0
  80. #define F1 0xF1
  81. #define F2 0xF2
  82. #define F3 0xF3
  83. #define F4 0xF4
  84. #define F5 0xF5
  85. #define F6 0xF6
  86. #define F7 0xF7
  87. #define A0 0x00
  88. #define A1 0x01
  89. #define A2 0x02
  90. #define A3 0x03
  91. #define A4 0x04
  92. #define A5 0x05
  93. #define A6 0x06
  94. #define A7 0x07
  95. #define QMK_ESC_COL F1
  96. #define QMK_ESC_ROW D5
  97. #define QMK_LED E6
  98. #define QMK_SPEAKER C6
  99. #define DDR(pin) _SFR_IO8(((pin) >> 4) + 1)
  100. #define PORT(pin) _SFR_IO8(((pin) >> 4) + 2)
  101. #define PIN(pin) _SFR_IO8((pin) >> 4)
  102. #define NUM(pin) _BV((pin) & 0xF)
  103. /* Public Interface - May be used in end-application: */
  104. /* Macros: */
  105. /** LED mask for the first LED on the board. */
  106. #define LEDS_LED1 NUM(QMK_LED)
  107. #define LEDS_LED2 NUM(QMK_SPEAKER)
  108. /** LED mask for all the LEDs on the board. */
  109. #define LEDS_ALL_LEDS LEDS_LED1 | LEDS_LED2
  110. /** LED mask for none of the board LEDs. */
  111. #define LEDS_NO_LEDS 0
  112. /* Inline Functions: */
  113. #if !defined(__DOXYGEN__)
  114. static inline void LEDs_Init(void)
  115. {
  116. DDR(QMK_LED) |= LEDS_LED1;
  117. PORT(QMK_LED) |= LEDS_LED1;
  118. DDR(QMK_SPEAKER) |= LEDS_LED2;
  119. PORT(QMK_SPEAKER) |= LEDS_LED2;
  120. }
  121. static inline void LEDs_Disable(void)
  122. {
  123. DDR(QMK_LED) &= ~LEDS_LED1;
  124. PORT(QMK_LED) &= ~LEDS_LED2;
  125. DDR(QMK_SPEAKER) &= ~LEDS_LED1;
  126. PORT(QMK_SPEAKER) &= ~LEDS_LED2;
  127. }
  128. static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
  129. {
  130. PORT(QMK_LED) &= (LEDS_LED1 & ~LEDMask);
  131. PORT(QMK_SPEAKER) &= (LEDS_LED2 & ~LEDMask);
  132. }
  133. static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
  134. {
  135. PORT(QMK_LED) |= (LEDS_LED1 & LEDMask);
  136. PORT(QMK_SPEAKER) |= (LEDS_LED2 & LEDMask);
  137. }
  138. static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
  139. {
  140. PORT(QMK_LED) = ((PORT(QMK_LED) | LEDS_LED1) & ~LEDMask);
  141. PORT(QMK_SPEAKER) = ((PORT(QMK_SPEAKER) | LEDS_LED2) & ~LEDMask);
  142. }
  143. static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
  144. const uint8_t ActiveMask)
  145. {
  146. PORT(QMK_LED) = ((PORT(QMK_LED) | (LEDS_LED1 & LEDMask)) & ~ActiveMask);
  147. PORT(QMK_SPEAKER) = ((PORT(QMK_SPEAKER) | (LEDS_LED1 & LEDMask)) & ~ActiveMask);
  148. }
  149. static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
  150. {
  151. PIN(QMK_LED) = (LEDS_LED1 & LEDMask);
  152. PIN(QMK_SPEAKER) = (LEDS_LED2 & LEDMask);
  153. }
  154. static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
  155. static inline uint8_t LEDs_GetLEDs(void)
  156. {
  157. return (~PORT(QMK_LED) & LEDS_LED1) | (~(PORT(QMK_SPEAKER) & LEDS_LED2));
  158. }
  159. #endif
  160. /* Disable C linkage for C++ Compilers: */
  161. #if defined(__cplusplus)
  162. }
  163. #endif
  164. #endif
  165. /** @} */