2 Copyright 2017 Jack Humbert
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * \brief General driver header for QMK-powered keyboards.
20 * \copydetails Group_LEDs_QMK
22 * \note This file should not be included directly. It is automatically included as needed by the LEDs driver
23 * dispatch header located in LUFA/Drivers/Board/LEDs.h.
26 /** \ingroup Group_LEDs
27 * \defgroup Group_LEDs_QMK QMK
28 * \brief General driver header for QMK-powered keyboards.
30 * General driver header for QMK-powered keyboards (http://qmk.fm).
34 * <tr><th>Name</th><th>Color</th><th>Info</th><th>Active Level</th><th>Port Pin</th></tr>
35 * <tr><td>LEDS_LED1</td><td>Green</td><td>General Indicator</td><td>High</td><td>PORT(QMK_LED).6</td></tr>
41 #ifndef __LEDS_QMK_H__
42 #define __LEDS_QMK_H__
45 #include "../../../../Common/Common.h"
47 /* Enable C linkage for C++ Compilers: */
48 #if defined(__cplusplus)
52 /* Preprocessor Checks: */
53 #if !defined(__INCLUDE_FROM_LEDS_H)
54 #error Do not include this file directly. Include LUFA/Drivers/Board/LEDS.h instead.
106 #include "Keyboard.h"
108 #ifndef QMK_ESC_INPUT
109 #define QMK_ESC_INPUT F1
111 #ifndef QMK_ESC_OUTPUT
112 #define QMK_ESC_OUTPUT D5
118 #define QMK_SPEAKER C6
121 #define DDR(pin) _SFR_IO8(((pin) >> 4) + 1)
122 #define PORT(pin) _SFR_IO8(((pin) >> 4) + 2)
123 #define PIN(pin) _SFR_IO8((pin) >> 4)
124 #define NUM(pin) _BV((pin) & 0xF)
126 /* Public Interface - May be used in end-application: */
128 /** LED mask for the first LED on the board. */
129 #define LEDS_LED1 NUM(QMK_LED)
130 #define LEDS_LED2 NUM(QMK_SPEAKER)
132 /** LED mask for all the LEDs on the board. */
133 #define LEDS_ALL_LEDS LEDS_LED1 | LEDS_LED2
135 /** LED mask for none of the board LEDs. */
136 #define LEDS_NO_LEDS 0
138 /* Inline Functions: */
139 #if !defined(__DOXYGEN__)
140 static inline void LEDs_Init(void)
142 DDR(QMK_LED) |= LEDS_LED1;
143 PORT(QMK_LED) |= LEDS_LED1;
145 DDR(QMK_SPEAKER) |= LEDS_LED2;
146 PORT(QMK_SPEAKER) |= LEDS_LED2;
149 static inline void LEDs_Disable(void)
151 DDR(QMK_LED) &= ~LEDS_LED1;
152 PORT(QMK_LED) &= ~LEDS_LED2;
154 DDR(QMK_SPEAKER) &= ~LEDS_LED1;
155 PORT(QMK_SPEAKER) &= ~LEDS_LED2;
158 static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
160 PORT(QMK_LED) &= (LEDS_LED1 & ~LEDMask);
161 PORT(QMK_SPEAKER) &= (LEDS_LED2 & ~LEDMask);
164 static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
166 PORT(QMK_LED) |= (LEDS_LED1 & LEDMask);
167 PORT(QMK_SPEAKER) |= (LEDS_LED2 & LEDMask);
170 static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
172 PORT(QMK_LED) = ((PORT(QMK_LED) | LEDS_LED1) & ~LEDMask);
173 PORT(QMK_SPEAKER) = ((PORT(QMK_SPEAKER) | LEDS_LED2) & ~LEDMask);
176 static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
177 const uint8_t ActiveMask)
179 PORT(QMK_LED) = ((PORT(QMK_LED) | (LEDS_LED1 & LEDMask)) & ~ActiveMask);
180 PORT(QMK_SPEAKER) = ((PORT(QMK_SPEAKER) | (LEDS_LED1 & LEDMask)) & ~ActiveMask);
183 static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
185 PIN(QMK_LED) = (LEDS_LED1 & LEDMask);
186 PIN(QMK_SPEAKER) = (LEDS_LED2 & LEDMask);
189 static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
190 static inline uint8_t LEDs_GetLEDs(void)
192 return (~PORT(QMK_LED) & LEDS_LED1) | (~(PORT(QMK_SPEAKER) & LEDS_LED2));
196 /* Disable C linkage for C++ Compilers: */
197 #if defined(__cplusplus)