Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralize Massdrop LED instruction code, add new effects #3

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions keyboards/massdrop/alt/alt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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 },
};
3 changes: 3 additions & 0 deletions keyboards/massdrop/alt/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define MATRIX_ROWS 5
#define MATRIX_COLS 15

#define KEYMAP_ROWS 5
#define KEYMAP_COLS 15

#define PA 0
#define PB 1

Expand Down
2 changes: 1 addition & 1 deletion keyboards/massdrop/alt/config_led.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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
Expand Down
5 changes: 2 additions & 3 deletions keyboards/massdrop/alt/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
196 changes: 196 additions & 0 deletions keyboards/massdrop/alt/keymaps/example_custom_patterns/keymap.c
Original file line number Diff line number Diff line change
@@ -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 }
};
Loading