Skip to content

Commit

Permalink
compiling post restruction (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossless committed Feb 12, 2024
1 parent 3748c2b commit 04145b4
Show file tree
Hide file tree
Showing 29 changed files with 253 additions and 161 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: cachix/install-nix-action@v22
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- uses: cachix/cachix-action@v12
- uses: cachix/cachix-action@v14
with:
name: smk
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
Expand All @@ -36,7 +36,7 @@ jobs:
- uses: cachix/install-nix-action@v22
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- uses: cachix/cachix-action@v12
- uses: cachix/cachix-action@v14
with:
name: smk
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,21 @@ AFLAGS := -plosgff

# TODO: this should be selected based on the target being built
LAYOUT_SOURCES := $(wildcard $(SRCDIR)/keyboards/nuphy-air60/layouts/default/*.c)
KEYBOARD_SOURCES := $(wildcard $(SRCDIR)/keyboards/nuphy-air60/*.c)

# main.c has to be the first file
MAIN_SOURCES := $(SRCDIR)/main.c \
$(filter-out $(SRCDIR)/main.c, $(wildcard $(SRCDIR)/*.c)) \
$(wildcard $(SRCDIR)/smk/*.c) \
$(KEYBOARD_SOURCES) \
$(LAYOUT_SOURCES)
MAIN_OBJECTS := $(MAIN_SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.rel)

LIBSINO8051_SOURCES := $(wildcard $(SRCDIR)/lib/sh68f90a/*.c)
LIBSINO8051_OBJECTS := $(LIBSINO8051_SOURCES:$(SRCDIR)/lib/sh68f90a/%.c=$(OBJDIR)/lib/sh68f90a/%.rel)

OVERRIDABLE_SOURCES := $(wildcard $(SRCDIR)/overridable/*.c)
OVERRIDABLE_OBJECTS := $(OVERRIDABLE_SOURCES:$(SRCDIR)/overridable/%.c=$(OBJDIR)/overridable/%.rel)
USER_SOURCES := $(wildcard $(SRCDIR)/user/*.c)
USER_OBJECTS := $(USER_SOURCES:$(SRCDIR)/user/%.c=$(OBJDIR)/user/%.rel)

KEYBOARDS_LAYOUTS = nuphy-air60_default

Expand Down
75 changes: 75 additions & 0 deletions src/keyboards/nuphy-air60/kbdef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#ifndef KBDEF_H
#define KBDEF_H

#include "../../lib/sh68f90a/sh68f90a.h"

#define MATRIX_ROWS 5
#define MATRIX_COLS 16

// Row Pins Bits
#define KB_R0_P7_1 _P7_1
#define KB_R1_P7_2 _P7_2
#define KB_R2_P7_3 _P7_3
#define KB_R2_P5_3 _P5_3
#define KB_R2_P5_4 _P5_4

// Row Pins
// TODO

// Column Pins Bits
#define KB_C0_P5_0 _P5_0
#define KB_C1_P5_1 _P5_1
#define KB_C2_P5_2 _P5_2
#define KB_C3_P3_5 _P3_5
#define KB_C4_P3_4 _P3_4
#define KB_C5_P3_3 _P3_3
#define KB_C6_P3_2 _P3_2
#define KB_C7_P3_1 _P3_1
#define KB_C8_P3_0 _P3_0
#define KB_C9_P2_5 _P2_5
#define KB_C10_P2_4 _P2_4
#define KB_C11_P2_3 _P2_3
#define KB_C12_P2_2 _P2_2
#define KB_C13_P2_1 _P2_1
#define KB_C14_P2_0 _P2_0
#define KB_C15_P1_5 _P1_5

// Column Pins
#define KB_C0 P5_0
#define KB_C1 P5_1
#define KB_C2 P5_2
#define KB_C3 P3_5
#define KB_C4 P3_4
#define KB_C5 P3_3
#define KB_C6 P3_2
#define KB_C7 P3_1
#define KB_C8 P3_0
#define KB_C9 P2_5
#define KB_C10 P2_4
#define KB_C11 P2_3
#define KB_C12 P2_2
#define KB_C13 P2_1
#define KB_C14 P2_0
#define KB_C15 P1_5

// RGB Row Pins
#define RGB_R0R_P0_4 _P0_4
#define RGB_R0G_P6_1 _P6_1
#define RGB_R0B_P0_3 _P0_3
#define RGB_R1R_P6_7 _P6_7
#define RGB_R1G_P6_2 _P6_2
#define RGB_R1B_P6_6 _P6_6
#define RGB_R2R_P0_2 _P0_2
#define RGB_R2G_P6_3 _P6_3
#define RGB_R2B_P5_7 _P5_7
#define RGB_R3R_P4_5 _P4_5
#define RGB_R3G_P6_4 _P6_4
#define RGB_R3B_P4_6 _P4_6
#define RGB_R4R_P4_4 _P4_4
#define RGB_R4G_P6_5 _P6_5
#define RGB_R4B_P4_3 _P4_3
#define RGB_ULR_P1_1 _P1_1
#define RGB_ULG_P1_2 _P1_2
#define RGB_ULB_P1_3 _P1_3

#endif
22 changes: 21 additions & 1 deletion src/keyboards/nuphy-air60/layouts/default/indicators.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
#include "../../../../indicators.h"
#include "../../../../user/indicators.h"
#include "../../../../lib/sh68f90a/sh68f90a.h"
#include "../../../../lib/sh68f90a/pwm.h"
#include <stdlib.h>

void indicators_pre_update()
{
// set all rgb sinks to low (animation step will enable needed ones)
P0 &= ~(_P0_2 | _P0_3 | _P0_4);
P1 &= ~(_P1_1 | _P1_2 | _P1_3);
P4 &= ~(_P4_3 | _P4_4 | _P4_5 | _P4_6);
P5 &= ~(_P5_7);
P6 &= ~(_P6_1 | _P6_2 | _P6_3 | _P6_4 | _P6_5 | _P6_6 | _P6_7);

pwm_disable();
}

bool indicators_update_step(keyboard_state_t *keyboard, uint8_t current_step)
{
static uint16_t current_cycle = 0;
Expand Down Expand Up @@ -86,3 +98,11 @@ bool indicators_update_step(keyboard_state_t *keyboard, uint8_t current_step)

return false;
}

void indicators_post_update()
{
// clear pwm isr flag
PWM00CON &= ~(1 << 5);

pwm_enable();
}
6 changes: 3 additions & 3 deletions src/keyboards/nuphy-air60/layouts/default/layout.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "../../../../layout.h"
#include "../../../../matrix.h"
#include "../../../../report.h"
#include "../../kbdef.h"
#include "../../../../user/layout.h"
#include "../../../../smk/report.h"
#include <stdint.h>

#define LAYOUT_60( \
Expand Down
98 changes: 98 additions & 0 deletions src/keyboards/nuphy-air60/matrix.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include "kbdef.h"

void matrix_pre_scan(uint8_t col)
{
// set all columns to high
P1 |= (uint8_t)(_P1_5);
P2 |= (uint8_t)(_P2_0 | _P2_1 | _P2_2 | _P2_3 | _P2_4 | _P2_5);
P3 |= (uint8_t)(_P3_0 | _P3_1 | _P3_2 | _P3_3 | _P3_4 | _P3_5);
P5 |= (uint8_t)(_P5_0 | _P5_1 | _P5_2);

// set current (!) column to low
switch (col) {
case 0:
KB_C0 = 0;
break;

case 1:
KB_C1 = 0;
break;

case 2:
KB_C2 = 0;
break;

case 3:
KB_C3 = 0;
break;

case 4:
KB_C4 = 0;
break;

case 5:
KB_C5 = 0;
break;

case 6:
KB_C6 = 0;
break;

case 7:
KB_C7 = 0;
break;

case 8:
KB_C8 = 0;
break;

case 9:
KB_C9 = 0;
break;

case 10:
KB_C10 = 0;
break;

case 11:
KB_C11 = 0;
break;

case 12:
KB_C12 = 0;
break;

case 13:
KB_C13 = 0;
break;

case 14:
KB_C14 = 0;
break;

case 15:
KB_C15 = 0;
break;
}

}

uint8_t matrix_scan_col(uint8_t col)
{
// grab key for the column state
// P7_1 - R0
// P7_2 - R1
// P7_3 - R2
// P5_3 - R3
// P5_4 - R4
return (((P7 >> 1) & 0x07) | (P5 & 0x18)) | 0xe0;
}

void matrix_post_scan()
{
// set all columns down to low
P1 &= (uint8_t) ~(_P1_5);
P2 &= (uint8_t) ~(_P2_0 | _P2_1 | _P2_2 | _P2_3 | _P2_4 | _P2_5);
P3 &= (uint8_t) ~(_P3_0 | _P3_1 | _P3_2 | _P3_3 | _P3_4 | _P3_5);
P5 &= (uint8_t) ~(_P5_0 | _P5_1 | _P5_2);
}
16 changes: 8 additions & 8 deletions src/lib/sh68f90a/delay.c
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
#include "delay.h"
#include "watchdog.h"
#include "../../utils.h"
#include "../../smk/utils.h"
#include <stdint.h>

// very naive implementation, not very accurate or optimized
// hardcoded for F_SYS = 24Mhz
// hardcoded for FREQ_SYS = 24Mhz

void delay_ms(uint16_t cnt)
void delay_ms(uint16_t cnt) // should be __naked, currently unaccounted for
{
for (uint16_t i = 0; i < cnt; i++) {
delay_us(1000);
}
}

void delay_us(uint16_t cnt) __naked
void delay_us(uint16_t cnt) // should be __naked, currently unaccounted for
{
for (uint16_t i = 0; i < cnt; i++) {
for (uint16_t i = 0; i < cnt; i++) { // unaccounted for
// 4*6 = 24 instructions
// @ 24 Mhz one cycle should be 1us
// unverified

#ifdef WATCHDOG_ENABLE
CLR_WDT(); // 2c
_nop_3_(); // 3c
CLR_WDT(); // 3c - MOV direct, #data
_nop_(); // 1c
#else
_nop_4_(); // 4c
#endif
Expand All @@ -32,6 +32,6 @@ void delay_us(uint16_t cnt) __naked
_nop_4_(); // 4c
_nop_4_(); // 4c
_nop_4_(); // 4c
// =
// = 24c
}
}
4 changes: 2 additions & 2 deletions src/lib/sh68f90a/keyboard.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "../../keyboard.h"
#include "sh68f90a.h"
#include "../../debug.h"
#include "../../smk/keyboard.h"
#include "../../smk/debug.h"

__xdata keyboard_state_t keyboard_state;

Expand Down
1 change: 0 additions & 1 deletion src/lib/sh68f90a/pwm.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "pwm.h"
#include "../../matrix.h"
#include <stdint.h>
#include <stdio.h>

Expand Down
10 changes: 5 additions & 5 deletions src/lib/sh68f90a/usb.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "usb.h"
#include "watchdog.h"
#include "isp.h"
#include "../../usbdef.h"
#include "../../smk/usbdef.h"
#include "usbregs.h"
#include "../../debug.h"
#include "../../utils.h"
#include "../../usbhidreport.h"
#include "../../keyboard.h"
#include "../../smk/debug.h"
#include "../../smk/utils.h"
#include "../../smk/usbhidreport.h"
#include "../../smk/keyboard.h"
#include <stdint.h>
#include <string.h>

Expand Down
2 changes: 1 addition & 1 deletion src/lib/sh68f90a/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define USB_H

#include "sh68f90a.h"
#include "../../report.h"
#include "../../smk/report.h"
#include <stdint.h>

void usb_init();
Expand Down
8 changes: 4 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#include "lib/sh68f90a/isp.h"
#include "lib/sh68f90a/uart.h"
#include "lib/sh68f90a/gpio.h"
#include "matrix.h"
#include "lib/sh68f90a/pwm.h"
#include "lib/sh68f90a/usb.h"
#include "debug.h"
#include "utils.h"
#include "keyboard.h"
#include "smk/debug.h"
#include "smk/matrix.h"
#include "smk/utils.h"
#include "smk/keyboard.h"

#include <stdio.h>

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/host.c → src/smk/host.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "host.h"
#include "debug.h"
#include "lib/sh68f90a/usb.h"
#include "../lib/sh68f90a/usb.h"

/* send report */
void host_keyboard_send(report_keyboard_t *report)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 04145b4

Please sign in to comment.