Skip to content

Commit ecdadfb

Browse files
committed
Implement basic keyboard firmware
Lights up capslock LED and when in USB suspend blinks it every 500ms. Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 7e61d58 commit ecdadfb

File tree

12 files changed

+489
-1
lines changed

12 files changed

+489
-1
lines changed

.github/workflows/firmware.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,21 @@ jobs:
3434
- run: cargo install flip-link
3535
- run: cargo make --cwd b1display
3636
- run: cargo make --cwd c1minimal
37+
- run: cargo make --cwd keyboard
3738
- run: cargo make --cwd ledmatrix build-release
3839
- run: cargo make --cwd ledmatrix build-release-10k
3940
- run: cargo make --cwd ledmatrix build-release-evt
4041
- run: cargo make --cwd b1display build-release
4142
- run: cargo make --cwd c1minimal build-release
43+
- run: cargo make --cwd keyboard build-release
4244

4345
- name: Convert to UF2 format
4446
run: |
4547
sudo apt-get update
4648
sudo apt-get install -y libudev-dev
4749
cargo make --cwd b1display uf2
4850
cargo make --cwd c1minimal uf2
51+
cargo make --cwd keyboard uf2
4952
cargo make --cwd ledmatrix build-release-10k-uf2
5053
cargo make --cwd ledmatrix build-release-evt-uf2
5154
cargo make --cwd ledmatrix uf2
@@ -56,6 +59,7 @@ jobs:
5659
sudo apt-get install -y llvm
5760
cargo make --cwd b1display bin
5861
cargo make --cwd c1minimal bin
62+
cargo make --cwd keyboard bin
5963
cargo make --cwd ledmatrix bin
6064
6165
- name: Upload ledmatrix files
@@ -87,6 +91,14 @@ jobs:
8791
target/thumbv6m-none-eabi/release/c1minimal.bin
8892
target/thumbv6m-none-eabi/release/c1minimal.uf2
8993
94+
- name: Upload keyboard files
95+
uses: actions/upload-artifact@v3
96+
with:
97+
name: c1minimal_fw_${{github.sha}}
98+
path: |
99+
target/thumbv6m-none-eabi/release/keyboard.bin
100+
target/thumbv6m-none-eabi/release/keyboard.uf2
101+
90102
linting:
91103
name: Linting
92104
runs-on: ubuntu-latest
@@ -103,6 +115,7 @@ jobs:
103115
sudo apt-get install -y libudev-dev
104116
cargo make clippy --cwd b1display
105117
cargo make clippy --cwd c1minimal
118+
cargo make clippy --cwd keyboard
106119
cargo make clippy --cwd ledmatrix
107120
108121
# fl16-inputmodules/src/serialnum.rs
@@ -114,6 +127,7 @@ jobs:
114127
cargo pkgid -p fl16-inputmodules | cut -d "#" -f2 >> versions.tmp
115128
cargo pkgid -p b1display | cut -d "#" -f2 >> versions.tmp
116129
cargo pkgid -p c1minimal | cut -d "#" -f2 >> versions.tmp
130+
cargo pkgid -p keyboard | cut -d "#" -f2 >> versions.tmp
117131
cargo pkgid -p ledmatrix | cut -d "#" -f2 >> versions.tmp
118132
uniq -c versions.tmp | [ $(wc -l) -eq 1 ]
119133
@@ -129,5 +143,6 @@ jobs:
129143
- run: |
130144
cargo fmt -p b1display -- --check
131145
cargo fmt -p c1minimal -- --check
146+
cargo fmt -p keyboard -- --check
132147
cargo fmt -p ledmatrix -- --check
133148
cargo fmt -p fl16-inputmodules -- --check

.github/workflows/software.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
paths-ignore:
99
- 'b1display/**'
1010
- 'c1minimal/**'
11+
- 'keyboard/**'
1112
- 'fl16-inputmodules/**'
1213
- 'ledmatrix/**'
1314
pull_request:
@@ -16,6 +17,7 @@ on:
1617
paths-ignore:
1718
- 'b1display/**'
1819
- 'c1minimal/**'
20+
- 'keyboard/**'
1921
- 'fl16-inputmodules/**'
2022
- 'ledmatrix/**'
2123

