diff --git a/boards/rp2040/src/main.rs b/boards/rp2040/src/main.rs index 7279fd14..3862c34b 100644 --- a/boards/rp2040/src/main.rs +++ b/boards/rp2040/src/main.rs @@ -7,7 +7,10 @@ mod keymap; mod macros; mod vial; +use crate::keymap::{COL, NUM_LAYER, ROW}; use core::cell::RefCell; +use defmt::*; +use defmt_rtt as _; use embassy_executor::Spawner; use embassy_rp::{ bind_interrupts, @@ -16,21 +19,15 @@ use embassy_rp::{ peripherals::{self, USB}, usb::{Driver, InterruptHandler}, }; - -use defmt::*; -use defmt_rtt as _; use panic_probe as _; -use rmk::{eeprom::EepromStorageConfig, initialize_keyboard_and_run, keymap::KeyMap}; +use rmk::{initialize_keyboard_and_run, keymap::KeyMap}; use static_cell::StaticCell; - -use crate::keymap::{COL, NUM_LAYER, ROW}; +use vial::{VIAL_KEYBOARD_DEF, VIAL_KEYBOARD_ID}; bind_interrupts!(struct Irqs { USBCTRL_IRQ => InterruptHandler; }); -// static SUSPENDED: AtomicBool = AtomicBool::new(false); -const FLASH_SECTOR_15_ADDR: u32 = 15 * 8192; const EEPROM_SIZE: usize = 128; const FLASH_SIZE: usize = 2 * 1024 * 1024; @@ -46,6 +43,8 @@ async fn main(_spawner: Spawner) { // Pin config let (input_pins, output_pins) = config_matrix_pins_rp!(peripherals: p, input: [PIN_6, PIN_7, PIN_8, PIN_9], output: [PIN_19, PIN_20, PIN_21]); + // Use internal flash to emulate eeprom + let flash = Flash::<_, Blocking, FLASH_SIZE>::new_blocking(p.FLASH); // Keymap + eeprom config static MY_KEYMAP: StaticCell< RefCell< @@ -58,19 +57,9 @@ async fn main(_spawner: Spawner) { >, >, > = StaticCell::new(); - let eeprom_storage_config = EepromStorageConfig { - start_addr: FLASH_SECTOR_15_ADDR, - storage_size: 8192, // uses 8KB for eeprom - page_size: 32, - }; - // Use internal flash to emulate eeprom - // let f = Flash::new_blocking(p.FLASH); - let flash = Flash::<_, Blocking, FLASH_SIZE>::new_blocking(p.FLASH); - // let mut flash = Flash::new_blocking(p.FLASH); let keymap = MY_KEYMAP.init(RefCell::new(KeyMap::new( crate::keymap::KEYMAP, Some(flash), - eeprom_storage_config, None, ))); @@ -89,8 +78,8 @@ async fn main(_spawner: Spawner) { input_pins, output_pins, keymap, - &vial::VIAL_KEYBOARD_ID, - &vial::VIAL_KEYBOARD_DEF, + &VIAL_KEYBOARD_ID, + &VIAL_KEYBOARD_DEF, ) .await; } diff --git a/boards/stm32f4/Cargo.toml b/boards/stm32f4/Cargo.toml index cad1f1ef..c7bc6526 100644 --- a/boards/stm32f4/Cargo.toml +++ b/boards/stm32f4/Cargo.toml @@ -1,5 +1,3 @@ -# cargo-features = ["per-package-target"] - [package] name = "rmk-stm32f4" version = "0.1.2" @@ -11,8 +9,6 @@ readme = "../../README.md" edition = "2021" license = "MIT OR Apache-2.0" -# forced-target = "thumbv7em-none-eabihf" - [dependencies] rmk = { version = "0.1.2", path = "../../rmk", features = [ "eeprom", @@ -21,7 +17,6 @@ rmk = { version = "0.1.2", path = "../../rmk", features = [ cortex-m = { version = "0.7.7", features = ['critical-section-single-core'] } cortex-m-rt = "0.7.3" embassy-time = { version = "0.3", git = "https://github.com/embassy-rs/embassy", features = [ - # "tick-hz-1_000_000", "tick-hz-32_768", "defmt", ] } @@ -38,8 +33,6 @@ embassy-executor = { version = "0.5.0", git = "https://github.com/embassy-rs/emb "executor-thread", "integrated-timers", ] } -rtt-target = "0.5.0" -log = "0.4.19" packed_struct = { version = "0.10.1", default-features = false } embedded-storage = { version = "0.3" } static_cell = { version = "2" } @@ -52,4 +45,4 @@ panic-probe = { version = "0.3", features = ["print-defmt"] } [[bin]] name = "rmk-stm32f4" test = false -bench = false \ No newline at end of file +bench = false diff --git a/boards/stm32f4/src/main.rs b/boards/stm32f4/src/main.rs index 25231250..d65b03e7 100644 --- a/boards/stm32f4/src/main.rs +++ b/boards/stm32f4/src/main.rs @@ -19,8 +19,9 @@ use embassy_stm32::{ Config, }; use panic_probe as _; -use rmk::{eeprom::EepromStorageConfig, initialize_keyboard_and_run, keymap::KeyMap}; +use rmk::{initialize_keyboard_and_run, keymap::KeyMap}; use static_cell::StaticCell; +use vial::{VIAL_KEYBOARD_DEF, VIAL_KEYBOARD_ID}; use crate::keymap::{COL, NUM_LAYER, ROW}; @@ -28,12 +29,11 @@ bind_interrupts!(struct Irqs { OTG_FS => InterruptHandler; }); -const FLASH_SECTOR_7_ADDR: u32 = 0x60000; const EEPROM_SIZE: usize = 128; #[embassy_executor::main] async fn main(_spawner: Spawner) { - info!("start!"); + info!("Rmk start!"); // RCC config let config = Config::default(); @@ -56,25 +56,19 @@ async fn main(_spawner: Spawner) { // Pin config let (input_pins, output_pins) = config_matrix_pins_stm32!(peripherals: p, input: [PD9, PD8, PB13, PB12], output: [PE13, PE14, PE15]); + // Use internal flash to emulate eeprom + let f = Flash::new_blocking(p.FLASH); // Keymap + eeprom config static MY_KEYMAP: StaticCell< RefCell, EEPROM_SIZE, ROW, COL, NUM_LAYER>>, > = StaticCell::new(); - let eeprom_storage_config = EepromStorageConfig { - start_addr: FLASH_SECTOR_7_ADDR, - storage_size: 0x20000, // uses last sector, 128KB for eeprom - page_size: 8, - }; - // Use internal flash to emulate eeprom - let f = Flash::new_blocking(p.FLASH); let keymap = MY_KEYMAP.init(RefCell::new(KeyMap::new( crate::keymap::KEYMAP, Some(f), - eeprom_storage_config, None, ))); - // Initialize all utilities: keyboard, usb and keymap + // Start serving initialize_keyboard_and_run::< Driver<'_, USB_OTG_FS>, Input<'_, AnyPin>, @@ -89,7 +83,8 @@ async fn main(_spawner: Spawner) { input_pins, output_pins, keymap, - &vial::VIAL_KEYBOARD_ID, - &vial::VIAL_KEYBOARD_DEF, - ).await; + &VIAL_KEYBOARD_ID, + &VIAL_KEYBOARD_DEF, + ) + .await; } diff --git a/boards/stm32h7/Cargo.toml b/boards/stm32h7/Cargo.toml index 69e7df20..2805b9fd 100644 --- a/boards/stm32h7/Cargo.toml +++ b/boards/stm32h7/Cargo.toml @@ -1,5 +1,3 @@ -# cargo-features = ["per-package-target"] - [package] name = "rmk-stm32h7" version = "0.1.2" @@ -11,8 +9,6 @@ readme = "../../README.md" edition = "2021" license = "MIT OR Apache-2.0" -# forced-target = "thumbv7em-none-eabihf" - [dependencies] rmk = { version = "0.1.2", path = "../../rmk", features = [ "eeprom", @@ -20,7 +16,6 @@ rmk = { version = "0.1.2", path = "../../rmk", features = [ ] } cortex-m = { version = "0.7.7", features = ['critical-section-single-core'] } cortex-m-rt = "0.7.3" -panic-rtt-target = { version = "0.1.2", features = ["cortex-m"] } embassy-time = { version = "0.3", git = "https://github.com/embassy-rs/embassy", features = [ # "tick-hz-1_000_000", "tick-hz-32_768", @@ -36,16 +31,23 @@ embassy-executor = { version = "0.5.0", git = "https://github.com/embassy-rs/emb "executor-thread", "integrated-timers", ] } -rtt-target = "0.5.0" -log = "0.4.19" packed_struct = { version = "0.10.1", default-features = false } embedded-storage = { version = "0.3" } static_cell = { version = "2" } +# rtt-target = "0.5.0" +# panic-rtt-target = { version = "0.1.2", features = ["cortex-m"] } +# log = "0.4.19" + # defmt deps -# defmt = "0.3.5" -# defmt-rtt = "0.4.0" -# panic-probe = "0.3.1" +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-stm32h7" diff --git a/boards/stm32h7/src/main.rs b/boards/stm32h7/src/main.rs index dd249439..dea17def 100644 --- a/boards/stm32h7/src/main.rs +++ b/boards/stm32h7/src/main.rs @@ -4,11 +4,15 @@ #[macro_use] mod macros; mod keymap; -#[macro_use] -pub mod rtt_logger; mod vial; +// #[macro_use] +// pub mod rtt_logger; +// use log::info; +use crate::keymap::{COL, NUM_LAYER, ROW}; use core::cell::RefCell; +use defmt::*; +use defmt_rtt as _; use embassy_executor::Spawner; use embassy_stm32::{ bind_interrupts, @@ -19,25 +23,22 @@ use embassy_stm32::{ usb_otg::{Driver, InterruptHandler}, Config, }; -use log::info; -use panic_rtt_target as _; -use rmk::{eeprom::EepromStorageConfig, initialize_keyboard_and_run, keymap::KeyMap}; +use panic_probe as _; +use rmk::{initialize_keyboard_and_run, keymap::KeyMap}; use static_cell::StaticCell; - -use crate::keymap::{COL, NUM_LAYER, ROW}; +use vial::{VIAL_KEYBOARD_DEF, VIAL_KEYBOARD_ID}; bind_interrupts!(struct Irqs { OTG_HS => InterruptHandler; }); -const FLASH_SECTOR_15_ADDR: u32 = 15 * 8192; const EEPROM_SIZE: usize = 128; #[embassy_executor::main] async fn main(_spawner: Spawner) { - if cfg!(debug_assertions) { - rtt_logger::init(log::LevelFilter::Info); - } + // if cfg!(debug_assertions) { + // rtt_logger::init(log::LevelFilter::Info); + // } info!("Rmk start!"); // RCC config let mut config = Config::default(); @@ -90,21 +91,15 @@ async fn main(_spawner: Spawner) { // Pin config let (input_pins, output_pins) = config_matrix_pins_stm32!(peripherals: p, input: [PD9, PD8, PB13, PB12], output: [PE13, PE14, PE15]); + // Use internal flash to emulate eeprom + let f = Flash::new_blocking(p.FLASH); // Keymap + eeprom config static MY_KEYMAP: StaticCell< RefCell, EEPROM_SIZE, ROW, COL, NUM_LAYER>>, > = StaticCell::new(); - let eeprom_storage_config = EepromStorageConfig { - start_addr: FLASH_SECTOR_15_ADDR, - storage_size: 8192, // uses 8KB for eeprom - page_size: 32, - }; - // Use internal flash to emulate eeprom - let f = Flash::new_blocking(p.FLASH); let keymap = MY_KEYMAP.init(RefCell::new(KeyMap::new( crate::keymap::KEYMAP, Some(f), - eeprom_storage_config, None, ))); @@ -123,8 +118,8 @@ async fn main(_spawner: Spawner) { input_pins, output_pins, keymap, - &vial::VIAL_KEYBOARD_ID, - &vial::VIAL_KEYBOARD_DEF, + &VIAL_KEYBOARD_ID, + &VIAL_KEYBOARD_DEF, ) .await; } diff --git a/rmk/src/keymap.rs b/rmk/src/keymap.rs index aa29baed..ec806d99 100644 --- a/rmk/src/keymap.rs +++ b/rmk/src/keymap.rs @@ -54,7 +54,6 @@ impl< pub fn new( mut action_map: [[[KeyAction; COL]; ROW]; NUM_LAYER], storage: Option, - eeprom_storage_config: EepromStorageConfig, eeconfig: Option, ) -> KeyMap { // Initialize the allocator at the very beginning of the initialization of the keymap @@ -63,7 +62,7 @@ impl< // 1KB heap size const HEAP_SIZE: usize = 512; // Check page_size and heap size - assert!((eeprom_storage_config.page_size as usize) < HEAP_SIZE); + assert!(F::WRITE_SIZE < HEAP_SIZE); static mut HEAP_MEM: [MaybeUninit; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE]; unsafe { HEAP.init(HEAP_MEM.as_ptr() as usize, HEAP_SIZE) } } @@ -71,6 +70,12 @@ impl< // Initialize eeprom, if success, re-load keymap from it let eeprom = match storage { Some(s) => { + // TODO: Refactor Eeprom so that we don't need this anymore + let eeprom_storage_config = EepromStorageConfig { + start_addr: (F::ERASE_SIZE * (s.capacity() / F::ERASE_SIZE - 1)) as u32, + storage_size: F::ERASE_SIZE as u32, + page_size: F::WRITE_SIZE as u32, + }; let e = Eeprom::new(s, eeprom_storage_config, eeconfig, &mut action_map); // If eeprom is initialized, read keymap from it. match e {