summaryrefslogtreecommitdiffstats
path: root/keyboards/mxss/mxss_frontled.h
blob: c8d4199d4780fb323e505a41d7a817ef7b5c7cb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* Copyright 2020 Jumail Mundekkat / MxBlue
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// EEPROM management code taken from Wilba6582
// https://github.com/Wilba6582/qmk_firmware/blob/zeal60/keyboards/zeal60/zeal_eeprom.h

#pragma once

#include "quantum.h"
#include "quantum_keycodes.h"
#include "via.h"

// RGBLED index for front LEDs
#define RGBLIGHT_FLED1 14
#define RGBLIGHT_FLED2 15

// Brightness increase step for front LEDs
#define FLED_VAL_STEP 8

// Front LED settings
#define FRONTLED_CONF_ADDR ((uint8_t*) VIA_EEPROM_CUSTOM_CONFIG_ADDR)
#define FRONTLED_COLOR_CNT_ADDR (FRONTLED_CONF_ADDR + 1)
#define FRONTLED_COLOR_ADDR ((uint16_t*)(FRONTLED_COLOR_CNT_ADDR + 1))

// No point persisting more 4, VIA only allows editing of 3 + 1 for caps
#define FRONTLED_COLOR_MAXCNT 4

// Modes for front LEDs
#define FLED_OFF    0b00
#define FLED_INDI   0b01
#define FLED_RGB    0b10
#define FLED_UNDEF  0b11

// Config storage format for EEPROM
typedef union {
  uint8_t raw;
  struct {
    uint8_t  mode    :2;
    uint8_t  val     :6;
  };
} fled_config;

// Structure to store hue and saturation values
typedef union {
    uint16_t raw;
    struct {
        uint8_t hue;
        uint8_t sat;
    };
} hs_set;

// Custom keycodes for front LED control
enum fled_keycodes {
    FLED_MOD = QK_KB_0, // QK_KB_0 = VIA custom keycode start
    FLED_VAI,
    FLED_VAD,
};

void fled_init(void);                // Run init functions for front LEDs
void process_record_fled(uint16_t keycode, keyrecord_t* record); // Process keycodes for front LEDs
void fled_load_conf(void);          // Load front LED config from EEPROM
void fled_update_conf(void);        // Store current front LED config to EEPROM

void fled_mode_cycle(void);         // Cycle between the 3 modes for the front LEDs
void fled_val_increase(void);       // Increase the brightness of the front LEDs
void fled_val_decrease(void);       // Decrease the brightness of the front LEDs

void fled_layer_update(layer_state_t state);   // Process layer update for front LEDs
void fled_lock_update(led_t led_state);     // Process lock update for front LEDs

void set_fled_layer_color(uint8_t layer, hs_set hs); // Set color for a given layer
void set_fled_caps_color(hs_set hs);        // Set color for the capslock indicator
hs_set get_fled_caps_color(void);           // Get color for the capslock indicator
hs_set get_fled_layer_color(uint8_t layer);       // Get color for a given layer