diff options
Diffstat (limited to 'keyboards/duck/jetfire/indicator_leds.c')
| -rw-r--r-- | keyboards/duck/jetfire/indicator_leds.c | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/keyboards/duck/jetfire/indicator_leds.c b/keyboards/duck/jetfire/indicator_leds.c new file mode 100644 index 000000000..7dbdb1ff7 --- /dev/null +++ b/keyboards/duck/jetfire/indicator_leds.c | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | /* | ||
| 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/>. | ||
| 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 "indicator_leds.h" | ||
| 21 | #include "quantum.h" | ||
| 22 | |||
| 23 | #define LED_T1H 900 | ||
| 24 | #define LED_T1L 600 | ||
| 25 | #define LED_T0H 400 | ||
| 26 | #define LED_T0L 900 | ||
| 27 | |||
| 28 | void send_bit_d4(bool bitVal) | ||
| 29 | { | ||
| 30 | if(bitVal) { | ||
| 31 | asm volatile ( | ||
| 32 | "sbi %[port], %[bit] \n\t" | ||
| 33 | ".rept %[onCycles] \n\t" | ||
| 34 | "nop \n\t" | ||
| 35 | ".endr \n\t" | ||
| 36 | "cbi %[port], %[bit] \n\t" | ||
| 37 | ".rept %[offCycles] \n\t" | ||
| 38 | "nop \n\t" | ||
| 39 | ".endr \n\t" | ||
| 40 | :: | ||
| 41 | [port] "I" (_SFR_IO_ADDR(PORTD)), | ||
| 42 | [bit] "I" (4), | ||
| 43 | [onCycles] "I" (NS_TO_CYCLES(LED_T1H) - 2), | ||
| 44 | [offCycles] "I" (NS_TO_CYCLES(LED_T1L) - 2)); | ||
| 45 | } else { | ||
| 46 | asm volatile ( | ||
| 47 | "sbi %[port], %[bit] \n\t" | ||
| 48 | ".rept %[onCycles] \n\t" | ||
| 49 | "nop \n\t" | ||
| 50 | ".endr \n\t" | ||
| 51 | "cbi %[port], %[bit] \n\t" | ||
| 52 | ".rept %[offCycles] \n\t" | ||
| 53 | "nop \n\t" | ||
| 54 | ".endr \n\t" | ||
| 55 | :: | ||
| 56 | [port] "I" (_SFR_IO_ADDR(PORTD)), | ||
| 57 | [bit] "I" (4), | ||
| 58 | [onCycles] "I" (NS_TO_CYCLES(LED_T0H) - 2), | ||
| 59 | [offCycles] "I" (NS_TO_CYCLES(LED_T0L) - 2)); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | void send_bit_d6(bool bitVal) | ||
| 64 | { | ||
| 65 | if(bitVal) { | ||
| 66 | asm volatile ( | ||
| 67 | "sbi %[port], %[bit] \n\t" | ||
| 68 | ".rept %[onCycles] \n\t" | ||
| 69 | "nop \n\t" | ||
| 70 | ".endr \n\t" | ||
| 71 | "cbi %[port], %[bit] \n\t" | ||
| 72 | ".rept %[offCycles] \n\t" | ||
| 73 | "nop \n\t" | ||
| 74 | ".endr \n\t" | ||
| 75 | :: | ||
| 76 | [port] "I" (_SFR_IO_ADDR(PORTD)), | ||
| 77 | [bit] "I" (6), | ||
| 78 | [onCycles] "I" (NS_TO_CYCLES(LED_T1H) - 2), | ||
| 79 | [offCycles] "I" (NS_TO_CYCLES(LED_T1L) - 2)); | ||
| 80 | } else { | ||
| 81 | asm volatile ( | ||
| 82 | "sbi %[port], %[bit] \n\t" | ||
| 83 | ".rept %[onCycles] \n\t" | ||
| 84 | "nop \n\t" | ||
| 85 | ".endr \n\t" | ||
| 86 | "cbi %[port], %[bit] \n\t" | ||
| 87 | ".rept %[offCycles] \n\t" | ||
| 88 | "nop \n\t" | ||
| 89 | ".endr \n\t" | ||
| 90 | :: | ||
| 91 | [port] "I" (_SFR_IO_ADDR(PORTD)), | ||
| 92 | [bit] "I" (6), | ||
| 93 | [onCycles] "I" (NS_TO_CYCLES(LED_T0H) - 2), | ||
| 94 | [offCycles] "I" (NS_TO_CYCLES(LED_T0L) - 2)); | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | void send_value(uint8_t byte, enum Device device) | ||
| 99 | { | ||
| 100 | for(uint8_t b = 0; b < 8; b++) { | ||
| 101 | if(device == Device_STATUSLED) { | ||
| 102 | send_bit_d4(byte & 0b10000000); | ||
| 103 | } | ||
| 104 | if(device == Device_PCBRGB) { | ||
| 105 | send_bit_d6(byte & 0b10000000); | ||
| 106 | } | ||
| 107 | byte <<= 1; | ||
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | void send_color(uint8_t r, uint8_t g, uint8_t b, enum Device device) | ||
| 112 | { | ||
| 113 | send_value(r, device); | ||
| 114 | send_value(g, device); | ||
| 115 | send_value(b, device); | ||
| 116 | } | ||
