Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup Satisfaction75 Firmware and add new revisions #22082

Merged
merged 29 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6b6eba1
Save progress on Sat75 redo firmware
awkannan Jun 19, 2023
ed6a2c5
Add hacky workaround for OLED reliability
awkannan Jun 19, 2023
7ae3cb9
Update Sat75 HS and make common lib
awkannan Sep 14, 2023
54e81ac
Update sat75v2 to point to common folder
awkannan Sep 14, 2023
07a8c4b
Make changes for master
awkannan Sep 14, 2023
6b46c43
Update sat core lib to work with VIA again
awkannan Sep 20, 2023
f74fa62
Move oled on to info.json from rules
awkannan Sep 20, 2023
9a34c90
a bit more cleanup of keycodes
awkannan Sep 20, 2023
4313471
Make names common
awkannan Sep 20, 2023
94bbf8e
Add layout to indicate full BS matrix pos
awkannan Sep 20, 2023
161657c
Add layout to indicate matrix positions for non-hs PCB
awkannan Sep 20, 2023
94ed704
invert encoder pins Sat75v2 hS
awkannan Sep 20, 2023
285cf31
change it back it was right before
awkannan Sep 20, 2023
07ca553
Unify all solderable Sat75s into one folder
awkannan Sep 20, 2023
83a39a2
Update readmes
awkannan Sep 20, 2023
0b255d7
Remove Sat75v2 folder now that rev2 exists
awkannan Sep 20, 2023
ec18aff
Some final cleanup
awkannan Sep 20, 2023
70c3f61
remove blank layers on rev2 via keymap
awkannan Sep 20, 2023
19fb0c5
A bit more cleanup
awkannan Sep 20, 2023
b097e80
a bit more cleanup
awkannan Sep 20, 2023
dd11506
remove dead variable
awkannan Sep 20, 2023
474a99f
Reformat JSONs
awkannan Sep 20, 2023
3f5e568
remove TODO now that it's done
awkannan Sep 20, 2023
9f3edc4
License headers, remove some unnecessary defines
awkannan Sep 21, 2023
d5bcf43
Move keymap imports to keyboard header
awkannan Sep 24, 2023
f900014
remove oled define
awkannan Sep 24, 2023
d2f4ff0
Apply suggestions from code review
Oct 23, 2023
6b46079
Move user keymaps into rev1 folder
awkannan Feb 26, 2024
1988add
Merge branch 'develop' into 202306_sat75_redo_firmware
tzarc Feb 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
// 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_CUSTOM_BACKLIGHT (VIA_EEPROM_CUSTOM_CONFIG_ADDR+1)
#define EEPROM_DEFAULT_OLED (VIA_EEPROM_CUSTOM_CONFIG_ADDR+2)
#define EEPROM_CUSTOM_ENCODER (VIA_EEPROM_CUSTOM_CONFIG_ADDR+3)

typedef union {
uint8_t raw;
struct {
bool enable :1;
bool breathing : 1;
uint8_t level :6;
};
} backlight_config_t;

// Start these at the USER code range in VIA
enum my_keycodes {
ENC_PRESS = QK_KB_0,
CLOCK_SET,
OLED_TOGG
};
#define EEPROM_DEFAULT_OLED (VIA_EEPROM_CUSTOM_CONFIG_ADDR+1)
#define EEPROM_CUSTOM_ENCODER (VIA_EEPROM_CUSTOM_CONFIG_ADDR+2)

enum s75_custom_value_id {
enum s75_keyboard_value_id {
id_encoder_modes = 1,
id_oled_default_mode,
id_encoder_custom,
Expand Down Expand Up @@ -90,8 +78,10 @@ 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);
Expand All @@ -108,10 +98,4 @@ void oled_request_wakeup(void);
void oled_request_repaint(void);
bool oled_task_needs_to_repaint(void);

void backlight_init_ports(void);
void backlight_set(uint8_t level);
bool is_breathing(void);
void breathing_enable(void);
void breathing_disable(void);
void custom_config_load(void);
void backlight_config_save(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
awkannan marked this conversation as resolved.
Show resolved Hide resolved

enum my_keycodes {
ENC_PRESS = QK_KB_0,
CLOCK_SET,
OLED_TOGG
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include "satisfaction75.h"
// Copyright 2023 Andrew Kannan
// SPDX-License-Identifier: GPL-2.0-or-later

#include "satisfaction_core.h"
#include <stdio.h>

void draw_default(void);
void draw_clock(void);
Expand All @@ -15,7 +19,7 @@ bool oled_task_kb(void) {
oled_clear();
if (clock_set_mode) {
draw_clock();
return false;;
return false;
}
switch (oled_mode) {
default:
Expand Down Expand Up @@ -145,8 +149,8 @@ static char* get_time(void) {
hour = 12;
}

static char time_str[11] = "";
sprintf(time_str, "%02d:%02d%s", hour, minute, is_pm ? "pm" : "am");
static char time_str[8] = "";
snprintf(time_str, sizeof(time_str), "%02hhu:%02hu%s", hour, minute, is_pm ? "pm" : "am");

return time_str;
}
Expand All @@ -162,8 +166,8 @@ static char* get_date(void) {
day = day_config;
}

static char date_str[15] = "";
sprintf(date_str, "%04d-%02d-%02d", year, month, day);
static char date_str[11] = "";
snprintf(date_str, sizeof(date_str), "%04hd-%02hhd-%02hhd", year, month, day);

return date_str;
}
Expand Down Expand Up @@ -264,4 +268,12 @@ void draw_clock(void) {
draw_line_v(113, 8, 8);
}

#endif
#else

void oled_request_repaint(void){
}

void oled_request_wakeup(void){
}

#endif
17 changes: 2 additions & 15 deletions keyboards/cannonkeys/satisfaction75/chconf.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/* Copyright 2020 QMK
*
* 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/>.
*/
// Copyright 2023 Andrew Kannan (@awkannan)
// SPDX-License-Identifier: GPL-2.0-or-later

/*
* This file was auto-generated by:
Expand Down
Loading