Skip to content

Commit

Permalink
Cleanup Satisfaction75 Firmware and add new revisions (#22082)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan <[email protected]>
Co-authored-by: Nick Brassel <[email protected]>
  • Loading branch information
3 people authored Feb 26, 2024
1 parent 0f701c7 commit 4906413
Show file tree
Hide file tree
Showing 46 changed files with 1,064 additions and 817 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "satisfaction75.h"
// Copyright 2023 Andrew Kannan
// SPDX-License-Identifier: GPL-2.0-or-later

#include "satisfaction_core.h"
#include "print.h"
#include "debug.h"

Expand Down Expand Up @@ -42,66 +45,27 @@ int8_t month_config = 0;
int8_t day_config = 0;
uint8_t previous_encoder_mode = 0;

backlight_config_t kb_backlight_config = {
.enable = true,
.breathing = true,
.level = BACKLIGHT_LEVELS
};

void board_init(void) {
SYSCFG->CFGR1 |= SYSCFG_CFGR1_I2C1_DMA_RMP;
SYSCFG->CFGR1 &= ~(SYSCFG_CFGR1_SPI2_DMA_RMP);
}

#ifdef VIA_ENABLE

void backlight_get_value( uint8_t *data )
{
uint8_t *value_id = &(data[0]);
uint8_t *value_data = &(data[1]);
switch (*value_id)
{
case id_qmk_backlight_brightness:
{
// level / BACKLIGHT_LEVELS * 255
value_data[0] = ((uint16_t)kb_backlight_config.level) * 255 / BACKLIGHT_LEVELS;
break;
}
case id_qmk_backlight_effect:
{
value_data[0] = kb_backlight_config.breathing ? 1 : 0;
break;
}
}
}

void backlight_set_value( uint8_t *data )
{
uint8_t *value_id = &(data[0]);
uint8_t *value_data = &(data[1]);
switch (*value_id)
{
case id_qmk_backlight_brightness:
{
// level / 255 * BACKLIGHT_LEVELS
kb_backlight_config.level = ((uint16_t)value_data[0]) * BACKLIGHT_LEVELS / 255;
backlight_set(kb_backlight_config.level);
break;
void keyboard_post_init_kb(){
/*
This is a workaround to some really weird behavior
Without this code, the OLED will turn on, but not when you initially plug the keyboard in.
You have to manually trigger a user reset to get the OLED to initialize properly
I'm not sure what the root cause is at this time, but this workaround fixes it.
*/
#ifdef OLED_ENABLE
if(!is_oled_on()){
wait_ms(3000);
oled_init(OLED_ROTATION_0);
}
case id_qmk_backlight_effect:
{
if ( value_data[0] == 0 ) {
kb_backlight_config.breathing = false;
breathing_disable();
} else {
kb_backlight_config.breathing = true;
breathing_enable();
}
break;
}
}
#endif
}

#ifdef VIA_ENABLE
void custom_set_value(uint8_t *data) {
uint8_t *value_id = &(data[0]);
uint8_t *value_data = &(data[1]);
Expand Down Expand Up @@ -171,43 +135,12 @@ void custom_get_value(uint8_t *data) {
}
}

// TODO
// Refactor so this keyboard uses QMK Core backlight code,
// then change this to via_custom_value_command_kb() so it
// only handles the custom values not the backlight
// (i.e. use QMK Core default handler for backlight values).
//
void via_custom_value_command(uint8_t *data, uint8_t length) {
void via_custom_value_command_kb(uint8_t *data, uint8_t length) {
uint8_t *command_id = &(data[0]);
uint8_t *channel_id = &(data[1]);
uint8_t *value_id_and_data = &(data[2]);

if ( *channel_id == id_qmk_backlight_channel ) {
switch ( *command_id )
{
case id_custom_set_value:
{
backlight_set_value(value_id_and_data);
break;
}
case id_custom_get_value:
{
backlight_get_value(value_id_and_data);
break;
}
case id_custom_save:
{
backlight_config_save();
break;
}
default:
{
// Unhandled message.
*command_id = id_unhandled;
break;
}
}
} else if ( *channel_id == id_custom_channel ) {
if ( *channel_id == id_custom_channel ) {
switch ( *command_id )
{
case id_custom_set_value:
Expand Down Expand Up @@ -361,12 +294,7 @@ void custom_config_reset(void){
eeprom_update_byte((uint8_t*)EEPROM_ENABLED_ENCODER_MODES, 0x1F);
}

void backlight_config_save(void){
eeprom_update_byte((uint8_t*)EEPROM_CUSTOM_BACKLIGHT, kb_backlight_config.raw);
}

void custom_config_load(void){
kb_backlight_config.raw = eeprom_read_byte((uint8_t*)EEPROM_CUSTOM_BACKLIGHT);
#ifdef DYNAMIC_KEYMAP_ENABLE
oled_mode = eeprom_read_byte((uint8_t*)EEPROM_DEFAULT_OLED);
enabled_encoder_modes = eeprom_read_byte((uint8_t*)EEPROM_ENABLED_ENCODER_MODES);
Expand Down Expand Up @@ -398,7 +326,6 @@ void matrix_init_kb(void)
#endif // VIA_ENABLE

rtcGetTime(&RTCD1, &last_timespec);
backlight_init_ports();
matrix_init_user();
oled_request_wakeup();
}
Expand Down
101 changes: 101 additions & 0 deletions keyboards/cannonkeys/lib/satisfaction75/satisfaction_core.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright 2023 Andrew Kannan
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include "quantum.h"

#include "via.h" // only for EEPROM address
#include "satisfaction_keycodes.h"

#define EEPROM_ENABLED_ENCODER_MODES (VIA_EEPROM_CUSTOM_CONFIG_ADDR)
#define EEPROM_DEFAULT_OLED (VIA_EEPROM_CUSTOM_CONFIG_ADDR+1)
#define EEPROM_CUSTOM_ENCODER (VIA_EEPROM_CUSTOM_CONFIG_ADDR+2)

enum s75_keyboard_value_id {
id_encoder_modes = 1,
id_oled_default_mode,
id_encoder_custom,
id_oled_mode
};

enum encoder_modes {
ENC_MODE_VOLUME,
ENC_MODE_MEDIA,
ENC_MODE_SCROLL,
ENC_MODE_BRIGHTNESS,
ENC_MODE_BACKLIGHT,
ENC_MODE_CUSTOM0,
ENC_MODE_CUSTOM1,
ENC_MODE_CUSTOM2,
_NUM_ENCODER_MODES,
ENC_MODE_CLOCK_SET // This shouldn't be included in the default modes, so we put it after NUM_ENCODER_MODES
};

enum custom_encoder_behavior {
ENC_CUSTOM_CW = 0,
ENC_CUSTOM_CCW,
ENC_CUSTOM_PRESS
};

enum oled_modes {
OLED_DEFAULT,
OLED_TIME,
OLED_OFF,
_NUM_OLED_MODES
};


// Keyboard Information
extern volatile uint8_t led_numlock;
extern volatile uint8_t led_capslock;
extern volatile uint8_t led_scrolllock;
extern uint8_t layer;

// OLED Behavior
extern uint8_t oled_mode;
extern bool oled_repaint_requested;
extern bool oled_wakeup_requested;
extern uint32_t oled_sleep_timer;

// Encoder Behavior
extern uint8_t encoder_value;
extern uint8_t encoder_mode;
extern uint8_t enabled_encoder_modes;

// RTC
extern RTCDateTime last_timespec;
extern uint16_t last_minute;

// RTC Configuration
extern bool clock_set_mode;
extern uint8_t time_config_idx;
extern int8_t hour_config;
extern int16_t minute_config;
extern int8_t year_config;
extern int8_t month_config;
extern int8_t day_config;
extern uint8_t previous_encoder_mode;

// Backlighting
#ifdef BACKLIGHT_ENABLE
extern backlight_config_t kb_backlight_config;
extern bool kb_backlight_breathing;
#endif

void pre_encoder_mode_change(void);
void post_encoder_mode_change(void);
void change_encoder_mode(bool negative);
uint16_t handle_encoder_clockwise(void);
uint16_t handle_encoder_ccw(void);
uint16_t handle_encoder_press(void);
uint16_t retrieve_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior);
void set_custom_encoder_config(uint8_t encoder_idx, uint8_t behavior, uint16_t new_code);

void update_time_config(int8_t increment);

void oled_request_wakeup(void);
void oled_request_repaint(void);
bool oled_task_needs_to_repaint(void);

void custom_config_load(void);
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "satisfaction75.h"
// Copyright 2023 Andrew Kannan
// SPDX-License-Identifier: GPL-2.0-or-later

#include "satisfaction_core.h"
#include "eeprom.h"

void pre_encoder_mode_change(void){
Expand All @@ -11,8 +14,6 @@ void pre_encoder_mode_change(void){
// timespec.dstflag = last_timespec.dstflag;
timespec.millisecond = (hour_config * 60 + minute_config) * 60 * 1000;
rtcSetTime(&RTCD1, &timespec);
} else if (encoder_mode == ENC_MODE_BACKLIGHT){
backlight_config_save();
}
}

Expand Down Expand Up @@ -99,16 +100,14 @@ uint16_t handle_encoder_clockwise(void){
case ENC_MODE_SCROLL:
mapped_code = KC_WH_D;
break;
#ifdef BACKLIGHT_ENABLE
case ENC_MODE_BACKLIGHT:
kb_backlight_config.level = kb_backlight_config.level + 1;
if(kb_backlight_config.level > BACKLIGHT_LEVELS){
kb_backlight_config.level = BACKLIGHT_LEVELS;
}
backlight_set(kb_backlight_config.level);
if (kb_backlight_config.level != 0){
kb_backlight_config.enable = true;
backlight_increase();
if(get_backlight_level() != 0){
backlight_enable();
}
break;
#endif
case ENC_MODE_BRIGHTNESS:
mapped_code = KC_BRIGHTNESS_UP;
break;
Expand Down Expand Up @@ -143,16 +142,14 @@ uint16_t handle_encoder_ccw(void){
case ENC_MODE_SCROLL:
mapped_code = KC_WH_U;
break;
#ifdef BACKLIGHT_ENABLE
case ENC_MODE_BACKLIGHT:
// mapped_code = BL_DOWN;
if(kb_backlight_config.level != 0){
kb_backlight_config.level = kb_backlight_config.level - 1;
}
backlight_set(kb_backlight_config.level);
if (kb_backlight_config.level == 0){
kb_backlight_config.enable = false;
backlight_decrease();
if(get_backlight_level() == 0){
backlight_disable();
}
break;
#endif
case ENC_MODE_BRIGHTNESS:
mapped_code = KC_BRIGHTNESS_DOWN;
break;
Expand Down Expand Up @@ -188,15 +185,11 @@ uint16_t handle_encoder_press(void){
case ENC_MODE_SCROLL:
mapped_code = KC_BTN3;
break;
#ifdef BACKLIGHT_ENABLE
case ENC_MODE_BACKLIGHT:
// mapped_code = BL_TOGG;
kb_backlight_config.breathing = !kb_backlight_config.breathing;
if(!kb_backlight_config.breathing){
breathing_disable();
} else{
breathing_enable();
}
breathing_toggle();
break;
#endif
#ifdef DYNAMIC_KEYMAP_ENABLE
case ENC_MODE_CUSTOM0:
mapped_code = retrieve_custom_encoder_config(0, ENC_CUSTOM_PRESS);
Expand Down
10 changes: 10 additions & 0 deletions keyboards/cannonkeys/lib/satisfaction75/satisfaction_keycodes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2023 Andrew Kannan
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

enum my_keycodes {
ENC_PRESS = QK_KB_0,
CLOCK_SET,
OLED_TOGG
};
Loading

0 comments on commit 4906413

Please sign in to comment.