diff --git a/builddefs/common_features.mk b/builddefs/common_features.mk index 0795a5c5470d..7508687db4ac 100644 --- a/builddefs/common_features.mk +++ b/builddefs/common_features.mk @@ -622,6 +622,13 @@ ifeq ($(strip $(LED_TABLES)), yes) SRC += $(QUANTUM_DIR)/led_tables.c endif +ifeq ($(strip $(OPENRGB_ENABLE)), yes) + + RAW_ENABLE := yes + SRC += $(QUANTUM_DIR)/openrgb.c + OPT_DEFS += -DOPENRGB_ENABLE +endif + ifeq ($(strip $(VIA_ENABLE)), yes) DYNAMIC_KEYMAP_ENABLE := yes RAW_ENABLE := yes diff --git a/builddefs/show_options.mk b/builddefs/show_options.mk index 9723b45438a8..ab6a9ae8d2ac 100644 --- a/builddefs/show_options.mk +++ b/builddefs/show_options.mk @@ -10,8 +10,9 @@ BUILD_OPTION_NAMES = \ SPLIT_KEYBOARD \ DYNAMIC_KEYMAP_ENABLE \ USB_HID_ENABLE \ + OPENRGB_ENABLE \ VIA_ENABLE - + HARDWARE_OPTION_NAMES = \ SLEEP_LED_ENABLE \ BACKLIGHT_ENABLE \ diff --git a/keyboards/keychron/bluetooth/indicator.c b/keyboards/keychron/bluetooth/indicator.c index 434846070025..ce238a71cb5f 100644 --- a/keyboards/keychron/bluetooth/indicator.c +++ b/keyboards/keychron/bluetooth/indicator.c @@ -477,25 +477,7 @@ void indicator_task(void) { #if defined(LED_MATRIX_ENABLE) || defined(RGB_MATRIX_ENABLE) __attribute__((weak)) void os_state_indicate(void) { -# if defined(NUM_LOCK_INDEX) - if (host_keyboard_led_state().num_lock) { - SET_LED_ON(NUM_LOCK_INDEX); - } -# endif -# if defined(CAPS_LOCK_INDEX) - if (host_keyboard_led_state().caps_lock) { -# if defined(DIM_CAPS_LOCK) - SET_LED_OFF(CAPS_LOCK_INDEX); -# else - SET_LED_ON(CAPS_LOCK_INDEX); -# endif - } -# endif -# if defined(SCROLL_LOCK_INDEX) - if (host_keyboard_led_state().scroll_lock) { - SET_LED_ON(SCROLL_LOCK_INDEX); - } -# endif + # if defined(COMPOSE_LOCK_INDEX) if (host_keyboard_led_state().compose) { SET_LED_ON(COMPOSE_LOCK_INDEX); @@ -585,15 +567,7 @@ void LED_NONE_INDICATORS_KB(void) { # if defined(LED_MATRIX_DRIVER_SHUTDOWN_ENABLE) || defined(RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE) bool LED_DRIVER_ALLOW_SHUTDOWN(void) { -# if defined(NUM_LOCK_INDEX) - if (host_keyboard_led_state().num_lock) return false; -# endif -# if defined(CAPS_LOCK_INDEX) && !defined(DIM_CAPS_LOCK) - if (host_keyboard_led_state().caps_lock) return false; -# endif -# if defined(SCROLL_LOCK_INDEX) - if (host_keyboard_led_state().scroll_lock) return false; -# endif + # if defined(COMPOSE_LOCK_INDEX) if (host_keyboard_led_state().compose) return false; # endif diff --git a/keyboards/keychron/q6_pro/ansi_encoder/keymaps/default/keymap.c b/keyboards/keychron/q6_pro/ansi_encoder/keymaps/default/keymap.c index 237cafbd58a8..8edd55359f6d 100755 --- a/keyboards/keychron/q6_pro/ansi_encoder/keymaps/default/keymap.c +++ b/keyboards/keychron/q6_pro/ansi_encoder/keymaps/default/keymap.c @@ -24,6 +24,8 @@ enum layers{ WIN_FN, }; +#define SWITCH_MODE 0x1688 + const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [MAC_BASE] = LAYOUT_109_ansi( KC_ESC, KC_BRID, KC_BRIU, KC_MCTL, KC_LPAD, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, KC_MUTE, KC_SNAP, KC_SIRI, RGB_MOD, KC_F13, KC_F14, KC_F15, KC_F16, @@ -35,7 +37,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [MAC_FN] = LAYOUT_109_ansi( _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, RGB_TOG, _______, _______, RGB_TOG, _______, _______, _______, _______, _______, BT_HST1, BT_HST2, BT_HST3, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, - RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, _______, _______, _______, SWITCH_MODE, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ ), @@ -49,7 +51,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [WIN_FN] = LAYOUT_109_ansi( _______, KC_BRID, KC_BRIU, KC_TASK, KC_FILE, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, RGB_TOG, _______, _______, RGB_TOG, _______, _______, _______, _______, _______, BT_HST1, BT_HST2, BT_HST3, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, - RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, _______, _______, _______, SWITCH_MODE, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ ), @@ -63,3 +65,20 @@ const uint16_t PROGMEM encoder_map[][1][2] = { [WIN_FN] = {ENCODER_CCW_CW(RGB_VAD, RGB_VAI) } }; #endif // ENCODER_MAP_ENABLE + +extern uint8_t is_orgb_mode; + +bool process_record_user(uint16_t keycode, keyrecord_t *record) +{ + switch (keycode) { + case SWITCH_MODE: + #ifdef OPENRGB_ENABLE + if (record->event.pressed) { + is_orgb_mode = !is_orgb_mode; + } + #endif + return false; + } + + return true; +} \ No newline at end of file diff --git a/keyboards/keychron/q6_pro/ansi_encoder/keymaps/default/rules.mk b/keyboards/keychron/q6_pro/ansi_encoder/keymaps/default/rules.mk index ee325681483f..6356ed297338 100644 --- a/keyboards/keychron/q6_pro/ansi_encoder/keymaps/default/rules.mk +++ b/keyboards/keychron/q6_pro/ansi_encoder/keymaps/default/rules.mk @@ -1 +1,4 @@ -ENCODER_MAP_ENABLE = yes +OPENRGB_ENABLE = yes +RGB_MATRIX_ENABLE = yes +VIA_ENABLE = yes +ENCODER_MAP_ENABLE = yes \ No newline at end of file diff --git a/keyboards/keychron/q6_pro/ansi_encoder/keymaps/via/keymap.c b/keyboards/keychron/q6_pro/ansi_encoder/keymaps/via/keymap.c index 237cafbd58a8..8edd55359f6d 100755 --- a/keyboards/keychron/q6_pro/ansi_encoder/keymaps/via/keymap.c +++ b/keyboards/keychron/q6_pro/ansi_encoder/keymaps/via/keymap.c @@ -24,6 +24,8 @@ enum layers{ WIN_FN, }; +#define SWITCH_MODE 0x1688 + const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [MAC_BASE] = LAYOUT_109_ansi( KC_ESC, KC_BRID, KC_BRIU, KC_MCTL, KC_LPAD, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, KC_MUTE, KC_SNAP, KC_SIRI, RGB_MOD, KC_F13, KC_F14, KC_F15, KC_F16, @@ -35,7 +37,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [MAC_FN] = LAYOUT_109_ansi( _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, RGB_TOG, _______, _______, RGB_TOG, _______, _______, _______, _______, _______, BT_HST1, BT_HST2, BT_HST3, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, - RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, _______, _______, _______, SWITCH_MODE, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ ), @@ -49,7 +51,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [WIN_FN] = LAYOUT_109_ansi( _______, KC_BRID, KC_BRIU, KC_TASK, KC_FILE, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, RGB_TOG, _______, _______, RGB_TOG, _______, _______, _______, _______, _______, BT_HST1, BT_HST2, BT_HST3, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, - RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, _______, _______, _______, SWITCH_MODE, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ ), @@ -63,3 +65,20 @@ const uint16_t PROGMEM encoder_map[][1][2] = { [WIN_FN] = {ENCODER_CCW_CW(RGB_VAD, RGB_VAI) } }; #endif // ENCODER_MAP_ENABLE + +extern uint8_t is_orgb_mode; + +bool process_record_user(uint16_t keycode, keyrecord_t *record) +{ + switch (keycode) { + case SWITCH_MODE: + #ifdef OPENRGB_ENABLE + if (record->event.pressed) { + is_orgb_mode = !is_orgb_mode; + } + #endif + return false; + } + + return true; +} \ No newline at end of file diff --git a/keyboards/keychron/q6_pro/ansi_encoder/keymaps/via/rules.mk b/keyboards/keychron/q6_pro/ansi_encoder/keymaps/via/rules.mk index f1adcab005e8..634c9409a261 100644 --- a/keyboards/keychron/q6_pro/ansi_encoder/keymaps/via/rules.mk +++ b/keyboards/keychron/q6_pro/ansi_encoder/keymaps/via/rules.mk @@ -1,2 +1,3 @@ +OPENRGB_ENABLE = yes VIA_ENABLE = yes -ENCODER_MAP_ENABLE = yes +ENCODER_MAP_ENABLE = yes \ No newline at end of file diff --git a/keyboards/keychron/q6_pro/ansi_encoder/rules.mk b/keyboards/keychron/q6_pro/ansi_encoder/rules.mk index 6e7633bfe015..027fcc849c5e 100755 --- a/keyboards/keychron/q6_pro/ansi_encoder/rules.mk +++ b/keyboards/keychron/q6_pro/ansi_encoder/rules.mk @@ -1 +1 @@ -# This file intentionally left blank +# This file intentionally left blankOPENRGB_ENABLE = yes \ No newline at end of file diff --git a/keyboards/keychron/q6_pro/info.json b/keyboards/keychron/q6_pro/info.json index 00cc833b29c7..33804d04e528 100755 --- a/keyboards/keychron/q6_pro/info.json +++ b/keyboards/keychron/q6_pro/info.json @@ -43,7 +43,8 @@ "solid_reactive_multiwide": true, "solid_reactive_multinexus": true, "splash": true, - "solid_splash": true + "solid_splash": true, + "openrgb_direct": true } }, "matrix_pins": { diff --git a/keyboards/keychron/q6_pro/q6_pro.c b/keyboards/keychron/q6_pro/q6_pro.c index bba69f32605b..360c6e67fb51 100755 --- a/keyboards/keychron/q6_pro/q6_pro.c +++ b/keyboards/keychron/q6_pro/q6_pro.c @@ -332,3 +332,4 @@ void raw_hid_receive(uint8_t *data, uint8_t length) { } } #endif + diff --git a/keyboards/keychron/q6_pro/q6_pro.h b/keyboards/keychron/q6_pro/q6_pro.h index 9cc6693d4dc6..e5bf76b8b675 100755 --- a/keyboards/keychron/q6_pro/q6_pro.h +++ b/keyboards/keychron/q6_pro/q6_pro.h @@ -17,6 +17,7 @@ #pragma once #include "quantum.h" + #ifdef VIA_ENABLE # include "via.h" #endif diff --git a/keyboards/keychron/q6_pro/rules.mk b/keyboards/keychron/q6_pro/rules.mk index 1f9fc1ab58ea..b1928a8aa8d3 100755 --- a/keyboards/keychron/q6_pro/rules.mk +++ b/keyboards/keychron/q6_pro/rules.mk @@ -1,4 +1,5 @@ # Enter lower-power sleep mode when on the ChibiOS idle thread + OPT_DEFS += -DCORTEX_ENABLE_WFI_IDLE=TRUE OPT_DEFS += -DNO_USB_STARTUP_CHECK -DENABLE_FACTORY_TEST diff --git a/quantum/openrgb.c b/quantum/openrgb.c new file mode 100644 index 000000000000..7c150e7741c8 --- /dev/null +++ b/quantum/openrgb.c @@ -0,0 +1,370 @@ +/* Copyright 2020 Kasper + * + * 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 . + */ + +#ifndef RAW_ENABLE +# error "RAW_ENABLE is not enabled" +#endif + +#include "version.h" +#include "quantum.h" +#include "openrgb.h" +#include "raw_hid.h" +#include "string.h" +#include + +#if !defined(OPENRGB_DIRECT_MODE_STARTUP_RED) +# define OPENRGB_DIRECT_MODE_STARTUP_RED 0 +#endif + +#if !defined(OPENRGB_DIRECT_MODE_STARTUP_GREEN) +# define OPENRGB_DIRECT_MODE_STARTUP_GREEN 0 +#endif + +#if !defined(OPENRGB_DIRECT_MODE_STARTUP_BLUE) +# define OPENRGB_DIRECT_MODE_STARTUP_BLUE 255 +#endif + +RGB g_openrgb_direct_mode_colors[RGB_MATRIX_LED_COUNT] = {[0 ... RGB_MATRIX_LED_COUNT - 1] = {OPENRGB_DIRECT_MODE_STARTUP_GREEN, OPENRGB_DIRECT_MODE_STARTUP_RED, OPENRGB_DIRECT_MODE_STARTUP_BLUE}}; +static const uint8_t openrgb_rgb_matrix_effects_indexes[] = { + 1, 2, + +#ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS + 3, +#endif +#ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN + 4, +#endif +#ifndef DISABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT + 5, +#endif +#ifndef DISABLE_RGB_MATRIX_BREATHING + 6, +#endif +#ifndef DISABLE_RGB_MATRIX_BAND_SAT + 7, +#endif +#ifndef DISABLE_RGB_MATRIX_BAND_VAL + 8, +#endif +#ifndef DISABLE_RGB_MATRIX_BAND_PINWHEEL_SAT + 9, +#endif +#ifndef DISABLE_RGB_MATRIX_BAND_PINWHEEL_VAL + 10, +#endif +#ifndef DISABLE_RGB_MATRIX_BAND_SPIRAL_SAT + 11, +#endif +#ifndef DISABLE_RGB_MATRIX_BAND_SPIRAL_VAL + 12, +#endif +#ifndef DISABLE_RGB_MATRIX_CYCLE_ALL + 13, +#endif +#ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT + 14, +#endif +#ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN + 15, +#endif +#ifndef DISABLE_RGB_MATRIX_CYCLE_OUT_IN + 16, +#endif +#ifndef DISABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL + 17, +#endif +#ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON + 18, +#endif +#ifndef DISABLE_RGB_MATRIX_CYCLE_PINWHEEL + 19, +#endif +#ifndef DISABLE_RGB_MATRIX_CYCLE_SPIRAL + 20, +#endif +#ifndef DISABLE_RGB_MATRIX_DUAL_BEACON + 21, +#endif +#ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON + 22, +#endif +#ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS + 23, +#endif +#ifndef DISABLE_RGB_MATRIX_RAINDROPS + 24, +#endif +#ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS + 25, +#endif +#ifndef DISABLE_RGB_MATRIX_HUE_BREATHING + 26, +#endif +#ifndef DISABLE_RGB_MATRIX_HUE_PENDULUM + 27, +#endif +#ifndef DISABLE_RGB_MATRIX_HUE_WAVE + 28, +#endif +#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP) + 29, +#endif +#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN) + 30, +#endif +#if defined RGB_MATRIX_KEYREACTIVE_ENABLED && !defined DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE + 31, +#endif +#if defined RGB_MATRIX_KEYREACTIVE_ENABLED && !defined DISABLE_RGB_MATRIX_SOLID_REACTIVE + 32, +#endif +#if defined RGB_MATRIX_KEYREACTIVE_ENABLED && !defined DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE + 33, +#endif +#if defined RGB_MATRIX_KEYREACTIVE_ENABLED && !defined DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE + 34, +#endif +#if defined RGB_MATRIX_KEYREACTIVE_ENABLED && !defined DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS + 35, +#endif +#if defined RGB_MATRIX_KEYREACTIVE_ENABLED && !defined DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS + 36, +#endif +#if defined RGB_MATRIX_KEYREACTIVE_ENABLED && !defined DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS + 37, +#endif +#if defined RGB_MATRIX_KEYREACTIVE_ENABLED && !defined DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS + 38, +#endif +#if defined RGB_MATRIX_KEYREACTIVE_ENABLED && !defined DISABLE_RGB_MATRIX_SPLASH + 39, +#endif +#if defined RGB_MATRIX_KEYREACTIVE_ENABLED && !defined DISABLE_RGB_MATRIX_MULTISPLASH + 40, +#endif +#if defined RGB_MATRIX_KEYREACTIVE_ENABLED && !defined DISABLE_RGB_MATRIX_SOLID_SPLASH + 41, +#endif +#if defined RGB_MATRIX_KEYREACTIVE_ENABLED && !defined DISABLE_RGB_MATRIX_SOLID_MULTISPLASH + 42, +#endif +}; +static uint8_t raw_hid_buffer[RAW_EPSIZE]; + +uint8_t is_orgb_mode = 1; + +void orgb_raw_hid_receive(uint8_t *data, uint8_t length) { + switch (*data) { + case OPENRGB_GET_PROTOCOL_VERSION: + openrgb_get_protocol_version(); + break; + case OPENRGB_GET_QMK_VERSION: + openrgb_get_qmk_version(); + break; + case OPENRGB_GET_DEVICE_INFO: + openrgb_get_device_info(); + break; + case OPENRGB_GET_MODE_INFO: + openrgb_get_mode_info(); + break; + case OPENRGB_GET_LED_INFO: + openrgb_get_led_info(data); + break; + case OPENRGB_GET_ENABLED_MODES: + openrgb_get_enabled_modes(); + break; + + case OPENRGB_SET_MODE: + openrgb_set_mode(data); + break; + case OPENRGB_DIRECT_MODE_SET_SINGLE_LED: + openrgb_direct_mode_set_single_led(data); + break; + case OPENRGB_DIRECT_MODE_SET_LEDS: + openrgb_direct_mode_set_leds(data); + break; + } + + if (*data != OPENRGB_DIRECT_MODE_SET_LEDS) { + raw_hid_buffer[RAW_EPSIZE - 1] = OPENRGB_END_OF_MESSAGE; + raw_hid_send(raw_hid_buffer, RAW_EPSIZE); + memset(raw_hid_buffer, 0x00, RAW_EPSIZE); + } +} + +void openrgb_get_protocol_version(void) { + raw_hid_buffer[0] = OPENRGB_GET_PROTOCOL_VERSION; + raw_hid_buffer[1] = OPENRGB_PROTOCOL_VERSION; +} +void openrgb_get_qmk_version(void) { + raw_hid_buffer[0] = OPENRGB_GET_QMK_VERSION; + uint8_t current_byte = 1; + for (uint8_t i = 0; (current_byte < (RAW_EPSIZE - 2)) && (QMK_VERSION[i] != 0); i++) { + raw_hid_buffer[current_byte] = QMK_VERSION[i]; + current_byte++; + } +} +void openrgb_get_device_info(void) { + raw_hid_buffer[0] = OPENRGB_GET_DEVICE_INFO; + raw_hid_buffer[1] = RGB_MATRIX_LED_COUNT; + raw_hid_buffer[2] = MATRIX_COLS * MATRIX_ROWS; + +#define MASSDROP_VID 0x04D8 +#if VENDOR_ID == MASSDROP_VID +# define PRODUCT_STRING PRODUCT +# define MANUFACTURER_STRING MANUFACTURER +#else +# define PRODUCT_STRING STR(PRODUCT) +# define MANUFACTURER_STRING STR(MANUFACTURER) +#endif + + uint8_t current_byte = 3; + for (uint8_t i = 0; (current_byte < ((RAW_EPSIZE - 2) / 2)) && (PRODUCT_STRING[i] != 0); i++) { + raw_hid_buffer[current_byte] = PRODUCT_STRING[i]; + current_byte++; + } + raw_hid_buffer[current_byte] = 0; + current_byte++; + + for (uint8_t i = 0; (current_byte + 2 < RAW_EPSIZE) && (MANUFACTURER_STRING[i] != 0); i++) { + raw_hid_buffer[current_byte] = MANUFACTURER_STRING[i]; + current_byte++; + } +} +void openrgb_get_mode_info(void) { + const HSV hsv_color = rgb_matrix_get_hsv(); + + raw_hid_buffer[0] = OPENRGB_GET_MODE_INFO; + raw_hid_buffer[1] = rgb_matrix_get_mode(); + raw_hid_buffer[2] = rgb_matrix_get_speed(); + raw_hid_buffer[3] = hsv_color.h; + raw_hid_buffer[4] = hsv_color.s; + raw_hid_buffer[5] = hsv_color.v; +} +void openrgb_get_led_info(uint8_t *data) { + const uint8_t first_led = data[1]; + const uint8_t number_leds = data[2]; + + raw_hid_buffer[0] = OPENRGB_GET_LED_INFO; + + for (uint8_t i = 0; i < number_leds; i++) { + const uint8_t led_idx = first_led + i; + const uint8_t data_idx = i * 7; + + if (led_idx >= RGB_MATRIX_LED_COUNT) { + raw_hid_buffer[data_idx + 3] = OPENRGB_FAILURE; + } else { + raw_hid_buffer[data_idx + 1] = g_led_config.point[led_idx].x; + raw_hid_buffer[data_idx + 2] = g_led_config.point[led_idx].y; + raw_hid_buffer[data_idx + 3] = g_led_config.flags[led_idx]; + raw_hid_buffer[data_idx + 4] = g_openrgb_direct_mode_colors[led_idx].r; + raw_hid_buffer[data_idx + 5] = g_openrgb_direct_mode_colors[led_idx].g; + raw_hid_buffer[data_idx + 6] = g_openrgb_direct_mode_colors[led_idx].b; + } + + uint8_t row = 0; + uint8_t col = 0; + uint8_t found = 0; + + for (row = 0; row < MATRIX_ROWS; row++) { + for (col = 0; col < MATRIX_COLS; col++) { + if (g_led_config.matrix_co[row][col] == led_idx) { + found = 1; + break; + } + } + + if (found == 1) { + break; + } + } + + if (col >= MATRIX_COLS || row >= MATRIX_ROWS) { + raw_hid_buffer[data_idx + 7] = KC_NO; + } + else { + raw_hid_buffer[data_idx + 7] = keycode_at_keymap_location(0, row, col); + } + } +} +void openrgb_get_enabled_modes(void) { + raw_hid_buffer[0] = OPENRGB_GET_ENABLED_MODES; + const uint8_t size = sizeof openrgb_rgb_matrix_effects_indexes / sizeof openrgb_rgb_matrix_effects_indexes[0]; + for (int i = 0; i < size; i++) { + raw_hid_buffer[i + 1] = openrgb_rgb_matrix_effects_indexes[i]; + } +} + +void openrgb_set_mode(uint8_t *data) { + const uint8_t h = data[1]; + const uint8_t s = data[2]; + const uint8_t v = data[3]; + const uint8_t mode = data[4]; + const uint8_t speed = data[5]; + const uint8_t save = data[6]; + + raw_hid_buffer[0] = OPENRGB_SET_MODE; + + if (h > 255 || s > 255 || v > 255 || mode >= RGB_MATRIX_EFFECT_MAX || speed > 255) { + raw_hid_buffer[RAW_EPSIZE - 2] = OPENRGB_FAILURE; + return; + } + + if (save == 1) { + rgb_matrix_mode(mode); + rgb_matrix_set_speed(speed); + rgb_matrix_sethsv(h, s, v); + } + else { + rgb_matrix_mode_noeeprom(mode); + rgb_matrix_set_speed_noeeprom(speed); + rgb_matrix_sethsv_noeeprom(h, s, v); + } + + raw_hid_buffer[RAW_EPSIZE - 2] = OPENRGB_SUCCESS; +} +void openrgb_direct_mode_set_single_led(uint8_t *data) { + const uint8_t led = data[1]; + const uint8_t r = data[2]; + const uint8_t g = data[3]; + const uint8_t b = data[4]; + + raw_hid_buffer[0] = OPENRGB_DIRECT_MODE_SET_SINGLE_LED; + + if (led >= RGB_MATRIX_LED_COUNT || r > 255 || g > 255 || b > 255) { + raw_hid_buffer[RAW_EPSIZE - 2] = OPENRGB_FAILURE; + return; + } + + g_openrgb_direct_mode_colors[led].r = r; + g_openrgb_direct_mode_colors[led].g = g; + g_openrgb_direct_mode_colors[led].b = b; + + raw_hid_buffer[RAW_EPSIZE - 2] = OPENRGB_SUCCESS; +} +void openrgb_direct_mode_set_leds(uint8_t *data) { + const uint8_t first_led = data[1]; + const uint8_t number_leds = data[2]; + + for (uint8_t i = 0; i < number_leds; i++) { + const uint8_t color_idx = first_led + i; + const uint8_t data_idx = i * 3; + + g_openrgb_direct_mode_colors[color_idx].r = data[data_idx + 3]; + g_openrgb_direct_mode_colors[color_idx].g = data[data_idx + 4]; + g_openrgb_direct_mode_colors[color_idx].b = data[data_idx + 5]; + } +} \ No newline at end of file diff --git a/quantum/openrgb.h b/quantum/openrgb.h new file mode 100644 index 000000000000..86773bde3cc4 --- /dev/null +++ b/quantum/openrgb.h @@ -0,0 +1,55 @@ +/* Copyright 2020 Kasper + * + * 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 . + */ + +#pragma once + +// This is changed only when the command IDs change, +// so OpenRGB can detect compatible firmware. +#define OPENRGB_PROTOCOL_VERSION 0xC + +#define RAW_EPSIZE 64 + +enum openrgb_command_id { + OPENRGB_GET_PROTOCOL_VERSION = 1, + OPENRGB_GET_QMK_VERSION, + OPENRGB_GET_DEVICE_INFO, + OPENRGB_GET_MODE_INFO, + OPENRGB_GET_LED_INFO, + OPENRGB_GET_ENABLED_MODES, + + OPENRGB_SET_MODE, + OPENRGB_DIRECT_MODE_SET_SINGLE_LED, + OPENRGB_DIRECT_MODE_SET_LEDS, +}; + +enum openrgb_responses { + OPENRGB_FAILURE = 25, + OPENRGB_SUCCESS = 50, + OPENRGB_END_OF_MESSAGE = 100, +}; + +extern RGB g_openrgb_direct_mode_colors[RGB_MATRIX_LED_COUNT]; + +void openrgb_get_protocol_version(void); +void openrgb_get_qmk_version(void); +void openrgb_get_device_info(void); +void openrgb_get_mode_info(void); +void openrgb_get_led_info(uint8_t *data); +void openrgb_get_enabled_modes(void); + +void openrgb_set_mode(uint8_t *data); +void openrgb_direct_mode_set_single_led(uint8_t *data); +void openrgb_direct_mode_set_leds(uint8_t *data); diff --git a/quantum/quantum.h b/quantum/quantum.h index 315fa2556882..542d2d4632fb 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -212,6 +212,10 @@ extern layer_state_t layer_state; # include "digitizer.h" #endif +#ifdef OPENRGB_ENABLE +# include "openrgb.h" +#endif + #ifdef VIA_ENABLE # include "via.h" #endif diff --git a/quantum/rgb_matrix/animations/openrgb_direct_anim.h b/quantum/rgb_matrix/animations/openrgb_direct_anim.h new file mode 100644 index 000000000000..87c3462e0457 --- /dev/null +++ b/quantum/rgb_matrix/animations/openrgb_direct_anim.h @@ -0,0 +1,29 @@ +#ifdef OPENRGB_ENABLE +RGB_MATRIX_EFFECT(OPENRGB_DIRECT) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +bool OPENRGB_DIRECT(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + for (uint8_t i = led_min; i < led_max; i++) { + #ifdef OPENRGB_DIRECT_MODE_USE_UNIVERSAL_BRIGHTNESS + float brightness = (float)rgb_matrix_config.hsv.v / UINT8_MAX; + rgb_matrix_set_color( + i, + brightness * g_openrgb_direct_mode_colors[i].r, + brightness * g_openrgb_direct_mode_colors[i].g, + brightness * g_openrgb_direct_mode_colors[i].b + ); + #else + rgb_matrix_set_color( + i, + g_openrgb_direct_mode_colors[i].r, + g_openrgb_direct_mode_colors[i].g, + g_openrgb_direct_mode_colors[i].b + ); + #endif + } + return led_max < RGB_MATRIX_LED_COUNT; +} +# endif +#endif \ No newline at end of file diff --git a/quantum/rgb_matrix/animations/rgb_matrix_effects.inc b/quantum/rgb_matrix/animations/rgb_matrix_effects.inc index ac7bac428d1e..598b95e730c6 100644 --- a/quantum/rgb_matrix/animations/rgb_matrix_effects.inc +++ b/quantum/rgb_matrix/animations/rgb_matrix_effects.inc @@ -38,3 +38,4 @@ #include "solid_reactive_nexus.h" #include "splash_anim.h" #include "solid_splash_anim.h" +#include "openrgb_direct_anim.h" \ No newline at end of file diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c index 429ad81762b4..02871abbdd62 100644 --- a/quantum/rgb_matrix/rgb_matrix.c +++ b/quantum/rgb_matrix/rgb_matrix.c @@ -81,11 +81,15 @@ __attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { #endif #if !defined(RGB_MATRIX_DEFAULT_MODE) -# ifdef ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT -# define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT +# ifdef OPENRGB_ENABLE +# define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_OPENRGB_DIRECT # else +# ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT +# define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT +# else // fallback to solid colors if RGB_MATRIX_CYCLE_LEFT_RIGHT is disabled in userspace -# define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_SOLID_COLOR +# define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_SOLID_COLOR +# endif # endif #endif diff --git a/quantum/via.c b/quantum/via.c index 4631423a7f9a..a8455adfc8ad 100644 --- a/quantum/via.c +++ b/quantum/via.c @@ -243,7 +243,24 @@ __attribute__((weak)) bool via_command_kb(uint8_t *data, uint8_t length) { return false; } +#ifdef OPENRGB_ENABLE +extern uint8_t is_orgb_mode; +extern void orgb_raw_hid_receive(uint8_t *data, uint8_t length); +#endif + void raw_hid_receive(uint8_t *data, uint8_t length) { + +// NEW begin + +#ifdef OPENRGB_ENABLE + if (is_orgb_mode) { + orgb_raw_hid_receive(data, length); + return; + } +#endif + +// NEW end + uint8_t *command_id = &(data[0]); uint8_t *command_data = &(data[1]); diff --git a/tmk_core/protocol/arm_atsam/usb/udi_device_epsize.h b/tmk_core/protocol/arm_atsam/usb/udi_device_epsize.h index 7a9ed3193001..7a85d53cd3d7 100644 --- a/tmk_core/protocol/arm_atsam/usb/udi_device_epsize.h +++ b/tmk_core/protocol/arm_atsam/usb/udi_device_epsize.h @@ -21,7 +21,7 @@ along with this program. If not, see . #define KEYBOARD_EPSIZE 8 #define MOUSE_EPSIZE 8 #define EXTRAKEY_EPSIZE 8 -#define RAW_EPSIZE 32 +#define RAW_EPSIZE 64 #define CONSOLE_EPSIZE 32 #define NKRO_EPSIZE 32 #define MIDI_STREAM_EPSIZE 64 diff --git a/tmk_core/protocol/usb_descriptor.h b/tmk_core/protocol/usb_descriptor.h index ed84f4c9ab55..1f3260c119cc 100644 --- a/tmk_core/protocol/usb_descriptor.h +++ b/tmk_core/protocol/usb_descriptor.h @@ -300,7 +300,7 @@ enum usb_endpoints { #define KEYBOARD_EPSIZE 8 #define SHARED_EPSIZE 32 #define MOUSE_EPSIZE 8 -#define RAW_EPSIZE 32 +#define RAW_EPSIZE 64 #define CONSOLE_EPSIZE 32 #define MIDI_STREAM_EPSIZE 64 #define CDC_NOTIFICATION_EPSIZE 8