From dba761decee083075f089571d5a79f66de8b49f5 Mon Sep 17 00:00:00 2001 From: Haobo Gu Date: Fri, 26 Jan 2024 15:43:17 +0800 Subject: [PATCH] feat: release RMK 0.1.3 Signed-off-by: Haobo Gu --- README.md | 7 ++-- boards/rp2040/Cargo.lock | 68 +++++++++++++++++++++++++++++++++-- boards/rp2040/Cargo.toml | 9 +++-- boards/rp2040/src/main.rs | 2 +- boards/rp2040/vial.json | 43 ++++++++++++++++++++++ boards/stm32f4/Cargo.lock | 74 ++++++++++++++++++++++++++++++++++++-- boards/stm32f4/Cargo.toml | 9 +++-- boards/stm32f4/build.rs | 41 +++++++++++++++++++-- boards/stm32f4/src/main.rs | 2 +- boards/stm32f4/vial.json | 43 ++++++++++++++++++++++ boards/stm32h7/Cargo.lock | 4 +-- boards/stm32h7/Cargo.toml | 4 +-- boards/stm32h7/build.rs | 1 + boards/stm32h7/src/main.rs | 5 +-- boards/stm32h7/src/vial.rs | 1 + rmk/Cargo.toml | 2 +- 16 files changed, 291 insertions(+), 24 deletions(-) create mode 100644 boards/rp2040/vial.json create mode 100644 boards/stm32f4/vial.json diff --git a/README.md b/README.md index 7bc849a7..40465217 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,11 @@ Keyboard firmware for cortex-m, with layer/dynamic keymap/[vial](https://get.vial.today) support, written in Rust. +RMK is under active development, breaking changes may happen. Please check the latest doc or file an issue if you have any problem. + ## News -Rmk just released version 0.1.0, migrate to [Embassy](https://github.com/embassy-rs/embassy)! By migrating to Embassy, Rmk now has better async support, more supported MCUs and much easier usages than before. For examples using Embassy, check [`boards`](https://github.com/HaoboGu/rmk/tree/main/boards) folder! +RMK just released version 0.1.0, migrate to [Embassy](https://github.com/embassy-rs/embassy)! By migrating to Embassy, RMK now has better async support, more supported MCUs and much easier usages than before. For examples using Embassy, check [`boards`](https://github.com/HaoboGu/rmk/tree/main/boards) folder! ## Prerequisites @@ -16,6 +18,7 @@ This crate requires Rust 1.75 and up. `openocd`(stm32) or `probe-rs`(stm32/rp204 ## Usage +NOTE: RMK You can build your own keyboard firmware using RMK or try built-in firmware example for stm32h7 & rp2040. ### Build your own firmware @@ -93,7 +96,7 @@ A lot of todos at the list, any contributions are welcomed :) - [ ] cli tools ## License -Rmk is licensed under either of +RMK is licensed under either of - Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) - MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) diff --git a/boards/rp2040/Cargo.lock b/boards/rp2040/Cargo.lock index 610559f9..40febff9 100644 --- a/boards/rp2040/Cargo.lock +++ b/boards/rp2040/Cargo.lock @@ -113,6 +113,15 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -129,6 +138,26 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "const-gen" +version = "1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbfc446f8d46196335995e72ee07271b558d0fab5152edc8b5c3d2a44da30e87" +dependencies = [ + "const-gen-derive", +] + +[[package]] +name = "const-gen-derive" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab3a2f53a0577d76789175307af9b6ab5ed3c119f3ce4e0646f6ba5ae6ff100" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "cortex-m" version = "0.7.7" @@ -834,6 +863,12 @@ dependencies = [ "either", ] +[[package]] +name = "json" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd" + [[package]] name = "lalrpop" version = "0.19.12" @@ -916,6 +951,17 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "lzma-sys" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fda04ab3764e6cde78b9974eec4f779acaba7c4e84b36eca3cf77c581b85d27" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + [[package]] name = "memchr" version = "2.7.1" @@ -1129,6 +1175,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "pkg-config" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" + [[package]] name = "portable-atomic" version = "1.6.0" @@ -1255,7 +1307,7 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "rmk" -version = "0.1.2" +version = "0.1.3" dependencies = [ "byteorder", "defmt", @@ -1275,8 +1327,9 @@ dependencies = [ [[package]] name = "rmk-rp2040" -version = "0.1.2" +version = "0.1.3" dependencies = [ + "const-gen", "cortex-m-rt", "defmt", "defmt-rtt", @@ -1284,11 +1337,13 @@ dependencies = [ "embassy-rp", "embassy-time", "embedded-storage", + "json", "packed_struct", "panic-probe", "portable-atomic", "rmk", "static_cell", + "xz2", ] [[package]] @@ -1800,3 +1855,12 @@ checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" dependencies = [ "tap", ] + +[[package]] +name = "xz2" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2" +dependencies = [ + "lzma-sys", +] diff --git a/boards/rp2040/Cargo.toml b/boards/rp2040/Cargo.toml index 9270f963..29f67b1d 100644 --- a/boards/rp2040/Cargo.toml +++ b/boards/rp2040/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rmk-rp2040" -version = "0.1.2" +version = "0.1.3" authors = ["Haobo Gu "] description = "Keyboard firmware written in Rust" homepage = "https://github.com/haobogu/rmk" @@ -10,7 +10,7 @@ edition = "2021" license = "MIT OR Apache-2.0" [dependencies] -rmk = { version = "0.1.2", path = "../../rmk" } +rmk = { version = "0.1.3", path = "../../rmk" } embassy-time = { version = "0.3", features = ["defmt"] } embassy-rp = { version = "0.1", features = [ "defmt", @@ -37,6 +37,11 @@ panic-probe = { version = "0.3", features = ["print-defmt"] } # on macOS with Apple Silicon at least # default = ["rp-pico/disable-intrinsics"] +[build-dependencies] +xz2 = "0.1.7" +json = "0.12" +const-gen = "1.6" + [[bin]] name = "rmk-rp2040" test = false diff --git a/boards/rp2040/src/main.rs b/boards/rp2040/src/main.rs index 3862c34b..db134b0c 100644 --- a/boards/rp2040/src/main.rs +++ b/boards/rp2040/src/main.rs @@ -33,7 +33,7 @@ const FLASH_SIZE: usize = 2 * 1024 * 1024; #[embassy_executor::main] async fn main(_spawner: Spawner) { - info!("Rmk start!"); + info!("RMK start!"); // Initialize peripherals let p = embassy_rp::init(Default::default()); diff --git a/boards/rp2040/vial.json b/boards/rp2040/vial.json new file mode 100644 index 00000000..8bc2797d --- /dev/null +++ b/boards/rp2040/vial.json @@ -0,0 +1,43 @@ +{ + "name": "HID Keyboard", + "vendorId": "0x4C4B", + "productId": "0x4643", + "lighting": "none", + "matrix": { + "rows": 4, + "cols": 3 + }, + "layouts": { + "labels": [ + [ + "label", + "label2" + ] + ], + "keymap": [ + [ + "0,0", + "0,1", + "0,2" + ], + [ + "1,0", + "1,1", + "1,2" + ], + [ + "2,0", + "2,1", + "2,2" + ], + [ + { + "y": -2, + "x": 4 + }, + "3,0", + "3,2" + ] + ] + } +} \ No newline at end of file diff --git a/boards/stm32f4/Cargo.lock b/boards/stm32f4/Cargo.lock index 160d8b48..c2e382c7 100644 --- a/boards/stm32f4/Cargo.lock +++ b/boards/stm32f4/Cargo.lock @@ -75,12 +75,41 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "const-gen" +version = "1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbfc446f8d46196335995e72ee07271b558d0fab5152edc8b5c3d2a44da30e87" +dependencies = [ + "const-gen-derive", +] + +[[package]] +name = "const-gen-derive" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab3a2f53a0577d76789175307af9b6ab5ed3c119f3ce4e0646f6ba5ae6ff100" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "cortex-m" version = "0.7.7" @@ -638,6 +667,18 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" +[[package]] +name = "json" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd" + +[[package]] +name = "libc" +version = "0.2.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" + [[package]] name = "linked_list_allocator" version = "0.10.5" @@ -666,6 +707,17 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "lzma-sys" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fda04ab3764e6cde78b9974eec4f779acaba7c4e84b36eca3cf77c581b85d27" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + [[package]] name = "nb" version = "0.1.3" @@ -753,6 +805,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkg-config" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" + [[package]] name = "portable-atomic" version = "1.6.0" @@ -815,7 +873,7 @@ checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" [[package]] name = "rmk" -version = "0.1.2" +version = "0.1.3" dependencies = [ "byteorder", "defmt", @@ -835,8 +893,9 @@ dependencies = [ [[package]] name = "rmk-stm32f4" -version = "0.1.2" +version = "0.1.3" dependencies = [ + "const-gen", "cortex-m", "cortex-m-rt", "defmt", @@ -845,10 +904,12 @@ dependencies = [ "embassy-stm32", "embassy-time", "embedded-storage", + "json", "packed_struct", "panic-probe", "rmk", "static_cell", + "xz2", ] [[package]] @@ -1115,3 +1176,12 @@ checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" dependencies = [ "tap", ] + +[[package]] +name = "xz2" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2" +dependencies = [ + "lzma-sys", +] diff --git a/boards/stm32f4/Cargo.toml b/boards/stm32f4/Cargo.toml index b3a8e3df..e5d88d62 100644 --- a/boards/stm32f4/Cargo.toml +++ b/boards/stm32f4/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rmk-stm32f4" -version = "0.1.2" +version = "0.1.3" authors = ["Haobo Gu "] description = "Keyboard firmware written in Rust" homepage = "https://github.com/haobogu/rmk" @@ -10,7 +10,7 @@ edition = "2021" license = "MIT OR Apache-2.0" [dependencies] -rmk = { version = "0.1.2", path = "../../rmk" } +rmk = { version = "0.1.3", path = "../../rmk" } cortex-m = { version = "0.7.7", features = ['critical-section-single-core'] } cortex-m-rt = "0.7.3" embassy-time = { version = "0.3", features = ["tick-hz-32_768", "defmt"] } @@ -34,6 +34,11 @@ defmt = "0.3" defmt-rtt = "0.4" panic-probe = { version = "0.3", features = ["print-defmt"] } +[build-dependencies] +xz2 = "0.1.7" +json = "0.12" +const-gen = "1.6" + [[bin]] name = "rmk-stm32f4" test = false diff --git a/boards/stm32f4/build.rs b/boards/stm32f4/build.rs index 2bfc6a14..75db1551 100644 --- a/boards/stm32f4/build.rs +++ b/boards/stm32f4/build.rs @@ -10,12 +10,17 @@ //! //! The build script also sets the linker flags to tell it which link script to use. -use std::env; +use const_gen::*; use std::fs::File; -use std::io::Write; -use std::path::PathBuf; +use std::io::{Read, Write}; +use std::path::{Path, PathBuf}; +use std::{env, fs}; +use xz2::read::XzEncoder; fn main() { + // Generate vial config at the root of project + generate_vial_config(); + // Put `memory.x` in our output directory and ensure it's // on the linker search path. let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); @@ -44,5 +49,35 @@ fn main() { // Set the extra linker script from defmt println!("cargo:rustc-link-arg=-Tdefmt.x"); + // Use flip-link overflow check: https://github.com/knurling-rs/flip-link println!("cargo:rustc-linker=flip-link"); } + +fn generate_vial_config() { + // Generated vial config file + let out_file = Path::new(&env::var_os("OUT_DIR").unwrap()).join("config_generated.rs"); + + let p = Path::new("vial.json"); + let mut content = String::new(); + match File::open(&p) { + Ok(mut file) => { + file.read_to_string(&mut content) + .expect("Cannot read vial.json"); + } + Err(e) => println!("Cannot find vial.json {:?}: {}", p, e), + }; + + let vial_cfg = json::stringify(json::parse(&content).unwrap()); + let mut keyboard_def_compressed: Vec = Vec::new(); + XzEncoder::new(vial_cfg.as_bytes(), 6) + .read_to_end(&mut keyboard_def_compressed) + .unwrap(); + + let keyboard_id: Vec = vec![0xB9, 0xBC, 0x09, 0xB2, 0x9D, 0x37, 0x4C, 0xEA]; + let const_declarations = vec![ + const_declaration!(pub VIAL_KEYBOARD_DEF = keyboard_def_compressed), + const_declaration!(pub VIAL_KEYBOARD_ID = keyboard_id), + ] + .join("\n"); + fs::write(&out_file, const_declarations).unwrap(); +} diff --git a/boards/stm32f4/src/main.rs b/boards/stm32f4/src/main.rs index ccd33eef..61d62238 100644 --- a/boards/stm32f4/src/main.rs +++ b/boards/stm32f4/src/main.rs @@ -32,7 +32,7 @@ const EEPROM_SIZE: usize = 128; #[embassy_executor::main] async fn main(_spawner: Spawner) { - info!("Rmk start!"); + info!("RMK start!"); // RCC config let config = Config::default(); diff --git a/boards/stm32f4/vial.json b/boards/stm32f4/vial.json new file mode 100644 index 00000000..8bc2797d --- /dev/null +++ b/boards/stm32f4/vial.json @@ -0,0 +1,43 @@ +{ + "name": "HID Keyboard", + "vendorId": "0x4C4B", + "productId": "0x4643", + "lighting": "none", + "matrix": { + "rows": 4, + "cols": 3 + }, + "layouts": { + "labels": [ + [ + "label", + "label2" + ] + ], + "keymap": [ + [ + "0,0", + "0,1", + "0,2" + ], + [ + "1,0", + "1,1", + "1,2" + ], + [ + "2,0", + "2,1", + "2,2" + ], + [ + { + "y": -2, + "x": 4 + }, + "3,0", + "3,2" + ] + ] + } +} \ No newline at end of file diff --git a/boards/stm32h7/Cargo.lock b/boards/stm32h7/Cargo.lock index d8a9dec3..bc6eaa05 100644 --- a/boards/stm32h7/Cargo.lock +++ b/boards/stm32h7/Cargo.lock @@ -873,7 +873,7 @@ checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" [[package]] name = "rmk" -version = "0.1.2" +version = "0.1.3" dependencies = [ "byteorder", "defmt", @@ -893,7 +893,7 @@ dependencies = [ [[package]] name = "rmk-stm32h7" -version = "0.1.2" +version = "0.1.3" dependencies = [ "const-gen", "cortex-m", diff --git a/boards/stm32h7/Cargo.toml b/boards/stm32h7/Cargo.toml index 51bb931e..30e655d7 100644 --- a/boards/stm32h7/Cargo.toml +++ b/boards/stm32h7/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rmk-stm32h7" -version = "0.1.2" +version = "0.1.3" authors = ["Haobo Gu "] description = "Keyboard firmware written in Rust" homepage = "https://github.com/haobogu/rmk" @@ -10,7 +10,7 @@ edition = "2021" license = "MIT OR Apache-2.0" [dependencies] -rmk = { version = "0.1.2", path = "../../rmk" } +rmk = { version = "0.1.3", path = "../../rmk" } cortex-m = { version = "0.7.7", features = ['critical-section-single-core'] } cortex-m-rt = "0.7.3" embassy-time = { version = "0.3", features = ["tick-hz-32_768", "defmt"] } diff --git a/boards/stm32h7/build.rs b/boards/stm32h7/build.rs index a91fd212..75db1551 100644 --- a/boards/stm32h7/build.rs +++ b/boards/stm32h7/build.rs @@ -49,6 +49,7 @@ fn main() { // Set the extra linker script from defmt println!("cargo:rustc-link-arg=-Tdefmt.x"); + // Use flip-link overflow check: https://github.com/knurling-rs/flip-link println!("cargo:rustc-linker=flip-link"); } diff --git a/boards/stm32h7/src/main.rs b/boards/stm32h7/src/main.rs index b3c08185..b6d28e39 100644 --- a/boards/stm32h7/src/main.rs +++ b/boards/stm32h7/src/main.rs @@ -5,9 +5,6 @@ mod macros; mod keymap; mod vial; -// #[macro_use] -// pub mod rtt_logger; -// use log::info; use crate::keymap::{COL, NUM_LAYER, ROW}; use core::cell::RefCell; @@ -39,7 +36,7 @@ async fn main(_spawner: Spawner) { // if cfg!(debug_assertions) { // rtt_logger::init(log::LevelFilter::Info); // } - info!("Rmk start!"); + info!("RMK start!"); // RCC config let mut config = Config::default(); { diff --git a/boards/stm32h7/src/vial.rs b/boards/stm32h7/src/vial.rs index b087bed2..9c3362cf 100644 --- a/boards/stm32h7/src/vial.rs +++ b/boards/stm32h7/src/vial.rs @@ -1,4 +1,5 @@ // Use `build.rs` automatically generate vial config, according to `vial.json` +// Please put `vial.json` at your project's root include!(concat!(env!("OUT_DIR"), "/config_generated.rs")); // Or you can manually generate vial config then put here diff --git a/rmk/Cargo.toml b/rmk/Cargo.toml index 4ee78897..6f1873fd 100644 --- a/rmk/Cargo.toml +++ b/rmk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rmk" -version = "0.1.2" +version = "0.1.3" authors = ["Haobo Gu "] description = "Keyboard firmware written in Rust" homepage = "https://github.com/haobogu/rmk"