diff options
| author | Jack Humbert <jack.humb@gmail.com> | 2016-06-21 22:39:54 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-06-21 22:39:54 -0400 |
| commit | 649b33d7783cf3021928534b7ae127e0a89e8807 (patch) | |
| tree | c2b5e0cf8ff4aa2918e3b88ab75dbdb071cc0a1d /keyboards/preonic/preonic.c | |
| parent | 464c8e274f993d3571fe5ea5e836fe55a3912ffe (diff) | |
| download | qmk_firmware-649b33d7783cf3021928534b7ae127e0a89e8807.tar.gz qmk_firmware-649b33d7783cf3021928534b7ae127e0a89e8807.zip | |
Renames keyboard folder to keyboards, adds couple of tmk's fixes (#432)
* fixes from tmk's repo
* rename keyboard to keyboards
Diffstat (limited to 'keyboards/preonic/preonic.c')
| -rw-r--r-- | keyboards/preonic/preonic.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/keyboards/preonic/preonic.c b/keyboards/preonic/preonic.c new file mode 100644 index 000000000..773451bf0 --- /dev/null +++ b/keyboards/preonic/preonic.c | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | #include "preonic.h" | ||
| 2 | |||
| 3 | __attribute__ ((weak)) | ||
| 4 | void matrix_init_user(void) { | ||
| 5 | |||
| 6 | }; | ||
| 7 | |||
| 8 | __attribute__ ((weak)) | ||
| 9 | void matrix_scan_user(void) { | ||
| 10 | |||
| 11 | }; | ||
| 12 | |||
| 13 | __attribute__ ((weak)) | ||
| 14 | bool process_action_user(keyrecord_t *record) { | ||
| 15 | return true; | ||
| 16 | }; | ||
| 17 | |||
| 18 | void matrix_init_kb(void) { | ||
| 19 | #ifdef BACKLIGHT_ENABLE | ||
| 20 | backlight_init_ports(); | ||
| 21 | #endif | ||
| 22 | |||
| 23 | // Turn status LED on | ||
| 24 | DDRE |= (1<<6); | ||
| 25 | PORTE |= (1<<6); | ||
| 26 | |||
| 27 | matrix_init_user(); | ||
| 28 | }; | ||
| 29 | |||
| 30 | void matrix_scan_kb(void) { | ||
| 31 | matrix_scan_user(); | ||
| 32 | }; | ||
| 33 | |||
| 34 | bool process_action_kb(keyrecord_t *record) { | ||
| 35 | return process_action_user(record); | ||
| 36 | } | ||
| 37 | |||
| 38 | #ifdef BACKLIGHT_ENABLE | ||
| 39 | #define CHANNEL OCR1C | ||
| 40 | |||
| 41 | void backlight_init_ports() | ||
| 42 | { | ||
| 43 | |||
| 44 | // Setup PB7 as output and output low. | ||
| 45 | DDRB |= (1<<7); | ||
| 46 | PORTB &= ~(1<<7); | ||
| 47 | |||
| 48 | // Use full 16-bit resolution. | ||
| 49 | ICR1 = 0xFFFF; | ||
| 50 | |||
| 51 | // I could write a wall of text here to explain... but TL;DW | ||
| 52 | // Go read the ATmega32u4 datasheet. | ||
| 53 | // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on | ||
| 54 | |||
| 55 | // Pin PB7 = OCR1C (Timer 1, Channel C) | ||
| 56 | // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0 | ||
| 57 | // (i.e. start high, go low when counter matches.) | ||
| 58 | // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0 | ||
| 59 | // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1 | ||
| 60 | |||
| 61 | TCCR1A = _BV(COM1C1) | _BV(WGM11); // = 0b00001010; | ||
| 62 | TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; | ||
| 63 | |||
| 64 | backlight_init(); | ||
| 65 | } | ||
| 66 | |||
| 67 | void backlight_set(uint8_t level) | ||
| 68 | { | ||
| 69 | if ( level == 0 ) | ||
| 70 | { | ||
| 71 | // Turn off PWM control on PB7, revert to output low. | ||
| 72 | TCCR1A &= ~(_BV(COM1C1)); | ||
| 73 | CHANNEL = 0x0; | ||
| 74 | // Prevent backlight blink on lowest level | ||
| 75 | PORTB &= ~(_BV(PORTB7)); | ||
| 76 | } | ||
| 77 | else if ( level == BACKLIGHT_LEVELS ) | ||
| 78 | { | ||
| 79 | // Prevent backlight blink on lowest level | ||
| 80 | PORTB &= ~(_BV(PORTB7)); | ||
| 81 | // Turn on PWM control of PB7 | ||
| 82 | TCCR1A |= _BV(COM1C1); | ||
| 83 | // Set the brightness | ||
| 84 | CHANNEL = 0xFFFF; | ||
| 85 | } | ||
| 86 | else | ||
| 87 | { | ||
| 88 | // Prevent backlight blink on lowest level | ||
| 89 | PORTB &= ~(_BV(PORTB7)); | ||
| 90 | // Turn on PWM control of PB7 | ||
| 91 | TCCR1A |= _BV(COM1C1); | ||
| 92 | // Set the brightness | ||
| 93 | CHANNEL = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2)); | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | #endif | ||
