Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[keyboard] annepro2 Add and use functions to directly control led colors #17196

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion keyboards/annepro2/annepro2.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ void keyboard_post_init_kb(void) {

#ifdef RGB_MATRIX_ENABLE
ap2_led_enable();
ap2_led_set_manual_control(1);
#endif

keyboard_post_init_user();
Expand All @@ -129,7 +130,7 @@ void matrix_scan_kb() {
if(rgb_row_changed[current_rgb_row])
{
rgb_row_changed[current_rgb_row] = 0;
ap2_led_mask_set_row(current_rgb_row);
ap2_led_colors_set_row(current_rgb_row);
}
current_rgb_row = (current_rgb_row + 1) % NUM_ROW;
#endif
Expand Down
27 changes: 27 additions & 0 deletions keyboards/annepro2/ap2_led.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "protocol.h"

ap2_led_t led_mask[KEY_COUNT];
ap2_led_t led_colors[KEY_COUNT];
ap2_led_status_t ap2_led_status;
uint8_t rgb_row_changed[NUM_ROW];

Expand Down Expand Up @@ -91,6 +92,32 @@ void ap2_led_mask_set_all(void) {
/* Set all keys to a given color */
void ap2_led_mask_set_mono(const ap2_led_t color) { proto_tx(CMD_LED_MASK_SET_MONO, (uint8_t *)&color, sizeof(color), 1); }

void ap2_led_colors_set_key(uint8_t row, uint8_t col, ap2_led_t color) {
uint8_t payload[] = {row, col, color.p.blue, color.p.green, color.p.red, color.p.alpha};
proto_tx(CMD_LED_COLOR_SET_KEY, payload, sizeof(payload), 1);
}

/* Push a whole local row to the shine */
void ap2_led_colors_set_row(uint8_t row) {
uint8_t payload[NUM_COLUMN * sizeof(ap2_led_t) + 1];
payload[0] = row;
memcpy(payload + 1, &led_colors[ROWCOL2IDX(row, 0)], sizeof(*led_colors) * NUM_COLUMN);
proto_tx(CMD_LED_COLOR_SET_ROW, payload, sizeof(payload), 1);
}

/* Synchronize all rows */
void ap2_led_colors_set_all(void) {
for (int row = 0; row < 5; row++) ap2_led_colors_set_row(row);
}

/* Set all keys to a given color */
void ap2_led_colors_set_mono(const ap2_led_t color) { proto_tx(CMD_LED_COLOR_SET_MONO, (uint8_t *)&color, sizeof(color), 1); }

void ap2_led_set_manual_control(uint8_t manual) {
uint8_t payload[] = {manual};
proto_tx(CMD_LED_SET_MANUAL, payload, sizeof(payload), 1);
}

void ap2_led_blink(uint8_t row, uint8_t col, ap2_led_t color, uint8_t count, uint8_t hundredths) {
uint8_t payload[] = {row, col, color.p.blue, color.p.green, color.p.red, color.p.alpha, count, hundredths};
proto_tx(CMD_LED_KEY_BLINK, payload, sizeof(payload), 1);
Expand Down
13 changes: 13 additions & 0 deletions keyboards/annepro2/ap2_led.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef union {

/* Local copy of led_mask, used to override colors on the board */
extern ap2_led_t led_mask[KEY_COUNT];
extern ap2_led_t led_colors[KEY_COUNT];
extern uint8_t rgb_row_changed[NUM_ROW];

/* Handle incoming messages */
Expand All @@ -66,6 +67,18 @@ void ap2_led_mask_set_all(void);
/* Set all keys to a given color */
void ap2_led_mask_set_mono(ap2_led_t color);

/* Set single key to a given color; alpha controls which is displayed */
void ap2_led_colors_set_key(uint8_t row, uint8_t col, ap2_led_t color);
/* Push a whole local row to the shine */
void ap2_led_colors_set_row(uint8_t row);
/* Synchronize all rows */
void ap2_led_colors_set_all(void);

/* Set all keys to a given color */
void ap2_led_colors_set_mono(ap2_led_t color);

void ap2_led_set_manual_control(uint8_t manual);

/* Blink given key `count` times by masking it with a `color`. Blink takes `hundredths` of a second */
void ap2_led_blink(uint8_t row, uint8_t col, ap2_led_t color, uint8_t count, uint8_t hundredths);

Expand Down
6 changes: 6 additions & 0 deletions keyboards/annepro2/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ enum {
CMD_LED_KEY_UP = 0x23, /* TODO */
CMD_LED_IAP = 0x24,

/* Manual color control */
CMD_LED_SET_MANUAL = 0x30,
CMD_LED_COLOR_SET_KEY = 0x31,
CMD_LED_COLOR_SET_ROW = 0x32,
CMD_LED_COLOR_SET_MONO = 0x33,

/* LED -> Main */
/* Payload with data to send over HID */
CMD_LED_DEBUG = 0x40,
Expand Down
8 changes: 4 additions & 4 deletions keyboards/annepro2/rgb_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ void init(void) {
void flush(void) {}

void set_color(int index, uint8_t r, uint8_t g, uint8_t b) {
if (r != led_mask[led_pos[index]].p.red ||
g != led_mask[led_pos[index]].p.green ||
b != led_mask[led_pos[index]].p.blue)
if (r != led_colors[led_pos[index]].p.red ||
g != led_colors[led_pos[index]].p.green ||
b != led_colors[led_pos[index]].p.blue)
{
led_mask[led_pos[index]] = (ap2_led_t){
led_colors[led_pos[index]] = (ap2_led_t){
.p.blue = b,
.p.red = r,
.p.green = g,
Expand Down