Browse Source

Change split_common to use RGBLIGHT_SPLIT (#5509)

* add I2C_slave_buffer_t to quantum/split_common/transport.c

Improvements to ease the maintenance of the I2C slave buffer layout. And this commit does not change the compilation results.

* add temporary pdhelix(Patched Helix) code

* temporary cherry-pick from #5020

add new version(#5020) quantum/rgblight.[ch], quantum/rgblight_modes.h

* add post_config.h support to build_keyboard.mk

* add quantum/rgblight_post_config.h, quantum/split_common/post_config.h

Add quantum/rgblight_post_config.h and quantum/split_common/post_config.h using POST_CONFIG_H variable of build_keyboard.mk.

quantum/rgblight_post_config.h additionally defines RGBLIGHT_SPLIT if RGBLED_SPIT is defined.

quantum/split_common/post_config.h defines RGBLIGHT_SPLIT additionally when master-slave communication is I2C.

* Change split_common's transport.c I2C to use the synchronization feature of rgblight.c

* Change split_common's transport.c serial to use the synchronization feature of rgblight.c

* test RGBLIGHT_SPLIT on keyboards/handwired/pdhelix

* Test End Revert "test RGBLIGHT_SPLIT on keyboards/handwired/pdhelix"

This reverts commit 80118a6bbd.

[x] make RGBLIGHT_TEST=1 handwired/pdhelix/i2c:default
[x] make RGBLIGHT_TEST=2 handwired/pdhelix/i2c:default (same RGBLIGHT_TEST=3)
[x] make RGBLIGHT_TEST=3 handwired/pdhelix/i2c:default

[x] make RGBLIGHT_TEST=1 handwired/pdhelix/pd2:default
[x] make RGBLIGHT_TEST=2 handwired/pdhelix/pd2:default
[x] make RGBLIGHT_TEST=3 handwired/pdhelix/pd2:default

[x] make RGBLIGHT_TEST=1 handwired/pdhelix/pd2_2oled:default
[x] make RGBLIGHT_TEST=2 handwired/pdhelix/pd2_2oled:default
[x] make RGBLIGHT_TEST=3 handwired/pdhelix/pd2_2oled:default

* Test End, Revert "temporary cherry-pick from #5020"

This reverts commit d35069f68b.

* Test End, Revert "add temporary pdhelix(Patched Helix) code"

This reverts commit aebddfc1a8.

* temporarily cherry-pick from #5020 to see if it passes the travis-ci test.

add new version(#5020) quantum/rgblight.[ch], quantum/rgblight_modes.h

* Passed the travis-ci test. Revert "temporarily cherry-pick from #5020 to see if it passes the travis-ci test."

This reverts commit 647c0a9755.

* update docs/config_options.md

* update split_common/transport.c, improves maintainability of serial transaction IDs.

No change in build result.

* temporary cherry-pick from #5020

* fix build fail keebio/iris/rev3:default

* fix build fail lets_split_eh/eh:default

* Revert "temporary cherry-pick from #5020"

This reverts commit be48ca1b45.

* temporary cherry-pick from #5020 (0.6.336)

* Revert "temporary cherry-pick from #5020 (0.6.336)"

This reverts commit 978d26a8b3.

* temporary cherry-pick from #5020 (0.6.336)
pjones-keymap
Takeshi ISHII 2 months ago
parent
commit
7e67bd791b

+ 18
- 0
build_keyboard.mk View File

@@ -280,6 +280,23 @@ ifneq ("$(wildcard $(KEYBOARD_PATH_1)/config.h)","")
280 280
     CONFIG_H += $(KEYBOARD_PATH_1)/config.h
281 281
 endif
282 282
 
283
+POST_CONFIG_H :=
284
+ifneq ("$(wildcard $(KEYBOARD_PATH_1)/post_config.h)","")
285
+    POST_CONFIG_H += $(KEYBOARD_PATH_1)/post_config.h
286
+endif
287
+ifneq ("$(wildcard $(KEYBOARD_PATH_2)/post_config.h)","")
288
+    POST_CONFIG_H += $(KEYBOARD_PATH_2)/post_config.h
289
+endif
290
+ifneq ("$(wildcard $(KEYBOARD_PATH_3)/post_config.h)","")
291
+    POST_CONFIG_H += $(KEYBOARD_PATH_3)/post_config.h
292
+endif
293
+ifneq ("$(wildcard $(KEYBOARD_PATH_4)/post_config.h)","")
294
+    POST_CONFIG_H += $(KEYBOARD_PATH_4)/post_config.h
295
+endif
296
+ifneq ("$(wildcard $(KEYBOARD_PATH_5)/post_config.h)","")
297
+    POST_CONFIG_H += $(KEYBOARD_PATH_5)/post_config.h
298
+endif
299
+
283 300
 # Save the defines and includes here, so we don't include any keymap specific ones
284 301
 PROJECT_DEFS := $(OPT_DEFS)
285 302
 PROJECT_INC := $(VPATH) $(EXTRAINCDIRS) $(KEYBOARD_PATHS)
@@ -355,6 +372,7 @@ ifeq ($(strip $(VISUALIZER_ENABLE)), yes)
355 372
     include $(VISUALIZER_PATH)/visualizer.mk
356 373
 endif
357 374
 
375
+CONFIG_H += $(POST_CONFIG_H)
358 376
 ALL_CONFIGS := $(PROJECT_CONFIG) $(CONFIG_H)
359 377
 
360 378
 OUTPUTS := $(KEYMAP_OUTPUT) $(KEYBOARD_OUTPUT)

+ 2
- 0
common_features.mk View File

@@ -103,6 +103,7 @@ ifeq ($(strip $(UNICODE_COMMON)), yes)
103 103
 endif
104 104
 
105 105
 ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
106
+    POST_CONFIG_H += $(QUANTUM_DIR)/rgblight_post_config.h
106 107
     OPT_DEFS += -DRGBLIGHT_ENABLE
107 108
     SRC += $(QUANTUM_DIR)/rgblight.c
108 109
     CIE1931_CURVE = yes
@@ -318,6 +319,7 @@ ifneq ($(strip $(DEBOUNCE_TYPE)), custom)
318 319
 endif
319 320
 
320 321
 ifeq ($(strip $(SPLIT_KEYBOARD)), yes)
322
+    POST_CONFIG_H += $(QUANTUM_DIR)/split_common/post_config.h
321 323
     OPT_DEFS += -DSPLIT_KEYBOARD
322 324
 
323 325
     # Include files used by all split keyboards

+ 3
- 1
docs/config_options.md View File

@@ -180,10 +180,12 @@ If you define these options you will enable the associated feature, which may in
180 180
   * run RGB animations
181 181
 * `#define RGBLED_NUM 12`
182 182
   * number of LEDs
183
+* `#define RGBLIGHT_SPLIT`
184
+  * Needed if both halves of the board have RGB LEDs wired directly to the RGB output pin on the controllers instead of passing the output of the left half to the input of the right half
183 185
 * `#define RGBLED_SPLIT { 6, 6 }`
184 186
   * number of LEDs connected that are directly wired to `RGB_DI_PIN` on each half of a split keyboard
185 187
   * First value indicates number of LEDs for left half, second value is for the right half
186
-  * Needed if both halves of the board have RGB LEDs wired directly to the RGB output pin on the controllers instead of passing the output of the left half to the input of the right half
188
+  * When RGBLED_SPLIT is defined, RGBLIGHT_SPLIT is implicitly defined.
187 189
 * `#define RGBLIGHT_HUE_STEP 12`
188 190
   * units to step when in/decreasing hue
189 191
 * `#define RGBLIGHT_SAT_STEP 25`

+ 5
- 0
quantum/rgblight_post_config.h View File

@@ -0,0 +1,5 @@
1
+#if defined(RGBLED_SPLIT) && !defined(RGBLIGHT_SPLIT)
2
+  // When RGBLED_SPLIT is defined,
3
+  // it is considered that RGBLIGHT_SPLIT is defined implicitly.
4
+  #define RGBLIGHT_SPLIT
5
+#endif

+ 15
- 0
quantum/split_common/post_config.h View File

@@ -0,0 +1,15 @@
1
+#if defined(USE_I2C) || defined(EH)
2
+  // When using I2C, using rgblight implicitly involves split support.
3
+  #if defined(RGBLIGHT_ENABLE) && !defined(RGBLIGHT_SPLIT)
4
+    #define RGBLIGHT_SPLIT
5
+  #endif
6
+
7
+#else  // use serial
8
+  // When using serial, the user must define RGBLIGHT_SPLIT explicitly
9
+  //  in config.h as needed.
10
+  //      see quantum/rgblight_post_config.h
11
+  #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
12
+    // When using serial and RGBLIGHT_SPLIT need separate transaction
13
+    #define SERIAL_USE_MULTI_TRANSACTION
14
+  #endif
15
+#endif

+ 110
- 74
quantum/split_common/transport.c View File

@@ -25,36 +25,23 @@ extern backlight_config_t backlight_config;
25 25
 #  include "i2c_master.h"
26 26
 #  include "i2c_slave.h"
27 27
 
28
-typedef struct __attribute__ ((__packed__)) {
29
-#ifdef BACKLIGHT_ENABLE
30
-  uint8_t backlight_level;
31
-#endif
32
-#ifdef RGBLIGHT_ENABLE
33
-  uint32_t rgb_settings;
28
+typedef struct _I2C_slave_buffer_t {
29
+    matrix_row_t smatrix[ROWS_PER_HAND];
30
+    uint8_t      backlight_level;
31
+#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
32
+    rgblight_syncinfo_t rgblight_sync;
34 33
 #endif
35 34
 #ifdef ENCODER_ENABLE
36
-  uint8_t encoder_state[NUMBER_OF_ENCODERS];
37
-#endif
38
-  // Keep matrix last, we are only using this for it's offset
39
-  uint8_t matrix_start[0];
40
-} transport_values_t;
41
-
42
-__attribute__ ((unused))
43
-static transport_values_t transport_values;
44
-
45
-#ifdef BACKLIGHT_ENABLE
46
-#  define I2C_BACKLIT_START (uint8_t)offsetof(transport_values_t, backlight_level)
47
-#endif
48
-
49
-#ifdef RGBLIGHT_ENABLE
50
-#  define I2C_RGB_START (uint8_t)offsetof(transport_values_t, rgb_settings)
35
+    uint8_t encoder_state[NUMBER_OF_ENCODERS];
51 36
 #endif
37
+} I2C_slave_buffer_t;
52 38
 
53
-#ifdef ENCODER_ENABLE
54
-#  define I2C_ENCODER_START (uint8_t)offsetof(transport_values_t, encoder_state)
55
-#endif
39
+static I2C_slave_buffer_t * const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg;
56 40
 
57
-#define I2C_KEYMAP_START (uint8_t)offsetof(transport_values_t, matrix_start)
41
+#  define I2C_BACKLIGHT_START offsetof(I2C_slave_buffer_t, backlight_level)
42
+#  define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync)
43
+#  define I2C_KEYMAP_START offsetof(I2C_slave_buffer_t, smatrix)
44
+#  define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state)
58 45
 
59 46
 #  define TIMEOUT 100
60 47
 
@@ -64,30 +51,32 @@ static transport_values_t transport_values;
64 51
 
65 52
 // Get rows from other half over i2c
66 53
 bool transport_master(matrix_row_t matrix[]) {
67
-  i2c_readReg(SLAVE_I2C_ADDRESS, I2C_KEYMAP_START, (void *)matrix, ROWS_PER_HAND * sizeof(matrix_row_t), TIMEOUT);
54
+  i2c_readReg(SLAVE_I2C_ADDRESS, I2C_KEYMAP_START, (void *)matrix, sizeof(i2c_buffer->smatrix), TIMEOUT);
68 55
 
69 56
   // write backlight info
70 57
 #  ifdef BACKLIGHT_ENABLE
71 58
   uint8_t level = get_backlight_level();
72
-  if (level != transport_values.backlight_level) {
73
-    if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_BACKLIT_START, (void *)&level, sizeof(level), TIMEOUT) >= 0) {
74
-      transport_values.backlight_level = level;
59
+  if (level != i2c_buffer->backlight_level) {
60
+    if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_BACKLIGHT_START, (void *)&level, sizeof(level), TIMEOUT) >= 0) {
61
+      i2c_buffer->backlight_level = level;
75 62
     }
76 63
   }
77 64
 #  endif
78 65
 
79
-#  ifdef RGBLIGHT_ENABLE
80
-  uint32_t rgb = rgblight_read_dword();
81
-  if (rgb != transport_values.rgb_settings) {
82
-    if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_START, (void *)&rgb, sizeof(rgb), TIMEOUT) >= 0) {
83
-      transport_values.rgb_settings = rgb;
66
+#  if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
67
+  if (rgblight_get_change_flags()) {
68
+    rgblight_syncinfo_t rgblight_sync;
69
+    rgblight_get_syncinfo(&rgblight_sync);
70
+    if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_START,
71
+                     (void *)&rgblight_sync, sizeof(rgblight_sync), TIMEOUT) >= 0) {
72
+      rgblight_clear_change_flags();
84 73
     }
85 74
   }
