Skip to content

Commit

Permalink
dipsw test on helix/rev2/sc/back:five_rows
Browse files Browse the repository at this point in the history
  • Loading branch information
mtei committed Apr 9, 2020
1 parent 582cea6 commit bf99ace
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
3 changes: 3 additions & 0 deletions keyboards/helix/rev2/keymaps/five_rows/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* when TAPPING_TERM >= 500 same effect PERMISSIVE_HOLD.
see tmk_core/common/action_tapping.c */

//#define DIP_SWITCH_PINS { B5, B6 }
#define DIP_SWITCH_PINS { B5, B6, B5, B6 }

// place overrides here

// If you need more program area, try select and reduce rgblight modes to use.
Expand Down
102 changes: 101 additions & 1 deletion keyboards/helix/rev2/keymaps/five_rows/keymap.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include QMK_KEYBOARD_H
#include <avr/pgmspace.h>
#include "bootloader.h"
#ifdef PROTOCOL_LUFA
#include "lufa.h"
Expand All @@ -13,6 +14,7 @@
#ifdef CONSOLE_ENABLE
#include <print.h>
#endif
#include "timer.h"

extern keymap_config_t keymap_config;

Expand Down Expand Up @@ -332,8 +334,13 @@ uint32_t default_layer_state_set_kb(uint32_t state) {
return state;
}

void dump_pbuf(void);
void update_base_layer(int base)
{
uprintf("layer\n");
dump_pbuf();
uprintf("call dip_switch_read(true)\n");
dip_switch_read(true);
if( current_default_layer != base ) {
eeconfig_update_default_layer(1UL<<base);
default_layer_set(1UL<<base);
Expand Down Expand Up @@ -472,7 +479,6 @@ void music_scale_user(void)

#endif


//SSD1306 OLED update loop, make sure to add #define SSD1306OLED in config.h
#ifdef SSD1306OLED

Expand Down Expand Up @@ -595,3 +601,97 @@ void iota_gfx_task_user(void) {
}

#endif

typedef struct _pr {
const char * PROGMEM fmt;
uint8_t arg1;
uint8_t arg2;
uint16_t timer;
} printbuf_t;
uint8_t pbuf_count = 0;
bool pbuf_overflow = false;
printbuf_t pbuf[16] = {0};
bool pbuf_wait = true;
uint16_t pbuf_timer = 0;

void dump_pbuf(void) {
if( pbuf_wait )
return;

#ifdef CONSOLE_ENABLE
if( pbuf_count > 0 ) {
if (pbuf_count > 1)
uprintf(" %06d : dump_pbuf %d\n", timer_read(), pbuf_count);
for( uint8_t i = 0; i < pbuf_count; i++ ) {
uprintf(" %06d : ", pbuf[i].timer);
__xprintf(pbuf[i].fmt, pbuf[i].arg1, pbuf[i].arg2);
}
pbuf_count = 0;
if( pbuf_overflow ) {
uprintf(" pbuf overflow \n");
pbuf_overflow = false;
}
}
#endif
}

void matrix_scan_user(void) {
if( pbuf_wait ) {
if( pbuf_timer == 0 ) {
/* the first scan. */
pbuf_timer = timer_read();
}
if( timer_elapsed(pbuf_timer) < 2000 ) {
return;
}
pbuf_wait = false;
dump_pbuf();
}
}

void dip_switch_update_user(uint8_t index, bool active) {
if( pbuf_count < sizeof(pbuf)/sizeof(pbuf[0]) ) {
pbuf[pbuf_count].fmt = PSTR("dip_switch_update_user(%d,%d)\n");
pbuf[pbuf_count].arg1 = index;
pbuf[pbuf_count].arg2 = active;
pbuf[pbuf_count].timer = timer_read();
pbuf_count++;
} else {
pbuf_overflow = true;
}
dump_pbuf();
}

void dip_switch_update_mask_user(uint32_t state) {
if( pbuf_count < sizeof(pbuf)/sizeof(pbuf[0]) ) {
pbuf[pbuf_count].fmt = PSTR("dip_switch_update_mask_user(0b%b)\n");
pbuf[pbuf_count].arg1 = state;
pbuf[pbuf_count].timer = timer_read();
pbuf_count++;
} else {
pbuf_overflow = true;
}
dump_pbuf();
}

void keyboard_pre_init_user(void)
{
if( pbuf_count < sizeof(pbuf)/sizeof(pbuf[0]) ) {
pbuf[pbuf_count].fmt = PSTR("keyboard_pre_init_user()\n");
pbuf[pbuf_count].timer = timer_read();
pbuf_count++;
} else {
pbuf_overflow = true;
}
}

void keyboard_post_init_user(void)
{
if( pbuf_count < sizeof(pbuf)/sizeof(pbuf[0]) ) {
pbuf[pbuf_count].fmt = PSTR("keyboard_post_init_user()\n");
pbuf[pbuf_count].timer = timer_read();
pbuf_count++;
} else {
pbuf_overflow = true;
}
}
3 changes: 3 additions & 0 deletions keyboards/helix/rev2/keymaps/five_rows/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ ifneq ($(strip $(HELIX)),)
endif
endif

CONSOLE_ENABLE = yes
DIP_SWITCH_ENABLE = yes

# convert Helix-specific options (that represent combinations of standard options)
# into QMK standard options.
include $(strip $(KEYBOARD_LOCAL_FEATURES_MK))

0 comments on commit bf99ace

Please sign in to comment.