Add init function to RGBLight driver struct (#23076)

This commit is contained in:
Ryan 2024-03-18 22:03:27 +11:00 committed by GitHub
parent 23b7a02ebe
commit f7cf40fa77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
42 changed files with 306 additions and 93 deletions

View file

@ -67,7 +67,9 @@ static void apa102_send_byte(uint8_t byte) {
}
static void apa102_start_frame(void) {
apa102_init();
gpio_write_pin_low(APA102_DI_PIN);
gpio_write_pin_low(APA102_CI_PIN);
for (uint16_t i = 0; i < 4; i++) {
apa102_send_byte(0);
}
@ -103,7 +105,8 @@ static void apa102_end_frame(uint16_t num_leds) {
apa102_send_byte(0);
}
apa102_init();
gpio_write_pin_low(APA102_DI_PIN);
gpio_write_pin_low(APA102_CI_PIN);
}
static void apa102_send_frame(uint8_t red, uint8_t green, uint8_t blue, uint8_t brightness) {
@ -116,9 +119,6 @@ static void apa102_send_frame(uint8_t red, uint8_t green, uint8_t blue, uint8_t
void apa102_init(void) {
gpio_set_pin_output(APA102_DI_PIN);
gpio_set_pin_output(APA102_CI_PIN);
gpio_write_pin_low(APA102_DI_PIN);
gpio_write_pin_low(APA102_CI_PIN);
}
void apa102_setleds(rgb_led_t *start_led, uint16_t num_leds) {

View file

@ -62,6 +62,8 @@
# define WS2812_LED_COUNT RGB_MATRIX_LED_COUNT
#endif
void ws2812_init(void);
/* User Interface
*
* Input:

View file

@ -21,5 +21,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
}
void keyboard_post_init_user(void) {
rgblite_init();
rgblite_increase_hue();
}

View file

@ -6,6 +6,10 @@
#include "ws2812.h"
#include "color.h"
static inline void rgblite_init(void) {
ws2812_init();
}
static inline void rgblite_setrgb(RGB rgb) {
rgb_led_t leds[RGBLIGHT_LED_COUNT] = {{.r = rgb.r, .g = rgb.g, .b = rgb.b}};
ws2812_setleds(leds, RGBLIGHT_LED_COUNT);

View file

@ -0,0 +1,200 @@
#include QMK_KEYBOARD_H
#include "version.h"
enum layers {
BASE, // default layer
SYMB, // symbols
MDIA, // media keys
};
enum custom_keycodes {
VRSN = SAFE_RANGE,
};
// clang-format off
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Keymap 0: Basic layer
*
* ,--------------------------------------------------. ,--------------------------------------------------.
* | = | 1 | 2 | 3 | 4 | 5 | LEFT | | RIGHT| 6 | 7 | 8 | 9 | 0 | - |
* |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------|
* | Del | Q | W | E | R | T | L1 | | L1 | Y | U | I | O | P | \ |
* |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
* | BkSp | A | S | D | F | G |------| |------| H | J | K | L |; / L2|' / Cmd |
* |--------+------+------+------+------+------| Hyper| | Meh |------+------+------+------+------+--------|
* | LShift |Z/Ctrl| X | C | V | B | | | | N | M | , | . |//Ctrl| RShift |
* `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
* |Grv/L1| '" |AltShf| Left | Right| | Up | Down | [ | ] | ~L1 |
* `----------------------------------' `----------------------------------'
* ,-------------. ,-------------.
* | App | LGui | | Alt |Ctrl/Esc|
* ,------|------|------| |------+--------+------.
* | | | Home | | PgUp | | |
* | Space|Backsp|------| |------| Tab |Enter |
* | |ace | End | | PgDn | | |
* `--------------------' `----------------------'
*/
[BASE] = LAYOUT_ergodox_pretty(
// left hand
KC_EQL, KC_1, KC_2, KC_3, KC_4, KC_5, KC_LEFT, KC_RGHT, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS,
KC_DEL, KC_Q, KC_W, KC_E, KC_R, KC_T, TG(SYMB), TG(SYMB), KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLS,
KC_BSPC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, LT(MDIA, KC_SCLN), GUI_T(KC_QUOT),
KC_LSFT, CTL_T(KC_Z), KC_X, KC_C, KC_V, KC_B, ALL_T(KC_NO), MEH_T(KC_NO), KC_N, KC_M, KC_COMM, KC_DOT, CTL_T(KC_SLSH), KC_RSFT,
LT(SYMB,KC_GRV), KC_QUOT, LALT(KC_LSFT), KC_LEFT, KC_RGHT, KC_UP, KC_DOWN, KC_LBRC, KC_RBRC, TT(SYMB),
ALT_T(KC_APP), KC_LGUI, KC_LALT, CTL_T(KC_ESC),
KC_HOME, KC_PGUP,
KC_SPC, KC_BSPC, KC_END, KC_PGDN, KC_TAB, KC_ENT
),
/* Keymap 1: Symbol Layer
*
* ,---------------------------------------------------. ,--------------------------------------------------.
* |Version | F1 | F2 | F3 | F4 | F5 | | | | F6 | F7 | F8 | F9 | F10 | F11 |
* |---------+------+------+------+------+------+------| |------+------+------+------+------+------+--------|
* | | ! | @ | { | } | | | | | | Up | 7 | 8 | 9 | * | F12 |
* |---------+------+------+------+------+------| | | |------+------+------+------+------+--------|
* | | # | $ | ( | ) | ` |------| |------| Down | 4 | 5 | 6 | + | |
* |---------+------+------+------+------+------| | | |------+------+------+------+------+--------|
* | | % | ^ | [ | ] | ~ | | | | & | 1 | 2 | 3 | \ | |
* `---------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
* | EPRM | | | | | | | . | 0 | = | |
* `-----------------------------------' `----------------------------------'
* ,-------------. ,-------------.
* |Animat| | |Toggle|Solid |
* ,------|------|------| |------+------+------.
* |Bright|Bright| | | |Hue- |Hue+ |
* |ness- |ness+ |------| |------| | |
* | | | | | | | |
* `--------------------' `--------------------'
*/
[SYMB] = LAYOUT_ergodox_pretty(
// left hand
VRSN, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_TRNS, KC_TRNS, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11,
KC_TRNS, KC_EXLM, KC_AT, KC_LCBR, KC_RCBR, KC_PIPE, KC_TRNS, KC_TRNS, KC_UP, KC_7, KC_8, KC_9, KC_ASTR, KC_F12,
KC_TRNS, KC_HASH, KC_DLR, KC_LPRN, KC_RPRN, KC_GRV, KC_DOWN, KC_4, KC_5, KC_6, KC_PLUS, KC_TRNS,
KC_TRNS, KC_PERC, KC_CIRC, KC_LBRC, KC_RBRC, KC_TILD, KC_TRNS, KC_TRNS, KC_AMPR, KC_1, KC_2, KC_3, KC_BSLS, KC_TRNS,
EE_CLR, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_DOT, KC_0, KC_EQL, KC_TRNS,
RGB_MOD, KC_TRNS, RGB_TOG, RGB_M_P,
KC_TRNS, KC_TRNS,
RGB_VAD, RGB_VAI, KC_TRNS, KC_TRNS, RGB_HUD, RGB_HUI
),
/* Keymap 2: Media and mouse keys
*
* ,--------------------------------------------------. ,--------------------------------------------------.
* | | | | | | | | | | | | | | | |
* |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------|
* | | | | MsUp | | | | | | | | | | | |
* |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
* | | |MsLeft|MsDown|MsRght| |------| |------| | | | | | Play |
* |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
* | | | | | | | | | | | | Prev | Next | | |
* `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
* | | | | Lclk | Rclk | |VolUp |VolDn | Mute | | |
* `----------------------------------' `----------------------------------'
* ,-------------. ,-------------.
* | | | | | |
* ,------|------|------| |------+------+------.
* | | | | | | |Brwser|
* | | |------| |------| |Back |
* | | | | | | | |
* `--------------------' `--------------------'
*/
[MDIA] = LAYOUT_ergodox_pretty(
// left hand
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_MS_U, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_MS_L, KC_MS_D, KC_MS_R, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPLY,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPRV, KC_MNXT, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_BTN1, KC_BTN2, KC_VOLU, KC_VOLD, KC_MUTE, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_WBAK
),
};
// clang-format on
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {
switch (keycode) {
case VRSN:
SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION);
return false;
}
}
return true;
}
// Runs just one time when the keyboard initializes.
void keyboard_post_init_user(void) {
#ifdef RGBLIGHT_COLOR_LAYER_0
rgblight_setrgb(RGBLIGHT_COLOR_LAYER_0);
#endif
};
// Runs whenever there is a layer state change.
layer_state_t layer_state_set_user(layer_state_t state) {
ergodox_board_led_off();
ergodox_right_led_1_off();
ergodox_right_led_2_off();
ergodox_right_led_3_off();
uint8_t layer = get_highest_layer(state);
switch (layer) {
case 0:
#ifdef RGBLIGHT_COLOR_LAYER_0
rgblight_setrgb(RGBLIGHT_COLOR_LAYER_0);
#endif
break;
case 1:
ergodox_right_led_1_on();
#ifdef RGBLIGHT_COLOR_LAYER_1
rgblight_setrgb(RGBLIGHT_COLOR_LAYER_1);
#endif
break;
case 2:
ergodox_right_led_2_on();
#ifdef RGBLIGHT_COLOR_LAYER_2
rgblight_setrgb(RGBLIGHT_COLOR_LAYER_2);
#endif
break;
case 3:
ergodox_right_led_3_on();
#ifdef RGBLIGHT_COLOR_LAYER_3
rgblight_setrgb(RGBLIGHT_COLOR_LAYER_3);
#endif
break;
case 4:
ergodox_right_led_1_on();
ergodox_right_led_2_on();
#ifdef RGBLIGHT_COLOR_LAYER_4
rgblight_setrgb(RGBLIGHT_COLOR_LAYER_4);
#endif
break;
case 5:
ergodox_right_led_1_on();
ergodox_right_led_3_on();
#ifdef RGBLIGHT_COLOR_LAYER_5
rgblight_setrgb(RGBLIGHT_COLOR_LAYER_5);
#endif
break;
case 6:
ergodox_right_led_2_on();
ergodox_right_led_3_on();
#ifdef RGBLIGHT_COLOR_LAYER_6
rgblight_setrgb(RGBLIGHT_COLOR_LAYER_6);
#endif
break;
case 7:
ergodox_right_led_1_on();
ergodox_right_led_2_on();
ergodox_right_led_3_on();
#ifdef RGBLIGHT_COLOR_LAYER_7
rgblight_setrgb(RGBLIGHT_COLOR_LAYER_7);
#endif
break;
default:
break;
}
return state;
};

View file

@ -0,0 +1,2 @@
RGBLIGHT_ENABLE = no
RGB_MATRIX_ENABLE = yes

View file

@ -1 +0,0 @@
// Placeholder. See ../default/keymap.c for details

View file

@ -1,4 +0,0 @@
RGBLIGHT_ENABLE = no
RGB_MATRIX_ENABLE = yes # enable later
SRC += keymaps/default/keymap.c

View file

@ -151,6 +151,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
),
};
#ifdef RGBLIGHT_ENABLE
void eeconfig_init_user(void) {
rgblight_enable();
rgblight_sethsv(HSV_CYAN);
@ -158,7 +159,7 @@ void eeconfig_init_user(void) {
user_config.rgb_layer_change = true;
eeconfig_update_user(user_config.raw);
}
#endif
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
@ -168,21 +169,17 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
eeconfig_init();
}
return false;
break;
case VRSN:
if (record->event.pressed) {
SEND_STRING (QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION);
}
return false;
break;
#ifdef RGBLIGHT_ENABLE
case RGB_SLD:
if (record->event.pressed) {
#ifdef RGBLIGHT_ENABLE
rgblight_mode(1);
#endif
}
return false;
break;
case RGB_LYR: // This allows me to use underglow as layer indication, or as normal
if (record->event.pressed) {
user_config.rgb_layer_change ^= 1; // Toggles the status
@ -191,7 +188,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
layer_state_set(layer_state); // then immediately update the layer color
}
}
return false; break;
return false;
case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // For any of the RGB codes (see quantum_keycodes.h, L400 for reference)
if (record->event.pressed) { //This disables layer indication, as it's assumed that if you're changing this ... you want that disabled
if (user_config.rgb_layer_change) { // only if this is enabled
@ -199,11 +196,13 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
eeconfig_update_user(user_config.raw); // write the setings to EEPROM
}
}
return true; break;
return true;
#endif
}
return true;
}
#ifdef RGBLIGHT_ENABLE
void matrix_init_user(void) {
// Call the keymap level matrix init.
@ -217,11 +216,7 @@ void matrix_init_user(void) {
rgblight_mode_noeeprom(1);
}
}
// Runs constantly in the background, in a loop.
void matrix_scan_user(void) {
};
#endif
layer_state_t layer_state_set_user(layer_state_t state) {
ergodox_board_led_off();
@ -231,39 +226,55 @@ layer_state_t layer_state_set_user(layer_state_t state) {
switch (get_highest_layer(state)) {
case SYMB:
ergodox_right_led_1_on();
#ifdef RGBLIGHT_ENABLE
if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom(HSV_RED); rgblight_mode_noeeprom(1); }
#endif
break;
case MDIA:
ergodox_right_led_2_on();
#ifdef RGBLIGHT_ENABLE
if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom(HSV_GREEN); rgblight_mode_noeeprom(1); }
#endif
break;
case 3:
ergodox_right_led_3_on();
#ifdef RGBLIGHT_ENABLE
if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom(HSV_BLUE); rgblight_mode_noeeprom(1); }
#endif
break;
case 4:
ergodox_right_led_1_on();
ergodox_right_led_2_on();
#ifdef RGBLIGHT_ENABLE
if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom(HSV_ORANGE); rgblight_mode_noeeprom(1); }
#endif
break;
case 5:
ergodox_right_led_1_on();
ergodox_right_led_3_on();
#ifdef RGBLIGHT_ENABLE
if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom(HSV_YELLOW); rgblight_mode_noeeprom(1); }
#endif
break;
case 6:
ergodox_right_led_2_on();
ergodox_right_led_3_on();
#ifdef RGBLIGHT_ENABLE
if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom(HSV_PINK); rgblight_mode_noeeprom(1); }
#endif
break;
case 7:
ergodox_right_led_1_on();
ergodox_right_led_2_on();
ergodox_right_led_3_on();
#ifdef RGBLIGHT_ENABLE
if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom(HSV_WHITE); rgblight_mode_noeeprom(1); }
#endif
break;
default: // for any other layers, or the default layer
#ifdef RGBLIGHT_ENABLE
if (user_config.rgb_layer_change) { rgblight_sethsv_noeeprom(HSV_CYAN); rgblight_mode_noeeprom(1); }
#endif
break;
}
return state;

