mirror of
https://github.com/zsa/qmk_firmware.git
synced 2026-01-08 22:52:28 +00:00
feat: allows to take over the rgb leds and light them individually from raw hid
This commit is contained in:
26
keyboards/moonlander/rgb_matrix_kb.inc
Normal file
26
keyboards/moonlander/rgb_matrix_kb.inc
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifdef RGB_MATRIX_ENABLE
|
||||
RGB_MATRIX_EFFECT(oryx_webhid_effect)
|
||||
# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
|
||||
|
||||
static void oryx_webhid_effect_init(void) {
|
||||
// Paint it black
|
||||
for (uint8_t i = 0; i < DRIVER_LED_TOTAL; ++i) {
|
||||
webhid_leds[i] = (RGB){0, 0, 0};
|
||||
}
|
||||
}
|
||||
|
||||
static bool oryx_webhid_effect_run(effect_params_t* params) {
|
||||
RGB_MATRIX_USE_LIMITS(led_min, led_max);
|
||||
for (uint8_t i = led_min; i < led_max; ++i) {
|
||||
rgb_matrix_set_color(i, webhid_leds[i].r, webhid_leds[i].g, webhid_leds[i].b);
|
||||
}
|
||||
return rgb_matrix_check_finished_leds(led_max);
|
||||
}
|
||||
|
||||
static bool oryx_webhid_effect(effect_params_t* params) {
|
||||
if (params->init) oryx_webhid_effect_init();
|
||||
return oryx_webhid_effect_run(params);
|
||||
}
|
||||
|
||||
# endif
|
||||
#endif
|
||||
26
keyboards/planck/ez/rgb_matrix_kb.inc
Normal file
26
keyboards/planck/ez/rgb_matrix_kb.inc
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifdef RGB_MATRIX_ENABLE
|
||||
RGB_MATRIX_EFFECT(oryx_webhid_effect)
|
||||
# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
|
||||
|
||||
static void oryx_webhid_effect_init(void) {
|
||||
// Paint it black
|
||||
for (uint8_t i = 0; i < DRIVER_LED_TOTAL; ++i) {
|
||||
webhid_leds[i] = (RGB){0, 0, 0};
|
||||
}
|
||||
}
|
||||
|
||||
static bool oryx_webhid_effect_run(effect_params_t* params) {
|
||||
RGB_MATRIX_USE_LIMITS(led_min, led_max);
|
||||
for (uint8_t i = led_min; i < led_max; ++i) {
|
||||
rgb_matrix_set_color(i, webhid_leds[i].r, webhid_leds[i].g, webhid_leds[i].b);
|
||||
}
|
||||
return rgb_matrix_check_finished_leds(led_max);
|
||||
}
|
||||
|
||||
static bool oryx_webhid_effect(effect_params_t* params) {
|
||||
if (params->init) oryx_webhid_effect_init();
|
||||
return oryx_webhid_effect_run(params);
|
||||
}
|
||||
|
||||
# endif
|
||||
#endif
|
||||
@@ -8,6 +8,13 @@ keypos_t keyboard_pairing_sequence[PAIRING_SEQUENCE_SIZE];
|
||||
keypos_t host_pairing_sequence[PAIRING_SEQUENCE_SIZE];
|
||||
uint8_t pairing_input_index = 0;
|
||||
|
||||
void oryx_error(uint8_t code) {
|
||||
uint8_t event[RAW_EPSIZE];
|
||||
event[0] = ORYX_EVT_ERROR;
|
||||
event[1] = code;
|
||||
raw_hid_send(event, RAW_EPSIZE);
|
||||
}
|
||||
|
||||
void raw_hid_receive(uint8_t *data, uint8_t length) {
|
||||
uint8_t command = data[0];
|
||||
uint8_t *param = &data[1];
|
||||
@@ -45,11 +52,33 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
|
||||
break;
|
||||
|
||||
case ORYX_SET_LAYER:
|
||||
if(rawhid_state.paired == true) {
|
||||
if (rawhid_state.paired == true) {
|
||||
layer_clear();
|
||||
layer_on(param[0]);
|
||||
}
|
||||
break;
|
||||
|
||||
case ORYX_RGB_CONTROL:
|
||||
#if defined(RGB_MATRIX_ENABLE) && !defined(KEYBOARD_ergodox_ez_glow)
|
||||
if (param[0] == 0) {
|
||||
rgb_matrix_reload_from_eeprom();
|
||||
rawhid_state.rgb_control = false;
|
||||
} else {
|
||||
rgb_matrix_mode_noeeprom(RGB_MATRIX_CUSTOM_oryx_webhid_effect);
|
||||
rawhid_state.rgb_control = true;
|
||||
}
|
||||
#else
|
||||
oryx_error(ORYX_ERR_RGB_MATRIX_NOT_ENABLED);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case ORYX_SET_RGB_LED:
|
||||
#if defined(RGB_MATRIX_ENABLE) && !defined(KEYBOARD_ergodox_ez_glow)
|
||||
webhid_leds[param[0]] = (RGB){.r = param[1], .g = param[2], .b = param[3]};
|
||||
#else
|
||||
oryx_error(ORYX_ERR_RGB_MATRIX_NOT_ENABLED);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +151,6 @@ bool compare_sequences(keypos_t a[PAIRING_SEQUENCE_SIZE], keypos_t b[PAIRING_SEQ
|
||||
}
|
||||
|
||||
void pairing_validate_handler() {
|
||||
|
||||
uint8_t event[RAW_EPSIZE];
|
||||
bool valid = compare_sequences(keyboard_pairing_sequence, host_pairing_sequence);
|
||||
|
||||
@@ -153,6 +181,16 @@ keypos_t get_random_keypos(void) {
|
||||
}
|
||||
}
|
||||
|
||||
keypos_t *pairing_sequence(void) {
|
||||
// The pairing sequence is derived from Oryx's layout id declared
|
||||
// in the generated source config file with the FIRMWARE_VERSION define.
|
||||
keypos_t *sequence = (keypos_t *)&host_pairing_sequence[0];
|
||||
for (uint8_t i = 0; i < PAIRING_SEQUENCE_SIZE; i++) {
|
||||
}
|
||||
|
||||
return sequence;
|
||||
}
|
||||
|
||||
void create_pairing_code(void) {
|
||||
for (uint8_t i = 0; i < PAIRING_SEQUENCE_SIZE; i++) {
|
||||
keypos_t pos = get_random_keypos();
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
#pragma once
|
||||
/*
|
||||
The Oryx Webhid protocol
|
||||
|
||||
Each HID packet is a series of bytes. The first byte is the packet type is the command. The rest of the bytes are the params.
|
||||
|
||||
Before sending a packet, the host needs to be paired or should request a pairing code.
|
||||
|
||||
The pairing code is a sequence of key positions derived from Oryx's firmware version code stored in the FIRMWARE_VERSION define.
|
||||
|
||||
Once the host has paired, it can freely use the commands define in the Oryx_Command_Code enum for which the board will always respond with a Oryx_Event_Code or a Oryx_Error_Code.
|
||||
*/
|
||||
|
||||
#include "quantum.h"
|
||||
#include "raw_hid.h"
|
||||
@@ -10,6 +21,7 @@
|
||||
# define RAW_EPSIZE 32
|
||||
#endif
|
||||
|
||||
#define ORYX_PROTOCOL_VERSION = 0x01
|
||||
#define ORYX_STOP_BIT -2
|
||||
#define PAIRING_BLINK_STEPS 512
|
||||
#define PAIRING_BLINK_END PAIRING_BLINK_STEPS * 60
|
||||
@@ -22,7 +34,10 @@ enum Oryx_Command_Code {
|
||||
ORYX_CMD_PAIRING_INIT,
|
||||
ORYX_CMD_PAIRING_VALIDATE,
|
||||
ORYX_CMD_DISCONNECT,
|
||||
ORYX_SET_LAYER
|
||||
ORYX_SET_LAYER,
|
||||
ORYX_RGB_CONTROL,
|
||||
ORYX_SET_RGB_LED,
|
||||
ORYX_GET_PROTOCOL_VERSION = 0xFE,
|
||||
};
|
||||
|
||||
enum Oryx_Event_Code {
|
||||
@@ -34,6 +49,16 @@ enum Oryx_Event_Code {
|
||||
ORYX_EVT_LAYER,
|
||||
ORYX_EVT_KEYDOWN,
|
||||
ORYX_EVT_KEYUP,
|
||||
ORYX_EVT_GET_PROTOCOL_VERSION = 0XFE,
|
||||
ORYX_EVT_ERROR = 0xFF,
|
||||
};
|
||||
|
||||
enum Oryx_Error_Code {
|
||||
ORYX_ERR_PAIRING_INIT_FAILED,
|
||||
ORYX_ERR_PAIRING_INPUT_FAILED,
|
||||
ORYX_ERR_PAIRING_KEY_INPUT_FAILED,
|
||||
ORYX_ERR_PAIRING_FAILED,
|
||||
ORYX_ERR_RGB_MATRIX_NOT_ENABLED,
|
||||
};
|
||||
|
||||
extern bool oryx_state_live_training_enabled;
|
||||
@@ -41,23 +66,30 @@ extern bool oryx_state_live_training_enabled;
|
||||
typedef struct {
|
||||
bool pairing;
|
||||
bool paired;
|
||||
bool rgb_control;
|
||||
} rawhid_state_t;
|
||||
|
||||
extern rawhid_state_t rawhid_state;
|
||||
|
||||
void create_pairing_code(void);
|
||||
bool store_pairing_sequence(keypos_t* pairing_sequence);
|
||||
keypos_t get_random_keypos(void);
|
||||
void pairing_init_handler(void);
|
||||
void pairing_validate_handler(void);
|
||||
void pairing_validate_eeprom_handler(void);
|
||||
void pairing_init_event(void);
|
||||
bool compare_sequences(keypos_t a[PAIRING_SEQUENCE_SIZE], keypos_t b[PAIRING_SEQUENCE_SIZE]);
|
||||
void pairing_key_input_event(void);
|
||||
void pairing_failed_event(void);
|
||||
void pairing_succesful_event(void);
|
||||
void create_pairing_code(void);
|
||||
void oryx_error(uint8_t code);
|
||||
bool store_pairing_sequence(keypos_t* pairing_sequence);
|
||||
keypos_t get_random_keypos(void);
|
||||
void pairing_init_handler(void);
|
||||
void pairing_validate_handler(void);
|
||||
void pairing_validate_eeprom_handler(void);
|
||||
void pairing_init_event(void);
|
||||
bool compare_sequences(keypos_t a[PAIRING_SEQUENCE_SIZE], keypos_t b[PAIRING_SEQUENCE_SIZE]);
|
||||
void pairing_key_input_event(void);
|
||||
void pairing_failed_event(void);
|
||||
void pairing_succesful_event(void);
|
||||
keypos_t* pairing_sequence(void);
|
||||
|
||||
void oryx_layer_event(void);
|
||||
bool is_oryx_live_training_enabled(void);
|
||||
bool process_record_oryx(uint16_t keycode, keyrecord_t* record);
|
||||
void layer_state_set_oryx(layer_state_t state);
|
||||
|
||||
#if defined(RGB_MATRIX_ENABLE) && !defined(KEYBOARD_ergodox_ez_glow)
|
||||
RGB webhid_leds[DRIVER_LED_TOTAL];
|
||||
#endif
|
||||
Reference in New Issue
Block a user