X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=quantum%2Fquantum.c;h=4a6d0355fabe1590226aa5672ea89d41fe385545;hb=7042af702057d4d129f1517712fab7f28e75b2f3;hp=0aecd238e45f9813e5a0a2da9a21cad8b972c558;hpb=f644b9a07a34ae19a6014b08db656a4eeca1dcda;p=qmk_firmware.git diff --git a/quantum/quantum.c b/quantum/quantum.c index 0aecd238e..4a6d0355f 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -1,9 +1,16 @@ #include "quantum.h" +#ifdef PROTOCOL_LUFA +#include "outputselect.h" +#endif #ifndef TAPPING_TERM #define TAPPING_TERM 200 #endif +#ifdef FAUXCLICKY_ENABLE +#include "fauxclicky.h" +#endif + static void do_code16 (uint16_t code, void (*f) (uint8_t)) { switch (code) { case QK_MODS ... QK_MODS_MAX: @@ -158,6 +165,9 @@ bool process_record_quantum(keyrecord_t *record) { #ifndef DISABLE_CHORDING process_chording(keycode, record) && #endif + #ifdef COMBO_ENABLE + process_combo(keycode, record) && + #endif #ifdef UNICODE_ENABLE process_unicode(keycode, record) && #endif @@ -190,6 +200,26 @@ bool process_record_quantum(keyrecord_t *record) { } return false; break; + #ifdef FAUXCLICKY_ENABLE + case FC_TOG: + if (record->event.pressed) { + FAUXCLICKY_TOGGLE; + } + return false; + break; + case FC_ON: + if (record->event.pressed) { + FAUXCLICKY_ON; + } + return false; + break; + case FC_OFF: + if (record->event.pressed) { + FAUXCLICKY_OFF; + } + return false; + break; + #endif #ifdef RGBLIGHT_ENABLE case RGB_TOG: if (record->event.pressed) { @@ -240,6 +270,36 @@ bool process_record_quantum(keyrecord_t *record) { return false; break; #endif + #ifdef PROTOCOL_LUFA + case OUT_AUTO: + if (record->event.pressed) { + set_output(OUTPUT_AUTO); + } + return false; + break; + case OUT_USB: + if (record->event.pressed) { + set_output(OUTPUT_USB); + } + return false; + break; + #ifdef BLUETOOTH_ENABLE + case OUT_BT: + if (record->event.pressed) { + set_output(OUTPUT_BLUETOOTH); + } + return false; + break; + #endif + #ifdef ADAFRUIT_BLE_ENABLE + case OUT_BLE: + if (record->event.pressed) { + set_output(OUTPUT_ADAFRUIT_BLE); + } + return false; + break; + #endif + #endif case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_NKRO: if (record->event.pressed) { // MAGIC actions (BOOTMAGIC without the boot) @@ -536,6 +596,11 @@ void matrix_scan_quantum() { #ifdef TAP_DANCE_ENABLE matrix_scan_tap_dance(); #endif + + #ifdef COMBO_ENABLE + matrix_scan_combo(); + #endif + matrix_scan_kb(); } @@ -553,34 +618,45 @@ static const uint8_t backlight_pin = BACKLIGHT_PIN; # define COM1x1 COM1A1 # define OCR1x OCR1A #else -# error "Backlight pin not supported - use B5, B6, or B7" +# define NO_BACKLIGHT_CLOCK +#endif + +#ifndef BACKLIGHT_ON_STATE +#define BACKLIGHT_ON_STATE 0 #endif __attribute__ ((weak)) void backlight_init_ports(void) { - // Setup backlight pin as output and output low. + // Setup backlight pin as output and output to on state. // DDRx |= n _SFR_IO8((backlight_pin >> 4) + 1) |= _BV(backlight_pin & 0xF); - // PORTx &= ~n - _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF); + #if BACKLIGHT_ON_STATE == 0 + // PORTx &= ~n + _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF); + #else + // PORTx |= n + _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF); + #endif - // Use full 16-bit resolution. - ICR1 = 0xFFFF; + #ifndef NO_BACKLIGHT_CLOCK + // Use full 16-bit resolution. + ICR1 = 0xFFFF; - // I could write a wall of text here to explain... but TL;DW - // Go read the ATmega32u4 datasheet. - // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on + // I could write a wall of text here to explain... but TL;DW + // Go read the ATmega32u4 datasheet. + // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on - // Pin PB7 = OCR1C (Timer 1, Channel C) - // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0 - // (i.e. start high, go low when counter matches.) - // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0 - // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1 + // Pin PB7 = OCR1C (Timer 1, Channel C) + // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0 + // (i.e. start high, go low when counter matches.) + // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0 + // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1 - TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010; - TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; + TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010; + TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; + #endif backlight_init(); #ifdef BACKLIGHT_BREATHING @@ -592,24 +668,43 @@ __attribute__ ((weak)) void backlight_set(uint8_t level) { // Prevent backlight blink on lowest level - // PORTx &= ~n - _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF); + #if BACKLIGHT_ON_STATE == 0 + // PORTx &= ~n + _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF); + #else + // PORTx |= n + _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF); + #endif if ( level == 0 ) { - // Turn off PWM control on backlight pin, revert to output low. - TCCR1A &= ~(_BV(COM1x1)); - OCR1x = 0x0; - } else if ( level == BACKLIGHT_LEVELS ) { - // Turn on PWM control of backlight pin - TCCR1A |= _BV(COM1x1); - // Set the brightness - OCR1x = 0xFFFF; - } else { - // Turn on PWM control of backlight pin - TCCR1A |= _BV(COM1x1); - // Set the brightness - OCR1x = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2)); - } + #ifndef NO_BACKLIGHT_CLOCK + // Turn off PWM control on backlight pin, revert to output low. + TCCR1A &= ~(_BV(COM1x1)); + OCR1x = 0x0; + #else + #if BACKLIGHT_ON_STATE == 0 + // PORTx |= n + _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF); + #else + // PORTx &= ~n + _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF); + #endif + #endif + } + #ifndef NO_BACKLIGHT_CLOCK + else if ( level == BACKLIGHT_LEVELS ) { + // Turn on PWM control of backlight pin + TCCR1A |= _BV(COM1x1); + // Set the brightness + OCR1x = 0xFFFF; + } + else { + // Turn on PWM control of backlight pin + TCCR1A |= _BV(COM1x1); + // Set the brightness + OCR1x = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2)); + } + #endif #ifdef BACKLIGHT_BREATHING breathing_intensity_default(); @@ -877,6 +972,19 @@ void send_nibble(uint8_t number) { } } + +__attribute__((weak)) +uint16_t hex_to_keycode(uint8_t hex) +{ + if (hex == 0x0) { + return KC_0; + } else if (hex < 0xA) { + return KC_1 + (hex - 0x1); + } else { + return KC_A + (hex - 0xA); + } +} + void api_send_unicode(uint32_t unicode) { #ifdef API_ENABLE uint8_t chunk[4];