Skip to content
Permalink
Browse files

Replace serial.c of quantum/split_common/ (#4669)

* Add provisional Helix implementation to test the quantum/split_common.

* copy keyboards/helix/serial.[ch] to quantum/split_common/

* Make serial.c a pure driver.

Remove buffer name and buffer size from serial.c. They should be placed in the caller(matrix.c, split_utils.c).

* remove quantum/split_common/serial_backward_compatibility.h

* Changed array serial_master_buffer to structure serial_m2s_buffer.

* Changed array serial_slave_buffer to structure serial_s2m_buffer.

* Change keyboards/miniaxe/matrix.c

I also made changes to quantum/split_comon/matrix.c to keyboards/miniaxe/matrix.c.

Note: I contacted @ka2hiro, creator of miniaxe, and I got permission to change keyboards/miniaxe/matrix.c.

* update history comment in quantum/split_common/serial.c

* Revert "Add provisional Helix implementation to test the quantum/split_common."

This reverts commit 168c82e.

* fix keyboards/miniaxe/matrix.c, quantum/split_common/matrix.c

avr-gcc 4.9.[23] report error.
avr-gcc 5.4.0, avr-gcc 7.3.0 pass.
It is funny.

* update comment quantum/split_common/serial.c

* Reserve RGBLIGHT_SPLIT macro in quantum/split_common
  • Loading branch information
mtei authored and drashna committed Dec 24, 2018
1 parent 2149f3b commit 72d4e4bfd76b2c83b89787f8b3a8ba779a3e8d81
@@ -263,11 +263,6 @@ ifneq ($(strip $(CUSTOM_MATRIX)), yes)
endif

ifeq ($(strip $(SPLIT_KEYBOARD)), yes)
SERIAL_BACKWARD_COMPAT := $(wildcard $(QUANTUM_DIR)/split_common/serial_backward_compatibility.h)
ifneq ($(SERIAL_BACKWARD_COMPAT),)
CONFIG_H += $(SERIAL_BACKWARD_COMPAT)
# $(info CONFIG_H=$(CONFIG_H))
endif
OPT_DEFS += -DSPLIT_KEYBOARD
QUANTUM_SRC += $(QUANTUM_DIR)/split_common/split_flags.c \
$(QUANTUM_DIR)/split_common/split_util.c
@@ -32,9 +32,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "timer.h"
#include "split_flags.h"

#ifdef RGBLIGHT_ENABLE
# include "rgblight.h"
#endif
#ifdef BACKLIGHT_ENABLE
# include "backlight.h"
extern backlight_config_t backlight_config;
@@ -55,13 +52,36 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
static bool debouncing = false;
#endif

#if defined(USE_I2C) || defined(EH)

#if (MATRIX_COLS <= 8)
# define print_matrix_header() print("\nr/c 01234567\n")
# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
# define matrix_bitpop(i) bitpop(matrix[i])
# define ROW_SHIFTER ((uint8_t)1)
#else
# error "Currently only supports 8 COLS"
#endif

#else // USE_SERIAL

#if (MATRIX_COLS <= 8)
# define print_matrix_header() print("\nr/c 01234567\n")
# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
# define matrix_bitpop(i) bitpop(matrix[i])
# define ROW_SHIFTER ((uint8_t)1)
#elif (MATRIX_COLS <= 16)
# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n")
# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row))
# define matrix_bitpop(i) bitpop16(matrix[i])
# define ROW_SHIFTER ((uint16_t)1)
#elif (MATRIX_COLS <= 32)
# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row))
# define matrix_bitpop(i) bitpop32(matrix[i])
# define ROW_SHIFTER ((uint32_t)1)
#endif

#endif
static matrix_row_t matrix_debouncing[MATRIX_ROWS];

@@ -315,15 +335,39 @@ int i2c_transaction(void) {

#else // USE_SERIAL


typedef struct _Serial_s2m_buffer_t {
// TODO: if MATRIX_COLS > 8 change to uint8_t packed_matrix[] for pack/unpack
matrix_row_t smatrix[ROWS_PER_HAND];
} Serial_s2m_buffer_t;

volatile Serial_s2m_buffer_t serial_s2m_buffer = {};
volatile Serial_m2s_buffer_t serial_m2s_buffer = {};
uint8_t volatile status0 = 0;

SSTD_t transactions[] = {
{ (uint8_t *)&status0,
sizeof(serial_m2s_buffer), (uint8_t *)&serial_m2s_buffer,
sizeof(serial_s2m_buffer), (uint8_t *)&serial_s2m_buffer
}
};

void serial_master_init(void)
{ soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); }

void serial_slave_init(void)
{ soft_serial_target_init(transactions, TID_LIMIT(transactions)); }

int serial_transaction(void) {
int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;

if (serial_update_buffers()) {
if (soft_serial_transaction()) {
return 1;
}

// TODO: if MATRIX_COLS > 8 change to unpack()
for (int i = 0; i < ROWS_PER_HAND; ++i) {
matrix[slaveOffset+i] = serial_slave_buffer[i];
matrix[slaveOffset+i] = serial_s2m_buffer.smatrix[i];
}

#ifdef RGBLIGHT_ENABLE
@@ -332,7 +376,7 @@ int serial_transaction(void) {

#ifdef BACKLIGHT_ENABLE
// Write backlight level for slave to read
serial_master_buffer[SERIAL_BACKLIT_START] = backlight_config.enable ? backlight_config.level : 0;
serial_m2s_buffer.backlight_level = backlight_config.enable ? backlight_config.level : 0;
#endif

return 0;
@@ -375,8 +419,9 @@ void matrix_slave_scan(void) {
i2c_slave_buffer[I2C_KEYMAP_START+i] = matrix[offset+i];
}
#else // USE_SERIAL
// TODO: if MATRIX_COLS > 8 change to pack()
for (int i = 0; i < ROWS_PER_HAND; ++i) {
serial_slave_buffer[i] = matrix[offset+i];
serial_s2m_buffer.smatrix[i] = matrix[offset+i];
}
#endif
matrix_slave_scan_user();
@@ -32,9 +32,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "timer.h"
#include "split_flags.h"

#ifdef RGBLIGHT_ENABLE
# include "rgblight.h"
#endif
#ifdef BACKLIGHT_ENABLE
# include "backlight.h"
extern backlight_config_t backlight_config;
@@ -55,13 +52,36 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
static bool debouncing = false;
#endif

#if defined(USE_I2C) || defined(EH)

#if (MATRIX_COLS <= 8)
# define print_matrix_header() print("\nr/c 01234567\n")
# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
# define matrix_bitpop(i) bitpop(matrix[i])
# define ROW_SHIFTER ((uint8_t)1)
#else
# error "Currently only supports 8 COLS"
#endif

#else // USE_SERIAL

#if (MATRIX_COLS <= 8)
# define print_matrix_header() print("\nr/c 01234567\n")
# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
# define matrix_bitpop(i) bitpop(matrix[i])
# define ROW_SHIFTER ((uint8_t)1)
#elif (MATRIX_COLS <= 16)
# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n")
# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row))
# define matrix_bitpop(i) bitpop16(matrix[i])
# define ROW_SHIFTER ((uint16_t)1)
#elif (MATRIX_COLS <= 32)
# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row))
# define matrix_bitpop(i) bitpop32(matrix[i])
# define ROW_SHIFTER ((uint32_t)1)
#endif

#endif
static matrix_row_t matrix_debouncing[MATRIX_ROWS];

@@ -286,24 +306,48 @@ int i2c_transaction(void) {

#else // USE_SERIAL


typedef struct _Serial_s2m_buffer_t {
// TODO: if MATRIX_COLS > 8 change to uint8_t packed_matrix[] for pack/unpack
matrix_row_t smatrix[ROWS_PER_HAND];
} Serial_s2m_buffer_t;

volatile Serial_s2m_buffer_t serial_s2m_buffer = {};
volatile Serial_m2s_buffer_t serial_m2s_buffer = {};
uint8_t volatile status0 = 0;

SSTD_t transactions[] = {
{ (uint8_t *)&status0,
sizeof(serial_m2s_buffer), (uint8_t *)&serial_m2s_buffer,
sizeof(serial_s2m_buffer), (uint8_t *)&serial_s2m_buffer
}
};

void serial_master_init(void)
{ soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); }

void serial_slave_init(void)
{ soft_serial_target_init(transactions, TID_LIMIT(transactions)); }

int serial_transaction(void) {
int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;

if (serial_update_buffers()) {
if (soft_serial_transaction()) {
return 1;
}

// TODO: if MATRIX_COLS > 8 change to unpack()
for (int i = 0; i < ROWS_PER_HAND; ++i) {
matrix[slaveOffset+i] = serial_slave_buffer[i];
matrix[slaveOffset+i] = serial_s2m_buffer.smatrix[i];
}

#ifdef RGBLIGHT_ENABLE
#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
// Code to send RGB over serial goes here (not implemented yet)
#endif

#ifdef BACKLIGHT_ENABLE
// Write backlight level for slave to read
serial_master_buffer[SERIAL_BACKLIT_START] = backlight_config.enable ? backlight_config.level : 0;
serial_m2s_buffer.backlight_level = backlight_config.enable ? backlight_config.level : 0;
#endif

return 0;
@@ -346,8 +390,9 @@ void matrix_slave_scan(void) {
i2c_slave_buffer[I2C_KEYMAP_START+i] = matrix[offset+i];
}
#else // USE_SERIAL
// TODO: if MATRIX_COLS > 8 change to pack()
for (int i = 0; i < ROWS_PER_HAND; ++i) {
serial_slave_buffer[i] = matrix[offset+i];
serial_s2m_buffer.smatrix[i] = matrix[offset+i];
}
#endif
matrix_slave_scan_user();
@@ -0,0 +1,31 @@
#ifndef SPLIT_COMMON_MATRIX_H
#define SPLIT_COMMON_MATRIX_H

#include <common/matrix.h>

#ifdef RGBLIGHT_ENABLE
# include "rgblight.h"
#endif

typedef struct _Serial_m2s_buffer_t {
#ifdef BACKLIGHT_ENABLE
uint8_t backlight_level;
#endif
#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
rgblight_config_t rgblight_config; //not yet use
//
// When MCUs on both sides drive their respective RGB LED chains,
// it is necessary to synchronize, so it is necessary to communicate RGB information.
// In that case, define the RGBLIGHT_SPLIT macro.
//
// Otherwise, if the master side MCU drives both sides RGB LED chains,
// there is no need to communicate.
#endif
} Serial_m2s_buffer_t;

extern volatile Serial_m2s_buffer_t serial_m2s_buffer;

void serial_master_init(void);
void serial_slave_init(void);

#endif

0 comments on commit 72d4e4b

Please sign in to comment.