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)
21 #ifndef SLAVE_I2C_ADDRESS
22 # define SLAVE_I2C_ADDRESS 0x32
26 # error "Currently only supports 8 COLS"
29 // Get rows from other half over i2c
30 bool transport_master(matrix_row_t matrix[]) {
33 // write backlight info
34 #ifdef BACKLIGHT_ENABLE
36 err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE);
37 if (err) { goto i2c_error; }
40 err = i2c_master_write(I2C_BACKLIT_START);
41 if (err) { goto i2c_error; }
44 i2c_master_write(get_backlight_level());
46 BACKLIT_DIRTY = false;
50 err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE);
51 if (err) { goto i2c_error; }
53 // start of matrix stored at I2C_KEYMAP_START
54 err = i2c_master_write(I2C_KEYMAP_START);
55 if (err) { goto i2c_error; }
58 err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_READ);
59 if (err) { goto i2c_error; }
63 for (i = 0; i < ROWS_PER_HAND-1; ++i) {
64 matrix[i] = i2c_master_read(I2C_ACK);
66 matrix[i] = i2c_master_read(I2C_NACK);
69 i2c_error: // the cable is disconnceted, or something else went wrong
74 #ifdef RGBLIGHT_ENABLE
76 err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE);
77 if (err) { goto i2c_error; }
80 err = i2c_master_write(I2C_RGB_START);
81 if (err) { goto i2c_error; }
83 uint32_t dword = eeconfig_read_rgblight();
86 err = i2c_master_write_data(&dword, 4);
87 if (err) { goto i2c_error; }
97 void transport_slave(matrix_row_t matrix[]) {
99 for (int i = 0; i < ROWS_PER_HAND; ++i)
101 i2c_slave_buffer[I2C_KEYMAP_START + i] = matrix[i];
103 // Read Backlight Info
104 #ifdef BACKLIGHT_ENABLE
107 backlight_set(i2c_slave_buffer[I2C_BACKLIT_START]);
108 BACKLIT_DIRTY = false;
111 #ifdef RGBLIGHT_ENABLE
114 // Disable interupts (RGB data is big)
116 // Create new DWORD for RGB data
119 // Fill the new DWORD with the data that was sent over
120 uint8_t * dword_dat = (uint8_t *)(&dword);
121 for (int i = 0; i < 4; i++)
123 dword_dat[i] = i2c_slave_buffer[I2C_RGB_START + i];
126 // Update the RGB now with the new data and set RGB_DIRTY to false
127 rgblight_update_dword(dword);
129 // Re-enable interupts now that RGB is set
135 void transport_master_init(void) {
139 void transport_slave_init(void) {
140 i2c_slave_init(SLAVE_I2C_ADDRESS);
147 typedef struct _Serial_s2m_buffer_t {
148 // TODO: if MATRIX_COLS > 8 change to uint8_t packed_matrix[] for pack/unpack
149 matrix_row_t smatrix[ROWS_PER_HAND];
150 } Serial_s2m_buffer_t;
152 typedef struct _Serial_m2s_buffer_t {
153 #ifdef BACKLIGHT_ENABLE
154 uint8_t backlight_level;
156 #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
157 rgblight_config_t rgblight_config; //not yet use
159 // When MCUs on both sides drive their respective RGB LED chains,
160 // it is necessary to synchronize, so it is necessary to communicate RGB information.
161 // In that case, define the RGBLIGHT_SPLIT macro.
163 // Otherwise, if the master side MCU drives both sides RGB LED chains,
164 // there is no need to communicate.
166 } Serial_m2s_buffer_t;
168 volatile Serial_s2m_buffer_t serial_s2m_buffer = {};
169 volatile Serial_m2s_buffer_t serial_m2s_buffer = {};
170 uint8_t volatile status0 = 0;
172 SSTD_t transactions[] = {
173 { (uint8_t *)&status0,
174 sizeof(serial_m2s_buffer), (uint8_t *)&serial_m2s_buffer,
175 sizeof(serial_s2m_buffer), (uint8_t *)&serial_s2m_buffer
179 void transport_master_init(void)
180 { soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); }
182 void transport_slave_init(void)
183 { soft_serial_target_init(transactions, TID_LIMIT(transactions)); }
185 bool transport_master(matrix_row_t matrix[]) {
187 if (soft_serial_transaction()) {
191 // TODO: if MATRIX_COLS > 8 change to unpack()
192 for (int i = 0; i < ROWS_PER_HAND; ++i) {
193 matrix[i] = serial_s2m_buffer.smatrix[i];
196 #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
197 // Code to send RGB over serial goes here (not implemented yet)
200 #ifdef BACKLIGHT_ENABLE
201 // Write backlight level for slave to read
202 serial_m2s_buffer.backlight_level = backlight_config.enable ? backlight_config.level : 0;
208 void transport_slave(matrix_row_t matrix[]) {
210 // TODO: if MATRIX_COLS > 8 change to pack()
211 for (int i = 0; i < ROWS_PER_HAND; ++i)
213 serial_s2m_buffer.smatrix[i] = matrix[i];
215 #ifdef BACKLIGHT_ENABLE
216 backlight_set(serial_m2s_buffer.backlight_level);
218 #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
219 // Add serial implementation for RGB here