mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-07-01 05:22:05 +00:00
Unlock on RESET keypress:
- Display unlock pattern - Disable LED get/set functions - Enable reset to bootloader function
This commit is contained in:
parent
58dc8dc241
commit
e4adf94e76
@ -104,6 +104,20 @@ void matrix_scan_kb(void) {
|
|||||||
matrix_scan_user();
|
matrix_scan_user();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void system76_ec_unlock(void);
|
||||||
|
|
||||||
|
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
|
||||||
|
switch(keycode) {
|
||||||
|
case RESET:
|
||||||
|
if (record->event.pressed) {
|
||||||
|
system76_ec_unlock();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return process_record_user(keycode, record);
|
||||||
|
}
|
||||||
|
|
||||||
void suspend_power_down_kb(void) {
|
void suspend_power_down_kb(void) {
|
||||||
rgb_matrix_set_suspend_state(true);
|
rgb_matrix_set_suspend_state(true);
|
||||||
suspend_power_down_user();
|
suspend_power_down_user();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
RGB_MATRIX_EFFECT(raw_rgb)
|
RGB_MATRIX_EFFECT(raw_rgb)
|
||||||
|
RGB_MATRIX_EFFECT(unlocked)
|
||||||
|
|
||||||
#if defined(RGB_MATRIX_CUSTOM_EFFECT_IMPLS)
|
#if defined(RGB_MATRIX_CUSTOM_EFFECT_IMPLS)
|
||||||
RGB raw_rgb_data[DRIVER_LED_TOTAL] = { 0 };
|
RGB raw_rgb_data[DRIVER_LED_TOTAL] = { 0 };
|
||||||
@ -29,4 +30,65 @@ static bool raw_rgb(effect_params_t* params) {
|
|||||||
}
|
}
|
||||||
return led_max < DRIVER_LED_TOTAL;
|
return led_max < DRIVER_LED_TOTAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint8_t unlocked_keys[8][2] = {
|
||||||
|
{2, 7}, // U
|
||||||
|
{4, 6}, // N
|
||||||
|
{3, 9}, // L
|
||||||
|
{2, 9}, // O
|
||||||
|
{4, 3}, // C
|
||||||
|
{3, 8}, // K
|
||||||
|
{2, 3}, // E
|
||||||
|
{3, 3}, // D
|
||||||
|
};
|
||||||
|
|
||||||
|
static uint8_t unlocked_ticks = 0;
|
||||||
|
static uint8_t unlocked_i = 0;
|
||||||
|
static uint8_t unlocked_leds_count = 0;
|
||||||
|
static uint8_t unlocked_leds[2] = { 0, 0 };
|
||||||
|
|
||||||
|
static bool unlocked(effect_params_t* params) {
|
||||||
|
RGB_MATRIX_USE_LIMITS(led_min, led_max);
|
||||||
|
|
||||||
|
unlocked_ticks++;
|
||||||
|
|
||||||
|
if (params->init) {
|
||||||
|
unlocked_ticks = 0;
|
||||||
|
unlocked_i = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unlocked_ticks == 0) {
|
||||||
|
if (unlocked_i == 8) {
|
||||||
|
unlocked_leds_count = 0;
|
||||||
|
unlocked_i = 0;
|
||||||
|
} else {
|
||||||
|
unlocked_leds_count = rgb_matrix_map_row_column_to_led(
|
||||||
|
unlocked_keys[unlocked_i][0],
|
||||||
|
unlocked_keys[unlocked_i][1],
|
||||||
|
unlocked_leds
|
||||||
|
);
|
||||||
|
unlocked_i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint8_t i = led_min; i < led_max; i++) {
|
||||||
|
RGB_MATRIX_TEST_LED_FLAGS();
|
||||||
|
|
||||||
|
HSV hsv = {
|
||||||
|
.h = i + unlocked_ticks,
|
||||||
|
.s = 0xFF,
|
||||||
|
.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS,
|
||||||
|
};
|
||||||
|
for (uint8_t j = 0; j < unlocked_leds_count; j++) {
|
||||||
|
if (i == unlocked_leds[j]) {
|
||||||
|
hsv.s = 0;
|
||||||
|
hsv.v = 0xFF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RGB rgb = hsv_to_rgb(hsv);
|
||||||
|
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
|
||||||
|
}
|
||||||
|
return led_max < DRIVER_LED_TOTAL;
|
||||||
|
}
|
||||||
#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
|
#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
|
||||||
|
@ -53,6 +53,13 @@ static bool keymap_set(uint8_t layer, uint8_t output, uint8_t input, uint16_t va
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool bootloader_reset = false;
|
||||||
|
static bool bootloader_unlocked = false;
|
||||||
|
|
||||||
|
void system76_ec_unlock(void) {
|
||||||
|
rgb_matrix_mode_noeeprom(RGB_MATRIX_CUSTOM_unlocked);
|
||||||
|
bootloader_unlocked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(RGB_MATRIX_CUSTOM_KB)
|
#if defined(RGB_MATRIX_CUSTOM_KB)
|
||||||
@ -81,7 +88,10 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
|
|||||||
data[1] = 0;
|
data[1] = 0;
|
||||||
break;
|
break;
|
||||||
case CMD_RESET:
|
case CMD_RESET:
|
||||||
bootloader_jump();
|
if (bootloader_unlocked) {
|
||||||
|
data[1] = 0;
|
||||||
|
bootloader_reset = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case CMD_KEYMAP_GET:
|
case CMD_KEYMAP_GET:
|
||||||
{
|
{
|
||||||
@ -105,7 +115,7 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
|
|||||||
break;
|
break;
|
||||||
#if defined(RGB_MATRIX_CUSTOM_KB)
|
#if defined(RGB_MATRIX_CUSTOM_KB)
|
||||||
case CMD_LED_GET_VALUE:
|
case CMD_LED_GET_VALUE:
|
||||||
{
|
if (!bootloader_unlocked) {
|
||||||
if (data[2] == CMD_LED_INDEX_ALL) {
|
if (data[2] == CMD_LED_INDEX_ALL) {
|
||||||
data[3] = rgb_matrix_config.hsv.v;
|
data[3] = rgb_matrix_config.hsv.v;
|
||||||
data[4] = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
|
data[4] = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
|
||||||
@ -114,7 +124,7 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CMD_LED_SET_VALUE:
|
case CMD_LED_SET_VALUE:
|
||||||
{
|
if (!bootloader_unlocked) {
|
||||||
if (data[2] == CMD_LED_INDEX_ALL) {
|
if (data[2] == CMD_LED_INDEX_ALL) {
|
||||||
rgb_matrix_sethsv_noeeprom(
|
rgb_matrix_sethsv_noeeprom(
|
||||||
rgb_matrix_config.hsv.h,
|
rgb_matrix_config.hsv.h,
|
||||||
@ -126,7 +136,7 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CMD_LED_GET_COLOR:
|
case CMD_LED_GET_COLOR:
|
||||||
{
|
if (!bootloader_unlocked) {
|
||||||
uint8_t index = data[2];
|
uint8_t index = data[2];
|
||||||
if (index < DRIVER_LED_TOTAL) {
|
if (index < DRIVER_LED_TOTAL) {
|
||||||
data[3] = raw_rgb_data[index].r;
|
data[3] = raw_rgb_data[index].r;
|
||||||
@ -142,7 +152,7 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CMD_LED_SET_COLOR:
|
case CMD_LED_SET_COLOR:
|
||||||
{
|
if (!bootloader_unlocked) {
|
||||||
uint8_t index = data[2];
|
uint8_t index = data[2];
|
||||||
RGB rgb = {
|
RGB rgb = {
|
||||||
.r = data[3],
|
.r = data[3],
|
||||||
@ -166,4 +176,11 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
raw_hid_send(data, length);
|
raw_hid_send(data, length);
|
||||||
|
|
||||||
|
if (bootloader_reset) {
|
||||||
|
// Give host time to read response
|
||||||
|
wait_ms(100);
|
||||||
|
// Jump to the bootloader
|
||||||
|
bootloader_jump();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user