From 78886777d50f6b75ffff8af1b833dc3068d2f6b4 Mon Sep 17 00:00:00 2001 From: JX <572673807@qq.com> Date: Sun, 22 Aug 2021 03:05:10 +0800 Subject: [PATCH] fix split oled layer state and current input not sync --- keyboards/crkbd/rev1/config.h | 2 +- keyboards/yandrstudio/hotdox76_V2/config.h | 11 +- .../yandrstudio/hotdox76_V2/hotdox76_V2.c | 99 ++++--- .../yandrstudio/hotdox76_V2/hotdox76_V2.h | 3 + .../hotdox76_V2/keymaps/default/rules.mk | 4 +- .../hotdox76_V2/keymaps/via/config.h | 46 +-- .../hotdox76_V2/keymaps/via/keymap.c | 2 +- .../hotdox76_V2/keymaps/via/rules.mk | 4 +- .../hotdox76_V2/oled_font_lib/ext_font.h | 8 +- .../hotdox76_V2/oled_font_lib/logo.h | 4 +- keyboards/yandrstudio/hotdox76_V2/rules.mk | 18 +- .../hotdox76_V2/transport_lib/transport.c | 265 ++++++++++++++++++ keyboards/yandrstudio/zhou75/readme.md | 1 + 13 files changed, 378 insertions(+), 89 deletions(-) create mode 100644 keyboards/yandrstudio/hotdox76_V2/transport_lib/transport.c diff --git a/keyboards/crkbd/rev1/config.h b/keyboards/crkbd/rev1/config.h index 337859d05ca1..03c05cbf1635 100644 --- a/keyboards/crkbd/rev1/config.h +++ b/keyboards/crkbd/rev1/config.h @@ -22,7 +22,7 @@ along with this program. If not, see . #define SOFT_SERIAL_PIN D2 /* ws2812 RGB LED */ -#define RGB_DI_PIN D3 +#define RGB_DI_PIN D3 #ifdef RGBLIGHT_ENABLE # define RGBLED_NUM 12 // Number of LEDs diff --git a/keyboards/yandrstudio/hotdox76_V2/config.h b/keyboards/yandrstudio/hotdox76_V2/config.h index 2357448220dd..8bc08a841081 100644 --- a/keyboards/yandrstudio/hotdox76_V2/config.h +++ b/keyboards/yandrstudio/hotdox76_V2/config.h @@ -22,7 +22,7 @@ #define PRODUCT_ID 0xAAA9 #define DEVICE_VER 0x0002 #define MANUFACTURER JasonRen biu -#define PRODUCT hotdox76_V2 +#define PRODUCT hotdox76V2 /* key matrix size */ #define MATRIX_ROWS 6*2 @@ -86,12 +86,13 @@ # define RGBLIGHT_SPLIT # define RGBLED_SPLIT {43, 43} - # define RGB_DI_PIN D3 # define RGBLED_NUM (43*2) # define DRIVER_LED_TOTAL RGBLED_NUM # define RGBLIGHT_LIMIT_VAL 150 # define RGBLIGHT_SLEEP +# define WS2812_TRST_US 100 +# define RGBLIGHT_ANIMATIONS // # define WS2812_BYTE_ORDER WS2812_BYTE_ORDER_RGB @@ -106,6 +107,8 @@ # define SOFT_SERIAL_PIN D2 # define SPLIT_MODS_ENABLE +# define SPLIT_TRANSPORT_MIRROR + # define SPLIT_USB_DETECT @@ -127,8 +130,8 @@ */ /* disable action features */ -#define NO_ACTION_LAYER -#define NO_ACTION_TAPPING +// #define NO_ACTION_LAYER +// #define NO_ACTION_TAPPING #define NO_ACTION_ONESHOT /* disable these deprecated features by default */ diff --git a/keyboards/yandrstudio/hotdox76_V2/hotdox76_V2.c b/keyboards/yandrstudio/hotdox76_V2/hotdox76_V2.c index 2ce00cefa38e..f11f26aa3bd7 100644 --- a/keyboards/yandrstudio/hotdox76_V2/hotdox76_V2.c +++ b/keyboards/yandrstudio/hotdox76_V2/hotdox76_V2.c @@ -3,6 +3,20 @@ #include "oled_font_lib/logo.h" #include "oled_font_lib/ext_font.h" + + + +bool is_keyboard_left(void) { + +#ifdef I_AM_LEFT + return true; +#else + return false; +#endif + +} + + #ifdef RGB_MATRIX_ENABLE led_config_t g_led_config = { { @@ -54,6 +68,7 @@ led_config_t g_led_config = { #endif + #ifdef OLED_DRIVER_ENABLE # define UNC (94+0x21) @@ -81,85 +96,88 @@ void render_logo(void) { for (i = 0; i < 4; ++i) { for (j = 0; j < 32; ++j) { # ifdef I_AM_LEFT - oled_write_raw_byte(logo_idobao[i*32+j], i*128+j); + oled_write_raw_byte(pgm_read_byte(&logo_idobao[i*32+j]), i*128+j); # else - oled_write_raw_byte(logo_idobao[i*32+j], i*128+j+96); + oled_write_raw_byte(pgm_read_byte(&logo_idobao[i*32+j]), i*128+j+96); # endif } } } - -void render_layer_helper_fun(uint8_t start_line, const char * data, uint8_t gap_w) { - uint8_t j = 0, k = 0, l = strlen(data); +void render_layer_helper_fun(uint8_t start_line, const char * data, uint8_t gap_w, uint8_t l) { + uint8_t j = 0, k = 0; for (j = 0; j < l; ++j) { // font index for (k = 0; k < 12; ++k) { // font byte index // base + logo_w(32) + gap_w(12) +l*font_w(12)+current_byte_index - oled_write_raw_byte(ext_big_font[data[j]-0x21][k], start_line*2*128 + 32 + gap_w + j*12+k); - oled_write_raw_byte(ext_big_font[data[j]-0x21][k+12], start_line*2*128+128 + 32 + gap_w + j*12+k); + oled_write_raw_byte(pgm_read_byte(&ext_big_font[pgm_read_byte(&data[j])-0x21][k]), start_line*2*128 + 32 + gap_w + j*12+k); + oled_write_raw_byte(pgm_read_byte(&ext_big_font[pgm_read_byte(&data[j])-0x21][k+12]), start_line*2*128+128 + 32 + gap_w + j*12+k); } } for (j = 0; j < gap_w; ++j) { - oled_write_raw_byte(blank_block, start_line*2*128 + 32 + j); - oled_write_raw_byte(blank_block, start_line*2*128 + 32 + gap_w + l*12 + j); + oled_write_raw_byte(pgm_read_byte(&blank_block), start_line*2*128 + 32 + j); + oled_write_raw_byte(pgm_read_byte(&blank_block), start_line*2*128 + 32 + gap_w + l*12 + j); - oled_write_raw_byte(blank_block, start_line*2*128+128 + 32 + j); - oled_write_raw_byte(blank_block, start_line*2*128+128 + 32 + gap_w + l*12 + j); + oled_write_raw_byte(pgm_read_byte(&blank_block), start_line*2*128+128 + 32 + j); + oled_write_raw_byte(pgm_read_byte(&blank_block), start_line*2*128+128 + 32 + gap_w + l*12 + j); } } void render_layer(uint8_t layer) { - render_layer_helper_fun(0, PSTR("LAYER:"), 12); - switch (layer) - { + render_layer_helper_fun(0, PSTR("LAYER:"), 12, 6); + switch (layer) { case 0: - render_layer_helper_fun(1, PSTR("1:HOME"), 12); + render_layer_helper_fun(1, PSTR("1:HOME"), 12, 6); break; case 1: - render_layer_helper_fun(1, PSTR("2:CODE"), 12); + render_layer_helper_fun(1, PSTR("2:CODE"), 12, 6); break; case 2: - render_layer_helper_fun(1, PSTR("3:OFFICE"), 0); + render_layer_helper_fun(1, PSTR("3:OFFICE"), 0, 8); break; case 3: default: - render_layer_helper_fun(1, PSTR("OTHER"), 18); + render_layer_helper_fun(1, PSTR("4:OTHERS"), 0, 8); break; } } -void render_cur_input_helper_fun(uint8_t start_line, const char * data, uint8_t gap_w) { - uint8_t j = 0, k = 0, l = strlen(data); +void render_cur_input_helper_fun(uint8_t start_line, const char * data, uint8_t gap_w, uint8_t l) { + uint8_t j = 0, k = 0; for (j = 0; j < l; ++j) { // font index for (k = 0; k < 12; ++k) { // font byte index // base + logo_w(0) + gap_w(12) +l*font_w(12)+current_byte_index - oled_write_raw_byte(ext_big_font[data[j]-0x21][k], start_line*2*128 + gap_w + j*12+k); - oled_write_raw_byte(ext_big_font[data[j]-0x21][12+k], start_line*2*128+128 + gap_w + j*12+k); + oled_write_raw_byte(pgm_read_byte(&ext_big_font[data[j]-0x21][k]), start_line*2*128 + gap_w + j*12+k); + oled_write_raw_byte(pgm_read_byte(&ext_big_font[data[j]-0x21][12+k]), start_line*2*128+128 + gap_w + j*12+k); } } for (j = 0; j < gap_w; ++j) { - oled_write_raw_byte(blank_block, start_line*2*128 + j); - oled_write_raw_byte(blank_block, start_line*2*128 + gap_w + l*12 + j); + oled_write_raw_byte(pgm_read_byte(&blank_block), start_line*2*128 + j); + oled_write_raw_byte(pgm_read_byte(&blank_block), start_line*2*128 + gap_w + l*12 + j); - oled_write_raw_byte(blank_block, start_line*2*128+128 + j); - oled_write_raw_byte(blank_block, start_line*2*128+128 + gap_w + l*12 + j); + oled_write_raw_byte(pgm_read_byte(&blank_block), start_line*2*128+128 + j); + oled_write_raw_byte(pgm_read_byte(&blank_block), start_line*2*128+128 + gap_w + l*12 + j); } } void render_cur_input(void) { - render_cur_input_helper_fun(0, PSTR("INPUTS:"), 6); - render_cur_input_helper_fun(1, (const char *)(current_alp), 12); + render_cur_input_helper_fun(0, "INPUTS:", 6, 7); + render_cur_input_helper_fun(1, (const char *)(current_alp), 12, 6); return; } void oled_task_user(void) { render_logo(); -# ifdef I_AM_LEFT - render_layer(biton32(layer_state)); -# else - render_cur_input(); -# endif + if (is_keyboard_left()) { + render_layer(biton32(layer_state)); + } else { + render_cur_input(); + } +// # ifdef I_AM_LEFT +// render_layer(biton32(layer_state)); +// # else +// render_cur_input(); +// # endif } @@ -192,18 +210,17 @@ void get_cur_alp_hook(uint16_t keycode) { keycode = 0xF0; } if (cur_alp_index < 4) { - current_alp[cur_alp_index] = code_to_name[keycode]; + current_alp[cur_alp_index] = pgm_read_byte(&code_to_name[keycode]); cur_alp_index++; } else { for (uint8_t i = 2; i <= 4; ++i) { current_alp[i-1] = current_alp[i]; } - current_alp[cur_alp_index] = code_to_name[keycode]; + current_alp[cur_alp_index] = pgm_read_byte(&code_to_name[keycode]); } } bool process_record_kb(uint16_t keycode, keyrecord_t *record) { - get_cur_alp_hook(keycode); return true; @@ -215,19 +232,9 @@ void matrix_scan_kb(void) { cur_alp_index = 1; } } - - #endif -bool is_keyboard_left(void) { - -#ifdef I_AM_LEFT - return true; -#else - return false; -#endif -} // void keyboard_post_init_kb(void) { diff --git a/keyboards/yandrstudio/hotdox76_V2/hotdox76_V2.h b/keyboards/yandrstudio/hotdox76_V2/hotdox76_V2.h index a47f8acc9d18..4e8b74ee36ff 100644 --- a/keyboards/yandrstudio/hotdox76_V2/hotdox76_V2.h +++ b/keyboards/yandrstudio/hotdox76_V2/hotdox76_V2.h @@ -51,3 +51,6 @@ { R110, R111, R112, R113, R114, R115, R116 } \ } +extern volatile char current_alp[7]; +extern volatile uint8_t cur_alp_index; + diff --git a/keyboards/yandrstudio/hotdox76_V2/keymaps/default/rules.mk b/keyboards/yandrstudio/hotdox76_V2/keymaps/default/rules.mk index dc9bca95c85a..0f7809b5c2b1 100644 --- a/keyboards/yandrstudio/hotdox76_V2/keymaps/default/rules.mk +++ b/keyboards/yandrstudio/hotdox76_V2/keymaps/default/rules.mk @@ -1,4 +1,4 @@ -RGB_MATRIX_ENABLE = yes -RGB_MATRIX_DRIVER = WS2812 +# RGB_MATRIX_ENABLE = yes +# RGB_MATRIX_DRIVER = WS2812 # RGBLIGHT_ENABLE = yes # RGBLIGHT_DRIVER = WS2812 diff --git a/keyboards/yandrstudio/hotdox76_V2/keymaps/via/config.h b/keyboards/yandrstudio/hotdox76_V2/keymaps/via/config.h index 463aa7cec2a9..3f332ff78a6b 100644 --- a/keyboards/yandrstudio/hotdox76_V2/keymaps/via/config.h +++ b/keyboards/yandrstudio/hotdox76_V2/keymaps/via/config.h @@ -16,29 +16,29 @@ #pragma once /* RGN Matrix */ -#ifdef RGB_MATRIX_ENABLE +// #ifdef RGB_MATRIX_ENABLE -#define DISABLE_RGB_MATRIX_ALPHAS_MODS -#define DISABLE_RGB_MATRIX_BAND_SAT -#define DISABLE_RGB_MATRIX_BAND_VAL -#define DISABLE_RGB_MATRIX_BAND_PINWHEEL_SAT -#define DISABLE_RGB_MATRIX_BAND_PINWHEEL_VAL -#define DISABLE_RGB_MATRIX_CYCLE_ALL +// #define DISABLE_RGB_MATRIX_ALPHAS_MODS +// #define DISABLE_RGB_MATRIX_BAND_SAT +// #define DISABLE_RGB_MATRIX_BAND_VAL +// #define DISABLE_RGB_MATRIX_BAND_PINWHEEL_SAT +// #define DISABLE_RGB_MATRIX_BAND_PINWHEEL_VAL +// #define DISABLE_RGB_MATRIX_CYCLE_ALL -#define DISABLE_RGB_MATRIX_BAND_SPIRAL_VAL -#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE -#define DISABLE_RGB_MATRIX_SOLID_REACTIVE -#define DISABLE_RGB_MATRIX_HUE_BREATHING -#define DISABLE_RGB_MATRIX_DIGITAL_RAIN -#define DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN -#define DISABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL -#define DISABLE_RGB_MATRIX_CYCLE_SPIRAL -#define DISABLE_RGB_MATRIX_SPLASH -#define DISABLE_RGB_MATRIX_SOLID_MULTISPLASH -#define DISABLE_RGB_MATRIX_SOLID_SPLASH -#define DISABLE_RGB_MATRIX_DUAL_BEACON -#define DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON -#define DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT -#define DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS +// #define DISABLE_RGB_MATRIX_BAND_SPIRAL_VAL +// #define DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE +// #define DISABLE_RGB_MATRIX_SOLID_REACTIVE +// #define DISABLE_RGB_MATRIX_HUE_BREATHING +// #define DISABLE_RGB_MATRIX_DIGITAL_RAIN +// #define DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN +// #define DISABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL +// #define DISABLE_RGB_MATRIX_CYCLE_SPIRAL +// #define DISABLE_RGB_MATRIX_SPLASH +// #define DISABLE_RGB_MATRIX_SOLID_MULTISPLASH +// #define DISABLE_RGB_MATRIX_SOLID_SPLASH +// #define DISABLE_RGB_MATRIX_DUAL_BEACON +// #define DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON +// #define DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT +// #define DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS -#endif +// #endif diff --git a/keyboards/yandrstudio/hotdox76_V2/keymaps/via/keymap.c b/keyboards/yandrstudio/hotdox76_V2/keymaps/via/keymap.c index 90c37c9322c0..4ff9bf45e05c 100644 --- a/keyboards/yandrstudio/hotdox76_V2/keymaps/via/keymap.c +++ b/keyboards/yandrstudio/hotdox76_V2/keymaps/via/keymap.c @@ -31,7 +31,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { */ LAYOUT( // left hand - KC_EQL, RGB_TOG, KC_2, KC_3, KC_4, KC_5, KC_LEFT, + KC_EQL, KC_1, KC_2, KC_3, KC_4, KC_5, KC_LEFT, KC_DEL, KC_Q, KC_W, KC_E, KC_R, KC_T, TG(1), KC_BSPC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_LSFT, CTL_T(KC_Z), KC_X, KC_C, KC_V, KC_B, ALL_T(KC_NO), diff --git a/keyboards/yandrstudio/hotdox76_V2/keymaps/via/rules.mk b/keyboards/yandrstudio/hotdox76_V2/keymaps/via/rules.mk index 6db1bde5ebb2..a39f2e4990b2 100644 --- a/keyboards/yandrstudio/hotdox76_V2/keymaps/via/rules.mk +++ b/keyboards/yandrstudio/hotdox76_V2/keymaps/via/rules.mk @@ -1,5 +1,5 @@ VIA_ENABLE = yes -RGBLIGHT_ENABLE = yes -RGBLIGHT_DRIVER = WS2812 +# RGBLIGHT_ENABLE = yes +# RGBLIGHT_DRIVER = WS2812 # RGB_MATRIX_ENABLE = yes # RGB_MATRIX_DRIVER = WS2812 diff --git a/keyboards/yandrstudio/hotdox76_V2/oled_font_lib/ext_font.h b/keyboards/yandrstudio/hotdox76_V2/oled_font_lib/ext_font.h index c35965c4e117..23a88dc388fd 100644 --- a/keyboards/yandrstudio/hotdox76_V2/oled_font_lib/ext_font.h +++ b/keyboards/yandrstudio/hotdox76_V2/oled_font_lib/ext_font.h @@ -14,6 +14,9 @@ * along with this program. If not, see . */ #pragma once + +#include "progmem.h" + /* !(0) "(1) #(2) $(3) %(4) &(5) '(6) ((7) )(8) *(9) +(10) ,(11) -(12) .(13) /(14) 0(15) @@ -26,9 +29,10 @@ a(64) b(65) c(66) d(67) e(68) f(69) g(70) h(71) i(72) j(73) k(74) l(75) m(76) n(77) o(78) p(79) q(80) r(81) s(82) t(83) u(84) v(85) w(86) x(87) - y(88) z(89) {(90) |(91) }(92) ~(93) + y(88) z(89) {(90) |(91) }(92) ~(93) (94) */ -static const unsigned char ext_big_font[][24] = { + +static const unsigned char ext_big_font[95][24] PROGMEM = { {0x00,0x00,0x00,0x00,0xFC,0xFC,0xFC,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1B,0x1B,0x1B,0x1B,0x00,0x00,0x00,0x00},/*"!",0*/ {0x00,0x00,0x00,0x18,0xF8,0x18,0x00,0x18,0xF8,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*""",1*/ {0x00,0x00,0x60,0x60,0xFE,0xFE,0x60,0xFE,0xFE,0x60,0x00,0x00,0x00,0x00,0x06,0x7F,0x7F,0x06,0x7F,0x7F,0x06,0x06,0x00,0x00},/*"#",2*/ diff --git a/keyboards/yandrstudio/hotdox76_V2/oled_font_lib/logo.h b/keyboards/yandrstudio/hotdox76_V2/oled_font_lib/logo.h index 4ebc539f0c2c..2fba8cc94446 100644 --- a/keyboards/yandrstudio/hotdox76_V2/oled_font_lib/logo.h +++ b/keyboards/yandrstudio/hotdox76_V2/oled_font_lib/logo.h @@ -15,7 +15,9 @@ */ #pragma once -static const unsigned char logo_idobao[] = { +#include "progmem.h" + +static const unsigned char logo_idobao[] PROGMEM = { 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xE0, 0xE0, 0xF0, 0xF0, 0x70, 0x60, 0x04, 0x0E, 0x0E, 0x1E, 0x8E, 0x8E, 0xC4, 0xC0, 0xE0, 0xF0, 0xF0, 0xF0, diff --git a/keyboards/yandrstudio/hotdox76_V2/rules.mk b/keyboards/yandrstudio/hotdox76_V2/rules.mk index 3d34cf9e5e0c..9ecf3c7ac706 100644 --- a/keyboards/yandrstudio/hotdox76_V2/rules.mk +++ b/keyboards/yandrstudio/hotdox76_V2/rules.mk @@ -1,14 +1,10 @@ # MCU name MCU = atmega32u4 - +BOOTLOADER = atmel-dfu F_CPU = 16000000 - ARCH = AVR8 - F_USB = $(F_CPU) -# Bootloader selection -BOOTLOADER = caterina # Build Options # comment out to disable the options. @@ -19,8 +15,16 @@ EXTRAKEY_ENABLE = yes # Audio control and System control(+450) CONSOLE_ENABLE = no # Console for debug(+400) COMMAND_ENABLE = no # Commands for debug and configuration NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work -OLED_DRIVER_ENABLE = yes # Enable Support for SSD1306 or SH1106 OLED Displays; Communicating over I2C -SPLIT_KEYBOARD = yes +OLED_DRIVER_ENABLE = yes # Enable Support for SSD1306 or SH1106 OLED Displays; Communicating over I2C +LTO_ENABLE = yes +RGBLIGHT_ENABLE = yes +RGBLIGHT_DRIVER = WS2812 +# RGB_MATRIX_ENABLE = yes +# RGB_MATRIX_DRIVER = WS2812 +SPLIT_KEYBOARD = yes +SPLIT_TRANSPORT = custom +QUANTUM_LIB_SRC += serial.c \ + transport_lib/transport.c diff --git a/keyboards/yandrstudio/hotdox76_V2/transport_lib/transport.c b/keyboards/yandrstudio/hotdox76_V2/transport_lib/transport.c new file mode 100644 index 000000000000..c90fd394eace --- /dev/null +++ b/keyboards/yandrstudio/hotdox76_V2/transport_lib/transport.c @@ -0,0 +1,265 @@ +#include +#include + +#include "config.h" +#include "matrix.h" +#include "quantum.h" + +#include QMK_KEYBOARD_H + + +#define ROWS_PER_HAND (MATRIX_ROWS / 2) +#define SYNC_TIMER_OFFSET 2 + +#ifdef RGBLIGHT_ENABLE +# include "rgblight.h" +#endif + +#ifdef BACKLIGHT_ENABLE +# include "backlight.h" +#endif + +#ifdef ENCODER_ENABLE +# include "encoder.h" +static pin_t encoders_pad[] = ENCODERS_PAD_A; +# define NUMBER_OF_ENCODERS (sizeof(encoders_pad) / sizeof(pin_t)) +#endif + +#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) +# include "led_matrix.h" +#endif +#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) +# include "rgb_matrix.h" +#endif + +# include "serial.h" + +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]; + +# ifdef ENCODER_ENABLE + uint8_t encoder_state[NUMBER_OF_ENCODERS]; +# endif + +} Serial_s2m_buffer_t; + +typedef struct _Serial_m2s_buffer_t { +# ifdef SPLIT_MODS_ENABLE + uint8_t real_mods; + uint8_t weak_mods; +# ifndef NO_ACTION_ONESHOT + uint8_t oneshot_mods; +# endif +# endif +# ifndef DISABLE_SYNC_TIMER + uint32_t sync_timer; +# endif +# ifdef SPLIT_TRANSPORT_MIRROR + matrix_row_t mmatrix[ROWS_PER_HAND]; +# endif +# ifdef BACKLIGHT_ENABLE + uint8_t backlight_level; +# endif +# ifdef WPM_ENABLE + uint8_t current_wpm; +# endif +# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) + led_eeconfig_t led_matrix; + bool led_suspend_state; +# endif +# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) + rgb_config_t rgb_matrix; + bool rgb_suspend_state; +# endif + char current_alp[7]; + layer_state_t layer_state; + uint8_t cur_alp_index; +} Serial_m2s_buffer_t; + +# if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) +// 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 RGBLIGHT_SPLIT with info on the number +// of LEDs on each half. +// +// Otherwise, if the master side MCU drives both sides RGB LED chains, +// there is no need to communicate. + +typedef struct _Serial_rgblight_t { + rgblight_syncinfo_t rgblight_sync; +} Serial_rgblight_t; + +volatile Serial_rgblight_t serial_rgblight = {}; +uint8_t volatile status_rgblight = 0; +# endif + +volatile Serial_s2m_buffer_t serial_s2m_buffer = {}; +volatile Serial_m2s_buffer_t serial_m2s_buffer = {}; +uint8_t volatile status0 = 0; + +enum serial_transaction_id { + GET_SLAVE_MATRIX = 0, +# if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) + PUT_RGBLIGHT, +# endif +}; + +SSTD_t transactions[] = { + [GET_SLAVE_MATRIX] = + { + (uint8_t *)&status0, + sizeof(serial_m2s_buffer), + (uint8_t *)&serial_m2s_buffer, + sizeof(serial_s2m_buffer), + (uint8_t *)&serial_s2m_buffer, + }, +# if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) + [PUT_RGBLIGHT] = + { + (uint8_t *)&status_rgblight, sizeof(serial_rgblight), (uint8_t *)&serial_rgblight, 0, NULL // no slave to master transfer + }, +# endif +}; + +void transport_master_init(void) { soft_serial_initiator_init(transactions, TID_LIMIT(transactions)); } + +void transport_slave_init(void) { soft_serial_target_init(transactions, TID_LIMIT(transactions)); } + +# if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) + +// rgblight synchronization information communication. + +void transport_rgblight_master(void) { + if (rgblight_get_change_flags()) { + rgblight_get_syncinfo((rgblight_syncinfo_t *)&serial_rgblight.rgblight_sync); + if (soft_serial_transaction(PUT_RGBLIGHT) == TRANSACTION_END) { + rgblight_clear_change_flags(); + } + } +} + +void transport_rgblight_slave(void) { + if (status_rgblight == TRANSACTION_ACCEPTED) { + rgblight_update_sync((rgblight_syncinfo_t *)&serial_rgblight.rgblight_sync, false); + status_rgblight = TRANSACTION_END; + } +} + +# else +# define transport_rgblight_master() +# define transport_rgblight_slave() +# endif + +bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { +# ifndef SERIAL_USE_MULTI_TRANSACTION + if (soft_serial_transaction() != TRANSACTION_END) { + return false; + } +# else + transport_rgblight_master(); + if (soft_serial_transaction(GET_SLAVE_MATRIX) != TRANSACTION_END) { + return false; + } +# endif + + // TODO: if MATRIX_COLS > 8 change to unpack() + for (int i = 0; i < ROWS_PER_HAND; ++i) { + slave_matrix[i] = serial_s2m_buffer.smatrix[i]; +# ifdef SPLIT_TRANSPORT_MIRROR + serial_m2s_buffer.mmatrix[i] = master_matrix[i]; +# endif + } + +# ifdef BACKLIGHT_ENABLE + // Write backlight level for slave to read + serial_m2s_buffer.backlight_level = is_backlight_enabled() ? get_backlight_level() : 0; +# endif + +# ifdef ENCODER_ENABLE + encoder_update_raw((uint8_t *)serial_s2m_buffer.encoder_state); +# endif + +# ifdef WPM_ENABLE + // Write wpm to slave + serial_m2s_buffer.current_wpm = get_current_wpm(); +# endif + +# ifdef SPLIT_MODS_ENABLE + serial_m2s_buffer.real_mods = get_mods(); + serial_m2s_buffer.weak_mods = get_weak_mods(); +# ifndef NO_ACTION_ONESHOT + serial_m2s_buffer.oneshot_mods = get_oneshot_mods(); +# endif +# endif + +# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) + serial_m2s_buffer.led_matrix = led_matrix_eeconfig; + serial_m2s_buffer.led_suspend_state = led_matrix_get_suspend_state(); +# endif +# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) + serial_m2s_buffer.rgb_matrix = rgb_matrix_config; + serial_m2s_buffer.rgb_suspend_state = rgb_matrix_get_suspend_state(); +# endif + + for (uint8_t i = 0; i < 7; ++i) { + serial_m2s_buffer.current_alp[i] = current_alp[i]; + } + serial_m2s_buffer.layer_state = layer_state; + serial_m2s_buffer.cur_alp_index = cur_alp_index; + +# ifndef DISABLE_SYNC_TIMER + serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; +# endif + return true; +} + +void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { + transport_rgblight_slave(); +# ifndef DISABLE_SYNC_TIMER + sync_timer_update(serial_m2s_buffer.sync_timer); +# endif + + // TODO: if MATRIX_COLS > 8 change to pack() + for (int i = 0; i < ROWS_PER_HAND; ++i) { + serial_s2m_buffer.smatrix[i] = slave_matrix[i]; +# ifdef SPLIT_TRANSPORT_MIRROR + master_matrix[i] = serial_m2s_buffer.mmatrix[i]; +# endif + } +# ifdef BACKLIGHT_ENABLE + backlight_set(serial_m2s_buffer.backlight_level); +# endif + +# ifdef ENCODER_ENABLE + encoder_state_raw((uint8_t *)serial_s2m_buffer.encoder_state); +# endif + +# ifdef WPM_ENABLE + set_current_wpm(serial_m2s_buffer.current_wpm); +# endif + +# ifdef SPLIT_MODS_ENABLE + set_mods(serial_m2s_buffer.real_mods); + set_weak_mods(serial_m2s_buffer.weak_mods); +# ifndef NO_ACTION_ONESHOT + set_oneshot_mods(serial_m2s_buffer.oneshot_mods); +# endif +# endif + +# if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) + led_matrix_eeconfig = serial_m2s_buffer.led_matrix; + led_matrix_set_suspend_state(serial_m2s_buffer.led_suspend_state); +# endif +# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) + rgb_matrix_config = serial_m2s_buffer.rgb_matrix; + rgb_matrix_set_suspend_state(serial_m2s_buffer.rgb_suspend_state); +# endif + + for (uint8_t i = 0; i < 7; ++i) { + current_alp[i] = serial_m2s_buffer.current_alp[i]; + } + layer_state = serial_m2s_buffer.layer_state; + cur_alp_index = serial_m2s_buffer.cur_alp_index; +} + diff --git a/keyboards/yandrstudio/zhou75/readme.md b/keyboards/yandrstudio/zhou75/readme.md index f1c593ab06f9..ad5964b995ac 100644 --- a/keyboards/yandrstudio/zhou75/readme.md +++ b/keyboards/yandrstudio/zhou75/readme.md @@ -13,3 +13,4 @@ Make example for this keyboard (after setting up your build environment): make yandrstudio/zhou75/f401:via See [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) then the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. +