]> git.donarmstrong.com Git - qmk_firmware.git/blob - lib/lufa/LUFA/Drivers/Board/AVR8/QMK/LEDs.h
QMK DFU bootloader generation (#2009)
[qmk_firmware.git] / lib / lufa / LUFA / Drivers / Board / AVR8 / QMK / LEDs.h
1 /*
2 Copyright 2017 Jack Humbert
3
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.
8
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.
13
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/>.
16 */
17
18 /** \file
19  *  \brief General driver header for QMK-powered keyboards.
20  *  \copydetails Group_LEDs_QMK
21  *
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.
24  */
25
26 /** \ingroup Group_LEDs
27  *  \defgroup Group_LEDs_QMK QMK
28  *  \brief General driver header for QMK-powered keyboards.
29  *
30  *  General driver header for QMK-powered keyboards (http://qmk.fm).
31  *
32  *  <b>QMK</b>:
33  *  <table>
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>
36  *  </table>
37  *
38  *  @{
39  */
40
41 #ifndef __LEDS_QMK_H__
42 #define __LEDS_QMK_H__
43
44     /* Includes: */
45         #include "../../../../Common/Common.h"
46
47     /* Enable C linkage for C++ Compilers: */
48         #if defined(__cplusplus)
49             extern "C" {
50         #endif
51
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.
55         #endif
56
57         #define B0 0x30
58         #define B1 0x31
59         #define B2 0x32
60         #define B3 0x33
61         #define B4 0x34
62         #define B5 0x35
63         #define B6 0x36
64         #define B7 0x37
65         #define C0 0x60
66         #define C1 0x61
67         #define C2 0x62
68         #define C3 0x63
69         #define C4 0x64
70         #define C5 0x65
71         #define C6 0x66
72         #define C7 0x67
73         #define D0 0x90
74         #define D1 0x91
75         #define D2 0x92
76         #define D3 0x93
77         #define D4 0x94
78         #define D5 0x95
79         #define D6 0x96
80         #define D7 0x97
81         #define E0 0xC0
82         #define E1 0xC1
83         #define E2 0xC2
84         #define E3 0xC3
85         #define E4 0xC4
86         #define E5 0xC5
87         #define E6 0xC6
88         #define E7 0xC7
89         #define F0 0xF0
90         #define F1 0xF1
91         #define F2 0xF2
92         #define F3 0xF3
93         #define F4 0xF4
94         #define F5 0xF5
95         #define F6 0xF6
96         #define F7 0xF7
97         #define A0 0x00
98         #define A1 0x01
99         #define A2 0x02
100         #define A3 0x03
101         #define A4 0x04
102         #define A5 0x05
103         #define A6 0x06
104         #define A7 0x07
105
106         #include "Keyboard.h"
107
108         #ifndef QMK_ESC_INPUT
109             #define QMK_ESC_INPUT F1
110         #endif
111         #ifndef QMK_ESC_OUTPUT
112             #define QMK_ESC_OUTPUT D5
113         #endif
114         #ifndef QMK_LED
115             #define QMK_LED     E6
116         #endif
117         #ifndef QMK_SPEAKER
118             #define QMK_SPEAKER C6
119         #endif
120
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)
125
126     /* Public Interface - May be used in end-application: */
127         /* Macros: */
128             /** LED mask for the first LED on the board. */
129             #define LEDS_LED1        NUM(QMK_LED)
130             #define LEDS_LED2        NUM(QMK_SPEAKER)
131
132             /** LED mask for all the LEDs on the board. */
133             #define LEDS_ALL_LEDS    LEDS_LED1 | LEDS_LED2
134
135             /** LED mask for none of the board LEDs. */
136             #define LEDS_NO_LEDS     0
137
138         /* Inline Functions: */
139         #if !defined(__DOXYGEN__)
140             static inline void LEDs_Init(void)
141             {
142                 DDR(QMK_LED)  |= LEDS_LED1;
143                 PORT(QMK_LED) |= LEDS_LED1;
144
145                 DDR(QMK_SPEAKER)  |= LEDS_LED2;
146                 PORT(QMK_SPEAKER) |= LEDS_LED2;
147             }
148
149             static inline void LEDs_Disable(void)
150             {
151                 DDR(QMK_LED)  &= ~LEDS_LED1;
152                 PORT(QMK_LED) &= ~LEDS_LED2;
153
154                 DDR(QMK_SPEAKER)  &= ~LEDS_LED1;
155                 PORT(QMK_SPEAKER) &= ~LEDS_LED2;
156             }
157
158             static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
159             {
160                 PORT(QMK_LED) &= (LEDS_LED1 & ~LEDMask);
161                 PORT(QMK_SPEAKER) &= (LEDS_LED2 & ~LEDMask);
162             }
163
164             static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
165             {
166                 PORT(QMK_LED) |=  (LEDS_LED1 & LEDMask);
167                 PORT(QMK_SPEAKER) |=  (LEDS_LED2 & LEDMask);
168             }
169
170             static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
171             {
172                 PORT(QMK_LED) = ((PORT(QMK_LED) | LEDS_LED1) & ~LEDMask);
173                 PORT(QMK_SPEAKER) = ((PORT(QMK_SPEAKER) | LEDS_LED2) & ~LEDMask);
174             }
175
176             static inline void LEDs_ChangeLEDs(const uint8_t LEDMask,
177                                                const uint8_t ActiveMask)
178             {
179                 PORT(QMK_LED) = ((PORT(QMK_LED) | (LEDS_LED1 & LEDMask)) & ~ActiveMask);
180                 PORT(QMK_SPEAKER) = ((PORT(QMK_SPEAKER) | (LEDS_LED1 & LEDMask)) & ~ActiveMask);
181             }
182
183             static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
184             {
185                 PIN(QMK_LED)  = (LEDS_LED1 & LEDMask);
186                 PIN(QMK_SPEAKER)  = (LEDS_LED2 & LEDMask);
187             }
188
189             static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
190             static inline uint8_t LEDs_GetLEDs(void)
191             {
192                 return (~PORT(QMK_LED) & LEDS_LED1) | (~(PORT(QMK_SPEAKER) & LEDS_LED2));
193             }
194         #endif
195
196     /* Disable C linkage for C++ Compilers: */
197         #if defined(__cplusplus)
198             }
199         #endif
200
201 #endif
202
203 /** @} */
204