Add VIA support for QMK backlight, QMK RGBLight (#7911)

* Add VIA support for QMK backlight, QMK RGBLight

* clang-format changes
This commit is contained in:
Wilba
2020-01-21 05:18:25 +11:00
committed by MechMerlin
parent ce81c4f89b
commit 484a9b12bc
37 changed files with 500 additions and 35 deletions

View File

@@ -62,6 +62,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 1
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE
// Let VIA handle the QMK RGBLIGHT
#define VIA_QMK_RGBLIGHT_ENABLE
/*
* Feature disable options
* These options are also useful to firmware size reduction.

View File

@@ -62,6 +62,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 1
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE
// Let VIA handle the QMK RGBLIGHT
#define VIA_QMK_RGBLIGHT_ENABLE
/*
* Feature disable options
* These options are also useful to firmware size reduction.

View File

@@ -54,6 +54,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 1
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE
/*
* Feature disable options
* These options are also useful to firmware size reduction.

View File

@@ -73,6 +73,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// 6 for 3x custom encoder settings, left, right, and press (18 bytes)
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 21
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE
/*
* Feature disable options
* These options are also useful to firmware size reduction.

View File

@@ -3,3 +3,5 @@
void backlight_task(void);
void breathing_interrupt_disable(void);
void breathing_interrupt_enable(void);
void breathing_enable(void);
void breathing_disable(void);

View File

@@ -55,6 +55,54 @@ backlight_config_t kb_backlight_config = {
};
#ifdef VIA_ENABLE
void backlight_get_value( uint8_t *data )
{
uint8_t *value_id = &(data[0]);
uint8_t *value_data = &(data[1]);
switch (*value_id)
{
case id_qmk_backlight_brightness:
{
// level / BACKLIGHT_LEVELS * 255
value_data[0] = ((uint16_t)kb_backlight_config.level) * 255 / BACKLIGHT_LEVELS;
break;
}
case id_qmk_backlight_effect:
{
value_data[0] = kb_backlight_config.breathing ? 1 : 0;
break;
}
}
}
void backlight_set_value( uint8_t *data )
{
uint8_t *value_id = &(data[0]);
uint8_t *value_data = &(data[1]);
switch (*value_id)
{
case id_qmk_backlight_brightness:
{
// level / 255 * BACKLIGHT_LEVELS
kb_backlight_config.level = ((uint16_t)value_data[0]) * BACKLIGHT_LEVELS / 255;
backlight_set(kb_backlight_config.level);
break;
}
case id_qmk_backlight_effect:
{
if ( value_data[0] == 0 ) {
kb_backlight_config.breathing = false;
breathing_disable();
} else {
kb_backlight_config.breathing = true;
breathing_enable();
}
break;
}
}
}
void raw_hid_receive_kb( uint8_t *data, uint8_t length )
{
uint8_t *command_id = &(data[0]);
@@ -139,6 +187,21 @@ void raw_hid_receive_kb( uint8_t *data, uint8_t length )
}
break;
}
case id_lighting_set_value:
{
backlight_set_value(command_data);
break;
}
case id_lighting_get_value:
{
backlight_get_value(command_data);
break;
}
case id_lighting_save:
{
backlight_config_save();
break;
}
default:
{
// Unhandled message.

View File

@@ -62,6 +62,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 1
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE
// Let VIA handle the QMK RGBLIGHT
#define VIA_QMK_RGBLIGHT_ENABLE
/*
* Feature disable options
* These options are also useful to firmware size reduction.

View File

@@ -126,8 +126,86 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
return process_record_user(keycode, record);;
}
#ifdef VIA_ENABLE
void backlight_get_value( uint8_t *data )
{
uint8_t *value_id = &(data[0]);
uint8_t *value_data = &(data[1]);
switch (*value_id)
{
case id_qmk_backlight_brightness:
{
// level / BACKLIGHT_LEVELS * 255
value_data[0] = ((uint16_t)kb_backlight_config.level) * 255 / BACKLIGHT_LEVELS;
break;
}
case id_qmk_backlight_effect:
{
value_data[0] = kb_backlight_config.breathing ? 1 : 0;
break;
}
}
}
void backlight_set_value( uint8_t *data )
{
uint8_t *value_id = &(data[0]);
uint8_t *value_data = &(data[1]);
switch (*value_id)
{
case id_qmk_backlight_brightness:
{
// level / 255 * BACKLIGHT_LEVELS
kb_backlight_config.level = ((uint16_t)value_data[0]) * BACKLIGHT_LEVELS / 255;
backlight_set(kb_backlight_config.level);
break;
}
case id_qmk_backlight_effect:
{
if ( value_data[0] == 0 ) {
kb_backlight_config.breathing = false;
breathing_disable();
} else {
kb_backlight_config.breathing = true;
breathing_enable();
}
break;
}
}
}
void raw_hid_receive_kb( uint8_t *data, uint8_t length )
{
uint8_t *command_id = &(data[0]);
uint8_t *command_data = &(data[1]);
switch ( *command_id )
{
case id_lighting_set_value:
{
backlight_set_value(command_data);
break;
}
case id_lighting_get_value:
{
backlight_get_value(command_data);
break;
}
case id_lighting_save:
{
backlight_config_save();
break;
}
default:
{
// Unhandled message.
*command_id = id_unhandled;
break;
}
}
// DO NOT call raw_hid_send(data,length) here, let caller do this
}
#endif
//
// In the case of VIA being disabled, we still need to check if

View File

@@ -4,3 +4,5 @@ void backlight_task(void);
void breathing_interrupt_disable(void);
void breathing_interrupt_enable(void);
void breathing_toggle(void);
void breathing_enable(void);
void breathing_disable(void);

View File

@@ -62,6 +62,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 1
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE
// Let VIA handle the QMK RGBLIGHT
#define VIA_QMK_RGBLIGHT_ENABLE
/*
* Feature disable options
* These options are also useful to firmware size reduction.

View File

@@ -138,3 +138,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 31
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE

View File

@@ -141,3 +141,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Backlight config starts after VIA's EEPROM usage,
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 31
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE

View File

@@ -62,6 +62,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 1
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE
// Let VIA handle the QMK RGBLIGHT
#define VIA_QMK_RGBLIGHT_ENABLE
/*
* Feature disable options
* These options are also useful to firmware size reduction.

View File

@@ -121,4 +121,7 @@
// Backlight config starts after VIA's EEPROM usage,
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 31
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 31
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE

View File

@@ -119,3 +119,6 @@
// Backlight config starts after VIA's EEPROM usage,
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 31
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE

View File

@@ -109,3 +109,6 @@
// Backlight config starts after VIA's EEPROM usage,
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 43
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE

View File

@@ -152,3 +152,6 @@
// Backlight config starts after VIA's EEPROM usage,
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 43
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE

View File

@@ -235,3 +235,6 @@
// Backlight config starts after VIA's EEPROM usage,
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 31
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE

View File

@@ -204,3 +204,5 @@
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 7
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE

View File

@@ -201,3 +201,5 @@
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 7
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE

View File

@@ -201,3 +201,5 @@
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 7
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE

View File

@@ -204,3 +204,5 @@
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 7
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE

View File

@@ -204,3 +204,5 @@
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 7
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE

View File

@@ -204,3 +204,5 @@
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 7
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE

View File

@@ -200,3 +200,6 @@
// Backlight config starts after VIA's EEPROM usage,
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 7
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE

View File

@@ -123,17 +123,17 @@ void raw_hid_receive_kb(uint8_t *data, uint8_t length) {
switch ( *command_id )
{
#if RGB_BACKLIGHT_ENABLED || MONO_BACKLIGHT_ENABLED
case id_backlight_config_set_value:
case id_lighting_set_value:
{
backlight_config_set_value(command_data);
break;
}
case id_backlight_config_get_value:
case id_lighting_get_value:
{
backlight_config_get_value(command_data);
break;
}
case id_backlight_config_save:
case id_lighting_save:
{
backlight_config_save();
break;

View File

@@ -26,9 +26,13 @@
#include "quantum/color.h"
#include "tmk_core/common/eeprom.h"
#include "via.h" // uses only the EEPROM address
#include "via.h" // uses EEPROM address, lighting value IDs
#define MONO_BACKLIGHT_CONFIG_EEPROM_ADDR (VIA_EEPROM_CUSTOM_CONFIG_ADDR)
#if VIA_EEPROM_CUSTOM_CONFIG_SIZE == 0
#error VIA_EEPROM_CUSTOM_CONFIG_SIZE was not defined to store backlight_config struct
#endif
#include "drivers/issi/is31fl3736.h"
#define ISSI_ADDR_DEFAULT 0x50

View File

@@ -50,9 +50,13 @@ LED_TYPE g_ws2812_leds[WS2812_LED_TOTAL];
#include "quantum/color.h"
#include "tmk_core/common/eeprom.h"
#include "via.h" // uses only the EEPROM address
#include "via.h" // uses EEPROM address, lighting value IDs
#define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR (VIA_EEPROM_CUSTOM_CONFIG_ADDR)
#if VIA_EEPROM_CUSTOM_CONFIG_SIZE == 0
#error VIA_EEPROM_CUSTOM_CONFIG_SIZE was not defined to store backlight_config struct
#endif
#if defined(RGB_BACKLIGHT_M6_B)
#include "drivers/issi/is31fl3218.h"
#define BACKLIGHT_LED_COUNT 6

View File

@@ -117,4 +117,7 @@
// Backlight config starts after VIA's EEPROM usage,
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 31
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 31
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE

View File

@@ -118,3 +118,6 @@
// Backlight config starts after VIA's EEPROM usage,
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 31
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE

View File

@@ -140,3 +140,6 @@
// Backlight config starts after VIA's EEPROM usage,
// dynamic keymaps start after this.
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 31
// VIA lighting is handled by the keyboard-level code
#define VIA_CUSTOM_LIGHTING_ENABLE