From f8c5868ca4dc2353aebef9706244d8e06f5ef6d8 Mon Sep 17 00:00:00 2001 From: Karolis Stasaitis Date: Sun, 31 Dec 2023 16:03:08 +0100 Subject: [PATCH] library usage (one function per file) --- Makefile | 8 ++--- src/indicators.h | 3 +- src/keyboard.c | 36 +++++++++++++++++++ src/keyboard.h | 3 ++ .../nuphy-air60/layouts/default/indicators.c | 2 +- src/lib/indicators.c | 9 +++-- src/lib/layout.c | 2 ++ src/main.c | 34 ++---------------- src/matrix.c | 3 +- 9 files changed, 55 insertions(+), 45 deletions(-) diff --git a/Makefile b/Makefile index 9abb765..6774a04 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CC= sdcc ASM = sdas8051 -SDAR ?= sdar rc +SDAR ?= sdar -rc OBJCOPY = objcopy PACKIHX = packihx FLASHER = sinowealth-kb-tool write -p nuphy-air60 @@ -64,13 +64,13 @@ $(OBJDIR)/%.rel: $(SRCDIR)/%.c @mkdir -p $(@D) $(CC) -m$(FAMILY) -l$(PROC) $(CFLAGS) -c $< -o $@ -$(BINDIR)/main.lib: $(LIB_OBJECTS) +$(BINDIR)/smk.lib: $(LIB_OBJECTS) @mkdir -p $(@D) $(SDAR) $@ $^ -$(BINDIR)/main.ihx: $(MAIN_OBJECTS) $(BINDIR)/main.lib +$(BINDIR)/main.ihx: $(MAIN_OBJECTS) $(BINDIR)/smk.lib @mkdir -p $(@D) - $(CC) -m$(FAMILY) -l$(PROC) $(LFLAGS) -o $@ $^ + $(CC) -m$(FAMILY) -l$(PROC) $(LFLAGS) -o $@ $(MAIN_OBJECTS) -L$(BINDIR) -lsmk $(BINDIR)/%.hex: $(BINDIR)/%.ihx ${PACKIHX} < $< > $@ diff --git a/src/indicators.h b/src/indicators.h index b5d8e73..8bf6484 100644 --- a/src/indicators.h +++ b/src/indicators.h @@ -5,7 +5,6 @@ #include #include -bool indicators_update(__xdata keyboard_state_t *keyboard); -bool indicators_update_step(__xdata keyboard_state_t *keyboard, uint8_t current_step); +bool indicators_update_step(keyboard_state_t *keyboard, uint8_t current_step); #endif diff --git a/src/keyboard.c b/src/keyboard.c index d1e9813..ea2f1d9 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -1,3 +1,39 @@ #include "keyboard.h" +#include "sh68f90a.h" +#include "debug.h" __xdata keyboard_state_t keyboard_state; + +void keyboard_init() +{ + keyboard_state.led_state = 0x00; + keyboard_state.conn_mode = P5_5; + keyboard_state.os_mode = P5_6; +} + +void keyboard_update_switches() +{ + if (keyboard_state.conn_mode != P5_5) { + keyboard_state.conn_mode = P5_5; + switch (keyboard_state.conn_mode) { + case KEYBOARD_CONN_MODE_USB: + dprintf("USB_MODE\r\n"); + break; + case KEYBOARD_CONN_MODE_RF: + dprintf("RF_MODE\r\n"); + break; + } + } + + if (keyboard_state.os_mode != P5_6) { + keyboard_state.os_mode = P5_6; + switch (keyboard_state.os_mode) { + case KEYBOARD_OS_MODE_MAC: + dprintf("MAC_MODE\r\n"); + break; + case KEYBOARD_OS_MODE_WIN: + dprintf("WIN_MODE\r\n"); + break; + } + } +} diff --git a/src/keyboard.h b/src/keyboard.h index 8269d83..de3f099 100644 --- a/src/keyboard.h +++ b/src/keyboard.h @@ -21,4 +21,7 @@ typedef struct { extern __xdata keyboard_state_t keyboard_state; +void keyboard_init(); +void keyboard_update_switches(); + #endif diff --git a/src/keyboards/nuphy-air60/layouts/default/indicators.c b/src/keyboards/nuphy-air60/layouts/default/indicators.c index 35e4250..5ddfe90 100644 --- a/src/keyboards/nuphy-air60/layouts/default/indicators.c +++ b/src/keyboards/nuphy-air60/layouts/default/indicators.c @@ -3,7 +3,7 @@ #include "../../../../pwm.h" #include -bool indicators_update_step(__xdata keyboard_state_t *keyboard, uint8_t current_step) +bool indicators_update_step(keyboard_state_t *keyboard, uint8_t current_step) { static uint16_t current_cycle = 0; diff --git a/src/lib/indicators.c b/src/lib/indicators.c index 2ddbd71..63f4d30 100644 --- a/src/lib/indicators.c +++ b/src/lib/indicators.c @@ -1,9 +1,8 @@ #include "../indicators.h" -bool indicators_update(__xdata keyboard_state_t *keyboard) { +bool indicators_update_step(keyboard_state_t *keyboard, uint8_t current_step) +{ + keyboard; + current_step; return true; } - -// bool indicators_update_step(__xdata keyboard_state_t *keyboard, uint8_t current_step) { -// return true; -// } diff --git a/src/lib/layout.c b/src/lib/layout.c index a25671e..53a0d9b 100644 --- a/src/lib/layout.c +++ b/src/lib/layout.c @@ -2,5 +2,7 @@ bool process_record_user(uint16_t keycode, bool key_pressed) { + keycode; + key_pressed; return true; } diff --git a/src/main.c b/src/main.c index 4a08b95..a3c6c6d 100644 --- a/src/main.c +++ b/src/main.c @@ -22,6 +22,7 @@ void init() pwm_init(); usb_init(); matrix_init(); + keyboard_init(); // usb interupt priority - 3 IPH1 |= (1 << 6); @@ -40,45 +41,14 @@ void main() dprintf("SMK v" TOSTRING(SMK_VERSION) "\r\n"); dprintf("DEVICE vId:" TOSTRING(USB_VID) " pId:" TOSTRING(USB_PID) "\n\r"); + dprintf("OS: 0x%x, CONN: 0x%x\n\r", keyboard_state.os_mode, keyboard_state.conn_mode); // enable pwm and interrupt (driving matrix scan) pwm_enable(); - // connection state only becomes stable after pwm is enabled - // they shouldn't be related, assumptions about the circuit are wrong somewhere - delay_ms(10); - - keyboard_state.led_state = 0x00; - keyboard_state.conn_mode = P5_5; - keyboard_state.os_mode = P5_6; - while (1) { CLR_WDT(); - if (keyboard_state.conn_mode != P5_5) { - keyboard_state.conn_mode = P5_5; - switch (keyboard_state.conn_mode) { - case KEYBOARD_CONN_MODE_USB: - dprintf("USB_MODE\r\n"); - break; - case KEYBOARD_CONN_MODE_RF: - dprintf("RF_MODE\r\n"); - break; - } - } - - if (keyboard_state.os_mode != P5_6) { - keyboard_state.os_mode = P5_6; - switch (keyboard_state.os_mode) { - case KEYBOARD_OS_MODE_MAC: - dprintf("MAC_MODE\r\n"); - break; - case KEYBOARD_OS_MODE_WIN: - dprintf("WIN_MODE\r\n"); - break; - } - } - matrix_task(); } } diff --git a/src/matrix.c b/src/matrix.c index ec603bb..dd00a02 100644 --- a/src/matrix.c +++ b/src/matrix.c @@ -257,10 +257,11 @@ inline void matrix_scan_step() P5 &= (uint8_t) ~(_P5_0 | _P5_1 | _P5_2); matrix[current_step] = ~column_state; + + keyboard_update_switches(); } // rgb led matrix animation - indicators_update(&keyboard_state); indicators_update_step(&keyboard_state, current_step); // move step