From c42a3475142ed6ab2417799f3d3458980f21657f Mon Sep 17 00:00:00 2001 From: "Khalid J." Date: Mon, 30 Sep 2024 02:27:15 +0300 Subject: [PATCH 1/2] Initial support for Redragon RYZE --- meson.build | 1 + src/keyboards/redragon-ryze/kbdef.h | 114 ++++++++++ .../layouts/default/indicators.c | 198 ++++++++++++++++++ .../redragon-ryze/layouts/default/layout.c | 47 +++++ src/keyboards/redragon-ryze/user_init.c | 83 ++++++++ src/keyboards/redragon-ryze/user_matrix.c | 93 ++++++++ 6 files changed, 536 insertions(+) create mode 100644 src/keyboards/redragon-ryze/kbdef.h create mode 100644 src/keyboards/redragon-ryze/layouts/default/indicators.c create mode 100644 src/keyboards/redragon-ryze/layouts/default/layout.c create mode 100644 src/keyboards/redragon-ryze/user_init.c create mode 100644 src/keyboards/redragon-ryze/user_matrix.c diff --git a/meson.build b/meson.build index cfd9e09..02e64b9 100644 --- a/meson.build +++ b/meson.build @@ -22,6 +22,7 @@ parts = [ ['example', 'sh68f90a', ['default'], {}], ['nuphy-air60', 'sh68f90a', ['default'], { 'vendor_id': '0x05ac', 'product_id': '0x024f' }], ['eyooso-z11', 'sh68f90a', ['default'], { 'vendor_id': '0x258a', 'product_id': '0x002a' }], + [ 'redragon-ryze', 'sh68f90a', [ 'default'], { 'vendor_id': '0x258a', 'product_id': '0x0049' }], ] # SMK diff --git a/src/keyboards/redragon-ryze/kbdef.h b/src/keyboards/redragon-ryze/kbdef.h new file mode 100644 index 0000000..3b21c7a --- /dev/null +++ b/src/keyboards/redragon-ryze/kbdef.h @@ -0,0 +1,114 @@ +#ifndef KBDEF_H +#define KBDEF_H + +#include "sh68f90a.h" + +#define MATRIX_ROWS 5 +#define MATRIX_COLS 15 + +// Row Pins Bits +#define KB_R0_P7_1 _P7_1 +#define KB_R1_P7_2 _P7_2 +#define KB_R2_P7_3 _P7_3 +#define KB_R3_P5_3 _P5_3 +#define KB_R4_P5_4 _P5_4 + +// Row Pins +#define KB_R0 P7_1 +#define KB_R1 P7_2 +#define KB_R2 P7_3 +#define KB_R3 P5_3 +#define KB_R4 P5_4 + +// Column Pins Bits +#define KB_C0_P5_0 _P5_0 +#define KB_C1_P5_1 _P5_1 +#define KB_C2_P5_2 _P5_2 +#define KB_C3_P3_5 _P3_5 +#define KB_C4_P3_4 _P3_4 +#define KB_C5_P3_3 _P3_3 +#define KB_C6_P3_2 _P3_2 +#define KB_C7_P3_1 _P3_1 +#define KB_C8_P3_0 _P3_0 +#define KB_C9_P2_5 _P2_5 +#define KB_C10_P2_4 _P2_4 +#define KB_C11_P2_3 _P2_3 +#define KB_C12_P2_2 _P2_2 +#define KB_C13_P2_1 _P2_1 +#define KB_C14_P2_0 _P2_0 + +// Column Pins +#define KB_C0 P5_0 +#define KB_C1 P5_1 +#define KB_C2 P5_2 +#define KB_C3 P3_5 +#define KB_C4 P3_4 +#define KB_C5 P3_3 +#define KB_C6 P3_2 +#define KB_C7 P3_1 +#define KB_C8 P3_0 +#define KB_C9 P2_5 +#define KB_C10 P2_4 +#define KB_C11 P2_3 +#define KB_C12 P2_2 +#define KB_C13 P2_1 +#define KB_C14 P2_0 + +// LED PWM Registers +#define LED_PWM_C0 PWM40 +#define LED_PWM_C1 PWM41 +#define LED_PWM_C2 PWM42 +#define LED_PWM_C3 PWM05 +#define LED_PWM_C4 PWM04 +#define LED_PWM_C5 PWM03 +#define LED_PWM_C6 PWM02 +#define LED_PWM_C7 PWM01 +#define LED_PWM_C8 PWM00 +#define LED_PWM_C9 PWM15 +#define LED_PWM_C10 PWM14 +#define LED_PWM_C11 PWM13 +#define LED_PWM_C12 PWM12 +#define LED_PWM_C13 PWM11 +#define LED_PWM_C14 PWM10 + +// RGB Row Pins +#define RGB_R0R P0_4 +#define RGB_R0G P6_1 +#define RGB_R0B P0_3 +#define RGB_R1R P6_7 +#define RGB_R1G P6_2 +#define RGB_R1B P6_6 +#define RGB_R2R P0_2 +#define RGB_R2G P6_3 +#define RGB_R2B P5_7 +#define RGB_R3R P4_5 +#define RGB_R3G P6_4 +#define RGB_R3B P4_6 +#define RGB_R4R P4_4 +#define RGB_R4G P6_5 +#define RGB_R4B P4_3 +#define RGB_ULR P1_1 +#define RGB_ULG P1_2 +#define RGB_ULB P1_3 + +// RGB Row Pin Bits +#define RGB_R0R_P0_4 _P0_4 +#define RGB_R0G_P6_1 _P6_1 +#define RGB_R0B_P0_3 _P0_3 +#define RGB_R1R_P6_7 _P6_7 +#define RGB_R1G_P6_2 _P6_2 +#define RGB_R1B_P6_6 _P6_6 +#define RGB_R2R_P0_2 _P0_2 +#define RGB_R2G_P6_3 _P6_3 +#define RGB_R2B_P5_7 _P5_7 +#define RGB_R3R_P4_5 _P4_5 +#define RGB_R3G_P6_4 _P6_4 +#define RGB_R3B_P4_6 _P4_6 +#define RGB_R4R_P4_4 _P4_4 +#define RGB_R4G_P6_5 _P6_5 +#define RGB_R4B_P4_3 _P4_3 +#define RGB_ULR_P1_1 _P1_1 +#define RGB_ULG_P1_2 _P1_2 +#define RGB_ULB_P1_3 _P1_3 + +#endif diff --git a/src/keyboards/redragon-ryze/layouts/default/indicators.c b/src/keyboards/redragon-ryze/layouts/default/indicators.c new file mode 100644 index 0000000..1d6495d --- /dev/null +++ b/src/keyboards/redragon-ryze/layouts/default/indicators.c @@ -0,0 +1,198 @@ +#include "indicators.h" +#include "kbdef.h" +#include "pwm.h" +#include + +// TODO: move these defines out +#define PWM_CLK_DIV 0b010 // PWM_CLK = SYS_CLK / 4 +#define PWM_SS_BIT (1 << 3) +#define PWM_MOD_BIT (1 << 4) +#define PWM_INT_ENABLE_BIT (1 << 6) +#define PWM_MODE_ENABLE_BIT (1 << 7) + +void indicators_pwm_set_all_columns(uint16_t intensity); +void indicators_pwm_enable(); +void indicators_pwm_disable(); + +void indicators_start() +{ + indicators_pwm_enable(); +} + +void indicators_pre_update() +{ + // set all rgb sinks to low (animation step will enable needed ones) + P0 &= ~(RGB_R2R_P0_2 | RGB_R0B_P0_3 | RGB_R0R_P0_4); + P1 &= ~(RGB_ULR_P1_1 | RGB_ULG_P1_2 | RGB_ULB_P1_3); + P4 &= ~(RGB_R4B_P4_3 | RGB_R4R_P4_4 | RGB_R3R_P4_5 | RGB_R3B_P4_6); + P5 &= ~(RGB_R2B_P5_7); + P6 &= ~(RGB_R0G_P6_1 | RGB_R1G_P6_2 | RGB_R2G_P6_3 | RGB_R3G_P6_4 | RGB_R4G_P6_5 | RGB_R1B_P6_6 | RGB_R1R_P6_7); + + indicators_pwm_disable(); +} + +bool indicators_update_step(keyboard_state_t *keyboard, uint8_t current_step) +{ + static uint16_t current_cycle = 0; + + if (current_step == 0) { + if (current_cycle < 3072) { + current_cycle++; + } else { + current_cycle = 0; + } + } + + uint16_t red_intensity = 0; + uint16_t green_intensity = 0; + uint16_t blue_intensity = 0; + + if (current_cycle < 1024) { + blue_intensity = 1024 - (uint16_t)abs((int16_t)((current_cycle + 1024) % 2048) - 1024); + red_intensity = 1024 - (uint16_t)abs((int16_t)((current_cycle) % 2048) - 1024); + } else if (current_cycle < 2048) { + red_intensity = 1024 - (uint16_t)abs((int16_t)((current_cycle) % 2048) - 1024); + green_intensity = 1024 - (uint16_t)abs((int16_t)((current_cycle + 1024) % 2048) - 1024); + } else { + green_intensity = 1024 - (uint16_t)abs((int16_t)((current_cycle + 1024) % 2048) - 1024); + blue_intensity = 1024 - (uint16_t)abs((int16_t)((current_cycle) % 2048) - 1024); + } + + uint16_t color_intensity; + + if (keyboard->led_state & (1 << 0)) { // num_lock + red_intensity = 1024; + } + + if (keyboard->led_state & (1 << 1)) { // caps_lock + green_intensity = 1024; + } + + if (keyboard->led_state & (1 << 2)) { // scroll_lock + blue_intensity = 1024; + } + + switch (current_step % 3) { + case 0: // red + RGB_R0R = 1; + RGB_R1R = 1; + RGB_R2R = 1; + RGB_R3R = 1; + RGB_R4R = 1; + RGB_ULR = 1; + + color_intensity = red_intensity; + break; + + case 1: // green + RGB_R0G = 1; + RGB_R1G = 1; + RGB_R2G = 1; + RGB_R3G = 1; + RGB_R4G = 1; + RGB_ULG = 1; + + color_intensity = green_intensity; + break; + + case 2: // blue + RGB_R0B = 1; + RGB_R1B = 1; + RGB_R2B = 1; + RGB_R3B = 1; + RGB_R4B = 1; + RGB_ULB = 1; + + color_intensity = blue_intensity; + break; + + default: + // unreachable + color_intensity = 0; + break; + } + + // set pwm duty cycles to expected colors + indicators_pwm_set_all_columns(color_intensity); + + return false; +} + +void indicators_post_update() +{ + // clear pwm isr flag + PWM00CON &= ~(1 << 5); + + indicators_pwm_enable(); +} + +void indicators_pwm_set_all_columns(uint16_t intensity) +{ + uint16_t adjusted = 0x0400 - intensity; + + SET_PWM_DUTY_2(LED_PWM_C0, adjusted); + SET_PWM_DUTY_2(LED_PWM_C1, adjusted); + SET_PWM_DUTY_2(LED_PWM_C2, adjusted); + SET_PWM_DUTY_2(LED_PWM_C3, adjusted); + SET_PWM_DUTY_2(LED_PWM_C4, adjusted); + SET_PWM_DUTY_2(LED_PWM_C5, adjusted); + SET_PWM_DUTY_2(LED_PWM_C6, adjusted); + SET_PWM_DUTY_2(LED_PWM_C7, adjusted); + SET_PWM_DUTY_2(LED_PWM_C8, adjusted); + SET_PWM_DUTY_2(LED_PWM_C9, adjusted); + SET_PWM_DUTY_2(LED_PWM_C10, adjusted); + SET_PWM_DUTY_2(LED_PWM_C11, adjusted); + SET_PWM_DUTY_2(LED_PWM_C12, adjusted); + SET_PWM_DUTY_2(LED_PWM_C13, adjusted); + SET_PWM_DUTY_2(LED_PWM_C14, adjusted); +} + +void indicators_pwm_enable() +{ + // TODO: try abstracting individual banks away + PWM00CON = (uint8_t)(PWM_MODE_ENABLE_BIT | PWM_INT_ENABLE_BIT | PWM_SS_BIT | PWM_CLK_DIV); + PWM01CON = PWM_SS_BIT; + PWM02CON = PWM_SS_BIT; + PWM03CON = PWM_SS_BIT; + PWM04CON = PWM_SS_BIT; + PWM05CON = PWM_SS_BIT; + + PWM10CON = (uint8_t)(PWM_MODE_ENABLE_BIT | PWM_SS_BIT | PWM_CLK_DIV); + PWM11CON = PWM_SS_BIT; + PWM12CON = PWM_SS_BIT; + PWM13CON = PWM_SS_BIT; + PWM14CON = PWM_SS_BIT; + + PWM20CON = (uint8_t)(PWM_MODE_ENABLE_BIT | PWM_SS_BIT | PWM_CLK_DIV); + // PWM24CON = PWM_SS_BIT; + PWM25CON = PWM_SS_BIT; + + PWM40CON = (uint8_t)(PWM_MODE_ENABLE_BIT | PWM_SS_BIT | PWM_CLK_DIV); + PWM41CON = PWM_SS_BIT; + PWM42CON = PWM_SS_BIT; +} + +void indicators_pwm_disable() +{ + // TODO: try abstracting individual banks away + PWM00CON = (uint8_t)(PWM_CLK_DIV); + PWM01CON = 0; + PWM02CON = 0; + PWM03CON = 0; + PWM04CON = 0; + PWM05CON = 0; + + PWM10CON = (uint8_t)(PWM_CLK_DIV); + PWM11CON = 0; + PWM12CON = 0; + PWM13CON = 0; + PWM14CON = 0; + + PWM20CON = (uint8_t)(PWM_CLK_DIV); + // PWM24CON = 0; + PWM25CON = 0; + + PWM40CON = (uint8_t)(PWM_CLK_DIV); + PWM41CON = 0; + PWM42CON = 0; +} diff --git a/src/keyboards/redragon-ryze/layouts/default/layout.c b/src/keyboards/redragon-ryze/layouts/default/layout.c new file mode 100644 index 0000000..52a54eb --- /dev/null +++ b/src/keyboards/redragon-ryze/layouts/default/layout.c @@ -0,0 +1,47 @@ +#include "kbdef.h" +#include "layout.h" +#include "user_layout.h" +#include "report.h" +#include + +// clang-format off + +#define LAYOUT_65( \ + K00_0, K01_0, K02_0, K03_0, K04_0, K05_0, K06_0, K07_0, K08_0, K09_0, K10_0, K11_0, K12_0, K13_0, K14_0, \ + K00_1, K01_1, K02_1, K03_1, K04_1, K05_1, K06_1, K07_1, K08_1, K09_1, K10_1, K11_1, K12_1, K13_1, K14_1, \ + K00_2, K01_2, K02_2, K03_2, K04_2, K05_2, K06_2, K07_2, K08_2, K09_2, K10_2, K11_2, K13_2, K14_2, \ + K00_3, K01_3, K02_3, K03_3, K04_3, K05_3, K06_3, K07_3, K08_3, K09_3, K10_3, K11_3, K13_3, K14_3, \ + K00_4, K01_4, K02_4, K05_4, K08_4, K09_4, K10_4, K12_4, K13_4, K14_4 \ + ) { \ + { K00_0, K01_0, K02_0, K03_0, K04_0, K05_0, K06_0, K07_0, K08_0, K09_0, K10_0, K11_0, K12_0, K13_0, K14_0 }, \ + { K00_1, K01_1, K02_1, K03_1, K04_1, K05_1, K06_1, K07_1, K08_1, K09_1, K10_1, K11_1, K12_1, K13_1, K14_1 }, \ + { K00_2, K01_2, K02_2, K03_2, K04_2, K05_2, K06_2, K07_2, K08_2, K09_2, K10_2, K11_2, KC_NO, K13_2, K14_2 }, \ + { K00_3, K01_3, K02_3, K03_3, K04_3, K05_3, K06_3, K07_3, K08_3, K09_3, K10_3, K11_3, KC_NO, K13_3, K14_3 }, \ + { K00_4, K01_4, K02_4, KC_NO, KC_NO, K05_4, KC_NO, KC_NO, K08_4, K09_4, K10_4, KC_NO, K12_4, K13_4, K14_4 } \ +} + +// Each layer gets a name for readability, which is then used in the keymap matrix below. +// The underscores don't mean anything - you can have a layer called STUFF or any other name. +// Layer names don't all need to be of the same length, obviously, and you can also skip them +// entirely and just use numbers. +#define _BL 0 +#define _FL 1 + +const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [_BL] = LAYOUT_65( + KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_DEL, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_GRV, + KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGUP, + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_PGDN, + KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(_FL), KC_APP, KC_LEFT, KC_DOWN, KC_RGHT + ), + [_FL] = LAYOUT_65( + _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_END, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_PSCR, KC_INS, _______, _______, + _______, KC_KB_VOLUME_DOWN, KC_KB_VOLUME_UP, KC_KB_MUTE, KC_MEDIA_STOP, KC_MEDIA_PREV_TRACK, KC_MEDIA_NEXT_TRACK, KC_MEDIA_PLAY_PAUSE, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ + ), +}; + +// clang-format on diff --git a/src/keyboards/redragon-ryze/user_init.c b/src/keyboards/redragon-ryze/user_init.c new file mode 100644 index 0000000..8b6c0a3 --- /dev/null +++ b/src/keyboards/redragon-ryze/user_init.c @@ -0,0 +1,83 @@ +#include "kbdef.h" +#include "user_init.h" +#include "pwm.h" + +// TODO: move these defines out +#define PWM_PERD 0x0400 // 1024 / PWM_CLK ~= 43 us + +#define PWM_DUTY1 (uint16_t) PWM_PERD +#define PWM_DUTY2 (uint16_t)0 + +#define PWM_PERDH_INIT ((uint8_t)(PWM_PERD >> 8)) +#define PWM_PERDL_INIT ((uint8_t)(PWM_PERD)) + +void user_gpio_init(); +void user_pwm_init(); + +void user_init() +{ + user_gpio_init(); + user_pwm_init(); + + IEN1 |= (1 << 1); // EPWM0 +} + +void user_gpio_init() +{ + // configure driving capabilities + DRVCON = 0x05; // allow P1 to be changed + P1DRV = 0x00; // 25mA + + DRVCON = 0x45; // allow P2 to be changed + P2DRV = 0x00; // 25mA + + DRVCON = 0x85; // allow P3 to be changed + P3DRV = 0x00; // 25mA + + DRVCON = 0xc5; // allow P5 to be changed + P5DRV = 0x00; // 25mA + + DRVCON = 0; + + P0CR = (uint8_t)(RGB_R2R_P0_2 | RGB_R0B_P0_3 | RGB_R0R_P0_4); + P1CR = (uint8_t)(RGB_ULR_P1_1 | RGB_ULG_P1_2 | RGB_ULB_P1_3); + P2CR = (uint8_t)(KB_C14_P2_0 | KB_C13_P2_1 | KB_C12_P2_2 | KB_C11_P2_3 | KB_C10_P2_4 | KB_C9_P2_5); + P3CR = (uint8_t)(KB_C8_P3_0 | KB_C7_P3_1 | KB_C6_P3_2 | KB_C5_P3_3 | KB_C4_P3_4 | KB_C3_P3_5); + P4CR = (uint8_t)(RGB_R4B_P4_3 | RGB_R4R_P4_4 | RGB_R3R_P4_5 | RGB_R3B_P4_6); + P5CR = (uint8_t)(KB_C0_P5_0 | KB_C1_P5_1 | KB_C2_P5_2 | RGB_R2B_P5_7); + P6CR = (uint8_t)(RGB_R0G_P6_1 | RGB_R1G_P6_2 | RGB_R2G_P6_3 | RGB_R3G_P6_4 | RGB_R4G_P6_5 | RGB_R1B_P6_6 | RGB_R1R_P6_7); + + P5PCR = (uint8_t)(KB_R3_P5_3 | KB_R4_P5_4); + P7PCR = (uint8_t)(KB_R0_P7_1 | KB_R1_P7_2 | KB_R2_P7_3); +} + +void user_pwm_init() +{ + PWM0PERDH = PWM_PERDH_INIT; + PWM0PERDL = PWM_PERDL_INIT; + + PWM1PERDH = PWM_PERDH_INIT; + PWM1PERDL = PWM_PERDL_INIT; + + PWM2PERDH = PWM_PERDH_INIT; + PWM2PERDL = PWM_PERDL_INIT; + + PWM4PERDH = PWM_PERDH_INIT; + PWM4PERDL = PWM_PERDL_INIT; + + SET_PWM_DUTY(LED_PWM_C0, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C1, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C2, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C3, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C4, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C5, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C6, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C7, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C8, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C9, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C10, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C11, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C12, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C13, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C14, PWM_DUTY1, PWM_DUTY2); +} diff --git a/src/keyboards/redragon-ryze/user_matrix.c b/src/keyboards/redragon-ryze/user_matrix.c new file mode 100644 index 0000000..0c72b56 --- /dev/null +++ b/src/keyboards/redragon-ryze/user_matrix.c @@ -0,0 +1,93 @@ +#include "kbdef.h" +#include "user_matrix.h" + +void user_matrix_pre_scan(uint8_t col) +{ + // set all columns to high + P2 |= (uint8_t)(KB_C14_P2_0 | KB_C13_P2_1 | KB_C12_P2_2 | KB_C11_P2_3 | KB_C10_P2_4 | KB_C9_P2_5); + P3 |= (uint8_t)(KB_C8_P3_0 | KB_C7_P3_1 | KB_C6_P3_2 | KB_C5_P3_3 | KB_C4_P3_4 | KB_C3_P3_5); + P5 |= (uint8_t)(KB_C0_P5_0 | KB_C1_P5_1 | KB_C2_P5_2); + + // set current (!) column to low + switch (col) { + case 0: + KB_C0 = 0; + break; + + case 1: + KB_C1 = 0; + break; + + case 2: + KB_C2 = 0; + break; + + case 3: + KB_C3 = 0; + break; + + case 4: + KB_C4 = 0; + break; + + case 5: + KB_C5 = 0; + break; + + case 6: + KB_C6 = 0; + break; + + case 7: + KB_C7 = 0; + break; + + case 8: + KB_C8 = 0; + break; + + case 9: + KB_C9 = 0; + break; + + case 10: + KB_C10 = 0; + break; + + case 11: + KB_C11 = 0; + break; + + case 12: + KB_C12 = 0; + break; + + case 13: + KB_C13 = 0; + break; + + case 14: + KB_C14 = 0; + break; + } +} + +uint8_t user_matrix_scan_col(uint8_t col) +{ + col; + // grab key for the column state + // P7_1 - R0 + // P7_2 - R1 + // P7_3 - R2 + // P5_3 - R3 + // P5_4 - R4 + return (((P7 >> 1) & 0x07) | (P5 & 0x18)) | 0xe0; +} + +void user_matrix_post_scan() +{ + // set all columns down to low + P2 &= (uint8_t) ~(KB_C14_P2_0 | KB_C13_P2_1 | KB_C12_P2_2 | KB_C11_P2_3 | KB_C10_P2_4 | KB_C9_P2_5); + P3 &= (uint8_t) ~(KB_C8_P3_0 | KB_C7_P3_1 | KB_C6_P3_2 | KB_C5_P3_3 | KB_C4_P3_4 | KB_C3_P3_5); + P5 &= (uint8_t) ~(KB_C0_P5_0 | KB_C1_P5_1 | KB_C2_P5_2); +} From 74d1bfd8b2b7ff2b169307f52bf24b1664352432 Mon Sep 17 00:00:00 2001 From: "Khalid J." Date: Wed, 2 Oct 2024 01:57:33 +0300 Subject: [PATCH 2/2] Fix RGB LED columns --- src/keyboards/redragon-ryze/kbdef.h | 6 ------ src/keyboards/redragon-ryze/layouts/default/indicators.c | 6 ++---- src/keyboards/redragon-ryze/user_init.c | 1 - 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/keyboards/redragon-ryze/kbdef.h b/src/keyboards/redragon-ryze/kbdef.h index 3b21c7a..96beeb0 100644 --- a/src/keyboards/redragon-ryze/kbdef.h +++ b/src/keyboards/redragon-ryze/kbdef.h @@ -87,9 +87,6 @@ #define RGB_R4R P4_4 #define RGB_R4G P6_5 #define RGB_R4B P4_3 -#define RGB_ULR P1_1 -#define RGB_ULG P1_2 -#define RGB_ULB P1_3 // RGB Row Pin Bits #define RGB_R0R_P0_4 _P0_4 @@ -107,8 +104,5 @@ #define RGB_R4R_P4_4 _P4_4 #define RGB_R4G_P6_5 _P6_5 #define RGB_R4B_P4_3 _P4_3 -#define RGB_ULR_P1_1 _P1_1 -#define RGB_ULG_P1_2 _P1_2 -#define RGB_ULB_P1_3 _P1_3 #endif diff --git a/src/keyboards/redragon-ryze/layouts/default/indicators.c b/src/keyboards/redragon-ryze/layouts/default/indicators.c index 1d6495d..1cb1331 100644 --- a/src/keyboards/redragon-ryze/layouts/default/indicators.c +++ b/src/keyboards/redragon-ryze/layouts/default/indicators.c @@ -23,7 +23,6 @@ void indicators_pre_update() { // set all rgb sinks to low (animation step will enable needed ones) P0 &= ~(RGB_R2R_P0_2 | RGB_R0B_P0_3 | RGB_R0R_P0_4); - P1 &= ~(RGB_ULR_P1_1 | RGB_ULG_P1_2 | RGB_ULB_P1_3); P4 &= ~(RGB_R4B_P4_3 | RGB_R4R_P4_4 | RGB_R3R_P4_5 | RGB_R3B_P4_6); P5 &= ~(RGB_R2B_P5_7); P6 &= ~(RGB_R0G_P6_1 | RGB_R1G_P6_2 | RGB_R2G_P6_3 | RGB_R3G_P6_4 | RGB_R4G_P6_5 | RGB_R1B_P6_6 | RGB_R1R_P6_7); @@ -79,7 +78,6 @@ bool indicators_update_step(keyboard_state_t *keyboard, uint8_t current_step) RGB_R2R = 1; RGB_R3R = 1; RGB_R4R = 1; - RGB_ULR = 1; color_intensity = red_intensity; break; @@ -90,7 +88,6 @@ bool indicators_update_step(keyboard_state_t *keyboard, uint8_t current_step) RGB_R2G = 1; RGB_R3G = 1; RGB_R4G = 1; - RGB_ULG = 1; color_intensity = green_intensity; break; @@ -101,7 +98,6 @@ bool indicators_update_step(keyboard_state_t *keyboard, uint8_t current_step) RGB_R2B = 1; RGB_R3B = 1; RGB_R4B = 1; - RGB_ULB = 1; color_intensity = blue_intensity; break; @@ -162,6 +158,7 @@ void indicators_pwm_enable() PWM12CON = PWM_SS_BIT; PWM13CON = PWM_SS_BIT; PWM14CON = PWM_SS_BIT; + PWM15CON = PWM_SS_BIT; PWM20CON = (uint8_t)(PWM_MODE_ENABLE_BIT | PWM_SS_BIT | PWM_CLK_DIV); // PWM24CON = PWM_SS_BIT; @@ -187,6 +184,7 @@ void indicators_pwm_disable() PWM12CON = 0; PWM13CON = 0; PWM14CON = 0; + PWM15CON = 0; PWM20CON = (uint8_t)(PWM_CLK_DIV); // PWM24CON = 0; diff --git a/src/keyboards/redragon-ryze/user_init.c b/src/keyboards/redragon-ryze/user_init.c index 8b6c0a3..89b092a 100644 --- a/src/keyboards/redragon-ryze/user_init.c +++ b/src/keyboards/redragon-ryze/user_init.c @@ -40,7 +40,6 @@ void user_gpio_init() DRVCON = 0; P0CR = (uint8_t)(RGB_R2R_P0_2 | RGB_R0B_P0_3 | RGB_R0R_P0_4); - P1CR = (uint8_t)(RGB_ULR_P1_1 | RGB_ULG_P1_2 | RGB_ULB_P1_3); P2CR = (uint8_t)(KB_C14_P2_0 | KB_C13_P2_1 | KB_C12_P2_2 | KB_C11_P2_3 | KB_C10_P2_4 | KB_C9_P2_5); P3CR = (uint8_t)(KB_C8_P3_0 | KB_C7_P3_1 | KB_C6_P3_2 | KB_C5_P3_3 | KB_C4_P3_4 | KB_C3_P3_5); P4CR = (uint8_t)(RGB_R4B_P4_3 | RGB_R4R_P4_4 | RGB_R3R_P4_5 | RGB_R3B_P4_6);