aboutsummaryrefslogtreecommitdiff
path: root/keyboards/duck/jetfire/backlight_led.c
diff options
context:
space:
mode:
authorMechMerlin <30334081+mechmerlin@users.noreply.github.com>2018-08-25 18:00:20 -0700
committerDrashna Jaelre <drashna@live.com>2018-08-25 18:00:20 -0700
commite16b39f0c20c73348ae12af0e82e4b4c0d30b393 (patch)
tree74d33ae10f38fb4fbb39ab2eaa298f9ecdd272cf /keyboards/duck/jetfire/backlight_led.c
parenta68057852bbffc45f783523a86a6aa2e80a03d44 (diff)
downloadqmk_firmware-e16b39f0c20c73348ae12af0e82e4b4c0d30b393.tar.gz
qmk_firmware-e16b39f0c20c73348ae12af0e82e4b4c0d30b393.zip
Keyboard: Duck Jetfire QMK Support (#3752)
* Initial Commit Port from xauser's jetfire code. Does not compile yet * fix up keymap from uint8 to uin16 * update rules file to contain custom matrix * Good stopping point Still lots of compile errors but I'm getting there. * fix a few more compile errors * move a few functions around to help with compiling * Finally got it all to compile * Get rid of that old KEYMAP macro * edit readme * Put my name everywhere and some minor code clean ups * start to remove that kc nonsense * fix keymap compilation issues * add reset key info * better human readable formatting * match the duck default layout * add confgurator support * clarify reset key * might be a good idea to use the correct pin * get the riight keycode for RGB * include an ALL layout * I tried to fix the formatting....sigh * add functons to ensure Configurator compile-ability * move jetfire to duck directory * Moved and renamed things as per Drashna's PR comments as his back was hurting as he reviewed this
Diffstat (limited to 'keyboards/duck/jetfire/backlight_led.c')
-rw-r--r--keyboards/duck/jetfire/backlight_led.c129
1 files changed, 129 insertions, 0 deletions
diff --git a/keyboards/duck/jetfire/backlight_led.c b/keyboards/duck/jetfire/backlight_led.c
new file mode 100644
index 000000000..7e9dca6e9
--- /dev/null
+++ b/keyboards/duck/jetfire/backlight_led.c
@@ -0,0 +1,129 @@
1/*
2Copyright 2016 Ralf Schmitt <ralf@bunkertor.net>
3This program is free software: you can redistribute it and/or modify
4it under the terms of the GNU General Public License as published by
5the Free Software Foundation, either version 2 of the License, or
6(at your option) any later version.
7This program is distributed in the hope that it will be useful,
8but WITHOUT ANY WARRANTY; without even the implied warranty of
9MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10GNU General Public License for more details.
11You should have received a copy of the GNU General Public License
12along with this program. If not, see <http://www.gnu.org/licenses/>.
13*/
14
15#include <avr/interrupt.h>
16#include <avr/io.h>
17#include <stdbool.h>
18#include <util/delay.h>
19#include <stdint.h>
20#include "backlight_led.h"
21#include "quantum.h"
22// #include "led.h"
23
24
25#define T1H 900
26#define T1L 600
27#define T0H 400
28#define T0L 900
29#define RES 6000
30
31#define NS_PER_SEC (1000000000L)
32#define CYCLES_PER_SEC (F_CPU)
33#define NS_PER_CYCLE (NS_PER_SEC / CYCLES_PER_SEC)
34#define NS_TO_CYCLES(n) ((n) / NS_PER_CYCLE)
35
36void send_bit_d4(bool bitVal)
37{
38 if(bitVal) {
39 asm volatile (
40 "sbi %[port], %[bit] \n\t"
41 ".rept %[onCycles] \n\t"
42 "nop \n\t"
43 ".endr \n\t"
44 "cbi %[port], %[bit] \n\t"
45 ".rept %[offCycles] \n\t"
46 "nop \n\t"
47 ".endr \n\t"
48 ::
49 [port] "I" (_SFR_IO_ADDR(PORTD)),
50 [bit] "I" (4),
51 [onCycles] "I" (NS_TO_CYCLES(T1H) - 2),
52 [offCycles] "I" (NS_TO_CYCLES(T1L) - 2));
53 } else {
54 asm volatile (
55 "sbi %[port], %[bit] \n\t"
56 ".rept %[onCycles] \n\t"
57 "nop \n\t"
58 ".endr \n\t"
59 "cbi %[port], %[bit] \n\t"
60 ".rept %[offCycles] \n\t"
61 "nop \n\t"
62 ".endr \n\t"
63 ::
64 [port] "I" (_SFR_IO_ADDR(PORTD)),
65 [bit] "I" (4),
66 [onCycles] "I" (NS_TO_CYCLES(T0H) - 2),
67 [offCycles] "I" (NS_TO_CYCLES(T0L) - 2));
68 }
69}
70
71void send_bit_d6(bool bitVal)
72{
73 if(bitVal) {
74 asm volatile (
75 "sbi %[port], %[bit] \n\t"
76 ".rept %[onCycles] \n\t"
77 "nop \n\t"
78 ".endr \n\t"
79 "cbi %[port], %[bit] \n\t"
80 ".rept %[offCycles] \n\t"
81 "nop \n\t"
82 ".endr \n\t"
83 ::
84 [port] "I" (_SFR_IO_ADDR(PORTD)),
85 [bit] "I" (6),
86 [onCycles] "I" (NS_TO_CYCLES(T1H) - 2),
87 [offCycles] "I" (NS_TO_CYCLES(T1L) - 2));
88 } else {
89 asm volatile (
90 "sbi %[port], %[bit] \n\t"
91 ".rept %[onCycles] \n\t"
92 "nop \n\t"
93 ".endr \n\t"
94 "cbi %[port], %[bit] \n\t"
95 ".rept %[offCycles] \n\t"
96 "nop \n\t"
97 ".endr \n\t"
98 ::
99 [port] "I" (_SFR_IO_ADDR(PORTD)),
100 [bit] "I" (6),
101 [onCycles] "I" (NS_TO_CYCLES(T0H) - 2),
102 [offCycles] "I" (NS_TO_CYCLES(T0L) - 2));
103 }
104}
105
106void show(void)
107{
108 _delay_us((RES / 1000UL) + 1);
109}
110
111void send_value(uint8_t byte, enum Device device)
112{
113 for(uint8_t b = 0; b < 8; b++) {
114 if(device == Device_STATELED) {
115 send_bit_d4(byte & 0b10000000);
116 }
117 if(device == Device_PCBRGB) {
118 send_bit_d6(byte & 0b10000000);
119 }
120 byte <<= 1;
121 }
122}
123
124void send_color(uint8_t r, uint8_t g, uint8_t b, enum Device device)
125{
126 send_value(g, device);
127 send_value(r, device);
128 send_value(b, device);
129}