summaryrefslogtreecommitdiffstats
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/api.c2
-rw-r--r--quantum/audio/musical_notes.h4
-rw-r--r--quantum/audio/song_list.h260
-rw-r--r--quantum/color.c2
-rw-r--r--quantum/config_common.h5
-rw-r--r--quantum/debounce/eager_pr.c100
-rw-r--r--quantum/debounce/readme.md2
-rw-r--r--quantum/encoder.c33
-rw-r--r--quantum/encoder.h8
-rw-r--r--quantum/keymap_common.c22
-rw-r--r--quantum/process_keycode/process_unicode_common.c3
-rw-r--r--quantum/quantum.c76
-rw-r--r--quantum/quantum.h6
-rw-r--r--quantum/rgb_matrix.c1185
-rw-r--r--quantum/rgb_matrix.h149
-rw-r--r--quantum/rgb_matrix_animations/alpha_mods_anim.h26
-rw-r--r--quantum/rgb_matrix_animations/breathing_anim.h20
-rw-r--r--quantum/rgb_matrix_animations/cycle_all_anim.h21
-rw-r--r--quantum/rgb_matrix_animations/cycle_left_right_anim.h22
-rw-r--r--quantum/rgb_matrix_animations/cycle_up_down_anim.h22
-rw-r--r--quantum/rgb_matrix_animations/digital_rain_anim.h74
-rw-r--r--quantum/rgb_matrix_animations/dual_beacon_anim.h24
-rw-r--r--quantum/rgb_matrix_animations/gradient_up_down_anim.h22
-rw-r--r--quantum/rgb_matrix_animations/jellybean_raindrops_anim.h30
-rw-r--r--quantum/rgb_matrix_animations/rainbow_beacon_anim.h24
-rw-r--r--quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h22
-rw-r--r--quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h24
-rw-r--r--quantum/rgb_matrix_animations/raindrops_anim.h40
-rw-r--r--quantum/rgb_matrix_animations/solid_color_anim.h14
-rw-r--r--quantum/rgb_matrix_animations/solid_reactive_anim.h33
-rw-r--r--quantum/rgb_matrix_animations/solid_reactive_simple_anim.h32
-rw-r--r--quantum/rgb_matrix_animations/solid_splash_anim.h42
-rw-r--r--quantum/rgb_matrix_animations/splash_anim.h44
-rw-r--r--quantum/rgb_matrix_types.h97
-rw-r--r--quantum/rgblight.c41
-rw-r--r--quantum/rgblight.h2
-rw-r--r--quantum/split_common/i2c.c184
-rw-r--r--quantum/split_common/i2c.h59
-rw-r--r--quantum/split_common/matrix.c8
-rw-r--r--quantum/split_common/split_flags.c5
-rw-r--r--quantum/split_common/split_flags.h15
-rw-r--r--quantum/split_common/split_util.c37
-rw-r--r--quantum/split_common/transport.c284
-rw-r--r--quantum/template/avr/template.c30
-rw-r--r--quantum/template/ps2avrgb/config.h13
-rw-r--r--quantum/template/ps2avrgb/i2c.c106
-rw-r--r--quantum/template/ps2avrgb/i2c.h27
-rw-r--r--quantum/template/ps2avrgb/matrix.c112
-rw-r--r--quantum/template/ps2avrgb/rules.mk4
-rw-r--r--quantum/template/ps2avrgb/template.c77
-rw-r--r--quantum/visualizer/readme.md2
51 files changed, 1851 insertions, 1645 deletions
diff --git a/quantum/api.c b/quantum/api.c
index 52dfe23e1..233f99636 100644
--- a/quantum/api.c
+++ b/quantum/api.c
@@ -67,7 +67,7 @@ void process_api(uint16_t length, uint8_t * data) {
case DT_RGBLIGHT: {
#ifdef RGBLIGHT_ENABLE
uint32_t rgblight = bytes_to_dword(data, 2);
- rgblight_update_dword(rgblight);
+ eeconfig_update_rgblight(rgblight);
#endif
break;
}
diff --git a/quantum/audio/musical_notes.h b/quantum/audio/musical_notes.h
index ce8d47d1c..cd54af38d 100644
--- a/quantum/audio/musical_notes.h
+++ b/quantum/audio/musical_notes.h
@@ -26,12 +26,14 @@
// Note Types
#define MUSICAL_NOTE(note, duration) {(NOTE##note), duration}
+#define BREVE_NOTE(note) MUSICAL_NOTE(note, 128)
#define WHOLE_NOTE(note) MUSICAL_NOTE(note, 64)
#define HALF_NOTE(note) MUSICAL_NOTE(note, 32)
#define QUARTER_NOTE(note) MUSICAL_NOTE(note, 16)
#define EIGHTH_NOTE(note) MUSICAL_NOTE(note, 8)
#define SIXTEENTH_NOTE(note) MUSICAL_NOTE(note, 4)
+#define BREVE_DOT_NOTE(note) MUSICAL_NOTE(note, 128+64)
#define WHOLE_DOT_NOTE(note) MUSICAL_NOTE(note, 64+32)
#define HALF_DOT_NOTE(note) MUSICAL_NOTE(note, 32+16)
#define QUARTER_DOT_NOTE(note) MUSICAL_NOTE(note, 16+8)
@@ -40,11 +42,13 @@
// Note Type Shortcuts
#define M__NOTE(note, duration) MUSICAL_NOTE(note, duration)
+#define B__NOTE(n) BREVE_NOTE(n)
#define W__NOTE(n) WHOLE_NOTE(n)
#define H__NOTE(n) HALF_NOTE(n)
#define Q__NOTE(n) QUARTER_NOTE(n)
#define E__NOTE(n) EIGHTH_NOTE(n)
#define S__NOTE(n) SIXTEENTH_NOTE(n)
+#define BD_NOTE(n) BREVE_DOT_NOTE(n)
#define WD_NOTE(n) WHOLE_DOT_NOTE(n)
#define HD_NOTE(n) HALF_DOT_NOTE(n)
#define QD_NOTE(n) QUARTER_DOT_NOTE(n)
diff --git a/quantum/audio/song_list.h b/quantum/audio/song_list.h
index 126c0e594..1d4eec711 100644
--- a/quantum/audio/song_list.h
+++ b/quantum/audio/song_list.h
@@ -533,5 +533,263 @@
H__NOTE(_C4 ), \
W__NOTE(_REST), \
QD_NOTE(_F4 ), \
- M__NOTE(_BF4, 128),
+ M__NOTE(_BF4, 128),
+
+#define KATAWARE_DOKI \
+ W__NOTE(_G5), HD_NOTE(_G5), Q__NOTE(_G5), H__NOTE(_G5), H__NOTE(_E5), H__NOTE(_D5), Q__NOTE(_D5), Q__NOTE(_C5), \
+ B__NOTE(_E5), H__NOTE(_C5), W__NOTE(_G5), HD_NOTE(_G5), Q__NOTE(_C5), H__NOTE(_C6), Q__NOTE(_B5), \
+ Q__NOTE(_A5), H__NOTE(_G5), Q__NOTE(_G5), Q__NOTE(_A5), W__NOTE(_G5), QD_NOTE(_E5), \
+ QD_NOTE(_F5), Q__NOTE(_E5), WD_NOTE(_D5), H__NOTE(_C5), W__NOTE(_G5), HD_NOTE(_G5), Q__NOTE(_G5), \
+ H__NOTE(_G5), H__NOTE(_E5), H__NOTE(_D5), Q__NOTE(_D5), Q__NOTE(_C5), B__NOTE(_E5), H__NOTE(_G4), \
+ Q__NOTE(_C5), Q__NOTE(_D5), Q__NOTE(_E5), H__NOTE(_D5), Q__NOTE(_C5), Q__NOTE(_C5), \
+ Q__NOTE(_A4), H__NOTE(_C5), Q__NOTE(_C5), W__NOTE(_C5), Q__NOTE(_F4), Q__NOTE(_C5), \
+ Q__NOTE(_D5), Q__NOTE(_E5), H__NOTE(_D5), H__NOTE(_C5), Q__NOTE(_C5), H__NOTE(_G5), \
+ Q__NOTE(_C5), HD_NOTE(_D5), H__NOTE(_G4), Q__NOTE(_C5), Q__NOTE(_D5), Q__NOTE(_E5), \
+ H__NOTE(_D5), Q__NOTE(_C5), Q__NOTE(_C5), Q__NOTE(_A4), H__NOTE(_C5), Q__NOTE(_C5), \
+ W__NOTE(_C5), Q__NOTE(_F4), Q__NOTE(_C5), Q__NOTE(_D5), Q__NOTE(_E5), H__NOTE(_D5), \
+ H__NOTE(_C5), Q__NOTE(_C5), H__NOTE(_G5), Q__NOTE(_C5), HD_NOTE(_D5), \
+ HD_NOTE(_G4), Q__NOTE(_C5), Q__NOTE(_D5), BD_NOTE(_C5),
+
+#define CAMPANELLA \
+ Q__NOTE(_DS4), E__NOTE(_DS4), E__NOTE(_DS5), Q__NOTE(_DS5), E__NOTE(_DS5), E__NOTE(_DS6), Q__NOTE(_DS5), E__NOTE(_DS5), \
+ E__NOTE(_DS6), Q__NOTE(_CS5), E__NOTE(_CS5), E__NOTE(_DS6), Q__NOTE(_B4), E__NOTE(_B4), E__NOTE(_DS6), \
+ Q__NOTE(_B4), E__NOTE(_B4), E__NOTE(_DS6), Q__NOTE(_AS4), E__NOTE(_AS4), E__NOTE(_DS6), Q__NOTE(_GS4), \
+ E__NOTE(_GS4), E__NOTE(_DS6), Q__NOTE(_G4), E__NOTE(_G4), E__NOTE(_DS6), Q__NOTE(_GS4), E__NOTE(_GS4), \
+ E__NOTE(_DS6), Q__NOTE(_AS4), E__NOTE(_AS4), E__NOTE(_DS6), Q__NOTE(_DS4), E__NOTE(_DS4), E__NOTE(_DS6), \
+ Q__NOTE(_DS5), E__NOTE(_DS5), E__NOTE(_DS6), Q__NOTE(_E5), E__NOTE(_E5), E__NOTE(_DS6), Q__NOTE(_DS5), \
+ E__NOTE(_DS5), E__NOTE(_DS6), Q__NOTE(_CS5), E__NOTE(_CS5), E__NOTE(_DS6), Q__NOTE(_B4), E__NOTE(_B4), \
+ E__NOTE(_DS6), Q__NOTE(_B4), E__NOTE(_B4), E__NOTE(_DS6), Q__NOTE(_AS4), E__NOTE(_AS4), E__NOTE(_DS6), \
+ Q__NOTE(_GS4), E__NOTE(_GS4), E__NOTE(_DS6), Q__NOTE(_G4), E__NOTE(_G4), E__NOTE(_DS6), Q__NOTE(_GS4), \
+ E__NOTE(_GS4), E__NOTE(_DS6), Q__NOTE(_AS4), E__NOTE(_AS4), E__NOTE(_DS6), Q__NOTE(_DS4), E__NOTE(_DS4), \
+ E__NOTE(_DS5), Q__NOTE(_DS5), E__NOTE(_DS5), E__NOTE(_DS6), Q__NOTE(_DS6), E__NOTE(_DS6), E__NOTE(_DS7), \
+ Q__NOTE(_DS6), E__NOTE(_DS6), E__NOTE(_DS7), Q__NOTE(_CS6), E__NOTE(_CS6), E__NOTE(_DS7), Q__NOTE(_B5), \
+ E__NOTE(_B5), E__NOTE(_DS7), Q__NOTE(_B5), E__NOTE(_B5), E__NOTE(_DS7), Q__NOTE(_AS5), E__NOTE(_AS5), \
+ E__NOTE(_DS7), Q__NOTE(_GS5), E__NOTE(_GS5), E__NOTE(_DS7), Q__NOTE(_G5), E__NOTE(_G5), E__NOTE(_DS7), \
+ Q__NOTE(_GS5), E__NOTE(_GS5), E__NOTE(_DS7), Q__NOTE(_AS5), E__NOTE(_AS5), E__NOTE(_DS7), Q__NOTE(_DS5), \
+ E__NOTE(_DS5), E__NOTE(_DS7), W__NOTE(_DS6), W__NOTE(_GS5),
+
+#define MEGALOVANIA \
+ Q__NOTE(_D4), Q__NOTE(_D4), H__NOTE(_D5), HD_NOTE(_A4), H__NOTE(_AF4), H__NOTE(_G4), H__NOTE(_F4), \
+ Q__NOTE(_D4), Q__NOTE(_F4), Q__NOTE(_G4), Q__NOTE(_C4), Q__NOTE(_C4), H__NOTE(_D5), HD_NOTE(_A4), \
+ H__NOTE(_AF4), H__NOTE(_G4), H__NOTE(_F4), Q__NOTE(_D4), Q__NOTE(_F4), Q__NOTE(_G4), \
+ Q__NOTE(_B3), Q__NOTE(_B3), H__NOTE(_D5), HD_NOTE(_A4), H__NOTE(_AF4), H__NOTE(_G4), H__NOTE(_F4), \
+ Q__NOTE(_D4), Q__NOTE(_F4), Q__NOTE(_G4), Q__NOTE(_BF3), Q__NOTE(_BF3), H__NOTE(_D5), \
+ HD_NOTE(_A4), H__NOTE(_AF4), H__NOTE(_G4), H__NOTE(_F4), Q__NOTE(_D4), Q__NOTE(_F4), \
+ Q__NOTE(_G4),
+
+#define MICHISHIRUBE \
+ W__NOTE(_A5), H__NOTE(_A5), H__NOTE(_A5), W__NOTE(_B5), H__NOTE(_A5), H__NOTE(_B5), BD_NOTE(_CS6), W__NOTE(_E6), \
+ W__NOTE(_CS6), WD_NOTE(_B5), H__NOTE(_A5), BD_NOTE(_A5), W__NOTE(_A5), H__NOTE(_A5), H__NOTE(_A5), \
+ W__NOTE(_B5), H__NOTE(_A5), H__NOTE(_B5), W__NOTE(_A5), W__NOTE(_A6), W__NOTE(_GS6), H__NOTE(_CS6), \
+ Q__NOTE(_E6), Q__NOTE(_CS6), W__NOTE(_B5), H__NOTE(_B5), H__NOTE(_CS6), W__NOTE(_B5), H__NOTE(_A5), \
+ Q__NOTE(_B5), BD_NOTE(_A5), \
+ H__NOTE(_E6), H__NOTE(_FS6), H__NOTE(_E6), H__NOTE(_B6), \
+ W__NOTE(_A6), H__NOTE(_E6), H__NOTE(_B6), W__NOTE(_A6), H__NOTE(_A6), H__NOTE(_B6), \
+ B__NOTE(_CS7), H__NOTE(_E6), H__NOTE(_FS6), H__NOTE(_E6), H__NOTE(_B6), W__NOTE(_A6), H__NOTE(_E6), \
+ H__NOTE(_B6), W__NOTE(_A6), H__NOTE(_A6), H__NOTE(_GS6), B__NOTE(_E6), H__NOTE(_E6), \
+ H__NOTE(_FS6), H__NOTE(_E6), H__NOTE(_B6), W__NOTE(_A6), H__NOTE(_E6), H__NOTE(_B6), \
+ W__NOTE(_A6), H__NOTE(_A6), H__NOTE(_B6), H__NOTE(_CS7), B__NOTE(_CS7), H__NOTE(_E6), H__NOTE(_E6), \
+ H__NOTE(_E6), H__NOTE(_E6), H__NOTE(_D6), H__NOTE(_D6), H__NOTE(_CS6), H__NOTE(_CS6), Q__NOTE(_B5), \
+ BD_NOTE(_B5), W__NOTE(_A5), H__NOTE(_A5), H__NOTE(_A5), W__NOTE(_B5), H__NOTE(_A5), H__NOTE(_B5), \
+ BD_NOTE(_CS6), W__NOTE(_E6), W__NOTE(_CS6), WD_NOTE(_B5), H__NOTE(_A5), BD_NOTE(_A5), W__NOTE(_A5), \
+ H__NOTE(_A5), H__NOTE(_A5), W__NOTE(_B5), H__NOTE(_A5), H__NOTE(_B5), W__NOTE(_A5), W__NOTE(_A6), \
+ W__NOTE(_GS6), H__NOTE(_CS6), Q__NOTE(_E6), Q__NOTE(_CS6), W__NOTE(_B5), H__NOTE(_B5), H__NOTE(_CS6), \
+ W__NOTE(_B5), H__NOTE(_A5), Q__NOTE(_B5), BD_NOTE(_A5),
+
+#define LIEBESLEID \
+ Q__NOTE(_E4), Q__NOTE(_DS4), Q__NOTE(_E4), Q__NOTE(_F4), Q__NOTE(_E4), Q__NOTE(_FS4), Q__NOTE(_EF4), Q__NOTE(_G4), Q__NOTE(_D4), \
+ Q__NOTE(_GS4), Q__NOTE(_CS4), W__NOTE(_A4), H__NOTE(_E5), H__NOTE(_E5), HD_NOTE(_G4), Q__NOTE(_E5), E__NOTE(_E5), \
+ E__NOTE(_F5), ED_NOTE(_E5), HD_NOTE(_D5), Q__NOTE(_E5), H__NOTE(_F5), H__NOTE(_CS5), H__NOTE(_C5), W__NOTE(_G4), \
+ H__NOTE(_D5), H__NOTE(_D5), HD_NOTE(_D5), Q__NOTE(_D5), E__NOTE(_D5), E__NOTE(_E5), E__NOTE(_D5), HD_NOTE(_C5), \
+ Q__NOTE(_D5), H__NOTE(_E5), H__NOTE(_B4), H__NOTE(_BF4), W__NOTE(_F4), H__NOTE(_C5), H__NOTE(_C5), HD_NOTE(_EF4), \
+ Q__NOTE(_C5), E__NOTE(_C5), E__NOTE(_D5), E__NOTE(_C5), HD_NOTE(_BF4), Q__NOTE(_C5), H__NOTE(_D5), H__NOTE(_FS4), \
+ H__NOTE(_F4), HD_NOTE(_E4), Q__NOTE(_A4), HD_NOTE(_FS4), Q__NOTE(_A4), HD_NOTE(_GS4), Q__NOTE(_B4), Q__NOTE(_A4), \
+ Q__NOTE(_E4), Q__NOTE(_DS4), Q__NOTE(_E4), Q__NOTE(_F4), Q__NOTE(_D4), Q__NOTE(_FS4), Q__NOTE(_CS4), Q__NOTE(_G4), \
+ Q__NOTE(_C4), Q__NOTE(_GS4), Q__NOTE(_D4), WD_NOTE(_A4),
+
+#define MELODIES_OF_LIFE \
+ H__NOTE(_B5), W__NOTE(_GS6), H__NOTE(_GS6), H__NOTE(_FS6), W__NOTE(_E6), H__NOTE(_E6), H__NOTE(_DS6), H__NOTE(_CS6), H__NOTE(_DS6), \
+ H__NOTE(_E6), H__NOTE(_FS6), WD_NOTE(_B5), H__NOTE(_B5), H__NOTE(_CS6), H__NOTE(_DS6), H__NOTE(_E6), H__NOTE(_CS6), \
+ H__NOTE(_CS6), H__NOTE(_B5), H__NOTE(_E6), H__NOTE(_GS6), H__NOTE(_A6), H__NOTE(_GS6), H__NOTE(_E6), H__NOTE(_GS6), \
+ WD_NOTE(_FS6), H__NOTE(_GS6), WD_NOTE(_B6), H__NOTE(_CS7), H__NOTE(_B6), H__NOTE(_A6), H__NOTE(_A6), H__NOTE(_GS6), \
+ H__NOTE(_GS6), H__NOTE(_FS6), H__NOTE(_FS6), H__NOTE(_GS6), WD_NOTE(_A6), Q__NOTE(_GS6), Q__NOTE(_FS6), Q__NOTE(_FS6), \
+ Q__NOTE(_E6), W__NOTE(_E6), Q__NOTE(_B5), Q__NOTE(_CS6), WD_NOTE(_E6), Q__NOTE(_E6), Q__NOTE(_FS6), W__NOTE(_GS6), \
+ H__NOTE(_A6), B__NOTE(_FS6),
+
+#define EYES_ON_ME \
+ Q__NOTE(_A6), Q__NOTE(_G6), Q__NOTE(_FS6), Q__NOTE(_D6), Q__NOTE(_A5), Q__NOTE(_G5), Q__NOTE(_FS5), Q__NOTE(_D5), \
+ W__NOTE(_A4), W__NOTE(_D5), W__NOTE(_E5), W__NOTE(_FS5), H__NOTE(_A5), M__NOTE(_FS5, 256), H__NOTE(_E5), \
+ H__NOTE(_FS5), B__NOTE(_D5), H__NOTE(_B4), H__NOTE(_D5), BD_NOTE(_E5), H__NOTE(_A4), W__NOTE(_D5), W__NOTE(_E5), \
+ W__NOTE(_FS5), H__NOTE(_A5), BD_NOTE(_CS6), W__NOTE(_A5), H__NOTE(_CS6), H__NOTE(_D6), WD_NOTE(_B5), \
+ H__NOTE(_A5), H__NOTE(_B5), B__NOTE(_A5), WD_NOTE(_B4), W__NOTE(_CS5), WD_NOTE(_D6), H__NOTE(_D6), \
+ W__NOTE(_CS6), H__NOTE(_B5), H__NOTE(_B5), H__NOTE(_B5), B__NOTE(_A5), H__NOTE(_A5), H__NOTE(_FS5), H__NOTE(_A5), \
+ WD_NOTE(_B5), H__NOTE(_B5), H__NOTE(_A5), H__NOTE(_G5), H__NOTE(_D5), W__NOTE(_FS5), WD_NOTE(_E5), \
+ H__NOTE(_CS4), H__NOTE(_E4), H__NOTE(_A4), H__NOTE(_CS5), W__NOTE(_D5), W__NOTE(_E5), W__NOTE(_FS5), H__NOTE(_G5), \
+ H__NOTE(_A5), B__NOTE(_A5), H__NOTE(_A5), H__NOTE(_G5), H__NOTE(_D5), BD_NOTE(_FS5), W__NOTE(_E5), B__NOTE(_D5), \
+ H__NOTE(_G4), H__NOTE(_FS4), W__NOTE(_E4), BD_NOTE(_D4),
+
+#define SONG_OF_THE_ANCIENTS \
+ H__NOTE(_D6), H__NOTE(_EF6), B__NOTE(_EF6), H__NOTE(_EF6), H__NOTE(_D6), H__NOTE(_BF5), H__NOTE(_G5), BD_NOTE(_C6), H__NOTE(_D6), \
+ H__NOTE(_EF6), B__NOTE(_EF6), H__NOTE(_EF6), H__NOTE(_D6), H__NOTE(_BF5), H__NOTE(_G5), BD_NOTE(_G6), H__NOTE(_G5), \
+ H__NOTE(_AF5), B__NOTE(_G6), H__NOTE(_AF6), H__NOTE(_G6), H__NOTE(_F6), H__NOTE(_D6), H__NOTE(_D6), H__NOTE(_EF6), \
+ B__NOTE(_EF6), WD_NOTE(_G5), WD_NOTE(_BF5), H__NOTE(_D6), H__NOTE(_EF6), B__NOTE(_EF6), H__NOTE(_EF6), H__NOTE(_D6), \
+ H__NOTE(_BF5), H__NOTE(_G5), BD_NOTE(_C6), WD_NOTE(_B5), WD_NOTE(_G5), WD_NOTE(_G6), W__NOTE(_G6), H__NOTE(_AF6), \
+ W__NOTE(_G6), H__NOTE(_AF6), H__NOTE(_G6), H__NOTE(_F6), H__NOTE(_D6), H__NOTE(_D6), H__NOTE(_EF6), B__NOTE(_EF6), \
+ WD_NOTE(_E6), H__NOTE(_E6), H__NOTE(_F6), H__NOTE(_G6), H__NOTE(_BF6), H__NOTE(_AF6), W__NOTE(_AF6), H__NOTE(_C6), \
+ H__NOTE(_BF6), H__NOTE(_AF6), W__NOTE(_AF6), H__NOTE(_C6), H__NOTE(_AF6), BD_NOTE(_G6), WD_NOTE(_B5), WD_NOTE(_G6), \
+ W__NOTE(_G6), H__NOTE(_AF6), W__NOTE(_G6), H__NOTE(_AF6), H__NOTE(_G6), H__NOTE(_F6), H__NOTE(_D6), H__NOTE(_D6), \
+ H__NOTE(_EF6), B__NOTE(_EF6), WD_NOTE(_E6), H__NOTE(_E6), H__NOTE(_F6), H__NOTE(_G6), H__NOTE(_BF6), H__NOTE(_AF6), \
+ W__NOTE(_AF6), H__NOTE(_C6), H__NOTE(_AF6), H__NOTE(_G6), W__NOTE(_G6), H__NOTE(_F6), H__NOTE(_D6), BD_NOTE(_EF6), \
+ WD_NOTE(_F6), WD_NOTE(_G6), BD_NOTE(_C7),
+
+#define NIER_AMUSEMENT_PARK \
+ H__NOTE(_D5), E__NOTE(_G6), E__NOTE(_GF6), Q__NOTE(_F6), Q__NOTE(_E6), Q__NOTE(_EF6), Q__NOTE(_DF6), Q__NOTE(_EF6), WD_NOTE(_D6), \
+ Q__NOTE(_G5), Q__NOTE(_A5), H__NOTE(_BF5), H__NOTE(_D6), H__NOTE(_G6), H__NOTE(_A6), W__NOTE(_BF6), W__NOTE(_EF7), \
+ H__NOTE(_D5), E__NOTE(_G6), E__NOTE(_GF6), Q__NOTE(_F6), Q__NOTE(_E6), Q__NOTE(_EF6), Q__NOTE(_DF6), Q__NOTE(_EF6), \
+ WD_NOTE(_D6), Q__NOTE(_G5), Q__NOTE(_A5), H__NOTE(_BF5), H__NOTE(_D6), H__NOTE(_G6), H__NOTE(_A6), W__NOTE(_BF6), \
+ H__NOTE(_EF7), H__NOTE(_D5), HD_NOTE(_A5), HD_NOTE(_BF5), B__NOTE(_D5), H__NOTE(_D5), HD_NOTE(_G5), HD_NOTE(_F5), \
+ H__NOTE(_EF5), WD_NOTE(_D5), H__NOTE(_D5), HD_NOTE(_A5), HD_NOTE(_BF5), WD_NOTE(_D5), W__NOTE(_D5), B__NOTE(_G5), \
+ H__NOTE(_D5), HD_NOTE(_A5), HD_NOTE(_BF5), B__NOTE(_D5), H__NOTE(_D5), HD_NOTE(_G5), HD_NOTE(_F5), H__NOTE(_EF5), \
+ W__NOTE(_D5), W__NOTE(_C5), W__NOTE(_BF4), W__NOTE(_C5), W__NOTE(_D5), W__NOTE(_G5), B__NOTE(_D5), B__NOTE(_E5), \
+ W__NOTE(_EF5), QD_NOTE(_C5), QD_NOTE(_D5), Q__NOTE(_EF5), H__NOTE(_G5), H__NOTE(_F5), H__NOTE(_EF5), H__NOTE(_F5), \
+ B__NOTE(_D5), B__NOTE(_BF4), W__NOTE(_EF5), QD_NOTE(_C5), QD_NOTE(_D5), Q__NOTE(_EF5), H__NOTE(_G5), H__NOTE(_F5), \
+ H__NOTE(_EF5), H__NOTE(_F5), W__NOTE(_D5), W__NOTE(_BF5), W__NOTE(_G5), W__NOTE(_D5), W__NOTE(_EF5), QD_NOTE(_C5), \
+ QD_NOTE(_D5), Q__NOTE(_EF5), H__NOTE(_G5), H__NOTE(_F5), H__NOTE(_EF5), H__NOTE(_F5), B__NOTE(_D5), B__NOTE(_BF4), \
+ B__NOTE(_C5), H__NOTE(_C5), H__NOTE(_D5), H__NOTE(_EF5), H__NOTE(_F5), WD_NOTE(_G5), H__NOTE(_C5), W__NOTE(_AF5), \
+ WD_NOTE(_G5),
+
+#define COPIED_CITY \
+ Q__NOTE(_F6), Q__NOTE(_BF5), Q__NOTE(_EF6), Q__NOTE(_G5), Q__NOTE(_AF5), Q__NOTE(_G6), Q__NOTE(_AF6), Q__NOTE(_EF6), Q__NOTE(_BF5), \
+ Q__NOTE(_F6), Q__NOTE(_G5), Q__NOTE(_AF5), Q__NOTE(_EF6), Q__NOTE(_G5), Q__NOTE(_F5), Q__NOTE(_D6), Q__NOTE(_C6), \
+ Q__NOTE(_G5), Q__NOTE(_BF5), Q__NOTE(_EF5), Q__NOTE(_AF5), Q__NOTE(_G5), Q__NOTE(_EF5), Q__NOTE(_BF4), H__NOTE(_C5), \
+ Q__NOTE(_F5), Q__NOTE(_G5), Q__NOTE(_AF5), Q__NOTE(_EF6), Q__NOTE(_BF5), Q__NOTE(_G6), Q__NOTE(_EF6), Q__NOTE(_BF6), \
+ Q__NOTE(_AF6), Q__NOTE(_EF6), Q__NOTE(_BF5), Q__NOTE(_F6), Q__NOTE(_G5), Q__NOTE(_F5), Q__NOTE(_EF6), Q__NOTE(_BF5), \
+ Q__NOTE(_B6), Q__NOTE(_DF6), Q__NOTE(_EF6), Q__NOTE(_F6), Q__NOTE(_AF6), Q__NOTE(_EF7), Q__NOTE(_F6), Q__NOTE(_C6), \
+ Q__NOTE(_G5), Q__NOTE(_AF5), Q__NOTE(_BF5), Q__NOTE(_C6), Q__NOTE(_EF6), Q__NOTE(_G5), Q__NOTE(_EF5), Q__NOTE(_F5), \
+ Q__NOTE(_G5), Q__NOTE(_EF5), Q__NOTE(_F5), Q__NOTE(_C5), Q__NOTE(_EF5), Q__NOTE(_C5), Q__NOTE(_BF4), Q__NOTE(_G4), \
+ Q__NOTE(_F4), Q__NOTE(_G4), H__NOTE(_AF4), Q__NOTE(_C5), Q__NOTE(_EF5), Q__NOTE(_F5), Q__NOTE(_C5), Q__NOTE(_EF5), \
+ Q__NOTE(_F5), Q__NOTE(_G5), Q__NOTE(_BF5), Q__NOTE(_AF5), Q__NOTE(_G5), Q__NOTE(_EF5), Q__NOTE(_F5), Q__NOTE(_C5), \
+ Q__NOTE(_AF4), Q__NOTE(_F5), Q__NOTE(_G5), Q__NOTE(_AF5), Q__NOTE(_G5), Q__NOTE(_F5), Q__NOTE(_EF5), Q__NOTE(_F5), \
+ Q__NOTE(_G5), Q__NOTE(_BF5), Q__NOTE(_C6), Q__NOTE(_G6), Q__NOTE(_EF6), WD_NOTE(_F7),
+
+#define VAGUE_HOPE_COLD_RAIN \
+ HD_NOTE(_D6), HD_NOTE(_E6), HD_NOTE(_CS6), HD_NOTE(_D6), HD_NOTE(_B5), Q__NOTE(_B5), Q__NOTE(_CS6), Q__NOTE(_D6), WD_NOTE(_A6), \
+ HD_NOTE(_FS6), HD_NOTE(_G6), HD_NOTE(_D6), HD_NOTE(_E6), HD_NOTE(_FS6), Q__NOTE(_D5), Q__NOTE(_CS5), Q__NOTE(_A4), \
+ W__NOTE(_FS4), H__NOTE(_D6), HD_NOTE(_E6), HD_NOTE(_FS6), HD_NOTE(_CS6), HD_NOTE(_E6), HD_NOTE(_D6), Q__NOTE(_CS6), \
+ Q__NOTE(_D6), Q__NOTE(_E6), W__NOTE(_FS6), H__NOTE(_CS6), WD_NOTE(_D6), HD_NOTE(_D6), Q__NOTE(_D6), H__NOTE(_E6), \
+ WD_NOTE(_CS6), HD_NOTE(_AS5), HD_NOTE(_B5), HD_NOTE(_B5), Q__NOTE(_B4), Q__NOTE(_CS5), Q__NOTE(_D5), HD_NOTE(_A5), \
+ Q__NOTE(_B5), Q__NOTE(_CS6), Q__NOTE(_A6), HD_NOTE(_FS6), Q__NOTE(_D5), Q__NOTE(_CS5), Q__NOTE(_A4), H__NOTE(_FS4), \
+ HD_NOTE(_FS6), HD_NOTE(_D6), HD_NOTE(_E6), HD_NOTE(_A6), HD_NOTE(_FS6), Q__NOTE(_CS5), Q__NOTE(_D5), Q__NOTE(_A5), \
+ HD_NOTE(_FS5), Q__NOTE(_FS6), Q__NOTE(_FS6), Q__NOTE(_GS6), HD_NOTE(_A6), Q__NOTE(_B6), H__NOTE(_A6), H__NOTE(_GS6), \
+ H__NOTE(_FS6), H__NOTE(_E6), H__NOTE(_CS6), H__NOTE(_FS6), E__NOTE(_FS5), E__NOTE(_CS5), Q__NOTE(_B4), H__NOTE(_AS4), \
+ W__NOTE(_FS5), HD_NOTE(_FS6), HD_NOTE(_B5), H__NOTE(_D6), H__NOTE(_CS6), H__NOTE(_E6), HD_NOTE(_A6), HD_NOTE(_E6), \
+ W__NOTE(_D6), Q__NOTE(_CS6), Q__NOTE(_D6), HD_NOTE(_E6), HD_NOTE(_FS6), WD_NOTE(_B6), HD_NOTE(_E6), HD_NOTE(_FS6), \
+ HD_NOTE(_B5), Q__NOTE(_B5), Q__NOTE(_B5), Q__NOTE(_CS6), H__NOTE(_D6), H__NOTE(_E6), H__NOTE(_FS6), HD_NOTE(_E6), \
+ HD_NOTE(_CS6), H__NOTE(_FS6), H__NOTE(_A6), H__NOTE(_B6), W__NOTE(_A6), H__NOTE(_FS6), BD_NOTE(_B6),
+
+#define KAINE_SALVATION \
+ BD_NOTE(_D5), W__NOTE(_BF4), W__NOTE(_C5), W__NOTE(_F5), BD_NOTE(_D5), BD_NOTE(_BF4), BD_NOTE(_C5), W__NOTE(_BF4), W__NOTE(_C5), \
+ W__NOTE(_D5), BD_NOTE(_C5), BD_NOTE(_F4), BD_NOTE(_D5), W__NOTE(_BF4), W__NOTE(_C5), W__NOTE(_F5), BD_NOTE(_D5), \
+ BD_NOTE(_BF4), WD_NOTE(_EF5), WD_NOTE(_BF4), W__NOTE(_A4), W__NOTE(_BF4), W__NOTE(_C5), B__NOTE(_C5), H__NOTE(_B4), \
+ H__NOTE(_C5), BD_NOTE(_D5), WD_NOTE(_G5), W__NOTE(_G5), H__NOTE(_FS5), H__NOTE(_G5), H__NOTE(_A5), H__NOTE(_B5), \
+ H__NOTE(_A5), H__NOTE(_G5), H__NOTE(_FS5), WD_NOTE(_G5), W__NOTE(_G5), H__NOTE(_D6), H__NOTE(_C6), H__NOTE(_B5), \
+ H__NOTE(_A5), WD_NOTE(_G5), WD_NOTE(_G5), W__NOTE(_G5), H__NOTE(_FS5), H__NOTE(_G5), H__NOTE(_A5), H__NOTE(_B5), \
+ H__NOTE(_A5), H__NOTE(_G5), H__NOTE(_FS5), W__NOTE(_G5), H__NOTE(_B5), H__NOTE(_A5), H__NOTE(_G5), H__NOTE(_FS5), \
+ BD_NOTE(_E5), WD_NOTE(_G5), W__NOTE(_G5), H__NOTE(_FS5), H__NOTE(_G5), H__NOTE(_A5), H__NOTE(_B5), H__NOTE(_A5), \
+ H__NOTE(_G5), H__NOTE(_FS5), WD_NOTE(_G5), W__NOTE(_G5), H__NOTE(_D6), H__NOTE(_C6), H__NOTE(_B5), H__NOTE(_A5), \
+ WD_NOTE(_G5), WD_NOTE(_G5), W__NOTE(_G5), H__NOTE(_FS5), H__NOTE(_G5), H__NOTE(_A5), H__NOTE(_B5), H__NOTE(_A5), \
+ H__NOTE(_G5), H__NOTE(_FS5), W__NOTE(_G5), H__NOTE(_D6), WD_NOTE(_D6), W__NOTE(_F5), H__NOTE(_C6), H__NOTE(_C6), \
+ H__NOTE(_BF5), H__NOTE(_A5), WD_NOTE(_G5), WD_NOTE(_F5), WD_NOTE(_G5), WD_NOTE(_A5), BD_NOTE(_G5),
+
+#define WEIGHT_OF_THE_WORLD \
+ H__NOTE(_B5), Q__NOTE(_C6), Q__NOTE(_C6), Q__NOTE(_B5), H__NOTE(_C6), H__NOTE(_G6), WD_NOTE(_G6), H__NOTE(_B5), Q__NOTE(_C6), \
+ Q__NOTE(_C6), Q__NOTE(_B5), H__NOTE(_C6), H__NOTE(_G6), H__NOTE(_G6), Q__NOTE(_A6), W__NOTE(_G6), Q__NOTE(_C6), \
+ Q__NOTE(_D6), H__NOTE(_E6), Q__NOTE(_F6), H__NOTE(_E6), H__NOTE(_F6), HD_NOTE(_E6), H__NOTE(_D6), H__NOTE(_C6), \
+ H__NOTE(_D6), WD_NOTE(_D6), Q__NOTE(_C6), Q__NOTE(_B5), WD_NOTE(_B5), H__NOTE(_B5), Q__NOTE(_C6), Q__NOTE(_C6), \
+ Q__NOTE(_B5), H__NOTE(_C6), H__NOTE(_G6), WD_NOTE(_G6), H__NOTE(_B5), Q__NOTE(_C6), Q__NOTE(_C6), Q__NOTE(_B5), \
+ H__NOTE(_C6), H__NOTE(_G6), H__NOTE(_G6), Q__NOTE(_A6), W__NOTE(_G6), Q__NOTE(_C6), Q__NOTE(_D6), H__NOTE(_E6), \
+ Q__NOTE(_F6), H__NOTE(_E6), H__NOTE(_F6), HD_NOTE(_E6), H__NOTE(_D6), H__NOTE(_C6), H__NOTE(_D6), BD_NOTE(_D6), \
+ Q__NOTE(_E6), Q__NOTE(_D6), Q__NOTE(_C6), Q__NOTE(_B5), H__NOTE(_C6), Q__NOTE(_C6), H__NOTE(_C6), HD_NOTE(_C6), \
+ H__NOTE(_B5), H__NOTE(_C6), H__NOTE(_E6), H__NOTE(_G6), WD_NOTE(_G6), Q__NOTE(_C6), B__NOTE(_C6), H__NOTE(_B6), \
+ Q__NOTE(_C7), BD_NOTE(_C7),
+
+#define ISABELLAS_LULLABY \
+ W__NOTE(_BF4), B__NOTE(_D5), W__NOTE(_EF5), B__NOTE(_F5), W__NOTE(_BF5), B__NOTE(_AF5), W__NOTE(_GF5), BD_NOTE(_F5), B__NOTE(_CS5), \
+ W__NOTE(_F5), B__NOTE(_C5), W__NOTE(_EF5), BD_NOTE(_BF4), W__NOTE(_AF4), W__NOTE(_BF4), W__NOTE(_F5), W__NOTE(_GF5), \
+ WD_NOTE(_AF5), H__NOTE(_FS5), W__NOTE(_F5), B__NOTE(_EF5), W__NOTE(_C6), B__NOTE(_AF5), W__NOTE(_F5), WD_NOTE(_AF5), \
+ H__NOTE(_BF5), W__NOTE(_F5), WD_NOTE(_AF5), H__NOTE(_BF5), W__NOTE(_F5), W__NOTE(_EF5), W__NOTE(_BF4), W__NOTE(_AF5), \
+ WD_NOTE(_F5), H__NOTE(_F5), H__NOTE(_BF5), H__NOTE(_C6), WD_NOTE(_CS6), H__NOTE(_C6), W__NOTE(_BF5), W__NOTE(_AF5), \
+ W__NOTE(_F5), W__NOTE(_EF5), WD_NOTE(_EF5), H__NOTE(_DF5), W__NOTE(_AF5), BD_NOTE(_F5), WD_NOTE(_BF4), H__NOTE(_C5), \
+ W__NOTE(_CS5), W__NOTE(_EF5), W__NOTE(_AF4), W__NOTE(_EF5), WD_NOTE(_GF5), H__NOTE(_F5), W__NOTE(_EF5), WD_NOTE(_F5), \
+ H__NOTE(_F5), H__NOTE(_BF5), H__NOTE(_C6), WD_NOTE(_CS6), H__NOTE(_C6), W__NOTE(_CS6), W__NOTE(_EF6), W__NOTE(_AF5), \
+ W__NOTE(_EF6), WD_NOTE(_GF6), H__NOTE(_F6), W__NOTE(_EF6), B__NOTE(_DF6), H__NOTE(_GF6), H__NOTE(_AF6), BD_NOTE(_DF6), \
+ B__NOTE(_BF5), W__NOTE(_F6), BD_NOTE(_C6), W__NOTE(_AF5), WD_NOTE(_EF6), H__NOTE(_DF6), W__NOTE(_C6), B__NOTE(_BF5),
+
+#define FANTASIE_IMPROMPTU \
+ E__NOTE(_GS4), E__NOTE(_A4), E__NOTE(_GS4), E__NOTE(_REST), E__NOTE(_GS4), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_DS5), E__NOTE(_CS5), \
+ E__NOTE(_DS5), E__NOTE(_CS5), E__NOTE(_C5), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_GS5), E__NOTE(_GS4), E__NOTE(_A4), \
+ E__NOTE(_GS4), E__NOTE(_REST), E__NOTE(_GS4), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_DS5), E__NOTE(_CS5), E__NOTE(_DS5), \
+ E__NOTE(_CS5), E__NOTE(_C5), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_GS5), E__NOTE(_A4), E__NOTE(_CS5), E__NOTE(_DS5), \
+ E__NOTE(_FS5), E__NOTE(_A5), E__NOTE(_CS6), E__NOTE(_DS6), E__NOTE(_B6), E__NOTE(_A6), E__NOTE(_GS6), E__NOTE(_FS6), \
+ E__NOTE(_E6), E__NOTE(_DS6), E__NOTE(_FS6), E__NOTE(_CS6), E__NOTE(_C5), E__NOTE(_DS6), E__NOTE(_A5), E__NOTE(_GS5), \
+ E__NOTE(_FS5), E__NOTE(_A5), E__NOTE(_E5), E__NOTE(_DS5), E__NOTE(_FS5), E__NOTE(_CS5), E__NOTE(_C5), E__NOTE(_DS5), \
+ E__NOTE(_A4), E__NOTE(_GS4), E__NOTE(_B4), E__NOTE(_A4), E__NOTE(_A4), E__NOTE(_GS4), E__NOTE(_A4), E__NOTE(_GS4), \
+ E__NOTE(_REST), E__NOTE(_GS4), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_DS5), E__NOTE(_CS5), E__NOTE(_DS5), E__NOTE(_CS5), \
+ E__NOTE(_C5), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_GS5), E__NOTE(_GS4), E__NOTE(_AS4), E__NOTE(_GS4), E__NOTE(_REST), \
+ E__NOTE(_GS4), E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_DS5), E__NOTE(_CS5), E__NOTE(_DS5), E__NOTE(_CS5), E__NOTE(_C5), \
+ E__NOTE(_CS5), E__NOTE(_E5), E__NOTE(_GS5), E__NOTE(_DS5), E__NOTE(_E5), E__NOTE(_DS5), E__NOTE(_REST), E__NOTE(_DS5), \
+ E__NOTE(_B5), E__NOTE(_AS5), E__NOTE(_GS5), E__NOTE(_REST), E__NOTE(_E6), E__NOTE(_DS6), E__NOTE(_CS6), E__NOTE(_B5), \
+ E__NOTE(_AS5), E__NOTE(_GS5), E__NOTE(_REST), E__NOTE(_AS5), WD_NOTE(_GS5),
+
+#define TERRAS_THEME \
+ Q__NOTE(_GS5), Q__NOTE(_AS5), Q__NOTE(_B5), Q__NOTE(_EF6), BD_NOTE(_B5), Q__NOTE(_AS5), Q__NOTE(_GS5), W__NOTE(_AS5), \
+ BD_NOTE(_DS5), Q__NOTE(_AF5), Q__NOTE(_BF5), Q__NOTE(_B5), Q__NOTE(_DS6), BD_NOTE(_B5), \
+ Q__NOTE(_BF5), Q__NOTE(_AF5), W__NOTE(_AS5), BD_NOTE(_DS6), Q__NOTE(_B5), Q__NOTE(_CS6), Q__NOTE(_DS6), \
+ Q__NOTE(_FS6), BD_NOTE(_DS6), Q__NOTE(_CS6), Q__NOTE(_B5), W__NOTE(_CS6), BD_NOTE(_FS5), \
+ Q__NOTE(_B5), Q__NOTE(_AS5), BD_NOTE(_GS5), Q__NOTE(_B5), Q__NOTE(_AS5), BD_NOTE(_GS5),
+
+#define RENAI_CIRCULATION \
+ Q__NOTE(_E6), Q__NOTE(_B5), HD_NOTE(_CS6), HD_NOTE(_CS6), H__NOTE(_B5), HD_NOTE(_E6), HD_NOTE(_E6), Q__NOTE(_E6), Q__NOTE(_B5), \
+ HD_NOTE(_CS6), HD_NOTE(_CS6), H__NOTE(_B5), HD_NOTE(_E6), HD_NOTE(_GS6), Q__NOTE(_E6), Q__NOTE(_B5), HD_NOTE(_CS6), \
+ H__NOTE(_CS6), Q__NOTE(_CS6), H__NOTE(_B5), HD_NOTE(_E6), H__NOTE(_E6), Q__NOTE(_E6), H__NOTE(_FS6), HD_NOTE(_E6), \
+ H__NOTE(_E6), Q__NOTE(_E6), H__NOTE(_CS6), WD_NOTE(_GS6), HD_NOTE(_E6), H__NOTE(_E6), Q__NOTE(_FS6), H__NOTE(_G6), \
+ HD_NOTE(_GS6), HD_NOTE(_E6), Q__NOTE(_B5), Q__NOTE(_CS6), HD_NOTE(_E6), H__NOTE(_E6), Q__NOTE(_FS6), H__NOTE(_G6), \
+ HD_NOTE(_GS6), HD_NOTE(_E6), H__NOTE(_CS6), H__NOTE(_E6), Q__NOTE(_CS6), HD_NOTE(_E6), H__NOTE(_CS6), H__NOTE(_E6), \
+ Q__NOTE(_CS6), HD_NOTE(_E6), H__NOTE(_E6), Q__NOTE(_A6), H__NOTE(_GS6), HD_NOTE(_E6), H__NOTE(_FS6), WD_NOTE(_E6), \
+ H__NOTE(_GS6), H__NOTE(_A6), H__NOTE(_GS6), H__NOTE(_A6), W__NOTE(_B6), H__NOTE(_GS6), H__NOTE(_A6), H__NOTE(_GS6), \
+ H__NOTE(_A6), W__NOTE(_B6), H__NOTE(_B6), H__NOTE(_A6), H__NOTE(_GS6), H__NOTE(_A6), Q__NOTE(_GS6), H__NOTE(_E6), \
+ H__NOTE(_E6), Q__NOTE(_E6), H__NOTE(_CS6), Q__NOTE(_GS6), H__NOTE(_E6), H__NOTE(_E6), Q__NOTE(_E6), H__NOTE(_CS6), \
+ Q__NOTE(_E6), H__NOTE(_E6), H__NOTE(_E6), Q__NOTE(_E6), H__NOTE(_FS6), WD_NOTE(_E6), W__NOTE(_B6), W__NOTE(_GS6), \
+ W__NOTE(_FS6), H__NOTE(_GS6), H__NOTE(_GS6), H__NOTE(_FS6), H__NOTE(_E6), H__NOTE(_FS6), B__NOTE(_GS6), H__NOTE(_GS6), \
+ W__NOTE(_CS7), W__NOTE(_GS6), W__NOTE(_E6), H__NOTE(_GS6), H__NOTE(_GS6), HD_NOTE(_E6), H__NOTE(_E6), Q__NOTE(_E6), \
+ H__NOTE(_FS6), WD_NOTE(_E6),
+
+#define PLATINUM_DISCO \
+ H__NOTE(_DS6), H__NOTE(_FS6), H__NOTE(_GS6), H__NOTE(_AS6), H__NOTE(_DS6), H__NOTE(_FS6), W__NOTE(_GS6), H__NOTE(_DS6), H__NOTE(_FS6), \
+ H__NOTE(_GS6), H__NOTE(_AS6), H__NOTE(_CS6), H__NOTE(_FS6), WD_NOTE(_FS6), H__NOTE(_CS6), W__NOTE(_DS6), H__NOTE(_FS6), \
+ H__NOTE(_AS6), W__NOTE(_GS6), H__NOTE(_FS6), H__NOTE(_GS6), Q__NOTE(_AS6), Q__NOTE(_CS7), Q__NOTE(_GS6), Q__NOTE(_AS6), \
+ Q__NOTE(_FS6), Q__NOTE(_GS6), Q__NOTE(_DS6), Q__NOTE(_FS6), Q__NOTE(_CS6), Q__NOTE(_DS6), Q__NOTE(_AS5), Q__NOTE(_CS6), \
+ H__NOTE(_DS6), H__NOTE(_FS6), H__NOTE(_GS6), H__NOTE(_AS6), H__NOTE(_DS6), H__NOTE(_FS6), W__NOTE(_GS6), H__NOTE(_DS6), \
+ H__NOTE(_FS6), H__NOTE(_GS6), H__NOTE(_AS6), H__NOTE(_CS7), H__NOTE(_GS6), WD_NOTE(_FS6), H__NOTE(_CS6), W__NOTE(_DS6), \
+ H__NOTE(_FS6), H__NOTE(_AS6), WD_NOTE(_GS6), H__NOTE(_FS6), Q__NOTE(_FS6), Q__NOTE(_GS5), Q__NOTE(_AS5), Q__NOTE(_CS6), \
+ Q__NOTE(_FS6), Q__NOTE(_GS6), Q__NOTE(_AS6), Q__NOTE(_CS7), WD_NOTE(_FS7), H__NOTE(_CS6), WD_NOTE(_DS6), H__NOTE(_CS6), \
+ WD_NOTE(_DS6), H__NOTE(_CS6), H__NOTE(_DS6), H__NOTE(_FS6), H__NOTE(_GS6), H__NOTE(_AS6), WD_NOTE(_GS6), H__NOTE(_FS6), \
+ WD_NOTE(_GS6), H__NOTE(_FS6), WD_NOTE(_GS6), H__NOTE(_FS6), H__NOTE(_GS6), H__NOTE(_AS6), H__NOTE(_DS6), H__NOTE(_FS6), \
+ WD_NOTE(_FS6), H__NOTE(_CS6), WD_NOTE(_DS6), H__NOTE(_CS6), WD_NOTE(_DS6), H__NOTE(_CS6), H__NOTE(_DS6), H__NOTE(_FS6), \
+ H__NOTE(_GS6), H__NOTE(_AS6), H__NOTE(_CS7), H__NOTE(_AS6), H__NOTE(_GS6), H__NOTE(_FS6), H__NOTE(_DS6), W__NOTE(_FS6), \
+ H__NOTE(_CS6), H__NOTE(_DS6), W__NOTE(_FS6), H__NOTE(_FS6), H__NOTE(_GS6), H__NOTE(_FS6), H__NOTE(_GS6), H__NOTE(_FS6), \
+ B__NOTE(_FS6),
+
+#define NOCTURNE_OP_9_NO_1 \
+ H__NOTE(_BF5), H__NOTE(_C6), H__NOTE(_DF6), H__NOTE(_A5), H__NOTE(_BF5), H__NOTE(_GF5), W__NOTE(_F5), W__NOTE(_F5), W__NOTE(_F5), \
+ W__NOTE(_F5), H__NOTE(_GF5), H__NOTE(_F5), H__NOTE(_EF5), H__NOTE(_C5), B__NOTE(_DF5), W__NOTE(_BF4), Q__NOTE(_BF5), \
+ Q__NOTE(_C6), Q__NOTE(_DF6), Q__NOTE(_A5), Q__NOTE(_BF5), Q__NOTE(_A5), Q__NOTE(_GS5), Q__NOTE(_A5), Q__NOTE(_C6), \
+ Q__NOTE(_BF5), Q__NOTE(_GF5), Q__NOTE(_F5), Q__NOTE(_GF5), Q__NOTE(_E5), Q__NOTE(_F5), Q__NOTE(_BF5), Q__NOTE(_A5), \
+ Q__NOTE(_AF5), Q__NOTE(_G5), Q__NOTE(_GF5), Q__NOTE(_F5), Q__NOTE(_E5), Q__NOTE(_EF5), Q__NOTE(_D5), Q__NOTE(_DF5), \
+ Q__NOTE(_C5), Q__NOTE(_DF5), Q__NOTE(_C5), Q__NOTE(_B4), Q__NOTE(_C5), Q__NOTE(_F5), Q__NOTE(_E5), Q__NOTE(_EF5), \
+ B__NOTE(_DF5), W__NOTE(_BF4), W__NOTE(_BF5), W__NOTE(_BF5), W__NOTE(_BF5), BD_NOTE(_AF5), W__NOTE(_DF5), H__NOTE(_BF4), \
+ H__NOTE(_C5), H__NOTE(_DF5), H__NOTE(_GF5), H__NOTE(_GF5), BD_NOTE(_F5), W__NOTE(_EF5), H__NOTE(_F5), H__NOTE(_EF5), \
+ H__NOTE(_DF5), H__NOTE(_A4), B__NOTE(_AF4), W__NOTE(_DF5), W__NOTE(_EF5), H__NOTE(_F5), H__NOTE(_EF5), H__NOTE(_DF5), \
+ H__NOTE(_EF5), BD_NOTE(_F5),
+
#endif
diff --git a/quantum/color.c b/quantum/color.c
index 8ede053e7..c49877592 100644
--- a/quantum/color.c
+++ b/quantum/color.c
@@ -78,9 +78,11 @@ RGB hsv_to_rgb( HSV hsv )
break;
}
+#ifdef USE_CIE1931_CURVE
rgb.r = pgm_read_byte( &CIE1931_CURVE[rgb.r] );
rgb.g = pgm_read_byte( &CIE1931_CURVE[rgb.g] );
rgb.b = pgm_read_byte( &CIE1931_CURVE[rgb.b] );
+#endif
return rgb;
}
diff --git a/quantum/config_common.h b/quantum/config_common.h
index 0b2e408a4..c489e1407 100644
--- a/quantum/config_common.h
+++ b/quantum/config_common.h
@@ -59,6 +59,11 @@
#define PINC_ADDRESS 0x3
#define PINB_ADDRESS 0x6
#define PINA_ADDRESS 0x9
+ #elif defined(__AVR_ATmega328P__)
+ #define ADDRESS_BASE 0x00
+ #define PINB_ADDRESS 0x3
+ #define PINC_ADDRESS 0x6
+ #define PIND_ADDRESS 0x9
#else
#error "Pins are not defined"
#endif
diff --git a/quantum/debounce/eager_pr.c b/quantum/debounce/eager_pr.c
new file mode 100644
index 000000000..9eb9480a7
--- /dev/null
+++ b/quantum/debounce/eager_pr.c
@@ -0,0 +1,100 @@
+/*
+Copyright 2019 Alex Ong<the.onga@gmail.com>
+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 <http://www.gnu.org/licenses/>.
+*/
+
+/*
+Basic per-row algorithm. Uses an 8-bit counter per row.
+After pressing a key, it immediately changes state, and sets a counter.
+No further inputs are accepted until DEBOUNCE milliseconds have occurred.
+*/
+
+#include "matrix.h"
+#include "timer.h"
+#include "quantum.h"
+#include <stdlib.h>
+
+#ifndef DEBOUNCE
+ #define DEBOUNCE 5
+#endif
+
+
+#define debounce_counter_t uint8_t
+
+static debounce_counter_t *debounce_counters;
+
+#define DEBOUNCE_ELAPSED 251
+#define MAX_DEBOUNCE (DEBOUNCE_ELAPSED - 1)
+
+void update_debounce_counters(uint8_t num_rows, uint8_t current_time);
+void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time);
+
+//we use num_rows rather than MATRIX_ROWS to support split keyboards
+void debounce_init(uint8_t num_rows)
+{
+ debounce_counters = (debounce_counter_t*)malloc(num_rows*sizeof(debounce_counter_t));
+ for (uint8_t r = 0; r < num_rows; r++)
+ {
+ debounce_counters[r] = DEBOUNCE_ELAPSED;
+ }
+}
+
+void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed)
+{
+ uint8_t current_time = timer_read() % MAX_DEBOUNCE;
+ update_debounce_counters(num_rows, current_time);
+ transfer_matrix_values(raw, cooked, num_rows, current_time);
+}
+
+//If the current time is > debounce counter, set the counter to enable input.
+void update_debounce_counters(uint8_t num_rows, uint8_t current_time)
+{
+ debounce_counter_t *debounce_pointer = debounce_counters;
+ for (uint8_t row = 0; row < num_rows; row++)
+ {
+ if (*debounce_pointer != DEBOUNCE_ELAPSED)
+ {
+ if (TIMER_DIFF(current_time, *debounce_pointer, MAX_DEBOUNCE) >= DEBOUNCE) {
+ *debounce_pointer = DEBOUNCE_ELAPSED;
+ }
+ }
+ debounce_pointer++;
+ }
+}
+
+// upload from raw_matrix to final matrix;
+void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time)
+{
+ debounce_counter_t *debounce_pointer = debounce_counters;
+ for (uint8_t row = 0; row < num_rows; row++)
+ {
+ matrix_row_t existing_row = cooked[row];
+ matrix_row_t raw_row = raw[row];
+
+ //determine new value basd on debounce pointer + raw value
+ if (*debounce_pointer == DEBOUNCE_ELAPSED &&
+ (existing_row != raw_row))
+ {
+ *debounce_pointer = current_time;
+ existing_row = raw_row;
+ }
+ cooked[row] = existing_row;
+
+ debounce_pointer++;
+ }
+}
+
+bool debounce_active(void)
+{
+ return true;
+}
+
diff --git a/quantum/debounce/readme.md b/quantum/debounce/readme.md
index 5b318d845..f77f78c76 100644
--- a/quantum/debounce/readme.md
+++ b/quantum/debounce/readme.md
@@ -22,7 +22,7 @@ Here are a few that could be implemented:
sym_g.c
sym_pk.c
sym_pr.c
-sym_pr_cycles.c //currently used in ergo-dox
+sym_pr_cycles.c
eager_g.c
eager_pk.c
eager_pr.c //could be used in ergo-dox!
diff --git a/quantum/encoder.c b/quantum/encoder.c
index 6629a098b..ddf6234ab 100644
--- a/quantum/encoder.c
+++ b/quantum/encoder.c
@@ -17,6 +17,10 @@
#include "encoder.h"
+// for memcpy
+#include <string.h>
+
+
#ifndef ENCODER_RESOLUTION
#define ENCODER_RESOLUTION 4
#endif
@@ -35,7 +39,13 @@ static pin_t encoders_pad_b[NUMBER_OF_ENCODERS] = ENCODERS_PAD_B;
static int8_t encoder_LUT[] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0 };
static uint8_t encoder_state[NUMBER_OF_ENCODERS] = {0};
+
+#ifdef SPLIT_KEYBOARD
+// slave half encoders come over as second set of encoders
+static int8_t encoder_value[NUMBER_OF_ENCODERS * 2] = {0};
+#else
static int8_t encoder_value[NUMBER_OF_ENCODERS] = {0};
+#endif
__attribute__ ((weak))
void encoder_update_user(int8_t index, bool clockwise) { }
@@ -60,11 +70,30 @@ void encoder_read(void) {
encoder_state[i] |= (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1);
encoder_value[i] += encoder_LUT[encoder_state[i] & 0xF];
if (encoder_value[i] >= ENCODER_RESOLUTION) {
- encoder_update_kb(i, COUNTRECLOCKWISE);
+ encoder_update_kb(i, false);
}
if (encoder_value[i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise
- encoder_update_kb(i, CLOCKWISE);
+ encoder_update_kb(i, true);
}
encoder_value[i] %= ENCODER_RESOLUTION;
}
}
+
+#ifdef SPLIT_KEYBOARD
+void encoder_state_raw(uint8_t* slave_state) {
+ memcpy(slave_state, encoder_state, sizeof(encoder_state));
+}
+
+void encoder_update_raw(uint8_t* slave_state) {
+ for (int i = 0; i < NUMBER_OF_ENCODERS; i++) {
+ encoder_value[NUMBER_OF_ENCODERS + i] += encoder_LUT[slave_state[i] & 0xF];
+ if (encoder_value[NUMBER_OF_ENCODERS + i] >= ENCODER_RESOLUTION) {
+ encoder_update_kb(NUMBER_OF_ENCODERS + i, false);
+ }
+ if (encoder_value[NUMBER_OF_ENCODERS + i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise
+ encoder_update_kb(NUMBER_OF_ENCODERS + i, true);
+ }
+ encoder_value[NUMBER_OF_ENCODERS + i] %= ENCODER_RESOLUTION;
+ }
+}
+#endif
diff --git a/quantum/encoder.h b/quantum/encoder.h
index 2024fa303..ec09a8cc4 100644
--- a/quantum/encoder.h
+++ b/quantum/encoder.h
@@ -19,11 +19,13 @@
#include "quantum.h"
-#define COUNTRECLOCKWISE 0
-#define CLOCKWISE 1
-
void encoder_init(void);
void encoder_read(void);
void encoder_update_kb(int8_t index, bool clockwise);
void encoder_update_user(int8_t index, bool clockwise);
+
+#ifdef SPLIT_KEYBOARD
+void encoder_state_raw(uint8_t* slave_state);
+void encoder_update_raw(uint8_t* slave_state);
+#endif
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index 9d2d331ce..eef739a14 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -29,10 +29,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "backlight.h"
#include "quantum.h"
-#ifdef SPLIT_KEYBOARD
- #include "split_flags.h"
-#endif
-
#ifdef MIDI_ENABLE
#include "process_midi.h"
#endif
@@ -138,39 +134,21 @@ action_t action_for_key(uint8_t layer, keypos_t key)
#ifdef BACKLIGHT_ENABLE
case BL_ON:
action.code = ACTION_BACKLIGHT_ON();
- #ifdef SPLIT_KEYBOARD
- BACKLIT_DIRTY = true;
- #endif
break;
case BL_OFF:
action.code = ACTION_BACKLIGHT_OFF();
- #ifdef SPLIT_KEYBOARD
- BACKLIT_DIRTY = true;
- #endif
break;
case BL_DEC:
action.code = ACTION_BACKLIGHT_DECREASE();
- #ifdef SPLIT_KEYBOARD
- BACKLIT_DIRTY = true;
- #endif
break;
case BL_INC:
action.code = ACTION_BACKLIGHT_INCREASE();
- #ifdef SPLIT_KEYBOARD
- BACKLIT_DIRTY = true;
- #endif
break;
case BL_TOGG:
action.code = ACTION_BACKLIGHT_TOGGLE();
- #ifdef SPLIT_KEYBOARD
- BACKLIT_DIRTY = true;
- #endif
break;
case BL_STEP:
action.code = ACTION_BACKLIGHT_STEP();
- #ifdef SPLIT_KEYBOARD
- BACKLIT_DIRTY = true;
- #endif
break;
#endif
#ifdef SWAP_HANDS_ENABLE
diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c
index b64feb700..d0a9cf232 100644
--- a/quantum/process_keycode/process_unicode_common.c
+++ b/quantum/process_keycode/process_unicode_common.c
@@ -118,6 +118,9 @@ void unicode_input_finish(void) {
case UC_WIN:
unregister_code(KC_LALT);
break;
+ case UC_WINC:
+ tap_code(KC_ENTER);
+ break;
}
set_mods(saved_mods); // Reregister previously set mods
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 96760de87..a62368ded 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -225,27 +225,39 @@ static uint16_t scs_timer[2] = {0, 0};
*/
static bool grave_esc_was_shifted = false;
-bool process_record_quantum(keyrecord_t *record) {
+/* Convert record into usable keycode via the contained event. */
+uint16_t get_record_keycode(keyrecord_t *record) {
+ return get_event_keycode(record->event);
+}
- /* This gets the keycode from the key pressed */
- keypos_t key = record->event.key;
- uint16_t keycode;
+
+/* Convert event into usable keycode. Checks the layer cache to ensure that it
+ * retains the correct keycode after a layer change, if the key is still pressed.
+ */
+uint16_t get_event_keycode(keyevent_t event) {
#if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
/* TODO: Use store_or_get_action() or a similar function. */
if (!disable_action_cache) {
uint8_t layer;
- if (record->event.pressed) {
- layer = layer_switch_get_layer(key);
- update_source_layers_cache(key, layer);
+ if (event.pressed) {
+ layer = layer_switch_get_layer(event.key);
+ update_source_layers_cache(event.key, layer);
} else {
- layer = read_source_layers_cache(key);
+ layer = read_source_layers_cache(event.key);
}
- keycode = keymap_key_to_keycode(layer, key);
+ return keymap_key_to_keycode(layer, event.key);
} else
#endif
- keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key);
+ return keymap_key_to_keycode(layer_switch_get_layer(event.key), event.key);
+}
+
+/* Main keycode processing function. Hands off handling to other functions,
+ * then processes internal Quantum keycodes, then processes ACTIONs.
+ */
+bool process_record_quantum(keyrecord_t *record) {
+ uint16_t keycode = get_record_keycode(record);
// This is how you use actions here
// if (keycode == KC_LEAD) {
@@ -274,10 +286,10 @@ bool process_record_quantum(keyrecord_t *record) {
#ifdef HAPTIC_ENABLE
process_haptic(keycode, record) &&
#endif //HAPTIC_ENABLE
- process_record_kb(keycode, record) &&
- #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_KEYPRESSES)
+ #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_KEYREACTIVE_ENABLED)
process_rgb_matrix(keycode, record) &&
#endif
+ process_record_kb(keycode, record) &&
#if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
process_midi(keycode, record) &&
#endif
@@ -360,9 +372,6 @@ bool process_record_quantum(keyrecord_t *record) {
if (!record->event.pressed) {
#endif
rgblight_toggle();
- #ifdef SPLIT_KEYBOARD
- RGB_DIRTY = true;
- #endif
}
return false;
case RGB_MODE_FORWARD:
@@ -374,9 +383,6 @@ bool process_record_quantum(keyrecord_t *record) {
else {
rgblight_step();
}
- #ifdef SPLIT_KEYBOARD
- RGB_DIRTY = true;
- #endif
}
return false;
case RGB_MODE_REVERSE:
@@ -388,9 +394,6 @@ bool process_record_quantum(keyrecord_t *record) {
else {
rgblight_step_reverse();
}
- #ifdef SPLIT_KEYBOARD
- RGB_DIRTY = true;
- #endif
}
return false;
case RGB_HUI:
@@ -401,9 +404,6 @@ bool process_record_quantum(keyrecord_t *record) {
if (!record->event.pressed) {
#endif
rgblight_increase_hue();
- #ifdef SPLIT_KEYBOARD
- RGB_DIRTY = true;
- #endif
}
return false;
case RGB_HUD:
@@ -414,9 +414,6 @@ bool process_record_quantum(keyrecord_t *record) {
if (!record->event.pressed) {
#endif
rgblight_decrease_hue();
- #ifdef SPLIT_KEYBOARD
- RGB_DIRTY = true;
- #endif
}
return false;
case RGB_SAI:
@@ -427,9 +424,6 @@ bool process_record_quantum(keyrecord_t *record) {
if (!record->event.pressed) {
#endif
rgblight_increase_sat();
- #ifdef SPLIT_KEYBOARD
- RGB_DIRTY = true;
- #endif
}
return false;
case RGB_SAD:
@@ -440,9 +434,6 @@ bool process_record_quantum(keyrecord_t *record) {
if (!record->event.pressed) {
#endif
rgblight_decrease_sat();
- #ifdef SPLIT_KEYBOARD
- RGB_DIRTY = true;
- #endif
}
return false;
case RGB_VAI:
@@ -453,9 +444,6 @@ bool process_record_quantum(keyrecord_t *record) {
if (!record->event.pressed) {
#endif
rgblight_increase_val();
- #ifdef SPLIT_KEYBOARD
- RGB_DIRTY = true;
- #endif
}
return false;
case RGB_VAD:
@@ -466,9 +454,6 @@ bool process_record_quantum(keyrecord_t *record) {
if (!record->event.pressed) {
#endif
rgblight_decrease_val();
- #ifdef SPLIT_KEYBOARD
- RGB_DIRTY = true;
- #endif
}
return false;
case RGB_SPI:
@@ -484,9 +469,6 @@ bool process_record_quantum(keyrecord_t *record) {
case RGB_MODE_PLAIN:
if (record->event.pressed) {
rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT);
- #ifdef SPLIT_KEYBOARD
- RGB_DIRTY = true;
- #endif
}
return false;
case RGB_MODE_BREATHE:
@@ -1079,12 +1061,6 @@ void matrix_init_quantum() {
matrix_init_kb();
}
-uint8_t rgb_matrix_task_counter = 0;
-
-#ifndef RGB_MATRIX_SKIP_FRAMES
- #define RGB_MATRIX_SKIP_FRAMES 1
-#endif
-
void matrix_scan_quantum() {
#if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE)
matrix_scan_music();
@@ -1108,10 +1084,6 @@ void matrix_scan_quantum() {
#ifdef RGB_MATRIX_ENABLE
rgb_matrix_task();
- if (rgb_matrix_task_counter == 0) {
- rgb_matrix_update_pwm_buffers();
- }
- rgb_matrix_task_counter = ((rgb_matrix_task_counter + 1) % (RGB_MATRIX_SKIP_FRAMES + 1));
#endif
#ifdef ENCODER_ENABLE
diff --git a/quantum/quantum.h b/quantum/quantum.h
index e1e20a760..c7fce9a0f 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -44,10 +44,6 @@
#endif
#endif
-#ifdef SPLIT_KEYBOARD
- #include "split_flags.h"
-#endif
-
#ifdef RGB_MATRIX_ENABLE
#include "rgb_matrix.h"
#endif
@@ -232,6 +228,8 @@ void matrix_init_kb(void);
void matrix_scan_kb(void);
void matrix_init_user(void);
void matrix_scan_user(void);
+uint16_t get_record_keycode(keyrecord_t *record);
+uint16_t get_event_keycode(keyevent_t event);
bool process_action_kb(keyrecord_t *record);
bool process_record_kb(uint16_t keycode, keyrecord_t *record);
bool process_record_user(uint16_t keycode, keyrecord_t *record);
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c
index 2ed36304d..a1193d4c0 100644
--- a/quantum/rgb_matrix.c
+++ b/quantum/rgb_matrix.c
@@ -24,77 +24,96 @@
#include <string.h>
#include <math.h>
-rgb_config_t rgb_matrix_config;
+#include "lib/lib8tion/lib8tion.h"
+
+#include "rgb_matrix_animations/solid_color_anim.h"
+#include "rgb_matrix_animations/alpha_mods_anim.h"
+#include "rgb_matrix_animations/dual_beacon_anim.h"
+#include "rgb_matrix_animations/gradient_up_down_anim.h"
+#include "rgb_matrix_animations/raindrops_anim.h"
+#include "rgb_matrix_animations/cycle_all_anim.h"
+#include "rgb_matrix_animations/cycle_left_right_anim.h"
+#include "rgb_matrix_animations/cycle_up_down_anim.h"
+#include "rgb_matrix_animations/rainbow_beacon_anim.h"
+#include "rgb_matrix_animations/rainbow_pinwheels_anim.h"
+#include "rgb_matrix_animations/rainbow_moving_chevron_anim.h"
+#include "rgb_matrix_animations/jellybean_raindrops_anim.h"
+#include "rgb_matrix_animations/digital_rain_anim.h"
+#include "rgb_matrix_animations/solid_reactive_simple_anim.h"
+#include "rgb_matrix_animations/solid_reactive_anim.h"
+#include "rgb_matrix_animations/splash_anim.h"
+#include "rgb_matrix_animations/solid_splash_anim.h"
+#include "rgb_matrix_animations/breathing_anim.h"
-#ifndef MAX
- #define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
+#ifndef RGB_DISABLE_AFTER_TIMEOUT
+ #define RGB_DISABLE_AFTER_TIMEOUT 0
#endif
-#ifndef MIN
- #define MIN(a,b) ((a) < (b)? (a): (b))
+#ifndef RGB_DISABLE_WHEN_USB_SUSPENDED
+ #define RGB_DISABLE_WHEN_USB_SUSPENDED false
#endif
-#ifndef RGB_DISABLE_AFTER_TIMEOUT
- #define RGB_DISABLE_AFTER_TIMEOUT 0
+#ifndef EECONFIG_RGB_MATRIX
+ #define EECONFIG_RGB_MATRIX EECONFIG_RGBLIGHT
#endif
-#ifndef RGB_DISABLE_WHEN_USB_SUSPENDED
- #define RGB_DISABLE_WHEN_USB_SUSPENDED false
+#if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX
+ #undef RGB_MATRIX_MAXIMUM_BRIGHTNESS
+ #define RGB_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX
#endif
-#ifndef EECONFIG_RGB_MATRIX
- #define EECONFIG_RGB_MATRIX EECONFIG_RGBLIGHT
+#if !defined(RGB_MATRIX_HUE_STEP)
+ #define RGB_MATRIX_HUE_STEP 8
#endif
-#if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > 255
- #define RGB_MATRIX_MAXIMUM_BRIGHTNESS 255
+#if !defined(RGB_MATRIX_SAT_STEP)
+ #define RGB_MATRIX_SAT_STEP 16
#endif
-#ifndef RGB_DIGITAL_RAIN_DROPS
- // lower the number for denser effect/wider keyboard
- #define RGB_DIGITAL_RAIN_DROPS 24
+#if !defined(RGB_MATRIX_VAL_STEP)
+ #define RGB_MATRIX_VAL_STEP 16
#endif
-#if !defined(DISABLE_RGB_MATRIX_RAINDROPS) || !defined(DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS) || !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN)
- #define TRACK_PREVIOUS_EFFECT
+#if !defined(RGB_MATRIX_SPD_STEP)
+ #define RGB_MATRIX_SPD_STEP 16
#endif
bool g_suspend_state = false;
-// Global tick at 20 Hz
-uint32_t g_tick = 0;
-
-// Ticks since this key was last hit.
-uint8_t g_key_hit[DRIVER_LED_TOTAL];
+rgb_config_t rgb_matrix_config;
-// Ticks since any key was last hit.
-uint32_t g_any_key_hit = 0;
+rgb_counters_t g_rgb_counters;
+static uint32_t rgb_counters_buffer;
-#ifndef PI
-#define PI 3.14159265
-#endif
+#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
+ last_hit_t g_last_hit_tracker;
+ static last_hit_t last_hit_buffer;
+#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
uint32_t eeconfig_read_rgb_matrix(void) {
return eeprom_read_dword(EECONFIG_RGB_MATRIX);
}
+
void eeconfig_update_rgb_matrix(uint32_t val) {
eeprom_update_dword(EECONFIG_RGB_MATRIX, val);
}
+
void eeconfig_update_rgb_matrix_default(void) {
dprintf("eeconfig_update_rgb_matrix_default\n");
rgb_matrix_config.enable = 1;
-#ifndef DISABLE_RGB_MATRIX_CYCLE_ALL
+#ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
rgb_matrix_config.mode = RGB_MATRIX_CYCLE_LEFT_RIGHT;
#else
// fallback to solid colors if RGB_MATRIX_CYCLE_LEFT_RIGHT is disabled in userspace
rgb_matrix_config.mode = RGB_MATRIX_SOLID_COLOR;
#endif
rgb_matrix_config.hue = 0;
- rgb_matrix_config.sat = 255;
+ rgb_matrix_config.sat = UINT8_MAX;
rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
- rgb_matrix_config.speed = 0;
+ rgb_matrix_config.speed = UINT8_MAX / 2;
eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
}
+
void eeconfig_debug_rgb_matrix(void) {
dprintf("rgb_matrix_config eprom\n");
dprintf("rgb_matrix_config.enable = %d\n", rgb_matrix_config.enable);
@@ -105,691 +124,347 @@ void eeconfig_debug_rgb_matrix(void) {
dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed);
}
-// Last led hit
-#define LED_HITS_TO_REMEMBER 8
-uint8_t g_last_led_hit[LED_HITS_TO_REMEMBER] = {255};
-uint8_t g_last_led_count = 0;
-
-void map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i, uint8_t *led_count) {
- rgb_led led;
- *led_count = 0;
-
- for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
- // map_index_to_led(i, &led);
- led = g_rgb_leds[i];
- if (row == led.matrix_co.row && column == led.matrix_co.col) {
- led_i[*led_count] = i;
- (*led_count)++;
- }
+uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) {
+ // TODO: This is kinda expensive, fix this soonish
+ uint8_t led_count = 0;
+ for (uint8_t i = 0; i < DRIVER_LED_TOTAL && led_count < LED_HITS_TO_REMEMBER; i++) {
+ matrix_co_t matrix_co = g_rgb_leds[i].matrix_co;
+ if (row == matrix_co.row && column == matrix_co.col) {
+ led_i[led_count] = i;
+ led_count++;
}
+ }
+ return led_count;
}
void rgb_matrix_update_pwm_buffers(void) {
- rgb_matrix_driver.flush();
+ rgb_matrix_driver.flush();
}
void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) {
- rgb_matrix_driver.set_color(index, red, green, blue);
+#ifdef RGB_MATRIX_EXTRA_TOG
+ const bool is_key = g_rgb_leds[index].matrix_co.raw != 0xff;
+ if (
+ (rgb_matrix_config.enable == RGB_ZONE_KEYS && !is_key) ||
+ (rgb_matrix_config.enable == RGB_ZONE_UNDER && is_key)
+ ) {
+ rgb_matrix_driver.set_color(index, 0, 0, 0);
+ return;
+ }
+#endif
+
+ rgb_matrix_driver.set_color(index, red, green, blue);
}
void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) {
- rgb_matrix_driver.set_color_all(red, green, blue);
+#ifdef RGB_MATRIX_EXTRA_TOG
+ for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
+ rgb_matrix_set_color(i, red, green, blue);
+ }
+#else
+ rgb_matrix_driver.set_color_all(red, green, blue);
+#endif
}
bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) {
- if ( record->event.pressed ) {
- uint8_t led[8], led_count;
- map_row_column_to_led(record->event.key.row, record->event.key.col, led, &led_count);
- if (led_count > 0) {
- for (uint8_t i = LED_HITS_TO_REMEMBER; i > 1; i--) {
- g_last_led_hit[i - 1] = g_last_led_hit[i - 2];
- }
- g_last_led_hit[0] = led[0];
- g_last_led_count = MIN(LED_HITS_TO_REMEMBER, g_last_led_count + 1);
- }
- for(uint8_t i = 0; i < led_count; i++)
- g_key_hit[led[i]] = 0;
- g_any_key_hit = 0;
- } else {
- #ifdef RGB_MATRIX_KEYRELEASES
- uint8_t led[8], led_count;
- map_row_column_to_led(record->event.key.row, record->event.key.col, led, &led_count);
- for(uint8_t i = 0; i < led_count; i++)
- g_key_hit[led[i]] = 255;
-
- g_any_key_hit = 255;
- #endif
- }
- return true;
-}
+#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
+ uint8_t led[LED_HITS_TO_REMEMBER];
+ uint8_t led_count = 0;
+
+#if defined(RGB_MATRIX_KEYRELEASES)
+ if (!record->event.pressed) {
+ led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led);
+ g_rgb_counters.any_key_hit = 0;
+ }
+#elif defined(RGB_MATRIX_KEYPRESSES)
+ if (record->event.pressed) {
+ led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led);
+ g_rgb_counters.any_key_hit = 0;
+ }
+#endif // defined(RGB_MATRIX_KEYRELEASES)
+
+ if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) {
+ memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count);
+ memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count);
+ memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit
+ memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count);
+ last_hit_buffer.count--;
+ }
-void rgb_matrix_set_suspend_state(bool state) {
- g_suspend_state = state;
+ for(uint8_t i = 0; i < led_count; i++) {
+ uint8_t index = last_hit_buffer.count;
+ last_hit_buffer.x[index] = g_rgb_leds[led[i]].point.x;
+ last_hit_buffer.y[index] = g_rgb_leds[led[i]].point.y;
+ last_hit_buffer.index[index] = led[i];
+ last_hit_buffer.tick[index] = 0;
+ last_hit_buffer.count++;
+ }
+#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+ return true;
}
void rgb_matrix_test(void) {
- // Mask out bits 4 and 5
- // Increase the factor to make the test animation slower (and reduce to make it faster)
- uint8_t factor = 10;
- switch ( (g_tick & (0b11 << factor)) >> factor )
- {
- case 0:
- {
- rgb_matrix_set_color_all( 20, 0, 0 );
- break;
- }
- case 1:
- {
- rgb_matrix_set_color_all( 0, 20, 0 );
- break;
- }
- case 2:
- {
- rgb_matrix_set_color_all( 0, 0, 20 );
- break;
- }
- case 3:
- {
- rgb_matrix_set_color_all( 20, 20, 20 );
- break;
- }
- }
-}
-
-// All LEDs off
-void rgb_matrix_all_off(void) {
- rgb_matrix_set_color_all( 0, 0, 0 );
-}
-
-// Solid color
-void rgb_matrix_solid_color(void) {
- HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val };
- RGB rgb = hsv_to_rgb( hsv );
- rgb_matrix_set_color_all( rgb.r, rgb.g, rgb.b );
-}
-
-void rgb_matrix_solid_reactive(void) {
- // Relies on hue being 8-bit and wrapping
- for ( int i=0; i<DRIVER_LED_TOTAL; i++ )
- {
- uint16_t offset2 = g_key_hit[i]<<2;
- offset2 = (offset2<=130) ? (130-offset2) : 0;
-
- HSV hsv = { .h = rgb_matrix_config.hue+offset2, .s = 255, .v = rgb_matrix_config.val };
- RGB rgb = hsv_to_rgb( hsv );
- rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
- }
-}
-
-// alphas = color1, mods = color2
-void rgb_matrix_alphas_mods(void) {
-
- RGB rgb1 = hsv_to_rgb( (HSV){ .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val } );
- RGB rgb2 = hsv_to_rgb( (HSV){ .h = (rgb_matrix_config.hue + 180) % 360, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val } );
-
- rgb_led led;
- for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
- led = g_rgb_leds[i];
- if ( led.matrix_co.raw < 0xFF ) {
- if ( led.modifier )
- {
- rgb_matrix_set_color( i, rgb2.r, rgb2.g, rgb2.b );
- }
- else
- {
- rgb_matrix_set_color( i, rgb1.r, rgb1.g, rgb1.b );
- }
- }
- }
-}
-
-void rgb_matrix_gradient_up_down(void) {
- int16_t h1 = rgb_matrix_config.hue;
- int16_t h2 = (rgb_matrix_config.hue + 180) % 360;
- int16_t deltaH = h2 - h1;
-
- // Take the shortest path between hues
- if ( deltaH > 127 )
- {
- deltaH -= 256;
- }
- else if ( deltaH < -127 )
- {
- deltaH += 256;
+ // Mask out bits 4 and 5
+ // Increase the factor to make the test animation slower (and reduce to make it faster)
+ uint8_t factor = 10;
+ switch ( (g_rgb_counters.tick & (0b11 << factor)) >> factor )
+ {
+ case 0: {
+ rgb_matrix_set_color_all( 20, 0, 0 );
+ break;
}
- // Divide delta by 4, this gives the delta per row
- deltaH /= 4;
-
- int16_t s1 = rgb_matrix_config.sat;
- int16_t s2 = rgb_matrix_config.hue;
- int16_t deltaS = ( s2 - s1 ) / 4;
-
- HSV hsv = { .h = 0, .s = 255, .v = rgb_matrix_config.val };
- RGB rgb;
- Point point;
- for ( int i=0; i<DRIVER_LED_TOTAL; i++ )
- {
- // map_led_to_point( i, &point );
- point = g_rgb_leds[i].point;
- // The y range will be 0..64, map this to 0..4
- uint8_t y = (point.y>>4);
- // Relies on hue being 8-bit and wrapping
- hsv.h = rgb_matrix_config.hue + ( deltaH * y );
- hsv.s = rgb_matrix_config.sat + ( deltaS * y );
- rgb = hsv_to_rgb( hsv );
- rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
+ case 1: {
+ rgb_matrix_set_color_all( 0, 20, 0 );
+ break;
}
-}
-
-void rgb_matrix_raindrops(bool initialize) {
- int16_t h1 = rgb_matrix_config.hue;
- int16_t h2 = (rgb_matrix_config.hue + 180) % 360;
- int16_t deltaH = h2 - h1;
- deltaH /= 4;
-
- // Take the shortest path between hues
- if ( deltaH > 127 )
- {
- deltaH -= 256;
- }
- else if ( deltaH < -127 )
- {
- deltaH += 256;
- }
-
- int16_t s1 = rgb_matrix_config.sat;
- int16_t s2 = rgb_matrix_config.sat;
- int16_t deltaS = ( s2 - s1 ) / 4;
-
- HSV hsv;
- RGB rgb;
-
- // Change one LED every tick, make sure speed is not 0
- uint8_t led_to_change = ( g_tick & ( 0x0A / (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed) ) ) == 0 ? rand() % (DRIVER_LED_TOTAL) : 255;
-
- for ( int i=0; i<DRIVER_LED_TOTAL; i++ )
- {
- // If initialize, all get set to random colors
- // If not, all but one will stay the same as before.
- if ( initialize || i == led_to_change )
- {
- hsv.h = h1 + ( deltaH * ( rand() & 0x03 ) );
- hsv.s = s1 + ( deltaS * ( rand() & 0x03 ) );
- // Override brightness with global brightness control
- hsv.v = rgb_matrix_config.val;
-
- rgb = hsv_to_rgb( hsv );
- rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
- }
- }
-}
-
-void rgb_matrix_cycle_all(void) {
- uint8_t offset = ( g_tick << rgb_matrix_config.speed ) & 0xFF;
-
- rgb_led led;
-
- // Relies on hue being 8-bit and wrapping
- for ( int i=0; i<DRIVER_LED_TOTAL; i++ )
- {
- // map_index_to_led(i, &led);
- led = g_rgb_leds[i];
- if (led.matrix_co.raw < 0xFF) {
- uint16_t offset2 = g_key_hit[i]<<2;
- offset2 = (offset2<=63) ? (63-offset2) : 0;
-
- HSV hsv = { .h = offset+offset2, .s = 255, .v = rgb_matrix_config.val };
- RGB rgb = hsv_to_rgb( hsv );
- rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
- }
+ case 2: {
+ rgb_matrix_set_color_all( 0, 0, 20 );
+ break;
}
-}
-
-void rgb_matrix_cycle_left_right(void) {
- uint8_t offset = ( g_tick << rgb_matrix_config.speed ) & 0xFF;
- HSV hsv = { .h = 0, .s = 255, .v = rgb_matrix_config.val };
- RGB rgb;
- Point point;
- rgb_led led;
- for ( int i=0; i<DRIVER_LED_TOTAL; i++ )
- {
- // map_index_to_led(i, &led);
- led = g_rgb_leds[i];
- if (led.matrix_co.raw < 0xFF) {
- uint16_t offset2 = g_key_hit[i]<<2;
- offset2 = (offset2<=63) ? (63-offset2) : 0;
-
- // map_led_to_point( i, &point );
- point = g_rgb_leds[i].point;
- // Relies on hue being 8-bit and wrapping
- hsv.h = point.x + offset + offset2;
- rgb = hsv_to_rgb( hsv );
- rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
- }
- }
-}
-
-void rgb_matrix_cycle_up_down(void) {
- uint8_t offset = ( g_tick << rgb_matrix_config.speed ) & 0xFF;
- HSV hsv = { .h = 0, .s = 255, .v = rgb_matrix_config.val };
- RGB rgb;
- Point point;
- rgb_led led;
- for ( int i=0; i<DRIVER_LED_TOTAL; i++ )
- {
- // map_index_to_led(i, &led);
- led = g_rgb_leds[i];
- if (led.matrix_co.raw < 0xFF) {
- uint16_t offset2 = g_key_hit[i]<<2;
- offset2 = (offset2<=63) ? (63-offset2) : 0;
-
- // map_led_to_point( i, &point );
- point = g_rgb_leds[i].point;
- // Relies on hue being 8-bit and wrapping
- hsv.h = point.y + offset + offset2;
- rgb = hsv_to_rgb( hsv );
- rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
- }
+ case 3: {
+ rgb_matrix_set_color_all( 20, 20, 20 );
+ break;
}
+ }
}
+static bool rgb_matrix_none(effect_params_t* params) {
+ if (!params->init) {
+ return false;
+ }
-void rgb_matrix_dual_beacon(void) {
- HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val };
- RGB rgb;
- Point point;
- double cos_value = cos(g_tick * PI / 128) / 32;
- double sin_value = sin(g_tick * PI / 128) / 112;
- for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
- point = g_rgb_leds[i].point;
- hsv.h = ((point.y - 32.0)* cos_value + (point.x - 112.0) * sin_value) * (180) + rgb_matrix_config.hue;
- rgb = hsv_to_rgb( hsv );
- rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
- }
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+ for (uint8_t i = led_min; i < led_max; i++) {
+ rgb_matrix_set_color(i, 0, 0, 0);
+ }
+ return led_max < DRIVER_LED_TOTAL;
}
-void rgb_matrix_rainbow_beacon(void) {
- HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val };
- RGB rgb;
- Point point;
- double cos_value = cos(g_tick * PI / 128);
- double sin_value = sin(g_tick * PI / 128);
- for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
- point = g_rgb_leds[i].point;
- hsv.h = (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (point.y - 32.0)* cos_value + (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (point.x - 112.0) * sin_value + rgb_matrix_config.hue;
- rgb = hsv_to_rgb( hsv );
- rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
- }
-}
+static uint8_t rgb_last_enable = UINT8_MAX;
+static uint8_t rgb_last_effect = UINT8_MAX;
+static effect_params_t rgb_effect_params = { 0, 0 };
+static rgb_task_states rgb_task_state = SYNCING;
-void rgb_matrix_rainbow_pinwheels(void) {
- HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val };
- RGB rgb;
- Point point;
- double cos_value = cos(g_tick * PI / 128);
- double sin_value = sin(g_tick * PI / 128);
- for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
- point = g_rgb_leds[i].point;
- hsv.h = (2 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (point.y - 32.0)* cos_value + (2 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (66 - abs(point.x - 112.0)) * sin_value + rgb_matrix_config.hue;
- rgb = hsv_to_rgb( hsv );
- rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
+static void rgb_task_timers(void) {
+ // Update double buffer timers
+ uint16_t deltaTime = timer_elapsed32(rgb_counters_buffer);
+ rgb_counters_buffer = timer_read32();
+ if (g_rgb_counters.any_key_hit < UINT32_MAX) {
+ if (UINT32_MAX - deltaTime < g_rgb_counters.any_key_hit) {
+ g_rgb_counters.any_key_hit = UINT32_MAX;
+ } else {
+ g_rgb_counters.any_key_hit += deltaTime;
}
-}
+ }
-void rgb_matrix_rainbow_moving_chevron(void) {
- HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val };
- RGB rgb;
- Point point;
- uint8_t r = 128;
- double cos_value = cos(r * PI / 128);
- double sin_value = sin(r * PI / 128);
- double multiplier = (g_tick / 256.0 * 224);
- for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
- point = g_rgb_leds[i].point;
- hsv.h = (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * abs(point.y - 32.0)* sin_value + (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (point.x - multiplier) * cos_value + rgb_matrix_config.hue;
- rgb = hsv_to_rgb( hsv );
- rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
+ // Update double buffer last hit timers
+#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
+ uint8_t count = last_hit_buffer.count;
+ for (uint8_t i = 0; i < count; ++i) {
+ if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) {
+ last_hit_buffer.count--;
+ continue;
}
-}
-
-
-void rgb_matrix_jellybean_raindrops( bool initialize ) {
- HSV hsv;
- RGB rgb;
+ last_hit_buffer.tick[i] += deltaTime;
+ }
+#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+}
+
+static void rgb_task_sync(void) {
+ // next task
+ if (timer_elapsed32(g_rgb_counters.tick) >= RGB_MATRIX_LED_FLUSH_LIMIT)
+ rgb_task_state = STARTING;
+}
+
+static void rgb_task_start(void) {
+ // reset iter
+ rgb_effect_params.iter = 0;
+
+ // update double buffers
+ g_rgb_counters.tick = rgb_counters_buffer;
+#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
+ g_last_hit_tracker = last_hit_buffer;
+#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+
+ // next task
+ rgb_task_state = RENDERING;
+}
+
+static void rgb_task_render(uint8_t effect) {
+ bool rendering = false;
+ rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable);
+
+ // each effect can opt to do calculations
+ // and/or request PWM buffer updates.
+ switch (effect) {
+ case RGB_MATRIX_NONE:
+ rendering = rgb_matrix_none(&rgb_effect_params);
+ break;
+
+ case RGB_MATRIX_SOLID_COLOR:
+ rendering = rgb_matrix_solid_color(&rgb_effect_params); // Max 1ms Avg 0ms
+ break;
+#ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS
+ case RGB_MATRIX_ALPHAS_MODS:
+ rendering = rgb_matrix_alphas_mods(&rgb_effect_params); // Max 2ms Avg 1ms
+ break;
+#endif // DISABLE_RGB_MATRIX_ALPHAS_MODS
+#ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
+ case RGB_MATRIX_GRADIENT_UP_DOWN:
+ rendering = rgb_matrix_gradient_up_down(&rgb_effect_params); // Max 4ms Avg 3ms
+ break;
+#endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
+#ifndef DISABLE_RGB_MATRIX_BREATHING
+ case RGB_MATRIX_BREATHING:
+ rendering = rgb_matrix_breathing(&rgb_effect_params); // Max 1ms Avg 0ms
+ break;
+#endif // DISABLE_RGB_MATRIX_BREATHING
+#ifndef DISABLE_RGB_MATRIX_CYCLE_ALL
+ case RGB_MATRIX_CYCLE_ALL:
+ rendering = rgb_matrix_cycle_all(&rgb_effect_params); // Max 4ms Avg 3ms
+ break;
+#endif // DISABLE_RGB_MATRIX_CYCLE_ALL
+#ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
+ case RGB_MATRIX_CYCLE_LEFT_RIGHT:
+ rendering = rgb_matrix_cycle_left_right(&rgb_effect_params); // Max 4ms Avg 3ms
+ break;
+#endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
+#ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
+ case RGB_MATRIX_CYCLE_UP_DOWN:
+ rendering = rgb_matrix_cycle_up_down(&rgb_effect_params); // Max 4ms Avg 3ms
+ break;
+#endif // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
+#ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
+ case RGB_MATRIX_RAINBOW_MOVING_CHEVRON:
+ rendering = rgb_matrix_rainbow_moving_chevron(&rgb_effect_params); // Max 4ms Avg 3ms
+ break;
+#endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
+#ifndef DISABLE_RGB_MATRIX_DUAL_BEACON
+ case RGB_MATRIX_DUAL_BEACON:
+ rendering = rgb_matrix_dual_beacon(&rgb_effect_params); // Max 4ms Avg 3ms
+ break;
+#endif // DISABLE_RGB_MATRIX_DUAL_BEACON
+#ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON
+ case RGB_MATRIX_RAINBOW_BEACON:
+ rendering = rgb_matrix_rainbow_beacon(&rgb_effect_params); // Max 4ms Avg 3ms
+ break;
+#endif // DISABLE_RGB_MATRIX_RAINBOW_BEACON
+#ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
+ case RGB_MATRIX_RAINBOW_PINWHEELS:
+ rendering = rgb_matrix_rainbow_pinwheels(&rgb_effect_params); // Max 4ms Avg 3ms
+ break;
+#endif // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
+#ifndef DISABLE_RGB_MATRIX_RAINDROPS
+ case RGB_MATRIX_RAINDROPS:
+ rendering = rgb_matrix_raindrops(&rgb_effect_params); // Max 1ms Avg 0ms
+ break;
+#endif // DISABLE_RGB_MATRIX_RAINDROPS
+#ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
+ case RGB_MATRIX_JELLYBEAN_RAINDROPS:
+ rendering = rgb_matrix_jellybean_raindrops(&rgb_effect_params); // Max 1ms Avg 0ms
+ break;
+#endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
+#ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN
+ case RGB_MATRIX_DIGITAL_RAIN:
+ rendering = rgb_matrix_digital_rain(&rgb_effect_params); // Max 9ms Avg 8ms | this is expensive, fix it
+ break;
+#endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN
+#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
+#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
+ case RGB_MATRIX_SOLID_REACTIVE_SIMPLE:
+ rendering = rgb_matrix_solid_reactive_simple(&rgb_effect_params);// Max 4ms Avg 3ms
+ break;
+#endif
+#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE
+ case RGB_MATRIX_SOLID_REACTIVE:
+ rendering = rgb_matrix_solid_reactive(&rgb_effect_params); // Max 4ms Avg 3ms
+ break;
+#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE
+#ifndef DISABLE_RGB_MATRIX_SPLASH
+ case RGB_MATRIX_SPLASH:
+ rendering = rgb_matrix_splash(&rgb_effect_params); // Max 5ms Avg 3ms
+ break;
+#endif // DISABLE_RGB_MATRIX_SPLASH
+#ifndef DISABLE_RGB_MATRIX_MULTISPLASH
+ case RGB_MATRIX_MULTISPLASH:
+ rendering = rgb_matrix_multisplash(&rgb_effect_params); // Max 10ms Avg 5ms
+ break;
+#endif // DISABLE_RGB_MATRIX_MULTISPLASH
+#ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH
+ case RGB_MATRIX_SOLID_SPLASH:
+ rendering = rgb_matrix_solid_splash(&rgb_effect_params); // Max 5ms Avg 3ms
+ break;
+#endif // DISABLE_RGB_MATRIX_SOLID_SPLASH
+#ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
+ case RGB_MATRIX_SOLID_MULTISPLASH:
+ rendering = rgb_matrix_solid_multisplash(&rgb_effect_params); // Max 10ms Avg 5ms
+ break;
+#endif // DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
+#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
- // Change one LED every tick, make sure speed is not 0
- uint8_t led_to_change = ( g_tick & ( 0x0A / (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed) ) ) == 0 ? rand() % (DRIVER_LED_TOTAL) : 255;
+ // Factory default magic value
+ case UINT8_MAX: {
+ rgb_matrix_test();
+ rgb_task_state = FLUSHING;
+ }
+ return;
+ }
- for ( int i=0; i<DRIVER_LED_TOTAL; i++ )
- {
- // If initialize, all get set to random colors
- // If not, all but one will stay the same as before.
- if ( initialize || i == led_to_change )
- {
- hsv.h = rand() & 0xFF;
- hsv.s = rand() & 0xFF;
- // Override brightness with global brightness control
- hsv.v = rgb_matrix_config.val;
+ rgb_effect_params.iter++;
- rgb = hsv_to_rgb( hsv );
- rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
- }
+ // next task
+ if (!rendering) {
+ rgb_task_state = FLUSHING;
+ if (!rgb_effect_params.init && effect == RGB_MATRIX_NONE) {
+ // We only need to flush once if we are RGB_MATRIX_NONE
+ rgb_task_state = SYNCING;
}
+ }
}
-void rgb_matrix_digital_rain( const bool initialize ) {
- // algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain
- const uint8_t drop_ticks = 28;
- const uint8_t pure_green_intensity = 0xd0;
- const uint8_t max_brightness_boost = 0xc0;
- const uint8_t max_intensity = 0xff;
+static void rgb_task_flush(uint8_t effect) {
+ // update last trackers after the first full render so we can init over several frames
+ rgb_last_effect = effect;
+ rgb_last_enable = rgb_matrix_config.enable;
- static uint8_t map[MATRIX_COLS][MATRIX_ROWS] = {{0}};
- static uint8_t drop = 0;
-
- if (initialize) {
- rgb_matrix_set_color_all(0, 0, 0);
- memset(map, 0, sizeof map);
- drop = 0;
- }
- for (uint8_t col = 0; col < MATRIX_COLS; col++) {
- for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
- if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) {
- // top row, pixels have just fallen and we're
- // making a new rain drop in this column
- map[col][row] = max_intensity;
- }
- else if (map[col][row] > 0 && map[col][row] < max_intensity) {
- // neither fully bright nor dark, decay it
- map[col][row]--;
- }
- // set the pixel colour
- uint8_t led, led_count;
- map_row_column_to_led(row, col, &led, &led_count);
-
- if (map[col][row] > pure_green_intensity) {
- const uint8_t boost = (uint8_t) ((uint16_t) max_brightness_boost
- * (map[col][row] - pure_green_intensity) / (max_intensity - pure_green_intensity));
- rgb_matrix_set_color(led, boost, max_intensity, boost);
- }
- else {
- const uint8_t green = (uint8_t) ((uint16_t) max_intensity * map[col][row] / pure_green_intensity);
- rgb_matrix_set_color(led, 0, green, 0);
- }
- }
- }
- if (++drop > drop_ticks) {
- // reset drop timer
- drop = 0;
- for (uint8_t row = MATRIX_ROWS - 1; row > 0; row--) {
- for (uint8_t col = 0; col < MATRIX_COLS; col++) {
- // if ths is on the bottom row and bright allow decay
- if (row == MATRIX_ROWS - 1 && map[col][row] == max_intensity) {
- map[col][row]--;
- }
- // check if the pixel above is bright
- if (map[col][row - 1] == max_intensity) {
- // allow old bright pixel to decay
- map[col][row - 1]--;
- // make this pixel bright
- map[col][row] = max_intensity;
- }
- }
- }
- }
-}
+ // update pwm buffers
+ rgb_matrix_update_pwm_buffers();
-void rgb_matrix_multisplash(void) {
- // if (g_any_key_hit < 0xFF) {
- HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val };
- RGB rgb;
- rgb_led led;
- for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
- led = g_rgb_leds[i];
- uint16_t c = 0, d = 0;
- rgb_led last_led;
- // if (g_last_led_count) {
- for (uint8_t last_i = 0; last_i < g_last_led_count; last_i++) {
- last_led = g_rgb_leds[g_last_led_hit[last_i]];
- uint16_t dist = (uint16_t)sqrt(pow(led.point.x - last_led.point.x, 2) + pow(led.point.y - last_led.point.y, 2));
- uint16_t effect = (g_key_hit[g_last_led_hit[last_i]] << 2) - dist;
- c += MIN(MAX(effect, 0), 255);
- d += 255 - MIN(MAX(effect, 0), 255);
- }
- // } else {
- // d = 255;
- // }
- hsv.h = (rgb_matrix_config.hue + c) % 256;
- hsv.v = MAX(MIN(d, 255), 0);
- rgb = hsv_to_rgb( hsv );
- rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
- }
- // } else {
- // rgb_matrix_set_color_all( 0, 0, 0 );
- // }
-}
-
-
-void rgb_matrix_splash(void) {
- g_last_led_count = MIN(g_last_led_count, 1);
- rgb_matrix_multisplash();
-}
-
-
-void rgb_matrix_solid_multisplash(void) {
- // if (g_any_key_hit < 0xFF) {
- HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val };
- RGB rgb;
- rgb_led led;
- for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
- led = g_rgb_leds[i];
- uint16_t d = 0;
- rgb_led last_led;
- // if (g_last_led_count) {
- for (uint8_t last_i = 0; last_i < g_last_led_count; last_i++) {
- last_led = g_rgb_leds[g_last_led_hit[last_i]];
- uint16_t dist = (uint16_t)sqrt(pow(led.point.x - last_led.point.x, 2) + pow(led.point.y - last_led.point.y, 2));
- uint16_t effect = (g_key_hit[g_last_led_hit[last_i]] << 2) - dist;
- d += 255 - MIN(MAX(effect, 0), 255);
- }
- // } else {
- // d = 255;
- // }
- hsv.v = MAX(MIN(d, 255), 0);
- rgb = hsv_to_rgb( hsv );
- rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
- }
- // } else {
- // rgb_matrix_set_color_all( 0, 0, 0 );
- // }
-}
-
-
-void rgb_matrix_solid_splash(void) {
- g_last_led_count = MIN(g_last_led_count, 1);
- rgb_matrix_solid_multisplash();
-}
-
-
-// Needs eeprom access that we don't have setup currently
-
-void rgb_matrix_custom(void) {
-// HSV hsv;
-// RGB rgb;
-// for ( int i=0; i<DRIVER_LED_TOTAL; i++ )
-// {
-// backlight_get_key_color(i, &hsv);
-// // Override brightness with global brightness control
-// hsv.v = rgb_matrix_config.val;
-// rgb = hsv_to_rgb( hsv );
-// rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
-// }
+ // next task
+ rgb_task_state = SYNCING;
}
void rgb_matrix_task(void) {
- #ifdef TRACK_PREVIOUS_EFFECT
- static uint8_t toggle_enable_last = 255;
- #endif
- if (!rgb_matrix_config.enable) {
- rgb_matrix_all_off();
- rgb_matrix_indicators();
- #ifdef TRACK_PREVIOUS_EFFECT
- toggle_enable_last = rgb_matrix_config.enable;
- #endif
- return;
- }
- // delay 1 second before driving LEDs or doing anything else
- static uint8_t startup_tick = 0;
- if ( startup_tick < 20 ) {
- startup_tick++;
- return;
- }
-
- g_tick++;
-
- if ( g_any_key_hit < 0xFFFFFFFF ) {
- g_any_key_hit++;
- }
-
- for ( int led = 0; led < DRIVER_LED_TOTAL; led++ ) {
- if ( g_key_hit[led] < 255 ) {
- if (g_key_hit[led] == 254)
- g_last_led_count = MAX(g_last_led_count - 1, 0);
- g_key_hit[led]++;
- }
- }
-
- // Factory default magic value
- if ( rgb_matrix_config.mode == 255 ) {
- rgb_matrix_test();
- return;
- }
-
- // Ideally we would also stop sending zeros to the LED driver PWM buffers
- // while suspended and just do a software shutdown. This is a cheap hack for now.
- bool suspend_backlight = ((g_suspend_state && RGB_DISABLE_WHEN_USB_SUSPENDED) ||
- (RGB_DISABLE_AFTER_TIMEOUT > 0 && g_any_key_hit > RGB_DISABLE_AFTER_TIMEOUT * 60 * 20));
- uint8_t effect = suspend_backlight ? 0 : rgb_matrix_config.mode;
-
- #ifdef TRACK_PREVIOUS_EFFECT
- // Keep track of the effect used last time,
- // detect change in effect, so each effect can
- // have an optional initialization.
-
- static uint8_t effect_last = 255;
- bool initialize = (effect != effect_last) || (rgb_matrix_config.enable != toggle_enable_last);
- effect_last = effect;
- toggle_enable_last = rgb_matrix_config.enable;
- #endif
-
- // this gets ticked at 20 Hz.
- // each effect can opt to do calculations
- // and/or request PWM buffer updates.
- switch ( effect ) {
- case RGB_MATRIX_SOLID_COLOR:
- rgb_matrix_solid_color();
- break;
- #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS
- case RGB_MATRIX_ALPHAS_MODS:
- rgb_matrix_alphas_mods();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON
- case RGB_MATRIX_DUAL_BEACON:
- rgb_matrix_dual_beacon();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
- case RGB_MATRIX_GRADIENT_UP_DOWN:
- rgb_matrix_gradient_up_down();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_RAINDROPS
- case RGB_MATRIX_RAINDROPS:
- rgb_matrix_raindrops( initialize );
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL
- case RGB_MATRIX_CYCLE_ALL:
- rgb_matrix_cycle_all();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
- case RGB_MATRIX_CYCLE_LEFT_RIGHT:
- rgb_matrix_cycle_left_right();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
- case RGB_MATRIX_CYCLE_UP_DOWN:
- rgb_matrix_cycle_up_down();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON
- case RGB_MATRIX_RAINBOW_BEACON:
- rgb_matrix_rainbow_beacon();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
- case RGB_MATRIX_RAINBOW_PINWHEELS:
- rgb_matrix_rainbow_pinwheels();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
- case RGB_MATRIX_RAINBOW_MOVING_CHEVRON:
- rgb_matrix_rainbow_moving_chevron();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
- case RGB_MATRIX_JELLYBEAN_RAINDROPS:
- rgb_matrix_jellybean_raindrops( initialize );
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN
- case RGB_MATRIX_DIGITAL_RAIN:
- rgb_matrix_digital_rain( initialize );
- break;
- #endif
- #ifdef RGB_MATRIX_KEYPRESSES
- #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE
- case RGB_MATRIX_SOLID_REACTIVE:
- rgb_matrix_solid_reactive();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_SPLASH
- case RGB_MATRIX_SPLASH:
- rgb_matrix_splash();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_MULTISPLASH
- case RGB_MATRIX_MULTISPLASH:
- rgb_matrix_multisplash();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH
- case RGB_MATRIX_SOLID_SPLASH:
- rgb_matrix_solid_splash();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
- case RGB_MATRIX_SOLID_MULTISPLASH:
- rgb_matrix_solid_multisplash();
- break;
- #endif
- #endif
- default:
- rgb_matrix_custom();
- break;
- }
-
- if ( ! suspend_backlight ) {
- rgb_matrix_indicators();
- }
+ rgb_task_timers();
+
+ // Ideally we would also stop sending zeros to the LED driver PWM buffers
+ // while suspended and just do a software shutdown. This is a cheap hack for now.
+ bool suspend_backlight = ((g_suspend_state && RGB_DISABLE_WHEN_USB_SUSPENDED) || (RGB_DISABLE_AFTER_TIMEOUT > 0 && g_rgb_counters.any_key_hit > RGB_DISABLE_AFTER_TIMEOUT * 60 * 20));
+ uint8_t effect = suspend_backlight || !rgb_matrix_config.enable ? 0 : rgb_matrix_config.mode;
+
+ switch (rgb_task_state) {
+ case STARTING:
+ rgb_task_start();
+ break;
+ case RENDERING:
+ rgb_task_render(effect);
+ break;
+ case FLUSHING:
+ rgb_task_flush(effect);
+ break;
+ case SYNCING:
+ rgb_task_sync();
+ break;
+ }
+ if (!suspend_backlight) {
+ rgb_matrix_indicators();
+ }
}
void rgb_matrix_indicators(void) {
- rgb_matrix_indicators_kb();
- rgb_matrix_indicators_user();
+ rgb_matrix_indicators_kb();
+ rgb_matrix_indicators_user();
}
__attribute__((weak))
@@ -798,103 +473,54 @@ void rgb_matrix_indicators_kb(void) {}
__attribute__((weak))
void rgb_matrix_indicators_user(void) {}
-
-// void rgb_matrix_set_indicator_index( uint8_t *index, uint8_t row, uint8_t column )
-// {
-// if ( row >= MATRIX_ROWS )
-// {
-// // Special value, 255=none, 254=all
-// *index = row;
-// }
-// else
-// {
-// // This needs updated to something like
-// // uint8_t led[8], led_count;
-// // map_row_column_to_led(row,column,led,&led_count);
-// // for(uint8_t i = 0; i < led_count; i++)
-// map_row_column_to_led( row, column, index );
-// }
-// }
-
void rgb_matrix_init(void) {
rgb_matrix_driver.init();
// TODO: put the 1 second startup delay here?
- // clear the key hits
- for ( int led=0; led<DRIVER_LED_TOTAL; led++ ) {
- g_key_hit[led] = 255;
+#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
+ g_last_hit_tracker.count = 0;
+ for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
+ g_last_hit_tracker.tick[i] = UINT16_MAX;
}
+ last_hit_buffer.count = 0;
+ for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
+ last_hit_buffer.tick[i] = UINT16_MAX;
+ }
+#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
if (!eeconfig_is_enabled()) {
- dprintf("rgb_matrix_init_drivers eeconfig is not enabled.\n");
- eeconfig_init();
- eeconfig_update_rgb_matrix_default();
+ dprintf("rgb_matrix_init_drivers eeconfig is not enabled.\n");
+ eeconfig_init();
+ eeconfig_update_rgb_matrix_default();
}
+
rgb_matrix_config.raw = eeconfig_read_rgb_matrix();
+ rgb_matrix_config.speed = UINT8_MAX / 2; //EECONFIG needs to be increased to support this
if (!rgb_matrix_config.mode) {
- dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n");
- eeconfig_update_rgb_matrix_default();
- rgb_matrix_config.raw = eeconfig_read_rgb_matrix();
+ dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n");
+ eeconfig_update_rgb_matrix_default();
+ rgb_matrix_config.raw = eeconfig_read_rgb_matrix();
}
eeconfig_debug_rgb_matrix(); // display current eeprom values
}
-// Deals with the messy details of incrementing an integer
-static uint8_t increment( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) {
- int16_t new_value = value;
- new_value += step;
- return MIN( MAX( new_value, min ), max );
-}
-
-static uint8_t decrement( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) {
- int16_t new_value = value;
- new_value -= step;
- return MIN( MAX( new_value, min ), max );
-}
-
-// void *backlight_get_custom_key_color_eeprom_address( uint8_t led )
-// {
-// // 3 bytes per color
-// return EECONFIG_RGB_MATRIX + ( led * 3 );
-// }
-
-// void backlight_get_key_color( uint8_t led, HSV *hsv )
-// {
-// void *address = backlight_get_custom_key_color_eeprom_address( led );
-// hsv->h = eeprom_read_byte(address);
-// hsv->s = eeprom_read_byte(address+1);
-// hsv->v = eeprom_read_byte(address+2);
-// }
-
-// void backlight_set_key_color( uint8_t row, uint8_t column, HSV hsv )
-// {
-// uint8_t led[8], led_count;
-// map_row_column_to_led(row,column,led,&led_count);
-// for(uint8_t i = 0; i < led_count; i++) {
-// if ( led[i] < DRIVER_LED_TOTAL )
-// {
-// void *address = backlight_get_custom_key_color_eeprom_address(led[i]);
-// eeprom_update_byte(address, hsv.h);
-// eeprom_update_byte(address+1, hsv.s);
-// eeprom_update_byte(address+2, hsv.v);
-// }
-// }
-// }
-
-uint32_t rgb_matrix_get_tick(void) {
- return g_tick;
+void rgb_matrix_set_suspend_state(bool state) {
+ g_suspend_state = state;
}
void rgb_matrix_toggle(void) {
- rgb_matrix_config.enable ^= 1;
- eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
+ rgb_matrix_config.enable++;
+ if (!rgb_matrix_config.enable) {
+ rgb_task_state = STARTING;
+ }
+ eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
}
void rgb_matrix_enable(void) {
rgb_matrix_config.enable = 1;
- eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
+ eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
}
void rgb_matrix_enable_noeeprom(void) {
@@ -903,7 +529,7 @@ void rgb_matrix_enable_noeeprom(void) {
void rgb_matrix_disable(void) {
rgb_matrix_config.enable = 0;
- eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
+ eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
}
void rgb_matrix_disable_noeeprom(void) {
@@ -911,76 +537,79 @@ void rgb_matrix_disable_noeeprom(void) {
}
void rgb_matrix_step(void) {
- rgb_matrix_config.mode++;
- if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX)
- rgb_matrix_config.mode = 1;
- eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
+ rgb_matrix_config.mode++;
+ if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX)
+ rgb_matrix_config.mode = 1;
+ rgb_task_state = STARTING;
+ eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
}
void rgb_matrix_step_reverse(void) {
- rgb_matrix_config.mode--;
- if (rgb_matrix_config.mode < 1)
- rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1;
- eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
+ rgb_matrix_config.mode--;
+ if (rgb_matrix_config.mode < 1)
+ rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1;
+ rgb_task_state = STARTING;
+ eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
}
void rgb_matrix_increase_hue(void) {
- rgb_matrix_config.hue = increment( rgb_matrix_config.hue, 8, 0, 255 );
- eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
+ rgb_matrix_config.hue += RGB_MATRIX_HUE_STEP;
+ eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
}
void rgb_matrix_decrease_hue(void) {
- rgb_matrix_config.hue = decrement( rgb_matrix_config.hue, 8, 0, 255 );
- eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
+ rgb_matrix_config.hue -= RGB_MATRIX_HUE_STEP;
+ eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
}
void rgb_matrix_increase_sat(void) {
- rgb_matrix_config.sat = increment( rgb_matrix_config.sat, 8, 0, 255 );
- eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
+ rgb_matrix_config.sat = qadd8(rgb_matrix_config.sat, RGB_MATRIX_SAT_STEP);
+ eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
}
void rgb_matrix_decrease_sat(void) {
- rgb_matrix_config.sat = decrement( rgb_matrix_config.sat, 8, 0, 255 );
- eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
+ rgb_matrix_config.sat = qsub8(rgb_matrix_config.sat, RGB_MATRIX_SAT_STEP);
+ eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
}
void rgb_matrix_increase_val(void) {
- rgb_matrix_config.val = increment( rgb_matrix_config.val, 8, 0, RGB_MATRIX_MAXIMUM_BRIGHTNESS );
- eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
+ rgb_matrix_config.val = qadd8(rgb_matrix_config.val, RGB_MATRIX_VAL_STEP);
+ if (rgb_matrix_config.val > RGB_MATRIX_MAXIMUM_BRIGHTNESS)
+ rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
+ eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
}
void rgb_matrix_decrease_val(void) {
- rgb_matrix_config.val = decrement( rgb_matrix_config.val, 8, 0, RGB_MATRIX_MAXIMUM_BRIGHTNESS );
- eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
+ rgb_matrix_config.val = qsub8(rgb_matrix_config.val, RGB_MATRIX_VAL_STEP);
+ eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
}
void rgb_matrix_increase_speed(void) {
- rgb_matrix_config.speed = increment( rgb_matrix_config.speed, 1, 0, 3 );
- eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this
+ rgb_matrix_config.speed = qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP);
+ eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this
}
void rgb_matrix_decrease_speed(void) {
- rgb_matrix_config.speed = decrement( rgb_matrix_config.speed, 1, 0, 3 );
- eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this
+ rgb_matrix_config.speed = qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP);
+ eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this
}
void rgb_matrix_mode(uint8_t mode) {
- rgb_matrix_config.mode = mode;
- eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
+ rgb_matrix_config.mode = mode;
+ rgb_task_state = STARTING;
+ eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
}
void rgb_matrix_mode_noeeprom(uint8_t mode) {
- rgb_matrix_config.mode = mode;
+ rgb_matrix_config.mode = mode;
}
uint8_t rgb_matrix_get_mode(void) {
- return rgb_matrix_config.mode;
+ return rgb_matrix_config.mode;
}
void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) {
- rgb_matrix_config.hue = hue;
- rgb_matrix_config.sat = sat;
- rgb_matrix_config.val = val;
+ rgb_matrix_sethsv_noeeprom(hue, sat, val);
eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
}
@@ -988,4 +617,6 @@ void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) {
rgb_matrix_config.hue = hue;
rgb_matrix_config.sat = sat;
rgb_matrix_config.val = val;
+ if (rgb_matrix_config.val > RGB_MATRIX_MAXIMUM_BRIGHTNESS)
+ rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
}
diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h
index e43532d11..855ea0323 100644
--- a/quantum/rgb_matrix.h
+++ b/quantum/rgb_matrix.h
@@ -21,32 +21,33 @@
#include <stdint.h>
#include <stdbool.h>
+#include "rgb_matrix_types.h"
#include "color.h"
#include "quantum.h"
#ifdef IS31FL3731
- #include "is31fl3731.h"
+ #include "is31fl3731.h"
#elif defined (IS31FL3733)
- #include "is31fl3733.h"
+ #include "is31fl3733.h"
#endif
-typedef struct Point {
- uint8_t x;
- uint8_t y;
-} __attribute__((packed)) Point;
+#ifndef RGB_MATRIX_LED_FLUSH_LIMIT
+ #define RGB_MATRIX_LED_FLUSH_LIMIT 16
+#endif
-typedef struct rgb_led {
- union {
- uint8_t raw;
- struct {
- uint8_t row:4; // 16 max
- uint8_t col:4; // 16 max
- };
- } matrix_co;
- Point point;
- uint8_t modifier:1;
-} __attribute__((packed)) rgb_led;
+#ifndef RGB_MATRIX_LED_PROCESS_LIMIT
+ #define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5
+#endif
+#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
+#define RGB_MATRIX_USE_LIMITS(min, max) uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \
+ uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \
+ if (max > DRIVER_LED_TOTAL) \
+ max = DRIVER_LED_TOTAL;
+#else
+#define RGB_MATRIX_USE_LIMITS(min, max) uint8_t min = 0; \
+ uint8_t max = DRIVER_LED_TOTAL;
+#endif
extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
@@ -56,76 +57,73 @@ typedef struct
uint8_t index;
} rgb_indicator;
-typedef union {
- uint32_t raw;
- struct {
- bool enable :1;
- uint8_t mode :6;
- uint16_t hue :9;
- uint8_t sat :8;
- uint8_t val :8;
- uint8_t speed :8;//EECONFIG needs to be increased to support this
- };
-} rgb_config_t;
-
enum rgb_matrix_effects {
+ RGB_MATRIX_NONE = 0,
RGB_MATRIX_SOLID_COLOR = 1,
#ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS
- RGB_MATRIX_ALPHAS_MODS,
-#endif
-#ifndef DISABLE_RGB_MATRIX_DUAL_BEACON
- RGB_MATRIX_DUAL_BEACON,
-#endif
+ RGB_MATRIX_ALPHAS_MODS,
+#endif // DISABLE_RGB_MATRIX_ALPHAS_MODS
#ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
- RGB_MATRIX_GRADIENT_UP_DOWN,
-#endif
-#ifndef DISABLE_RGB_MATRIX_RAINDROPS
- RGB_MATRIX_RAINDROPS,
-#endif
+ RGB_MATRIX_GRADIENT_UP_DOWN,
+#endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
+#ifndef DISABLE_RGB_MATRIX_BREATHING
+ RGB_MATRIX_BREATHING,
+#endif // DISABLE_RGB_MATRIX_BREATHING
#ifndef DISABLE_RGB_MATRIX_CYCLE_ALL
- RGB_MATRIX_CYCLE_ALL,
-#endif
+ RGB_MATRIX_CYCLE_ALL,
+#endif // DISABLE_RGB_MATRIX_CYCLE_ALL
#ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
- RGB_MATRIX_CYCLE_LEFT_RIGHT,
-#endif
+ RGB_MATRIX_CYCLE_LEFT_RIGHT,
+#endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
#ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
- RGB_MATRIX_CYCLE_UP_DOWN,
-#endif
+ RGB_MATRIX_CYCLE_UP_DOWN,
+#endif // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
+#ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
+ RGB_MATRIX_RAINBOW_MOVING_CHEVRON,
+#endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
+#ifndef DISABLE_RGB_MATRIX_DUAL_BEACON
+ RGB_MATRIX_DUAL_BEACON,
+#endif // DISABLE_RGB_MATRIX_DUAL_BEACON
#ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON
- RGB_MATRIX_RAINBOW_BEACON,
-#endif
+ RGB_MATRIX_RAINBOW_BEACON,
+#endif // DISABLE_RGB_MATRIX_RAINBOW_BEACON
#ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
- RGB_MATRIX_RAINBOW_PINWHEELS,
-#endif
-#ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
- RGB_MATRIX_RAINBOW_MOVING_CHEVRON,
-#endif
+ RGB_MATRIX_RAINBOW_PINWHEELS,
+#endif // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
+#ifndef DISABLE_RGB_MATRIX_RAINDROPS
+ RGB_MATRIX_RAINDROPS,
+#endif // DISABLE_RGB_MATRIX_RAINDROPS
#ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
- RGB_MATRIX_JELLYBEAN_RAINDROPS,
-#endif
+ RGB_MATRIX_JELLYBEAN_RAINDROPS,
+#endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
#ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN
- RGB_MATRIX_DIGITAL_RAIN,
-#endif
-#ifdef RGB_MATRIX_KEYPRESSES
- #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE
- RGB_MATRIX_SOLID_REACTIVE,
- #endif
- #ifndef DISABLE_RGB_MATRIX_SPLASH
- RGB_MATRIX_SPLASH,
- #endif
- #ifndef DISABLE_RGB_MATRIX_MULTISPLASH
- RGB_MATRIX_MULTISPLASH,
- #endif
- #ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH
- RGB_MATRIX_SOLID_SPLASH,
- #endif
- #ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
- RGB_MATRIX_SOLID_MULTISPLASH,
- #endif
-#endif
- RGB_MATRIX_EFFECT_MAX
+ RGB_MATRIX_DIGITAL_RAIN,
+#endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN
+#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
+#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
+ RGB_MATRIX_SOLID_REACTIVE_SIMPLE,
+#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
+#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE
+ RGB_MATRIX_SOLID_REACTIVE,
+#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE
+#ifndef DISABLE_RGB_MATRIX_SPLASH
+ RGB_MATRIX_SPLASH,
+#endif // DISABLE_RGB_MATRIX_SPLASH
+#ifndef DISABLE_RGB_MATRIX_MULTISPLASH
+ RGB_MATRIX_MULTISPLASH,
+#endif // DISABLE_RGB_MATRIX_MULTISPLASH
+#ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH
+ RGB_MATRIX_SOLID_SPLASH,
+#endif // DISABLE_RGB_MATRIX_SOLID_SPLASH
+#ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
+ RGB_MATRIX_SOLID_MULTISPLASH,
+#endif // DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
+#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+ RGB_MATRIX_EFFECT_MAX
};
+uint8_t rgb_matrix_map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i);
+
void rgb_matrix_set_color( int 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 );
@@ -159,8 +157,6 @@ void rgb_matrix_decrease(void);
// void backlight_get_key_color( uint8_t led, HSV *hsv );
// void backlight_set_key_color( uint8_t row, uint8_t column, HSV hsv );
-uint32_t rgb_matrix_get_tick(void);
-
void rgb_matrix_toggle(void);
void rgb_matrix_enable(void);
void rgb_matrix_enable_noeeprom(void);
@@ -209,7 +205,6 @@ uint8_t rgb_matrix_get_mode(void);
typedef struct {
/* Perform any initialisation required for the other driver functions to work. */
void (*init)(void);
-
/* Set the colour of a single LED in the buffer. */
void (*set_color)(int index, uint8_t r, uint8_t g, uint8_t b);
/* Set the colour of all LEDS on the keyboard in the buffer. */
diff --git a/quantum/rgb_matrix_animations/alpha_mods_anim.h b/quantum/rgb_matrix_animations/alpha_mods_anim.h
new file mode 100644
index 000000000..cc1914d7f
--- /dev/null
+++ b/quantum/rgb_matrix_animations/alpha_mods_anim.h
@@ -0,0 +1,26 @@
+#pragma once
+#ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS
+
+extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
+extern rgb_config_t rgb_matrix_config;
+
+// alphas = color1, mods = color2
+bool rgb_matrix_alphas_mods(effect_params_t* params) {
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+ HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, rgb_matrix_config.val };
+ RGB rgb1 = hsv_to_rgb(hsv);
+ hsv.h += rgb_matrix_config.speed;
+ RGB rgb2 = hsv_to_rgb(hsv);
+
+ for (uint8_t i = led_min; i < led_max; i++) {
+ if (g_rgb_leds[i].modifier) {
+ rgb_matrix_set_color(i, rgb2.r, rgb2.g, rgb2.b);
+ } else {
+ rgb_matrix_set_color(i, rgb1.r, rgb1.g, rgb1.b);
+ }
+ }
+ return led_max < DRIVER_LED_TOTAL;
+}
+
+#endif // DISABLE_RGB_MATRIX_ALPHAS_MODS
diff --git a/quantum/rgb_matrix_animations/breathing_anim.h b/quantum/rgb_matrix_animations/breathing_anim.h
new file mode 100644
index 000000000..4a9a1dcdb
--- /dev/null
+++ b/quantum/rgb_matrix_animations/breathing_anim.h
@@ -0,0 +1,20 @@
+#pragma once
+#ifndef DISABLE_RGB_MATRIX_BREATHING
+
+extern rgb_counters_t g_rgb_counters;
+extern rgb_config_t rgb_matrix_config;
+
+bool rgb_matrix_breathing(effect_params_t* params) {
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+ uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 8);
+ uint8_t val = scale8(abs8(sin8(time) - 128) * 2, rgb_matrix_config.val);
+ HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, val };
+ RGB rgb = hsv_to_rgb(hsv);
+ for (uint8_t i = led_min; i < led_max; i++) {
+ rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+ }
+ return led_max < DRIVER_LED_TOTAL;
+}
+
+#endif // DISABLE_RGB_MATRIX_BREATHING
diff --git a/quantum/rgb_matrix_animations/cycle_all_anim.h b/quantum/rgb_matrix_animations/cycle_all_anim.h
new file mode 100644
index 000000000..5c18cfa0c
--- /dev/null
+++ b/quantum/rgb_matrix_animations/cycle_all_anim.h
@@ -0,0 +1,21 @@
+#pragma once
+#ifndef DISABLE_RGB_MATRIX_CYCLE_ALL
+
+extern rgb_counters_t g_rgb_counters;
+extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
+extern rgb_config_t rgb_matrix_config;
+
+bool rgb_matrix_cycle_all(effect_params_t* params) {
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+ HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };
+ uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
+ for (uint8_t i = led_min; i < led_max; i++) {
+ hsv.h = time;
+ RGB rgb = hsv_to_rgb(hsv);
+ rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+ }
+ return led_max < DRIVER_LED_TOTAL;
+}
+
+#endif // DISABLE_RGB_MATRIX_CYCLE_ALL
diff --git a/quantum/rgb_matrix_animations/cycle_left_right_anim.h b/quantum/rgb_matrix_animations/cycle_left_right_anim.h
new file mode 100644
index 000000000..f519aeb47
--- /dev/null
+++ b/quantum/rgb_matrix_animations/cycle_left_right_anim.h
@@ -0,0 +1,22 @@
+#pragma once
+#ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
+
+extern rgb_counters_t g_rgb_counters;
+extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
+extern rgb_config_t rgb_matrix_config;
+
+bool rgb_matrix_cycle_left_right(effect_params_t* params) {
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+ HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };
+ uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
+ for (uint8_t i = led_min; i < led_max; i++) {
+ point_t point = g_rgb_leds[i].point;
+ hsv.h = point.x - time;
+ RGB rgb = hsv_to_rgb(hsv);
+ rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+ }
+ return led_max < DRIVER_LED_TOTAL;
+}
+
+#endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
diff --git a/quantum/rgb_matrix_animations/cycle_up_down_anim.h b/quantum/rgb_matrix_animations/cycle_up_down_anim.h
new file mode 100644
index 000000000..8b91d890d
--- /dev/null
+++ b/quantum/rgb_matrix_animations/cycle_up_down_anim.h
@@ -0,0 +1,22 @@
+#pragma once
+#ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
+
+extern rgb_counters_t g_rgb_counters;
+extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
+extern rgb_config_t rgb_matrix_config;
+
+bool rgb_matrix_cycle_up_down(effect_params_t* params) {
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+ HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };
+ uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
+ for (uint8_t i = led_min; i < led_max; i++) {
+ point_t point = g_rgb_leds[i].point;
+ hsv.h = point.y - time;
+ RGB rgb = hsv_to_rgb(hsv);
+ rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+ }
+ return led_max < DRIVER_LED_TOTAL;
+}
+
+#endif // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
diff --git a/quantum/rgb_matrix_animations/digital_rain_anim.h b/quantum/rgb_matrix_animations/digital_rain_anim.h
new file mode 100644
index 000000000..4ba3c1c87
--- /dev/null
+++ b/quantum/rgb_matrix_animations/digital_rain_anim.h
@@ -0,0 +1,74 @@
+#pragma once
+#ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN
+
+#ifndef RGB_DIGITAL_RAIN_DROPS
+ // lower the number for denser effect/wider keyboard
+ #define RGB_DIGITAL_RAIN_DROPS 24
+#endif
+
+bool rgb_matrix_digital_rain(effect_params_t* params) {
+ // algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain
+ const uint8_t drop_ticks = 28;
+ const uint8_t pure_green_intensity = 0xd0;
+ const uint8_t max_brightness_boost = 0xc0;
+ const uint8_t max_intensity = 0xff;
+
+ static uint8_t map[MATRIX_COLS][MATRIX_ROWS] = {{0}};
+ static uint8_t drop = 0;
+
+ if (params->init) {
+ rgb_matrix_set_color_all(0, 0, 0);
+ memset(map, 0, sizeof map);
+ drop = 0;
+ }
+ for (uint8_t col = 0; col < MATRIX_COLS; col++) {
+ for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
+ if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) {
+ // top row, pixels have just fallen and we're
+ // making a new rain drop in this column
+ map[col][row] = max_intensity;
+ }
+ else if (map[col][row] > 0 && map[col][row] < max_intensity) {
+ // neither fully bright nor dark, decay it
+ map[col][row]--;
+ }
+ // set the pixel colour
+ uint8_t led[LED_HITS_TO_REMEMBER];
+ uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led);
+
+ // TODO: multiple leds are supported mapped to the same row/column
+ if (led_count > 0) {
+ if (map[col][row] > pure_green_intensity) {
+ const uint8_t boost = (uint8_t) ((uint16_t) max_brightness_boost * (map[col][row] - pure_green_intensity) / (max_intensity - pure_green_intensity));
+ rgb_matrix_set_color(led[0], boost, max_intensity, boost);
+ }
+ else {
+ const uint8_t green = (uint8_t) ((uint16_t) max_intensity * map[col][row] / pure_green_intensity);
+ rgb_matrix_set_color(led[0], 0, green, 0);
+ }
+ }
+ }
+ }
+ if (++drop > drop_ticks) {
+ // reset drop timer
+ drop = 0;
+ for (uint8_t row = MATRIX_ROWS - 1; row > 0; row--) {
+ for (uint8_t col = 0; col < MATRIX_COLS; col++) {
+ // if ths is on the bottom row and bright allow decay
+ if (row == MATRIX_ROWS - 1 && map[col][row] == max_intensity) {
+ map[col][row]--;
+ }
+ // check if the pixel above is bright
+ if (map[col][row - 1] == max_intensity) {
+ // allow old bright pixel to decay
+ map[col][row - 1]--;
+ // make this pixel bright
+ map[col][row] = max_intensity;
+ }
+ }
+ }
+ }
+ return false;
+}
+
+#endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN
diff --git a/quantum/rgb_matrix_animations/dual_beacon_anim.h b/quantum/rgb_matrix_animations/dual_beacon_anim.h
new file mode 100644
index 000000000..dda315780
--- /dev/null
+++ b/quantum/rgb_matrix_animations/dual_beacon_anim.h
@@ -0,0 +1,24 @@
+#pragma once
+#ifndef DISABLE_RGB_MATRIX_DUAL_BEACON
+
+extern rgb_counters_t g_rgb_counters;
+extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
+extern rgb_config_t rgb_matrix_config;
+
+bool rgb_matrix_dual_beacon(effect_params_t* params) {
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+ HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };
+ uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
+ int8_t cos_value = cos8(time) - 128;
+ int8_t sin_value = sin8(time) - 128;
+ for (uint8_t i = led_min; i < led_max; i++) {
+ point_t point = g_rgb_leds[i].point;
+ hsv.h = ((point.y - 32) * cos_value + (point.x - 112) * sin_value) / 128 + rgb_matrix_config.hue;
+ RGB rgb = hsv_to_rgb(hsv);
+ rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+ }
+ return led_max < DRIVER_LED_TOTAL;
+}
+
+#endif // DISABLE_RGB_MATRIX_DUAL_BEACON
diff --git a/quantum/rgb_matrix_animations/gradient_up_down_anim.h b/quantum/rgb_matrix_animations/gradient_up_down_anim.h
new file mode 100644
index 000000000..11498e22f
--- /dev/null
+++ b/quantum/rgb_matrix_animations/gradient_up_down_anim.h
@@ -0,0 +1,22 @@
+#pragma once
+#ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
+
+extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
+extern rgb_config_t rgb_matrix_config;
+
+bool rgb_matrix_gradient_up_down(effect_params_t* params) {
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+ HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };
+ uint8_t scale = scale8(64, rgb_matrix_config.speed);
+ for (uint8_t i = led_min; i < led_max; i++) {
+ point_t point = g_rgb_leds[i].point;
+ // The y range will be 0..64, map this to 0..4
+ // Relies on hue being 8-bit and wrapping
+ hsv.h = rgb_matrix_config.hue + scale * (point.y >> 4);
+ RGB rgb = hsv_to_rgb(hsv);
+ rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+ }
+ return led_max < DRIVER_LED_TOTAL;
+}
+#endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
diff --git a/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h b/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h
new file mode 100644
index 000000000..01ff5c230
--- /dev/null
+++ b/quantum/rgb_matrix_animations/jellybean_raindrops_anim.h
@@ -0,0 +1,30 @@
+#pragma once
+#ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
+
+extern rgb_counters_t g_rgb_counters;
+extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
+extern rgb_config_t rgb_matrix_config;
+
+static void jellybean_raindrops_set_color(int i) {
+ HSV hsv = { rand() & 0xFF , rand() & 0xFF, rgb_matrix_config.val };
+ RGB rgb = hsv_to_rgb(hsv);
+ rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+}
+
+bool rgb_matrix_jellybean_raindrops(effect_params_t* params) {
+ if (!params->init) {
+ // Change one LED every tick, make sure speed is not 0
+ if (scale16by8(g_rgb_counters.tick, qadd8(rgb_matrix_config.speed, 16)) % 5 == 0) {
+ jellybean_raindrops_set_color(rand() % DRIVER_LED_TOTAL);
+ }
+ return false;
+ }
+
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+ for (int i = led_min; i < led_max; i++) {
+ jellybean_raindrops_set_color(i);
+ }
+ return led_max < DRIVER_LED_TOTAL;
+}
+
+#endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
diff --git a/quantum/rgb_matrix_animations/rainbow_beacon_anim.h b/quantum/rgb_matrix_animations/rainbow_beacon_anim.h
new file mode 100644
index 000000000..3c15e64ab
--- /dev/null
+++ b/quantum/rgb_matrix_animations/rainbow_beacon_anim.h
@@ -0,0 +1,24 @@
+#pragma once
+#ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON
+
+extern rgb_counters_t g_rgb_counters;
+extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
+extern rgb_config_t rgb_matrix_config;
+
+bool rgb_matrix_rainbow_beacon(effect_params_t* params) {
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+ HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };
+ uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
+ int16_t cos_value = 2 * (cos8(time) - 128);
+ int16_t sin_value = 2 * (sin8(time) - 128);
+ for (uint8_t i = led_min; i < led_max; i++) {
+ point_t point = g_rgb_leds[i].point;
+ hsv.h = ((point.y - 32) * cos_value + (point.x - 112) * sin_value) / 128 + rgb_matrix_config.hue;
+ RGB rgb = hsv_to_rgb(hsv);
+ rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+ }
+ return led_max < DRIVER_LED_TOTAL;
+}
+
+#endif // DISABLE_RGB_MATRIX_RAINBOW_BEACON
diff --git a/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h b/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h
new file mode 100644
index 000000000..0d11d5280
--- /dev/null
+++ b/quantum/rgb_matrix_animations/rainbow_moving_chevron_anim.h
@@ -0,0 +1,22 @@
+#pragma once
+#ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
+
+extern rgb_counters_t g_rgb_counters;
+extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
+extern rgb_config_t rgb_matrix_config;
+
+bool rgb_matrix_rainbow_moving_chevron(effect_params_t* params) {
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+ HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };
+ uint8_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
+ for (uint8_t i = led_min; i < led_max; i++) {
+ point_t point = g_rgb_leds[i].point;
+ hsv.h = abs8(point.y - 32) + (point.x - time) + rgb_matrix_config.hue;
+ RGB rgb = hsv_to_rgb(hsv);
+ rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+ }
+ return led_max < DRIVER_LED_TOTAL;
+}
+
+#endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
diff --git a/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h b/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h
new file mode 100644
index 000000000..d7cd42cbe
--- /dev/null
+++ b/quantum/rgb_matrix_animations/rainbow_pinwheels_anim.h
@@ -0,0 +1,24 @@
+#pragma once
+#ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
+
+extern rgb_counters_t g_rgb_counters;
+extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
+extern rgb_config_t rgb_matrix_config;
+
+bool rgb_matrix_rainbow_pinwheels(effect_params_t* params) {
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+ HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };
+ uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 4);
+ int16_t cos_value = 3 * (cos8(time) - 128);
+ int16_t sin_value = 3 * (sin8(time) - 128);
+ for (uint8_t i = led_min; i < led_max; i++) {
+ point_t point = g_rgb_leds[i].point;
+ hsv.h = ((point.y - 32) * cos_value + (56 - abs8(point.x - 112)) * sin_value) / 128 + rgb_matrix_config.hue;
+ RGB rgb = hsv_to_rgb(hsv);
+ rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+ }
+ return led_max < DRIVER_LED_TOTAL;
+}
+
+#endif // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
diff --git a/quantum/rgb_matrix_animations/raindrops_anim.h b/quantum/rgb_matrix_animations/raindrops_anim.h
new file mode 100644
index 000000000..fc721375b
--- /dev/null
+++ b/quantum/rgb_matrix_animations/raindrops_anim.h
@@ -0,0 +1,40 @@
+#pragma once
+#ifndef DISABLE_RGB_MATRIX_RAINDROPS
+#include "rgb_matrix_types.h"
+
+extern rgb_counters_t g_rgb_counters;
+extern rgb_config_t rgb_matrix_config;
+
+static void raindrops_set_color(int i) {
+ HSV hsv = { 0 , rgb_matrix_config.sat, rgb_matrix_config.val };
+
+ // Take the shortest path between hues
+ int16_t deltaH = ((rgb_matrix_config.hue + 180) % 360 - rgb_matrix_config.hue) / 4;
+ if (deltaH > 127) {
+ deltaH -= 256;
+ } else if (deltaH < -127) {
+ deltaH += 256;
+ }
+
+ hsv.h = rgb_matrix_config.hue + (deltaH * (rand() & 0x03));
+ RGB rgb = hsv_to_rgb(hsv);
+ rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+}
+
+bool rgb_matrix_raindrops(effect_params_t* params) {
+ if (!params->init) {
+ // Change one LED every tick, make sure speed is not 0
+ if (scale16by8(g_rgb_counters.tick, qadd8(rgb_matrix_config.speed, 16)) % 10 == 0) {
+ raindrops_set_color(rand() % DRIVER_LED_TOTAL);
+ }
+ return false;
+ }
+
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+ for (int i = led_min; i < led_max; i++) {
+ raindrops_set_color(i);
+ }
+ return led_max < DRIVER_LED_TOTAL;
+}
+
+#endif // DISABLE_RGB_MATRIX_RAINDROPS
diff --git a/quantum/rgb_matrix_animations/solid_color_anim.h b/quantum/rgb_matrix_animations/solid_color_anim.h
new file mode 100644
index 000000000..24a197beb
--- /dev/null
+++ b/quantum/rgb_matrix_animations/solid_color_anim.h
@@ -0,0 +1,14 @@
+#pragma once
+
+extern rgb_config_t rgb_matrix_config;
+
+bool rgb_matrix_solid_color(effect_params_t* params) {
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+ HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, rgb_matrix_config.val };
+ RGB rgb = hsv_to_rgb(hsv);
+ for (uint8_t i = led_min; i < led_max; i++) {
+ rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+ }
+ return led_max < DRIVER_LED_TOTAL;
+}
diff --git a/quantum/rgb_matrix_animations/solid_reactive_anim.h b/quantum/rgb_matrix_animations/solid_reactive_anim.h
new file mode 100644
index 000000000..220e54233
--- /dev/null
+++ b/quantum/rgb_matrix_animations/solid_reactive_anim.h
@@ -0,0 +1,33 @@
+#pragma once
+#if defined(RGB_MATRIX_KEYREACTIVE_ENABLED)
+#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE
+
+extern rgb_config_t rgb_matrix_config;
+extern last_hit_t g_last_hit_tracker;
+
+bool rgb_matrix_solid_reactive(effect_params_t* params) {
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+ HSV hsv = { rgb_matrix_config.hue, 255, rgb_matrix_config.val };
+ // Max tick based on speed scale ensures results from scale16by8 with rgb_matrix_config.speed are no greater than 255
+ uint16_t max_tick = 65535 / rgb_matrix_config.speed;
+ // Relies on hue being 8-bit and wrapping
+ for (uint8_t i = led_min; i < led_max; i++) {
+ uint16_t tick = max_tick;
+ for(uint8_t j = 0; j < g_last_hit_tracker.count; j++) {
+ if (g_last_hit_tracker.index[j] == i && g_last_hit_tracker.tick[j] < tick) {
+ tick = g_last_hit_tracker.tick[j];
+ break;
+ }
+ }
+
+ uint16_t offset = scale16by8(tick, rgb_matrix_config.speed);
+ hsv.h = rgb_matrix_config.hue + qsub8(130, offset);
+ RGB rgb = hsv_to_rgb(hsv);
+ rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+ }
+ return led_max < DRIVER_LED_TOTAL;
+}
+
+#endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
+#endif // defined(RGB_MATRIX_KEYREACTIVE_ENABLED)
diff --git a/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h b/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h
new file mode 100644
index 000000000..e84cd6939
--- /dev/null
+++ b/quantum/rgb_matrix_animations/solid_reactive_simple_anim.h
@@ -0,0 +1,32 @@
+#pragma once
+#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
+#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
+
+extern rgb_config_t rgb_matrix_config;
+extern last_hit_t g_last_hit_tracker;
+
+bool rgb_matrix_solid_reactive_simple(effect_params_t* params) {
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+ HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 };
+ // Max tick based on speed scale ensures results from scale16by8 with rgb_matrix_config.speed are no greater than 255
+ uint16_t max_tick = 65535 / rgb_matrix_config.speed;
+ for (uint8_t i = led_min; i < led_max; i++) {
+ uint16_t tick = max_tick;
+ for(uint8_t j = 0; j < g_last_hit_tracker.count; j++) {
+ if (g_last_hit_tracker.index[j] == i && g_last_hit_tracker.tick[j] < tick) {
+ tick = g_last_hit_tracker.tick[j];
+ break;
+ }
+ }
+
+ uint16_t offset = scale16by8(tick, rgb_matrix_config.speed);
+ hsv.v = scale8(255 - offset, rgb_matrix_config.val);
+ RGB rgb = hsv_to_rgb(hsv);
+ rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+ }
+ return led_max < DRIVER_LED_TOTAL;
+}
+
+#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
+#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
diff --git a/quantum/rgb_matrix_animations/solid_splash_anim.h b/quantum/rgb_matrix_animations/solid_splash_anim.h
new file mode 100644
index 000000000..82ac055b8
--- /dev/null
+++ b/quantum/rgb_matrix_animations/solid_splash_anim.h
@@ -0,0 +1,42 @@
+#pragma once
+#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
+#if !defined(DISABLE_RGB_MATRIX_SOLID_SPLASH) || !defined(DISABLE_RGB_MATRIX_SOLID_MULTISPLASH)
+
+extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
+extern rgb_config_t rgb_matrix_config;
+extern last_hit_t g_last_hit_tracker;
+
+static bool rgb_matrix_solid_multisplash_range(uint8_t start, effect_params_t* params) {
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+ HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 };
+ uint8_t count = g_last_hit_tracker.count;
+ for (uint8_t i = led_min; i < led_max; i++) {
+ hsv.v = 0;
+ point_t point = g_rgb_leds[i].point;
+ for (uint8_t j = start; j < count; j++) {
+ int16_t dx = point.x - g_last_hit_tracker.x[j];
+ int16_t dy = point.y - g_last_hit_tracker.y[j];
+ uint8_t dist = sqrt16(dx * dx + dy * dy);
+ uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) - dist;
+ if (effect > 255)
+ effect = 255;
+ hsv.v = qadd8(hsv.v, 255 - effect);
+ }
+ hsv.v = scale8(hsv.v, rgb_matrix_config.val);
+ RGB rgb = hsv_to_rgb(hsv);
+ rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+ }
+ return led_max < DRIVER_LED_TOTAL;
+}
+
+bool rgb_matrix_solid_multisplash(effect_params_t* params) {
+ return rgb_matrix_solid_multisplash_range(0, params);
+}
+
+bool rgb_matrix_solid_splash(effect_params_t* params) {
+ return rgb_matrix_solid_multisplash_range(qsub8(g_last_hit_tracker.count, 1), params);
+}
+
+#endif // !defined(DISABLE_RGB_MATRIX_SPLASH) && !defined(DISABLE_RGB_MATRIX_MULTISPLASH)
+#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
diff --git a/quantum/rgb_matrix_animations/splash_anim.h b/quantum/rgb_matrix_animations/splash_anim.h
new file mode 100644
index 000000000..829d30eef
--- /dev/null
+++ b/quantum/rgb_matrix_animations/splash_anim.h
@@ -0,0 +1,44 @@
+#pragma once
+#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
+#if !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH)
+
+extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
+extern rgb_config_t rgb_matrix_config;
+extern last_hit_t g_last_hit_tracker;
+
+static bool rgb_matrix_multisplash_range(uint8_t start, effect_params_t* params) {
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+ HSV hsv = { 0, rgb_matrix_config.sat, 0 };
+ uint8_t count = g_last_hit_tracker.count;
+ for (uint8_t i = led_min; i < led_max; i++) {
+ hsv.h = rgb_matrix_config.hue;
+ hsv.v = 0;
+ point_t point = g_rgb_leds[i].point;
+ for (uint8_t j = start; j < count; j++) {
+ int16_t dx = point.x - g_last_hit_tracker.x[j];
+ int16_t dy = point.y - g_last_hit_tracker.y[j];
+ uint8_t dist = sqrt16(dx * dx + dy * dy);
+ uint16_t effect = scale16by8(g_last_hit_tracker.tick[j], rgb_matrix_config.speed) - dist;
+ if (effect > 255)
+ effect = 255;
+ hsv.h += effect;
+ hsv.v = qadd8(hsv.v, 255 - effect);
+ }
+ hsv.v = scale8(hsv.v, rgb_matrix_config.val);
+ RGB rgb = hsv_to_rgb(hsv);
+ rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
+ }
+ return led_max < DRIVER_LED_TOTAL;
+}
+
+bool rgb_matrix_multisplash(effect_params_t* params) {
+ return rgb_matrix_multisplash_range(0, params);
+}
+
+bool rgb_matrix_splash(effect_params_t* params) {
+ return rgb_matrix_multisplash_range(qsub8(g_last_hit_tracker.count, 1), params);
+}
+
+#endif // !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH)
+#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
diff --git a/quantum/rgb_matrix_types.h b/quantum/rgb_matrix_types.h
new file mode 100644
index 000000000..908e96da5
--- /dev/null
+++ b/quantum/rgb_matrix_types.h
@@ -0,0 +1,97 @@
+#pragma once
+
+#include <stdint.h>
+#include <stdbool.h>
+
+#if defined(__GNUC__)
+#define PACKED __attribute__ ((__packed__))
+#else
+#define PACKED
+#endif
+
+#if defined(_MSC_VER)
+#pragma pack( push, 1 )
+#endif
+
+#if defined(RGB_MATRIX_KEYPRESSES) || defined(RGB_MATRIX_KEYRELEASES)
+ #define RGB_MATRIX_KEYREACTIVE_ENABLED
+#endif
+
+// Last led hit
+#ifndef LED_HITS_TO_REMEMBER
+ #define LED_HITS_TO_REMEMBER 8
+#endif // LED_HITS_TO_REMEMBER
+
+#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
+typedef struct PACKED {
+ uint8_t count;
+ uint8_t x[LED_HITS_TO_REMEMBER];
+ uint8_t y[LED_HITS_TO_REMEMBER];
+ uint8_t index[LED_HITS_TO_REMEMBER];
+ uint16_t tick[LED_HITS_TO_REMEMBER];
+} last_hit_t;
+#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
+
+typedef enum rgb_task_states {
+ STARTING,
+ RENDERING,
+ FLUSHING,
+ SYNCING
+} rgb_task_states;
+
+typedef uint8_t led_flags_t;
+
+typedef struct PACKED {
+ uint8_t iter;
+ led_flags_t flags;
+ bool init;
+} effect_params_t;
+
+typedef struct PACKED {
+ // Global tick at 20 Hz
+ uint32_t tick;
+ // Ticks since this key was last hit.
+ uint32_t any_key_hit;
+} rgb_counters_t;
+
+typedef struct PACKED {
+ uint8_t x;
+ uint8_t y;
+} point_t;
+
+typedef union {
+ uint8_t raw;
+ struct {
+ uint8_t row:4; // 16 max
+ uint8_t col:4; // 16 max
+ };
+} matrix_co_t;
+
+typedef struct PACKED {
+ matrix_co_t matrix_co;
+ point_t point;
+ uint8_t modifier:1;
+} rgb_led;
+
+typedef enum {
+ RGB_ZONE_OFF = 0,
+ RGB_ZONE_ALL,
+ RGB_ZONE_KEYS,
+ RGB_ZONE_UNDER,
+} rgb_zone_t;
+
+typedef union {
+ uint32_t raw;
+ struct PACKED {
+ uint8_t enable :2;
+ uint8_t mode :6;
+ uint8_t hue :8;
+ uint8_t sat :8;
+ uint8_t val :8;
+ uint8_t speed :8;//EECONFIG needs to be increased to support this
+ };
+} rgb_config_t;
+
+#if defined(_MSC_VER)
+#pragma pack( pop )
+#endif
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index 52e0be8ba..08515564b 100644
--- a/quantum/rgblight.c
+++ b/quantum/rgblight.c
@@ -51,6 +51,10 @@ static inline int is_static_effect(uint8_t mode) {
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
+#ifdef RGBLIGHT_LED_MAP
+const uint8_t led_map[] PROGMEM = RGBLIGHT_LED_MAP;
+#endif
+
#ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT
__attribute__ ((weak))
const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90};
@@ -62,6 +66,15 @@ bool is_rgblight_initialized = false;
LED_TYPE led[RGBLED_NUM];
bool rgblight_timer_enabled = false;
+static uint8_t clipping_start_pos = 0;
+static uint8_t clipping_num_leds = RGBLED_NUM;
+
+void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds) {
+ clipping_start_pos = start_pos;
+ clipping_num_leds = num_leds;
+}
+
+
void sethsv(uint16_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) {
uint8_t r = 0, g = 0, b = 0, base, color;
@@ -225,11 +238,14 @@ void rgblight_init(void) {
}
+uint32_t rgblight_read_dword(void) {
+ return rgblight_config.raw;
+}
+
void rgblight_update_dword(uint32_t dword) {
rgblight_config.raw = dword;
- eeconfig_update_rgblight(rgblight_config.raw);
if (rgblight_config.enable)
- rgblight_mode(rgblight_config.mode);
+ rgblight_mode_noeeprom(rgblight_config.mode);
else {
#ifdef RGBLIGHT_USE_TIMER
rgblight_timer_disable();
@@ -614,7 +630,7 @@ void rgblight_sethsv_at(uint16_t hue, uint8_t sat, uint8_t val, uint8_t index) {
|| defined(RGBLIGHT_EFFECT_SNAKE) || defined(RGBLIGHT_EFFECT_KNIGHT)
static uint8_t get_interval_time(const uint8_t* default_interval_address, uint8_t velocikey_min, uint8_t velocikey_max) {
- return
+ return
#ifdef VELOCIKEY_ENABLE
velocikey_enabled() ? velocikey_match_speed(velocikey_min, velocikey_max) :
#endif
@@ -661,11 +677,20 @@ void rgblight_sethsv_slave(uint16_t hue, uint8_t sat, uint8_t val) {
#ifndef RGBLIGHT_CUSTOM_DRIVER
void rgblight_set(void) {
+ LED_TYPE *start_led = led + clipping_start_pos;
+ uint16_t num_leds = clipping_num_leds;
if (rgblight_config.enable) {
+ #ifdef RGBLIGHT_LED_MAP
+ LED_TYPE led0[RGBLED_NUM];
+ for(uint8_t i = 0; i < RGBLED_NUM; i++) {
+ led0[i] = led[pgm_read_byte(&led_map[i])];
+ }
+ start_led = led0 + clipping_start_pos;
+ #endif
#ifdef RGBW
- ws2812_setleds_rgbw(led, RGBLED_NUM);
+ ws2812_setleds_rgbw(start_led, num_leds);
#else
- ws2812_setleds(led, RGBLED_NUM);
+ ws2812_setleds(start_led, num_leds);
#endif
} else {
for (uint8_t i = 0; i < RGBLED_NUM; i++) {
@@ -674,9 +699,9 @@ void rgblight_set(void) {
led[i].b = 0;
}
#ifdef RGBW
- ws2812_setleds_rgbw(led, RGBLED_NUM);
+ ws2812_setleds_rgbw(start_led, num_leds);
#else
- ws2812_setleds(led, RGBLED_NUM);
+ ws2812_setleds(start_led, num_leds);
#endif
}
}
@@ -796,7 +821,7 @@ void rgblight_effect_breathing(uint8_t interval) {
float val;
uint8_t interval_time = get_interval_time(&RGBLED_BREATHING_INTERVALS[interval], 1, 100);
-
+
if (timer_elapsed(last_timer) < interval_time) {
return;
}
diff --git a/quantum/rgblight.h b/quantum/rgblight.h
index f92388c96..1769f719d 100644
--- a/quantum/rgblight.h
+++ b/quantum/rgblight.h
@@ -174,6 +174,7 @@ void rgblight_step_reverse(void);
uint8_t rgblight_get_mode(void);
void rgblight_mode(uint8_t mode);
void rgblight_set(void);
+uint32_t rgblight_read_dword(void);
void rgblight_update_dword(uint32_t dword);
void rgblight_increase_hue(void);
void rgblight_decrease_hue(void);
@@ -196,6 +197,7 @@ void rgblight_setrgb_master(uint8_t r, uint8_t g, uint8_t b);
void rgblight_setrgb_slave(uint8_t r, uint8_t g, uint8_t b);
void rgblight_sethsv_master(uint16_t hue, uint8_t sat, uint8_t val);
void rgblight_sethsv_slave(uint16_t hue, uint8_t sat, uint8_t val);
+void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds);
uint32_t eeconfig_read_rgblight(void);
void eeconfig_update_rgblight(uint32_t val);
diff --git a/quantum/split_common/i2c.c b/quantum/split_common/i2c.c
deleted file mode 100644
index 45e958b39..000000000
--- a/quantum/split_common/i2c.c
+++ /dev/null
@@ -1,184 +0,0 @@
-#include <util/twi.h>
-#include <avr/io.h>
-#include <stdlib.h>
-#include <avr/interrupt.h>
-#include <util/twi.h>
-#include <stdbool.h>
-#include "i2c.h"
-#include "split_flags.h"
-
-// Limits the amount of we wait for any one i2c transaction.
-// Since were running SCL line 100kHz (=> 10μs/bit), and each transactions is
-// 9 bits, a single transaction will take around 90μs to complete.
-//
-// (F_CPU/SCL_CLOCK) => # of μC cycles to transfer a bit
-// poll loop takes at least 8 clock cycles to execute
-#define I2C_LOOP_TIMEOUT (9+1)*(F_CPU/SCL_CLOCK)/8
-
-#define BUFFER_POS_INC() (slave_buffer_pos = (slave_buffer_pos+1)%SLAVE_BUFFER_SIZE)
-
-volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE];
-
-static volatile uint8_t slave_buffer_pos;
-static volatile bool slave_has_register_set = false;
-
-// Wait for an i2c operation to finish
-inline static
-void i2c_delay(void) {
- uint16_t lim = 0;
- while(!(TWCR & (1<<TWINT)) && lim < I2C_LOOP_TIMEOUT)
- lim++;
-
- // easier way, but will wait slightly longer
- // _delay_us(100);
-}
-
-// Setup twi to run at 100kHz
-void i2c_master_init(void) {
- // no prescaler
- TWSR = 0;
- // Set TWI clock frequency to SCL_CLOCK. Need TWBR>10.
- // Check datasheets for more info.
- TWBR = ((F_CPU/SCL_CLOCK)-16)/2;
-}
-
-// Start a transaction with the given i2c slave address. The direction of the
-// transfer is set with I2C_READ and I2C_WRITE.
-// returns: 0 => success
-// 1 => error
-uint8_t i2c_master_start(uint8_t address) {
- TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTA);
-
- i2c_delay();
-
- // check that we started successfully
- if ( (TW_STATUS != TW_START) && (TW_STATUS != TW_REP_START))
- return 1;
-
- TWDR = address;
- TWCR = (1<<TWINT) | (1<<TWEN);
-
- i2c_delay();
-
- if ( (TW_STATUS != TW_MT_SLA_ACK) && (TW_STATUS != TW_MR_SLA_ACK) )
- return 1; // slave did not acknowledge
- else
- return 0; // success
-}
-
-
-// Finish the i2c transaction.
-void i2c_master_stop(void) {
- TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
-
- uint16_t lim = 0;
- while(!(TWCR & (1<<TWSTO)) && lim < I2C_LOOP_TIMEOUT)
- lim++;
-}
-
-// Write one byte to the i2c slave.
-// returns 0 => slave ACK
-// 1 => slave NACK
-uint8_t i2c_master_write(uint8_t data) {
- TWDR = data;
- TWCR = (1<<TWINT) | (1<<TWEN);
-
- i2c_delay();
-
- // check if the slave acknowledged us
- return (TW_STATUS == TW_MT_DATA_ACK) ? 0 : 1;
-}
-
-uint8_t i2c_master_write_data(void *const TXdata, uint8_t dataLen) {
-
- uint8_t *data = (uint8_t *)TXdata;
- int err = 0;
-
- for (int i = 0; i < dataLen; i++) {
- err = i2c_master_write(data[i]);
-
- if ( err )
- return err;
- }
-
- return err;
-
-}
-
-// Read one byte from the i2c slave. If ack=1 the slave is acknowledged,
-// if ack=0 the acknowledge bit is not set.
-// returns: byte read from i2c device
-uint8_t i2c_master_read(int ack) {
- TWCR = (1<<TWINT) | (1<<TWEN) | (ack<<TWEA);
-
- i2c_delay();
- return TWDR;
-}
-
-void i2c_reset_state(void) {
- TWCR = 0;
-}
-
-void i2c_slave_init(uint8_t address) {
- TWAR = address << 0; // slave i2c address
- // TWEN - twi enable
- // TWEA - enable address acknowledgement
- // TWINT - twi interrupt flag
- // TWIE - enable the twi interrupt
- TWCR = (1<<TWIE) | (1<<TWEA) | (1<<TWINT) | (1<<TWEN);
-}
-
-ISR(TWI_vect);
-
-ISR(TWI_vect) {
- uint8_t ack = 1;
- switch(TW_STATUS) {
- case TW_SR_SLA_ACK:
- // this device has been addressed as a slave receiver
- slave_has_register_set = false;
- break;
-
- case TW_SR_DATA_ACK:
- // this device has received data as a slave receiver
- // The first byte that we receive in this transaction sets the location
- // of the read/write location of the slaves memory that it exposes over
- // i2c. After that, bytes will be written at slave_buffer_pos, incrementing
- // slave_buffer_pos after each write.
- if(!slave_has_register_set) {
- slave_buffer_pos = TWDR;
- // don't acknowledge the master if this memory loctaion is out of bounds
- if ( slave_buffer_pos >= SLAVE_BUFFER_SIZE ) {
- ack = 0;
- slave_buffer_pos = 0;
- }
-
- slave_has_register_set = true;
- } else {
- i2c_slave_buffer[slave_buffer_pos] = TWDR;
-
- if ( slave_buffer_pos == I2C_BACKLIT_START) {
- BACKLIT_DIRTY = true;
- } else if ( slave_buffer_pos == (I2C_RGB_START+3)) {
- RGB_DIRTY = true;
- }
-
- BUFFER_POS_INC();
- }
- break;
-
- case TW_ST_SLA_ACK:
- case TW_ST_DATA_ACK:
- // master has addressed this device as a slave transmitter and is
- // requesting data.
- TWDR = i2c_slave_buffer[slave_buffer_pos];
- BUFFER_POS_INC();
- break;
-
- case TW_BUS_ERROR: // something went wrong, reset twi state
- TWCR = 0;
- default:
- break;
- }
- // Reset everything, so we are ready for the next TWI interrupt
- TWCR |= (1<<TWIE) | (1<<TWINT) | (ack<<TWEA) | (1<<TWEN);
-}
diff --git a/quantum/split_common/i2c.h b/quantum/split_common/i2c.h
deleted file mode 100644
index 91e8e96f4..000000000
--- a/quantum/split_common/i2c.h
+++ /dev/null
@@ -1,59 +0,0 @@
-#pragma once
-
-#include <stdint.h>
-
-#ifndef F_CPU
-#define F_CPU 16000000UL
-#endif
-
-#define I2C_READ 1
-#define I2C_WRITE 0
-
-#define I2C_ACK 1
-#define I2C_NACK 0
-
-// Address location defines (Keymap should be last, as it's size is dynamic)
-#define I2C_BACKLIT_START 0x00
-// Need 4 bytes for RGB (32 bit)
-#define I2C_RGB_START 0x01
-#define I2C_KEYMAP_START 0x06
-
-// Slave buffer (8bit per)
-// Rows per hand + backlit space + rgb space
-// TODO : Make this dynamically sized
-#define SLAVE_BUFFER_SIZE 0x20
-
-// i2c SCL clock frequency
-#ifndef SCL_CLOCK
-#define SCL_CLOCK 100000L
-#endif
-
-// Support 8bits right now (8 cols) will need to edit to take higher (code exists in delta split?)
-extern volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE];
-
-void i2c_master_init(void);
-uint8_t i2c_master_start(uint8_t address);
-void i2c_master_stop(void);
-uint8_t i2c_master_write(uint8_t data);
-uint8_t i2c_master_write_data(void *const TXdata, uint8_t dataLen);
-uint8_t i2c_master_read(int);
-void i2c_reset_state(void);
-void i2c_slave_init(uint8_t address);
-
-
-static inline unsigned char i2c_start_read(unsigned char addr) {
- return i2c_master_start((addr << 1) | I2C_READ);
-}
-
-static inline unsigned char i2c_start_write(unsigned char addr) {
- return i2c_master_start((addr << 1) | I2C_WRITE);
-}
-
-// from SSD1306 scrips
-extern unsigned char i2c_rep_start(unsigned char addr);
-extern void i2c_start_wait(unsigned char addr);
-extern unsigned char i2c_readAck(void);
-extern unsigned char i2c_readNak(void);
-extern unsigned char i2c_read(unsigned char ack);
-
-#define i2c_read(ack) (ack) ? i2c_readAck() : i2c_readNak();
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c
index f2a277c69..eb110bd23 100644
--- a/quantum/split_common/matrix.c
+++ b/quantum/split_common/matrix.c
@@ -25,11 +25,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h"
#include "split_util.h"
#include "config.h"
-#include "split_flags.h"
#include "quantum.h"
#include "debounce.h"
#include "transport.h"
+#ifdef ENCODER_ENABLE
+ #include "encoder.h"
+#endif
+
#if (MATRIX_COLS <= 8)
# define print_matrix_header() print("\nr/c 01234567\n")
# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
@@ -321,6 +324,9 @@ uint8_t matrix_scan(void) {
matrix_scan_quantum();
} else {
transport_slave(matrix + thisHand);
+#ifdef ENCODER_ENABLE
+ encoder_read();
+#endif
matrix_slave_scan_user();
}
diff --git a/quantum/split_common/split_flags.c b/quantum/split_common/split_flags.c
deleted file mode 100644
index 1f5825d65..000000000
--- a/quantum/split_common/split_flags.c
+++ /dev/null
@@ -1,5 +0,0 @@
-#include "split_flags.h"
-
-volatile bool RGB_DIRTY = false;
-
-volatile bool BACKLIT_DIRTY = false; \ No newline at end of file
diff --git a/quantum/split_common/split_flags.h b/quantum/split_common/split_flags.h
deleted file mode 100644
index aaac474a7..000000000
--- a/quantum/split_common/split_flags.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#pragma once
-
-#include <stdbool.h>
-#include <stdint.h>
-
-/**
-* Global Flags
-**/
-
-//RGB Stuff
-extern volatile bool RGB_DIRTY;
-
-
-//Backlight Stuff
-extern volatile bool BACKLIT_DIRTY;
diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c
index 5095cb8fd..09a307b8e 100644
--- a/quantum/split_common/split_util.c
+++ b/quantum/split_common/split_util.c
@@ -3,7 +3,6 @@
#include "keyboard.h"
#include "config.h"
#include "timer.h"
-#include "split_flags.h"
#include "transport.h"
#include "quantum.h"
@@ -12,25 +11,25 @@
# include "eeconfig.h"
#endif
+#if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT)
+#include "rgblight.h"
+#endif
+
volatile bool isLeftHand = true;
__attribute__((weak))
bool is_keyboard_left(void) {
- #ifdef SPLIT_HAND_PIN
+ #if defined(SPLIT_HAND_PIN)
// Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand
setPinInput(SPLIT_HAND_PIN);
return readPin(SPLIT_HAND_PIN);
- #else
- #ifdef EE_HANDS
- return eeprom_read_byte(EECONFIG_HANDEDNESS);
- #else
- #ifdef MASTER_RIGHT
- return !is_keyboard_master();
- #else
- return is_keyboard_master();
- #endif
- #endif
+ #elif defined(EE_HANDS)
+ return eeprom_read_byte(EECONFIG_HANDEDNESS);
+ #elif defined(MASTER_RIGHT)
+ return !is_keyboard_master();
#endif
+
+ return is_keyboard_master();
}
bool is_keyboard_master(void)
@@ -60,10 +59,6 @@ static void keyboard_master_setup(void) {
#endif
#endif
transport_master_init();
-
- // For master the Backlight info needs to be sent on startup
- // Otherwise the salve won't start with the proper info until an update
- BACKLIT_DIRTY = true;
}
static void keyboard_slave_setup(void)
@@ -76,6 +71,16 @@ void matrix_setup(void)
{
isLeftHand = is_keyboard_left();
+#if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT)
+ uint8_t num_rgb_leds_split[2] = RGBLED_SPLIT;
+ if (isLeftHand) {
+ rgblight_set_clipping_range(0, num_rgb_leds_split[0]);
+ }
+ else {
+ rgblight_set_clipping_range(num_rgb_leds_split[0], num_rgb_leds_split[1]);
+ }
+#endif
+
if (is_keyboard_master())
{
keyboard_master_setup();
diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c
index 95738530e..ab055ee65 100644
--- a/quantum/split_common/transport.c
+++ b/quantum/split_common/transport.c
@@ -1,189 +1,170 @@
+#include <string.h>
+#include <stddef.h>
#include "config.h"
#include "matrix.h"
#include "quantum.h"
-#define ROWS_PER_HAND (MATRIX_ROWS/2)
+#define ROWS_PER_HAND (MATRIX_ROWS / 2)
#ifdef RGBLIGHT_ENABLE
-# include "rgblight.h"
+# include "rgblight.h"
#endif
#ifdef BACKLIGHT_ENABLE
-# include "backlight.h"
- extern backlight_config_t backlight_config;
+# include "backlight.h"
+extern backlight_config_t backlight_config;
+#endif
+
+#ifdef ENCODER_ENABLE
+# include "encoder.h"
#endif
#if defined(USE_I2C) || defined(EH)
-#include "i2c.h"
+# include "i2c_master.h"
+# include "i2c_slave.h"
-#ifndef SLAVE_I2C_ADDRESS
-# define SLAVE_I2C_ADDRESS 0x32
+typedef struct __attribute__ ((__packed__)) {
+#ifdef BACKLIGHT_ENABLE
+ uint8_t backlight_level;
#endif
-
-#if (MATRIX_COLS > 8)
-# error "Currently only supports 8 COLS"
+#ifdef RGBLIGHT_ENABLE
+ uint32_t rgb_settings;
+#endif
+#ifdef ENCODER_ENABLE
+ uint8_t encoder_state[NUMBER_OF_ENCODERS];
#endif
+ // Keep matrix last, we are only using this for it's offset
+ uint8_t matrix_start[0];
+} transport_values_t;
-// Get rows from other half over i2c
-bool transport_master(matrix_row_t matrix[]) {
- int err = 0;
+__attribute__ ((unused))
+static transport_values_t transport_values;
- // write backlight info
#ifdef BACKLIGHT_ENABLE
- if (BACKLIT_DIRTY) {
- err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE);
- if (err) { goto i2c_error; }
-
- // Backlight location
- err = i2c_master_write(I2C_BACKLIT_START);
- if (err) { goto i2c_error; }
+# define I2C_BACKLIT_START (uint8_t)offsetof(transport_values_t, backlight_level)
+#endif
- // Write backlight
- i2c_master_write(get_backlight_level());
+#ifdef RGBLIGHT_ENABLE
+# define I2C_RGB_START (uint8_t)offsetof(transport_values_t, rgb_settings)
+#endif
- BACKLIT_DIRTY = false;
- }
+#ifdef ENCODER_ENABLE
+# define I2C_ENCODER_START (uint8_t)offsetof(transport_values_t, encoder_state)
#endif
- err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE);
- if (err) { goto i2c_error; }
+#define I2C_KEYMAP_START (uint8_t)offsetof(transport_values_t, matrix_start)
+
+# define TIMEOUT 100
- // start of matrix stored at I2C_KEYMAP_START
- err = i2c_master_write(I2C_KEYMAP_START);
- if (err) { goto i2c_error; }
+# ifndef SLAVE_I2C_ADDRESS
+# define SLAVE_I2C_ADDRESS 0x32
+# endif
- // Start read
- err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_READ);
- if (err) { goto i2c_error; }
+// Get rows from other half over i2c
+bool transport_master(matrix_row_t matrix[]) {
+ i2c_readReg(SLAVE_I2C_ADDRESS, I2C_KEYMAP_START, (void *)matrix, ROWS_PER_HAND * sizeof(matrix_row_t), TIMEOUT);
- if (!err) {
- int i;
- for (i = 0; i < ROWS_PER_HAND-1; ++i) {
- matrix[i] = i2c_master_read(I2C_ACK);
+ // write backlight info
+# ifdef BACKLIGHT_ENABLE
+ uint8_t level = get_backlight_level();
+ if (level != transport_values.backlight_level) {
+ if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_BACKLIT_START, (void *)&level, sizeof(level), TIMEOUT) >= 0) {
+ transport_values.backlight_level = level;
}
- matrix[i] = i2c_master_read(I2C_NACK);
- i2c_master_stop();
- } else {
-i2c_error: // the cable is disconnceted, or something else went wrong
- i2c_reset_state();
- return false;
}
+# endif
-#ifdef RGBLIGHT_ENABLE
- if (RGB_DIRTY) {
- err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE);
- if (err) { goto i2c_error; }
-
- // RGB Location
- err = i2c_master_write(I2C_RGB_START);
- if (err) { goto i2c_error; }
-
- uint32_t dword = eeconfig_read_rgblight();
-
- // Write RGB
- err = i2c_master_write_data(&dword, 4);
- if (err) { goto i2c_error; }
-
- RGB_DIRTY = false;
- i2c_master_stop();
+# ifdef RGBLIGHT_ENABLE
+ uint32_t rgb = rgblight_read_dword();
+ if (rgb != transport_values.rgb_settings) {
+ if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_START, (void *)&rgb, sizeof(rgb), TIMEOUT) >= 0) {
+ transport_values.rgb_settings = rgb;
+ }
}
-#endif
+# endif
+
+# ifdef ENCODER_ENABLE
+ i2c_readReg(SLAVE_I2C_ADDRESS, I2C_ENCODER_START, (void *)transport_values.encoder_state, sizeof(transport_values.encoder_state), TIMEOUT);
+ encoder_update_raw(&transport_values.encoder_state[0]);
+# endif
return true;
}
void transport_slave(matrix_row_t matrix[]) {
-
- for (int i = 0; i < ROWS_PER_HAND; ++i)
- {
- i2c_slave_buffer[I2C_KEYMAP_START + i] = matrix[i];
- }
- // Read Backlight Info
- #ifdef BACKLIGHT_ENABLE
- if (BACKLIT_DIRTY)
- {
- backlight_set(i2c_slave_buffer[I2C_BACKLIT_START]);
- BACKLIT_DIRTY = false;
- }
- #endif
- #ifdef RGBLIGHT_ENABLE
- if (RGB_DIRTY)
- {
- // Disable interupts (RGB data is big)
- cli();
- // Create new DWORD for RGB data
- uint32_t dword;
-
- // Fill the new DWORD with the data that was sent over
- uint8_t * dword_dat = (uint8_t *)(&dword);
- for (int i = 0; i < 4; i++)
- {
- dword_dat[i] = i2c_slave_buffer[I2C_RGB_START + i];
- }
-
- // Update the RGB now with the new data and set RGB_DIRTY to false
- rgblight_update_dword(dword);
- RGB_DIRTY = false;
- // Re-enable interupts now that RGB is set
- sei();
- }
- #endif
+ // Copy matrix to I2C buffer
+ memcpy((void*)(i2c_slave_reg + I2C_KEYMAP_START), (void *)matrix, ROWS_PER_HAND * sizeof(matrix_row_t) );
+
+// Read Backlight Info
+# ifdef BACKLIGHT_ENABLE
+ backlight_set(i2c_slave_reg[I2C_BACKLIT_START]);
+# endif
+
+# ifdef RGBLIGHT_ENABLE
+ uint32_t rgb = *(uint32_t *)(i2c_slave_reg + I2C_RGB_START);
+ // Update the RGB with the new data
+ rgblight_update_dword(rgb);
+# endif
+
+# ifdef ENCODER_ENABLE
+ encoder_state_raw((uint8_t*)(i2c_slave_reg + I2C_ENCODER_START));
+# endif
}
-void transport_master_init(void) {
- i2c_master_init();
-}
+void transport_master_init(void) { i2c_init(); }
-void transport_slave_init(void) {
- i2c_slave_init(SLAVE_I2C_ADDRESS);
-}
+void transport_slave_init(void) { i2c_slave_init(SLAVE_I2C_ADDRESS); }
-#else // USE_SERIAL
+#else // USE_SERIAL
-#include "serial.h"
+# include "serial.h"
-typedef struct _Serial_s2m_buffer_t {
+typedef struct __attribute__ ((__packed__)) {
+# ifdef ENCODER_ENABLE
+ uint8_t encoder_state[NUMBER_OF_ENCODERS];
+# endif
// TODO: if MATRIX_COLS > 8 change to uint8_t packed_matrix[] for pack/unpack
matrix_row_t smatrix[ROWS_PER_HAND];
} Serial_s2m_buffer_t;
-typedef struct _Serial_m2s_buffer_t {
-#ifdef BACKLIGHT_ENABLE
- uint8_t backlight_level;
-#endif
-#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
- rgblight_config_t rgblight_config; //not yet use
- //
- // When MCUs on both sides drive their respective RGB LED chains,
- // it is necessary to synchronize, so it is necessary to communicate RGB information.
- // In that case, define the RGBLIGHT_SPLIT macro.
- //
- // Otherwise, if the master side MCU drives both sides RGB LED chains,
- // there is no need to communicate.
-#endif
+typedef struct __attribute__ ((__packed__)) {
+# ifdef BACKLIGHT_ENABLE
+ uint8_t backlight_level;
+# endif
+# if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT)
+ rgblight_config_t rgblight_config; // not yet use
+ //
+ // When MCUs on both sides drive their respective RGB LED chains,
+ // it is necessary to synchronize, so it is necessary to communicate RGB
+ // information. In that case, define RGBLED_SPLIT with info on the number
+ // of LEDs on each half.
+ //
+ // Otherwise, if the master side MCU drives both sides RGB LED chains,
+ // there is no need to communicate.
+# endif
} Serial_m2s_buffer_t;
volatile Serial_s2m_buffer_t serial_s2m_buffer = {};
volatile Serial_m2s_buffer_t serial_m2s_buffer = {};
-uint8_t volatile status0 = 0;
+uint8_t volatile status0 = 0;
SSTD_t transactions[] = {
- { (uint8_t *)&status0,
- sizeof(serial_m2s_buffer), (uint8_t *)&serial_m2s_buffer,
- sizeof(serial_s2m_buffer), (uint8_t *)&serial_s2m_buffer
- }
+ {
+ (uint8_t *)&status0,
+ sizeof(serial_m2s_buffer),
+ (uint8_t *)&serial_m2s_buffer,
+ sizeof(serial_s2m_buffer),
+ (uint8_t *)&serial_s2m_buffer,
+ },
};
-void transport_master_init(void)
-{ soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); }
+void transport_master_init(void) { soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); }
-void transport_slave_init(void)
-{ soft_serial_target_init(transactions, TID_LIMIT(transactions)); }
+void transport_slave_init(void) { soft_serial_target_init(transactions, TID_LIMIT(transactions)); }
bool transport_master(matrix_row_t matrix[]) {
-
if (soft_serial_transaction()) {
return false;
}
@@ -193,32 +174,43 @@ bool transport_master(matrix_row_t matrix[]) {
matrix[i] = serial_s2m_buffer.smatrix[i];
}
- #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
- // Code to send RGB over serial goes here (not implemented yet)
- #endif
+# ifdef BACKLIGHT_ENABLE
+ // Write backlight level for slave to read
+ serial_m2s_buffer.backlight_level = backlight_config.enable ? backlight_config.level : 0;
+# endif
+
+# if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT)
+ static rgblight_config_t prev_rgb = {~0};
+ uint32_t rgb = rgblight_read_dword();
+ if (rgb != prev_rgb.raw) {
+ serial_m2s_buffer.rgblight_config.raw = rgb;
+ prev_rgb.raw = rgb;
+ }
+# endif
- #ifdef BACKLIGHT_ENABLE
- // Write backlight level for slave to read
- serial_m2s_buffer.backlight_level = backlight_config.enable ? backlight_config.level : 0;
- #endif
+# ifdef ENCODER_ENABLE
+ encoder_update_raw((uint8_t*)&serial_s2m_buffer.encoder_state);
+# endif
return true;
}
void transport_slave(matrix_row_t matrix[]) {
-
// TODO: if MATRIX_COLS > 8 change to pack()
- for (int i = 0; i < ROWS_PER_HAND; ++i)
- {
+ for (int i = 0; i < ROWS_PER_HAND; ++i) {
serial_s2m_buffer.smatrix[i] = matrix[i];
}
- #ifdef BACKLIGHT_ENABLE
- backlight_set(serial_m2s_buffer.backlight_level);
- #endif
- #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
- // Add serial implementation for RGB here
- #endif
-
+# ifdef BACKLIGHT_ENABLE
+ backlight_set(serial_m2s_buffer.backlight_level);
+# endif
+# if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT)
+ // Update RGB config with the new data
+ rgblight_update_dword(serial_m2s_buffer.rgblight_config.raw);
+# endif
+
+# ifdef ENCODER_ENABLE
+ encoder_state_raw((uint8_t*)&serial_s2m_buffer.encoder_state);
+# endif
}
#endif
diff --git a/quantum/template/avr/template.c b/quantum/template/avr/template.c
index 1e4ce26cd..86dc69abc 100644
--- a/quantum/template/avr/template.c
+++ b/quantum/template/avr/template.c
@@ -15,29 +15,37 @@
*/
#include "%KEYBOARD%.h"
+// Optional override functions below.
+// You can leave any or all of these undefined.
+// These are only required if you want to perform custom actions.
+
+/*
+
void matrix_init_kb(void) {
- // put your keyboard start-up code here
- // runs once when the firmware starts up
+ // put your keyboard start-up code here
+ // runs once when the firmware starts up
- matrix_init_user();
+ matrix_init_user();
}
void matrix_scan_kb(void) {
- // put your looping keyboard code here
- // runs every cycle (a lot)
+ // put your looping keyboard code here
+ // runs every cycle (a lot)
- matrix_scan_user();
+ matrix_scan_user();
}
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
- // put your per-action keyboard code here
- // runs for every action, just before processing by the firmware
+ // put your per-action keyboard code here
+ // runs for every action, just before processing by the firmware
- return process_record_user(keycode, record);
+ return process_record_user(keycode, record);
}
void led_set_kb(uint8_t usb_led) {
- // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
+ // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
- led_set_user(usb_led);
+ led_set_user(usb_led);
}
+
+*/
diff --git a/quantum/template/ps2avrgb/config.h b/quantum/template/ps2avrgb/config.h
index 01cdf932e..8d9a993cf 100644
--- a/quantum/template/ps2avrgb/config.h
+++ b/quantum/template/ps2avrgb/config.h
@@ -21,17 +21,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define VENDOR_ID 0x20A0
#define PRODUCT_ID 0x422D
+#define DEVICE_VER 0x0001
#define MANUFACTURER You
#define PRODUCT %KEYBOARD%
+#define DESCRIPTION A custom keyboard
#define RGBLED_NUM 16
-#define MATRIX_ROWS 2
-#define MATRIX_COLS 3
+#define MATRIX_ROWS 8
+#define MATRIX_COLS 11
-#define MATRIX_ROW_PINS { D0, D5 }
-#define MATRIX_COL_PINS { F1, F0, B0 }
-#define UNUSED_PINS
+#define MATRIX_ROW_PINS { B0, B1, B2, B3, B4, B5, B6, B7 }
+#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5 }
+// #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, C1, C0, D7 }
+#define UNUSED_PINS {}
#define DIODE_DIRECTION COL2ROW
#define DEBOUNCING_DELAY 5
diff --git a/quantum/template/ps2avrgb/i2c.c b/quantum/template/ps2avrgb/i2c.c
deleted file mode 100644
index e8c4455ad..000000000
--- a/quantum/template/ps2avrgb/i2c.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
-Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
-
-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 <http://www.gnu.org/licenses/>.
-*/
-
-// Please do not modify this file
-
-#include <avr/io.h>
-#include <util/twi.h>
-
-#include "i2c.h"
-
-void i2c_set_bitrate(uint16_t bitrate_khz) {
- uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz);
- if (bitrate_div >= 16) {
- bitrate_div = (bitrate_div - 16) / 2;
- }
- TWBR = bitrate_div;
-}
-
-void i2c_init(void) {
- // set pull-up resistors on I2C bus pins
- PORTC |= 0b11;
-
- i2c_set_bitrate(400);
-
- // enable TWI (two-wire interface)
- TWCR |= (1 << TWEN);
-
- // enable TWI interrupt and slave address ACK
- TWCR |= (1 << TWIE);
- TWCR |= (1 << TWEA);
-}
-
-uint8_t i2c_start(uint8_t address) {
- // reset TWI control register
- TWCR = 0;
-
- // begin transmission and wait for it to end
- TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
- while (!(TWCR & (1<<TWINT)));
-
- // check if the start condition was successfully transmitted
- if ((TWSR & 0xF8) != TW_START) {
- return 1;
- }
-
- // transmit address and wait
- TWDR = address;
- TWCR = (1<<TWINT) | (1<<TWEN);
- while (!(TWCR & (1<<TWINT)));
-
- // check if the device has acknowledged the READ / WRITE mode
- uint8_t twst = TW_STATUS & 0xF8;
- if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
- return 1;
- }
-
- return 0;
-}
-
-void i2c_stop(void) {
- TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
-}
-
-uint8_t i2c_write(uint8_t data) {
- TWDR = data;
-
- // transmit data and wait
- TWCR = (1<<TWINT) | (1<<TWEN);
- while (!(TWCR & (1<<TWINT)));
-
- if ((TWSR & 0xF8) != TW_MT_DATA_ACK) {
- return 1;
- }
-
- return 0;
-}
-
-uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) {
- if (i2c_start(address)) {
- return 1;
- }
-
- for (uint16_t i = 0; i < length; i++) {
- if (i2c_write(data[i])) {
- return 1;
- }
- }
-
- i2c_stop();
-
- return 0;
-}
diff --git a/quantum/template/ps2avrgb/i2c.h b/quantum/template/ps2avrgb/i2c.h
deleted file mode 100644
index 7ce50cdb5..000000000
--- a/quantum/template/ps2avrgb/i2c.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
-Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
-
-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 <http://www.gnu.org/licenses/>.
-*/
-
-// Please do not modify this file
-
-#ifndef __I2C_H__
-#define __I2C_H__
-
-void i2c_init(void);
-void i2c_set_bitrate(uint16_t bitrate_khz);
-uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length);
-
-#endif
diff --git a/quantum/template/ps2avrgb/matrix.c b/quantum/template/ps2avrgb/matrix.c
deleted file mode 100644
index 245813dfd..000000000
--- a/quantum/template/ps2avrgb/matrix.c
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
-Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
-
-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 <http://www.gnu.org/licenses/>.
-*/
-
-#include <avr/io.h>
-#include <util/delay.h>
-
-#include "matrix.h"
-
-#ifndef DEBOUNCE
-# define DEBOUNCE 5
-#endif
-
-static uint8_t debouncing = DEBOUNCE;
-
-static matrix_row_t matrix[MATRIX_ROWS];
-static matrix_row_t matrix_debouncing[MATRIX_ROWS];
-
-void matrix_set_row_status(uint8_t row);
-uint8_t bit_reverse(uint8_t x);
-
-void matrix_init(void) {
- // all outputs for rows high
- DDRB = 0xFF;
- PORTB = 0xFF;
- // all inputs for columns
- DDRA = 0x00;
- DDRC &= ~(0x111111<<2);
- DDRD &= ~(1<<PIND7);
- // all columns are pulled-up
- PORTA = 0xFF;
- PORTC |= (0b111111<<2);
- PORTD |= (1<<PIND7);
-
- // initialize matrix state: all keys off
- for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
- matrix[row] = 0x00;
- matrix_debouncing[row] = 0x00;
- }
-
- matrix_init_quantum();
-}
-
-uint8_t matrix_scan(void) {
- for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
- matrix_set_row_status(row);
- _delay_us(5);
-
- matrix_row_t cols = (
- // cols 0..7, PORTA 0 -> 7
- (~PINA) & 0xFF
- ) | (
- // cols 8..13, PORTC 7 -> 0
- bit_reverse((~PINC) & 0xFF) << 8
- ) | (
- // col 14, PORTD 7
- ((~PIND) & (1 << PIND7)) << 7
- );
-
- if (matrix_debouncing[row] != cols) {
- matrix_debouncing[row] = cols;
- debouncing = DEBOUNCE;
- }
- }
-
- if (debouncing) {
- if (--debouncing) {
- _delay_ms(1);
- } else {
- for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
- matrix[i] = matrix_debouncing[i];
- }
- }
- }
-
- matrix_scan_quantum();
-
- return 1;
-}
-
-// declarations
-void matrix_set_row_status(uint8_t row) {
- DDRB = (1 << row);
- PORTB = ~(1 << row);
-}
-
-uint8_t bit_reverse(uint8_t x) {
- x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
- x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
- x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
- return x;
-}
-
-inline matrix_row_t matrix_get_row(uint8_t row) {
- return matrix[row];
-}
-
-void matrix_print(void) {
-}
diff --git a/quantum/template/ps2avrgb/rules.mk b/quantum/template/ps2avrgb/rules.mk
index bcd7dff99..191a13844 100644
--- a/quantum/template/ps2avrgb/rules.mk
+++ b/quantum/template/ps2avrgb/rules.mk
@@ -42,9 +42,7 @@ RGBLIGHT_CUSTOM_DRIVER = yes
OPT_DEFS = -DDEBUG_LEVEL=0
-# custom matrix setup
-CUSTOM_MATRIX = yes
-SRC = matrix.c i2c.c
+SRC += i2c_master.c
# programming options
PROGRAM_CMD = ./util/atmega32a_program.py $(TARGET).hex
diff --git a/quantum/template/ps2avrgb/template.c b/quantum/template/ps2avrgb/template.c
index 08156c562..3f920de48 100644
--- a/quantum/template/ps2avrgb/template.c
+++ b/quantum/template/ps2avrgb/template.c
@@ -13,13 +13,78 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+
#include "%KEYBOARD%.h"
-#include <avr/pgmspace.h>
-#include "action_layer.h"
-#include "i2c.h"
-#include "quantum.h"
+#ifdef RGBLIGHT_ENABLE
+
+#include <string.h>
+#include "i2c_master.h"
+#include "rgblight.h"
+
+extern rgblight_config_t rgblight_config;
+
+void matrix_init_kb(void) {
+ i2c_init();
+ // call user level keymaps, if any
+ matrix_init_user();
+}
+
+// custom RGB driver
+void rgblight_set(void) {
+ if (!rgblight_config.enable) {
+ memset(led, 0, 3 * RGBLED_NUM);
+ }
+
+ i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
+}
+
+bool rgb_init = false;
+
+void matrix_scan_kb(void) {
+ // if LEDs were previously on before poweroff, turn them back on
+ if (rgb_init == false && rgblight_config.enable) {
+ i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
+ rgb_init = true;
+ }
+
+ rgblight_task();
+ matrix_scan_user();
+}
+
+#endif
-__attribute__ ((weak))
-void matrix_scan_user(void) {
+// Optional override functions below.
+// You can leave any or all of these undefined.
+// These are only required if you want to perform custom actions.
+
+/*
+
+void matrix_init_kb(void) {
+ // put your keyboard start-up code here
+ // runs once when the firmware starts up
+
+ matrix_init_user();
}
+
+void matrix_scan_kb(void) {
+ // put your looping keyboard code here
+ // runs every cycle (a lot)
+
+ matrix_scan_user();
+}
+
+bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
+ // put your per-action keyboard code here
+ // runs for every action, just before processing by the firmware
+
+ return process_record_user(keycode, record);
+}
+
+void led_set_kb(uint8_t usb_led) {
+ // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
+
+ led_set_user(usb_led);
+}
+
+*/
diff --git a/quantum/visualizer/readme.md b/quantum/visualizer/readme.md
index 545ba2270..298efb742 100644
--- a/quantum/visualizer/readme.md
+++ b/quantum/visualizer/readme.md
@@ -1,7 +1,7 @@
# A visualization library for the TMK keyboard firmware
This library is designed to work together with the [TMK keyboard firmware](https://github.com/tmk/tmk_keyboard). Currently it only works for [Chibios](http://www.chibios.org/)
- flavors, but it would be possible to add support for other configurations as well. The LCD display functionality is provided by the [uGFX library](http://www.ugfx.org/).
+ flavors, but it would be possible to add support for other configurations as well. The LCD display functionality is provided by the [uGFX library](https://ugfx.io/).
## To use this library as a user
You can and should modify the visualizer\_user.c file. Check the comments in the file for more information.