Upgraded HID interface
parent
ac7423c1f3
commit
a3e5e8b83a
|
@ -5,12 +5,12 @@ RGB_MATRIX_EFFECT(FFT_ANIM)
|
||||||
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
|
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
|
||||||
|
|
||||||
// Maps fft columns to leds.
|
// Maps fft columns to leds.
|
||||||
// col_to_array[i] returns an array of leds in the ith bin of the fft.
|
// fft_col_to_array[i] returns an array of leds in the ith bin of the fft.
|
||||||
// Negative indices are "invisible" leds.
|
// Negative indices are "invisible" leds.
|
||||||
// Use them when your keyboard has gaps.
|
// Use them when your keyboard has gaps.
|
||||||
//
|
//
|
||||||
// This layout is for the Ergodox EZ.
|
// This layout is for the Ergodox EZ.
|
||||||
static int8_t col_to_array[10][5] = {
|
static int8_t fft_col_to_array[10][5] = {
|
||||||
{ 47, 43, 38, 33, 28 },
|
{ 47, 43, 38, 33, 28 },
|
||||||
{ 46, 42, 37, 32, 27 },
|
{ 46, 42, 37, 32, 27 },
|
||||||
{ 45, 41, 36, 31, 26 },
|
{ 45, 41, 36, 31, 26 },
|
||||||
|
@ -62,13 +62,13 @@ bool FFT_ANIM(effect_params_t* params) {
|
||||||
// There are 5 keys in each column.
|
// There are 5 keys in each column.
|
||||||
for (uint8_t i = bin_height; i < 6; i++) {
|
for (uint8_t i = bin_height; i < 6; i++) {
|
||||||
// Ignore negative indices.
|
// Ignore negative indices.
|
||||||
// See col_to_array definition.
|
// See fft_col_to_array definition.
|
||||||
if (col_to_array[bin][i] < 0) {
|
if (fft_col_to_array[bin][i] < 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
rgb_matrix_set_color(
|
rgb_matrix_set_color(
|
||||||
col_to_array[bin][i],
|
fft_col_to_array[bin][i],
|
||||||
0x00, 0x00, 0x00
|
0x00, 0x00, 0x00
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -77,8 +77,8 @@ bool FFT_ANIM(effect_params_t* params) {
|
||||||
// Turn on leds that should be on.
|
// Turn on leds that should be on.
|
||||||
for (uint8_t i = 0; i < bin_height; i++) {
|
for (uint8_t i = 0; i < bin_height; i++) {
|
||||||
// Ignore negative indices.
|
// Ignore negative indices.
|
||||||
// See col_to_array definition.
|
// See fft_col_to_array definition.
|
||||||
if (col_to_array[bin][i] < 0) {
|
if (fft_col_to_array[bin][i] < 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ bool FFT_ANIM(effect_params_t* params) {
|
||||||
// brightness depends on the height of the bar.
|
// brightness depends on the height of the bar.
|
||||||
if (i == bin_height - 1) {
|
if (i == bin_height - 1) {
|
||||||
rgb_matrix_set_color(
|
rgb_matrix_set_color(
|
||||||
col_to_array[bin][i],
|
fft_col_to_array[bin][i],
|
||||||
last_brightness, 0x00, last_brightness
|
last_brightness, 0x00, last_brightness
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ bool FFT_ANIM(effect_params_t* params) {
|
||||||
// it has a plain full-brightness color.
|
// it has a plain full-brightness color.
|
||||||
} else {
|
} else {
|
||||||
rgb_matrix_set_color(
|
rgb_matrix_set_color(
|
||||||
col_to_array[bin][i],
|
fft_col_to_array[bin][i],
|
||||||
0x00, 0x00, 0xFF
|
0x00, 0x00, 0xFF
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "betalupi_ergodox.h"
|
#include "betalupi_ergodox.h"
|
||||||
|
#include "rawhid.h"
|
||||||
|
|
||||||
extern inline void ergodox_board_led_on(void);
|
extern inline void ergodox_board_led_on(void);
|
||||||
extern inline void ergodox_right_led_1_on(void);
|
extern inline void ergodox_right_led_1_on(void);
|
||||||
|
@ -336,7 +337,14 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
|
||||||
}
|
}
|
||||||
eeconfig_update_kb(keyboard_config.raw);
|
eeconfig_update_kb(keyboard_config.raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hid_send_state();
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
case RGB_MOD:
|
||||||
|
// Tell the host whenever we change animation mode.
|
||||||
|
hid_send_state();
|
||||||
|
return true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Custom RGBLIGHT macros
|
// Custom RGBLIGHT macros
|
||||||
|
|
5
config.h
5
config.h
|
@ -13,6 +13,11 @@
|
||||||
#define USB_MAX_POWER_CONSUMPTION 500
|
#define USB_MAX_POWER_CONSUMPTION 500
|
||||||
#define USB_SUSPEND_WAKEUP_DELAY 0
|
#define USB_SUSPEND_WAKEUP_DELAY 0
|
||||||
|
|
||||||
|
// raw HID params
|
||||||
|
#define RAW_USAGE_PAGE 0xFF60
|
||||||
|
#define RAW_USAGE_ID 0x61
|
||||||
|
|
||||||
|
|
||||||
// Key matrix info
|
// Key matrix info
|
||||||
#define MATRIX_ROWS 14
|
#define MATRIX_ROWS 14
|
||||||
#define MATRIX_ROWS_PER_SIDE (MATRIX_ROWS / 2)
|
#define MATRIX_ROWS_PER_SIDE (MATRIX_ROWS / 2)
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
|
|
||||||
#include "layers.h"
|
#include "layers.h"
|
||||||
#include "tapdance.h"
|
#include "tapdance.h"
|
||||||
#include "raw_hid.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define KC_MAC_UNDO LGUI(KC_Z)
|
#define KC_MAC_UNDO LGUI(KC_Z)
|
||||||
|
|
86
rawhid.c
86
rawhid.c
|
@ -1,28 +1,22 @@
|
||||||
#include "betalupi_ergodox.h"
|
#include "rawhid.h"
|
||||||
|
|
||||||
void raw_hid_receive(uint8_t *data, uint8_t length);
|
|
||||||
|
|
||||||
#ifdef RGB_MATRIX_DATAPOINTER_ENABLED
|
|
||||||
void cmd_animation(uint8_t *data, uint8_t length);
|
|
||||||
|
|
||||||
// Animation data.
|
|
||||||
// Data received from host is saved here,
|
|
||||||
// and rgb_matrix_anim_data points to this array when necessary.
|
|
||||||
uint8_t hid_anim_data[32];
|
uint8_t hid_anim_data[32];
|
||||||
|
|
||||||
// Datapointer
|
// See rawhid.h for prococol documentation
|
||||||
extern void* rgb_matrix_anim_data;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// END HEADERS
|
|
||||||
|
|
||||||
|
|
||||||
void raw_hid_receive(uint8_t *data, uint8_t length) {
|
void raw_hid_receive(uint8_t *data, uint8_t length) {
|
||||||
uint8_t cmd = data[0];
|
uint8_t cmd = data[0];
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
|
case CMD_HELLO:
|
||||||
|
ergodox_right_led_1_on();
|
||||||
|
_delay_ms(50);
|
||||||
|
ergodox_right_led_1_off();
|
||||||
|
|
||||||
|
hid_send_state();
|
||||||
|
break;
|
||||||
|
|
||||||
#ifdef RGB_MATRIX_DATAPOINTER_ENABLED
|
#ifdef RGB_MATRIX_DATAPOINTER_ENABLED
|
||||||
case 0x01: // Animation
|
case CMD_ANIM_DATA:
|
||||||
cmd_animation(data, length);
|
cmd_animation(data, length);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
@ -31,21 +25,59 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// raw_hid_send(data, length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void hid_send_state() {
|
||||||
|
uint8_t packet[RAW_EPSIZE] = {
|
||||||
|
CMD_SEND_STATE
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
if (rgb_matrix_get_flags() != LED_FLAG_ALL) {
|
||||||
|
// RGB matrix is disabled
|
||||||
|
packet[1] = 0x00;
|
||||||
|
} else {
|
||||||
|
uint8_t mode = rgb_matrix_get_mode();
|
||||||
|
switch (mode) {
|
||||||
|
case RGB_MATRIX_CUSTOM_FFT_ANIM:
|
||||||
|
// FFT Animation is active
|
||||||
|
packet[1] = 0x02;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Normal animation is active
|
||||||
|
packet[1] = 0x01;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note that all sent packets MUST be
|
||||||
|
// RAW_EPSIZE long.
|
||||||
|
raw_hid_send(packet, RAW_EPSIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef RGB_MATRIX_DATAPOINTER_ENABLED
|
#ifdef RGB_MATRIX_DATAPOINTER_ENABLED
|
||||||
void cmd_animation(uint8_t *data, uint8_t length) {
|
void cmd_animation(uint8_t *data, uint8_t length) {
|
||||||
uint8_t subcmd = data[1];
|
switch (data[1]) {
|
||||||
|
case CMD_ANIM_DATA_fft:
|
||||||
|
// Only read data if animation is in fft mode
|
||||||
|
if (rgb_matrix_get_mode() == RGB_MATRIX_CUSTOM_FFT_ANIM) {
|
||||||
|
// rgb_matrix_anim_data is set to NULL at animation init.
|
||||||
|
if (rgb_matrix_anim_data == NULL) { rgb_matrix_anim_data = hid_anim_data; }
|
||||||
|
|
||||||
switch (subcmd) {
|
// Copy data into rgb matrix array
|
||||||
case 0x02: // Data input (fft)
|
memcpy(
|
||||||
|
hid_anim_data,
|
||||||
// TODO: assign pointer smartly.
|
data + 2,
|
||||||
rgb_matrix_anim_data = hid_anim_data;
|
sizeof(uint8_t) + 10
|
||||||
|
);
|
||||||
for (uint8_t bin = 0; bin < 10; bin++) {
|
} else {
|
||||||
hid_anim_data[bin] = data[bin + 2];
|
// If not in fft mode and we receive fft data, send a state packet so host stops sending data.
|
||||||
|
hid_send_state();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
#pragma once
|
||||||
|
#include "betalupi_ergodox.h"
|
||||||
|
#include "raw_hid.h"
|
||||||
|
|
||||||
|
|
||||||
|
void raw_hid_receive(uint8_t *data, uint8_t length);
|
||||||
|
void hid_send_state(void);
|
||||||
|
|
||||||
|
#ifdef RGB_MATRIX_DATAPOINTER_ENABLED
|
||||||
|
void cmd_animation(uint8_t *data, uint8_t length);
|
||||||
|
|
||||||
|
// Animation data.
|
||||||
|
// Data received from host is saved here,
|
||||||
|
// and rgb_matrix_anim_data points to this array when necessary.
|
||||||
|
extern uint8_t hid_anim_data[32];
|
||||||
|
|
||||||
|
// Datapointer
|
||||||
|
extern void* rgb_matrix_anim_data;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Sent by host when connection is initiated.
|
||||||
|
#define CMD_HELLO 0x00
|
||||||
|
|
||||||
|
// Send keyboard state to host.
|
||||||
|
//
|
||||||
|
// Packet structure:
|
||||||
|
// Data: | cmd | anim state |
|
||||||
|
// # of Bytes: | 1 | 1 |
|
||||||
|
//
|
||||||
|
// anim state:
|
||||||
|
// 0x00: RGBMatrix disabled
|
||||||
|
// 0x01: normal animation, no HID data.
|
||||||
|
// 0x02: FFT Animation
|
||||||
|
#define CMD_SEND_STATE 0x01
|
||||||
|
|
||||||
|
|
||||||
|
// Animation data. Sent by host.
|
||||||
|
//
|
||||||
|
// Packet structure:
|
||||||
|
// Data: | cmd | data type | data |
|
||||||
|
// # of Bytes: | 1 | 1 | ? |
|
||||||
|
//
|
||||||
|
// data type:
|
||||||
|
// Which animation this data is for. These are defined below.
|
||||||
|
//
|
||||||
|
// data:
|
||||||
|
// Animation data. Content depends on data type.
|
||||||
|
#define CMD_ANIM_DATA 0x02
|
||||||
|
|
||||||
|
// Data for FFT animation.
|
||||||
|
// Data segment consists of 10 bits, each representing the height of a column.
|
||||||
|
// Minimum height is 0, maximum is 250.
|
||||||
|
#define CMD_ANIM_DATA_fft 0x00
|
Loading…
Reference in New Issue