.github/workflows/traditional-cargo.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
- run: cargo build -p ledmatrix --features evt
3737
- run: cargo build -p b1display
3838
- run: cargo build -p c1minimal
39+
- run: cargo build -p keyboard
3940

4041
linux-software:
4142
name: Build Linux
@@ -92,6 +93,7 @@ jobs:
9293
run: |
9394
cargo clippy -p b1display -- --deny=warnings
9495
cargo clippy -p c1minimal -- --deny=warnings
96+
cargo clippy -p keyboard -- --deny=warnings
9597
cargo clippy -p ledmatrix -- --deny=warnings
9698
cargo clippy -p fl16-inputmodules -- --deny=warnings
9799

Cargo.lock

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

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ resolver = "2"
77
members = [
88
"b1display",
99
"c1minimal",
10+
"keyboard",
1011
"ledmatrix",
1112
"fl16-inputmodules",
1213
"inputmodule-control",
@@ -57,6 +58,12 @@ incremental = true
5758
# To allow single-stepping through code use 0. Will cause timing issues, though
5859
opt-level = 3
5960

61+
[profile.dev.package.keyboard]
62+
codegen-units = 1
63+
incremental = true
64+
# To allow single-stepping through code use 0. Will cause timing issues, though
65+
opt-level = 3
66+
6067
[profile.dev.package.b1display]
6168
codegen-units = 1
6269
incremental = true

fl16-inputmodules/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ default = []
4747
ledmatrix = ["is31fl3741"]
4848
b1display = ["st7306", "embedded-graphics", "tinybmp"]
4949
c1minimal = ["smart-leds", "ws2812-pio"]
50+
keyboard = []

fl16-inputmodules/src/keyboard_hal.rs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Taken from rp_pico hal and adjusted
2+
3+
pub extern crate rp2040_hal as hal;
4+
5+
extern crate cortex_m_rt;
6+
pub use hal::entry;
7+
8+
/// The linker will place this boot block at the start of our program image. We
9+
/// need this to help the ROM bootloader get our code up and running.
10+
#[link_section = ".boot2"]
11+
#[no_mangle]
12+
#[used]
13+
pub static BOOT2_FIRMWARE: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
14+
15+
pub use hal::pac;
16+
17+
hal::bsp_pins!(
18+
/// GPIO 0 is connected to the SLEEP# pin of the EC
19+
Gpio0 { name: sleep },
20+
/// Mux selector A
21+
Gpio1 { name: mux_a },
22+
/// Mux selector B
23+
Gpio2 { name: mux_b },
24+
/// Mux selector C
25+
Gpio3 { name: mux_c },
26+
/// Mux enable
27+
Gpio4 { name: mux_enable },
28+
/// Pull low when firmware has started to turn off bootloader logic
29+
Gpio5 { name: boot_done },
30+
/// Connected to KSI5 but unused, should use high-Z
31+
Gpio6 {
32+
name: ksi5_reserved
33+
},
34+
/// Connected to KSI5 but unused, should use high-Z
35+
Gpio7 {
36+
name: ksi6_reserved
37+
},
38+
/// Keyboard column drive
39+
Gpio8 { name: kso0 },
40+
/// Keyboard column drive
41+
Gpio9 { name: kso1 },
42+
/// Keyboard column drive
43+
Gpio10 { name: kso2 },
44+
/// Keyboard column drive
45+
Gpio11 { name: kso3 },
46+
/// Keyboard column drive
47+
Gpio12 { name: kso4 },
48+
/// Keyboard column drive
49+
Gpio13 { name: kso5 },
50+
/// Keyboard column drive
51+
Gpio14 { name: kso6 },
52+
/// Keyboard column drive
53+
Gpio15 { name: kso7 },
54+
/// Keyboard column drive
55+
Gpio16 { name: kso13 },
56+
/// Keyboard column drive
57+
Gpio17 { name: kso12 },
58+
/// Keyboard column drive
59+
Gpio18 { name: kso11 },
60+
/// Keyboard column drive
61+
Gpio19 { name: kso10 },
62+
/// Keyboard column drive
63+
Gpio20 { name: kso9 },
64+
/// Keyboard column drive
65+
Gpio21 { name: kso8 },
66+
/// Keyboard column drive
67+
Gpio22 { name: kso15 },
68+
/// Keyboard column drive
69+
Gpio23 { name: kso14 },
70+
/// Capslock LED
71+
Gpio24 { name: caps_led },
72+
/// Single zone backlight (unused on RGB keyboard)
73+
Gpio25 { name: backlight },
74+
/// GPIO 26 is connected to I2C SDA of the LED controller
75+
Gpio26 {
76+
name: gpio26,
77+
aliases: {
78+
/// I2C Function alias for pin [crate::Pins::gpio26].
79+
FunctionI2C: Gp26I2C1Sda
80+
}
81+
},
82+
/// GPIO 27 is connected to I2C SCL of the LED controller
83+
Gpio27 {
84+
name: gpio27,
85+
aliases: {
86+
/// I2C Function alias for pin [crate::Pins::gpio27].
87+
FunctionI2C: Gp27I2C1Scl
88+
}
89+
},
90+
/// Analog IN from mux
91+
Gpio28 { name: analog_in },
92+
/// GPIO 29 is connected to the SDB pin of the LED controller
93+
Gpio29 { name: sdb },
94+
);
95+
96+
// External crystal frequency, same as Raspberry Pi Pico
97+
pub const XOSC_CRYSTAL_FREQ: u32 = 12_000_000;

fl16-inputmodules/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
all(feature = "ledmatrix", feature = "b1display"),
66
all(feature = "ledmatrix", feature = "c1minimal"),
77
all(feature = "b1display", feature = "c1minimal"),
8+
all(feature = "ledmatrix", feature = "keyboard"),
9+
all(feature = "b1display", feature = "keyboard"),
10+
all(feature = "c1minimal", feature = "keyboard"),
811
))]
9-
compile_error!("Features \"ledmatrix\", \"b1display\", and \"c1minimal\" are mutually exclusive");
12+
compile_error!(
13+
"Features \"ledmatrix\", \"b1display\", \"c1minimal\", and \"keyboard\" are mutually exclusive"
14+
);
1015

