6 #define ROWS_PER_HAND (MATRIX_ROWS / 2)
12 #ifdef BACKLIGHT_ENABLE
13 # include "backlight.h"
14 extern backlight_config_t backlight_config;
17 #if defined(USE_I2C) || defined(EH)
19 # include "i2c_master.h"
20 # include "i2c_slave.h"
22 # define I2C_BACKLIT_START 0x00
23 // Need 4 bytes for RGB (32 bit)
24 # define I2C_RGB_START 0x01
25 # define I2C_KEYMAP_START 0x05
29 # ifndef SLAVE_I2C_ADDRESS
30 # define SLAVE_I2C_ADDRESS 0x32
33 // Get rows from other half over i2c
34 bool transport_master(matrix_row_t matrix[]) {
35 i2c_readReg(SLAVE_I2C_ADDRESS, I2C_KEYMAP_START, (void *)matrix, ROWS_PER_HAND * sizeof(matrix_row_t), TIMEOUT);
37 // write backlight info
38 # ifdef BACKLIGHT_ENABLE
39 static uint8_t prev_level = ~0;
40 uint8_t level = get_backlight_level();
41 if (level != prev_level) {
42 if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_BACKLIT_START, (void *)&level, sizeof(level), TIMEOUT) >= 0) {
48 # ifdef RGBLIGHT_ENABLE
49 static uint32_t prev_rgb = ~0;
50 uint32_t rgb = rgblight_read_dword();
51 if (rgb != prev_rgb) {
52 if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_START, (void *)&rgb, sizeof(rgb), TIMEOUT) >= 0) {
61 void transport_slave(matrix_row_t matrix[]) {
62 for (int i = 0; i < ROWS_PER_HAND * sizeof(matrix_row_t); ++i) {
63 i2c_slave_reg[I2C_KEYMAP_START + i] = matrix[i];
66 // Read Backlight Info
67 # ifdef BACKLIGHT_ENABLE
68 backlight_set(i2c_slave_reg[I2C_BACKLIT_START]);
71 # ifdef RGBLIGHT_ENABLE
72 uint32_t rgb = *(uint32_t *)(i2c_slave_reg + I2C_RGB_START);
73 // Update the RGB with the new data
74 rgblight_update_dword(rgb);
78 void transport_master_init(void) { i2c_init(); }
80 void transport_slave_init(void) { i2c_slave_init(SLAVE_I2C_ADDRESS); }
86 typedef struct _Serial_s2m_buffer_t {
87 // TODO: if MATRIX_COLS > 8 change to uint8_t packed_matrix[] for pack/unpack
88 matrix_row_t smatrix[ROWS_PER_HAND];
89 } Serial_s2m_buffer_t;
91 typedef struct _Serial_m2s_buffer_t {
92 # ifdef BACKLIGHT_ENABLE
93 uint8_t backlight_level;
95 # if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
96 rgblight_config_t rgblight_config; // not yet use
98 // When MCUs on both sides drive their respective RGB LED chains,
99 // it is necessary to synchronize, so it is necessary to communicate RGB
100 // information. In that case, define the RGBLIGHT_SPLIT macro.
102 // Otherwise, if the master side MCU drives both sides RGB LED chains,
103 // there is no need to communicate.
105 } Serial_m2s_buffer_t;
107 volatile Serial_s2m_buffer_t serial_s2m_buffer = {};
108 volatile Serial_m2s_buffer_t serial_m2s_buffer = {};
109 uint8_t volatile status0 = 0;
111 SSTD_t transactions[] = {
114 sizeof(serial_m2s_buffer),
115 (uint8_t *)&serial_m2s_buffer,
116 sizeof(serial_s2m_buffer),
117 (uint8_t *)&serial_s2m_buffer,
121 void transport_master_init(void) { soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); }
123 void transport_slave_init(void) { soft_serial_target_init(transactions, TID_LIMIT(transactions)); }
125 bool transport_master(matrix_row_t matrix[]) {
126 if (soft_serial_transaction()) {
130 // TODO: if MATRIX_COLS > 8 change to unpack()
131 for (int i = 0; i < ROWS_PER_HAND; ++i) {
132 matrix[i] = serial_s2m_buffer.smatrix[i];
135 # if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
136 // Code to send RGB over serial goes here (not implemented yet)
139 # ifdef BACKLIGHT_ENABLE
140 // Write backlight level for slave to read
141 serial_m2s_buffer.backlight_level = backlight_config.enable ? backlight_config.level : 0;
147 void transport_slave(matrix_row_t matrix[]) {
148 // TODO: if MATRIX_COLS > 8 change to pack()
149 for (int i = 0; i < ROWS_PER_HAND; ++i) {
150 serial_s2m_buffer.smatrix[i] = matrix[i];
152 # ifdef BACKLIGHT_ENABLE
153 backlight_set(serial_m2s_buffer.backlight_level);
155 # if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
156 // Add serial implementation for RGB here