86 75
 #  endif
87 76
 
88 77
 #  ifdef ENCODER_ENABLE
89
-  i2c_readReg(SLAVE_I2C_ADDRESS, I2C_ENCODER_START, (void *)transport_values.encoder_state, sizeof(transport_values.encoder_state), TIMEOUT);
90
-  encoder_update_raw(&transport_values.encoder_state[0]);
78
+  i2c_readReg(SLAVE_I2C_ADDRESS, I2C_ENCODER_START, (void *)i2c_buffer->encoder_state, sizeof(I2C_slave_buffer_t.encoder_state), TIMEOUT);
79
+  encoder_update_raw(i2c_buffer->encoder_state);
91 80
 #  endif
92 81
 
93 82
   return true;
@@ -95,21 +84,23 @@ bool transport_master(matrix_row_t matrix[]) {
95 84
 
96 85
 void transport_slave(matrix_row_t matrix[]) {
97 86
   // Copy matrix to I2C buffer
98
-  memcpy((void*)(i2c_slave_reg + I2C_KEYMAP_START), (void *)matrix, ROWS_PER_HAND * sizeof(matrix_row_t) );
87
+  memcpy((void*)i2c_buffer->smatrix, (void *)matrix, sizeof(i2c_buffer->smatrix));
99 88
 
100 89
 // Read Backlight Info
101 90
 #  ifdef BACKLIGHT_ENABLE
102
-  backlight_set(i2c_slave_reg[I2C_BACKLIT_START]);
91
+  backlight_set(i2c_buffer->backlight_level);
103 92
 #  endif
104 93
 
105
-#  ifdef RGBLIGHT_ENABLE
106
-  uint32_t rgb = *(uint32_t *)(i2c_slave_reg + I2C_RGB_START);
94
+#  if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
107 95
   // Update the RGB with the new data
108
-  rgblight_update_dword(rgb);
96
+  if (i2c_buffer->rgblight_sync.status.change_flags != 0) {
97
+      rgblight_update_sync(&i2c_buffer->rgblight_sync, false);
98
+      i2c_buffer->rgblight_sync.status.change_flags = 0;
99
+  }
109 100
 #  endif
110 101
 
111 102
 #  ifdef ENCODER_ENABLE
112
-  encoder_state_raw((uint8_t*)(i2c_slave_reg + I2C_ENCODER_START));
103
+  encoder_state_raw(i2c_buffer->encoder_state);
113 104
 #  endif
114 105
 }
115 106
 
@@ -121,53 +112,109 @@ void transport_slave_init(void) { i2c_slave_init(SLAVE_I2C_ADDRESS); }
121 112
 
122 113
 #  include "serial.h"
123 114
 
124
-typedef struct __attribute__ ((__packed__)) {
115
+typedef struct _Serial_s2m_buffer_t {
116
+  // TODO: if MATRIX_COLS > 8 change to uint8_t packed_matrix[] for pack/unpack
117
+  matrix_row_t smatrix[ROWS_PER_HAND];
118
+
125 119
 #  ifdef ENCODER_ENABLE
126 120
   uint8_t encoder_state[NUMBER_OF_ENCODERS];
127 121
 #  endif
128
-  // TODO: if MATRIX_COLS > 8 change to uint8_t packed_matrix[] for pack/unpack
129
-  matrix_row_t smatrix[ROWS_PER_HAND];
122
+
130 123
 } Serial_s2m_buffer_t;
131 124
 
132
-typedef struct __attribute__ ((__packed__)) {
125
+typedef struct _Serial_m2s_buffer_t {
133 126
 #  ifdef BACKLIGHT_ENABLE
134 127
   uint8_t           backlight_level;
135 128
 #  endif
136
-#  if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT)
137
-  rgblight_config_t rgblight_config;  // not yet use
138
-  //
139
-  // When MCUs on both sides drive their respective RGB LED chains,
140
-  // it is necessary to synchronize, so it is necessary to communicate RGB
141
-  // information. In that case, define RGBLED_SPLIT with info on the number
142
-  // of LEDs on each half.
143
-  //
144
-  // Otherwise, if the master side MCU drives both sides RGB LED chains,
145
-  // there is no need to communicate.
146
-#  endif
147 129
 } Serial_m2s_buffer_t;
148 130
 
131
+#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
132
+// When MCUs on both sides drive their respective RGB LED chains,
133
+// it is necessary to synchronize, so it is necessary to communicate RGB
134
+// information. In that case, define RGBLIGHT_SPLIT with info on the number
135
+// of LEDs on each half.
136
+//
137
+// Otherwise, if the master side MCU drives both sides RGB LED chains,
138
+// there is no need to communicate.
139
+
140
+typedef struct _Serial_rgblight_t {
141
+    rgblight_syncinfo_t rgblight_sync;
142
+} Serial_rgblight_t;
143
+
144
+volatile Serial_rgblight_t serial_rgblight = {};
145
+uint8_t volatile status_rgblight           = 0;
146
+#endif
147
+
149 148
 volatile Serial_s2m_buffer_t serial_s2m_buffer = {};
150 149
 volatile Serial_m2s_buffer_t serial_m2s_buffer = {};
151 150
 uint8_t volatile status0                       = 0;
152 151
 
152
+enum serial_transaction_id {
153
+    GET_SLAVE_MATRIX = 0,
154
+#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
155
+    PUT_RGBLIGHT,
156
+#endif
157
+};
158
+
153 159
 SSTD_t transactions[] = {
154
-    {
160
+    [GET_SLAVE_MATRIX] = {
155 161
         (uint8_t *)&status0,
156 162
         sizeof(serial_m2s_buffer),
157 163
         (uint8_t *)&serial_m2s_buffer,
158 164
         sizeof(serial_s2m_buffer),
159 165
         (uint8_t *)&serial_s2m_buffer,
160 166
     },
167
+#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
168
+    [PUT_RGBLIGHT] = {
169
+        (uint8_t *)&status_rgblight,
170
+        sizeof(serial_rgblight),
171
+        (uint8_t *)&serial_rgblight,
172
+        0, NULL // no slave to master transfer
173
+    },
174
+#endif
161 175
 };
162 176
 
163 177
 void transport_master_init(void) { soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); }
164 178
 
165 179
 void transport_slave_init(void) { soft_serial_target_init(transactions, TID_LIMIT(transactions)); }
166 180
 
181
+#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
182
+
183
+// rgblight synchronization information communication.
184
+
185
+void transport_rgblight_master(void) {
186
+  if (rgblight_get_change_flags()) {
187
+    rgblight_get_syncinfo((rgblight_syncinfo_t *)&serial_rgblight.rgblight_sync);
188
+    if (soft_serial_transaction(PUT_RGBLIGHT) == TRANSACTION_END) {
189
+        rgblight_clear_change_flags();
190
+    }
191
+  }
192
+}
193
+
194
+void transport_rgblight_slave(void) {
195
+  if (status_rgblight == TRANSACTION_ACCEPTED) {
196
+    rgblight_update_sync((rgblight_syncinfo_t *)&serial_rgblight.rgblight_sync,
197
+                         false);
198
+    status_rgblight = TRANSACTION_END;
199
+  }
200
+}
201
+
202
+#else
203
+#define transport_rgblight_master()
204
+#define transport_rgblight_slave()
205
+#endif
206
+
167 207
 bool transport_master(matrix_row_t matrix[]) {
168
-  if (soft_serial_transaction()) {
208
+#ifndef SERIAL_USE_MULTI_TRANSACTION
209
+  if (soft_serial_transaction() != TRANSACTION_END) {
169 210
     return false;
170 211
   }
212
+#else
213
+  transport_rgblight_master();
214
+  if (soft_serial_transaction(GET_SLAVE_MATRIX) != TRANSACTION_END) {
215
+    return false;
216
+  }
217
+#endif
171 218
 
172 219
   // TODO:  if MATRIX_COLS > 8 change to unpack()
173 220
   for (int i = 0; i < ROWS_PER_HAND; ++i) {
@@ -179,23 +226,15 @@ bool transport_master(matrix_row_t matrix[]) {
179 226
   serial_m2s_buffer.backlight_level = backlight_config.enable ? backlight_config.level : 0;
180 227
 #  endif
181 228
 
182
-#  if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT)
183
-  static rgblight_config_t prev_rgb = {~0};
184
-  uint32_t rgb = rgblight_read_dword();
185
-  if (rgb != prev_rgb.raw) {
186
-    serial_m2s_buffer.rgblight_config.raw = rgb;
187
-    prev_rgb.raw = rgb;
188
-  }
189
-#  endif
190
-
191 229
 #  ifdef ENCODER_ENABLE
192
-  encoder_update_raw((uint8_t*)&serial_s2m_buffer.encoder_state);
230
+  encoder_update_raw((uint8_t *)serial_s2m_buffer.encoder_state);
193 231
 #  endif
194 232
 
195 233
   return true;
196 234
 }
197 235
 
198 236
 void transport_slave(matrix_row_t matrix[]) {
237
+  transport_rgblight_slave();
199 238
   // TODO: if MATRIX_COLS > 8 change to pack()
200 239
   for (int i = 0; i < ROWS_PER_HAND; ++i) {
201 240
     serial_s2m_buffer.smatrix[i] = matrix[i];
@@ -203,14 +242,11 @@ void transport_slave(matrix_row_t matrix[]) {
203 242
 #  ifdef BACKLIGHT_ENABLE
204 243
   backlight_set(serial_m2s_buffer.backlight_level);
205 244
 #  endif
206
-#  if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT)
207
-  // Update RGB config with the new data
208
-  rgblight_update_dword(serial_m2s_buffer.rgblight_config.raw);
209
-#  endif
210 245
 
211 246
 #  ifdef ENCODER_ENABLE
212
-  encoder_state_raw((uint8_t*)&serial_s2m_buffer.encoder_state);
247
+  encoder_state_raw((uint8_t *)serial_s2m_buffer.encoder_state);
213 248
 #  endif
249
+
214 250
 }
215 251
 
216 252
 #endif

Loading…
Cancel
Save