Update q7

This commit is contained in:
lalalademaxiya1 2022-04-07 15:05:09 +08:00
parent d846155734
commit c183bcf1fb
11 changed files with 63 additions and 81 deletions

View File

@ -16,7 +16,7 @@ NKRO_ENABLE = yes # Enable USB N-key Rollover
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
AUDIO_ENABLE = no # Audio output AUDIO_ENABLE = no # Audio output
ENCODER_ENABLE = no # Enable Encoder ENCODER_ENABLE = yes # Enable Encoder
DIP_SWITCH_ENABLE = yes DIP_SWITCH_ENABLE = yes
RGB_MATRIX_ENABLE = yes RGB_MATRIX_ENABLE = yes
RGB_MATRIX_DRIVER = CKLED2001 RGB_MATRIX_DRIVER = CKLED2001

View File

@ -18,7 +18,7 @@
/* USB Device descriptor parameter */ /* USB Device descriptor parameter */
#define PRODUCT_ID 0x0170 #define PRODUCT_ID 0x0170
#define DEVICE_VER 0x0103 #define DEVICE_VER 0x0104
/* RGB Matrix Configuration */ /* RGB Matrix Configuration */
#define DRIVER_1_LED_TOTAL 37 #define DRIVER_1_LED_TOTAL 37

View File

