summaryrefslogtreecommitdiff
path: root/keyboards/mxss/mxss.c
diff options
context:
space:
mode:
authorJumail Mundekkat <mundekkat@hotmail.com>2020-01-27 09:06:56 +1100
committerridingqwerty <george.g.koenig@gmail.com>2020-01-26 17:06:56 -0500
commit645c5fabf24411fe65d2172a3509c26e053651a2 (patch)
treebbba022ea3e1a9605f80fc4ca97c991dc941d4ed /keyboards/mxss/mxss.c
parent7f7b6b08e8afdd09f83b180e4c03b04f9a531035 (diff)
Add VIA support to MxSS, plus minor tweaks (#7809)
* Add VIA support to mxss and general cleanup * Add support for RGB test for FLEDs * Add LAYOUT_all to allow for more configuration * Remove blank layers * Updated readme * Improve use of EEPROM * Credit where its due * Use the latest iteration of rgblight code * Keep the RGB timer running if the front LED is in RGB mode * Fix RGB breathing animation * Better supported RGB animation Only thing not working is alternating, but that's not too important * Abstract front LED handlers from main kb code * Add support for indicator LED color changing * Remove debug statement * Persist indicator LED colors * Mark custom sections in rgblight.c * Light commenting * Fix up keymaps * Add/update comments * Remove bloat from default hex * Tidy a stray tab * Out with the old, in with the new * Out with the old, in with the new * Add LAYER_STATE_8BIT for VIA keymap
Diffstat (limited to 'keyboards/mxss/mxss.c')
-rw-r--r--keyboards/mxss/mxss.c205
1 files changed, 37 insertions, 168 deletions
diff --git a/keyboards/mxss/mxss.c b/keyboards/mxss/mxss.c
index 42ecdbc469..48ea466419 100644
--- a/keyboards/mxss/mxss.c
+++ b/keyboards/mxss/mxss.c
@@ -1,4 +1,4 @@
-/* Copyright 2018 Jumail Mundekkat / MxBlue
+/* 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
@@ -12,63 +12,29 @@
*
* 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 from ../cannonkeys/stm32f072/keyboard.c
*/
-
+
#include QMK_KEYBOARD_H
#include "tmk_core/common/eeprom.h"
#include "tmk_core/common/action_layer.h"
#include "rgblight.h"
+#include "via.h"
+#include "version.h" // for QMK_BUILDDATE used in EEPROM magic
-// Variables for controlling front LED application
-uint8_t fled_mode; // Mode for front LEDs
-uint8_t fled_val; // Brightness for front leds (0 - 255)
-LED_TYPE fleds[2]; // Front LED rgb values for indicator mode use
-
-// Predefined colors for layers
-// Format: {hue, saturation}
-// {0, 0} to turn off the LED
-// Add additional rows to handle more layers
-__attribute__ ((weak))
-const hs_set layer_colors[] = {
- [0] = {0, 0}, // Color for Layer 0
- [1] = {86, 255}, // Color for Layer 1
- [2] = {36, 255}, // Color for Layer 2
- [3] = {185, 255}, // Color for Layer 3
-};
-
-__attribute__ ((weak))
-const size_t lc_size = sizeof(layer_colors) / sizeof(uint16_t);
+void via_init_kb(void) {
+ fled_init();
+}
void matrix_init_kb(void) {
- // If EEPROM config exists, load it
- if (eeprom_is_valid()) {
- fled_config fled_conf;
- fled_conf.raw = eeprom_read_byte(EEPROM_FRONTLED_ADDR);
- fled_mode = fled_conf.mode;
- fled_val = fled_conf.val * FLED_VAL_STEP;
- // Else, default config
- } else {
- fled_mode = FLED_RGB;
- fled_val = 10 * FLED_VAL_STEP;
- eeprom_update_conf(); // Store default config to EEPROM
- }
-
- // Set default values for leds
- setrgb(0, 0, 0, &fleds[0]);
- setrgb(0, 0, 0, &fleds[1]);
-
- // Handle lighting for indicator mode
- if (fled_mode == FLED_INDI) {
- // Enable capslock led if enabled on host
- if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK))
- sethsv(FLED_CAPS_H, FLED_CAPS_S, fled_val, &fleds[0]);
-
- // Determine and set colour of layer LED according to current layer
- // if hue = sat = 0, leave LED off
- uint8_t layer = biton32(layer_state);
- if (layer < lc_size && !(layer_colors[layer].hue == 0 && layer_colors[layer].hue == 0))
- sethsv(layer_colors[layer].hue, layer_colors[layer].sat, fled_val, &fleds[1]);
- }
+ // If VIA is disabled, we still need to load settings
+ // Call via_init_kb() the same way as via_init(), with setting
+ // EEPROM valid afterwards.
+#ifndef VIA_ENABLE
+ fled_init();
+ via_eeprom_set_valid(true);
+#endif // VIA_ENABLE
matrix_init_user();
}
@@ -82,132 +48,35 @@ void matrix_scan_kb(void) {
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
// Handle custom keycodes for front LED operation
- switch (keycode) {
- case FLED_MOD: // Change between front LED operation modes (off, indicator, RGB)
- if (record->event.pressed)
- fled_mode_cycle();
- break;
-
- case FLED_VAI: // Increase the brightness of the front LEDs by FLED_VAL_STEP
- if (record->event.pressed)
- fled_val_increase();
- break;
-
- case FLED_VAD: // Decrease the brightness of the front LEDs by FLED_VAL_STEP
- if (record->event.pressed)
- fled_val_decrease();
- break;
-
- default:
- break; // Process all other keycodes normally
- }
-
+ process_record_fled(keycode, record);
return process_record_user(keycode, record);
}
-void led_set_kb(uint8_t usb_led) {
- // Set indicator LED appropriately, whether it is used or not
- if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
- sethsv(FLED_CAPS_H, FLED_CAPS_S, fled_val, &fleds[0]);
- } else {
- setrgb(0, 0, 0, &fleds[0]);
- }
-
- rgblight_set();
- led_set_user(usb_led);
-}
-
-uint32_t layer_state_set_kb(uint32_t state) {
- // Determine and set colour of layer LED according to current layer
- // if hue = sat = 0, leave LED off
- uint8_t layer = biton32(state);
-
- if (layer < lc_size && !(layer_colors[layer].hue == 0 && layer_colors[layer].hue == 0))
- sethsv(layer_colors[layer].hue, layer_colors[layer].sat, fled_val, &fleds[1]);
- else
- setrgb(0, 0, 0, &fleds[1]);
-
- return state;
-}
-
-// EEPROM Management
-
-// Test if magic value is present at expected location
-bool eeprom_is_valid(void)
-{
- return (eeprom_read_word(EEPROM_MAGIC_ADDR) == EEPROM_MAGIC);
-}
-
-// Set magic value at expected location
-void eeprom_set_valid(bool valid)
-{
- eeprom_update_word(EEPROM_MAGIC_ADDR, valid ? EEPROM_MAGIC : 0xFFFF);
+bool led_update_kb(led_t led_state) {
+ fled_lock_update(led_state);
+ return led_update_user(led_state);
}
-// Store current front led config in EEPROM
-void eeprom_update_conf(void)
-{
- // Create storage struct and set values
- fled_config conf;
- conf.mode = fled_mode;
-
- // Small hack to ensure max value is stored correctly
- if (fled_val == 255)
- conf.val = 256 / FLED_VAL_STEP;
- else
- conf.val = fled_val / FLED_VAL_STEP;
-
- // Set magic value and store config
- eeprom_set_valid(true);
- eeprom_update_byte(EEPROM_FRONTLED_ADDR, conf.raw);
+layer_state_t layer_state_set_kb(layer_state_t state) {
+ fled_layer_update(state);
+ return layer_state_set_user(state);
}
-// Custom keycode functions
+// Fallback eeprom functions if VIA is not enabled
+#ifndef VIA_ENABLE
-void fled_mode_cycle(void)
+// Sets VIA/keyboard level usage of EEPROM to valid/invalid
+// Keyboard level code (eg. via_init_kb()) should not call this
+void via_eeprom_set_valid(bool valid)
{
- // FLED -> FLED_RGB -> FLED_INDI
- switch (fled_mode) {
- case FLED_OFF:
- fled_mode = FLED_RGB;
- break;
-
- case FLED_RGB:
- fled_mode = FLED_INDI;
- break;
-
- case FLED_INDI:
- fled_mode = FLED_OFF;
- break;
- }
-
- // Update stored config
- eeprom_update_conf();
- rgblight_set();
+ char *p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54"
+ uint8_t magic0 = ( ( p[2] & 0x0F ) << 4 ) | ( p[3] & 0x0F );
+ uint8_t magic1 = ( ( p[5] & 0x0F ) << 4 ) | ( p[6] & 0x0F );
+ uint8_t magic2 = ( ( p[8] & 0x0F ) << 4 ) | ( p[9] & 0x0F );
+
+ eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+0, valid ? magic0 : 0xFF);
+ eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+1, valid ? magic1 : 0xFF);
+ eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+2, valid ? magic2 : 0xFF);
}
-void fled_val_increase(void)
-{
- // Increase val by FLED_VAL_STEP, handling the upper edge case
- if (fled_val + FLED_VAL_STEP > 255)
- fled_val = 255;
- else
- fled_val += FLED_VAL_STEP;
-
- // Update stored config
- eeprom_update_conf();
- rgblight_set();
-}
-
-void fled_val_decrease(void)
-{
- // Decrease val by FLED_VAL_STEP, handling the lower edge case
- if (fled_val - FLED_VAL_STEP > 255)
- fled_val = 255;
- else
- fled_val -= FLED_VAL_STEP;
-
- // Update stored config
- eeprom_update_conf();
- rgblight_set();
-}
+#endif