Skip to content

Commit d65d1be

Browse files
committed
USB support, SMK name, GPLv2 license, sh68f90a.h improvements
Squashed commit of the following: commit 39efd4c Author: Karolis Stasaitis <[email protected]> Date: Sat Dec 2 10:26:41 2023 +0100 improved led and other reports handler commit cd0acfa Author: Karolis Stasaitis <[email protected]> Date: Mon Nov 27 23:50:10 2023 +0100 reg control macro separation commit 2bda1c7 Author: Karolis Stasaitis <[email protected]> Date: Mon Nov 27 23:18:57 2023 +0100 gplv2 license commit 4d30f8e Author: Karolis Stasaitis <[email protected]> Date: Mon Nov 27 23:08:14 2023 +0100 cleanup of unused code commit 1a5b735 Author: Karolis Stasaitis <[email protected]> Date: Sat Nov 25 18:01:49 2023 +0100 _SBUF commit ebac878 Author: Karolis Stasaitis <[email protected]> Date: Sat Nov 25 17:52:22 2023 +0100 license and more register use commit 4069a4e Author: Karolis Stasaitis <[email protected]> Date: Sat Nov 25 12:01:49 2023 +0100 readme adjustments commit 7b7e96d Author: Karolis Stasaitis <[email protected]> Date: Sat Nov 25 11:45:39 2023 +0100 format commit f59fc4e Author: Karolis Stasaitis <[email protected]> Date: Sat Nov 25 11:44:25 2023 +0100 more cleanup commit 69df71d Author: Karolis Stasaitis <[email protected]> Date: Fri Nov 24 00:00:55 2023 +0100 include self-powered status commit 581bf67 Author: Karolis Stasaitis <[email protected]> Date: Thu Nov 23 23:28:54 2023 +0100 updated init code commit 797ddab Author: Karolis Stasaitis <[email protected]> Date: Thu Nov 23 23:19:27 2023 +0100 better declarations for usb buffers commit 003c2df Author: Karolis Stasaitis <[email protected]> Date: Wed Nov 22 22:56:03 2023 +0100 format changes commit 46d1424 Author: Karolis Stasaitis <[email protected]> Date: Wed Nov 22 22:55:04 2023 +0100 more cleanup and reorganization commit 758f79b Author: Karolis Stasaitis <[email protected]> Date: Tue Nov 21 23:49:13 2023 +0100 a bunch of duplicate define cleanup commit b327ec4 Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 19 17:43:53 2023 +0100 new docs commit 2f480e9 Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 19 17:14:39 2023 +0100 fixed USB_EP1_COM_BUFFER_ADDR commit 6e70eca Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 19 14:27:44 2023 +0100 remove buffer_addr usage and replace endpoint type mask commit b09ab2e Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 19 14:20:25 2023 +0100 removed global rx_data commit 24314a8 Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 19 12:55:37 2023 +0100 formatting commit 5ecd811 Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 19 12:55:05 2023 +0100 back to working state commit 718584d Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 19 10:27:13 2023 +0100 register bit flag defines commit 472c5a1 Author: Karolis Stasaitis <[email protected]> Date: Mon Nov 13 00:08:30 2023 +0100 a style cleanup commit 99e67b6 Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 12 23:57:00 2023 +0100 cleanup commit 81ec91f Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 12 23:51:54 2023 +0100 formatting changes commit 1c4f350 Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 12 23:51:17 2023 +0100 more refactoring commit 6839957 Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 12 21:41:29 2023 +0100 removed request table and replaced with switches and added a lint command commit be262d0 Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 12 18:48:08 2023 +0100 falke adjustments to get sdcc and astyle working properly commit dff639f Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 12 17:27:37 2023 +0100 more cleanup commit 1e8c9a5 Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 12 17:09:35 2023 +0100 clock init optimization commit bc98a30 Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 12 16:34:45 2023 +0100 uart update commit 9826754 Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 12 15:32:43 2023 +0100 formatting changes commit 8be7590 Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 12 14:47:10 2023 +0100 further refactoring commit b672443 Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 12 13:01:49 2023 +0100 peaces of cleanup commit 492994a Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 12 12:41:42 2023 +0100 removed unused rx buffer commit 810eb0f Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 12 12:36:42 2023 +0100 refactoring request methods commit cd0e698 Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 12 12:07:07 2023 +0100 refacotred stall commit 2230e4a Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 12 11:55:48 2023 +0100 removed uneeded printfs commit 36d6f27 Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 12 11:10:53 2023 +0100 fixed all setup timeouts commit abcdd86 Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 12 10:25:48 2023 +0100 more refactoring, but set_report seems to be slightly broken commit 4e39fbe Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 12 00:19:55 2023 +0100 formatting update commit 79388dd Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 12 00:00:41 2023 +0100 formatting changes commit 2c770e5 Author: Karolis Stasaitis <[email protected]> Date: Sat Nov 11 23:46:18 2023 +0100 remove led mode commit 6f915f2 Author: Karolis Stasaitis <[email protected]> Date: Sat Nov 11 23:44:39 2023 +0100 better HID definitions commit c0858c6 Author: Karolis Stasaitis <[email protected]> Date: Sat Nov 11 17:41:43 2023 +0100 more defined hid descriptions commit 4490e9a Author: Karolis Stasaitis <[email protected]> Date: Sat Nov 11 15:22:12 2023 +0100 more desscriptor struct usage, back to working keyboard commit 9c02ea2 Author: Karolis Stasaitis <[email protected]> Date: Sat Nov 11 12:03:19 2023 +0100 moved device descriptor to new structure commit af6009c Author: Karolis Stasaitis <[email protected]> Date: Sat Nov 11 11:18:53 2023 +0100 added structures from libfx2 and replace string handling with one of them commit f90d130 Author: Karolis Stasaitis <[email protected]> Date: Tue Nov 7 23:40:29 2023 +0100 first version of working layers commit 97d9cd5 Author: Karolis Stasaitis <[email protected]> Date: Tue Nov 7 22:13:54 2023 +0100 removed qmk action handling commit ad07688 Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 5 22:07:17 2023 +0100 broken wip attempt to bring in more qmk code commit c63ea4c Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 5 12:59:47 2023 +0100 successfully sending all 6 keys and modifiers + some debug utils commit f52ef39 Author: Karolis Stasaitis <[email protected]> Date: Sun Nov 5 10:20:48 2023 +0100 github actions commit bc68f30 Author: Karolis Stasaitis <[email protected]> Date: Sat Nov 4 21:53:02 2023 +0100 more cleanup commit a74cb79 Author: Karolis Stasaitis <[email protected]> Date: Sat Nov 4 20:31:52 2023 +0100 small format changes commit 67d6e1d Author: Karolis Stasaitis <[email protected]> Date: Sat Nov 4 16:55:35 2023 +0100 reworked usb_request handler into struct commit fdd1a23 Author: Karolis Stasaitis <[email protected]> Date: Sat Nov 4 16:31:20 2023 +0100 separation into usbdef commit 80e697a Author: Karolis Stasaitis <[email protected]> Date: Sat Nov 4 15:27:04 2023 +0100 working usb stack
1 parent c1e131f commit d65d1be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4756
-1745
lines changed

