Skip to content

Commit

Permalink
add I2C_slave_buffer_t to quantum/split_common/transport.c
Browse files Browse the repository at this point in the history
Improvements to ease the maintenance of the I2C slave buffer layout. And this commit does not change the compilation results.
  • Loading branch information
mtei committed Mar 29, 2019
1 parent aebddfc commit c01656a
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions quantum/split_common/transport.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <string.h>
#include <stddef.h>

#include "config.h"
#include "matrix.h"
Expand All @@ -20,10 +21,17 @@ extern backlight_config_t backlight_config;
# include "i2c_master.h"
# include "i2c_slave.h"

# define I2C_BACKLIT_START 0x00
// Need 4 bytes for RGB (32 bit)
# define I2C_RGB_START 0x01
# define I2C_KEYMAP_START 0x05
typedef struct _I2C_slave_buffer_t {
uint8_t backlit_level;
uint32_t rgb_config;
matrix_row_t smatrix[ROWS_PER_HAND];
} I2C_slave_buffer_t;

static I2C_slave_buffer_t * const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg;

# define I2C_BACKLIT_START offsetof(I2C_slave_buffer_t, backlit_level)
# define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgb_config)
# define I2C_KEYMAP_START offsetof(I2C_slave_buffer_t, smatrix)

# define TIMEOUT 100

Expand All @@ -33,7 +41,7 @@ extern backlight_config_t backlight_config;

// 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);
i2c_readReg(SLAVE_I2C_ADDRESS, I2C_KEYMAP_START, (void *)matrix, sizeof(i2c_buffer->smatrix), TIMEOUT);

// write backlight info
# ifdef BACKLIGHT_ENABLE
Expand Down Expand Up @@ -61,17 +69,16 @@ bool transport_master(matrix_row_t matrix[]) {

void transport_slave(matrix_row_t matrix[]) {
// Copy matrix to I2C buffer
memcpy((void*)(i2c_slave_reg + I2C_KEYMAP_START), (void *)matrix, ROWS_PER_HAND * sizeof(matrix_row_t) );
memcpy((void*)i2c_buffer->smatrix, (void *)matrix, sizeof(i2c_buffer->smatrix));

// Read Backlight Info
# ifdef BACKLIGHT_ENABLE
backlight_set(i2c_slave_reg[I2C_BACKLIT_START]);
backlight_set(i2c_buffer->backlit_level);
# 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);
rgblight_update_dword(i2c_buffer->rgb_config);
# endif
}

Expand Down

0 comments on commit c01656a

Please sign in to comment.