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 168c82ef82c88e79979d9796bab9cc819cc2f685.

* 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
This commit is contained in:
Takeshi ISHII
2018-12-25 04:14:57 +09:00
committed by Drashna Jaelre
parent 2149f3b588
commit 72d4e4bfd7
9 changed files with 580 additions and 173 deletions

View File

@ -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

View File

@ -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,6 +52,8 @@ 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))
@ -62,6 +61,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# 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 @@ i2c_error: // the cable is disconnceted, or something else went wrong
#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();

View File

@ -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,6 +52,8 @@ 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))
@ -62,6 +61,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# 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 @@ i2c_error: // the cable is disconnceted, or something else went wrong
#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();

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
#ifndef MY_SERIAL_H
#define MY_SERIAL_H
#ifndef SOFT_SERIAL_H
#define SOFT_SERIAL_H
#include <stdbool.h>
@ -7,20 +7,59 @@
// Need Soft Serial defines in config.h
// /////////////////////////////////////////////////////////////////
// ex.
// /* Configuration of lower interface with the lower layer(hardware) of serial.c */
// #define SOFT_SERIAL_PIN ?? // ?? = D0,D1,D2,D3,E6
// OPTIONAL: #define SELECT_SOFT_SERIAL_SPEED ? // ? = 1,2,3,4,5
// // 1: about 137kbps (default)
// // 2: about 75kbps
// // 3: about 39kbps
// // 4: about 26kbps
// // 5: about 20kbps
//
// /* Configuration of upper interface with the upper layer of serial.c */
// #define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
// #define SERIAL_MASTER_BUFFER_LENGTH 1
// //// USE simple API (using signle-type transaction function)
// /* nothing */
// //// USE flexible API (using multi-type transaction function)
// #define SERIAL_USE_MULTI_TRANSACTION
//
// /////////////////////////////////////////////////////////////////
// Buffers for master - slave communication
extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH];
extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH];
// Soft Serial Transaction Descriptor
typedef struct _SSTD_t {
uint8_t *status;
uint8_t initiator2target_buffer_size;
uint8_t *initiator2target_buffer;
uint8_t target2initiator_buffer_size;
uint8_t *target2initiator_buffer;
} SSTD_t;
#define TID_LIMIT( table ) (sizeof(table) / sizeof(SSTD_t))
void serial_master_init(void);
void serial_slave_init(void);
int serial_update_buffers(void);
bool serial_slave_data_corrupt(void);
// initiator is transaction start side
void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size);
// target is interrupt accept side
void soft_serial_target_init(SSTD_t *sstd_table, int sstd_table_size);
// initiator resullt
#define TRANSACTION_END 0
#define TRANSACTION_NO_RESPONSE 0x1
#define TRANSACTION_DATA_ERROR 0x2
#define TRANSACTION_TYPE_ERROR 0x4
#ifndef SERIAL_USE_MULTI_TRANSACTION
int soft_serial_transaction(void);
#else
int soft_serial_transaction(int sstd_index);
#endif
// target status
// *SSTD_t.status has
// initiator:
// TRANSACTION_END
// or TRANSACTION_NO_RESPONSE
// or TRANSACTION_DATA_ERROR
// target:
// TRANSACTION_DATA_ERROR
// or TRANSACTION_ACCEPTED
#define TRANSACTION_ACCEPTED 0x8
#ifdef SERIAL_USE_MULTI_TRANSACTION
int soft_serial_get_and_clean_status(int sstd_index);
#endif
#endif /* SOFT_SERIAL_H */

View File

@ -1,11 +0,0 @@
/* serial.h backward compatibility */
// #ifndef SOFT_SERIAL_PIN
// #define SOFT_SERIAL_PIN D0
// #endif
#ifndef SERIAL_SLAVE_BUFFER_LENGTH
#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
#define SERIAL_MASTER_BUFFER_LENGTH 1
#endif

View File

@ -11,9 +11,6 @@
#include "timer.h"
#include "split_flags.h"
#ifdef RGBLIGHT_ENABLE
# include "rgblight.h"
#endif
#ifdef BACKLIGHT_ENABLE
# include "backlight.h"
#endif
@ -24,8 +21,6 @@
#if defined(USE_I2C) || defined(EH)
# include "i2c.h"
#else
# include "serial.h"
#endif
volatile bool isLeftHand = true;
@ -112,7 +107,7 @@ void keyboard_slave_loop(void) {
BACKLIT_DIRTY = false;
}
#else // USE_SERIAL
backlight_set(serial_master_buffer[SERIAL_BACKLIT_START]);
backlight_set(serial_m2s_buffer.backlight_level);
#endif
#endif
// Read RGB Info
@ -137,7 +132,9 @@ void keyboard_slave_loop(void) {
sei();
}
#else // USE_SERIAL
#ifdef RGBLIGHT_SPLIT
// Add serial implementation for RGB here
#endif
#endif
#endif
}

View File

@ -7,9 +7,6 @@
#include <stdlib.h>
#include "eeconfig.h"
// backlight level store index in serial_master_buffer[] for slave to read
#define SERIAL_BACKLIT_START 0x00
#define SLAVE_I2C_ADDRESS 0x32
extern volatile bool isLeftHand;