.astylerc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# @file Astyle code automatic formatting settings
2+
# @see http://astyle.sourceforge.net/astyle.html#_General_Information
3+
4+
--style=otbs
5+
--indent=spaces=4
6+
--indent-switches
7+
--indent-preproc-block
8+
--indent-preproc-define
9+
--indent-col1-comments
10+
--break-blocks
11+
--pad-oper
12+
--pad-header
13+
--align-pointer=name
14+
--align-reference=name
15+
--convert-tabs
16+
--max-code-length=100
17+
--break-after-logical
18+
--mode=c
19+
--lineend=linux

.github/workflows/build.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
name: "Build"
3+
on: [pull_request, push]
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v3
9+
- uses: cachix/install-nix-action@v22
10+
with:
11+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
12+
- name: Build release
13+
run: nix develop --command make all
14+
- name: Archive code coverage results
15+
uses: actions/upload-artifact@v3
16+
with:
17+
name: firmware.hex
18+
path: bin/main.hex
19+
20+
lint:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v3
24+
- uses: cachix/install-nix-action@v22
25+
with:
26+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
27+
- name: Build release
28+
run: nix develop --command bash -c "! astyle --project -n --dry-run src/*.{h,c} | grep '^Formatted'"

LICENSE

Lines changed: 339 additions & 0 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,27 @@ FAMILY = mcs51
1212
PROC = mcs51
1313

