Skip to content

Commit

Permalink
Un-extern RGBLight led[] array (#23322)
Browse files Browse the repository at this point in the history
  • Loading branch information
fauxpark authored Mar 22, 2024
1 parent c038292 commit 583cde3
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 188 deletions.
15 changes: 0 additions & 15 deletions docs/feature_rgblight.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,27 +356,12 @@ Usually lighting layers apply their configured brightness once activated. If you

If you need to change your RGB lighting in code, for example in a macro to change the color whenever you switch layers, QMK provides a set of functions to assist you. See [`rgblight.h`](https://github.com/qmk/qmk_firmware/blob/master/quantum/rgblight/rgblight.h) for the full list, but the most commonly used functions include:

### Utility Functions
|Function |Description |
|--------------------------------------------|-------------------------------------------------------------------|
|`sethsv(hue, sat, val, ledbuf)` |Set ledbuf to the given HSV value |
|`sethsv_raw(hue, sat, val, ledbuf)` |Set ledbuf to the given HSV value without RGBLIGHT_LIMIT_VAL check |
|`setrgb(r, g, b, ledbuf)` |Set ledbuf to the given RGB value where `r`/`g`/`b` |

### Low level Functions
|Function |Description |
|--------------------------------------------|-------------------------------------------|
|`rgblight_set()` |Flush out led buffers to LEDs |
|`rgblight_set_clipping_range(pos, num)` |Set clipping Range. see [Clipping Range](#clipping-range) |

Example:
```c
sethsv(HSV_WHITE, (rgb_led_t *)&led[0]); // led 0
sethsv(HSV_RED, (rgb_led_t *)&led[1]); // led 1
sethsv(HSV_GREEN, (rgb_led_t *)&led[2]); // led 2
rgblight_set(); // Utility functions do not call rgblight_set() automatically, so they need to be called explicitly.
```
### Effects and Animations Functions
#### effect range setting
|Function |Description |
Expand Down
5 changes: 1 addition & 4 deletions keyboards/hineybush/hbcp/hbcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,9 @@ void keyboard_post_init_user(void) {

__attribute__ ((weak))
void hbcp_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end) {
rgb_led_t tmp_led;
sethsv_raw(hue, sat, val, &tmp_led);
for (uint8_t i = start; i < end; i++) {
led[i] = tmp_led;
rgblight_sethsv_at(hue, sat, val, i);
}
rgblight_set();
}

#endif
50 changes: 6 additions & 44 deletions keyboards/hineybush/hbcp/keymaps/hiney/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@
*/
#include QMK_KEYBOARD_H

// Defines the keycodes used by our macros in process_record_user
enum custom_keycodes {
QMKBEST = SAFE_RANGE,
ALTCUT,
QMKURL
};

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

[0] = LAYOUT_wkl( /* Base */
Expand All @@ -45,55 +38,24 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
),
};

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case ALTCUT:
if (record->event.pressed) {
// when keycode QMKBEST is pressed
send_string_with_delay_P(PSTR(SS_TAP(X_TAB)SS_TAP(X_T)SS_TAP(X_V)SS_TAP(X_B)), 20); // altium macro
} else {
// when keycode QMKBEST is released
}
break;
case QMKURL:
if (record->event.pressed) {
// when keycode QMKURL is pressed
SEND_STRING("https://qmk.fm/" SS_TAP(X_ENTER));
} else {
// when keycode QMKURL is released
}
break;
}
return true;
}

void matrix_init_user(void) {

}

void matrix_scan_user(void) {

}