@ -90,17 +90,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS) KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS)
}; };
void matrix_scan_user(void) {
timer_task_start();
}
bool dip_switch_update_user(uint8_t index, bool active) { bool dip_switch_update_user(uint8_t index, bool active) {
system_switch_state_report(index, active); system_switch_state_report(index, active);
return true; return true;
} }
bool process_record_user(uint16_t keycode, keyrecord_t *record) { bool process_record_user(uint16_t keycode, keyrecord_t *record) {
process_other_record(keycode, record);
switch (keycode) { switch (keycode) {
case KC_MCTL: case KC_MCTL:
if (record->event.pressed) { if (record->event.pressed) {

View File

@ -90,17 +90,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS) KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS)
}; };
void matrix_scan_user(void) {
timer_task_start();
}
bool dip_switch_update_user(uint8_t index, bool active) { bool dip_switch_update_user(uint8_t index, bool active) {
system_switch_state_report(index, active); system_switch_state_report(index, active);
return true; return true;
} }
bool process_record_user(uint16_t keycode, keyrecord_t *record) { bool process_record_user(uint16_t keycode, keyrecord_t *record) {
process_other_record(keycode, record);
switch (keycode) { switch (keycode) {
case KC_MCTL: case KC_MCTL:
if (record->event.pressed) { if (record->event.pressed) {

View File

@ -126,7 +126,7 @@ led_config_t g_led_config = {
// RGB LED Index to Flag // RGB LED Index to Flag
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1,
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1,
9, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 8, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1,
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1,
1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1,
} }

View File

@ -18,7 +18,7 @@
/* USB Device descriptor parameter */ /* USB Device descriptor parameter */
#define PRODUCT_ID 0x0172 #define PRODUCT_ID 0x0172
#define DEVICE_VER 0x0101 #define DEVICE_VER 0x0102
/* RGB Matrix Configuration */ /* RGB Matrix Configuration */
#define DRIVER_1_LED_TOTAL 37 #define DRIVER_1_LED_TOTAL 37

View File

@ -90,17 +90,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS) KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS)
}; };
void matrix_scan_user(void) {
timer_task_start();
}
bool dip_switch_update_user(uint8_t index, bool active) { bool dip_switch_update_user(uint8_t index, bool active) {
system_switch_state_report(index, active); system_switch_state_report(index, active);
return true; return true;
} }
bool process_record_user(uint16_t keycode, keyrecord_t *record) { bool process_record_user(uint16_t keycode, keyrecord_t *record) {
process_other_record(keycode, record);
switch (keycode) { switch (keycode) {
case KC_MCTL: case KC_MCTL:
if (record->event.pressed) { if (record->event.pressed) {

View File

@ -90,19 +90,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS) KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS)
}; };
void matrix_scan_user(void) {
timer_task_start();
}
bool dip_switch_update_user(uint8_t index, bool active) { bool dip_switch_update_user(uint8_t index, bool active) {
system_switch_state_report(index, active); system_switch_state_report(index, active);
return true; return true;
} }
bool process_record_user(uint16_t keycode, keyrecord_t *record) { bool process_record_user(uint16_t keycode, keyrecord_t *record) {
/* Handle other events like factory reset and led test */
process_other_record(keycode, record);
switch (keycode) { switch (keycode) {
case KC_MCTL: case KC_MCTL:
if (record->event.pressed) { if (record->event.pressed) {

View File

@ -127,7 +127,7 @@ led_config_t g_led_config = {
// RGB LED Index to Flag // RGB LED Index to Flag
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1,
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1,
9, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 8, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1,
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1,
1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1,
} }

View File

@ -18,10 +18,12 @@
#define MAC_FN 2 #define MAC_FN 2
#define WIN_FN 3 #define WIN_FN 3
#ifndef RAW_EPSIZE
# define RAW_EPSIZE 32
#endif
static void timer_3000ms_task(void); static void timer_3s_task(void);
static void timer_250ms_task(void); static void timer_300ms_task(void);
static void factory_test_send(uint8_t *payload, uint8_t length);
#define KEY_PRESS_FN (0x1<<0) #define KEY_PRESS_FN (0x1<<0)
#define KEY_PRESS_J (0x1<<1) #define KEY_PRESS_J (0x1<<1)
@ -51,12 +53,12 @@ enum {
}; };
uint16_t key_press_status = 0; uint16_t key_press_status = 0;
uint32_t timer_3000ms_buffer = 0; uint32_t timer_3s_buffer = 0;
uint32_t timer_250ms_buffer = 0; uint32_t timer_300ms_buffer = 0;
uint8_t factory_reset_count = 0; uint8_t factory_reset_count = 0;
bool report_os_sw_state = false; bool report_os_sw_state = false;
void process_other_record(uint16_t keycode, keyrecord_t *record) { bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
switch (keycode) { switch (keycode) {
case MO(MAC_FN): case MO(MAC_FN):
case MO(WIN_FN): case MO(WIN_FN):
@ -64,31 +66,31 @@ void process_other_record(uint16_t keycode, keyrecord_t *record) {
key_press_status |= KEY_PRESS_FN; key_press_status |= KEY_PRESS_FN;
} else { } else {
key_press_status &= ~KEY_PRESS_FN; key_press_status &= ~KEY_PRESS_FN;
timer_3000ms_buffer = 0; timer_3s_buffer = 0;
} }
break; return true;
case KC_J: case KC_J:
if (record->event.pressed) { if (record->event.pressed) {
key_press_status |= KEY_PRESS_J; key_press_status |= KEY_PRESS_J;
if (key_press_status == KEY_PRESS_FACTORY_RESET) { if (key_press_status == KEY_PRESS_FACTORY_RESET) {
timer_3000ms_buffer = sync_timer_read32() | 1; timer_3s_buffer = sync_timer_read32() | 1;
} }
} else { } else {
key_press_status &= ~KEY_PRESS_J; key_press_status &= ~KEY_PRESS_J;
timer_3000ms_buffer = 0; timer_3s_buffer = 0;
} }
break; return true;
case KC_Z: case KC_Z:
if (record->event.pressed) { if (record->event.pressed) {
key_press_status |= KEY_PRESS_Z; key_press_status |= KEY_PRESS_Z;
if (key_press_status == KEY_PRESS_FACTORY_RESET) { if (key_press_status == KEY_PRESS_FACTORY_RESET) {
timer_3000ms_buffer = sync_timer_read32() | 1; timer_3s_buffer = sync_timer_read32() | 1;
} }
} else { } else {
key_press_status &= ~KEY_PRESS_Z; key_press_status &= ~KEY_PRESS_Z;
timer_3000ms_buffer = 0; timer_3s_buffer = 0;
} }
break; return true;
case KC_RGHT: case KC_RGHT:
if (record->event.pressed) { if (record->event.pressed) {
key_press_status |= KEY_PRESS_RIGHT; key_press_status |= KEY_PRESS_RIGHT;
@ -97,46 +99,52 @@ void process_other_record(uint16_t keycode, keyrecord_t *record) {
led_test_mode = LED_TEST_MODE_WHITE; led_test_mode = LED_TEST_MODE_WHITE;
} }
} else if (key_press_status == KEY_PRESS_LED_TEST) { } else if (key_press_status == KEY_PRESS_LED_TEST) {
timer_3000ms_buffer = sync_timer_read32() | 1; timer_3s_buffer = sync_timer_read32() | 1;
} }
} else { } else {
key_press_status &= ~KEY_PRESS_RIGHT; key_press_status &= ~KEY_PRESS_RIGHT;
timer_3000ms_buffer = 0; timer_3s_buffer = 0;
} }
break; return true;
case KC_HOME: case KC_HOME:
if (record->event.pressed) { if (record->event.pressed) {
key_press_status |= KEY_PRESS_HOME; key_press_status |= KEY_PRESS_HOME;
if (led_test_mode) { if (led_test_mode) {
led_test_mode = LED_TEST_MODE_OFF; led_test_mode = LED_TEST_MODE_OFF;
} else if (key_press_status == KEY_PRESS_LED_TEST) { } else if (key_press_status == KEY_PRESS_LED_TEST) {
timer_3000ms_buffer = sync_timer_read32() | 1; timer_3s_buffer = sync_timer_read32() | 1;
} }
} else { } else {
key_press_status &= ~KEY_PRESS_HOME; key_press_status &= ~KEY_PRESS_HOME;
timer_3000ms_buffer = 0; timer_3s_buffer = 0;
} }
break; return true;
default:
return process_record_user(keycode, record);
} }
} }
void timer_task_start(void) { void matrix_scan_kb(void) {
if (timer_3000ms_buffer) { if (timer_3s_buffer) {
timer_3000ms_task(); timer_3s_task();
} else if (timer_250ms_buffer) {
timer_250ms_task();
} }
if (timer_300ms_buffer) {
timer_300ms_task();
}
matrix_scan_user();
} }
static void timer_3000ms_task(void) { static void timer_3s_task(void) {
if (sync_timer_elapsed32(timer_3000ms_buffer) > 3000) { if (sync_timer_elapsed32(timer_3s_buffer) > 3000) {
timer_3000ms_buffer = 0; timer_3s_buffer = 0;
if (key_press_status == KEY_PRESS_FACTORY_RESET) { if (key_press_status == KEY_PRESS_FACTORY_RESET) {
timer_250ms_buffer = sync_timer_read32() | 1; timer_300ms_buffer = sync_timer_read32() | 1;
factory_reset_count++; factory_reset_count++;
layer_state_t default_layer_tmp = default_layer_state; layer_state_t default_layer_tmp = default_layer_state;
eeconfig_init(); eeconfig_init();
default_layer_set(default_layer_tmp); default_layer_set(default_layer_tmp);
led_test_mode = LED_TEST_MODE_OFF;
#ifdef LED_MATRIX_ENABLE #ifdef LED_MATRIX_ENABLE
if (!led_matrix_is_enabled()) led_matrix_enable(); if (!led_matrix_is_enabled()) led_matrix_enable();
led_matrix_init(); led_matrix_init();
@ -159,13 +167,13 @@ static void timer_3000ms_task(void) {
} }
} }
static void timer_250ms_task(void) { static void timer_300ms_task(void) {
if (timer_250ms_buffer && sync_timer_elapsed32(timer_250ms_buffer) > 250) { if (timer_300ms_buffer && sync_timer_elapsed32(timer_300ms_buffer) > 300) {
if (factory_reset_count++ > 6) { if (factory_reset_count++ > 6) {
timer_250ms_buffer = 0; timer_300ms_buffer = 0;
factory_reset_count = 0; factory_reset_count = 0;
} else { } else {
timer_250ms_buffer = sync_timer_read32() | 1; timer_300ms_buffer = sync_timer_read32() | 1;
} }
} }
} }
@ -232,13 +240,13 @@ void raw_hid_receive_kb(uint8_t *data, uint8_t length) {
switch (data[1]) { switch (data[1]) {
case FACTORY_TEST_CMD_BACKLIGHT: case FACTORY_TEST_CMD_BACKLIGHT:
led_test_mode = data[2]; led_test_mode = data[2];
timer_3000ms_buffer = 0; timer_3s_buffer = 0;
break; break;
case FACTORY_TEST_CMD_OS_SWITCH: case FACTORY_TEST_CMD_OS_SWITCH:
report_os_sw_state = data[2]; report_os_sw_state = data[2];
if (report_os_sw_state) { // if (report_os_sw_state) {
// dip_switch_read(true); // dip_switch_read(true);
} // }
break; break;
case FACTORY_TEST_CMD_JUMP_TO_BL: case FACTORY_TEST_CMD_JUMP_TO_BL:
if (memcmp(&data[2], "JumpToBootloader", strlen("JumpToBootloader")) == 0) if (memcmp(&data[2], "JumpToBootloader", strlen("JumpToBootloader")) == 0)
@ -248,25 +256,23 @@ void raw_hid_receive_kb(uint8_t *data, uint8_t length) {
} }
} }
static void factory_test_send(uint8_t *payload, uint8_t length) { void system_switch_state_report(uint8_t index, bool active) {
uint16_t checksum = 0; uint16_t checksum = 0;
uint8_t data[RAW_EPSIZE] = {0}; uint8_t data[RAW_EPSIZE] = {0};
uint8_t i = 0; uint8_t payload[3] = { 0 };
data[i++] = 0xAB;
memcpy(&data[i], payload, length);
i += length;
for (uint8_t i=1; i<RAW_EPSIZE-3; i++ ) {
checksum += data[i];
}
data[RAW_EPSIZE-2] = checksum & 0xFF;
data[RAW_EPSIZE-1] = (checksum >> 8) & 0xFF;
raw_hid_send(data, RAW_EPSIZE);
}
void system_switch_state_report(uint8_t index, bool active) {
if (report_os_sw_state) { if (report_os_sw_state) {
uint8_t payload[3] = {FACTORY_TEST_CMD_OS_SWITCH, OS_SWITCH, active}; payload[0] = FACTORY_TEST_CMD_OS_SWITCH;
factory_test_send(payload, 3); payload[1] = OS_SWITCH;
payload[2] = active;
data[0] = 0xAB;
memcpy(&data[1], payload, 3);
for (uint8_t i=1; i<RAW_EPSIZE-3; i++ ) {
checksum += data[i];
}
data[RAW_EPSIZE-2] = checksum & 0xFF;
data[RAW_EPSIZE-1] = (checksum >> 8) & 0xFF;
raw_hid_send(data, RAW_EPSIZE);
} }
} }

View File

@ -20,8 +20,6 @@
#include "quantum.h" #include "quantum.h"
#include "raw_hid.h" #include "raw_hid.h"
void process_other_record(uint16_t keycode, keyrecord_t *record);
void timer_task_start(void);
void system_switch_state_report(uint8_t index, bool active); void system_switch_state_report(uint8_t index, bool active);
#endif /* _TEST_H_ */ #endif /* _TEST_H_ */