1414
FREQ_SYS ?= 24000000
15-
XRAM_SIZE ?= 0x0400
15+
XRAM_SIZE ?= 0x1000
1616
XRAM_LOC ?= 0x0000
1717
CODE_SIZE ?= 0xf000 # 61440 bytes (leaving the remaining 4096 for bootloader)
1818

19+
SMK_VERSION ?= alpha
20+
21+
# Ease backup & restore process by keeping same vid & pid as nuphy-air60
22+
USB_VID ?= 0x05ac
23+
USB_PID ?= 0x024f
24+
1925
CFLAGS := -V -mmcs51 --model-small \
2026
--xram-size $(XRAM_SIZE) --xram-loc $(XRAM_LOC) \
2127
--code-size $(CODE_SIZE) \
22-
-I$(ROOT_DIR)../include -DFREQ_SYS=$(FREQ_SYS) -DWATCHDOG_ENABLE=1
28+
--std-c2x \
29+
-I$(ROOT_DIR)../include \
30+
-DDEBUG=1 \
31+
-DFREQ_SYS=$(FREQ_SYS) \
32+
-DWATCHDOG_ENABLE=1 \
33+
-DUSB_VID=$(USB_VID) \
34+
-DUSB_PID=$(USB_PID) \
35+
-DSMK_VERSION=$(SMK_VERSION)
2336
LFLAGS := $(CFLAGS)
2437

2538
AFLAGS= -plosgff
@@ -35,7 +48,7 @@ clean:
3548
rm -rf $(BINDIR) $(OBJDIR)
3649

3750
flash: $(BINDIR)/main.hex
38-
$(FLASHER) $<
51+
$(FLASHER) $(BINDIR)/main.hex
3952

4053
$(OBJDIR)/%.rel: $(SRCDIR)/%.c
4154
@mkdir -p $(@D)

README.md

Lines changed: 14 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,23 @@
1-
# SH68F90A / BYK916 / NuPhy Air60 Experiments
1+
# SMK - Small (device) Mechanical Keyboard Firmware
22

