2 Copyright 2016 Ralf Schmitt <ralf@bunkertor.net>
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/>.
15 #include <avr/interrupt.h>
18 #include <util/delay.h>
20 #include "indicator_leds.h"
28 void send_bit_d4(bool bitVal)
32 "sbi %[port], %[bit] \n\t"
33 ".rept %[onCycles] \n\t"
36 "cbi %[port], %[bit] \n\t"
37 ".rept %[offCycles] \n\t"
41 [port] "I" (_SFR_IO_ADDR(PORTD)),
43 [onCycles] "I" (NS_TO_CYCLES(LED_T1H) - 2),
44 [offCycles] "I" (NS_TO_CYCLES(LED_T1L) - 2));
47 "sbi %[port], %[bit] \n\t"
48 ".rept %[onCycles] \n\t"
51 "cbi %[port], %[bit] \n\t"
52 ".rept %[offCycles] \n\t"
56 [port] "I" (_SFR_IO_ADDR(PORTD)),
58 [onCycles] "I" (NS_TO_CYCLES(LED_T0H) - 2),
59 [offCycles] "I" (NS_TO_CYCLES(LED_T0L) - 2));
63 void send_bit_d6(bool bitVal)
67 "sbi %[port], %[bit] \n\t"
68 ".rept %[onCycles] \n\t"
71 "cbi %[port], %[bit] \n\t"
72 ".rept %[offCycles] \n\t"
76 [port] "I" (_SFR_IO_ADDR(PORTD)),
78 [onCycles] "I" (NS_TO_CYCLES(LED_T1H) - 2),
79 [offCycles] "I" (NS_TO_CYCLES(LED_T1L) - 2));
82 "sbi %[port], %[bit] \n\t"
83 ".rept %[onCycles] \n\t"
86 "cbi %[port], %[bit] \n\t"
87 ".rept %[offCycles] \n\t"
91 [port] "I" (_SFR_IO_ADDR(PORTD)),
93 [onCycles] "I" (NS_TO_CYCLES(LED_T0H) - 2),
94 [offCycles] "I" (NS_TO_CYCLES(LED_T0L) - 2));
98 void send_value(uint8_t byte, enum Device device)
100 for(uint8_t b = 0; b < 8; b++) {
101 if(device == Device_STATUSLED) {
102 send_bit_d4(byte & 0b10000000);
104 if(device == Device_PCBRGB) {
105 send_bit_d6(byte & 0b10000000);
111 void send_color(uint8_t r, uint8_t g, uint8_t b, enum Device device)
113 send_value(r, device);
114 send_value(g, device);
115 send_value(b, device);