diff options
| author | Jack Humbert <jack.humb@gmail.com> | 2016-06-21 22:09:41 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-06-21 22:09:41 -0400 |
| commit | 464c8e274f993d3571fe5ea5e836fe55a3912ffe (patch) | |
| tree | 9d5c08ccf6de468a397f20a5438e72276977fe62 /keyboard/satan/satan.c | |
| parent | e329729d3a11b5798f4e2b9f65ac9bc2dcc84a9e (diff) | |
| download | qmk_firmware-464c8e274f993d3571fe5ea5e836fe55a3912ffe.tar.gz qmk_firmware-464c8e274f993d3571fe5ea5e836fe55a3912ffe.zip | |
adds backlight levels to the satan keyboard (#431)
* enable 4 levels
* remove breathing stuff
* update channels, comments, hex
Diffstat (limited to 'keyboard/satan/satan.c')
| -rw-r--r-- | keyboard/satan/satan.c | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/keyboard/satan/satan.c b/keyboard/satan/satan.c index 40bd9dcde..092eb4665 100644 --- a/keyboard/satan/satan.c +++ b/keyboard/satan/satan.c | |||
| @@ -14,6 +14,64 @@ void matrix_scan_user(void) { | |||
| 14 | // leave these blank | 14 | // leave these blank |
| 15 | }; | 15 | }; |
| 16 | 16 | ||
| 17 | |||
| 18 | #ifdef BACKLIGHT_ENABLE | ||
| 19 | |||
| 20 | void backlight_init_ports() | ||
| 21 | { | ||
| 22 | |||
| 23 | // Setup PB6 as output and output low. | ||
| 24 | DDRB |= (1<<6); | ||
| 25 | PORTB &= ~(1<<6); | ||
| 26 | |||
| 27 | // Use full 16-bit resolution. | ||
| 28 | ICR1 = 0xFFFF; | ||
| 29 | |||
| 30 | // I could write a wall of text here to explain... but TL;DW | ||
| 31 | // Go read the ATmega32u4 datasheet. | ||
| 32 | // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on | ||
| 33 | |||
| 34 | // Pin PB6 = OCR1B (Timer 1, Channel C) | ||
| 35 | // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0 | ||
| 36 | // (i.e. start high, go low when counter matches.) | ||
| 37 | // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0 | ||
| 38 | // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1 | ||
| 39 | |||
| 40 | TCCR1A = _BV(COM1B1) | _BV(WGM11); // = 0b00001010; | ||
| 41 | TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; | ||
| 42 | |||
| 43 | backlight_init(); | ||
| 44 | } | ||
| 45 | |||
| 46 | void backlight_set(uint8_t level) | ||
| 47 | { | ||
| 48 | // Prevent backlight blink on lowest level | ||
| 49 | PORTB &= ~(_BV(PORTB6)); | ||
| 50 | |||
| 51 | if ( level == 0 ) | ||
| 52 | { | ||
| 53 | // Turn off PWM control on PB6, revert to output low. | ||
| 54 | TCCR1A &= ~(_BV(COM1B1)); | ||
| 55 | OCR1B = 0x0; | ||
| 56 | } | ||
| 57 | else if ( level == BACKLIGHT_LEVELS ) | ||
| 58 | { | ||
| 59 | // Turn on PWM control of PB6 | ||
| 60 | TCCR1A |= _BV(COM1B1); | ||
| 61 | // Set the brightness | ||
| 62 | OCR1B = 0xFFFF; | ||
| 63 | } | ||
| 64 | else | ||
| 65 | { | ||
| 66 | // Turn on PWM control of PB6 | ||
| 67 | TCCR1A |= _BV(COM1B1); | ||
| 68 | // Set the brightness | ||
| 69 | OCR1B = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2)); | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | #endif | ||
| 74 | |||
| 17 | void matrix_init_kb(void) { | 75 | void matrix_init_kb(void) { |
| 18 | // put your keyboard start-up code here | 76 | // put your keyboard start-up code here |
| 19 | // runs once when the firmware starts up | 77 | // runs once when the firmware starts up |
| @@ -23,7 +81,7 @@ void matrix_init_kb(void) { | |||
| 23 | led_init_ports(); | 81 | led_init_ports(); |
| 24 | 82 | ||
| 25 | #ifdef BACKLIGHT_ENABLE | 83 | #ifdef BACKLIGHT_ENABLE |
| 26 | init_backlight_pin(); | 84 | backlight_init_ports(); |
| 27 | #endif | 85 | #endif |
| 28 | }; | 86 | }; |
| 29 | 87 | ||
| @@ -33,4 +91,4 @@ void matrix_scan_kb(void) { | |||
| 33 | if (matrix_scan_user) { | 91 | if (matrix_scan_user) { |
| 34 | (*matrix_scan_user)(); | 92 | (*matrix_scan_user)(); |
| 35 | } | 93 | } |
| 36 | }; | 94 | }; \ No newline at end of file |
