diff options
| author | XScorpion2 <rcalt2vt@gmail.com> | 2019-04-03 18:01:17 -0500 |
|---|---|---|
| committer | Drashna Jaelre <drashna@live.com> | 2019-04-03 16:01:17 -0700 |
| commit | 63177760deaf23bb1f676974cecf211676285604 (patch) | |
| tree | a0d60f4f55ef9632a20631c6f96b3f2e4e00367c /quantum/split_common | |
| parent | 17e7762de7e3fdfc61c20aa61022f47370630c6a (diff) | |
| download | qmk_firmware-63177760deaf23bb1f676974cecf211676285604.tar.gz qmk_firmware-63177760deaf23bb1f676974cecf211676285604.zip | |
Added encoder support to split common code (#5477)
* Added slave encoder support to split common
* Fixing handwired/xealous/rev1 compile error
* Removed unnecessary ifdef
Diffstat (limited to 'quantum/split_common')
| -rw-r--r-- | quantum/split_common/matrix.c | 7 | ||||
| -rw-r--r-- | quantum/split_common/transport.c | 77 |
2 files changed, 70 insertions, 14 deletions
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c index dcb96254f..eb110bd23 100644 --- a/quantum/split_common/matrix.c +++ b/quantum/split_common/matrix.c | |||
| @@ -29,6 +29,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 29 | #include "debounce.h" | 29 | #include "debounce.h" |
| 30 | #include "transport.h" | 30 | #include "transport.h" |
| 31 | 31 | ||
| 32 | #ifdef ENCODER_ENABLE | ||
| 33 | #include "encoder.h" | ||
| 34 | #endif | ||
| 35 | |||
| 32 | #if (MATRIX_COLS <= 8) | 36 | #if (MATRIX_COLS <= 8) |
| 33 | # define print_matrix_header() print("\nr/c 01234567\n") | 37 | # define print_matrix_header() print("\nr/c 01234567\n") |
| 34 | # define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) | 38 | # define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) |
| @@ -320,6 +324,9 @@ uint8_t matrix_scan(void) { | |||
| 320 | matrix_scan_quantum(); | 324 | matrix_scan_quantum(); |
| 321 | } else { | 325 | } else { |
| 322 | transport_slave(matrix + thisHand); | 326 | transport_slave(matrix + thisHand); |
| 327 | #ifdef ENCODER_ENABLE | ||
| 328 | encoder_read(); | ||
| 329 | #endif | ||
| 323 | matrix_slave_scan_user(); | 330 | matrix_slave_scan_user(); |
| 324 | } | 331 | } |
| 325 | 332 | ||
diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c index 8d408f6fd..ab055ee65 100644 --- a/quantum/split_common/transport.c +++ b/quantum/split_common/transport.c | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | #include <string.h> | 1 | #include <string.h> |
| 2 | #include <stddef.h> | ||
| 2 | 3 | ||
| 3 | #include "config.h" | 4 | #include "config.h" |
| 4 | #include "matrix.h" | 5 | #include "matrix.h" |
| @@ -15,15 +16,45 @@ | |||
| 15 | extern backlight_config_t backlight_config; | 16 | extern backlight_config_t backlight_config; |
| 16 | #endif | 17 | #endif |
| 17 | 18 | ||
| 19 | #ifdef ENCODER_ENABLE | ||
| 20 | # include "encoder.h" | ||
| 21 | #endif | ||
| 22 | |||
| 18 | #if defined(USE_I2C) || defined(EH) | 23 | #if defined(USE_I2C) || defined(EH) |
| 19 | 24 | ||
| 20 | # include "i2c_master.h" | 25 | # include "i2c_master.h" |
| 21 | # include "i2c_slave.h" | 26 | # include "i2c_slave.h" |
| 22 | 27 | ||
| 23 | # define I2C_BACKLIT_START 0x00 | 28 | typedef struct __attribute__ ((__packed__)) { |
| 24 | // Need 4 bytes for RGB (32 bit) | 29 | #ifdef BACKLIGHT_ENABLE |
| 25 | # define I2C_RGB_START 0x01 | 30 | uint8_t backlight_level; |
| 26 | # define I2C_KEYMAP_START 0x05 | 31 | #endif |
| 32 | #ifdef RGBLIGHT_ENABLE | ||
| 33 | uint32_t rgb_settings; | ||
| 34 | #endif | ||
| 35 | #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) | ||
| 51 | #endif | ||
| 52 | |||
| 53 | #ifdef ENCODER_ENABLE | ||
| 54 | # define I2C_ENCODER_START (uint8_t)offsetof(transport_values_t, encoder_state) | ||
| 55 | #endif | ||
| 56 | |||
| 57 | #define I2C_KEYMAP_START (uint8_t)offsetof(transport_values_t, matrix_start) | ||
| 27 | 58 | ||
| 28 | # define TIMEOUT 100 | 59 | # define TIMEOUT 100 |
| 29 | 60 | ||
| @@ -37,25 +68,28 @@ bool transport_master(matrix_row_t matrix[]) { | |||
| 37 | 68 | ||
| 38 | // write backlight info | 69 | // write backlight info |
| 39 | # ifdef BACKLIGHT_ENABLE | 70 | # ifdef BACKLIGHT_ENABLE |
| 40 | static uint8_t prev_level = ~0; | 71 | uint8_t level = get_backlight_level(); |
| 41 | uint8_t level = get_backlight_level(); | 72 | if (level != transport_values.backlight_level) { |
| 42 | if (level != prev_level) { | ||
| 43 | if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_BACKLIT_START, (void *)&level, sizeof(level), TIMEOUT) >= 0) { | 73 | if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_BACKLIT_START, (void *)&level, sizeof(level), TIMEOUT) >= 0) { |
| 44 | prev_level = level; | 74 | transport_values.backlight_level = level; |
| 45 | } | 75 | } |
| 46 | } | 76 | } |
| 47 | # endif | 77 | # endif |
| 48 | 78 | ||
| 49 | # ifdef RGBLIGHT_ENABLE | 79 | # ifdef RGBLIGHT_ENABLE |
| 50 | static uint32_t prev_rgb = ~0; | 80 | uint32_t rgb = rgblight_read_dword(); |
| 51 | uint32_t rgb = rgblight_read_dword(); | 81 | if (rgb != transport_values.rgb_settings) { |
| 52 | if (rgb != prev_rgb) { | ||
| 53 | if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_START, (void *)&rgb, sizeof(rgb), TIMEOUT) >= 0) { | 82 | if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_START, (void *)&rgb, sizeof(rgb), TIMEOUT) >= 0) { |
| 54 | prev_rgb = rgb; | 83 | transport_values.rgb_settings = rgb; |
| 55 | } | 84 | } |
| 56 | } | 85 | } |
| 57 | # endif | 86 | # endif |
| 58 | 87 | ||
| 88 | # 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]); | ||
| 91 | # endif | ||
| 92 | |||
| 59 | return true; | 93 | return true; |
| 60 | } | 94 | } |
| 61 | 95 | ||
| @@ -73,6 +107,10 @@ void transport_slave(matrix_row_t matrix[]) { | |||
| 73 | // Update the RGB with the new data | 107 | // Update the RGB with the new data |
| 74 | rgblight_update_dword(rgb); | 108 | rgblight_update_dword(rgb); |
| 75 | # endif | 109 | # endif |
| 110 | |||
| 111 | # ifdef ENCODER_ENABLE | ||
| 112 | encoder_state_raw((uint8_t*)(i2c_slave_reg + I2C_ENCODER_START)); | ||
| 113 | # endif | ||
| 76 | } | 114 | } |
| 77 | 115 | ||
| 78 | void transport_master_init(void) { i2c_init(); } | 116 | void transport_master_init(void) { i2c_init(); } |
| @@ -83,12 +121,15 @@ void transport_slave_init(void) { i2c_slave_init(SLAVE_I2C_ADDRESS); } | |||
| 83 | 121 | ||
| 84 | # include "serial.h" | 122 | # include "serial.h" |
| 85 | 123 | ||
| 86 | typedef struct _Serial_s2m_buffer_t { | 124 | typedef struct __attribute__ ((__packed__)) { |
| 125 | # ifdef ENCODER_ENABLE | ||
| 126 | uint8_t encoder_state[NUMBER_OF_ENCODERS]; | ||
| 127 | # endif | ||
| 87 | // TODO: if MATRIX_COLS > 8 change to uint8_t packed_matrix[] for pack/unpack | 128 | // TODO: if MATRIX_COLS > 8 change to uint8_t packed_matrix[] for pack/unpack |
| 88 | matrix_row_t smatrix[ROWS_PER_HAND]; | 129 | matrix_row_t smatrix[ROWS_PER_HAND]; |
| 89 | } Serial_s2m_buffer_t; | 130 | } Serial_s2m_buffer_t; |
| 90 | 131 | ||
| 91 | typedef struct _Serial_m2s_buffer_t { | 132 | typedef struct __attribute__ ((__packed__)) { |
| 92 | # ifdef BACKLIGHT_ENABLE | 133 | # ifdef BACKLIGHT_ENABLE |
| 93 | uint8_t backlight_level; | 134 | uint8_t backlight_level; |
| 94 | # endif | 135 | # endif |
| @@ -147,6 +188,10 @@ bool transport_master(matrix_row_t matrix[]) { | |||
| 147 | } | 188 | } |
| 148 | # endif | 189 | # endif |
| 149 | 190 | ||
| 191 | # ifdef ENCODER_ENABLE | ||
| 192 | encoder_update_raw((uint8_t*)&serial_s2m_buffer.encoder_state); | ||
| 193 | # endif | ||
| 194 | |||
| 150 | return true; | 195 | return true; |
| 151 | } | 196 | } |
| 152 | 197 | ||
| @@ -162,6 +207,10 @@ void transport_slave(matrix_row_t matrix[]) { | |||
| 162 | // Update RGB config with the new data | 207 | // Update RGB config with the new data |
| 163 | rgblight_update_dword(serial_m2s_buffer.rgblight_config.raw); | 208 | rgblight_update_dword(serial_m2s_buffer.rgblight_config.raw); |
| 164 | # endif | 209 | # endif |
| 210 | |||
| 211 | # ifdef ENCODER_ENABLE | ||
| 212 | encoder_state_raw((uint8_t*)&serial_s2m_buffer.encoder_state); | ||
| 213 | # endif | ||
| 165 | } | 214 | } |
| 166 | 215 | ||
| 167 | #endif | 216 | #endif |
