Skip to content

Commit

Permalink
Add _DEFAULT_ON lighting configuration options (qmk#21865)
Browse files Browse the repository at this point in the history
  • Loading branch information
zvecr authored and Lorenzo Castoldi committed Dec 27, 2023
1 parent e836fb5 commit 0c5948a
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 10 deletions.
3 changes: 2 additions & 1 deletion docs/feature_backlight.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ Add the following to your `config.h`:
|`BREATHING_PERIOD` |`6` |The length of one backlight "breath" in seconds |
|`BACKLIGHT_ON_STATE` |`1` |The state of the backlight pin when the backlight is "on" - `1` for high, `0` for low |
|`BACKLIGHT_LIMIT_VAL` |`255` |The maximum duty cycle of the backlight -- `255` allows for full brightness, any lower will decrease the maximum.|
|`BACKLIGHT_DEFAULT_ON` |`true` |Enable backlight upon clearing the EEPROM |
|`BACKLIGHT_DEFAULT_BREATHING`|`false` |Whether to enable backlight breathing upon clearing the EEPROM |
|`BACKLIGHT_DEFAULT_LEVEL` |`BACKLIGHT_LEVELS`|The default backlight level to use upon clearing the EEPROM |
|`BACKLIGHT_DEFAULT_BREATHING`|*Not defined* |Whether to enable backlight breathing upon clearing the EEPROM |
|`BACKLIGHT_PWM_PERIOD` |2048Hz |Defaults to `BACKLIGHT_PWM_COUNTER_FREQUENCY / 2048`, which results in a PWM frequency of 2048Hz. |

Unless you are designing your own keyboard, you generally should not need to change the `BACKLIGHT_PIN` or `BACKLIGHT_ON_STATE`.
Expand Down
1 change: 1 addition & 0 deletions docs/feature_led_matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ For inspiration and examples, check out the built-in effects under `quantum/led_
#define LED_MATRIX_LED_PROCESS_LIMIT (LED_MATRIX_LED_COUNT + 4) / 5 // limits the number of LEDs to process in an animation per task run (increases keyboard responsiveness)
#define LED_MATRIX_LED_FLUSH_LIMIT 16 // limits in milliseconds how frequently an animation will update the LEDs. 16 (16ms) is equivalent to limiting to 60fps (increases keyboard responsiveness)
#define LED_MATRIX_MAXIMUM_BRIGHTNESS 255 // limits maximum brightness of LEDs
#define LED_MATRIX_DEFAULT_ON true // Sets the default enabled state, if none has been set
#define LED_MATRIX_DEFAULT_MODE LED_MATRIX_SOLID // Sets the default mode, if none has been set
#define LED_MATRIX_DEFAULT_VAL LED_MATRIX_MAXIMUM_BRIGHTNESS // Sets the default brightness value, if none has been set
#define LED_MATRIX_DEFAULT_SPD 127 // Sets the default animation speed, if none has been set
Expand Down
1 change: 1 addition & 0 deletions docs/feature_rgb_matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,7 @@ These are defined in [`color.h`](https://github.com/qmk/qmk_firmware/blob/master
#define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT // Sets the default mode, if none has been set
#define RGB_MATRIX_DEFAULT_HUE 0 // Sets the default hue value, if none has been set
#define RGB_MATRIX_DEFAULT_SAT 255 // Sets the default saturation value, if none has been set
#define RGB_MATRIX_DEFAULT_ON true // Sets the default enabled state, if none has been set
#define RGB_MATRIX_DEFAULT_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS // Sets the default brightness value, if none has been set
#define RGB_MATRIX_DEFAULT_SPD 127 // Sets the default animation speed, if none has been set
#define RGB_MATRIX_DISABLE_KEYCODES // disables control of rgb matrix by keycodes (must use code functions to control the feature)
Expand Down
21 changes: 14 additions & 7 deletions quantum/backlight/backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

backlight_config_t backlight_config;

#ifndef BACKLIGHT_DEFAULT_ON
# define BACKLIGHT_DEFAULT_ON true
#endif

#ifndef BACKLIGHT_DEFAULT_LEVEL
# define BACKLIGHT_DEFAULT_LEVEL BACKLIGHT_LEVELS
#endif

#ifndef BACKLIGHT_DEFAULT_BREATHING
# define BACKLIGHT_DEFAULT_BREATHING false
#else
# undef BACKLIGHT_DEFAULT_BREATHING
# define BACKLIGHT_DEFAULT_BREATHING true
#endif

#ifdef BACKLIGHT_BREATHING
// TODO: migrate to backlight_config_t
static uint8_t breathing_period = BREATHING_PERIOD;
Expand Down Expand Up @@ -172,13 +183,9 @@ void eeconfig_update_backlight_current(void) {
}

void eeconfig_update_backlight_default(void) {
backlight_config.enable = 1;
#ifdef BACKLIGHT_DEFAULT_BREATHING
backlight_config.breathing = 1;
#else
backlight_config.breathing = 0;
#endif
backlight_config.level = BACKLIGHT_DEFAULT_LEVEL;
backlight_config.enable = BACKLIGHT_DEFAULT_ON;
backlight_config.breathing = BACKLIGHT_DEFAULT_BREATHING;
backlight_config.level = BACKLIGHT_DEFAULT_LEVEL;
eeconfig_update_backlight(backlight_config.raw);
}

Expand Down
2 changes: 1 addition & 1 deletion quantum/led_matrix/led_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void eeconfig_update_led_matrix(void) {

void eeconfig_update_led_matrix_default(void) {
dprintf("eeconfig_update_led_matrix_default\n");
led_matrix_eeconfig.enable = 1;
led_matrix_eeconfig.enable = LED_MATRIX_DEFAULT_ON;
led_matrix_eeconfig.mode = LED_MATRIX_DEFAULT_MODE;
led_matrix_eeconfig.val = LED_MATRIX_DEFAULT_VAL;
led_matrix_eeconfig.speed = LED_MATRIX_DEFAULT_SPD;
Expand Down
4 changes: 4 additions & 0 deletions quantum/led_matrix/led_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
# define LED_MATRIX_SPD_STEP 16
#endif

#ifndef LED_MATRIX_DEFAULT_ON
# define LED_MATRIX_DEFAULT_ON true
#endif

#ifndef LED_MATRIX_DEFAULT_MODE
# define LED_MATRIX_DEFAULT_MODE LED_MATRIX_SOLID
#endif
Expand Down
2 changes: 1 addition & 1 deletion quantum/rgb_matrix/rgb_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void eeconfig_update_rgb_matrix(void) {

void eeconfig_update_rgb_matrix_default(void) {
dprintf("eeconfig_update_rgb_matrix_default\n");
rgb_matrix_config.enable = 1;
rgb_matrix_config.enable = RGB_MATRIX_DEFAULT_ON;
rgb_matrix_config.mode = RGB_MATRIX_DEFAULT_MODE;
rgb_matrix_config.hsv = (HSV){RGB_MATRIX_DEFAULT_HUE, RGB_MATRIX_DEFAULT_SAT, RGB_MATRIX_DEFAULT_VAL};
rgb_matrix_config.speed = RGB_MATRIX_DEFAULT_SPD;
Expand Down
4 changes: 4 additions & 0 deletions quantum/rgb_matrix/rgb_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
# define RGB_MATRIX_SPD_STEP 16
#endif

#ifndef RGB_MATRIX_DEFAULT_ON
# define RGB_MATRIX_DEFAULT_ON true
#endif

#ifndef RGB_MATRIX_DEFAULT_MODE
# ifdef ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
# define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT
Expand Down

0 comments on commit 0c5948a

Please sign in to comment.