diff --git a/builddefs/common_features.mk b/builddefs/common_features.mk
index b7cb2193fa..286364d5cc 100644
--- a/builddefs/common_features.mk
+++ b/builddefs/common_features.mk
@@ -644,6 +644,15 @@ ifeq ($(strip $(VIA_ENABLE)), yes)
endif
endif
+ifeq ($(strip $(OPENRGB_ENABLE)), yes)
+ ifeq ($(strip $(VIA_ENABLE)), yes)
+ $(error OPENRGB_ENABLE and VIA_ENABLE cannot currently be enabled simultaneously)
+ endif
+ RAW_ENABLE := yes
+ SRC += $(QUANTUM_DIR)/openrgb.c
+ OPT_DEFS += -DOPENRGB_ENABLE
+endif
+
ifeq ($(strip $(RAW_ENABLE)), yes)
OPT_DEFS += -DRAW_ENABLE
SRC += raw_hid.c
diff --git a/builddefs/show_options.mk b/builddefs/show_options.mk
index 1c1a3ebf8e..5df0b26b84 100644
--- a/builddefs/show_options.mk
+++ b/builddefs/show_options.mk
@@ -10,7 +10,8 @@ BUILD_OPTION_NAMES = \
SPLIT_KEYBOARD \
DYNAMIC_KEYMAP_ENABLE \
USB_HID_ENABLE \
- VIA_ENABLE
+ VIA_ENABLE \
+ OPENRGB_ENABLE
HARDWARE_OPTION_NAMES = \
SLEEP_LED_ENABLE \
diff --git a/quantum/openrgb.c b/quantum/openrgb.c
new file mode 100644
index 0000000000..38d2e5b810
--- /dev/null
+++ b/quantum/openrgb.c
@@ -0,0 +1,367 @@
+/* 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[DRIVER_LED_TOTAL] = {[0 ... DRIVER_LED_TOTAL - 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];
+
+void 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] = DRIVER_LED_TOTAL;
+ 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 >= DRIVER_LED_TOTAL) {
+ 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] = pgm_read_byte(&keymaps[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 >= DRIVER_LED_TOTAL || 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 number_leds = data[1];
+
+ for (uint8_t i = 0; i < number_leds; i++) {
+ const uint8_t data_idx = i * 4;
+ const uint8_t color_idx = data[data_idx + 2];
+
+ 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];
+ }
+}
diff --git a/quantum/openrgb.h b/quantum/openrgb.h
new file mode 100644
index 0000000000..8dd7300b96
--- /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[DRIVER_LED_TOTAL];
+
+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 176c8a292d..c7a41045d2 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -203,6 +203,10 @@ extern layer_state_t layer_state;
# include "via.h"
#endif
+#ifdef OPENRGB_ENABLE
+# include "openrgb.h"
+#endif
+
#ifdef WPM_ENABLE
# include "wpm.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 0000000000..427e4c3862
--- /dev/null
+++ b/quantum/rgb_matrix/animations/openrgb_direct_anim.h
@@ -0,0 +1,19 @@
+#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 < DRIVER_LED_TOTAL;
+}
+# endif
+#endif
diff --git a/quantum/rgb_matrix/animations/rgb_matrix_effects.inc b/quantum/rgb_matrix/animations/rgb_matrix_effects.inc
index abc2adf2cc..2a771b4599 100644
--- a/quantum/rgb_matrix/animations/rgb_matrix_effects.inc
+++ b/quantum/rgb_matrix/animations/rgb_matrix_effects.inc
@@ -44,3 +44,4 @@
#include "starlight_dual_sat_anim.h"
#include "starlight_dual_hue_anim.h"
#include "riverflow_anim.h"
+#include "openrgb_direct_anim.h"