3-
A repository to test various features of the Sinowealth SH68F90A 8051-based microcontroller (also labeled as BYK916) on the [NuPhy Air60](https://nuphy.com/products/air60) keyboard.
3+
This is a keyboard firmware similar to [QMK](https://github.com/qmk/qmk_firmware), but targeting 8051-based devices like the Sinowealth SH68F90A (labeled as BYK916). It's aimed to be at least partially compatible with QMK configurations.
44

5-
## Features
5+
The S (Small) in SMK comes from this firmware using [SDCC](https://sdcc.sourceforge.net/) to build itself.
66

7-
### MCU
7+
## ⚠️ WARNING ⚠️
88

9-
- [x] 3.3V LDO
10-
- [x] CPU Clock (use 24Mhz as SYSCLK)
11-
- [x] GPIO
12-
- [x] UART
13-
- [x] Transmit
14-
- [ ] Receive
15-
- [x] PWM
16-
- [ ] SPI
17-
- [ ] USB
9+
This firmware is still highly experimental, so be cautious when trying to use it or extend it.
1810

19-
### Keyboard
11+
You can very easily end up with a bricked device if the written firmware can't jump back into ISP mode, so before testing or modifying it, it's best to have a full dump of your stock firmware and a tool (like the Sinolink) that can write it back.
2012

21-
- [x] ISP (jump)
22-
- [x] Key Scan
23-
- [x] RGB Matrix
24-
- [ ] USB HID
25-
- [ ] Wireless
13+
## Supported Devices
2614

27-
## Code Options
15+
| Keyboard | MCU | ISP | USB | Wireless | Details |
16+
| -------- | --- | --- | --- | -------- | ------- |
17+
| [NuPhy Air60 v1](https://nuphy.com/products/air60) | SH68F90A / BYK916 ||| TBD | [Details](docs/nuphy-air60.md) |
2818

29-
All code uses the following code options for SH68F90A
19+
## Acknowledgements
3020

31-
```
32-
Code Option String: A4E063C00F000088
33-
Code Option Number: 0x8800000fc063e0a4
34-
35-
Byte 0 - A4
36-
OP_OSCDRIVE 2 - 4MHz crystal or 8~12MHz crystal with external capacitance(C1=C2)<20pF
37-
OP_RST 1 - P0.2 used as IO pin
38-
OP_WMT 0 - longest warm up time
39-
OP_SCMEN 1 - Disable SCM
40-
OP_OSCRFB 0 - 150K
41-
42-
Byte 1 - E0
43-
OP_LVREN 1 - Enable LVR function
44-
OP_LVRLEVEL 3 - 2.1V LVR level4
45-
OP_SCM 0 - SCM is invalid in warm up period
46-
OP_OSC2SEL 0 - OSC2 select 12M RC
47-
OP_IOV1 0 - P7.1/P7.2/P7.3/P7.4 input/output level is VUSB(5V)
48-
OP_IOV0 0 - P5.5/P5.6 input/output level is VUSB(5V)
49-
50-
Byte 2 - 63
51-
OP_SCMSEL 3 - 8MHz
52-
OP_OSC 3 - Oscillator1 is internal 128KHz RC, oscillator2 is internal 24MHz RC
53-
54-
Byte 3 - C0
55-
OP_ISP 1 - Disable ISP function
56-
OP_ISPPIN 1 - Enter ISP mode only when P6.3 and P6.4 are connected to GND, simultaneously
57-
OP_WDT 0 - Enable WDT function
58-
OP_WDTPD 0 - Disable WDT function in Power-Down mode
59-
60-
Byte 4 - 0F
61-
OP_SINK1 3 - Port6[5:0] sink ability largest mode(380mA)
62-
OP_SINK0 3 - P4.7/Port7[7:5] sink ability largest mode(50mA)
63-
64-
Byte 5 - 00
65-
OP_BOPTP 0 - (1+21%)tr min
66-
OP_BOPTN 0 - (1+21%)tf min
67-
68-
Byte 6 - 00
69-
Unused
70-
71-
Byte 7 - 88
72-
OP_ISPSIZE 8 - 0Bytes
73-
```
21+
* [libfx2](https://github.com/whitequark/libfx2)
22+
* [LUFA](https://github.com/abcminiuser/lufa)
23+
* [QMK](https://github.com/qmk/qmk_firmware)

docs/nuphy-air60.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# NuPhy Air60 Support
2+
3+
## MCU
4+
5+
- [x] 3.3V LDO
6+
- [x] CPU Clock (use 24Mhz as SYSCLK)
7+
- [x] GPIO
8+
- [x] UART
9+
- [x] Transmit
10+
- [ ] Receive
11+
- [x] PWM
12+
- [x] USB
13+
- [ ] SPI
14+
15+
## Keyboard
16+
17+
- [x] ISP (jump)
18+
- [x] Key Scan
19+
- [x] RGB Matrix
20+
- [ ] Debouncing
21+
- [x] USB HID
22+
- [x] USB Keyboard
23+
- [ ] Status LEDs
24+
- [ ] Extra Keys (System / Consumer)
25+
- [ ] NKRO
26+
- [~] QMK Compatibility
27+
- [~] Layouts
28+
- [ ] Wireless
29+
30+
## Code Options
31+
32+
This firmware requires the following (stock) code options for SH68F90A
33+
34+
```
35+
Code Option String: A4E063C00F000088
36+
Code Option Number: 0x8800000fc063e0a4
37+
38+
Byte 0 - A4
39+
OP_OSCDRIVE 2 - 4MHz crystal or 8~12MHz crystal with external capacitance(C1=C2)<20pF
40+
OP_RST 1 - P0.2 used as IO pin
41+
OP_WMT 0 - longest warm up time
42+
OP_SCMEN 1 - Disable SCM
43+
OP_OSCRFB 0 - 150K
44+
45+
Byte 1 - E0
46+
OP_LVREN 1 - Enable LVR function
47+
OP_LVRLEVEL 3 - 2.1V LVR level4
48+
OP_SCM 0 - SCM is invalid in warm up period
49+
OP_OSC2SEL 0 - OSC2 select 12M RC
50+
OP_IOV1 0 - P7.1/P7.2/P7.3/P7.4 input/output level is VUSB(5V)
51+
OP_IOV0 0 - P5.5/P5.6 input/output level is VUSB(5V)
52+
53+
Byte 2 - 63
54+
OP_SCMSEL 3 - 8MHz
55+
OP_OSC 3 - Oscillator1 is internal 128KHz RC, oscillator2 is internal 24MHz RC
56+
57+
Byte 3 - C0
58+
OP_ISP 1 - Disable ISP function
59+
OP_ISPPIN 1 - Enter ISP mode only when P6.3 and P6.4 are connected to GND, simultaneously
60+
OP_WDT 0 - Enable WDT function
61+
OP_WDTPD 0 - Disable WDT function in Power-Down mode
62+
63+
Byte 4 - 0F
64+
OP_SINK1 3 - Port6[5:0] sink ability largest mode(380mA)
65+
OP_SINK0 3 - P4.7/Port7[7:5] sink ability largest mode(50mA)
66+
67+
Byte 5 - 00
68+
OP_BOPTP 0 - (1+21%)tr min
69+
OP_BOPTN 0 - (1+21%)tf min
70+
71+
Byte 6 - 00
72+
Unused
73+
74+
Byte 7 - 88
75+
OP_ISPSIZE 8 - 0Bytes
76+
```

flake.lock

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
{
22
inputs = {
3-
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
3+
nixpkgs.url = "github:carlossless/nixpkgs/fixups"; # latest patches to get astyle 4.3.10 & sdcc 4.3.0 working
44
utils.url = "github:numtide/flake-utils";
5-
sinowealth-kb-tool.url = "github:carlossless/sinowealth-kb-tool";
5+
sinowealth-kb-tool.url = "github:carlossless/sinowealth-kb-tool/noodle";
66
};
77

88
outputs = { self, nixpkgs, utils, sinowealth-kb-tool }:
99
utils.lib.eachDefaultSystem (
10-
system: let pkgs = nixpkgs.legacyPackages.${system}; in
11-
{
12-
devShells.default = pkgs.mkShell {
13-
buildInputs = with pkgs; [
14-
sdcc
15-
gnumake
16-
binutils
17-
astyle
18-
sinowealth-kb-tool.packages."${system}".default
19-
uhubctl
20-
];
21-
};
22-
}
23-
);
10+
system:
11+
let
12+
pkgs = import nixpkgs {
13+
inherit system;
14+
};
15+
in
16+
{
17+
devShells.default = pkgs.mkShell {
18+
buildInputs = with pkgs; [
19+
sdcc
20+
gnumake
21+
binutils
22+
astyle
23+
sinowealth-kb-tool.packages."${system}".default
24+
uhubctl
25+
];
26+
};
27+
}
28+
);
2429
}

src/clock.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
#include "clock.h"
22
#include "sh68f90a.h"
33
#include "delay.h"
4+
#include "watchdog.h"
45

5-
#define _SYSCLK_DIV 0 // no SYSCLK division (CLKS)
6-
#define _HRCCLK_EN (1 << 3) // enable HRCCLK (HFON)
7-
#define _CLK_SRC (1 << 2) // use OSCSCLK as SYSCLK (FS)
8-
9-
// PLL also necessary for USB peripheral
10-
#define _PLL_EN (1 << 1) // enables PLL, necessary for HRCCLK (PLLON)
11-
#define _OSCS_SRC (1 << 0) // PLL divided by two acts as OSCSCLK (PLLFS)
12-
13-
#define CLKCON_INIT (_SYSCLK_DIV|_HRCCLK_EN|_CLK_SRC)
14-
#define PLLCON_INIT (_PLL_EN|_OSCS_SRC)
15-
6+
/** \brief sets up HRCCLK and uses it as SYSCLK
7+
*
8+
*/
169
void clock_init()
1710
{
18-
CLKCON = (CLKCON_INIT & _HRCCLK_EN); // init HRCCLK
19-
delay_us(350); // unsure about span and if necessary
20-
PLLCON = (PLLCON_INIT & _PLL_EN); // init PLL
21-
delay_us(533); // unsure about span and if necessary
22-
PLLCON = PLLCON_INIT; // switch OSCSCLK
23-
CLKCON = CLKCON_INIT; // use HRCCLK as SYSCLK
11+
CLKCON = _HFON; // enable HRCCLK
12+
PLLCON = _PLLON; // init PLL
13+
14+
while (!(PLLCON & _PLLSTA)) { // wait for PLL to lock phase
15+
CLR_WDT();
16+
}
17+
18+
PLLCON |= _PLLFS; // switch OSCSCLK
19+
CLKCON |= _FS; // use HRCCLK as SYSCLK
2420
}

src/clock.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef _CLOCK_H_
2-
#define _CLOCK_H_
1+
#ifndef CLOCK_H
2+
#define CLOCK_H
33

44
void clock_init();
55

0 commit comments

Comments
 (0)