View file

@ -29,7 +29,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
};
void matrix_init_user(void) {
#ifdef RGBLIGHT_COLOR_LAYER_0
#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_COLOR_LAYER_0)
rgblight_setrgb(RGBLIGHT_COLOR_LAYER_0);
#endif
};
@ -42,19 +42,18 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
eeconfig_init();
}
return false;
break;
case VRSN:
if (record->event.pressed) {
SEND_STRING (QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION);
}
return false;
break;
#ifdef RGBLIGHT_ENABLE
case RGB_SLD:
if (record->event.pressed) {
rgblight_mode(1);
}
return false;
break;
#endif
}
return true;
@ -70,48 +69,50 @@ layer_state_t layer_state_set_user(layer_state_t state) {
ergodox_right_led_3_off();
switch (layer) {
case 0:
#ifdef RGBLIGHT_COLOR_LAYER_0
#ifdef RGBLIGHT_ENABLE
#ifdef RGBLIGHT_COLOR_LAYER_0
rgblight_setrgb(RGBLIGHT_COLOR_LAYER_0);
#else
#else
rgblight_init();
#endif
#endif
break;
case 1:
ergodox_right_led_1_on();
#ifdef RGBLIGHT_COLOR_LAYER_1
#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_COLOR_LAYER_1)
rgblight_setrgb(RGBLIGHT_COLOR_LAYER_1);
#endif
break;
case 2:
ergodox_right_led_2_on();
#ifdef RGBLIGHT_COLOR_LAYER_2
#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_COLOR_LAYER_2)
rgblight_setrgb(RGBLIGHT_COLOR_LAYER_2);
#endif
break;
case 3:
ergodox_right_led_3_on();
#ifdef RGBLIGHT_COLOR_LAYER_3
#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_COLOR_LAYER_3)
rgblight_setrgb(RGBLIGHT_COLOR_LAYER_3);
#endif
break;
case 4:
ergodox_right_led_1_on();
ergodox_right_led_2_on();
#ifdef RGBLIGHT_COLOR_LAYER_4
#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_COLOR_LAYER_4)
rgblight_setrgb(RGBLIGHT_COLOR_LAYER_4);
#endif
break;
case 5:
ergodox_right_led_1_on();
ergodox_right_led_3_on();
#ifdef RGBLIGHT_COLOR_LAYER_5
#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_COLOR_LAYER_5)
rgblight_setrgb(RGBLIGHT_COLOR_LAYER_5);
#endif
break;
case 6:
ergodox_right_led_2_on();
ergodox_right_led_3_on();
#ifdef RGBLIGHT_COLOR_LAYER_6
#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_COLOR_LAYER_6)
rgblight_setrgb(RGBLIGHT_COLOR_LAYER_6);
#endif
break;
@ -119,7 +120,7 @@ layer_state_t layer_state_set_user(layer_state_t state) {
ergodox_right_led_1_on();
ergodox_right_led_2_on();
ergodox_right_led_3_on();
#ifdef RGBLIGHT_COLOR_LAYER_7
#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_COLOR_LAYER_7)
rgblight_setrgb(RGBLIGHT_COLOR_LAYER_6);
#endif
break;

View file

@ -19,8 +19,7 @@ SWAP_HANDS_ENABLE= no # Allow swapping hands of keyboard
RGB_MATRIX_ENABLE = no # enable later
# project specific files
SRC += matrix.c \
led_i2c.c
SRC += matrix.c
I2C_DRIVER_REQUIRED = yes
# Disable unsupported hardware

View file

@ -18,10 +18,8 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef RGBLIGHT_ENABLE
# include "ergodox_ez.h"
# include "ws2812.h"
#include "ergodox_ez.h"
#include "ws2812.h"
void setleds_custom(rgb_led_t *led, uint16_t led_num) {
uint16_t length = 0;
@ -64,7 +62,6 @@ void setleds_custom(rgb_led_t *led, uint16_t led_num) {
}
const rgblight_driver_t rgblight_driver = {
.init = ws2812_init,
.setleds = setleds_custom,
};
#endif // RGBLIGHT_ENABLE

View file

@ -1,2 +1,3 @@
RGBLIGHT_ENABLE = yes
WS2812_DRIVER_REQUIRED = yes
SRC += rgblight_custom.c

View file

@ -1,8 +1,15 @@
#include "keyboard.h"
#include "ws2812.h"
#include "rgbsps.h"
rgb_led_t led[RGBSPS_NUM];
void keyboard_pre_init_kb(void) {
ws2812_init();
keyboard_pre_init_user();
}
void rgbsps_set(uint8_t index, uint8_t r, uint8_t g, uint8_t b) {
led[index].r = r;
led[index].g = g;

View file

@ -90,6 +90,7 @@ void sleep_led_enable(void) {
void keyboard_pre_init_kb(void) {
#ifdef KEYBOARD_ibm_model_m_mschwingen_led_ws2812
ws2812_init();
ws2812_setleds(led, RGBLIGHT_LED_COUNT);
#else
/* Set status LEDs pins to output and Low (on) */

View file

@ -154,6 +154,7 @@ rgb_led_t rgb_matrix_ws2812_array[WS2812_LED_TOTAL];
static void rgb_matrix_driver_init(void) {
i2c_init();
is31fl3733_init(0);
ws2812_init();
for (uint8_t index = 0; index < IS31FL3733_LED_COUNT; index++) {
bool enabled = true;
is31fl3733_set_led_control_register(index, enabled, enabled, enabled);

View file

@ -154,6 +154,7 @@ rgb_led_t rgb_matrix_ws2812_array[WS2812_LED_TOTAL];
static void rgb_matrix_driver_init(void) {
i2c_init();
is31fl3733_init(0);
ws2812_init();
for (uint8_t index = 0; index < IS31FL3733_LED_COUNT; index++) {
bool enabled = true;
is31fl3733_set_led_control_register(index, enabled, enabled, enabled);

View file

@ -150,6 +150,7 @@ rgb_led_t rgb_matrix_ws2812_array[WS2812_LED_TOTAL];
static void rgb_matrix_driver_init(void) {
i2c_init();
is31fl3733_init(0);
ws2812_init();
for (uint8_t index = 0; index < IS31FL3733_LED_COUNT; index++) {
bool enabled = true;
is31fl3733_set_led_control_register(index, enabled, enabled, enabled);

View file

@ -79,6 +79,7 @@ void setleds_custom(rgb_led_t *start_led, uint16_t num_leds)
}
const rgblight_driver_t rgblight_driver = {
.init = ws2812_init,
.setleds = setleds_custom,
};

View file

@ -55,6 +55,7 @@ void setleds_custom(rgb_led_t *ledarray, uint16_t num_leds) {
}
const rgblight_driver_t rgblight_driver = {
.init = ws2812_init,
.setleds = setleds_custom,
};
#endif

View file

@ -355,6 +355,7 @@ void setleds_custom(rgb_led_t *start_led, uint16_t num_leds)
}
const rgblight_driver_t rgblight_driver = {
.init = ws2812_init,
.setleds = setleds_custom,
};

View file

@ -350,6 +350,7 @@ void setleds_custom(rgb_led_t *start_led, uint16_t num_leds)
}
const rgblight_driver_t rgblight_driver = {
.init = ws2812_init,
.setleds = setleds_custom,
};

View file

@ -84,6 +84,7 @@ void setleds_custom(rgb_led_t *start_led, uint16_t num_leds)
}
const rgblight_driver_t rgblight_driver = {
.init = ws2812_init,
.setleds = setleds_custom,
};
#endif

View file

@ -23,12 +23,6 @@ void ws2812_init(void) {
// Setleds for standard RGB
void ws2812_setleds(rgb_led_t *ledarray, uint16_t leds) {
static bool s_init = false;
if (!s_init) {
ws2812_init();
s_init = true;
}
i2c_transmit(WS2812_I2C_ADDRESS, (uint8_t *)ledarray, sizeof(rgb_led_t) * (leds >> 1), WS2812_I2C_TIMEOUT);
i2c_transmit(WS2812_I2C_ADDRESS_RIGHT, (uint8_t *)ledarray+(sizeof(rgb_led_t) * (leds >> 1)), sizeof(rgb_led_t) * (leds - (leds >> 1)), WS2812_I2C_TIMEOUT);
}

View file

@ -24,8 +24,6 @@
// LED color buffer
rgb_led_t rgb_matrix_ws2812_array[RGB_MATRIX_LED_COUNT];
static void init(void) {}
static void flush(void) {
ws2812_setleds(rgb_matrix_ws2812_array, RGB_MATRIX_LED_COUNT);
}
@ -56,7 +54,7 @@ static void setled_all(uint8_t r, uint8_t g, uint8_t b) {
}
const rgb_matrix_driver_t rgb_matrix_driver = {
.init = init,
.init = ws2812_init,
.flush = flush,
.set_color = setled,
.set_color_all = setled_all,

View file

@ -2237,6 +2237,9 @@ void backlight_init_drivers(void)
is31fl3733_update_led_control_registers( 0 );
is31fl3733_update_led_control_registers( 1 );
#else
#if defined(RGB_BACKLIGHT_DAWN60)
ws2812_init();
#endif
// Init the #1 driver
is31fl3731_init( 0 );
// Init the #2 driver (if used)

View file

@ -20,11 +20,13 @@
#undef WS2812_DI_PIN
#define WS2812_DI_PIN RGBLIGHT_DI_PIN
#define ws2812_init ws2812_rgb_init
#define ws2812_setleds ws2812_rgb_setleds
#include "ws2812_bitbang.c"
const rgblight_driver_t rgblight_driver = {
.init = ws2812_init,
.setleds = ws2812_setleds,
};
#endif

View file

@ -155,7 +155,7 @@ static void init(void) {
is31fl3731_update_led_control_registers(1);
//RGB Underglow ws2812
ws2812_init();
}
static void flush(void) {

View file

@ -169,5 +169,6 @@ layer_state_t layer_state_set_user(layer_state_t state) {
// default color
void keyboard_post_init_user(void) {
rgblite_init();
rgblite_setrgb(RGB_GREEN);
}

View file

@ -3,7 +3,11 @@
#include "ws2812.h"
#include "color.h"
static inline void rgblite_setrgb(uint8_t _r, uint8_t _g, uint8_t _b) {
rgb_led_t leds[RGBLED_NUM] = {{.r = _r, .g = _g, .b = _b}, {.r = _r, .g = _g, .b = _b}};
ws2812_setleds(leds, RGBLED_NUM);
static inline void rgblite_init(void) {
ws2812_init();
}
static inline void rgblite_setrgb(uint8_t _r, uint8_t _g, uint8_t _b) {
rgb_led_t leds[RGBLIGHT_LED_COUNT] = {{.r = _r, .g = _g, .b = _b}, {.r = _r, .g = _g, .b = _b}};
ws2812_setleds(leds, RGBLIGHT_LED_COUNT);
}

View file

@ -27,5 +27,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
}
void keyboard_post_init_user(void) {
rgblite_init();
rgblite_increase_hue();
}

View file

@ -3,9 +3,13 @@
#include "ws2812.h"
#include "color.h"
static inline void rgblite_init(void) {
ws2812_init();
}
static inline void rgblite_setrgb(uint8_t _r, uint8_t _g, uint8_t _b) {
rgb_led_t leds[RGBLED_NUM] = {{.r = _r, .g = _g, .b = _b}, {.r = _r, .g = _g, .b = _b}};
ws2812_setleds(leds, RGBLED_NUM);
rgb_led_t leds[RGBLIGHT_LED_COUNT] = {{.r = _r, .g = _g, .b = _b}, {.r = _r, .g = _g, .b = _b}};
ws2812_setleds(leds, RGBLIGHT_LED_COUNT);
}
static void rgblite_increase_hue(void) {

View file

@ -37,9 +37,11 @@
static inline void ws2812_sendarray_mask(uint8_t *data, uint16_t datlen, uint8_t masklo, uint8_t maskhi);
void ws2812_setleds(rgb_led_t *ledarray, uint16_t number_of_leds) {
void ws2812_init(void) {
DDRx_ADDRESS(WS2812_DI_PIN) |= pinmask(WS2812_DI_PIN);
}
void ws2812_setleds(rgb_led_t *ledarray, uint16_t number_of_leds) {
uint8_t masklo = ~(pinmask(WS2812_DI_PIN)) & PORTx_ADDRESS(WS2812_DI_PIN);
uint8_t maskhi = pinmask(WS2812_DI_PIN) | PORTx_ADDRESS(WS2812_DI_PIN);

View file

@ -19,11 +19,5 @@ void ws2812_init(void) {
// Setleds for standard RGB
void ws2812_setleds(rgb_led_t *ledarray, uint16_t leds) {
static bool s_init = false;
if (!s_init) {
ws2812_init();
s_init = true;
}
i2c_transmit(WS2812_I2C_ADDRESS, (uint8_t *)ledarray, sizeof(rgb_led_t) * leds, WS2812_I2C_TIMEOUT);
}

View file

@ -177,7 +177,7 @@ static void ws2812_dma_callback(void* p, uint32_t ct) {
osalSysUnlockFromISR();
}
bool ws2812_init(void) {
void ws2812_init(void) {
uint pio_idx = pio_get_index(pio);
/* Get PIOx peripheral out of reset state. */
hal_lld_peripheral_unreset(pio_idx == 0 ? RESETS_ALLREG_PIO0 : RESETS_ALLREG_PIO1);
@ -196,7 +196,7 @@ bool ws2812_init(void) {
STATE_MACHINE = pio_claim_unused_sm(pio, true);
if (STATE_MACHINE < 0) {
dprintln("ERROR: Failed to acquire state machine for WS2812 output!");
return false;
return;
}
uint offset = pio_add_program(pio, &ws2812_program);
@ -246,8 +246,6 @@ bool ws2812_init(void) {
DMA_CTRL_TRIG_TREQ_SEL(pio == pio0 ? STATE_MACHINE : STATE_MACHINE + 8) |
DMA_CTRL_TRIG_PRIORITY(RP_DMA_PRIORITY_WS2812);
// clang-format on
return true;
}
static inline void sync_ws2812_transfer(void) {
@ -269,11 +267,6 @@ static inline void sync_ws2812_transfer(void) {
}
void ws2812_setleds(rgb_led_t* ledarray, uint16_t leds) {
static bool is_initialized = false;
if (unlikely(!is_initialized)) {
is_initialized = ws2812_init();
}
sync_ws2812_transfer();
for (int i = 0; i < leds; i++) {

View file

@ -82,12 +82,6 @@ void ws2812_init(void) {
// Setleds for standard RGB
void ws2812_setleds(rgb_led_t *ledarray, uint16_t leds) {
static bool s_init = false;
if (!s_init) {
ws2812_init();
s_init = true;
}
// this code is very time dependent, so we need to disable interrupts
chSysLock();

View file

@ -389,12 +389,6 @@ void ws2812_write_led_rgbw(uint16_t led_number, uint8_t r, uint8_t g, uint8_t b,
// Setleds for standard RGB
void ws2812_setleds(rgb_led_t* ledarray, uint16_t leds) {
static bool s_init = false;
if (!s_init) {
ws2812_init();
s_init = true;
}
for (uint16_t i = 0; i < leds; i++) {
#ifdef RGBW
ws2812_write_led_rgbw(i, ledarray[i].r, ledarray[i].g, ledarray[i].b, ledarray[i].w);

View file

@ -188,12 +188,6 @@ void ws2812_init(void) {
}
void ws2812_setleds(rgb_led_t* ledarray, uint16_t leds) {
static bool s_init = false;
if (!s_init) {
ws2812_init();
s_init = true;
}
for (uint8_t i = 0; i < leds; i++) {
set_led_color_rgb(ledarray[i], i);
}

View file

@ -151,6 +151,7 @@ rgb_led_t rgb_matrix_ws2812_array[WS2812_LED_COUNT];
bool ws2812_dirty = false;
static void init(void) {
ws2812_init();
ws2812_dirty = false;
}

View file

@ -247,6 +247,8 @@ void rgblight_init(void) {
rgblight_mode_noeeprom(rgblight_config.mode);
}
rgblight_driver.init();
is_rgblight_initialized = true;
}

View file

@ -7,6 +7,7 @@
# include "ws2812.h"
const rgblight_driver_t rgblight_driver = {
.init = ws2812_init,
.setleds = ws2812_setleds,
};
@ -14,6 +15,7 @@ const rgblight_driver_t rgblight_driver = {
# include "apa102.h"
const rgblight_driver_t rgblight_driver = {
.init = apa102_init,
.setleds = apa102_setleds,
};

View file

@ -7,6 +7,7 @@
#include "color.h"
typedef struct {
void (*init)(void);
void (*setleds)(rgb_led_t *ledarray, uint16_t number_of_leds);
} rgblight_driver_t;