diff --git a/keyboards/massdrop/alt/alt.h b/keyboards/massdrop/alt/alt.h index 8dfed8d2d6d8..36c6de2d073c 100644 --- a/keyboards/massdrop/alt/alt.h +++ b/keyboards/massdrop/alt/alt.h @@ -6,6 +6,7 @@ #include "i2c_master.h" #include "led_matrix.h" //For led keycodes +#include "led_instructions.h" #include "usb/udi_cdc.h" #include "usb/usb2422.h" @@ -32,3 +33,111 @@ dprintf(name " enabled\r\n"); \ } \ } + +// Rows/cols match key matrix. Values correspond to LED IDs. +static const uint8_t MATRIX_TO_LED_ID[MATRIX_ROWS][MATRIX_COLS] = { + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, + { 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 }, + { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 0, 43, 44 }, + { 45, 0, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58 }, + { 59, 60, 61, 0, 0, 0, 62, 0, 0, 0, 63, 64, 65, 66, 67 }, +}; + +static const keypos_t LED_ID_TO_KEYMAP[68] = { + { .col = -1, .row = -1 }, // Dummy row for 0s above + + // 1 - 15 + { .col = 0, .row = 0 }, + { .col = 1, .row = 0 }, + { .col = 2, .row = 0 }, + { .col = 3, .row = 0 }, + { .col = 4, .row = 0 }, + { .col = 5, .row = 0 }, + { .col = 6, .row = 0 }, + { .col = 7, .row = 0 }, + { .col = 8, .row = 0 }, + { .col = 9, .row = 0 }, + { .col = 10, .row = 0 }, + { .col = 11, .row = 0 }, + { .col = 12, .row = 0 }, + { .col = 13, .row = 0 }, + { .col = 14, .row = 0 }, // LED 15 + + // 16 - 30 + { .col = 0, .row = 1 }, + { .col = 1, .row = 1 }, + { .col = 2, .row = 1 }, + { .col = 3, .row = 1 }, + { .col = 4, .row = 1 }, + { .col = 5, .row = 1 }, + { .col = 6, .row = 1 }, + { .col = 7, .row = 1 }, + { .col = 8, .row = 1 }, + { .col = 9, .row = 1 }, + { .col = 10, .row = 1 }, + { .col = 11, .row = 1 }, + { .col = 12, .row = 1 }, + { .col = 13, .row = 1 }, + { .col = 14, .row = 1 }, // LED 30 + + // 31 - 44 + { .col = 0, .row = 2 }, + { .col = 1, .row = 2 }, + { .col = 2, .row = 2 }, + { .col = 3, .row = 2 }, + { .col = 4, .row = 2 }, + { .col = 5, .row = 2 }, + { .col = 6, .row = 2 }, + { .col = 7, .row = 2 }, + { .col = 8, .row = 2 }, + { .col = 9, .row = 2 }, + { .col = 10, .row = 2 }, + { .col = 11, .row = 2 }, // LED 42 + // gap + { .col = 13, .row = 2 }, + { .col = 14, .row = 2 }, + + // 45 - 58 + { .col = 0, .row = 3 }, + // gap + { .col = 2, .row = 3 }, + { .col = 3, .row = 3 }, + { .col = 4, .row = 3 }, + { .col = 5, .row = 3 }, + { .col = 6, .row = 3 }, + { .col = 7, .row = 3 }, + { .col = 8, .row = 3 }, + { .col = 9, .row = 3 }, + { .col = 10, .row = 3 }, + { .col = 11, .row = 3 }, + { .col = 12, .row = 3 }, + { .col = 13, .row = 3 }, + { .col = 14, .row = 3 }, + + // 59 - 67 + { .col = 0, .row = 4 }, + { .col = 1, .row = 4 }, + { .col = 2, .row = 4 }, + // gap + // gap + // gap + { .col = 6, .row = 4 }, + // gap + // gap + // gap + { .col = 10, .row = 4 }, + { .col = 11, .row = 4 }, + { .col = 12, .row = 4 }, + { .col = 13, .row = 4 }, + { .col = 14, .row = 4 }, +}; + +// Rows/cols match key laoyut. Values correspond to LED IDs. +// Note that matrix and key layout may not match (see CTRL Keyboard) +static const uint8_t KEYMAP_TO_LED_ID[KEYMAP_ROWS][KEYMAP_COLS] = { + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, + { 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 }, + { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 0, 43, 44 }, + { 45, 0, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58 }, + { 59, 60, 61, 0, 0, 0, 62, 0, 0, 0, 63, 64, 65, 66, 67 }, +}; diff --git a/keyboards/massdrop/alt/config.h b/keyboards/massdrop/alt/config.h index a486f34a0c41..7e2bebb23505 100644 --- a/keyboards/massdrop/alt/config.h +++ b/keyboards/massdrop/alt/config.h @@ -32,6 +32,9 @@ along with this program. If not, see . #define MATRIX_ROWS 5 #define MATRIX_COLS 15 +#define KEYMAP_ROWS 5 +#define KEYMAP_COLS 15 + #define PA 0 #define PB 1 diff --git a/keyboards/massdrop/alt/config_led.h b/keyboards/massdrop/alt/config_led.h index a049e38179a6..ad5035e6820b 100644 --- a/keyboards/massdrop/alt/config_led.h +++ b/keyboards/massdrop/alt/config_led.h @@ -41,7 +41,7 @@ along with this program. If not, see . #define V5_LOW 2480 //5V low level (LED power rolled back to stay above this limit) #define V5_CAT 2200 //5V catastrophic level (Host USB port potential to shut down) -#define ANIMATION_SPEED_STEP 1 +#define ANIMATION_SPEED_STEP 1.1 #define BREATHE_MIN_STEP 0 #define BREATHE_MAX_STEP 255 diff --git a/keyboards/massdrop/alt/keymaps/default/keymap.c b/keyboards/massdrop/alt/keymaps/default/keymap.c index e628bfe4a1c9..b670a6616ca1 100644 --- a/keyboards/massdrop/alt/keymaps/default/keymap.c +++ b/keyboards/massdrop/alt/keymaps/default/keymap.c @@ -100,13 +100,12 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { return false; case L_PSI: if (record->event.pressed) { - led_animation_speed += ANIMATION_SPEED_STEP; + led_animation_period_scalar /= ANIMATION_SPEED_STEP; } return false; case L_PSD: if (record->event.pressed) { - led_animation_speed -= ANIMATION_SPEED_STEP; - if (led_animation_speed < 0) led_animation_speed = 0; + led_animation_period_scalar *= ANIMATION_SPEED_STEP; } return false; case L_T_MD: diff --git a/keyboards/massdrop/alt/keymaps/example_custom_patterns/keymap.c b/keyboards/massdrop/alt/keymaps/example_custom_patterns/keymap.c new file mode 100644 index 000000000000..b670a6616ca1 --- /dev/null +++ b/keyboards/massdrop/alt/keymaps/example_custom_patterns/keymap.c @@ -0,0 +1,196 @@ +#include QMK_KEYBOARD_H + +enum alt_keycodes { + L_BRI = SAFE_RANGE, //LED Brightness Increase + L_BRD, //LED Brightness Decrease + L_PTN, //LED Pattern Select Next + L_PTP, //LED Pattern Select Previous + L_PSI, //LED Pattern Speed Increase + L_PSD, //LED Pattern Speed Decrease + L_T_MD, //LED Toggle Mode + L_T_ONF, //LED Toggle On / Off + L_ON, //LED On + L_OFF, //LED Off + L_T_BR, //LED Toggle Breath Effect + L_T_PTD, //LED Toggle Scrolling Pattern Direction + U_T_AUTO, //USB Extra Port Toggle Auto Detect / Always Active + U_T_AGCR, //USB Toggle Automatic GCR control + DBG_TOG, //DEBUG Toggle On / Off + DBG_MTRX, //DEBUG Toggle Matrix Prints + DBG_KBD, //DEBUG Toggle Keyboard Prints + DBG_MOU, //DEBUG Toggle Mouse Prints + MD_BOOT, //Restart into bootloader after hold timeout +}; + +#define TG_NKRO MAGIC_TOGGLE_NKRO //Toggle 6KRO / NKRO mode + +keymap_config_t keymap_config; + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = LAYOUT( + KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_DEL, \ + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_HOME, \ + KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGUP, \ + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_PGDN, \ + KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(1), KC_LEFT, KC_DOWN, KC_RGHT \ + ), + [1] = LAYOUT( + KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_TRNS, KC_MUTE, \ + L_T_BR, L_PSD, L_BRI, L_PSI, KC_TRNS, KC_TRNS, KC_TRNS, U_T_AUTO,U_T_AGCR,KC_TRNS, KC_PSCR, KC_SLCK, KC_PAUS, KC_TRNS, KC_END, \ + L_T_PTD, L_PTP, L_BRD, L_PTN, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_VOLU, \ + KC_TRNS, L_T_MD, L_T_ONF, KC_TRNS, KC_TRNS, MD_BOOT, TG_NKRO, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PGUP, KC_VOLD, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_PGDN, KC_END \ + ), + /* + [X] = LAYOUT( + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS \ + ), + */ +}; + +const uint16_t PROGMEM fn_actions[] = { + +}; + +// Runs just one time when the keyboard initializes. +void matrix_init_user(void) { +}; + +// Runs constantly in the background, in a loop. +void matrix_scan_user(void) { +}; + +#define MODS_SHIFT (keyboard_report->mods & MOD_BIT(KC_LSHIFT) || keyboard_report->mods & MOD_BIT(KC_RSHIFT)) +#define MODS_CTRL (keyboard_report->mods & MOD_BIT(KC_LCTL) || keyboard_report->mods & MOD_BIT(KC_RCTRL)) +#define MODS_ALT (keyboard_report->mods & MOD_BIT(KC_LALT) || keyboard_report->mods & MOD_BIT(KC_RALT)) + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + static uint32_t key_timer; + + switch (keycode) { + case L_BRI: + if (record->event.pressed) { + if (LED_GCR_STEP > LED_GCR_MAX - gcr_desired) gcr_desired = LED_GCR_MAX; + else gcr_desired += LED_GCR_STEP; + if (led_animation_breathing) gcr_breathe = gcr_desired; + } + return false; + case L_BRD: + if (record->event.pressed) { + if (LED_GCR_STEP > gcr_desired) gcr_desired = 0; + else gcr_desired -= LED_GCR_STEP; + if (led_animation_breathing) gcr_breathe = gcr_desired; + } + return false; + case L_PTN: + if (record->event.pressed) { + if (led_animation_id == led_setups_count - 1) led_animation_id = 0; + else led_animation_id++; + } + return false; + case L_PTP: + if (record->event.pressed) { + if (led_animation_id == 0) led_animation_id = led_setups_count - 1; + else led_animation_id--; + } + return false; + case L_PSI: + if (record->event.pressed) { + led_animation_period_scalar /= ANIMATION_SPEED_STEP; + } + return false; + case L_PSD: + if (record->event.pressed) { + led_animation_period_scalar *= ANIMATION_SPEED_STEP; + } + return false; + case L_T_MD: + if (record->event.pressed) { + led_lighting_mode++; + if (led_lighting_mode > LED_MODE_MAX_INDEX) led_lighting_mode = LED_MODE_NORMAL; + } + return false; + case L_T_ONF: + if (record->event.pressed) { + led_enabled = !led_enabled; + I2C3733_Control_Set(led_enabled); + } + return false; + case L_ON: + if (record->event.pressed) { + led_enabled = 1; + I2C3733_Control_Set(led_enabled); + } + return false; + case L_OFF: + if (record->event.pressed) { + led_enabled = 0; + I2C3733_Control_Set(led_enabled); + } + return false; + case L_T_BR: + if (record->event.pressed) { + led_animation_breathing = !led_animation_breathing; + if (led_animation_breathing) { + gcr_breathe = gcr_desired; + led_animation_breathe_cur = BREATHE_MIN_STEP; + breathe_dir = 1; + } + } + return false; + case L_T_PTD: + if (record->event.pressed) { + led_animation_direction = !led_animation_direction; + } + return false; + case U_T_AUTO: + if (record->event.pressed && MODS_SHIFT && MODS_CTRL) { + TOGGLE_FLAG_AND_PRINT(usb_extra_manual, "USB extra port manual mode"); + } + return false; + case U_T_AGCR: + if (record->event.pressed && MODS_SHIFT && MODS_CTRL) { + TOGGLE_FLAG_AND_PRINT(usb_gcr_auto, "USB GCR auto mode"); + } + return false; + case DBG_TOG: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_enable, "Debug mode"); + } + return false; + case DBG_MTRX: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_matrix, "Debug matrix"); + } + return false; + case DBG_KBD: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_keyboard, "Debug keyboard"); + } + return false; + case DBG_MOU: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_mouse, "Debug mouse"); + } + return false; + case MD_BOOT: + if (record->event.pressed) { + key_timer = timer_read32(); + } else { + if (timer_elapsed32(key_timer) >= 500) { + reset_keyboard(); + } + } + return false; + default: + return true; //Process all other keycodes normally + } +} + +led_instruction_t led_instructions[] = { + { .end = 1 } +}; diff --git a/keyboards/massdrop/alt/keymaps/example_custom_patterns/led_patterns.c b/keyboards/massdrop/alt/keymaps/example_custom_patterns/led_patterns.c new file mode 100644 index 000000000000..1868f4ad2f0d --- /dev/null +++ b/keyboards/massdrop/alt/keymaps/example_custom_patterns/led_patterns.c @@ -0,0 +1,52 @@ +/* +Copyright 2018 Massdrop Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include +#include "led_instructions.h" + +//Rainbow no scrolling +led_setup_t leds_rainbow_ns[] = { + { .hs = 0, .he = 16.67, .rs = 255, .re = 255, .gs = 0, .ge = 255, .bs = 0, .be = 0, .ef = EF_AXIS_X | EF_OVER }, + { .hs = 16.67, .he = 33.33, .rs = 255, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_AXIS_X | EF_OVER }, + { .hs = 33.33, .he = 50, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 255, .ef = EF_AXIS_X | EF_OVER }, + { .hs = 50, .he = 66.67, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 255, .ef = EF_AXIS_X | EF_OVER }, + { .hs = 66.67, .he = 83.33, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_AXIS_X | EF_OVER }, + { .hs = 83.33, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 0, .ef = EF_AXIS_X | EF_OVER }, + { .end = 1 }, +}; + +//Rainbow scrolling +led_setup_t leds_rainbow_s[] = { + { .hs = 0, .he = 16.67, .rs = 255, .re = 255, .gs = 0, .ge = 255, .bs = 0, .be = 0, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_OVER }, + { .hs = 16.67, .he = 33.33, .rs = 255, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_OVER }, + { .hs = 33.33, .he = 50, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 255, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_OVER }, + { .hs = 50, .he = 66.67, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 255, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_OVER }, + { .hs = 66.67, .he = 83.33, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_OVER }, + { .hs = 83.33, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 0, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_OVER }, + { .end = 1 }, +}; + +//Add new LED animations here using one from above as example +//The last entry must be { .end = 1 } +//Add the new animation name to the list below following its format + +void *led_setups[] = { + leds_rainbow_s, + leds_rainbow_ns +}; + +const uint8_t led_setups_count = sizeof(led_setups) / sizeof(led_setups[0]); diff --git a/keyboards/massdrop/alt/keymaps/example_reactive_blend_rgb/keymap.c b/keyboards/massdrop/alt/keymaps/example_reactive_blend_rgb/keymap.c new file mode 100644 index 000000000000..2cbc9a1adfc7 --- /dev/null +++ b/keyboards/massdrop/alt/keymaps/example_reactive_blend_rgb/keymap.c @@ -0,0 +1,226 @@ +#include QMK_KEYBOARD_H + +enum alt_keycodes { + L_BRI = SAFE_RANGE, //LED Brightness Increase + L_BRD, //LED Brightness Decrease + L_PTN, //LED Pattern Select Next + L_PTP, //LED Pattern Select Previous + L_PSI, //LED Pattern Speed Increase + L_PSD, //LED Pattern Speed Decrease + L_T_MD, //LED Toggle Mode + L_T_ONF, //LED Toggle On / Off + L_ON, //LED On + L_OFF, //LED Off + L_T_BR, //LED Toggle Breath Effect + L_T_PTD, //LED Toggle Scrolling Pattern Direction + U_T_AUTO, //USB Extra Port Toggle Auto Detect / Always Active + U_T_AGCR, //USB Toggle Automatic GCR control + DBG_TOG, //DEBUG Toggle On / Off + DBG_MTRX, //DEBUG Toggle Matrix Prints + DBG_KBD, //DEBUG Toggle Keyboard Prints + DBG_MOU, //DEBUG Toggle Mouse Prints + MD_BOOT, //Restart into bootloader after hold timeout +}; + +#define TG_NKRO MAGIC_TOGGLE_NKRO //Toggle 6KRO / NKRO mode + +keymap_config_t keymap_config; + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = LAYOUT( + KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_DEL, \ + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_HOME, \ + KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGUP, \ + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_PGDN, \ + KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(1), KC_LEFT, KC_DOWN, KC_RGHT \ + ), + [1] = LAYOUT( + KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_TRNS, KC_MUTE, \ + L_T_BR, L_PSD, L_BRI, L_PSI, KC_TRNS, KC_TRNS, KC_TRNS, U_T_AUTO,U_T_AGCR,KC_TRNS, KC_PSCR, KC_SLCK, KC_PAUS, KC_TRNS, KC_END, \ + L_T_PTD, L_PTP, L_BRD, L_PTN, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_VOLU, \ + KC_TRNS, L_T_MD, L_T_ONF, KC_TRNS, KC_TRNS, MD_BOOT, TG_NKRO, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PGUP, KC_VOLD, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_PGDN, KC_END \ + ), + /* + [X] = LAYOUT( + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS \ + ), + */ +}; + +const uint16_t PROGMEM fn_actions[] = { + +}; + +// Runs just one time when the keyboard initializes. +void matrix_init_user(void) { +}; + +// Runs constantly in the background, in a loop. +void matrix_scan_user(void) { +}; + +#define MODS_SHIFT (keyboard_report->mods & MOD_BIT(KC_LSHIFT) || keyboard_report->mods & MOD_BIT(KC_RSHIFT)) +#define MODS_CTRL (keyboard_report->mods & MOD_BIT(KC_LCTL) || keyboard_report->mods & MOD_BIT(KC_RCTRL)) +#define MODS_ALT (keyboard_report->mods & MOD_BIT(KC_LALT) || keyboard_report->mods & MOD_BIT(KC_RALT)) + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + static uint32_t key_timer; + + keypos_t key = record->event.key; + uint8_t led_id = MATRIX_TO_LED_ID[key.row][key.col]; + + if (led_id > 0) { + uint8_t led_col = LED_ID_TO_KEYMAP[led_id].col; + uint8_t led_row = LED_ID_TO_KEYMAP[led_id].row; + + uint32_t effect; + + if (record->event.pressed) { + effect = EF_BRG; + } else { + effect = EF_NONE; + } + + uint8_t row = 0; + while (row < KEYMAP_ROWS) { + static_color_map[KEYMAP_TO_LED_ID[row][led_col]].ef = effect; + row += 1; + } + + uint8_t col = 0; + while (col < KEYMAP_COLS) { + static_color_map[KEYMAP_TO_LED_ID[led_row][col]].ef = effect; + col += 1; + } + } + + switch (keycode) { + case L_BRI: + if (record->event.pressed) { + if (LED_GCR_STEP > LED_GCR_MAX - gcr_desired) gcr_desired = LED_GCR_MAX; + else gcr_desired += LED_GCR_STEP; + if (led_animation_breathing) gcr_breathe = gcr_desired; + } + return false; + case L_BRD: + if (record->event.pressed) { + if (LED_GCR_STEP > gcr_desired) gcr_desired = 0; + else gcr_desired -= LED_GCR_STEP; + if (led_animation_breathing) gcr_breathe = gcr_desired; + } + return false; + case L_PTN: + if (record->event.pressed) { + if (led_animation_id == led_setups_count - 1) led_animation_id = 0; + else led_animation_id++; + } + return false; + case L_PTP: + if (record->event.pressed) { + if (led_animation_id == 0) led_animation_id = led_setups_count - 1; + else led_animation_id--; + } + return false; + case L_PSI: + if (record->event.pressed) { + led_animation_period_scalar /= ANIMATION_SPEED_STEP; + } + return false; + case L_PSD: + if (record->event.pressed) { + led_animation_period_scalar *= ANIMATION_SPEED_STEP; + } + return false; + case L_T_MD: + if (record->event.pressed) { + led_lighting_mode++; + if (led_lighting_mode > LED_MODE_MAX_INDEX) led_lighting_mode = LED_MODE_NORMAL; + } + return false; + case L_T_ONF: + if (record->event.pressed) { + led_enabled = !led_enabled; + I2C3733_Control_Set(led_enabled); + } + return false; + case L_ON: + if (record->event.pressed) { + led_enabled = 1; + I2C3733_Control_Set(led_enabled); + } + return false; + case L_OFF: + if (record->event.pressed) { + led_enabled = 0; + I2C3733_Control_Set(led_enabled); + } + return false; + case L_T_BR: + if (record->event.pressed) { + led_animation_breathing = !led_animation_breathing; + if (led_animation_breathing) { + gcr_breathe = gcr_desired; + led_animation_breathe_cur = BREATHE_MIN_STEP; + breathe_dir = 1; + } + } + return false; + case L_T_PTD: + if (record->event.pressed) { + led_animation_direction = !led_animation_direction; + } + return false; + case U_T_AUTO: + if (record->event.pressed && MODS_SHIFT && MODS_CTRL) { + TOGGLE_FLAG_AND_PRINT(usb_extra_manual, "USB extra port manual mode"); + } + return false; + case U_T_AGCR: + if (record->event.pressed && MODS_SHIFT && MODS_CTRL) { + TOGGLE_FLAG_AND_PRINT(usb_gcr_auto, "USB GCR auto mode"); + } + return false; + case DBG_TOG: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_enable, "Debug mode"); + } + return false; + case DBG_MTRX: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_matrix, "Debug matrix"); + } + return false; + case DBG_KBD: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_keyboard, "Debug keyboard"); + } + return false; + case DBG_MOU: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_mouse, "Debug mouse"); + } + return false; + case MD_BOOT: + if (record->event.pressed) { + key_timer = timer_read32(); + } else { + if (timer_elapsed32(key_timer) >= 500) { + reset_keyboard(); + } + } + return false; + default: + return true; //Process all other keycodes normally + } +} + +led_instruction_t led_instructions[] = { + { .flags = LED_FLAG_USE_ROTATE_PATTERN }, + { .flags = LED_FLAG_USE_COLOR_MAP }, + { .end = 1 } +}; diff --git a/keyboards/massdrop/alt/keymaps/example_simple_set_rgb/keymap.c b/keyboards/massdrop/alt/keymaps/example_simple_set_rgb/keymap.c new file mode 100644 index 000000000000..e997227ca967 --- /dev/null +++ b/keyboards/massdrop/alt/keymaps/example_simple_set_rgb/keymap.c @@ -0,0 +1,146 @@ +#include QMK_KEYBOARD_H + +enum alt_keycodes { + L_BRI = SAFE_RANGE, //LED Brightness Increase + L_BRD, //LED Brightness Decrease + L_PTN, //LED Pattern Select Next + L_PTP, //LED Pattern Select Previous + L_PSI, //LED Pattern Speed Increase + L_PSD, //LED Pattern Speed Decrease + L_T_MD, //LED Toggle Mode + L_T_ONF, //LED Toggle On / Off + L_ON, //LED On + L_OFF, //LED Off + L_T_BR, //LED Toggle Breath Effect + L_T_PTD, //LED Toggle Scrolling Pattern Direction + U_T_AUTO, //USB Extra Port Toggle Auto Detect / Always Active + U_T_AGCR, //USB Toggle Automatic GCR control + DBG_TOG, //DEBUG Toggle On / Off + DBG_MTRX, //DEBUG Toggle Matrix Prints + DBG_KBD, //DEBUG Toggle Keyboard Prints + DBG_MOU, //DEBUG Toggle Mouse Prints + MD_BOOT, //Restart into bootloader after hold timeout +}; + +#define TG_NKRO MAGIC_TOGGLE_NKRO //Toggle 6KRO / NKRO mode + +keymap_config_t keymap_config; + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = LAYOUT( + KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_DEL, \ + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_HOME, \ + KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGUP, \ + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_PGDN, \ + KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(1), KC_LEFT, KC_DOWN, KC_RGHT \ + ), + [1] = LAYOUT( + KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_TRNS, KC_MUTE, \ + L_T_BR, L_PSD, L_BRI, L_PSI, KC_TRNS, KC_TRNS, KC_TRNS, U_T_AUTO,U_T_AGCR,KC_TRNS, KC_PSCR, KC_SLCK, KC_PAUS, KC_TRNS, KC_END, \ + L_T_PTD, L_PTP, L_BRD, L_PTN, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_VOLU, \ + KC_TRNS, L_T_MD, L_T_ONF, KC_TRNS, KC_TRNS, MD_BOOT, TG_NKRO, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PGUP, KC_VOLD, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_PGDN, KC_END \ + ), + /* + [X] = LAYOUT( + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS \ + ), + */ +}; + +const uint16_t PROGMEM fn_actions[] = { + +}; + +// Runs just one time when the keyboard initializes. +void matrix_init_user(void) { +}; + +// Runs constantly in the background, in a loop. +void matrix_scan_user(void) { +}; + +#define MODS_SHIFT (keyboard_report->mods & MOD_BIT(KC_LSHIFT) || keyboard_report->mods & MOD_BIT(KC_RSHIFT)) +#define MODS_CTRL (keyboard_report->mods & MOD_BIT(KC_LCTL) || keyboard_report->mods & MOD_BIT(KC_RCTRL)) +#define MODS_ALT (keyboard_report->mods & MOD_BIT(KC_LALT) || keyboard_report->mods & MOD_BIT(KC_RALT)) + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + static uint32_t key_timer; + + keypos_t key = record->event.key; + uint8_t led_id = MATRIX_TO_LED_ID[key.row][key.col]; + + if (led_id > 0) { + uint8_t led_col = LED_ID_TO_KEYMAP[led_id].col; + uint8_t led_row = LED_ID_TO_KEYMAP[led_id].row; + + uint8_t r = 0; + uint8_t g = 0; + uint8_t b = 0; + + if (record->event.pressed) { + g = 255; + b = 125; + } + + uint8_t row = 0; + while (row < KEYMAP_ROWS) { + rgb_matrix_set_color(KEYMAP_TO_LED_ID[row][led_col], r, g, b); + row += 1; + } + + uint8_t col = 0; + while (col < KEYMAP_COLS) { + rgb_matrix_set_color(KEYMAP_TO_LED_ID[led_row][col], r, g, b); + col += 1; + } + } + + switch (keycode) { + case U_T_AUTO: + if (record->event.pressed && MODS_SHIFT && MODS_CTRL) { + TOGGLE_FLAG_AND_PRINT(usb_extra_manual, "USB extra port manual mode"); + } + return false; + case U_T_AGCR: + if (record->event.pressed && MODS_SHIFT && MODS_CTRL) { + TOGGLE_FLAG_AND_PRINT(usb_gcr_auto, "USB GCR auto mode"); + } + return false; + case DBG_TOG: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_enable, "Debug mode"); + } + return false; + case DBG_MTRX: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_matrix, "Debug matrix"); + } + return false; + case DBG_KBD: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_keyboard, "Debug keyboard"); + } + return false; + case DBG_MOU: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_mouse, "Debug mouse"); + } + return false; + case MD_BOOT: + if (record->event.pressed) { + key_timer = timer_read32(); + } else { + if (timer_elapsed32(key_timer) >= 500) { + reset_keyboard(); + } + } + return false; + default: + return true; //Process all other keycodes normally + } +} diff --git a/keyboards/massdrop/alt/keymaps/example_simple_set_rgb/rules.mk b/keyboards/massdrop/alt/keymaps/example_simple_set_rgb/rules.mk new file mode 100644 index 000000000000..c4b8da30ac71 --- /dev/null +++ b/keyboards/massdrop/alt/keymaps/example_simple_set_rgb/rules.mk @@ -0,0 +1,32 @@ +# project specific files +SRC = matrix.c + +#For platform and packs +ARM_ATSAM = SAMD51J18A +MCU = cortex-m4 + +CUSTOM_MATRIX = yes + +# Build Options +# comment out to disable the options. +# +BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) +MOUSEKEY_ENABLE = no # Mouse keys(+4700) +EXTRAKEY_ENABLE = yes # Audio control and System control(+450) +CONSOLE_ENABLE = no # Console for debug(+400) +COMMAND_ENABLE = no # Commands for debug and configuration +# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE +SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend +# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work +NKRO_ENABLE = yes # USB Nkey Rollover +BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default +RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow +MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config) +UNICODE_ENABLE = no # Unicode +BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID +AUDIO_ENABLE = no # Audio output on port C6 +FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches +HD44780_ENABLE = no # Enable support for HD44780 based LCDs (+400) +VIRTSER_ENABLE = no # USB Serial Driver +RAW_ENABLE = no # Raw device +AUTO_SHIFT_ENABLE = no # Auto Shift diff --git a/keyboards/massdrop/alt/keymaps/mac/keymap.c b/keyboards/massdrop/alt/keymaps/mac/keymap.c index 5e517642852e..e03ca9eeb8b8 100644 --- a/keyboards/massdrop/alt/keymaps/mac/keymap.c +++ b/keyboards/massdrop/alt/keymaps/mac/keymap.c @@ -100,13 +100,12 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { return false; case L_PSI: if (record->event.pressed) { - led_animation_speed += ANIMATION_SPEED_STEP; + led_animation_period_scalar /= ANIMATION_SPEED_STEP; } return false; case L_PSD: if (record->event.pressed) { - led_animation_speed -= ANIMATION_SPEED_STEP; - if (led_animation_speed < 0) led_animation_speed = 0; + led_animation_period_scalar *= ANIMATION_SPEED_STEP; } return false; case L_T_MD: diff --git a/keyboards/massdrop/alt/keymaps/reywood/keymap.c b/keyboards/massdrop/alt/keymaps/reywood/keymap.c index 8b69f0e8ebbb..a6e367a6307f 100644 --- a/keyboards/massdrop/alt/keymaps/reywood/keymap.c +++ b/keyboards/massdrop/alt/keymaps/reywood/keymap.c @@ -74,49 +74,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { rgb_matrix_record_key_press(record); switch (keycode) { - case L_BRI: - if (record->event.pressed) { - if (LED_GCR_STEP > LED_GCR_MAX - gcr_desired) gcr_desired = LED_GCR_MAX; - else gcr_desired += LED_GCR_STEP; - if (led_animation_breathing) gcr_breathe = gcr_desired; - } - return false; - case L_BRD: - if (record->event.pressed) { - if (LED_GCR_STEP > gcr_desired) gcr_desired = 0; - else gcr_desired -= LED_GCR_STEP; - if (led_animation_breathing) gcr_breathe = gcr_desired; - } - return false; - case L_PTN: - if (record->event.pressed) { - if (led_animation_id == led_setups_count - 1) led_animation_id = 0; - else led_animation_id++; - } - return false; - case L_PTP: - if (record->event.pressed) { - if (led_animation_id == 0) led_animation_id = led_setups_count - 1; - else led_animation_id--; - } - return false; - case L_PSI: - if (record->event.pressed) { - led_animation_speed += ANIMATION_SPEED_STEP; - } - return false; - case L_PSD: - if (record->event.pressed) { - led_animation_speed -= ANIMATION_SPEED_STEP; - if (led_animation_speed < 0) led_animation_speed = 0; - } - return false; - case L_T_MD: - if (record->event.pressed) { - led_lighting_mode++; - if (led_lighting_mode > LED_MODE_MAX_INDEX) led_lighting_mode = LED_MODE_NORMAL; - } - return false; case L_T_ONF: if (record->event.pressed) { led_enabled = !led_enabled; @@ -135,21 +92,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { I2C3733_Control_Set(led_enabled); } return false; - case L_T_BR: - if (record->event.pressed) { - led_animation_breathing = !led_animation_breathing; - if (led_animation_breathing) { - gcr_breathe = gcr_desired; - led_animation_breathe_cur = BREATHE_MIN_STEP; - breathe_dir = 1; - } - } - return false; - case L_T_PTD: - if (record->event.pressed) { - led_animation_direction = !led_animation_direction; - } - return false; case U_T_AUTO: if (record->event.pressed && MODS_SHIFT && MODS_CTRL) { TOGGLE_FLAG_AND_PRINT(usb_extra_manual, "USB extra port manual mode"); diff --git a/keyboards/massdrop/alt/keymaps/reywood/rgb_matrix_user.c b/keyboards/massdrop/alt/keymaps/reywood/rgb_matrix_user.c index 36131e20209b..f59dab1cfead 100644 --- a/keyboards/massdrop/alt/keymaps/reywood/rgb_matrix_user.c +++ b/keyboards/massdrop/alt/keymaps/reywood/rgb_matrix_user.c @@ -1,13 +1,9 @@ #include "quantum.h" #include "led_matrix.h" - -extern issi3733_led_t *led_cur; -extern uint8_t led_per_run; -extern issi3733_led_t *lede; -extern issi3733_led_t led_map[]; +#include QMK_KEYBOARD_H static uint16_t last_boost_update; -static uint8_t led_boosts[ISSI3733_LED_COUNT]; +static uint8_t led_boosts[ISSI3733_LED_COUNT + 1]; static uint8_t led_boost_index; static uint8_t led_cur_index; @@ -35,30 +31,11 @@ static uint8_t led_cur_index; #define max(a, b) (((a) > (b)) ? (a) : (b)) -#define __ -1 -static const uint8_t KEY_TO_LED_MAP[MATRIX_ROWS][MATRIX_COLS] = { - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, - {15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29}, - {30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, __, 42, 43}, - {44, __, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57}, - {58, 59, 60, __, __, __, 61, __, __, __, 62, 63, 64, 65, 66}, -}; - #define KEY_LED_COUNT 67 -#define KP(c, r) { .col = c, .row = r } // shorthand for keypos_t -static const keypos_t LED_TO_KEY_MAP[KEY_LED_COUNT] = { - KP(0, 0), KP(1, 0), KP(2, 0), KP(3, 0), KP(4, 0), KP(5, 0), KP(6, 0), KP(7, 0), KP(8, 0), KP(9, 0), KP(10, 0), KP(11, 0), KP(12, 0), KP(13, 0), KP(14, 0), - KP(0, 1), KP(1, 1), KP(2, 1), KP(3, 1), KP(4, 1), KP(5, 1), KP(6, 1), KP(7, 1), KP(8, 1), KP(9, 1), KP(10, 1), KP(11, 1), KP(12, 1), KP(13, 1), KP(14, 1), - KP(0, 2), KP(1, 2), KP(2, 2), KP(3, 2), KP(4, 2), KP(5, 2), KP(6, 2), KP(7, 2), KP(8, 2), KP(9, 2), KP(10, 2), KP(11, 2), KP(13, 2), KP(14, 2), - KP(0, 3), KP(2, 3), KP(3, 3), KP(4, 3), KP(5, 3), KP(6, 3), KP(7, 3), KP(8, 3), KP(9, 3), KP(10, 3), KP(11, 3), KP(12, 3), KP(13, 3), KP(14, 3), - KP(0, 4), KP(1, 4), KP(2, 4), KP(6, 4), KP(10, 4), KP(11, 4), KP(12, 4), KP(13, 4), KP(14, 4), -}; - static void update_led_boosts(void); -static void update_led_cur_rgb_values(void); static void set_nearest_led_to_max(uint8_t col, uint8_t row); -static uint8_t calculate_new_color_component_value(uint8_t max, uint8_t min); +static uint8_t calculate_new_color_component_value(issi3733_led_t *led_cur, uint8_t max, uint8_t min); static void calculate_new_led_boosts(uint8_t new_led_boosts[]); static uint8_t calculate_new_led_boost_at(int index); static uint8_t get_propagated_boost_from_neighbors(int led_position); @@ -68,7 +45,7 @@ static uint8_t map_key_position_to_led_index(uint8_t col, uint8_t row); void rgb_matrix_init_user(void) { - for (int i = 0; i < ISSI3733_LED_COUNT; i++) { + for (int i = 1; i <= ISSI3733_LED_COUNT; i++) { led_boosts[i] = 0; } last_boost_update = timer_read(); @@ -76,22 +53,9 @@ void rgb_matrix_init_user(void) { led_cur_index = 0; } -void led_matrix_run(void) { - uint8_t led_this_run = 0; - - if (led_cur == 0) { //Denotes start of new processing cycle in the case of chunked processing - led_cur = led_map; - led_cur_index = 0; - } +void rgb_matrix_run_user(led_disp_t disp) { + led_cur_index = 0; update_led_boosts(); - - while (led_cur < lede && led_this_run < led_per_run) { - update_led_cur_rgb_values(); - - led_cur++; - led_cur_index++; - led_this_run++; - } } void rgb_matrix_record_key_press(keyrecord_t *record) { @@ -106,38 +70,38 @@ static void update_led_boosts(void) { if (timer_elapsed(last_boost_update) > LED_BOOST_REFRESH_INTERVAL_IN_MS) { last_boost_update = timer_read(); - uint8_t new_led_boosts[ISSI3733_LED_COUNT]; + uint8_t new_led_boosts[ISSI3733_LED_COUNT + 1]; calculate_new_led_boosts(new_led_boosts); set_new_led_boosts(new_led_boosts); } } -static void update_led_cur_rgb_values(void) { +void rgb_run(issi3733_led_t *led_cur) { if (led_cur->scan == UNDERGLOW_SCAN_CODE) { *led_cur->rgb.r = UNDERGLOW_R; *led_cur->rgb.g = UNDERGLOW_G; *led_cur->rgb.b = UNDERGLOW_B; } else { - *led_cur->rgb.r = calculate_new_color_component_value(MAX_R, MIN_R); - *led_cur->rgb.g = calculate_new_color_component_value(MAX_G, MIN_G); - *led_cur->rgb.b = calculate_new_color_component_value(MAX_B, MIN_B); + *led_cur->rgb.r = calculate_new_color_component_value(led_cur, MAX_R, MIN_R); + *led_cur->rgb.g = calculate_new_color_component_value(led_cur, MAX_G, MIN_G); + *led_cur->rgb.b = calculate_new_color_component_value(led_cur, MAX_B, MIN_B); } } static void set_nearest_led_to_max(uint8_t col, uint8_t row) { uint8_t led_index = map_key_position_to_led_index(col, row); - if (led_index >= 0 && led_index < ISSI3733_LED_COUNT) { + if (led_index > 0 && led_index <= ISSI3733_LED_COUNT) { led_boosts[led_index] = LED_BOOST_PEAK; } } -static uint8_t calculate_new_color_component_value(uint8_t max, uint8_t min) { - uint8_t current_boost = led_boosts[led_cur_index]; +static uint8_t calculate_new_color_component_value(issi3733_led_t *led_cur, uint8_t max, uint8_t min) { + uint8_t current_boost = led_boosts[led_cur->id]; return (float)(max - min) * current_boost / LED_BOOST_PEAK + min; } static void calculate_new_led_boosts(uint8_t new_led_boosts[]) { - for (int i = 0; i < ISSI3733_LED_COUNT; i++) { + for (int i = 1; i <= ISSI3733_LED_COUNT; i++) { new_led_boosts[i] = calculate_new_led_boost_at(i); } } @@ -153,10 +117,10 @@ static uint8_t calculate_new_led_boost_at(int index) { } static uint8_t get_propagated_boost_from_neighbors(int led_position) { - if (led_position < 0 || led_position >= KEY_LED_COUNT) { + if (led_position < 0 || led_position > KEY_LED_COUNT) { return 0; } - keypos_t led_keypos = LED_TO_KEY_MAP[led_position]; + keypos_t led_keypos = LED_ID_TO_KEYMAP[led_position]; uint8_t top_boost = get_led_boost_at_keypos(led_keypos.row - 1, led_keypos.col); uint8_t bottom_boost = get_led_boost_at_keypos(led_keypos.row + 1, led_keypos.col); uint8_t left_boost = get_led_boost_at_keypos(led_keypos.row, led_keypos.col - 1); @@ -172,22 +136,22 @@ static uint8_t get_led_boost_at_keypos(uint8_t row, uint8_t col) { if (row < 0 || row >= MATRIX_ROWS || col < 0 || col >= MATRIX_COLS) { return 0; } - uint8_t led_index = KEY_TO_LED_MAP[row][col]; - if (led_index < 0) { + uint8_t led_index = KEYMAP_TO_LED_ID[row][col]; + if (led_index <= 0) { return 0; } return led_boosts[led_index]; } static void set_new_led_boosts(uint8_t* new_led_boosts) { - for (int i = 0; i < ISSI3733_LED_COUNT; i++) { + for (int i = 1; i <= ISSI3733_LED_COUNT; i++) { led_boosts[i] = new_led_boosts[i]; } } static uint8_t map_key_position_to_led_index(uint8_t col, uint8_t row) { if (row >= 0 && row < MATRIX_ROWS && col >= 0 && col < MATRIX_COLS) { - return KEY_TO_LED_MAP[row][col]; + return KEYMAP_TO_LED_ID[row][col]; } return -1; } diff --git a/keyboards/massdrop/alt/keymaps/reywood/rules.mk b/keyboards/massdrop/alt/keymaps/reywood/rules.mk index b5b961a0f3b2..2e8bd28f60ca 100644 --- a/keyboards/massdrop/alt/keymaps/reywood/rules.mk +++ b/keyboards/massdrop/alt/keymaps/reywood/rules.mk @@ -1,6 +1,5 @@ # project specific files -SRC = led_programs.c -SRC += matrix.c +SRC = matrix.c SRC += rgb_matrix_user.c #For platform and packs diff --git a/keyboards/massdrop/alt/rules.mk b/keyboards/massdrop/alt/rules.mk index c5539158f580..2a1fb05877a7 100644 --- a/keyboards/massdrop/alt/rules.mk +++ b/keyboards/massdrop/alt/rules.mk @@ -1,5 +1,6 @@ # project specific files -SRC = led_programs.c +SRC = led_patterns.c +SRC += led_instructions.c SRC += matrix.c #For platform and packs diff --git a/keyboards/massdrop/ctrl/config.h b/keyboards/massdrop/ctrl/config.h index 1ab7f93cddce..7397e8f42f23 100644 --- a/keyboards/massdrop/ctrl/config.h +++ b/keyboards/massdrop/ctrl/config.h @@ -32,6 +32,9 @@ along with this program. If not, see . #define MATRIX_ROWS 11 #define MATRIX_COLS 8 +#define KEYMAP_ROWS 6 +#define KEYMAP_COLS 18 + #define PA 0 #define PB 1 diff --git a/keyboards/massdrop/ctrl/config_led.h b/keyboards/massdrop/ctrl/config_led.h index 471ab7007d1f..08d4e24c9da8 100644 --- a/keyboards/massdrop/ctrl/config_led.h +++ b/keyboards/massdrop/ctrl/config_led.h @@ -41,7 +41,7 @@ along with this program. If not, see . #define V5_LOW 2480 //5V low level (LED power rolled back to stay above this limit) #define V5_CAT 2200 //5V catastrophic level (Host USB port potential to shut down) -#define ANIMATION_SPEED_STEP 1 +#define ANIMATION_SPEED_STEP 1.1 #define BREATHE_MIN_STEP 0 #define BREATHE_MAX_STEP 255 diff --git a/keyboards/massdrop/ctrl/ctrl.h b/keyboards/massdrop/ctrl/ctrl.h index c83efca16d15..5f32e2418015 100644 --- a/keyboards/massdrop/ctrl/ctrl.h +++ b/keyboards/massdrop/ctrl/ctrl.h @@ -6,37 +6,188 @@ #include "i2c_master.h" #include "led_matrix.h" //For led keycodes +#include "led_instructions.h" #include "usb/udi_cdc.h" #include "usb/usb2422.h" #define LAYOUT( \ - K01, K02, K03, K04, K05, K06, K07, K08, K09, K10, K11, K12, K13, K14, K15, \ - K16, K17, K18, K19, K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K30, \ - K31, K32, K33, K34, K35, K36, K37, K38, K39, K40, K41, K42, K43, K44, K45, \ - K46, K47, K48, K49, K50, K51, K52, K53, K54, K55, K56, K57, K58, K59, K60, \ - K61, K62, K63, K64, K65, K66, K67, K68, K69, K70, K71, K72, K73, K74, K75, \ - K76, K77, K78, K79, K80, K81, K82, K83, K84, K85, K86, K87 \ - \ + K01, K02, K03, K04, K05, K06, K07, K08, K09, K10, K11, K12, K13, K14, K15, \ + K16, K17, K18, K19, K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K30, \ + K31, K32, K33, K34, K35, K36, K37, K38, K39, K40, K41, K42, K43, K44, K45, \ + K46, K47, K48, K49, K50, K51, K52, K53, K54, K55, K56, K57, K58, K59, K60, \ + K61, K62, K63, K64, K65, K66, K67, K68, K69, K70, K71, K72, K73, K74, K75, \ + K76, K77, K78, K79, K80, K81, K82, K83, K84, K85, K86, K87 \ + \ ) { \ - { K01, K02, K03, K04, K05, K06, K07, K08 }, \ - { K17, K18, K19, K20, K21, K22, K23, K24 }, \ - { K34, K35, K36, K37, K38, K39, K40, K41 }, \ - { K51, K52, K53, K54, K55, K56, K57, K58 }, \ - { K64, K65, K66, K67, K68, K69, K70, K71 }, \ - { K77, K78, K79, K80, K81, K82, K83, K84 }, \ - { K09, K10, K11, K12, K13, K14, K15, K16 }, \ - { K25, K26, K27, K28, K29, K30, K31, K32 }, \ - { K42, K43, K44, K45, K46, K47, K48, K49 }, \ - { K59, K60, K61, K62, K63, K76, K50, K33 }, \ - { K72, K73, K74, K75, K85, K86, K87, }, \ + { K01, K02, K03, K04, K05, K06, K07, K08 }, \ + { K17, K18, K19, K20, K21, K22, K23, K24 }, \ + { K34, K35, K36, K37, K38, K39, K40, K41 }, \ + { K51, K52, K53, K54, K55, K56, K57, K58 }, \ + { K64, K65, K66, K67, K68, K69, K70, K71 }, \ + { K77, K78, K79, K80, K81, K82, K83, K84 }, \ + { K09, K10, K11, K12, K13, K14, K15, K16 }, \ + { K25, K26, K27, K28, K29, K30, K31, K32 }, \ + { K42, K43, K44, K45, K46, K47, K48, K49 }, \ + { K59, K60, K61, K62, K63, K76, K50, K33 }, \ + { K72, K73, K74, K75, K85, K86, K87, }, \ } #define TOGGLE_FLAG_AND_PRINT(var, name) { \ - if (var) { \ - dprintf(name " disabled\r\n"); \ - var = !var; \ - } else { \ - var = !var; \ - dprintf(name " enabled\r\n"); \ - } \ - } + if (var) { \ + dprintf(name " disabled\r\n"); \ + var = !var; \ + } else { \ + var = !var; \ + dprintf(name " enabled\r\n"); \ + } \ + } + +// Rows/cols match key matrix. Values correspond to LED IDs. +static const uint8_t MATRIX_TO_LED_ID[MATRIX_ROWS][MATRIX_COLS] = { + { 1, 2, 3, 4, 5, 6, 7, 8 }, + { 17, 18, 19, 20, 21, 22, 23, 24 }, + { 34, 35, 36, 37, 38, 39, 40, 41 }, + { 51, 52, 53, 54, 55, 56, 57, 58 }, + { 64, 65, 66, 67, 68, 69, 70, 71 }, + { 77, 78, 79, 80, 81, 82, 83, 84 }, + { 9, 10, 11, 12, 13, 14, 15, 16 }, + { 25, 26, 27, 28, 29, 30, 31, 32 }, + { 42, 43, 44, 45, 46, 47, 48, 49 }, + { 59, 60, 61, 62, 63, 76, 50, 33 }, + { 72, 73, 74, 75, 85, 86, 87, 0 } +}; + +static const keypos_t LED_ID_TO_KEYMAP[109] = { + { .col = -1, .row = -1 }, // Dummy row for 0s above + + // row 0: 1 - 18 + { .col = 0, .row = 0 }, + // gap + { .col = 2, .row = 0 }, + { .col = 3, .row = 0 }, + { .col = 4, .row = 0 }, + { .col = 5, .row = 0 }, + { .col = 6, .row = 0 }, + { .col = 7, .row = 0 }, + { .col = 8, .row = 0 }, + { .col = 9, .row = 0 }, + // gap + { .col = 11, .row = 0 }, + { .col = 12, .row = 0 }, + { .col = 13, .row = 0 }, + { .col = 14, .row = 0 }, + { .col = 15, .row = 0 }, + { .col = 16, .row = 0 }, + { .col = 17, .row = 0 }, // LED 16 + + // row 1: 19 - 36 + { .col = 0, .row = 1 }, + { .col = 1, .row = 1 }, + { .col = 2, .row = 1 }, + { .col = 3, .row = 1 }, // LED 20 + { .col = 4, .row = 1 }, + { .col = 5, .row = 1 }, + { .col = 6, .row = 1 }, + { .col = 7, .row = 1 }, + { .col = 8, .row = 1 }, + { .col = 9, .row = 1 }, + { .col = 10, .row = 1 }, + { .col = 11, .row = 1 }, + { .col = 12, .row = 1 }, // LED 29 + // gap + { .col = 14, .row = 1 }, + { .col = 15, .row = 1 }, + { .col = 16, .row = 1 }, + { .col = 17, .row = 1 }, + + // row 2: 37 - 54 + { .col = 0, .row = 2 }, // LED 34 + // gap + { .col = 2, .row = 2 }, + { .col = 3, .row = 2 }, + { .col = 4, .row = 2 }, + { .col = 5, .row = 2 }, + { .col = 6, .row = 2 }, + { .col = 7, .row = 2 }, + { .col = 8, .row = 2 }, + { .col = 9, .row = 2 }, + { .col = 10, .row = 2 }, + { .col = 11, .row = 2 }, + { .col = 12, .row = 2 }, // LED 45 + { .col = 13, .row = 2 }, + { .col = 14, .row = 2 }, + { .col = 15, .row = 2 }, + { .col = 16, .row = 2 }, + { .col = 17, .row = 2 }, + + // row 3: 55 - 72 + { .col = 0, .row = 3 }, + // gap + { .col = 2, .row = 3 }, + { .col = 3, .row = 3 }, + { .col = 4, .row = 3 }, + { .col = 5, .row = 3 }, + { .col = 6, .row = 3 }, + { .col = 7, .row = 3 }, + { .col = 8, .row = 3 }, + { .col = 9, .row = 3 }, + { .col = 10, .row = 3 }, + { .col = 11, .row = 3 }, + { .col = 12, .row = 3 }, + // gap + { .col = 14, .row = 3 }, + // gap + // gap + // gap + + // row 4: 73 - 90 + { .col = 0, .row = 4 }, + // gap + { .col = 2, .row = 4 }, + { .col = 3, .row = 4 }, + { .col = 4, .row = 4 }, + { .col = 5, .row = 4 }, + { .col = 6, .row = 4 }, + { .col = 7, .row = 4 }, + { .col = 8, .row = 4 }, + { .col = 9, .row = 4 }, + { .col = 10, .row = 4 }, + { .col = 11, .row = 4 }, + // gap + { .col = 13, .row = 4 }, + // gap + // gap + { .col = 16, .row = 4 }, + // gap + + // row 5: 91 - 108 + { .col = 0, .row = 5 }, + { .col = 1, .row = 5 }, + // gap + { .col = 3, .row = 5 }, + // gap + // gap + { .col = 6, .row = 5 }, + // gap + // gap + // gap + { .col = 10, .row = 5 }, + { .col = 11, .row = 5 }, + // gap + { .col = 13, .row = 5 }, + { .col = 14, .row = 5 }, + { .col = 15, .row = 5 }, + { .col = 16, .row = 5 }, + { .col = 17, .row = 5 }, +}; + +// Rows/cols match key laoyut. Values correspond to LED IDs. +// Note that matrix and key layout do not match for CTRL Keyboard. +static const uint8_t KEYMAP_TO_LED_ID[KEYMAP_ROWS][KEYMAP_COLS] = { + { 1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16 }, + { 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 0, 30, 31, 32, 33 }, + { 34, 0, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50 }, + { 51, 0, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 0, 63, 0, 0, 0 }, + { 64, 0, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 0, 75, 0, 0, 76, 0 }, + { 77, 78, 0, 79, 0, 0, 80, 0, 0, 0, 81, 82, 0, 83, 84, 85, 86, 87 } +}; diff --git a/keyboards/massdrop/ctrl/keymaps/default/keymap.c b/keyboards/massdrop/ctrl/keymaps/default/keymap.c index a60b97d6d586..81e38685793b 100644 --- a/keyboards/massdrop/ctrl/keymaps/default/keymap.c +++ b/keyboards/massdrop/ctrl/keymaps/default/keymap.c @@ -103,13 +103,12 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { return false; case L_PSI: if (record->event.pressed) { - led_animation_speed += ANIMATION_SPEED_STEP; + led_animation_period_scalar /= ANIMATION_SPEED_STEP; } return false; case L_PSD: if (record->event.pressed) { - led_animation_speed -= ANIMATION_SPEED_STEP; - if (led_animation_speed < 0) led_animation_speed = 0; + led_animation_period_scalar *= ANIMATION_SPEED_STEP; } return false; case L_T_MD: diff --git a/keyboards/massdrop/ctrl/keymaps/example_custom_patterns/keymap.c b/keyboards/massdrop/ctrl/keymaps/example_custom_patterns/keymap.c new file mode 100644 index 000000000000..574fd66ed40e --- /dev/null +++ b/keyboards/massdrop/ctrl/keymaps/example_custom_patterns/keymap.c @@ -0,0 +1,199 @@ +#include QMK_KEYBOARD_H + +enum ctrl_keycodes { + L_BRI = SAFE_RANGE, //LED Brightness Increase + L_BRD, //LED Brightness Decrease + L_PTN, //LED Pattern Select Next + L_PTP, //LED Pattern Select Previous + L_PSI, //LED Pattern Speed Increase + L_PSD, //LED Pattern Speed Decrease + L_T_MD, //LED Toggle Mode + L_T_ONF, //LED Toggle On / Off + L_ON, //LED On + L_OFF, //LED Off + L_T_BR, //LED Toggle Breath Effect + L_T_PTD, //LED Toggle Scrolling Pattern Direction + U_T_AUTO, //USB Extra Port Toggle Auto Detect / Always Active + U_T_AGCR, //USB Toggle Automatic GCR control + DBG_TOG, //DEBUG Toggle On / Off + DBG_MTRX, //DEBUG Toggle Matrix Prints + DBG_KBD, //DEBUG Toggle Keyboard Prints + DBG_MOU, //DEBUG Toggle Mouse Prints + MD_BOOT, //Restart into bootloader after hold timeout +}; + +#define TG_NKRO MAGIC_TOGGLE_NKRO //Toggle 6KRO / NKRO mode + +keymap_config_t keymap_config; + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = LAYOUT( + KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PSCR, KC_SLCK, KC_PAUS, \ + KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_INS, KC_HOME, KC_PGUP, \ + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL, KC_END, KC_PGDN, \ + KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, \ + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, \ + KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(1), KC_APP, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT \ + ), + [1] = LAYOUT( + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MUTE, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPLY, KC_MSTP, KC_VOLU, \ + L_T_BR, L_PSD, L_BRI, L_PSI, KC_TRNS, KC_TRNS, KC_TRNS, U_T_AUTO,U_T_AGCR,KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPRV, KC_MNXT, KC_VOLD, \ + L_T_PTD, L_PTP, L_BRD, L_PTN, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, L_T_MD, L_T_ONF, KC_TRNS, KC_TRNS, MD_BOOT, TG_NKRO, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS \ + ), + /* + [X] = LAYOUT( + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, TG_NKRO, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS \ + ), + */ +}; + +const uint16_t PROGMEM fn_actions[] = { + +}; + +// Runs just one time when the keyboard initializes. +void matrix_init_user(void) { +}; + +// Runs constantly in the background, in a loop. +void matrix_scan_user(void) { +}; + +#define MODS_SHIFT (keyboard_report->mods & MOD_BIT(KC_LSHIFT) || keyboard_report->mods & MOD_BIT(KC_RSHIFT)) +#define MODS_CTRL (keyboard_report->mods & MOD_BIT(KC_LCTL) || keyboard_report->mods & MOD_BIT(KC_RCTRL)) +#define MODS_ALT (keyboard_report->mods & MOD_BIT(KC_LALT) || keyboard_report->mods & MOD_BIT(KC_RALT)) + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + static uint32_t key_timer; + + switch (keycode) { + case L_BRI: + if (record->event.pressed) { + if (LED_GCR_STEP > LED_GCR_MAX - gcr_desired) gcr_desired = LED_GCR_MAX; + else gcr_desired += LED_GCR_STEP; + if (led_animation_breathing) gcr_breathe = gcr_desired; + } + return false; + case L_BRD: + if (record->event.pressed) { + if (LED_GCR_STEP > gcr_desired) gcr_desired = 0; + else gcr_desired -= LED_GCR_STEP; + if (led_animation_breathing) gcr_breathe = gcr_desired; + } + return false; + case L_PTN: + if (record->event.pressed) { + if (led_animation_id == led_setups_count - 1) led_animation_id = 0; + else led_animation_id++; + } + return false; + case L_PTP: + if (record->event.pressed) { + if (led_animation_id == 0) led_animation_id = led_setups_count - 1; + else led_animation_id--; + } + return false; + case L_PSI: + if (record->event.pressed) { + led_animation_period_scalar /= ANIMATION_SPEED_STEP; + } + return false; + case L_PSD: + if (record->event.pressed) { + led_animation_period_scalar *= ANIMATION_SPEED_STEP; + } + return false; + case L_T_MD: + if (record->event.pressed) { + led_lighting_mode++; + if (led_lighting_mode > LED_MODE_MAX_INDEX) led_lighting_mode = LED_MODE_NORMAL; + } + return false; + case L_T_ONF: + if (record->event.pressed) { + led_enabled = !led_enabled; + I2C3733_Control_Set(led_enabled); + } + return false; + case L_ON: + if (record->event.pressed) { + led_enabled = 1; + I2C3733_Control_Set(led_enabled); + } + return false; + case L_OFF: + if (record->event.pressed) { + led_enabled = 0; + I2C3733_Control_Set(led_enabled); + } + return false; + case L_T_BR: + if (record->event.pressed) { + led_animation_breathing = !led_animation_breathing; + if (led_animation_breathing) { + gcr_breathe = gcr_desired; + led_animation_breathe_cur = BREATHE_MIN_STEP; + breathe_dir = 1; + } + } + return false; + case L_T_PTD: + if (record->event.pressed) { + led_animation_direction = !led_animation_direction; + } + return false; + case U_T_AUTO: + if (record->event.pressed && MODS_SHIFT && MODS_CTRL) { + TOGGLE_FLAG_AND_PRINT(usb_extra_manual, "USB extra port manual mode"); + } + return false; + case U_T_AGCR: + if (record->event.pressed && MODS_SHIFT && MODS_CTRL) { + TOGGLE_FLAG_AND_PRINT(usb_gcr_auto, "USB GCR auto mode"); + } + return false; + case DBG_TOG: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_enable, "Debug mode"); + } + return false; + case DBG_MTRX: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_matrix, "Debug matrix"); + } + return false; + case DBG_KBD: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_keyboard, "Debug keyboard"); + } + return false; + case DBG_MOU: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_mouse, "Debug mouse"); + } + return false; + case MD_BOOT: + if (record->event.pressed) { + key_timer = timer_read32(); + } else { + if (timer_elapsed32(key_timer) >= 500) { + reset_keyboard(); + } + } + return false; + default: + return true; //Process all other keycodes normally + } +} + +led_instruction_t led_instructions[] = { + { .end = 1 } +}; diff --git a/keyboards/massdrop/ctrl/keymaps/example_custom_patterns/led_patterns.c b/keyboards/massdrop/ctrl/keymaps/example_custom_patterns/led_patterns.c new file mode 100644 index 000000000000..1868f4ad2f0d --- /dev/null +++ b/keyboards/massdrop/ctrl/keymaps/example_custom_patterns/led_patterns.c @@ -0,0 +1,52 @@ +/* +Copyright 2018 Massdrop Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include +#include "led_instructions.h" + +//Rainbow no scrolling +led_setup_t leds_rainbow_ns[] = { + { .hs = 0, .he = 16.67, .rs = 255, .re = 255, .gs = 0, .ge = 255, .bs = 0, .be = 0, .ef = EF_AXIS_X | EF_OVER }, + { .hs = 16.67, .he = 33.33, .rs = 255, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_AXIS_X | EF_OVER }, + { .hs = 33.33, .he = 50, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 255, .ef = EF_AXIS_X | EF_OVER }, + { .hs = 50, .he = 66.67, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 255, .ef = EF_AXIS_X | EF_OVER }, + { .hs = 66.67, .he = 83.33, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_AXIS_X | EF_OVER }, + { .hs = 83.33, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 0, .ef = EF_AXIS_X | EF_OVER }, + { .end = 1 }, +}; + +//Rainbow scrolling +led_setup_t leds_rainbow_s[] = { + { .hs = 0, .he = 16.67, .rs = 255, .re = 255, .gs = 0, .ge = 255, .bs = 0, .be = 0, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_OVER }, + { .hs = 16.67, .he = 33.33, .rs = 255, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_OVER }, + { .hs = 33.33, .he = 50, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 255, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_OVER }, + { .hs = 50, .he = 66.67, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 255, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_OVER }, + { .hs = 66.67, .he = 83.33, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_OVER }, + { .hs = 83.33, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 0, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_OVER }, + { .end = 1 }, +}; + +//Add new LED animations here using one from above as example +//The last entry must be { .end = 1 } +//Add the new animation name to the list below following its format + +void *led_setups[] = { + leds_rainbow_s, + leds_rainbow_ns +}; + +const uint8_t led_setups_count = sizeof(led_setups) / sizeof(led_setups[0]); diff --git a/keyboards/massdrop/ctrl/keymaps/example_reactive_blend_rgb/keymap.c b/keyboards/massdrop/ctrl/keymaps/example_reactive_blend_rgb/keymap.c new file mode 100644 index 000000000000..f709fd804366 --- /dev/null +++ b/keyboards/massdrop/ctrl/keymaps/example_reactive_blend_rgb/keymap.c @@ -0,0 +1,229 @@ +#include QMK_KEYBOARD_H + +enum ctrl_keycodes { + L_BRI = SAFE_RANGE, //LED Brightness Increase + L_BRD, //LED Brightness Decrease + L_PTN, //LED Pattern Select Next + L_PTP, //LED Pattern Select Previous + L_PSI, //LED Pattern Speed Increase + L_PSD, //LED Pattern Speed Decrease + L_T_MD, //LED Toggle Mode + L_T_ONF, //LED Toggle On / Off + L_ON, //LED On + L_OFF, //LED Off + L_T_BR, //LED Toggle Breath Effect + L_T_PTD, //LED Toggle Scrolling Pattern Direction + U_T_AUTO, //USB Extra Port Toggle Auto Detect / Always Active + U_T_AGCR, //USB Toggle Automatic GCR control + DBG_TOG, //DEBUG Toggle On / Off + DBG_MTRX, //DEBUG Toggle Matrix Prints + DBG_KBD, //DEBUG Toggle Keyboard Prints + DBG_MOU, //DEBUG Toggle Mouse Prints + MD_BOOT, //Restart into bootloader after hold timeout +}; + +#define TG_NKRO MAGIC_TOGGLE_NKRO //Toggle 6KRO / NKRO mode + +keymap_config_t keymap_config; + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = LAYOUT( + KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PSCR, KC_SLCK, KC_PAUS, \ + KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_INS, KC_HOME, KC_PGUP, \ + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL, KC_END, KC_PGDN, \ + KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, \ + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, \ + KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(1), KC_APP, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT \ + ), + [1] = LAYOUT( + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MUTE, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPLY, KC_MSTP, KC_VOLU, \ + L_T_BR, L_PSD, L_BRI, L_PSI, KC_TRNS, KC_TRNS, KC_TRNS, U_T_AUTO,U_T_AGCR,KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPRV, KC_MNXT, KC_VOLD, \ + L_T_PTD, L_PTP, L_BRD, L_PTN, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, L_T_MD, L_T_ONF, KC_TRNS, KC_TRNS, MD_BOOT, TG_NKRO, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS \ + ), + /* + [X] = LAYOUT( + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, TG_NKRO, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \ + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS \ + ), + */ +}; + +const uint16_t PROGMEM fn_actions[] = { + +}; + +// Runs just one time when the keyboard initializes. +void matrix_init_user(void) { +}; + +// Runs constantly in the background, in a loop. +void matrix_scan_user(void) { +}; + +#define MODS_SHIFT (keyboard_report->mods & MOD_BIT(KC_LSHIFT) || keyboard_report->mods & MOD_BIT(KC_RSHIFT)) +#define MODS_CTRL (keyboard_report->mods & MOD_BIT(KC_LCTL) || keyboard_report->mods & MOD_BIT(KC_RCTRL)) +#define MODS_ALT (keyboard_report->mods & MOD_BIT(KC_LALT) || keyboard_report->mods & MOD_BIT(KC_RALT)) + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + static uint32_t key_timer; + + keypos_t key = record->event.key; + uint8_t led_id = MATRIX_TO_LED_ID[key.row][key.col]; + + if (led_id > 0) { + uint8_t led_col = LED_ID_TO_KEYMAP[led_id].col; + uint8_t led_row = LED_ID_TO_KEYMAP[led_id].row; + + uint32_t effect; + + if (record->event.pressed) { + effect = EF_BRG; + } else { + effect = EF_NONE; + } + + uint8_t row = 0; + while (row < KEYMAP_ROWS) { + static_color_map[KEYMAP_TO_LED_ID[row][led_col]].ef = effect; + row += 1; + } + + uint8_t col = 0; + while (col < KEYMAP_COLS) { + static_color_map[KEYMAP_TO_LED_ID[led_row][col]].ef = effect; + col += 1; + } + } + + switch (keycode) { + case L_BRI: + if (record->event.pressed) { + if (LED_GCR_STEP > LED_GCR_MAX - gcr_desired) gcr_desired = LED_GCR_MAX; + else gcr_desired += LED_GCR_STEP; + if (led_animation_breathing) gcr_breathe = gcr_desired; + } + return false; + case L_BRD: + if (record->event.pressed) { + if (LED_GCR_STEP > gcr_desired) gcr_desired = 0; + else gcr_desired -= LED_GCR_STEP; + if (led_animation_breathing) gcr_breathe = gcr_desired; + } + return false; + case L_PTN: + if (record->event.pressed) { + if (led_animation_id == led_setups_count - 1) led_animation_id = 0; + else led_animation_id++; + } + return false; + case L_PTP: + if (record->event.pressed) { + if (led_animation_id == 0) led_animation_id = led_setups_count - 1; + else led_animation_id--; + } + return false; + case L_PSI: + if (record->event.pressed) { + led_animation_period_scalar /= ANIMATION_SPEED_STEP; + } + return false; + case L_PSD: + if (record->event.pressed) { + led_animation_period_scalar *= ANIMATION_SPEED_STEP; + } + return false; + case L_T_MD: + if (record->event.pressed) { + led_lighting_mode++; + if (led_lighting_mode > LED_MODE_MAX_INDEX) led_lighting_mode = LED_MODE_NORMAL; + } + return false; + case L_T_ONF: + if (record->event.pressed) { + led_enabled = !led_enabled; + I2C3733_Control_Set(led_enabled); + } + return false; + case L_ON: + if (record->event.pressed) { + led_enabled = 1; + I2C3733_Control_Set(led_enabled); + } + return false; + case L_OFF: + if (record->event.pressed) { + led_enabled = 0; + I2C3733_Control_Set(led_enabled); + } + return false; + case L_T_BR: + if (record->event.pressed) { + led_animation_breathing = !led_animation_breathing; + if (led_animation_breathing) { + gcr_breathe = gcr_desired; + led_animation_breathe_cur = BREATHE_MIN_STEP; + breathe_dir = 1; + } + } + return false; + case L_T_PTD: + if (record->event.pressed) { + led_animation_direction = !led_animation_direction; + } + return false; + case U_T_AUTO: + if (record->event.pressed && MODS_SHIFT && MODS_CTRL) { + TOGGLE_FLAG_AND_PRINT(usb_extra_manual, "USB extra port manual mode"); + } + return false; + case U_T_AGCR: + if (record->event.pressed && MODS_SHIFT && MODS_CTRL) { + TOGGLE_FLAG_AND_PRINT(usb_gcr_auto, "USB GCR auto mode"); + } + return false; + case DBG_TOG: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_enable, "Debug mode"); + } + return false; + case DBG_MTRX: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_matrix, "Debug matrix"); + } + return false; + case DBG_KBD: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_keyboard, "Debug keyboard"); + } + return false; + case DBG_MOU: + if (record->event.pressed) { + TOGGLE_FLAG_AND_PRINT(debug_mouse, "Debug mouse"); + } + return false; + case MD_BOOT: + if (record->event.pressed) { + key_timer = timer_read32(); + } else { + if (timer_elapsed32(key_timer) >= 500) { + reset_keyboard(); + } + } + return false; + default: + return true; //Process all other keycodes normally + } +} + +led_instruction_t led_instructions[] = { + { .flags = LED_FLAG_USE_ROTATE_PATTERN }, + { .flags = LED_FLAG_USE_COLOR_MAP }, + { .end = 1 } +}; diff --git a/keyboards/massdrop/ctrl/keymaps/mac/keymap.c b/keyboards/massdrop/ctrl/keymaps/mac/keymap.c index 3e2a990ba8aa..34d4a5f1df14 100644 --- a/keyboards/massdrop/ctrl/keymaps/mac/keymap.c +++ b/keyboards/massdrop/ctrl/keymaps/mac/keymap.c @@ -103,13 +103,12 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { return false; case L_PSI: if (record->event.pressed) { - led_animation_speed += ANIMATION_SPEED_STEP; + led_animation_period_scalar /= ANIMATION_SPEED_STEP; } return false; case L_PSD: if (record->event.pressed) { - led_animation_speed -= ANIMATION_SPEED_STEP; - if (led_animation_speed < 0) led_animation_speed = 0; + led_animation_period_scalar *= ANIMATION_SPEED_STEP; } return false; case L_T_MD: diff --git a/keyboards/massdrop/ctrl/led_programs.c b/keyboards/massdrop/ctrl/led_programs.c deleted file mode 100644 index ca27016454dc..000000000000 --- a/keyboards/massdrop/ctrl/led_programs.c +++ /dev/null @@ -1,120 +0,0 @@ -/* -Copyright 2018 Massdrop Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include "ctrl.h" -#include "led_matrix.h" - -//Teal <-> Salmon -led_setup_t leds_teal_salmon[] = { - { .hs = 0, .he = 33, .rs = 24, .re = 24, .gs = 215, .ge = 215, .bs = 204, .be = 204, .ef = EF_NONE }, - { .hs = 33, .he = 66, .rs = 24, .re = 255, .gs = 215, .ge = 114, .bs = 204, .be = 118, .ef = EF_NONE }, - { .hs = 66, .he = 100, .rs = 255, .re = 255, .gs = 114, .ge = 114, .bs = 118, .be = 118, .ef = EF_NONE }, - { .end = 1 }, -}; - -//Yellow -led_setup_t leds_yellow[] = { - { .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_NONE }, - { .end = 1 }, -}; - -//Off -led_setup_t leds_off[] = { - { .hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_NONE }, - { .end = 1 }, -}; - -//Red -led_setup_t leds_red[] = { - { .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_NONE }, - { .end = 1 }, -}; - -//Green -led_setup_t leds_green[] = { - { .hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_NONE }, - { .end = 1 }, -}; - -//Blue -led_setup_t leds_blue[] = { - { .hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_NONE }, - { .end = 1 }, -}; - -//White -led_setup_t leds_white[] = { - { .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 255, .be = 255, .ef = EF_NONE }, - { .end = 1 }, -}; - -//White with moving red stripe -led_setup_t leds_white_with_red_stripe[] = { - { .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 255, .be = 255, .ef = EF_NONE }, - { .hs = 0, .he = 15, .rs = 0, .re = 0, .gs = 0, .ge = 255, .bs = 0, .be = 255, .ef = EF_SCR_R | EF_SUBTRACT }, - { .hs = 15, .he = 30, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 0, .ef = EF_SCR_R | EF_SUBTRACT }, - { .end = 1 }, -}; - -//Black with moving red stripe -led_setup_t leds_black_with_red_stripe[] = { - { .hs = 0, .he = 15, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_SCR_R }, - { .hs = 15, .he = 30, .rs = 255, .re = 0, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_SCR_R }, - { .end = 1 }, -}; - -//Rainbow no scrolling -led_setup_t leds_rainbow_ns[] = { - { .hs = 0, .he = 16.67, .rs = 255, .re = 255, .gs = 0, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER }, - { .hs = 16.67, .he = 33.33, .rs = 255, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER }, - { .hs = 33.33, .he = 50, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 255, .ef = EF_OVER }, - { .hs = 50, .he = 66.67, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER }, - { .hs = 66.67, .he = 83.33, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER }, - { .hs = 83.33, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 0, .ef = EF_OVER }, - { .end = 1 }, -}; - -//Rainbow scrolling -led_setup_t leds_rainbow_s[] = { - { .hs = 0, .he = 16.67, .rs = 255, .re = 255, .gs = 0, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER | EF_SCR_R }, - { .hs = 16.67, .he = 33.33, .rs = 255, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER | EF_SCR_R }, - { .hs = 33.33, .he = 50, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 255, .ef = EF_OVER | EF_SCR_R }, - { .hs = 50, .he = 66.67, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER | EF_SCR_R }, - { .hs = 66.67, .he = 83.33, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER | EF_SCR_R }, - { .hs = 83.33, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 0, .ef = EF_OVER | EF_SCR_R }, - { .end = 1 }, -}; - -//Add new LED animations here using one from above as example -//The last entry must be { .end = 1 } -//Add the new animation name to the list below following its format - -void *led_setups[] = { - leds_rainbow_s, - leds_rainbow_ns, - leds_teal_salmon, - leds_yellow, - leds_red, - leds_green, - leds_blue, - leds_white, - leds_white_with_red_stripe, - leds_black_with_red_stripe, - leds_off -}; - -const uint8_t led_setups_count = sizeof(led_setups) / sizeof(led_setups[0]); diff --git a/keyboards/massdrop/ctrl/matrix.c b/keyboards/massdrop/ctrl/matrix.c deleted file mode 100644 index 6f306962e613..000000000000 --- a/keyboards/massdrop/ctrl/matrix.c +++ /dev/null @@ -1,182 +0,0 @@ -/* -Copyright 2018 Massdrop Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include "ctrl.h" - -#include "d51_util.h" -#include "debug.h" -#include "clks.h" -#include - -matrix_row_t mlatest[MATRIX_ROWS]; -matrix_row_t mlast[MATRIX_ROWS]; -matrix_row_t mdebounced[MATRIX_ROWS]; - -uint8_t row_ports[] = { MATRIX_ROW_PORTS }; -uint8_t row_pins[] = { MATRIX_ROW_PINS }; -uint8_t col_ports[] = { MATRIX_COL_PORTS }; -uint8_t col_pins[] = { MATRIX_COL_PINS }; -uint32_t row_masks[2]; //NOTE: If more than PA PB used in the future, adjust code to accomodate - -__attribute__ ((weak)) -void matrix_init_kb(void) { - matrix_init_user(); -} - -__attribute__ ((weak)) -void matrix_scan_kb(void) { - matrix_scan_user(); -} - -__attribute__ ((weak)) -void matrix_init_user(void) { -} - -__attribute__ ((weak)) -void matrix_scan_user(void) { -} - -void matrix_init(void) -{ - memset(mlatest, 0, MATRIX_ROWS * sizeof(matrix_row_t)); - memset(mlast, 0, MATRIX_ROWS * sizeof(matrix_row_t)); - memset(mdebounced, 0, MATRIX_ROWS * sizeof(matrix_row_t)); - - row_masks[PA] = 0; - row_masks[PB] = 0; - - uint8_t row; - for (row = 0; row < MATRIX_ROWS; row++) - { - PORT->Group[row_ports[row]].DIRCLR.reg = 1 << row_pins[row]; //Input - PORT->Group[row_ports[row]].OUTCLR.reg = 1 << row_pins[row]; //Low - PORT->Group[row_ports[row]].PINCFG[row_pins[row]].bit.INEN = 1; //Input Enable, - PORT->Group[row_ports[row]].PINCFG[row_pins[row]].bit.PULLEN = 1; //Pull Enable - row_masks[row_ports[row]] |= 1 << row_pins[row]; //Add pin to proper row mask - } - - uint8_t col; - for (col = 0; col < MATRIX_COLS; col++) - { - PORT->Group[col_ports[col]].DIRSET.reg = 1 << col_pins[col]; //Output - PORT->Group[col_ports[col]].OUTCLR.reg = 1 << col_pins[col]; //Low - } - - matrix_init_quantum(); -} - -#define MATRIX_SCAN_DELAY 10 //Delay after setting a col to output (in us) - -uint64_t mdebouncing = 0; -uint8_t matrix_scan(void) -{ - uint8_t mchanged; - uint8_t row; - uint8_t col; - uint32_t scans[2]; //PA PB - - if (CLK_get_ms() < mdebouncing) return 1; //mdebouncing == 0 when no debouncing active - - //m15_off; //Profiling scans - - memset(mlatest, 0, MATRIX_ROWS * sizeof(matrix_row_t)); //Zero the result buffer - - for (col = 0; col < MATRIX_COLS; col++) - { - PORT->Group[col_ports[col]].OUTSET.reg = 1 << col_pins[col]; //Set col output - - CLK_delay_us(MATRIX_SCAN_DELAY); //Delay for output - - scans[PA] = PORT->Group[PA].IN.reg & row_masks[PA]; //Read PA row pins data - scans[PB] = PORT->Group[PB].IN.reg & row_masks[PB]; //Read PB row pins data - - PORT->Group[col_ports[col]].OUTCLR.reg = 1 << col_pins[col]; //Clear col output - - for (row = 0; row < MATRIX_ROWS; row++) - { - //Move scan bits from scans array into proper row bit locations - if (scans[row_ports[row]] & (1 << row_pins[row])) - mlatest[row] |= 1 << col; - } - } - - mchanged = 0; //Default to no matrix change since last - - for (row = 0; row < MATRIX_ROWS; row++) - { - if (mlast[row] != mlatest[row]) - mchanged = 1; - mlast[row] = mlatest[row]; - } - - if (!mchanged) - { - for (row = 0; row < MATRIX_ROWS; row++) - mdebounced[row] = mlatest[row]; - mdebouncing = 0; - } - else - { - //Begin or extend debounce on change - mdebouncing = CLK_get_ms() + DEBOUNCING_DELAY; - } - - //m15_on; //Profiling scans - - matrix_scan_quantum(); - - return 1; -} - -matrix_row_t matrix_get_row(uint8_t row) -{ - return mdebounced[row]; -} - -void matrix_print(void) -{ - char buf[(MATRIX_COLS+8)*(MATRIX_ROWS+1)] = "R C"; - char *pbuf = buf+3; - uint32_t cols; - uint32_t rows; - matrix_row_t row; - - for (cols = 1; cols <= MATRIX_COLS; cols++) - { - *pbuf = (cols%10)+48; - pbuf++; - } - *pbuf = '\r'; pbuf++; - *pbuf = '\n'; pbuf++; - - for (rows = 1; rows <= MATRIX_ROWS; rows++) - { - row = matrix_get_row(rows-1); - if (rows < 10) { *pbuf = rows+48; pbuf++; *pbuf = ' '; pbuf++; *pbuf = ' '; pbuf++; } - else { *pbuf = (rows/10)+48; pbuf++; *pbuf = (rows%10)+48; pbuf++; *pbuf = ' '; pbuf++; } - for (cols = 0; cols < MATRIX_COLS; cols++) - { - if (row & 1 << cols) *pbuf = 'X'; - else *pbuf = '.'; - pbuf++; - } - *pbuf = '\r'; pbuf++; - *pbuf = '\n'; pbuf++; - } - *pbuf = 0; - dprint(buf); -} diff --git a/keyboards/massdrop/ctrl/matrix.h b/keyboards/massdrop/ctrl/matrix.h deleted file mode 100644 index 3eab6dece10d..000000000000 --- a/keyboards/massdrop/ctrl/matrix.h +++ /dev/null @@ -1,77 +0,0 @@ -/* -Copyright 2011 Jun Wako - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ -#ifndef MATRIX_H -#define MATRIX_H - -#include -#include -#include "keyboard.h" - -#if (MATRIX_COLS <= 8) -typedef uint8_t matrix_row_t; -#elif (MATRIX_COLS <= 16) -typedef uint16_t matrix_row_t; -#elif (MATRIX_COLS <= 32) -typedef uint32_t matrix_row_t; -#else -#error "MATRIX_COLS: invalid value" -#endif - -#define MATRIX_IS_ON(row, col) (matrix_get_row(row) && (1< +#include +#include "led_matrix.h" +#include "led_instructions.h" +#include "quantum.h" + +uint8_t highest_active_layer = 0; +uint32_t temp_layer_state = 0; + +__attribute__((weak)) +led_instruction_t led_instructions[] = { { .end = 1 } }; + +// TODO: is there a better way to allocate this array to be the same length as +// the led_setups array? +float animation_offsets[11]; + +float breathe_mult; + +uint8_t led_animation_id; +uint8_t led_lighting_mode; +float led_animation_period_scalar; +uint8_t led_animation_direction; +uint8_t led_animation_orientation; +uint8_t led_animation_breathe_cur; +uint8_t breathe_step; +uint8_t breathe_dir; + +uint32_t ef_axis_x = EF_AXIS_X; +uint32_t ef_axis_x_invert = EF_AXIS_X_INVERT; +uint32_t ef_axis_y = EF_AXIS_Y; +uint32_t ef_axis_y_invert = EF_AXIS_Y_INVERT; + +led_setup_t *led_animation; + +void rgb_matrix_init_user(void) { + led_animation_id = 0; + led_lighting_mode = LED_MODE_NORMAL; + led_animation_period_scalar = 1; + led_animation_direction = 0; + led_animation_orientation = 0; + led_animation_breathe_cur = BREATHE_MIN_STEP; + breathe_step = 1; + breathe_dir = 1; +} + +static void apply_blend(float* r, float* g, float* b, uint32_t effect, float applied_r, float applied_g, float applied_b) { + uint32_t blend = effect & 0xffc00000; + + float temp_r; + float temp_g; + float temp_b; + + switch(blend) { + case EF_NONE: + if (*r == 0.0f && *g == 0.0f && *b == 0.0f) { + *r = applied_r; + *g = applied_g; + *b = applied_b; + } + break; + case EF_OVER: + *r = applied_r; + *g = applied_g; + *b = applied_b; + break; + case EF_ADD: + *r += applied_r; + *g += applied_g; + *b += applied_b; + break; + case EF_SUBTRACT: + *r -= applied_r; + *g -= applied_g; + *b -= applied_b; + break; + case EF_MULTIPLY: + *r = *r * applied_r / 255.0f; + *g = *g * applied_g / 255.0f; + *b = *b * applied_b / 255.0f; + break; + case EF_DIVIDE: + *r = *r / applied_r * 255.0f; + *g = *g / applied_g * 255.0f; + *b = *b / applied_b * 255.0f; + break; + case EF_RBG: + temp_g = *g; + temp_b = *b; + *g = temp_b; + *b = temp_g; + break; + case EF_GRB: + temp_r = *r; + temp_g = *g; + *r = temp_g; + *g = temp_r; + break; + case EF_GBR: + temp_r = *r; + temp_g = *g; + temp_b = *b; + *r = temp_g; + *g = temp_b; + *b = temp_r; + break; + case EF_BRG: + temp_r = *r; + temp_g = *g; + temp_b = *b; + *r = temp_b; + *g = temp_r; + *b = temp_g; + break; + case EF_BGR: + temp_r = *r; + temp_b = *b; + *r = temp_b; + *b = temp_r; + break; + } +} + +static void rgb_matrix_pattern(led_setup_t *f, uint8_t anim_id, float* ro, float* go, float* bo, issi3733_led_t *led) { + float led_px = led->px; + float led_py = led->py; + float px; + float py; + + while (f->end != 1) + { + // Reset px, py for the new frame + px = led_px; + py = led_py; + + bool is_x_axis = f->ef & (ef_axis_x | ef_axis_x_invert); + bool is_x_axis_invert = f->ef & ef_axis_x_invert; + bool is_y_axis = f->ef & (ef_axis_y | ef_axis_y_invert); + bool is_y_axis_invert = f->ef & ef_axis_y_invert; + + if (f->ef & (EF_ANIM_SCROLL | EF_ANIM_SCROLL_INVERT)) { + float offset; + + if ( + (led_animation_direction && (f->ef & EF_ANIM_SCROLL_INVERT)) || (!led_animation_direction && (f->ef & EF_ANIM_SCROLL)) + ) { + offset = -animation_offsets[anim_id]; + } else { + offset = animation_offsets[anim_id]; + } + + if (is_x_axis_invert) { + px -= offset; + } else if (is_x_axis) { + px += offset; + } + + if (is_y_axis_invert) { + py -= offset; + } else if (is_y_axis) { + py += offset; + } + } + + if (is_x_axis_invert) { + px = 100.0f - px; + } + + if (is_y_axis_invert) { + py = 100.0f - py; + } + + float effect_pct = 0; + + // Calculate the px within the start-stop percentage for color blending + if (is_x_axis && is_y_axis) { + float pd = fmod(px + py + 200.0f, 200.0f) / 2.0f; + if (pd < f->hs || pd > f->he) { f++; continue; } + + // Scrolled on both axes + effect_pct = (pd - f->hs) / (f->he - f->hs); + } else if (is_x_axis) { + px = fmod(px + 100.0f, 100.0f); + if (px < f->hs || px > f->he) { f++; continue; } + + // Scrolled horizontally + effect_pct = (px - f->hs) / (f->he - f->hs); + } else if (is_y_axis) { + py = fmod(py + 100.0f, 100.0f); + if (py < f->hs || py > f->he) { f++; continue; } + + // Scrolled vertically + effect_pct = (py - f->hs) / (f->he - f->hs); + } else if (f->ef & EF_ANIM_TIME) { + float offset; + + if (!led_animation_direction) { + offset = animation_offsets[anim_id]; + } else { + offset = 100.0f - animation_offsets[anim_id]; + } + + if (offset < f->hs || offset > f->he) { f++; continue; } + effect_pct = (offset - f->hs) / (f->he - f->hs); + } + + float applied_r = (effect_pct * (f->re - f->rs)) + f->rs; + float applied_g = (effect_pct * (f->ge - f->gs)) + f->gs; + float applied_b = (effect_pct * (f->be - f->bs)) + f->bs; + + apply_blend(ro, go, bo, f->ef, applied_r, applied_g, applied_b); + + f++; + } +} + +void rgb_matrix_run_user(led_disp_t disp) { + led_animation = (led_setup_t*) led_setups[led_animation_id]; + + breathe_mult = 1; + + if (led_animation_breathing) + { + //+60us 119 LED + led_animation_breathe_cur += breathe_step * breathe_dir; + + if (led_animation_breathe_cur >= BREATHE_MAX_STEP) + breathe_dir = -1; + else if (led_animation_breathe_cur <= BREATHE_MIN_STEP) + breathe_dir = 1; + + //Brightness curve created for 256 steps, 0 - ~98% + breathe_mult = 0.000015 * led_animation_breathe_cur * led_animation_breathe_cur; + if (breathe_mult > 1) breathe_mult = 1; + else if (breathe_mult < 0) breathe_mult = 0; + } + + //Only needs to be calculated once per frame + int anim_index; + for (anim_index = 0; anim_index < led_setups_count; anim_index += 1) { + led_setup_t *animation = led_setups[anim_index]; + uint32_t ms; + + if (animation->ms > 0) { + ms = (uint32_t) animation->ms * led_animation_period_scalar; + } else { + ms = (uint32_t) DEFAULT_ANIM_PERIOD_MS * led_animation_period_scalar; + } + + if (ms <= 0) { + ms = 1; + } + + float position_offset = (float) (disp.clk_ms % ms); + + // Scale offset to range 0-100 + animation_offsets[anim_index] = position_offset * 100.0f / ms; + } + + if (led_animation_orientation) { + ef_axis_x = EF_AXIS_Y; + ef_axis_x_invert = EF_AXIS_Y_INVERT; + ef_axis_y = EF_AXIS_X; + ef_axis_y_invert = EF_AXIS_X_INVERT; + } else { + ef_axis_x = EF_AXIS_X; + ef_axis_x_invert = EF_AXIS_X_INVERT; + ef_axis_y = EF_AXIS_Y; + ef_axis_y_invert = EF_AXIS_Y_INVERT; + } + + highest_active_layer = 0; + temp_layer_state = layer_state; + + while (temp_layer_state >> 1 != 0) { + highest_active_layer++; + temp_layer_state = temp_layer_state >> 1; + } +} + +void rgb_run(issi3733_led_t *led) +{ + float ro = 0; + float go = 0; + float bo = 0; + + if (led_lighting_mode == LED_MODE_KEYS_ONLY && led->scan == 255) + { + //Do not act on this LED + } + else if (led_lighting_mode == LED_MODE_NON_KEYS_ONLY && led->scan != 255) + { + //Do not act on this LED + } + else if (led_lighting_mode == LED_MODE_INDICATORS_ONLY) + { + //Do not act on this LED (Only show indicators) + } + else + { + led_instruction_t *led_cur_instruction; + led_cur_instruction = led_instructions; + + //Act on LED + if (led_cur_instruction->end) { + // If no instructions, use normal pattern + rgb_matrix_pattern(led_animation, led_animation_id, &ro, &go, &bo, led); + } else { + uint8_t skip; + uint8_t modid = (led->id - 1) / 32; //PS: Calculate which id# contains the led bit + uint32_t modidbit = 1 << ((led->id - 1) % 32); //PS: Calculate the bit within the id# + uint32_t *bitfield; //PS: Will point to the id# within the current instruction + + while (!led_cur_instruction->end) { + skip = 0; + + //PS: Check layer active first + if (led_cur_instruction->flags & LED_FLAG_MATCH_LAYER) { + if (led_cur_instruction->layer != highest_active_layer) { + skip = 1; + } + } + + if (!skip) + { + if (led_cur_instruction->flags & LED_FLAG_MATCH_ID) { + bitfield = &led_cur_instruction->id0 + modid; //PS: Add modid as offset to id0 address. *bitfield is now idX of the led id + if (~(*bitfield) & modidbit) { //PS: Check if led bit is not set in idX + skip = 1; + } + } + } + + if (!skip) { + if (led_cur_instruction->flags & LED_FLAG_USE_RGB) { + ro = led_cur_instruction->r; + go = led_cur_instruction->g; + bo = led_cur_instruction->b; + } else if (led_cur_instruction->flags & LED_FLAG_USE_PATTERN) { + rgb_matrix_pattern(led_setups[led_cur_instruction->pattern_id], led_cur_instruction->pattern_id, &ro, &go, &bo, led); + } else if (led_cur_instruction->flags & LED_FLAG_USE_ROTATE_PATTERN) { + rgb_matrix_pattern(led_animation, led_animation_id, &ro, &go, &bo, led); + } else if (led_cur_instruction->flags & LED_FLAG_USE_COLOR_MAP) { + led_static_color_t static_color = static_color_map[led->id]; + apply_blend(&ro, &go, &bo, static_color.ef, (float) static_color.r, (float) static_color.g, (float) static_color.b); + } + } + + led_cur_instruction++; + } + } + } + + //Clamp values 0-255 + if (ro > 255) ro = 255; else if (ro < 0) ro = 0; + if (go > 255) go = 255; else if (go < 0) go = 0; + if (bo > 255) bo = 255; else if (bo < 0) bo = 0; + + if (led_animation_breathing) + { + ro *= breathe_mult; + go *= breathe_mult; + bo *= breathe_mult; + } + + *led->rgb.r = (uint8_t)ro; + *led->rgb.g = (uint8_t)go; + *led->rgb.b = (uint8_t)bo; + + + + + +// TODO: Re-enable indicators + + + + + +// #ifdef USB_LED_INDICATOR_ENABLE +// if (keyboard_leds()) +// { +// uint8_t kbled = keyboard_leds(); +// if ( +// #if USB_LED_NUM_LOCK_SCANCODE != 255 +// (led->scan == USB_LED_NUM_LOCK_SCANCODE && kbled & (1<scan == USB_LED_CAPS_LOCK_SCANCODE && kbled & (1<scan == USB_LED_SCROLL_LOCK_SCANCODE && kbled & (1<scan == USB_LED_COMPOSE_SCANCODE && kbled & (1<scan == USB_LED_KANA_SCANCODE && kbled & (1<rgb.r > 127) *led->rgb.r = 0; +// else *led->rgb.r = 255; +// if (*led->rgb.g > 127) *led->rgb.g = 0; +// else *led->rgb.g = 255; +// if (*led->rgb.b > 127) *led->rgb.b = 0; +// else *led->rgb.b = 255; +// } +// } +// #endif //USB_LED_INDICATOR_ENABLE +} diff --git a/keyboards/massdrop/led_instructions.h b/keyboards/massdrop/led_instructions.h new file mode 100644 index 000000000000..7cbe510381fe --- /dev/null +++ b/keyboards/massdrop/led_instructions.h @@ -0,0 +1,85 @@ +typedef struct led_setup_s { + float hs; //Band begin at percent + float he; //Band end at percent + uint32_t ef; //Animation and color effects + uint32_t ms; //Animation period in ms (only first instruction of pattern) + uint8_t rs; //Red start value + uint8_t re; //Red end value + uint8_t gs; //Green start value + uint8_t ge; //Green end value + uint8_t bs; //Blue start value + uint8_t be; //Blue end value + uint8_t end; //Set to signal end of the setup +} led_setup_t; + +typedef struct led_instruction_s { + uint32_t id0; // Bitwise id, IDs 0-31 + uint32_t id1; // Bitwise id, IDs 32-63 + uint32_t id2; // Bitwise id, IDs 64-95 + uint32_t id3; // Bitwise id, IDs 96-127 + uint16_t flags; // Bitfield for LED instructions + uint8_t layer; + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t pattern_id; + uint8_t end; +} led_instruction_t; + +// LED Blends and Animation Options +// - - - - - - +#define EF_NONE 0x00000000 // No effect + +#define EF_AXIS_X 0x00000001 // Pattern start/end on horizontal axis +#define EF_AXIS_X_INVERT 0x00000002 // Invert axis +#define EF_AXIS_Y 0x00000004 // Pattern start/end on vertical axis +#define EF_AXIS_Y_INVERT 0x00000008 // Invert axis +// #define EF_AXIS_Z 0x00000010 // Man, like, who knows what the future holds? +// #define EF_AXIS_Z_INVERT 0x00000020 // Reversed + +// Cannot be combined with EF_ANIM_TIME +#define EF_ANIM_SCROLL 0x00000040 // Animate scroll in axis direction +#define EF_ANIM_SCROLL_INVERT 0x00000080 // Animate scroll in opposite of axis direction + +// Cannot be combined with EF_ANIM_SCROLL(_INVERT) +#define EF_ANIM_TIME 0x00000100 // Animate over time + +// Blend effects are all mutually-exclusive. Keep these bits separated from +// non-blend effects because led_instructions.c does a crude bit mask and +// switch-case. +#define EF_OVER 0x00400000 // Overwrite any previous color information with new +#define EF_ADD 0x00800000 // Add color values +#define EF_SUBTRACT 0x01000000 // Subtract color values +#define EF_MULTIPLY 0x02000000 // Multiply color values +#define EF_DIVIDE 0x04000000 // Divide color values +#define EF_RBG 0x08000000 // RGB -> RBG +#define EF_GRB 0x10000000 // RGB -> GRB +#define EF_GBR 0x20000000 // RGB -> GBR +#define EF_BRG 0x40000000 // RGB -> BRG +#define EF_BGR 0x80000000 // RGB -> BGR +// - - - - - - + +#define DEFAULT_ANIM_PERIOD_MS 2500 + +// LED Extra Instructions +#define LED_FLAG_NULL 0x00 +#define LED_FLAG_MATCH_ID 0x01 +#define LED_FLAG_MATCH_LAYER 0x02 +#define LED_FLAG_USE_RGB 0x10 +#define LED_FLAG_USE_PATTERN 0x20 +#define LED_FLAG_USE_ROTATE_PATTERN 0x40 +#define LED_FLAG_USE_COLOR_MAP 0x80 + +extern uint8_t led_animation_id; +extern float led_animation_period_scalar; +extern uint8_t led_lighting_mode; +extern uint8_t led_animation_direction; +extern uint8_t led_animation_orientation; +extern uint8_t led_animation_breathe_cur; +extern uint8_t breathe_dir; + +extern led_instruction_t led_instructions[]; +extern void *led_setups[]; +extern const uint8_t led_setups_count; + +extern uint32_t layer_state; diff --git a/keyboards/massdrop/alt/led_programs.c b/keyboards/massdrop/led_patterns.c similarity index 68% rename from keyboards/massdrop/alt/led_programs.c rename to keyboards/massdrop/led_patterns.c index b3b7a7e90e76..7772bae14ea5 100644 --- a/keyboards/massdrop/alt/led_programs.c +++ b/keyboards/massdrop/led_patterns.c @@ -15,87 +15,87 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "alt.h" -#include "led_matrix.h" +#include +#include "led_instructions.h" //Teal <-> Salmon led_setup_t leds_teal_salmon[] = { - { .hs = 0, .he = 33, .rs = 24, .re = 24, .gs = 215, .ge = 215, .bs = 204, .be = 204, .ef = EF_NONE }, - { .hs = 33, .he = 66, .rs = 24, .re = 255, .gs = 215, .ge = 114, .bs = 204, .be = 118, .ef = EF_NONE }, - { .hs = 66, .he = 100, .rs = 255, .re = 255, .gs = 114, .ge = 114, .bs = 118, .be = 118, .ef = EF_NONE }, + { .hs = 0, .he = 33, .rs = 24, .re = 24, .gs = 215, .ge = 215, .bs = 204, .be = 204, .ef = EF_AXIS_X }, + { .hs = 33, .he = 66, .rs = 24, .re = 255, .gs = 215, .ge = 114, .bs = 204, .be = 118, .ef = EF_AXIS_X }, + { .hs = 66, .he = 100, .rs = 255, .re = 255, .gs = 114, .ge = 114, .bs = 118, .be = 118, .ef = EF_AXIS_X }, { .end = 1 }, }; //Yellow led_setup_t leds_yellow[] = { - { .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_NONE }, + { .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_AXIS_X }, { .end = 1 }, }; //Off led_setup_t leds_off[] = { - { .hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_NONE }, + { .hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_AXIS_X }, { .end = 1 }, }; //Red led_setup_t leds_red[] = { - { .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_NONE }, + { .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_AXIS_X }, { .end = 1 }, }; //Green led_setup_t leds_green[] = { - { .hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_NONE }, + { .hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_AXIS_X }, { .end = 1 }, }; //Blue led_setup_t leds_blue[] = { - { .hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_NONE }, + { .hs = 0, .he = 100, .rs = 0, .re = 0, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_AXIS_X }, { .end = 1 }, }; //White led_setup_t leds_white[] = { - { .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 255, .be = 255, .ef = EF_NONE }, + { .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 255, .be = 255, .ef = EF_AXIS_X }, { .end = 1 }, }; //White with moving red stripe led_setup_t leds_white_with_red_stripe[] = { - { .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 255, .be = 255, .ef = EF_NONE }, - { .hs = 0, .he = 15, .rs = 0, .re = 0, .gs = 0, .ge = 255, .bs = 0, .be = 255, .ef = EF_SCR_R | EF_SUBTRACT }, - { .hs = 15, .he = 30, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 0, .ef = EF_SCR_R | EF_SUBTRACT }, + { .hs = 0, .he = 100, .rs = 255, .re = 255, .gs = 255, .ge = 255, .bs = 255, .be = 255, .ef = EF_AXIS_X }, + { .hs = 0, .he = 15, .rs = 0, .re = 0, .gs = 0, .ge = 255, .bs = 0, .be = 255, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_SUBTRACT }, + { .hs = 15, .he = 30, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 0, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_SUBTRACT }, { .end = 1 }, }; //Black with moving red stripe led_setup_t leds_black_with_red_stripe[] = { - { .hs = 0, .he = 15, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_SCR_R }, - { .hs = 15, .he = 30, .rs = 255, .re = 0, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_SCR_R }, + { .hs = 0, .he = 15, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_AXIS_X | EF_ANIM_SCROLL }, + { .hs = 15, .he = 30, .rs = 255, .re = 0, .gs = 0, .ge = 0, .bs = 0, .be = 0, .ef = EF_AXIS_X | EF_ANIM_SCROLL }, { .end = 1 }, }; //Rainbow no scrolling led_setup_t leds_rainbow_ns[] = { - { .hs = 0, .he = 16.67, .rs = 255, .re = 255, .gs = 0, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER }, - { .hs = 16.67, .he = 33.33, .rs = 255, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER }, - { .hs = 33.33, .he = 50, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 255, .ef = EF_OVER }, - { .hs = 50, .he = 66.67, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER }, - { .hs = 66.67, .he = 83.33, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER }, - { .hs = 83.33, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 0, .ef = EF_OVER }, + { .hs = 0, .he = 16.67, .rs = 255, .re = 255, .gs = 0, .ge = 255, .bs = 0, .be = 0, .ef = EF_AXIS_X | EF_OVER }, + { .hs = 16.67, .he = 33.33, .rs = 255, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_AXIS_X | EF_OVER }, + { .hs = 33.33, .he = 50, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 255, .ef = EF_AXIS_X | EF_OVER }, + { .hs = 50, .he = 66.67, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 255, .ef = EF_AXIS_X | EF_OVER }, + { .hs = 66.67, .he = 83.33, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_AXIS_X | EF_OVER }, + { .hs = 83.33, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 0, .ef = EF_AXIS_X | EF_OVER }, { .end = 1 }, }; //Rainbow scrolling led_setup_t leds_rainbow_s[] = { - { .hs = 0, .he = 16.67, .rs = 255, .re = 255, .gs = 0, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER | EF_SCR_R }, - { .hs = 16.67, .he = 33.33, .rs = 255, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_OVER | EF_SCR_R }, - { .hs = 33.33, .he = 50, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 255, .ef = EF_OVER | EF_SCR_R }, - { .hs = 50, .he = 66.67, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER | EF_SCR_R }, - { .hs = 66.67, .he = 83.33, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_OVER | EF_SCR_R }, - { .hs = 83.33, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 0, .ef = EF_OVER | EF_SCR_R }, + { .hs = 0, .he = 16.67, .rs = 255, .re = 255, .gs = 0, .ge = 255, .bs = 0, .be = 0, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_OVER }, + { .hs = 16.67, .he = 33.33, .rs = 255, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 0, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_OVER }, + { .hs = 33.33, .he = 50, .rs = 0, .re = 0, .gs = 255, .ge = 255, .bs = 0, .be = 255, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_OVER }, + { .hs = 50, .he = 66.67, .rs = 0, .re = 0, .gs = 255, .ge = 0, .bs = 255, .be = 255, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_OVER }, + { .hs = 66.67, .he = 83.33, .rs = 0, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 255, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_OVER }, + { .hs = 83.33, .he = 100, .rs = 255, .re = 255, .gs = 0, .ge = 0, .bs = 255, .be = 0, .ef = EF_AXIS_X | EF_ANIM_SCROLL | EF_OVER }, { .end = 1 }, }; diff --git a/keyboards/massdrop/alt/matrix.c b/keyboards/massdrop/matrix.c similarity index 99% rename from keyboards/massdrop/alt/matrix.c rename to keyboards/massdrop/matrix.c index 75a4d62b994a..e03602e52e49 100644 --- a/keyboards/massdrop/alt/matrix.c +++ b/keyboards/massdrop/matrix.c @@ -15,11 +15,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "alt.h" - #include "d51_util.h" #include "debug.h" #include "clks.h" +#include "matrix.h" #include matrix_row_t mlatest[MATRIX_ROWS]; @@ -75,7 +74,7 @@ void matrix_init(void) PORT->Group[col_ports[col]].DIRSET.reg = 1 << col_pins[col]; //Output PORT->Group[col_ports[col]].OUTCLR.reg = 1 << col_pins[col]; //Low } - + matrix_init_quantum(); } diff --git a/keyboards/massdrop/alt/matrix.h b/keyboards/massdrop/matrix.h similarity index 100% rename from keyboards/massdrop/alt/matrix.h rename to keyboards/massdrop/matrix.h diff --git a/tmk_core/protocol/arm_atsam/led_matrix.c b/tmk_core/protocol/arm_atsam/led_matrix.c index 2fc6b53fc1f3..4ded9026af3d 100644 --- a/tmk_core/protocol/arm_atsam/led_matrix.c +++ b/tmk_core/protocol/arm_atsam/led_matrix.c @@ -226,7 +226,7 @@ void disp_pixel_setup(void) while (cur < lede) { cur->px = (cur->x - disp.left) / disp.width * 100; - cur->py = (cur->y - disp.bottom) / disp.height * 100; + cur->py = (disp.top - cur->y) / disp.height * 100; *cur->rgb.r = 0; *cur->rgb.g = 0; *cur->rgb.b = 0; @@ -235,267 +235,123 @@ void disp_pixel_setup(void) } } +led_static_color_t static_color_map[ISSI3733_LED_COUNT+1]; + +void prepare_static_color_map(void) { + issi3733_led_t *cur = led_map; + issi3733_led_t *lede = led_map + ISSI3733_LED_COUNT; //End pointer of mapping + + while (cur < lede) + { + static_color_map[cur->id] = (led_static_color_t) { .r = 0, .b = 0, .g = 0 }; + cur++; + } +} + void led_matrix_prepare(void) { disp_calc_extents(); disp_pixel_setup(); + prepare_static_color_map(); } -uint8_t led_enabled; -float led_animation_speed; -uint8_t led_animation_direction; -uint8_t led_animation_orientation; -uint8_t led_animation_breathing; -uint8_t led_animation_breathe_cur; -uint8_t breathe_step; -uint8_t breathe_dir; -uint64_t led_next_run; - -uint8_t led_animation_id; -uint8_t led_lighting_mode; - -issi3733_led_t *led_cur; -uint8_t led_per_run = 15; -float breathe_mult; -float pomod; +void rgb_matrix_set_color(uint8_t index, uint8_t red, uint8_t green, uint8_t blue) { + static_color_map[index].r = red; + static_color_map[index].g = green; + static_color_map[index].b = blue; +} -void led_run_pattern(led_setup_t *f, float* ro, float* go, float* bo, float pos) { - float po; +void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { + issi3733_led_t *cur = led_map; + issi3733_led_t *lede = led_map + ISSI3733_LED_COUNT; //End pointer of mapping - while (f->end != 1) + while (cur < lede) { - po = pos; //Reset po for new frame + static_color_map[cur->id].r = red; + static_color_map[cur->id].g = green; + static_color_map[cur->id].b = blue; + cur++; + } +} - //Add in any moving effects - if ((!led_animation_direction && f->ef & EF_SCR_R) || (led_animation_direction && (f->ef & EF_SCR_L))) - { - po -= pomod; +__attribute__((weak)) +void rgb_matrix_run_user(led_disp_t disp) { +} - if (po > 100) po -= 100; - else if (po < 0) po += 100; - } - else if ((!led_animation_direction && f->ef & EF_SCR_L) || (led_animation_direction && (f->ef & EF_SCR_R))) - { - po += pomod; +__attribute__((weak)) +void rgb_run(issi3733_led_t *led_cur) { + led_static_color_t color = static_color_map[led_cur->id]; - if (po > 100) po -= 100; - else if (po < 0) po += 100; - } + float ro = color.r; + float go = color.g; + float bo = color.b; - //Check if LED's po is in current frame - if (po < f->hs) { f++; continue; } - if (po > f->he) { f++; continue; } - //note: < 0 or > 100 continue + //Clamp values 0-255 + if (ro > 255) ro = 255; else if (ro < 0) ro = 0; + if (go > 255) go = 255; else if (go < 0) go = 0; + if (bo > 255) bo = 255; else if (bo < 0) bo = 0; - //Calculate the po within the start-stop percentage for color blending - po = (po - f->hs) / (f->he - f->hs); + *led_cur->rgb.r = (uint8_t)ro; + *led_cur->rgb.g = (uint8_t)go; + *led_cur->rgb.b = (uint8_t)bo; - //Add in any color effects - if (f->ef & EF_OVER) - { - *ro = (po * (f->re - f->rs)) + f->rs;// + 0.5; - *go = (po * (f->ge - f->gs)) + f->gs;// + 0.5; - *bo = (po * (f->be - f->bs)) + f->bs;// + 0.5; - } - else if (f->ef & EF_SUBTRACT) - { - *ro -= (po * (f->re - f->rs)) + f->rs;// + 0.5; - *go -= (po * (f->ge - f->gs)) + f->gs;// + 0.5; - *bo -= (po * (f->be - f->bs)) + f->bs;// + 0.5; - } - else +#ifdef USB_LED_INDICATOR_ENABLE + if (keyboard_leds()) + { + uint8_t kbled = keyboard_leds(); + if ( + #if USB_LED_NUM_LOCK_SCANCODE != 255 + (led_cur->scan == USB_LED_NUM_LOCK_SCANCODE && kbled & (1<scan == USB_LED_CAPS_LOCK_SCANCODE && kbled & (1<scan == USB_LED_SCROLL_LOCK_SCANCODE && kbled & (1<scan == USB_LED_COMPOSE_SCANCODE && kbled & (1<scan == USB_LED_KANA_SCANCODE && kbled & (1<re - f->rs)) + f->rs;// + 0.5; - *go += (po * (f->ge - f->gs)) + f->gs;// + 0.5; - *bo += (po * (f->be - f->bs)) + f->bs;// + 0.5; + if (*led_cur->rgb.r > 127) *led_cur->rgb.r = 0; + else *led_cur->rgb.r = 255; + if (*led_cur->rgb.g > 127) *led_cur->rgb.g = 0; + else *led_cur->rgb.g = 255; + if (*led_cur->rgb.b > 127) *led_cur->rgb.b = 0; + else *led_cur->rgb.b = 255; } - - f++; } +#endif //USB_LED_INDICATOR_ENABLE } -__attribute__((weak)) -led_instruction_t led_instructions[] = { { .end = 1 } }; +uint8_t led_enabled; +uint8_t led_animation_breathing; +uint64_t led_next_run; -uint8_t highest_active_layer = 0; -uint32_t temp_layer_state = 0; +issi3733_led_t *led_cur; +uint8_t led_per_run = 15; __attribute__ ((weak)) void led_matrix_run(void) { - float ro; - float go; - float bo; - float po; uint8_t led_this_run = 0; - led_setup_t *f = (led_setup_t*)led_setups[led_animation_id]; if (led_cur == 0) //Denotes start of new processing cycle in the case of chunked processing { led_cur = led_map; - disp.frame += 1; + disp.clk_ms = CLK_get_ms(); - breathe_mult = 1; - - if (led_animation_breathing) - { - //+60us 119 LED - led_animation_breathe_cur += breathe_step * breathe_dir; - - if (led_animation_breathe_cur >= BREATHE_MAX_STEP) - breathe_dir = -1; - else if (led_animation_breathe_cur <= BREATHE_MIN_STEP) - breathe_dir = 1; - - //Brightness curve created for 256 steps, 0 - ~98% - breathe_mult = 0.000015 * led_animation_breathe_cur * led_animation_breathe_cur; - if (breathe_mult > 1) breathe_mult = 1; - else if (breathe_mult < 0) breathe_mult = 0; - } - - //Only needs to be calculated once per frame - pomod = (float)(disp.frame % (uint32_t)(1000.0f / led_animation_speed)) / 10.0f * led_animation_speed; - pomod *= 100.0f; - pomod = (uint32_t)pomod % 10000; - pomod /= 100.0f; - - highest_active_layer = 0; - temp_layer_state = layer_state; - - while (temp_layer_state >> 1 != 0) { - highest_active_layer++; - temp_layer_state = temp_layer_state >> 1; - } + rgb_matrix_run_user(disp); } while (led_cur < lede && led_this_run < led_per_run) { - ro = 0; - go = 0; - bo = 0; - - if (led_animation_orientation) - { - po = led_cur->py; - } - else - { - po = led_cur->px; - } - - if (led_lighting_mode == LED_MODE_KEYS_ONLY && led_cur->scan == 255) - { - //Do not act on this LED - } - else if (led_lighting_mode == LED_MODE_NON_KEYS_ONLY && led_cur->scan != 255) - { - //Do not act on this LED - } - else if (led_lighting_mode == LED_MODE_INDICATORS_ONLY) - { - //Do not act on this LED (Only show indicators) - } - else - { - led_instruction_t *led_cur_instruction; - led_cur_instruction = led_instructions; - - //Act on LED - if (led_cur_instruction->end) { - // If no instructions, use normal pattern - led_run_pattern(f, &ro, &go, &bo, po); - } else { - uint8_t skip; - uint8_t modid = (led_cur->id - 1) / 32; //PS: Calculate which id# contains the led bit - uint32_t modidbit = 1 << ((led_cur->id - 1) % 32); //PS: Calculate the bit within the id# - uint32_t *bitfield; //PS: Will point to the id# within the current instruction - - while (!led_cur_instruction->end) { - skip = 0; - - //PS: Check layer active first - if (led_cur_instruction->flags & LED_FLAG_MATCH_LAYER) { - if (led_cur_instruction->layer != highest_active_layer) { - skip = 1; - } - } - - if (!skip) - { - if (led_cur_instruction->flags & LED_FLAG_MATCH_ID) { - bitfield = &led_cur_instruction->id0 + modid; //PS: Add modid as offset to id0 address. *bitfield is now idX of the led id - if (~(*bitfield) & modidbit) { //PS: Check if led bit is not set in idX - skip = 1; - } - } - } - - if (!skip) { - if (led_cur_instruction->flags & LED_FLAG_USE_RGB) { - ro = led_cur_instruction->r; - go = led_cur_instruction->g; - bo = led_cur_instruction->b; - } else if (led_cur_instruction->flags & LED_FLAG_USE_PATTERN) { - led_run_pattern(led_setups[led_cur_instruction->pattern_id], &ro, &go, &bo, po); - } else if (led_cur_instruction->flags & LED_FLAG_USE_ROTATE_PATTERN) { - led_run_pattern(f, &ro, &go, &bo, po); - } - } - - led_cur_instruction++; - } - } - } - - //Clamp values 0-255 - if (ro > 255) ro = 255; else if (ro < 0) ro = 0; - if (go > 255) go = 255; else if (go < 0) go = 0; - if (bo > 255) bo = 255; else if (bo < 0) bo = 0; - - if (led_animation_breathing) - { - ro *= breathe_mult; - go *= breathe_mult; - bo *= breathe_mult; - } - - *led_cur->rgb.r = (uint8_t)ro; - *led_cur->rgb.g = (uint8_t)go; - *led_cur->rgb.b = (uint8_t)bo; - -#ifdef USB_LED_INDICATOR_ENABLE - if (keyboard_leds()) - { - uint8_t kbled = keyboard_leds(); - if ( - #if USB_LED_NUM_LOCK_SCANCODE != 255 - (led_cur->scan == USB_LED_NUM_LOCK_SCANCODE && kbled & (1<scan == USB_LED_CAPS_LOCK_SCANCODE && kbled & (1<scan == USB_LED_SCROLL_LOCK_SCANCODE && kbled & (1<scan == USB_LED_COMPOSE_SCANCODE && kbled & (1<scan == USB_LED_KANA_SCANCODE && kbled & (1<rgb.r > 127) *led_cur->rgb.r = 0; - else *led_cur->rgb.r = 255; - if (*led_cur->rgb.g > 127) *led_cur->rgb.g = 0; - else *led_cur->rgb.g = 255; - if (*led_cur->rgb.b > 127) *led_cur->rgb.b = 0; - else *led_cur->rgb.b = 255; - } - } -#endif //USB_LED_INDICATOR_ENABLE - + rgb_run(led_cur); led_cur++; led_this_run++; } @@ -509,19 +365,12 @@ uint8_t led_matrix_init(void) led_matrix_prepare(); + disp.clk_ms = CLK_get_ms(); disp.frame = 0; led_next_run = 0; led_enabled = 1; - led_animation_id = 0; - led_lighting_mode = LED_MODE_NORMAL; - led_animation_speed = 4.0f; - led_animation_direction = 0; - led_animation_orientation = 0; led_animation_breathing = 0; - led_animation_breathe_cur = BREATHE_MIN_STEP; - breathe_step = 1; - breathe_dir = 1; gcr_min_counter = 0; v_5v_cat_hit = 0; @@ -538,7 +387,6 @@ uint8_t led_matrix_init(void) __attribute__ ((weak)) void rgb_matrix_init_user(void) { - } #define LED_UPDATE_RATE 10 //ms diff --git a/tmk_core/protocol/arm_atsam/led_matrix.h b/tmk_core/protocol/arm_atsam/led_matrix.h index 9d3e2811fd48..cd2f6f5ac26e 100644 --- a/tmk_core/protocol/arm_atsam/led_matrix.h +++ b/tmk_core/protocol/arm_atsam/led_matrix.h @@ -41,48 +41,49 @@ along with this program. If not, see . #define ISSI3733_PG_FN_BYTES ISSI3733_PG3_BYTES typedef struct issi3733_driver_s { - uint8_t addr; //Address of the driver according to wiring "ISSI3733: Table 1 Slave Address" - uint8_t onoff[ISSI3733_PG_ONOFF_BYTES]; //PG0 - LED Control Register - LED On/Off Register - uint8_t open[ISSI3733_PG_OR_BYTES]; //PG0 - LED Control Register - LED Open Register - uint8_t shrt[ISSI3733_PG_SR_BYTES]; //PG0 - LED Control Register - LED Short Register - uint8_t pwm[ISSI3733_PG_PWM_BYTES]; //PG1 - PWM Register - uint8_t abm[ISSI3733_PG_ABM_BYTES]; //PG2 - Auto Breath Mode Register - uint8_t conf[ISSI3733_PG_FN_BYTES]; //PG3 - Function Register + uint8_t addr; //Address of the driver according to wiring "ISSI3733: Table 1 Slave Address" + uint8_t onoff[ISSI3733_PG_ONOFF_BYTES]; //PG0 - LED Control Register - LED On/Off Register + uint8_t open[ISSI3733_PG_OR_BYTES]; //PG0 - LED Control Register - LED Open Register + uint8_t shrt[ISSI3733_PG_SR_BYTES]; //PG0 - LED Control Register - LED Short Register + uint8_t pwm[ISSI3733_PG_PWM_BYTES]; //PG1 - PWM Register + uint8_t abm[ISSI3733_PG_ABM_BYTES]; //PG2 - Auto Breath Mode Register + uint8_t conf[ISSI3733_PG_FN_BYTES]; //PG3 - Function Register } issi3733_driver_t; typedef struct issi3733_rgb_s { - uint8_t *r; //Direct access into PWM data - uint8_t *g; //Direct access into PWM data - uint8_t *b; //Direct access into PWM data + uint8_t *r; //Direct access into PWM data + uint8_t *g; //Direct access into PWM data + uint8_t *b; //Direct access into PWM data } issi3733_rgb_t; typedef struct issi3733_rgb_adr_s { - uint8_t drv; //Driver from given list - uint8_t cs; //CS - uint8_t swr; //SW Red - uint8_t swg; //SW Green - uint8_t swb; //SW Blue + uint8_t drv; //Driver from given list + uint8_t cs; //CS + uint8_t swr; //SW Red + uint8_t swg; //SW Green + uint8_t swb; //SW Blue } issi3733_rgb_adr_t; typedef struct issi3733_led_s { - uint8_t id; //According to PCB ref - issi3733_rgb_t rgb; //PWM settings of R G B - issi3733_rgb_adr_t adr; //Hardware addresses - float x; //Physical position X - float y; //Physical position Y - float px; //Physical position X in percent - float py; //Physical position Y in percent - uint8_t scan; //Key scan code from wiring (set 0xFF if no key) + uint8_t id; //According to PCB ref + issi3733_rgb_t rgb; //PWM settings of R G B + issi3733_rgb_adr_t adr; //Hardware addresses + float x; //Physical position X + float y; //Physical position Y + float px; //Physical position X in percent + float py; //Physical position Y in percent + uint8_t scan; //Key scan code from wiring (set 0xFF if no key) } issi3733_led_t; typedef struct led_disp_s { - uint64_t frame; - float left; - float right; - float top; - float bottom; - float width; - float height; + uint64_t clk_ms; + uint64_t frame; + float left; + float right; + float top; + float bottom; + float width; + float height; } led_disp_t; uint8_t led_matrix_init(void); @@ -94,46 +95,12 @@ void rgb_matrix_init_user(void); #define LED_MODE_INDICATORS_ONLY 3 #define LED_MODE_MAX_INDEX LED_MODE_INDICATORS_ONLY //Must be highest value -#define EF_NONE 0x00000000 //No effect -#define EF_OVER 0x00000001 //Overwrite any previous color information with new -#define EF_SCR_L 0x00000002 //Scroll left -#define EF_SCR_R 0x00000004 //Scroll right -#define EF_SUBTRACT 0x00000008 //Subtract color values - -typedef struct led_setup_s { - float hs; //Band begin at percent - float he; //Band end at percent - uint8_t rs; //Red start value - uint8_t re; //Red end value - uint8_t gs; //Green start value - uint8_t ge; //Green end value - uint8_t bs; //Blue start value - uint8_t be; //Blue end value - uint32_t ef; //Animation and color effects - uint8_t end; //Set to signal end of the setup -} led_setup_t; - -//LED Extra Instructions -#define LED_FLAG_NULL 0x00 -#define LED_FLAG_MATCH_ID 0x01 -#define LED_FLAG_MATCH_LAYER 0x02 -#define LED_FLAG_USE_RGB 0x10 -#define LED_FLAG_USE_PATTERN 0x20 -#define LED_FLAG_USE_ROTATE_PATTERN 0x40 - -typedef struct led_instruction_s { - uint16_t flags; // Bitfield for LED instructions - uint32_t id0; // Bitwise id, IDs 0-31 - uint32_t id1; // Bitwise id, IDs 32-63 - uint32_t id2; // Bitwise id, IDs 64-95 - uint32_t id3; // Bitwise id, IDs 96-127 - uint8_t layer; - uint8_t r; - uint8_t g; - uint8_t b; - uint8_t pattern_id; - uint8_t end; -} led_instruction_t; +typedef struct led_static_color_s { + uint32_t ef; // Animation and color effects + uint8_t r; + uint8_t g; + uint8_t b; +} led_static_color_t; extern issi3733_driver_t issidrv[ISSI3733_DRIVER_COUNT]; @@ -142,28 +109,21 @@ extern uint8_t gcr_breathe; extern uint8_t gcr_actual; extern uint8_t gcr_actual_last; -extern uint8_t led_animation_id; extern uint8_t led_enabled; -extern float led_animation_speed; -extern uint8_t led_lighting_mode; -extern uint8_t led_animation_direction; -extern uint8_t led_animation_orientation; extern uint8_t led_animation_breathing; -extern uint8_t led_animation_breathe_cur; -extern uint8_t breathe_dir; -extern const uint8_t led_setups_count; - -extern void *led_setups[]; -extern led_instruction_t led_instructions[]; - -extern uint32_t layer_state; +extern issi3733_led_t led_map[ISSI3733_LED_COUNT+1]; extern issi3733_led_t *led_cur; extern issi3733_led_t *lede; +extern led_static_color_t static_color_map[ISSI3733_LED_COUNT+1]; void led_matrix_run(void); void led_matrix_task(void); void gcr_compute(void); +void rgb_matrix_set_color(uint8_t index, uint8_t red, uint8_t green, uint8_t blue); + +void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue); + #endif //_LED_MATRIX_H_