Skip to content

Commit

Permalink
library usage (one function per file)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossless committed Dec 31, 2023
1 parent 39e9d27 commit f8c5868
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 45 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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} < $< > $@
Expand Down
3 changes: 1 addition & 2 deletions src/indicators.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <stdint.h>
#include <stdbool.h>

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
36 changes: 36 additions & 0 deletions src/keyboard.c
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
3 changes: 3 additions & 0 deletions src/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ typedef struct {

extern __xdata keyboard_state_t keyboard_state;

void keyboard_init();
void keyboard_update_switches();

#endif
2 changes: 1 addition & 1 deletion src/keyboards/nuphy-air60/layouts/default/indicators.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "../../../../pwm.h"
#include <stdlib.h>

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;

Expand Down
9 changes: 4 additions & 5 deletions src/lib/indicators.c
Original file line number Diff line number Diff line change
@@ -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;
// }
2 changes: 2 additions & 0 deletions src/lib/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

bool process_record_user(uint16_t keycode, bool key_pressed)
{
keycode;
key_pressed;
return true;
}
34 changes: 2 additions & 32 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void init()
pwm_init();
usb_init();
matrix_init();
keyboard_init();

// usb interupt priority - 3
IPH1 |= (1 << 6);
Expand All @@ -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();
}
}
3 changes: 2 additions & 1 deletion src/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f8c5868

Please sign in to comment.