-
Notifications
You must be signed in to change notification settings - Fork 24
Add support for external userspace, encoder maps, and more #5
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
base: master
Are you sure you want to change the base?
Changes from all commits
91a9f9e
8c035c2
3194862
1e68392
3d591a2
a0b15d0
e31384b
56a2e33
70c36c6
e391793
7d66c11
127c664
863b308
38815db
b02b222
3236973
0371599
b7936cc
b4abbab
8e99361
4d41e56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,214 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| #include "matrix.h" | ||||||||||||||||||||||||||||||||||||||||||||||
| #include "quantum.h" | ||||||||||||||||||||||||||||||||||||||||||||||
| #include "print.h" | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #include QMK_KEYBOARD_H | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // This is to keep state between callbacks, when it is 0 the | ||||||||||||||||||||||||||||||||||||||||||||||
| // initial RGB flash is finished | ||||||||||||||||||||||||||||||||||||||||||||||
| uint8_t _hue_countdown = 50; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // These are to keep track of user selected color, so we | ||||||||||||||||||||||||||||||||||||||||||||||
| // can restore it after RGB flash | ||||||||||||||||||||||||||||||||||||||||||||||
| uint8_t _hue; | ||||||||||||||||||||||||||||||||||||||||||||||
| uint8_t _saturation; | ||||||||||||||||||||||||||||||||||||||||||||||
| uint8_t _value; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Do a little 2.5 seconds display of the different colors | ||||||||||||||||||||||||||||||||||||||||||||||
| // Use the deferred executor so the LED flash dance does not | ||||||||||||||||||||||||||||||||||||||||||||||
| // stop us from using the keyboard. | ||||||||||||||||||||||||||||||||||||||||||||||
| // https://docs.qmk.fm/#/custom_quantum_functions?id=deferred-executor-registration | ||||||||||||||||||||||||||||||||||||||||||||||
| uint32_t flash_led(uint32_t next_trigger_time, void *cb_arg) { | ||||||||||||||||||||||||||||||||||||||||||||||
| rgblight_sethsv(_hue_countdown * 5, 230, 70); | ||||||||||||||||||||||||||||||||||||||||||||||
| _hue_countdown--; | ||||||||||||||||||||||||||||||||||||||||||||||
| if (_hue_countdown == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||
| // Finished, reset to user chosen led color | ||||||||||||||||||||||||||||||||||||||||||||||
| rgblight_sethsv(_hue, _saturation, _value); | ||||||||||||||||||||||||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| return 50; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| void keyboard_post_init_kb(void) { | ||||||||||||||||||||||||||||||||||||||||||||||
| // debug_enable=true; | ||||||||||||||||||||||||||||||||||||||||||||||
| // debug_matrix=true; | ||||||||||||||||||||||||||||||||||||||||||||||
| // debug_keyboard=true; | ||||||||||||||||||||||||||||||||||||||||||||||
| // debug_mouse=true; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Store user selected rgb hsv: | ||||||||||||||||||||||||||||||||||||||||||||||
| _hue = rgblight_get_hue(); | ||||||||||||||||||||||||||||||||||||||||||||||
| _saturation = rgblight_get_sat(); | ||||||||||||||||||||||||||||||||||||||||||||||
| _value = rgblight_get_val(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Flash a little on start | ||||||||||||||||||||||||||||||||||||||||||||||
| defer_exec(50, flash_led, NULL); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // This is just to be able to declare constants as they appear in the qmk console | ||||||||||||||||||||||||||||||||||||||||||||||
| #define rev(b) \ | ||||||||||||||||||||||||||||||||||||||||||||||
| ((b & 1) << 15) | \ | ||||||||||||||||||||||||||||||||||||||||||||||
| ((b & (1 << 1)) << 13) | \ | ||||||||||||||||||||||||||||||||||||||||||||||
| ((b & (1 << 2)) << 11) | \ | ||||||||||||||||||||||||||||||||||||||||||||||
| ((b & (1 << 3)) << 9) | \ | ||||||||||||||||||||||||||||||||||||||||||||||
| ((b & (1 << 4)) << 7) | \ | ||||||||||||||||||||||||||||||||||||||||||||||
| ((b & (1 << 5)) << 5) | \ | ||||||||||||||||||||||||||||||||||||||||||||||
| ((b & (1 << 6)) << 3) | \ | ||||||||||||||||||||||||||||||||||||||||||||||
| ((b & (1 << 7)) << 1) | \ | ||||||||||||||||||||||||||||||||||||||||||||||
| ((b & (1 << 8)) >> 1) | \ | ||||||||||||||||||||||||||||||||||||||||||||||
| ((b & (1 << 9)) >> 3) | \ | ||||||||||||||||||||||||||||||||||||||||||||||
| ((b & (1 << 10)) >> 5) | \ | ||||||||||||||||||||||||||||||||||||||||||||||
| ((b & (1 << 11)) >> 7) | \ | ||||||||||||||||||||||||||||||||||||||||||||||
| ((b & (1 << 12)) >> 9) | \ | ||||||||||||||||||||||||||||||||||||||||||||||
| ((b & (1 << 13)) >> 11) | \ | ||||||||||||||||||||||||||||||||||||||||||||||
| ((b & (1 << 14)) >> 13) | \ | ||||||||||||||||||||||||||||||||||||||||||||||
| b >> 15 | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /* This is for debugging the matrix rows | ||||||||||||||||||||||||||||||||||||||||||||||
| void printBits(uint16_t n) | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| long i; | ||||||||||||||||||||||||||||||||||||||||||||||
| for (i = 15; i >= 0; i--) { | ||||||||||||||||||||||||||||||||||||||||||||||
| if ((n & (1 << i)) != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||
| printf("1"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| else { | ||||||||||||||||||||||||||||||||||||||||||||||
| printf("0"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| printf("\n"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| bool bit_pattern_set(uint16_t number, uint16_t bitPattern) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return !(~number & bitPattern); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| void fix_ghosting_instance( | ||||||||||||||||||||||||||||||||||||||||||||||
| matrix_row_t current_matrix[], | ||||||||||||||||||||||||||||||||||||||||||||||
| unsigned short row_num_with_possible_error_cause, | ||||||||||||||||||||||||||||||||||||||||||||||
| uint16_t possible_error_cause, | ||||||||||||||||||||||||||||||||||||||||||||||
| unsigned short row_num_with_possible_error, | ||||||||||||||||||||||||||||||||||||||||||||||
| uint16_t possible_error, | ||||||||||||||||||||||||||||||||||||||||||||||
| uint16_t error_fix) { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (bit_pattern_set(current_matrix[row_num_with_possible_error_cause], possible_error_cause)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (bit_pattern_set(current_matrix[row_num_with_possible_error], possible_error)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| current_matrix[row_num_with_possible_error] = current_matrix[row_num_with_possible_error] ^ error_fix; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| void fix_ghosting_column( | ||||||||||||||||||||||||||||||||||||||||||||||
| matrix_row_t matrix[], | ||||||||||||||||||||||||||||||||||||||||||||||
| uint16_t possible_error_cause, | ||||||||||||||||||||||||||||||||||||||||||||||
| uint16_t possible_error, | ||||||||||||||||||||||||||||||||||||||||||||||
| uint16_t error_fix) { | ||||||||||||||||||||||||||||||||||||||||||||||
| // First the right side | ||||||||||||||||||||||||||||||||||||||||||||||
| for (short i = 0; i<3; i++) { | ||||||||||||||||||||||||||||||||||||||||||||||
| fix_ghosting_instance(matrix, i, possible_error_cause, (i+1)%3, possible_error, error_fix); | ||||||||||||||||||||||||||||||||||||||||||||||
| fix_ghosting_instance(matrix, i, possible_error_cause, (i+2)%3, possible_error, error_fix); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Then exactly same procedure on the left side | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+106
to
+112
|
||||||||||||||||||||||||||||||||||||||||||||||
| // First the right side | |
| for (short i = 0; i<3; i++) { | |
| fix_ghosting_instance(matrix, i, possible_error_cause, (i+1)%3, possible_error, error_fix); | |
| fix_ghosting_instance(matrix, i, possible_error_cause, (i+2)%3, possible_error, error_fix); | |
| } | |
| // Then exactly same procedure on the left side | |
| // First the right side. | |
| // For each of the three rows on this side (i = 0..2), check for ghosting | |
| // interactions with the other two rows. The expressions (i+1)%3 and (i+2)%3 | |
| // cycle through the two remaining row indices in {0,1,2} without going out | |
| // of bounds, so every pair of rows on the right side is considered. | |
| for (short i = 0; i<3; i++) { | |
| fix_ghosting_instance(matrix, i, possible_error_cause, (i+1)%3, possible_error, error_fix); | |
| fix_ghosting_instance(matrix, i, possible_error_cause, (i+2)%3, possible_error, error_fix); | |
| } | |
| // Then exactly same procedure on the left side. | |
| // Rows for the left side are stored starting at index 4, so we add 4 to the | |
| // row indices. The bit patterns are shifted by 6 to match the left-half | |
| // column positions, but the modulo math ((i+1)%3, (i+2)%3) still cycles | |
| // within the three left-side rows in the same way as on the right. |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's inconsistent spacing in the loop condition. Use consistent spacing around operators for better readability.
| for (short i = 0; i<3; i++) { | |
| fix_ghosting_instance(matrix, i, possible_error_cause, (i+1)%3, possible_error, error_fix); | |
| fix_ghosting_instance(matrix, i, possible_error_cause, (i+2)%3, possible_error, error_fix); | |
| } | |
| // Then exactly same procedure on the left side | |
| for (short i = 0; i<3; i++) { | |
| for (short i = 0; i < 3; i++) { | |
| fix_ghosting_instance(matrix, i, possible_error_cause, (i+1)%3, possible_error, error_fix); | |
| fix_ghosting_instance(matrix, i, possible_error_cause, (i+2)%3, possible_error, error_fix); | |
| } | |
| // Then exactly same procedure on the left side | |
| for (short i = 0; i < 3; i++) { |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's inconsistent spacing in the loop condition. Use consistent spacing around operators for better readability.
| for (short i = 0; i<3; i++) { | |
| fix_ghosting_instance(matrix, i, possible_error_cause, (i+1)%3, possible_error, error_fix); | |
| fix_ghosting_instance(matrix, i, possible_error_cause, (i+2)%3, possible_error, error_fix); | |
| } | |
| // Then exactly same procedure on the left side | |
| for (short i = 0; i<3; i++) { | |
| fix_ghosting_instance(matrix, i+4, possible_error_cause<<6, 4+((i+1)%3), possible_error<<6, error_fix<<6); | |
| fix_ghosting_instance(matrix, i+4, possible_error_cause<<6, 4+((i+2)%3), possible_error<<6, error_fix<<6); | |
| for (short i = 0; i < 3; i++) { | |
| fix_ghosting_instance(matrix, i, possible_error_cause, (i + 1) % 3, possible_error, error_fix); | |
| fix_ghosting_instance(matrix, i, possible_error_cause, (i + 2) % 3, possible_error, error_fix); | |
| } | |
| // Then exactly same procedure on the left side | |
| for (short i = 0; i < 3; i++) { | |
| fix_ghosting_instance(matrix, i + 4, possible_error_cause << 6, 4 + ((i + 1) % 3), possible_error << 6, error_fix << 6); | |
| fix_ghosting_instance(matrix, i + 4, possible_error_cause << 6, 4 + ((i + 2) % 3), possible_error << 6, error_fix << 6); |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment references "v3" but it's unclear what version the current code is for. This comment should be updated to clarify which version it applies to, or the TODO should be addressed if this is for v3.
| // These are observed ghosts(following a pattern). TODO: need to fix this for v3 | |
| // Might need to add 2 diodes(one in each direction) for every row, to increase voltage drop. | |
| // These are observed ghosts (following a pattern). TODO: if a v3 PCB/hardware revision is created, | |
| // re-validate these patterns and update this table as needed. Might need to add 2 diodes | |
| // (one in each direction) for every row, to increase voltage drop. |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The external function declaration should be placed at the top of the file or in a header file rather than inside the function body. This improves code organization and makes the dependency more explicit.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // Copyright 2023 Thomas Haukland (@tompi) | ||
| // SPDX-License-Identifier: GPL-2.0-or-later | ||
|
|
||
| #pragma once | ||
|
|
||
| // Force the usage of PIO1 peripheral, by default the WS2812 implementation uses the PIO0 peripheral. | ||
| #define WS2812_PIO_USE_PIO1 | ||
| #define WS2812_BYTE_ORDER WS2812_BYTE_ORDER_RGB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commented-out debugging function should either be removed if not needed, or properly documented if it's intended to be kept for future debugging purposes. Leaving large blocks of commented code reduces code maintainability.