1116
#[cfg(feature = "ledmatrix")]
1217
pub mod fl16;
@@ -30,5 +35,8 @@ pub mod lcd_hal;
3035
#[cfg(feature = "c1minimal")]
3136
pub mod minimal_hal;
3237

38+
#[cfg(feature = "keyboard")]
39+
pub mod keyboard_hal;
40+
3341
pub mod control;
3442
pub mod serialnum;

keyboard/Cargo.toml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[package]
2+
edition = "2021"
3+
name = "keyboard"
4+
version = "0.1.7"
5+
6+
[features]
7+
default = ["macropad"]
8+
cli = []
9+
ansi = []
10+
iso = []
11+
jis = []
12+
numpad = []
13+
macropad = []
14+
15+
[dependencies]
16+
cortex-m.workspace = true
17+
cortex-m-rt.workspace = true
18+
embedded-hal.workspace = true
19+
20+
defmt.workspace = true
21+
defmt-rtt.workspace = true
22+
23+
#panic-probe.workspace = true
24+
rp2040-panic-usb-boot.workspace = true
25+
26+
# Not using an external BSP, we've got the Framework Laptop 16 BSPs locally in this crate
27+
rp2040-hal.workspace = true
28+
rp2040-boot2.workspace = true
29+
30+
# USB Serial
31+
usb-device.workspace = true
32+
heapless.workspace = true
33+
usbd-serial.workspace = true
34+
usbd-hid.workspace = true
35+
fugit.workspace = true
36+
37+
[dependencies.fl16-inputmodules]
38+
path = "../fl16-inputmodules"
39+
features = ["keyboard"]

keyboard/Makefile.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
extend = "../Makefile.toml"
2+
3+
[tasks.uf2]
4+
command = "elf2uf2-rs"
5+
args = ["../target/thumbv6m-none-eabi/release/b1display", "../target/thumbv6m-none-eabi/release/b1display.uf2"]
6+
dependencies = ["build-release"]
7+
install_crate = "elf2uf2-rs"
8+
9+
[tasks.bin]
10+
command = "llvm-objcopy"
11+
args = ["-Obinary", "../target/thumbv6m-none-eabi/release/b1display", "../target/thumbv6m-none-eabi/release/b1display.bin"]
12+
dependencies = ["build-release"]

keyboard/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Keyboard
2+
3+
NOT THE OFFICIAL Keyboard firmware
4+
Just experimental reference code for building keyboard firmare in Rust

0 commit comments

Comments
 (0)