qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

17.c (835B)


      1 #include "quantum.h"
      2 
      3 int pwm_level;
      4 
      5 void backlight_init_ports(void) {
      6     // Set C7 to output
      7     DDRC |= (1<<7);
      8 
      9     // Initialize the timer
     10     TC4H = 0x03;
     11     OCR4C = 0xFF;
     12     TCCR4A = 0b10000010;
     13     TCCR4B = 0b00000001;
     14 }
     15 
     16 void backlight_set(uint8_t level) {
     17     // Determine the PWM level
     18     switch (level)
     19     {
     20         case 0:
     21             // 33%
     22             pwm_level = 0x54;
     23             break;
     24         case 1:
     25             // 66%
     26             pwm_level = 0xA8;
     27             break;
     28         case 2:
     29             // 100%
     30             pwm_level = 0xFF;
     31             break;
     32         case 3:
     33             // 0%
     34             pwm_level = 0x00;
     35             break;
     36         default:
     37             xprintf("Unknown level: %d\n", level);
     38     }
     39 
     40     // Write the PWM level to the timer
     41     TC4H = pwm_level >> 8;
     42     OCR4A = 0xFF & pwm_level;
     43 }