diff --git a/keyboards/yandrstudio/nlhhkb/info-via.json b/keyboards/yandrstudio/nlhhkb/info-via.json index 565eba1fff18..e911375d9ead 100644 --- a/keyboards/yandrstudio/nlhhkb/info-via.json +++ b/keyboards/yandrstudio/nlhhkb/info-via.json @@ -1,7 +1,7 @@ { - "name": "HHKB (Biu)", - "vendorId": "0xFEED", - "productId": "0x6066", + "name": "HHKB_Y&R", + "vendorId": "0xAA96", + "productId": "0xAAA0", "lighting": { "extends": "none", "keycodes": "qmk" diff --git a/keyboards/yandrstudio/r65ble/config.h b/keyboards/yandrstudio/r65ble/config.h index e9d082d8129f..7e7a92399fdf 100644 --- a/keyboards/yandrstudio/r65ble/config.h +++ b/keyboards/yandrstudio/r65ble/config.h @@ -30,8 +30,8 @@ #define MATRIX_ROWS 5 #define MATRIX_COLS 15 -#define MATRIX_ROW_PINS { B5, B4, A3, A2, B9 } -#define MATRIX_COL_PINS { A10, A9, A8, B14, B13, B12, B11, B10, B1, B0, A7, A6, A5, A4, B8 } +#define MATRIX_ROW_PINS { B5, C13, A3, A2, B9 } +#define MATRIX_COL_PINS { C14, B4, A8, B14, B13, B12, B11, B10, B1, B0, A7, A6, A5, A4, B8 } #define DIODE_DIRECTION COL2ROW @@ -99,6 +99,6 @@ #define TAP_HOLD_CAPS_DELAY 20 #define TAP_CODE_DELAY 10 #ifdef CONSOLE_ENABLE -# define DEBUG_MATRIX_SCAN_RATE +// # define DEBUG_MATRIX_SCAN_RATE #endif diff --git a/keyboards/yandrstudio/r65ble/keymaps/test_uart/keymap.c b/keyboards/yandrstudio/r65ble/keymaps/test_uart/keymap.c index 24720bc841a5..1e7f5b122a72 100644 --- a/keyboards/yandrstudio/r65ble/keymaps/test_uart/keymap.c +++ b/keyboards/yandrstudio/r65ble/keymaps/test_uart/keymap.c @@ -15,7 +15,8 @@ */ #include QMK_KEYBOARD_H -#include +// #include +#include "print.h" #include "dynamic_keymap.h" #include "uart.h" @@ -123,7 +124,7 @@ void oled_task_user(void) { void keyboard_post_init_user(void) { - uart_init(115200); + // uart_init(115200); debug_enable=true; // debug_matrix=true; debug_keyboard=true; @@ -131,22 +132,24 @@ void keyboard_post_init_user(void) { -// bool process_record_user(uint16_t keycode, keyrecord_t *record) { -// uart_putchar(0xff); -// uart_putchar(keycode >> 8); -// uart_putchar(keycode & 0xff); -// uart_putchar(0xfe); -// uprintf("KL: kc: 0x%04X, col: %u, row: %u, pressed: %b, time: %u, interrupt: %b, count: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed, record->event.time, record->tap.interrupted, record->tap.count); -// return false; -// // switch (keycode) { -// // case KC_N: -// // if (record->event.pressed) { -// // uart_putchar('#'); -// // } else { -// // // Do something else when release -// // } -// // return false; // Skip all further processing of this key -// // default: -// // return true; // Process all other keycodes normally -// // } -// } +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + if (record->event.pressed) { + uart_putchar(0xff); + uart_putchar(keycode >> 8); + uart_putchar(keycode & 0xff); + uart_putchar(0xfe); + uprintf("KL: kc: 0x%04X, col: %u, row: %u, pressed: %b, time: %u, interrupt: %b, count: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed, record->event.time, record->tap.interrupted, record->tap.count); + } + return true; + // switch (keycode) { + // case KC_N: + // if (record->event.pressed) { + // uart_putchar('#'); + // } else { + // // Do something else when release + // } + // return false; // Skip all further processing of this key + // default: + // return true; // Process all other keycodes normally + // } +} diff --git a/keyboards/yandrstudio/r65ble/keymaps/test_uart/readme.md b/keyboards/yandrstudio/r65ble/keymaps/test_uart/readme.md index 274199716397..e163fe332ef3 100644 --- a/keyboards/yandrstudio/r65ble/keymaps/test_uart/readme.md +++ b/keyboards/yandrstudio/r65ble/keymaps/test_uart/readme.md @@ -1,23 +1,43 @@ # BLE_UART SUPPORT FOR ARM -## send source support -## uart support -1. add biu_ble5 support in your $(keymap)/rules.mk +## method 1 + + +### send source support +1. move host_driver declarations from "qmk_firmware/tmk_core/protocol/chibios/main.c" to "qmk_firmware/tmk_core/protocol/chibios/usb_main.h" +```c++ +#include "host_driver.h" +/* declarations */ +uint8_t keyboard_leds(void); +void send_keyboard(report_keyboard_t *report); +void send_mouse(report_mouse_t *report); +void send_system(uint16_t data); +void send_consumer(uint16_t data); +``` +### set no usb check + +```shell +NO_USB_STARTUP_CHECK = yes +``` + +### uart support + +1. add biu_ble5 support in your $(keymap)/relus.mk ```shell BIU_BLE5_ENABLE = yes ``` -2. add uart.c to src (in file qmk_firmware/tmk_core/protocol/chibios.mk) +2. add uart.c to src (in file "qmk_firmware/tmk_core/protocol/chibios.mk") ```shell # into end of the chibios.mk ifeq ($(strip $(BIU_BLE5_ENABLE)), yes) SRC += uart.c - VPATH += $(DRIVER_PATH)/chibios + # VPATH += $(DRIVER_PATH)/chibios #optional. For stability, it is recommended to add this line. OPT_DEFS += -DBIU_BLE5_ENABLE endif ``` -3. add uart support in the main function (in file qmk_firmware/tmk_core/protocol/chibios/main.c) +3. add uart support in the main function (in file "qmk_firmware/tmk_core/protocol/chibios/main.c") ```c++ // head of the main.c file #ifdef BIU_BLE5_ENABLE @@ -29,3 +49,12 @@ endif uart_init(9600); #endif ``` + +4. copy outputselect.h and outputselect.c into "qmk_firmware/tmk_core/protocol/chibios/" + + +## method 2 + + +## some important file +1. chibios usb state: "qmk_firmware/lib/chibios/os/hal/include/hal_usb.h" diff --git a/keyboards/yandrstudio/r65ble/keymaps/test_uart/rules.mk b/keyboards/yandrstudio/r65ble/keymaps/test_uart/rules.mk index e8f459441cc6..b589c30bf3ef 100644 --- a/keyboards/yandrstudio/r65ble/keymaps/test_uart/rules.mk +++ b/keyboards/yandrstudio/r65ble/keymaps/test_uart/rules.mk @@ -2,8 +2,8 @@ VIA_ENABLE = yes OPT_ENABLE = yes WPM_ENABLE = yes OLED_DRIVER_ENABLE = yes -CONSOLE_ENABLE = no +CONSOLE_ENABLE = yes # QUANTUM_LIB_SRC += uart.c BIU_BLE5_ENABLE = yes - +NO_USB_STARTUP_CHECK = yes diff --git a/keyboards/yandrstudio/r65ble/readme.md b/keyboards/yandrstudio/r65ble/readme.md index 67670e695e70..abb7ea004f23 100644 --- a/keyboards/yandrstudio/r65ble/readme.md +++ b/keyboards/yandrstudio/r65ble/readme.md @@ -1,4 +1,4 @@ -r65ble +rainbow65 === A 65% keyboard with rgb oled and encoder with nrf52840 ble chip supported by using the uart driver. diff --git a/keyboards/yandrstudio/r65ble/rules.mk b/keyboards/yandrstudio/r65ble/rules.mk index abe357e9b56a..d2052b93ca03 100644 --- a/keyboards/yandrstudio/r65ble/rules.mk +++ b/keyboards/yandrstudio/r65ble/rules.mk @@ -9,7 +9,7 @@ MOUSEKEY_ENABLE = yes # Mouse keys EXTRAKEY_ENABLE = yes # Audio control and System control COMMAND_ENABLE = yes # Commands for debug and configuration # if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work -NKRO_ENABLE = yes # USB Nkey Rollover +# NKRO_ENABLE = yes # USB Nkey Rollover #RGBLIGHT_ENABLE = yes RGB_MATRIX_ENABLE = yes RGB_MATRIX_DRIVER = WS2812 diff --git a/keyboards/yandrstudio/rainbow65/rules.mk b/keyboards/yandrstudio/rainbow65/rules.mk index 724a6f36200b..e119b8a3189e 100755 --- a/keyboards/yandrstudio/rainbow65/rules.mk +++ b/keyboards/yandrstudio/rainbow65/rules.mk @@ -9,7 +9,7 @@ EXTRAKEY_ENABLE = yes # Audio control and System control COMMAND_ENABLE = yes # Commands for debug and configuration # if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work NKRO_ENABLE = yes # USB Nkey Rollover -#RGBLIGHT_ENABLE = yes +# RGBLIGHT_ENABLE = yes RGB_MATRIX_ENABLE = yes RGB_MATRIX_DRIVER = WS2812 WS2812_DRIVER = spi diff --git a/keyboards/yandrstudio/sb65p/info-via.json b/keyboards/yandrstudio/sb65p/info-via.json index 976edca46a39..a9d7ba19861c 100644 --- a/keyboards/yandrstudio/sb65p/info-via.json +++ b/keyboards/yandrstudio/sb65p/info-via.json @@ -1,7 +1,7 @@ { - "name": "SP65", - "vendorId": "0xFEED", - "productId": "0x6060", + "name": "SP65_Y&R", + "vendorId": "0xAA96", + "productId": "0xAA02", "lighting": "none", "matrix": { "rows": 10, "cols": 9 }, "layouts": { diff --git a/keyboards/yandrstudio/tdcq64_2s/config.h b/keyboards/yandrstudio/tdcq64_2s/config.h index 5afc603a512f..72924dff784a 100644 --- a/keyboards/yandrstudio/tdcq64_2s/config.h +++ b/keyboards/yandrstudio/tdcq64_2s/config.h @@ -19,7 +19,7 @@ /* USB Device descriptor parameter */ #define VENDOR_ID 0xAA96 -#define PRODUCT_ID 0xAA04 +#define PRODUCT_ID 0xAAA2 #define DEVICE_VER 0x0001 #define MANUFACTURER JasonRen biu #define PRODUCT tdcq64_2s diff --git a/keyboards/yandrstudio/tdcq64_2s/f401/matrix.c b/keyboards/yandrstudio/tdcq64_2s/f401/matrix.c new file mode 100644 index 000000000000..d7040e338fbe --- /dev/null +++ b/keyboards/yandrstudio/tdcq64_2s/f401/matrix.c @@ -0,0 +1,236 @@ +/* Copyright 2021 JasonRen(biu) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include "util.h" +#include "matrix.h" +#include "debounce.h" +#include "quantum.h" + +#ifdef DIRECT_PINS +static pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; +#elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) +static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; +static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; +#endif + +/* matrix state(1:on, 0:off) */ +extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values +extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values + +static inline void setPinOutput_writeLow(pin_t pin) { + ATOMIC_BLOCK_FORCEON { + setPinOutput(pin); + writePinLow(pin); + } +} + +static inline void setPinInputHigh_atomic(pin_t pin) { + ATOMIC_BLOCK_FORCEON { setPinInputHigh(pin); } +} + +// matrix code + +#ifdef DIRECT_PINS + +static void init_pins(void) { + for (int row = 0; row < MATRIX_ROWS; row++) { + for (int col = 0; col < MATRIX_COLS; col++) { + pin_t pin = direct_pins[row][col]; + if (pin != NO_PIN) { + setPinInputHigh(pin); + } + } + } +} + +static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { + // Start with a clear matrix row + matrix_row_t current_row_value = 0; + + for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { + pin_t pin = direct_pins[current_row][col_index]; + if (pin != NO_PIN) { + current_row_value |= readPin(pin) ? 0 : (MATRIX_ROW_SHIFTER << col_index); + } + } + + // If the row has changed, store the row and return the changed flag. + if (current_matrix[current_row] != current_row_value) { + current_matrix[current_row] = current_row_value; + return true; + } + return false; +} + +#elif defined(DIODE_DIRECTION) +# if (DIODE_DIRECTION == COL2ROW) + +static void select_col(uint8_t col) { palSetLine(col_pins[col]); } + +static void unselect_col(uint8_t col) { palClearLine(col_pins[col]); } + +static void unselect_rows(void) { + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + palSetLineMode(row_pins[x], PAL_MODE_INPUT_PULLDOWN); + } +} + +static void init_pins(void) { + unselect_rows(); + for (uint8_t x = 0; x < MATRIX_COLS; x++) { + palSetLineMode(col_pins[x], PAL_MODE_OUTPUT_PUSHPULL); + } + for (uint8_t x = 0; x < MATRIX_COLS; x++) { + palClearLine(col_pins[x]); + } +} + +static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { + bool matrix_changed = false; + + // Select col + select_col(current_col); + matrix_output_select_delay(); + + // For each row... + for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { + // Store last value of row prior to reading + matrix_row_t last_row_value = current_matrix[row_index]; + matrix_row_t current_row_value = last_row_value; + + // Check row pin state + if (readPin(row_pins[row_index]) == 1) { + // Pin HI, set col bit + current_row_value |= (MATRIX_ROW_SHIFTER << current_col); + } else { + // Pin LO, clear col bit + current_row_value &= ~(MATRIX_ROW_SHIFTER << current_col); + } + + // Determine if the matrix changed state + if ((last_row_value != current_row_value)) { + matrix_changed |= true; + current_matrix[row_index] = current_row_value; + } + } + + // Unselect col + unselect_col(current_col); + if (current_col + 1 < MATRIX_COLS) { + matrix_output_unselect_delay(); // wait for col signal to go HIGH + } + + return matrix_changed; +} + +# elif (DIODE_DIRECTION == ROW2COL) + +static void select_row(uint8_t row) { palSetLine(row_pins[row]); } + +static void unselect_row(uint8_t row) { palClearLine(row_pins[row]); } + +static void unselect_cols(void) { + for (uint8_t x = 0; x < MATRIX_COLS; x++) { + palSetLineMode(col_pins[x], PAL_MODE_INPUT_PULLDOWN); + } +} + +static void init_pins(void) { + unselect_cols(); + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + palSetLineMode(row_pins[x], PAL_MODE_OUTPUT_PUSHPULL); + } + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + palClearLine(row_pins[x]); + } +} + + +static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { + // Start with a clear matrix row + matrix_row_t current_row_value = 0; + + // Select row + select_row(current_row); + matrix_output_select_delay(); + + // For each col... + for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { + // Select the col pin to read (active low) + uint8_t pin_state = readPin(col_pins[col_index]); + + // Populate the matrix row with the state of the col pin + current_row_value |= pin_state ? (MATRIX_ROW_SHIFTER << col_index) : 0; + } + + // Unselect row + unselect_row(current_row); + if (current_row + 1 < MATRIX_ROWS) { + matrix_output_unselect_delay(); // wait for row signal to go HIGH + } + + // If the row has changed, store the row and return the changed flag. + if (current_matrix[current_row] != current_row_value) { + current_matrix[current_row] = current_row_value; + return true; + } + return false; +} + +# else +# error DIODE_DIRECTION must be one of COL2ROW or ROW2COL! +# endif +#else +# error DIODE_DIRECTION is not defined! +#endif + +void matrix_init(void) { + // initialize key pins + init_pins(); + + // initialize matrix state: all keys off + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + raw_matrix[i] = 0; + matrix[i] = 0; + } + + debounce_init(MATRIX_ROWS); + + matrix_init_quantum(); +} + +uint8_t matrix_scan(void) { + bool changed = false; + +#if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW) + // Set col, read rows + for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { + changed |= read_rows_on_col(raw_matrix, current_col); + } +#elif (DIODE_DIRECTION == ROW2COL) + // Set row, read cols + for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { + changed |= read_cols_on_row(raw_matrix, current_row); + } +#endif + + debounce(raw_matrix, matrix, MATRIX_ROWS, changed); + + matrix_scan_quantum(); + return (uint8_t)changed; +} diff --git a/keyboards/yandrstudio/tdcq64_2s/f401/rules.mk b/keyboards/yandrstudio/tdcq64_2s/f401/rules.mk index 1685761b4c7c..1f81ff6f41f1 100644 --- a/keyboards/yandrstudio/tdcq64_2s/f401/rules.mk +++ b/keyboards/yandrstudio/tdcq64_2s/f401/rules.mk @@ -4,6 +4,8 @@ MCU = STM32F401 # Address of the bootloader in system memory STM32_BOOTLOADER_ADDRESS = 0x1FFF0000 -# Disable unsupported hardware -# AUDIO_SUPPORTED = no -# BACKLIGHT_SUPPORTED = no + +CUSTOM_MATRIX = lite # for using the A9 pin as matrix io + +# # project specific file +QUANTUM_SRC += matrix.c diff --git a/keyboards/yandrstudio/tdcq64_2s/info-via.json b/keyboards/yandrstudio/tdcq64_2s/info-via.json index a7e223590bc7..d5affa937767 100644 --- a/keyboards/yandrstudio/tdcq64_2s/info-via.json +++ b/keyboards/yandrstudio/tdcq64_2s/info-via.json @@ -1,7 +1,7 @@ { - "name": "TDCQ64", - "vendorId": "0xFEED", - "productId": "0x6060", + "name": "TDCQ64_Y&R", + "vendorId": "0xAA96", + "productId": "0xAAA2", "lighting": { "extends": "none", "keycodes": "qmk" diff --git a/keyboards/yandrstudio/tdcq68/config.h b/keyboards/yandrstudio/tdcq68/config.h index fbb4c1649c76..0fa22e59b010 100644 --- a/keyboards/yandrstudio/tdcq68/config.h +++ b/keyboards/yandrstudio/tdcq68/config.h @@ -19,7 +19,7 @@ /* USB Device descriptor parameter */ #define VENDOR_ID 0xAA96 -#define PRODUCT_ID 0xAA03 +#define PRODUCT_ID 0xAAA1 #define DEVICE_VER 0x0001 #define MANUFACTURER JasonRen biu #define PRODUCT tdcq68 diff --git a/keyboards/yandrstudio/tdcq68/f401/matrix.c b/keyboards/yandrstudio/tdcq68/f401/matrix.c new file mode 100644 index 000000000000..d7040e338fbe --- /dev/null +++ b/keyboards/yandrstudio/tdcq68/f401/matrix.c @@ -0,0 +1,236 @@ +/* Copyright 2021 JasonRen(biu) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include "util.h" +#include "matrix.h" +#include "debounce.h" +#include "quantum.h" + +#ifdef DIRECT_PINS +static pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; +#elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) +static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; +static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; +#endif + +/* matrix state(1:on, 0:off) */ +extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values +extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values + +static inline void setPinOutput_writeLow(pin_t pin) { + ATOMIC_BLOCK_FORCEON { + setPinOutput(pin); + writePinLow(pin); + } +} + +static inline void setPinInputHigh_atomic(pin_t pin) { + ATOMIC_BLOCK_FORCEON { setPinInputHigh(pin); } +} + +// matrix code + +#ifdef DIRECT_PINS + +static void init_pins(void) { + for (int row = 0; row < MATRIX_ROWS; row++) { + for (int col = 0; col < MATRIX_COLS; col++) { + pin_t pin = direct_pins[row][col]; + if (pin != NO_PIN) { + setPinInputHigh(pin); + } + } + } +} + +static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { + // Start with a clear matrix row + matrix_row_t current_row_value = 0; + + for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { + pin_t pin = direct_pins[current_row][col_index]; + if (pin != NO_PIN) { + current_row_value |= readPin(pin) ? 0 : (MATRIX_ROW_SHIFTER << col_index); + } + } + + // If the row has changed, store the row and return the changed flag. + if (current_matrix[current_row] != current_row_value) { + current_matrix[current_row] = current_row_value; + return true; + } + return false; +} + +#elif defined(DIODE_DIRECTION) +# if (DIODE_DIRECTION == COL2ROW) + +static void select_col(uint8_t col) { palSetLine(col_pins[col]); } + +static void unselect_col(uint8_t col) { palClearLine(col_pins[col]); } + +static void unselect_rows(void) { + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + palSetLineMode(row_pins[x], PAL_MODE_INPUT_PULLDOWN); + } +} + +static void init_pins(void) { + unselect_rows(); + for (uint8_t x = 0; x < MATRIX_COLS; x++) { + palSetLineMode(col_pins[x], PAL_MODE_OUTPUT_PUSHPULL); + } + for (uint8_t x = 0; x < MATRIX_COLS; x++) { + palClearLine(col_pins[x]); + } +} + +static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { + bool matrix_changed = false; + + // Select col + select_col(current_col); + matrix_output_select_delay(); + + // For each row... + for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { + // Store last value of row prior to reading + matrix_row_t last_row_value = current_matrix[row_index]; + matrix_row_t current_row_value = last_row_value; + + // Check row pin state + if (readPin(row_pins[row_index]) == 1) { + // Pin HI, set col bit + current_row_value |= (MATRIX_ROW_SHIFTER << current_col); + } else { + // Pin LO, clear col bit + current_row_value &= ~(MATRIX_ROW_SHIFTER << current_col); + } + + // Determine if the matrix changed state + if ((last_row_value != current_row_value)) { + matrix_changed |= true; + current_matrix[row_index] = current_row_value; + } + } + + // Unselect col + unselect_col(current_col); + if (current_col + 1 < MATRIX_COLS) { + matrix_output_unselect_delay(); // wait for col signal to go HIGH + } + + return matrix_changed; +} + +# elif (DIODE_DIRECTION == ROW2COL) + +static void select_row(uint8_t row) { palSetLine(row_pins[row]); } + +static void unselect_row(uint8_t row) { palClearLine(row_pins[row]); } + +static void unselect_cols(void) { + for (uint8_t x = 0; x < MATRIX_COLS; x++) { + palSetLineMode(col_pins[x], PAL_MODE_INPUT_PULLDOWN); + } +} + +static void init_pins(void) { + unselect_cols(); + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + palSetLineMode(row_pins[x], PAL_MODE_OUTPUT_PUSHPULL); + } + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + palClearLine(row_pins[x]); + } +} + + +static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { + // Start with a clear matrix row + matrix_row_t current_row_value = 0; + + // Select row + select_row(current_row); + matrix_output_select_delay(); + + // For each col... + for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { + // Select the col pin to read (active low) + uint8_t pin_state = readPin(col_pins[col_index]); + + // Populate the matrix row with the state of the col pin + current_row_value |= pin_state ? (MATRIX_ROW_SHIFTER << col_index) : 0; + } + + // Unselect row + unselect_row(current_row); + if (current_row + 1 < MATRIX_ROWS) { + matrix_output_unselect_delay(); // wait for row signal to go HIGH + } + + // If the row has changed, store the row and return the changed flag. + if (current_matrix[current_row] != current_row_value) { + current_matrix[current_row] = current_row_value; + return true; + } + return false; +} + +# else +# error DIODE_DIRECTION must be one of COL2ROW or ROW2COL! +# endif +#else +# error DIODE_DIRECTION is not defined! +#endif + +void matrix_init(void) { + // initialize key pins + init_pins(); + + // initialize matrix state: all keys off + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + raw_matrix[i] = 0; + matrix[i] = 0; + } + + debounce_init(MATRIX_ROWS); + + matrix_init_quantum(); +} + +uint8_t matrix_scan(void) { + bool changed = false; + +#if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW) + // Set col, read rows + for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { + changed |= read_rows_on_col(raw_matrix, current_col); + } +#elif (DIODE_DIRECTION == ROW2COL) + // Set row, read cols + for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { + changed |= read_cols_on_row(raw_matrix, current_row); + } +#endif + + debounce(raw_matrix, matrix, MATRIX_ROWS, changed); + + matrix_scan_quantum(); + return (uint8_t)changed; +} diff --git a/keyboards/yandrstudio/tdcq68/f401/rules.mk b/keyboards/yandrstudio/tdcq68/f401/rules.mk index 1685761b4c7c..1f81ff6f41f1 100644 --- a/keyboards/yandrstudio/tdcq68/f401/rules.mk +++ b/keyboards/yandrstudio/tdcq68/f401/rules.mk @@ -4,6 +4,8 @@ MCU = STM32F401 # Address of the bootloader in system memory STM32_BOOTLOADER_ADDRESS = 0x1FFF0000 -# Disable unsupported hardware -# AUDIO_SUPPORTED = no -# BACKLIGHT_SUPPORTED = no + +CUSTOM_MATRIX = lite # for using the A9 pin as matrix io + +# # project specific file +QUANTUM_SRC += matrix.c diff --git a/keyboards/yandrstudio/tdcq68/info-via.json b/keyboards/yandrstudio/tdcq68/info-via.json index 437c7cbe0948..4de88e849786 100644 --- a/keyboards/yandrstudio/tdcq68/info-via.json +++ b/keyboards/yandrstudio/tdcq68/info-via.json @@ -1,7 +1,7 @@ { - "name": "TDCQ68", - "vendorId": "0xFEED", - "productId": "0x6060", + "name": "TDCQ68_Y&R", + "vendorId": "0xAA96", + "productId": "0xAAA1", "lighting": { "extends": "none", "keycodes": "qmk" diff --git a/keyboards/yandrstudio/whiteMouse28T/config.h b/keyboards/yandrstudio/whiteMouse28T/config.h index d185a67bea13..3db8cd2482f6 100644 --- a/keyboards/yandrstudio/whiteMouse28T/config.h +++ b/keyboards/yandrstudio/whiteMouse28T/config.h @@ -19,7 +19,7 @@ /* USB Device descriptor parameter */ #define VENDOR_ID 0xAA96 -#define PRODUCT_ID 0xAA05 +#define PRODUCT_ID 0xAA04 #define DEVICE_VER 0x0001 #define MANUFACTURER JasonRen biu #define PRODUCT whiteMouse28T @@ -28,7 +28,7 @@ #define MATRIX_ROWS 4 #define MATRIX_COLS 7 -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 +// 0 1 2 3 4 5 6 #define MATRIX_COL_PINS { B14, B15, A8, A9, A10, B4, B3} #define MATRIX_ROW_PINS { B13, B12, B7, B6} diff --git a/keyboards/yandrstudio/whiteMouse28T/f401/board.h b/keyboards/yandrstudio/whiteMouse28T/f401/board.h index 1b34ad76c1b9..d6432824e162 100644 --- a/keyboards/yandrstudio/whiteMouse28T/f401/board.h +++ b/keyboards/yandrstudio/whiteMouse28T/f401/board.h @@ -17,8 +17,9 @@ #include_next "board.h" -#undef STM32_HSE_BYPASS -#ifdef STM32_HSECLK + #undef STM32_HSECLK -#endif // STM32_HSECLK #define STM32_HSECLK 8000000 + + +#define BOARD_YANDR_BIU_F401 diff --git a/keyboards/yandrstudio/whiteMouse28T/f401/halconf.h b/keyboards/yandrstudio/whiteMouse28T/f401/halconf.h index cb59ce0673b3..3c35122cf29d 100644 --- a/keyboards/yandrstudio/whiteMouse28T/f401/halconf.h +++ b/keyboards/yandrstudio/whiteMouse28T/f401/halconf.h @@ -14,18 +14,16 @@ * along with this program. If not, see . */ -/* - * This file was auto-generated by: - * `qmk chibios-confmigrate -i keyboards/zvecr/zv48/f401/halconf.h -r platforms/chibios/common/configs/halconf.h` - */ #pragma once - +#include_next // #undef HAL_USE_PWM // #define HAL_USE_PWM TRUE // #define HAL_USE_SERIAL TRUE + + #undef SERIAL_USB_BUFFERS_SIZE #define SERIAL_USB_BUFFERS_SIZE 256 @@ -33,4 +31,4 @@ #define HAL_USE_SPI TRUE -#include_next + diff --git a/keyboards/yandrstudio/whiteMouse28T/f401/matrix.c b/keyboards/yandrstudio/whiteMouse28T/f401/matrix.c new file mode 100644 index 000000000000..d7040e338fbe --- /dev/null +++ b/keyboards/yandrstudio/whiteMouse28T/f401/matrix.c @@ -0,0 +1,236 @@ +/* Copyright 2021 JasonRen(biu) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include "util.h" +#include "matrix.h" +#include "debounce.h" +#include "quantum.h" + +#ifdef DIRECT_PINS +static pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; +#elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) +static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; +static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; +#endif + +/* matrix state(1:on, 0:off) */ +extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values +extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values + +static inline void setPinOutput_writeLow(pin_t pin) { + ATOMIC_BLOCK_FORCEON { + setPinOutput(pin); + writePinLow(pin); + } +} + +static inline void setPinInputHigh_atomic(pin_t pin) { + ATOMIC_BLOCK_FORCEON { setPinInputHigh(pin); } +} + +// matrix code + +#ifdef DIRECT_PINS + +static void init_pins(void) { + for (int row = 0; row < MATRIX_ROWS; row++) { + for (int col = 0; col < MATRIX_COLS; col++) { + pin_t pin = direct_pins[row][col]; + if (pin != NO_PIN) { + setPinInputHigh(pin); + } + } + } +} + +static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { + // Start with a clear matrix row + matrix_row_t current_row_value = 0; + + for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { + pin_t pin = direct_pins[current_row][col_index]; + if (pin != NO_PIN) { + current_row_value |= readPin(pin) ? 0 : (MATRIX_ROW_SHIFTER << col_index); + } + } + + // If the row has changed, store the row and return the changed flag. + if (current_matrix[current_row] != current_row_value) { + current_matrix[current_row] = current_row_value; + return true; + } + return false; +} + +#elif defined(DIODE_DIRECTION) +# if (DIODE_DIRECTION == COL2ROW) + +static void select_col(uint8_t col) { palSetLine(col_pins[col]); } + +static void unselect_col(uint8_t col) { palClearLine(col_pins[col]); } + +static void unselect_rows(void) { + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + palSetLineMode(row_pins[x], PAL_MODE_INPUT_PULLDOWN); + } +} + +static void init_pins(void) { + unselect_rows(); + for (uint8_t x = 0; x < MATRIX_COLS; x++) { + palSetLineMode(col_pins[x], PAL_MODE_OUTPUT_PUSHPULL); + } + for (uint8_t x = 0; x < MATRIX_COLS; x++) { + palClearLine(col_pins[x]); + } +} + +static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { + bool matrix_changed = false; + + // Select col + select_col(current_col); + matrix_output_select_delay(); + + // For each row... + for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { + // Store last value of row prior to reading + matrix_row_t last_row_value = current_matrix[row_index]; + matrix_row_t current_row_value = last_row_value; + + // Check row pin state + if (readPin(row_pins[row_index]) == 1) { + // Pin HI, set col bit + current_row_value |= (MATRIX_ROW_SHIFTER << current_col); + } else { + // Pin LO, clear col bit + current_row_value &= ~(MATRIX_ROW_SHIFTER << current_col); + } + + // Determine if the matrix changed state + if ((last_row_value != current_row_value)) { + matrix_changed |= true; + current_matrix[row_index] = current_row_value; + } + } + + // Unselect col + unselect_col(current_col); + if (current_col + 1 < MATRIX_COLS) { + matrix_output_unselect_delay(); // wait for col signal to go HIGH + } + + return matrix_changed; +} + +# elif (DIODE_DIRECTION == ROW2COL) + +static void select_row(uint8_t row) { palSetLine(row_pins[row]); } + +static void unselect_row(uint8_t row) { palClearLine(row_pins[row]); } + +static void unselect_cols(void) { + for (uint8_t x = 0; x < MATRIX_COLS; x++) { + palSetLineMode(col_pins[x], PAL_MODE_INPUT_PULLDOWN); + } +} + +static void init_pins(void) { + unselect_cols(); + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + palSetLineMode(row_pins[x], PAL_MODE_OUTPUT_PUSHPULL); + } + for (uint8_t x = 0; x < MATRIX_ROWS; x++) { + palClearLine(row_pins[x]); + } +} + + +static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { + // Start with a clear matrix row + matrix_row_t current_row_value = 0; + + // Select row + select_row(current_row); + matrix_output_select_delay(); + + // For each col... + for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { + // Select the col pin to read (active low) + uint8_t pin_state = readPin(col_pins[col_index]); + + // Populate the matrix row with the state of the col pin + current_row_value |= pin_state ? (MATRIX_ROW_SHIFTER << col_index) : 0; + } + + // Unselect row + unselect_row(current_row); + if (current_row + 1 < MATRIX_ROWS) { + matrix_output_unselect_delay(); // wait for row signal to go HIGH + } + + // If the row has changed, store the row and return the changed flag. + if (current_matrix[current_row] != current_row_value) { + current_matrix[current_row] = current_row_value; + return true; + } + return false; +} + +# else +# error DIODE_DIRECTION must be one of COL2ROW or ROW2COL! +# endif +#else +# error DIODE_DIRECTION is not defined! +#endif + +void matrix_init(void) { + // initialize key pins + init_pins(); + + // initialize matrix state: all keys off + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + raw_matrix[i] = 0; + matrix[i] = 0; + } + + debounce_init(MATRIX_ROWS); + + matrix_init_quantum(); +} + +uint8_t matrix_scan(void) { + bool changed = false; + +#if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW) + // Set col, read rows + for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { + changed |= read_rows_on_col(raw_matrix, current_col); + } +#elif (DIODE_DIRECTION == ROW2COL) + // Set row, read cols + for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { + changed |= read_cols_on_row(raw_matrix, current_row); + } +#endif + + debounce(raw_matrix, matrix, MATRIX_ROWS, changed); + + matrix_scan_quantum(); + return (uint8_t)changed; +} diff --git a/keyboards/yandrstudio/whiteMouse28T/f401/mcuconf.h b/keyboards/yandrstudio/whiteMouse28T/f401/mcuconf.h index 0e2d442253a6..ec7ed63a1488 100644 --- a/keyboards/yandrstudio/whiteMouse28T/f401/mcuconf.h +++ b/keyboards/yandrstudio/whiteMouse28T/f401/mcuconf.h @@ -14,25 +14,15 @@ * along with this program. If not, see . */ -/* - * This file was auto-generated by: - * `qmk chibios-confmigrate -i keyboards/zvecr/zv48/f401/mcuconf.h -r platforms/chibios/BLACKPILL_STM32_F401/configs/mcuconf.h` - */ - #pragma once #include_next -// #undef STM32_PWM_USE_TIM3 -// #define STM32_PWM_USE_TIM3 TRUE - -#undef STM32_SERIAL_USE_USART1 -#define STM32_SERIAL_USE_USART1 FALSE - #undef STM32_SPI_USE_SPI1 #define STM32_SPI_USE_SPI1 TRUE + #undef STM32_NO_INIT #undef STM32_HSI_ENABLED #undef STM32_LSI_ENABLED diff --git a/keyboards/yandrstudio/whiteMouse28T/f401/rules.mk b/keyboards/yandrstudio/whiteMouse28T/f401/rules.mk index 1685761b4c7c..1f81ff6f41f1 100644 --- a/keyboards/yandrstudio/whiteMouse28T/f401/rules.mk +++ b/keyboards/yandrstudio/whiteMouse28T/f401/rules.mk @@ -4,6 +4,8 @@ MCU = STM32F401 # Address of the bootloader in system memory STM32_BOOTLOADER_ADDRESS = 0x1FFF0000 -# Disable unsupported hardware -# AUDIO_SUPPORTED = no -# BACKLIGHT_SUPPORTED = no + +CUSTOM_MATRIX = lite # for using the A9 pin as matrix io + +# # project specific file +QUANTUM_SRC += matrix.c diff --git a/keyboards/yandrstudio/whiteMouse28T/info-via.json b/keyboards/yandrstudio/whiteMouse28T/info-via.json index ecc47ad670da..c7fc952a32d4 100644 --- a/keyboards/yandrstudio/whiteMouse28T/info-via.json +++ b/keyboards/yandrstudio/whiteMouse28T/info-via.json @@ -1,12 +1,12 @@ { - "name": "BS28", + "name": "WM28_Y&R", "vendorId": "0xAA96", - "productId": "0xAA05", + "productId": "0xAA04", "lighting": { "extends": "none", "keycodes": "qmk" }, - "matrix": { "rows": 4, "cols": 7 }, + "matrix": { "rows": 5, "cols": 14 }, "layouts": { "keymap": [ diff --git a/keyboards/yandrstudio/whiteMouse28T/readme.md b/keyboards/yandrstudio/whiteMouse28T/readme.md index c67fab2def17..951c795b822d 100644 --- a/keyboards/yandrstudio/whiteMouse28T/readme.md +++ b/keyboards/yandrstudio/whiteMouse28T/readme.md @@ -1,7 +1,7 @@ whiteMouse28T === -A 68 keys keyboard with rgb (keys and underground). +A 28 keys keyboard with rgb (keys) and a external eeprom (95256). This keyboard use 8mhz HSE and STM32F401 as MCU. Keyboard Maintainer: https://github.com/jiaxin96