[Keyboard] dygma/raise: multiple fixes and improvements (#18361[)

This commit is contained in:
Mike Ryan 2022-09-28 14:23:42 -05:00 committed by GitHub
parent d050e689f5
commit d6f77637c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 76 additions and 51 deletions

View File

@ -28,7 +28,7 @@ const uint8_t led_map[DRIVER_LED_TOTAL] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 0xff, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 68, 69,
// right side - 36 keys includes LP
0 + LPH, 1 + LPH, 2 + LPH, 3 + LPH, 4 + LPH, 5 + LPH, 6 + LPH, 15 + LPH, 8 + LPH, 9 + LPH, 10 + LPH, 11 + LPH, 12 + LPH, 13 + LPH, 14 + LPH, 7 + LPH, 16 + LPH, 17 + LPH, 18 + LPH, 19 + LPH,
0 + LPH, 1 + LPH, 2 + LPH, 3 + LPH, 4 + LPH, 5 + LPH, 6 + LPH, 7 + LPH, 8 + LPH, 9 + LPH, 10 + LPH, 11 + LPH, 12 + LPH, 13 + LPH, 14 + LPH, 15 + LPH, 16 + LPH, 17 + LPH, 18 + LPH, 19 + LPH,
20 + LPH, 21 + LPH, 22 + LPH, 23 + LPH, 24 + LPH, 25 + LPH, 26 + LPH, 27 + LPH, 28 + LPH, 29 + LPH, 30 + LPH, 31 + LPH, 32 + LPH, 33 + LPH, 68 + LPH, 69 + LPH,
// left under glow - 30
@ -50,11 +50,11 @@ led_config_t g_led_config = { {
{ 26 , 27 , 28 , 29 , 30 , NO_LED , 31 , 32 } ,
// right hand
{ NO_LED , 6 + LHK , 5 + LHK , 4 + LHK , 3 + LHK , 2 + LHK , 1 + LHK , 0 + LHK } ,
{ 14 + LHK , 13 + LHK , 12 + LHK , 11 + LHK , 10 + LHK , 9 + LHK , 8 + LHK , 7 + LHK } ,
{ NO_LED , 21 + LHK , 20 + LHK , 19 + LHK , 18 + LHK , 17 + LHK , 16 + LHK , 15 + LHK } ,
{ NO_LED , NO_LED , 27 + LHK , 26 + LHK , 25 + LHK , 24 + LHK , 23 + LHK , 22 + LHK } ,
{ 35 + LHK , 34 + LHK , 33 + LHK , 32 + LHK , 31 + LHK , 30 + LHK , 29 + LHK , 28 + LHK }
{ 33 , 34 , 35 , 36 , 37 , 38 , 39 , NO_LED } ,
{ 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 } ,
{ 48 , 49 , 50 , 51 , 52 , 53 , 54 , NO_LED } ,
{ 55 , 56 , 57 , 58 , 59 , 60 , NO_LED , NO_LED } ,
{ 61 , 62 , 63 , 64 , 65 , 66 , 67 , 68 }
}, {
// generated from the svg image of the keyboard, see create-led-config.js
{82, 3}, {88, 3}, {94, 3}, {100, 3}, {106, 3}, {112, 3}, {118, 3}, {84, 10}, {91, 10}, {97, 10}, {103, 10}, {109, 10},
@ -72,7 +72,7 @@ led_config_t g_led_config = { {
{173, 63}, {177, 59}, {178, 49}, {179, 40}, {179, 31}, {177, 25}, {175, 20}, {175, 15}, {123, 54}
}, {
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
0,
0,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,

View File

@ -25,3 +25,33 @@
#define DEBOUNCE 0
#define DRIVER_LED_TOTAL 132
#ifdef RGB_MATRIX_ENABLE
// At the default flush limit of 16ms (~62.5 fps), the matrix scan rate is approximately
// ~140 scans per second under full load (when changes are being made to the LED state).
// Such a low scan rate will have impact the keyboard's accuracy for faster typists.
//
// With RGB completely disabled, the matrix scan rate is ~660 scans per second, and typing
// accuracy feels on par with the Dygma Raise Neuron.
//
// At 100ms (10 fps), the matrix scan rate is ~355 scans per second under full load, and typing
// accuracy is reasonably good.
#define RGB_MATRIX_LED_FLUSH_LIMIT 100
#define RGB_DISABLE_WHEN_USB_SUSPENDED // turn off effects when suspended
#define RGB_MATRIX_KEYPRESSES
#define RGB_MATRIX_FRAMEBUFFER_EFFECTS
// enabled only if RGB_MATRIX_FRAMEBUFFER_EFFECTS is defined
#define ENABLE_RGB_MATRIX_TYPING_HEATMAP
//# define ENABLE_RGB_MATRIX_DIGITAL_RAIN
// enabled only of RGB_MATRIX_KEYPRESSES or RGB_MATRIX_KEYRELEASES is defined
#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
#define ENABLE_RGB_MATRIX_SOLID_REACTIVE
#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
#endif

View File

@ -50,21 +50,21 @@ led_config_t g_led_config = { {
{ 26 , 27 , 28 , 29 , 30 , NO_LED , 31 , 32 } ,
// right hand
{ NO_LED , 6 + LHK , 5 + LHK , 4 + LHK , 3 + LHK , 2 + LHK , 1 + LHK , 0 + LHK } ,
{ 14 + LHK , 13 + LHK , 12 + LHK , 11 + LHK , 10 + LHK , 9 + LHK , 8 + LHK , 7 + LHK } ,
{ NO_LED , 21 + LHK , 20 + LHK , 19 + LHK , 18 + LHK , 17 + LHK , 16 + LHK , 15 + LHK } ,
{ NO_LED , NO_LED , 27 + LHK , 26 + LHK , 25 + LHK , 24 + LHK , 23 + LHK , 22 + LHK } ,
{ 35 + LHK , 34 + LHK , 33 + LHK , 32 + LHK , 31 + LHK , 30 + LHK , 29 + LHK , 28 + LHK }
{ 33 , 34 , 35 , 36 , 37 , 38 , 39 , NO_LED } ,
{ 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 } ,
{ 48 , 49 , 50 , 51 , 52 , 53 , 54 , NO_LED } ,
{ 55 , 56 , 57 , 58 , 59 , 60 , NO_LED , NO_LED } ,
{ 61 , 62 , 63 , 64 , 65 , 66 , 67 , 68 }
}, {
// generated from the svg image of the keyboard, see create-led-config.js
{82, 3}, {88, 3}, {94, 3}, {100, 3}, {106, 3}, {112, 3}, {118, 3}, {84, 10}, {91, 10}, {97, 10}, {103, 10}, {109, 10},
{82, 3}, {88, 3}, {94, 3}, {100, 3}, {106, 3}, {112, 3}, {118, 3}, {84, 10}, {91, 10}, {97, 10}, {103, 10}, {109, 10},
{115, 10}, {84, 16}, {92, 16}, {98, 16}, {104, 16}, {110, 16}, {116, 16}, {82, 22}, {88, 22}, {94, 22}, {100, 22},
{106, 22}, {112, 22}, {118, 22}, {83, 28}, {90, 28}, {98, 28}, {106, 28}, {116, 28}, {111, 34}, {118, 34}, {168, 3},
{159, 3}, {153, 3}, {147, 3}, {141, 3}, {135, 3}, {129, 3}, {170, 13}, {162, 10}, {156, 10}, {150, 10}, {144, 10},
{139, 10}, {133, 10}, {127, 10}, {164, 16}, {158, 16}, {152, 16}, {146, 16}, {140, 16}, {134, 16}, {128, 16}, {166, 22},
{139, 10}, {133, 10}, {127, 10}, {164, 16}, {158, 16}, {152, 16}, {146, 16}, {140, 16}, {134, 16}, {128, 16}, {166, 22},
{154, 22}, {148, 22}, {142, 22}, {136, 22}, {130, 22}, {170, 28}, {163, 28}, {156, 28}, {149, 28}, {140, 28}, {131, 28},
{136, 34}, {128, 34}, {78, 13}, {78, 6}, {80, 0}, {87, 0}, {95, 0}, {103, 0}, {111, 0}, {119, 0}, {122, 3}, {121, 9},
{120, 15}, {122, 21}, {123, 27}, {123, 33}, {120, 38}, {116, 42}, {114, 48}, {112, 55}, {109, 61}, {103, 64}, {96, 64},
{120, 15}, {122, 21}, {123, 27}, {123, 33}, {120, 38}, {116, 42}, {114, 48}, {112, 55}, {109, 61}, {103, 64}, {96, 64},
{88, 64}, {81, 63}, {76, 60}, {75, 52}, {75, 46}, {74, 38}, {74, 32}, {75, 27}, {77, 21}, {175, 10}, {175, 4}, {172, 0},
{164, 0}, {157, 0}, {149, 0}, {142, 0}, {134, 0}, {127, 0}, {123, 3}, {122, 8}, {122, 15}, {124, 21}, {124, 27}, {124, 33},
{126, 38}, {131, 42}, {134, 48}, {135, 55}, {137, 61}, {143, 63}, {150, 63}, {158, 63}, {166, 63}, {173, 63}, {177, 59},

View File

@ -24,16 +24,17 @@
#include "print.h"
#include "leds.h"
struct __attribute__((packed)) cRGB {
// Color order of LEDs is Green, Red, Blue.
typedef struct PACKED {
uint8_t r;
uint8_t g;
uint8_t b;
};
} raiseRGB;
#define LEDS_PER_HAND 72
#define LED_BANKS 9
#define LEDS_PER_BANK 8
#define LED_BYTES_PER_BANK (sizeof(cRGB) * LEDS_PER_BANK)
#define LED_BYTES_PER_BANK (sizeof(raiseRGB) * LEDS_PER_BANK)
// shifting << 1 is because drivers/chibios/i2c_master.h expects the address
// shifted.
@ -44,37 +45,28 @@ struct __attribute__((packed)) cRGB {
#define LEFT 0
#define RIGHT 1
static cRGB led_state[2 * LEDS_PER_HAND];
void set_all_leds_to(uint8_t r, uint8_t g, uint8_t b) {
uint8_t buf[] = {TWI_CMD_LED_SET_ALL_TO, b, g, r};
i2c_transmit(I2C_ADDR(LEFT), buf, sizeof(buf), I2C_TIMEOUT);
wait_us(10);
i2c_transmit(I2C_ADDR(RIGHT), buf, sizeof(buf), I2C_TIMEOUT);
wait_us(10);
}
void set_led_to(int led, uint8_t r, uint8_t g, uint8_t b) {
int sled = led_map[led];
uint8_t buf[] = {TWI_CMD_LED_SET_ONE_TO, sled & 0x1f, b, g, r};
int hand = (sled >= LEDS_PER_HAND) ? RIGHT : LEFT;
i2c_transmit(I2C_ADDR(hand), buf, sizeof(buf), I2C_TIMEOUT);
wait_us(10);
}
static raiseRGB led_pending[2 * LEDS_PER_HAND];
static raiseRGB led_state[2 * LEDS_PER_HAND];
static void set_color(int index, uint8_t r, uint8_t g, uint8_t b) {
int sled = led_map[index];
led_state[sled].r = r;
led_state[sled].g = g;
led_state[sled].b = b;
// The red component of the LED is apparently stronger than the others.
// From: https://github.com/keyboardio/Kaleidoscope/blob/aba8c9ee66bbb5ded15135618d2b2964ee82b2cc/plugins/Kaleidoscope-Hardware-Dygma-Raise/src/kaleidoscope/device/dygma/raise/RaiseSide.cpp#L235-L242
if (r >= 26) {
r -= 26;
}
led_pending[sled].r = r;
led_pending[sled].g = g;
led_pending[sled].b = b;
}
static void set_color_all(uint8_t r, uint8_t g, uint8_t b) {
for (int i = 0; i < DRIVER_LED_TOTAL; i++) set_color(i, r, g, b);
}
static void init(void) {}
static void init(void) {
set_color_all(0,0,0);
}
static void flush(void) {
uint8_t command[1 + LED_BYTES_PER_BANK];
@ -86,10 +78,17 @@ static void flush(void) {
for (int hand = 0; hand < 2; hand++) {
int addr = I2C_ADDR(hand);
int i = (hand * LEDS_PER_HAND) + (bank * LEDS_PER_BANK);
uint8_t *bank_data = (uint8_t *)&led_state[i];
if (memcmp(&led_state[i], &led_pending[i], LED_BYTES_PER_BANK) == 0) {
// No change.
continue;
}
// Update LED state
memcpy(&led_state[i], &led_pending[i], LED_BYTES_PER_BANK);
command[0] = TWI_CMD_LED_BASE + bank;
memcpy(&command[1], bank_data, LED_BYTES_PER_BANK);
memcpy(&command[1], &led_pending[i], LED_BYTES_PER_BANK);
i2c_transmit(addr, command, sizeof(command), I2C_TIMEOUT);
// delay to prevent issues with the i2c bus

View File

@ -16,10 +16,4 @@
#pragma once
#include "quantum.h"
#include "rgb_matrix.h"
extern const uint8_t led_map[DRIVER_LED_TOTAL];
void set_all_leds_to(uint8_t r, uint8_t g, uint8_t b);
void set_led_to(int led, uint8_t r, uint8_t g, uint8_t b);

View File

@ -0,0 +1,3 @@
ifeq ($(strip $(RGB_MATRIX_ENABLE)), yes)
SRC += leds.c
endif

View File

@ -17,6 +17,5 @@
#include "raise.h"
void keyboard_post_init_kb(void) {
set_all_leds_to(0, 0, 0);
keyboard_post_init_user();
}

View File

@ -10,7 +10,7 @@ BOOTLOADER = stm32-dfu
#
BOOTMAGIC_ENABLE = no # Enable Bootmagic Lite
MOUSEKEY_ENABLE = yes # Mouse keys
EXTRAKEY_ENABLE = no # Audio control and System control
EXTRAKEY_ENABLE = yes # Audio control and System control
CONSOLE_ENABLE = no # Console for debug
COMMAND_ENABLE = no # Commands for debug and configuration
NKRO_ENABLE = no # Enable N-Key Rollover
@ -28,6 +28,6 @@ CUSTOM_MATRIX = lite
RAW_ENABLE = yes
QUANTUM_LIB_SRC += i2c_master.c
SRC += leds.c matrix.c
SRC += matrix.c
DEFAULT_FOLDER = handwired/dygma/raise/ansi