Skip to content

Commit

Permalink
fix: improper usage of keyboard/user-level functions (qmk#22652)
Browse files Browse the repository at this point in the history
  • Loading branch information
lesshonor authored and mechlovin committed Jan 17, 2024
1 parent ed9560b commit bf26a3e
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 158 deletions.
50 changes: 28 additions & 22 deletions keyboards/aeboards/ext65/rev2/rev2.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@
#include "quantum.h"

// Tested and verified working on ext65rev2
void matrix_io_delay(void) { __asm__ volatile("nop\nnop\nnop\n"); }
void matrix_io_delay(void) {
__asm__ volatile("nop\nnop\nnop\n");
}

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

oled_rotation_t oled_init_kb(oled_rotation_t rotation) {
return OLED_ROTATION_90; // rotates the display 90 degrees
return OLED_ROTATION_90; // rotates the display 90 degrees
}

void render_layer_state(void) {
Expand Down Expand Up @@ -55,26 +57,31 @@ void render_mod_status(uint8_t modifiers) {
}

bool oled_task_kb(void) {
if (!oled_task_user()) {
return false;
}
render_layer_state();
render_keylock_status(host_keyboard_led_state());
render_mod_status(get_mods()|get_oneshot_mods());
return false;
render_mod_status(get_mods() | get_oneshot_mods());
return true;
}

#else

void keyboard_pre_init_user(void) {
// Call the keyboard pre init code.
// Set our LED pins as output
setPinOutput(B4);
setPinOutput(B3);
setPinOutput(A15);
setPinOutput(A14);
void keyboard_pre_init_kb(void) {
// Call the keyboard pre init code.
// Set our LED pins as output
setPinOutput(B4);
setPinOutput(B3);
setPinOutput(A15);
setPinOutput(A14);

keyboard_pre_init_user();
}

bool led_update_kb(led_t led_state) {
bool res = led_update_user(led_state);
if(res) {
if (res) {
writePin(B4, led_state.num_lock);
writePin(B3, led_state.caps_lock);
writePin(A15, led_state.scroll_lock);
Expand All @@ -84,14 +91,13 @@ bool led_update_kb(led_t led_state) {

layer_state_t layer_state_set_kb(layer_state_t state) {
switch (get_highest_layer(state)) {
case 1:
writePinHigh(A14);
break;
default: // for any other layers, or the default layer
writePinLow(A14);
break;
}
case 1:
writePinHigh(A14);
break;
default: // for any other layers, or the default layer
writePinLow(A14);
break;
}
return layer_state_set_user(state);
}
#endif

32 changes: 19 additions & 13 deletions keyboards/dumbpad/v1x_oled/v1x_oled.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
char wpm_str[10];

#ifdef ENCODER_ENABLE
bool encoder_update_user(uint8_t index, bool clockwise) {
bool encoder_update_kb(uint8_t index, bool clockwise) {
if (!encoder_update_user(index, clockwise)) {
return false;
}
// Right encoder
if (index == 0) {
if (clockwise) {
Expand All @@ -42,16 +45,16 @@ bool encoder_update_user(uint8_t index, bool clockwise) {
#ifdef OLED_ENABLE
// WPM-responsive animation stuff here
# define IDLE_FRAMES 5
# define IDLE_SPEED 20 // below this wpm value your animation will idle
# define IDLE_SPEED 20 // below this wpm value your animation will idle

// #define PREP_FRAMES 1 // uncomment if >1

# define TAP_FRAMES 2
# define TAP_SPEED 40 // above this wpm value typing animation to trigger
# define TAP_SPEED 40 // above this wpm value typing animation to trigger

# define ANIM_FRAME_DURATION 200 // how long each frame lasts in ms
# define ANIM_FRAME_DURATION 200 // how long each frame lasts in ms
// #define SLEEP_TIMER 60000 // should sleep after this period of 0 wpm, needs fixing
# define ANIM_SIZE 636 // number of bytes in array, minimize for adequate firmware size, max is 1024
# define ANIM_SIZE 636 // number of bytes in array, minimize for adequate firmware size, max is 1024

uint32_t anim_timer = 0;
uint32_t anim_sleep = 0;
Expand Down Expand Up @@ -111,15 +114,15 @@ static void render_anim(void) {
}
if (get_current_wpm() > IDLE_SPEED && get_current_wpm() < TAP_SPEED) {
// oled_write_raw_P(prep[abs((PREP_FRAMES-1)-current_prep_frame)], ANIM_SIZE); // uncomment if IDLE_FRAMES >1
oled_write_raw_P(prep[0], ANIM_SIZE); // remove if IDLE_FRAMES >1
oled_write_raw_P(prep[0], ANIM_SIZE); // remove if IDLE_FRAMES >1
}
if (get_current_wpm() >= TAP_SPEED) {
current_tap_frame = (current_tap_frame + 1) % TAP_FRAMES;
oled_write_raw_P(tap[abs((TAP_FRAMES - 1) - current_tap_frame)], ANIM_SIZE);
}
}
if (get_current_wpm() != 000) {
oled_on(); // not essential but turns on animation OLED with any alpha keypress
oled_on(); // not essential but turns on animation OLED with any alpha keypress
if (timer_elapsed32(anim_timer) > ANIM_FRAME_DURATION) {
anim_timer = timer_read32();
animation_phase();
Expand All @@ -138,18 +141,21 @@ static void render_anim(void) {
}

// Used to draw on to the oled screen
bool oled_task_user(void) {
render_anim(); // renders pixelart
bool oled_task_kb(void) {
if (!oled_task_user()) {
return false;
}
render_anim(); // renders pixelart

oled_set_cursor(0, 0); // sets cursor to (row, column) using charactar spacing (5 rows on 128x32 screen, anything more will overflow back to the top)
oled_set_cursor(0, 0); // sets cursor to (row, column) using charactar spacing (5 rows on 128x32 screen, anything more will overflow back to the top)
oled_write_P(PSTR("WPM: "), false);
oled_write(get_u8_str(get_current_wpm(), '0'), false);
oled_write(wpm_str, false); // writes wpm on top left corner of string
oled_write(wpm_str, false); // writes wpm on top left corner of string

led_t led_state = host_keyboard_led_state(); // caps lock stuff, prints CAPS on new line if caps led is on
led_t led_state = host_keyboard_led_state(); // caps lock stuff, prints CAPS on new line if caps led is on
oled_set_cursor(0, 1);
oled_write_P(led_state.caps_lock ? PSTR("CAPS") : PSTR(" "), false);

return false;
return true;
}
#endif
27 changes: 15 additions & 12 deletions keyboards/horrortroll/lemon40/lemon40.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@
#include "lib/bongocat.h"

#ifdef OLED_ENABLE
bool oled_task_kb(void) {
led_t led_usb_state = host_keyboard_led_state();
bool oled_task_kb(void) {
if (!oled_task_user()) {
return false;
}
led_t led_usb_state = host_keyboard_led_state();

render_bongocat();
oled_set_cursor(14, 0); // sets cursor to (column, row) using charactar spacing (4 rows on 128x32 screen, anything more will overflow back to the top)
oled_write_P(PSTR("WPM:"), false);
oled_write(get_u8_str(get_current_wpm(), '0'), false); // writes wpm on top right corner of string
oled_set_cursor(17, 2);
oled_write_P(led_usb_state.caps_lock ? PSTR("CAPS") : PSTR(" "), false);
oled_set_cursor(17, 3);
oled_write_P(led_usb_state.scroll_lock ? PSTR("SCRL") : PSTR(" "), false);
render_bongocat();
oled_set_cursor(14, 0); // sets cursor to (column, row) using charactar spacing (4 rows on 128x32 screen, anything more will overflow back to the top)
oled_write_P(PSTR("WPM:"), false);
oled_write(get_u8_str(get_current_wpm(), '0'), false); // writes wpm on top right corner of string
oled_set_cursor(17, 2);
oled_write_P(led_usb_state.caps_lock ? PSTR("CAPS") : PSTR(" "), false);
oled_set_cursor(17, 3);
oled_write_P(led_usb_state.scroll_lock ? PSTR("SCRL") : PSTR(" "), false);

return true;
}
return true;
}
#endif
62 changes: 32 additions & 30 deletions keyboards/lime/rev1/rev1.c
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
/* Copyright 2021 HellSingCoder
*
* 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 2021 HellSingCoder
*
* 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/>.
*/

#include "quantum.h"

/* Encoders */
#ifdef ENCODER_ENABLE
bool encoder_update_user(uint8_t index, bool clockwise) {

if (index == 0) {
if (clockwise) {
tap_code(KC_MNXT);
} else {
tap_code(KC_MPRV);
}
} else if (index == 1) {
if (clockwise) {
tap_code(KC_VOLU);
} else {
tap_code(KC_VOLD);
}
}
bool encoder_update_kb(uint8_t index, bool clockwise) {
if (!encoder_update_user(index, clockwise)) {
return false;
}
if (index == 0) {
if (clockwise) {
tap_code(KC_MNXT);
} else {
tap_code(KC_MPRV);
}
} else if (index == 1) {
if (clockwise) {
tap_code(KC_VOLU);
} else {
tap_code(KC_VOLD);
}
}
return true;
}
#endif
25 changes: 14 additions & 11 deletions keyboards/mino_plus/mino_plus.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
#include "quantum.h"

#ifdef OLED_ENABLE
#define FRAMES 5
#define ANIMATION_SIZE 512
#define TAP_SPEED 30
# define FRAMES 5
# define ANIMATION_SIZE 512
# define TAP_SPEED 30

uint8_t current_frame = 0;
uint32_t anim_timer = 0;
uint32_t anim_sleep = 0;
uint8_t current_frame = 0;
uint32_t anim_timer = 0;
uint32_t anim_sleep = 0;
uint32_t ANIM_FRAME_DURATION = 1000;

static void render_animation(void) {
Expand Down Expand Up @@ -191,8 +191,8 @@ static void render_animation(void) {
}

if (get_current_wpm() != 000) {
oled_on(); // not essential but turns on animation OLED with any alpha keypress
if (get_current_wpm() > TAP_SPEED){
oled_on(); // not essential but turns on animation OLED with any alpha keypress
if (get_current_wpm() > TAP_SPEED) {
ANIM_FRAME_DURATION = 100;
} else {
ANIM_FRAME_DURATION = 1000;
Expand Down Expand Up @@ -233,16 +233,19 @@ static void render_status(void) {
}

oled_rotation_t oled_init_kb(oled_rotation_t rotation) {
return OLED_ROTATION_270;
return OLED_ROTATION_270;
}

bool oled_task_kb(void) {
if (!oled_task_user()) {
return false;
}
render_animation();
render_status();

oled_write_ln_P(PSTR("WPM:"), false);
oled_write_ln(get_u8_str(get_current_wpm(), '0'), false);

return false;
return true;
}
#endif
#endif
Loading

0 comments on commit bf26a3e

Please sign in to comment.