#ifdef RGBLIGHT_ENABLE
// The first three LEDs are used as indicators for CAPS_LOCK, NUM_LOCK and SCROLL_LOCK.
bool led_update_user(led_t led_state) {
if (led_state.caps_lock) {
sethsv_raw(HSV_SOFT_RED, (rgb_led_t *)&led[0]);
rgblight_sethsv_at(HSV_SOFT_RED, 0);
} else {
sethsv(HSV_BLACK, (rgb_led_t *)&led[0]);
rgblight_sethsv_at(HSV_BLACK, 0);
}
if (led_state.num_lock) {
sethsv_raw(HSV_WARM_WHITE, (rgb_led_t *)&led[1]);
rgblight_sethsv_at(HSV_WARM_WHITE, 1);
} else {
sethsv(HSV_BLACK, (rgb_led_t *)&led[1]);
rgblight_sethsv_at(HSV_BLACK, 1);
}
if (led_state.scroll_lock) {
sethsv_raw(HSV_SOFT_BLUE, (rgb_led_t *)&led[2]);
rgblight_sethsv_at(HSV_SOFT_BLUE, 2);
} else {
sethsv(HSV_BLACK, (rgb_led_t *)&led[2]);
rgblight_sethsv_at(HSV_BLACK, 2);
}
rgblight_set();
return false;
}

Expand Down
3 changes: 1 addition & 2 deletions keyboards/neson_design/nico/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"pin": "B0"
},
"rgblight": {
"led_count": 5,
"driver": "custom"
"led_count": 5
},
"url": "",
"usb": {
Expand Down
90 changes: 0 additions & 90 deletions keyboards/neson_design/nico/nico.c

This file was deleted.

1 change: 0 additions & 1 deletion keyboards/neson_design/nico/rules.mk
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
WS2812_DRIVER_REQUIRED = yes
16 changes: 0 additions & 16 deletions keyboards/snes_macropad/snes_macropad.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,6 @@ static void setupForFlashing(void) {

// Force data to be rendered
oled_render_dirty(true);

// Set alternating backlight colors
const uint8_t max = 20;
rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
for (size_t i = 0; i < RGBLIGHT_LED_COUNT; ++i) {
rgb_led_t *led_ = (rgb_led_t *)&led[i];
switch (i % 2) {
case 0:
setrgb(max, 0, max, led_);
break;
case 1:
setrgb(0, max, max, led_);
break;
}
}
rgblight_set();
}

bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
Expand Down
18 changes: 9 additions & 9 deletions quantum/rgblight/rgblight.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ __attribute__((weak)) RGB rgblight_hsv_to_rgb(HSV hsv) {
return hsv_to_rgb(hsv);
}

void setrgb(uint8_t r, uint8_t g, uint8_t b, rgb_led_t *led1) {
led1->r = r;
led1->g = g;
led1->b = b;
#ifdef RGBW
led1->w = 0;
#endif
}

void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, rgb_led_t *led1) {
HSV hsv = {hue, sat, val};
RGB rgb = rgblight_hsv_to_rgb(hsv);
Expand All @@ -155,15 +164,6 @@ void sethsv(uint8_t hue, uint8_t sat, uint8_t val, rgb_led_t *led1) {
sethsv_raw(hue, sat, val > RGBLIGHT_LIMIT_VAL ? RGBLIGHT_LIMIT_VAL : val, led1);
}

void setrgb(uint8_t r, uint8_t g, uint8_t b, rgb_led_t *led1) {
led1->r = r;
led1->g = g;
led1->b = b;
#ifdef RGBW
led1->w = 0;
#endif
}

void rgblight_check_config(void) {
/* Add some out of bound checks for RGB light config */

Expand Down
7 changes: 0 additions & 7 deletions quantum/rgblight/rgblight.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,6 @@ void rgblight_unblink_all_but_layer(uint8_t layer);

#endif

extern rgb_led_t led[RGBLIGHT_LED_COUNT];

extern const uint8_t RGBLED_BREATHING_INTERVALS[4] PROGMEM;
extern const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[3] PROGMEM;
extern const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[3] PROGMEM;
Expand Down Expand Up @@ -290,11 +288,6 @@ typedef struct _rgblight_ranges_t {

extern rgblight_ranges_t rgblight_ranges;

/* === Utility Functions ===*/
void sethsv(uint8_t hue, uint8_t sat, uint8_t val, rgb_led_t *led1);
void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, rgb_led_t *led1); // without RGBLIGHT_LIMIT_VAL check
void setrgb(uint8_t r, uint8_t g, uint8_t b, rgb_led_t *led1);

/* === Low level Functions === */
void rgblight_set(void);
void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds);
Expand Down

0 comments on commit 583cde3

Please sign in to comment.