diff --git a/boards/rp2040/Cargo.lock b/boards/rp2040/Cargo.lock index 228f00f2..610559f9 100644 --- a/boards/rp2040/Cargo.lock +++ b/boards/rp2040/Cargo.lock @@ -356,6 +356,9 @@ name = "embassy-futures" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f878075b9794c1e4ac788c95b728f26aa6366d32eeb10c7051389f898f7d067" +dependencies = [ + "defmt", +] [[package]] name = "embassy-hal-internal" @@ -444,6 +447,7 @@ checksum = "dd938f25c0798db4280fcd8026bf4c2f48789aebf8f77b6e5cf8a7693ba114ec" dependencies = [ "cfg-if", "critical-section", + "defmt", "embedded-io-async", "futures-util", "heapless 0.8.0", @@ -489,6 +493,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1587e58ed8f7e0215246e6bb8d7ef4837db682e209e5ef7410a81c500dc949e5" dependencies = [ + "defmt", "embassy-futures", "embassy-net-driver-channel", "embassy-sync 0.5.0", @@ -532,6 +537,9 @@ name = "embedded-hal" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89" +dependencies = [ + "defmt", +] [[package]] name = "embedded-hal-async" @@ -1250,6 +1258,7 @@ name = "rmk" version = "0.1.2" dependencies = [ "byteorder", + "defmt", "embassy-futures", "embassy-sync 0.5.0", "embassy-time", @@ -1556,6 +1565,9 @@ name = "usb-device" version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f6cc3adc849b5292b4075fc0d5fdcf2f24866e88e336dd27a8943090a520508" +dependencies = [ + "defmt", +] [[package]] name = "usbd-hid" @@ -1563,6 +1575,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "975bd411f4a939986751ea09992a24fa47c4d25c6ed108d04b4c2999a4fd0132" dependencies = [ + "defmt", "serde", "ssmarshal", "usb-device", diff --git a/boards/rp2040/Cargo.toml b/boards/rp2040/Cargo.toml index 2870eb2f..5bd464e4 100644 --- a/boards/rp2040/Cargo.toml +++ b/boards/rp2040/Cargo.toml @@ -30,7 +30,7 @@ cortex-m-rt = "0.7.3" embedded-storage = "0.3" portable-atomic = { version = "1.5", features = ["critical-section"] } packed_struct = { version = "0.10.1", default-features = false } -static_cell = { version = "2" } +static_cell = "2" defmt = "0.3" defmt-rtt = "0.4" panic-probe = { version = "0.3", features = ["print-defmt"] } diff --git a/boards/stm32f4/.cargo/config.toml b/boards/stm32f4/.cargo/config.toml index cfb1fed2..d2ae2dde 100644 --- a/boards/stm32f4/.cargo/config.toml +++ b/boards/stm32f4/.cargo/config.toml @@ -33,4 +33,4 @@ target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) # target = "thumbv8m.main-none-eabihf" # Cortex-M33 (with FPU) [env] -DEFMT_LOG = "info" \ No newline at end of file +DEFMT_LOG = "debug" \ No newline at end of file diff --git a/boards/stm32f4/Cargo.lock b/boards/stm32f4/Cargo.lock index 073a5b4d..160d8b48 100644 --- a/boards/stm32f4/Cargo.lock +++ b/boards/stm32f4/Cargo.lock @@ -256,6 +256,9 @@ name = "embassy-futures" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f878075b9794c1e4ac788c95b728f26aa6366d32eeb10c7051389f898f7d067" +dependencies = [ + "defmt", +] [[package]] name = "embassy-hal-internal" @@ -396,6 +399,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1587e58ed8f7e0215246e6bb8d7ef4837db682e209e5ef7410a81c500dc949e5" dependencies = [ + "defmt", "embassy-futures", "embassy-net-driver-channel", "embassy-sync 0.5.0", @@ -439,6 +443,9 @@ name = "embedded-hal" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89" +dependencies = [ + "defmt", +] [[package]] name = "embedded-hal-async" @@ -811,6 +818,7 @@ name = "rmk" version = "0.1.2" dependencies = [ "byteorder", + "defmt", "embassy-futures", "embassy-sync 0.5.0", "embassy-time", @@ -1032,6 +1040,9 @@ name = "usb-device" version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f6cc3adc849b5292b4075fc0d5fdcf2f24866e88e336dd27a8943090a520508" +dependencies = [ + "defmt", +] [[package]] name = "usbd-hid" @@ -1039,6 +1050,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "975bd411f4a939986751ea09992a24fa47c4d25c6ed108d04b4c2999a4fd0132" dependencies = [ + "defmt", "serde", "ssmarshal", "usb-device", diff --git a/boards/stm32f4/Cargo.toml b/boards/stm32f4/Cargo.toml index c7b2d566..4345fcad 100644 --- a/boards/stm32f4/Cargo.toml +++ b/boards/stm32f4/Cargo.toml @@ -29,8 +29,8 @@ embassy-executor = { version = "0.5", features = [ "integrated-timers", ] } packed_struct = { version = "0.10.1", default-features = false } -embedded-storage = { version = "0.3" } -static_cell = { version = "2" } +embedded-storage = "0.3" +static_cell = "2" # defmt deps defmt = "0.3" diff --git a/boards/stm32h7/.cargo/config.toml b/boards/stm32h7/.cargo/config.toml index 58414be8..27a0b50a 100644 --- a/boards/stm32h7/.cargo/config.toml +++ b/boards/stm32h7/.cargo/config.toml @@ -37,4 +37,4 @@ target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) # target = "thumbv8m.main-none-eabihf" # Cortex-M33 (with FPU) [env] -DEFMT_LOG = "info" \ No newline at end of file +DEFMT_LOG = "debug" \ No newline at end of file diff --git a/boards/stm32h7/Cargo.lock b/boards/stm32h7/Cargo.lock index 530d4e90..d8a9dec3 100644 --- a/boards/stm32h7/Cargo.lock +++ b/boards/stm32h7/Cargo.lock @@ -285,6 +285,9 @@ name = "embassy-futures" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f878075b9794c1e4ac788c95b728f26aa6366d32eeb10c7051389f898f7d067" +dependencies = [ + "defmt", +] [[package]] name = "embassy-hal-internal" @@ -425,6 +428,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1587e58ed8f7e0215246e6bb8d7ef4837db682e209e5ef7410a81c500dc949e5" dependencies = [ + "defmt", "embassy-futures", "embassy-net-driver-channel", "embassy-sync 0.5.0", @@ -468,6 +472,9 @@ name = "embedded-hal" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89" +dependencies = [ + "defmt", +] [[package]] name = "embedded-hal-async" @@ -869,6 +876,7 @@ name = "rmk" version = "0.1.2" dependencies = [ "byteorder", + "defmt", "embassy-futures", "embassy-sync 0.5.0", "embassy-time", @@ -1093,6 +1101,9 @@ name = "usb-device" version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f6cc3adc849b5292b4075fc0d5fdcf2f24866e88e336dd27a8943090a520508" +dependencies = [ + "defmt", +] [[package]] name = "usbd-hid" @@ -1100,6 +1111,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "975bd411f4a939986751ea09992a24fa47c4d25c6ed108d04b4c2999a4fd0132" dependencies = [ + "defmt", "serde", "ssmarshal", "usb-device", diff --git a/boards/stm32h7/Cargo.toml b/boards/stm32h7/Cargo.toml index c277e42b..c3a9b7f6 100644 --- a/boards/stm32h7/Cargo.toml +++ b/boards/stm32h7/Cargo.toml @@ -29,8 +29,8 @@ embassy-executor = { version = "0.5", features = [ "integrated-timers", ] } packed_struct = { version = "0.10.1", default-features = false } -embedded-storage = { version = "0.3" } -static_cell = { version = "2" } +embedded-storage = "0.3" +static_cell = "2" # rtt-target = "0.5.0" # panic-rtt-target = { version = "0.1.2", features = ["cortex-m"] } diff --git a/rmk/Cargo.toml b/rmk/Cargo.toml index 13368f36..380b48e2 100644 --- a/rmk/Cargo.toml +++ b/rmk/Cargo.toml @@ -10,21 +10,23 @@ edition = "2021" license = "MIT OR Apache-2.0" [dependencies] -embedded-hal = "1.0.0" +embedded-hal = { version = "1.0.0", features = ["defmt-03"] } embedded-storage = "0.3" embedded-alloc = "0.5" -embassy-time = { version = "0.3" } +embassy-time = { version = "0.3", features = ["defmt"] } embassy-usb = { version = "0.1", features = [ + "defmt", "usbd-hid", "max-interface-count-8", "max-handler-count-8", ] } -embassy-sync = { version = "0.5" } -embassy-futures = { version = "0.1" } -num_enum = { version = "0.7", default-features = false } +embassy-sync = { version = "0.5", features = ["defmt"] } +embassy-futures = { version = "0.1", features = ["defmt"] } +usbd-hid = { version = "0.6.1", features = ["defmt"] } +defmt = "0.3" log = "0.4" -static_cell = { version = "2" } -usbd-hid = "0.6.1" +static_cell = "2" +num_enum = { version = "0.7", default-features = false } packed_struct = { version = "0.10", default-features = false } byteorder = { version = "1.4", default-features = false } diff --git a/rmk/src/action.rs b/rmk/src/action.rs index cccbfaec..b31700a2 100644 --- a/rmk/src/action.rs +++ b/rmk/src/action.rs @@ -1,5 +1,5 @@ use crate::keycode::{KeyCode, ModifierCombination}; -use log::{error, warn}; +use defmt::{error, warn, Format}; use num_enum::FromPrimitive; use packed_struct::PackedStructSlice; @@ -15,7 +15,7 @@ use packed_struct::PackedStructSlice; /// The `BasicAction` represents only a single key action of keycodes defined in HID spec. The `Action` represents all actions defined in the following `Action` enum, including modifier combination and layer switch. /// /// The KeyActionType bits varies between different types of a KeyAction, see docs of each enum variant. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Format, Copy, Clone, PartialEq, Eq)] pub enum KeyAction { /// No action. Serialized as 0x0000. No, @@ -120,7 +120,7 @@ impl KeyAction { /// A single basic action that a keyboard can execute. /// An Action can be represented in 12 bits, aka 0x000 ~ 0xFFF -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Format, Copy, Clone, PartialEq, Eq)] pub enum Action { /// A normal key stroke, uses for all keycodes defined in `KeyCode` enum, including mouse key, consumer/system control, etc. /// @@ -177,7 +177,7 @@ impl Action { Action::LayerToggle(layer) } _ => { - warn!("Not a valid 12-bit action code: {:X}", action_code); + warn!("Not a valid 12-bit action code: {:#X}", action_code); Action::Key(KeyCode::No) } } diff --git a/rmk/src/eeprom.rs b/rmk/src/eeprom.rs index 5e9dab94..a9f20eda 100644 --- a/rmk/src/eeprom.rs +++ b/rmk/src/eeprom.rs @@ -7,8 +7,8 @@ use self::eeconfig::{Eeconfig, EEPROM_MAGIC}; use crate::{action::KeyAction, keymap::KeyMapConfig}; use alloc::vec; use core::sync::atomic::{AtomicBool, Ordering::SeqCst}; +use defmt::{debug, error, info, warn}; use embedded_storage::nor_flash::NorFlash; -use log::{debug, error, info, warn}; /// A record in the eeprom, with 2-byte address and 2-byte data /// A record is 4-byte long, so the tracking pos in the `Eeprom` implementation must be a multiple of 4 @@ -133,11 +133,8 @@ impl Eeprom { eeprom.cache[record.address as usize + 1] = record.data as u8; eeprom.pos += eeprom.storage_config.page_size; } - Err(e) => { - error!( - "Restore eeprom value at pos {:X} error: {:?}", - eeprom.pos, e - ); + Err(_) => { + error!("Restore eeprom value at pos {} error", eeprom.pos); break; } } @@ -212,17 +209,16 @@ impl Eeprom { break; } else { warn!( - "Writing addr {:X} is not 0xFF", + "Writing addr {:#X} is not 0xFF", self.storage_config.start_addr + self.pos ); self.pos += self.storage_config.page_size; } } - Err(e) => { + Err(_) => { warn!( - "Check addr {:X} error before writing: {:?}", - self.storage_config.start_addr + self.pos, - e + "Check addr {:#X} error before writing", + self.storage_config.start_addr + self.pos ); // Go to next possible addr self.pos += self.storage_config.page_size; @@ -234,7 +230,7 @@ impl Eeprom { let mut buf = vec![0xFF_u8; self.storage_config.page_size as usize]; buf[..bytes.len()].copy_from_slice(&bytes); debug!( - "EEPROM write storage length {:?} at 0x{:X}: {:X?} ", + "EEPROM write storage length {} at {:#X}: {=[u8]:#X} ", buf.len(), self.storage_config.start_addr + self.pos, buf, @@ -246,11 +242,10 @@ impl Eeprom { { // `pos` should be aligned by write size Ok(_) => self.pos += self.storage_config.page_size, - Err(e) => { + Err(_) => { error!( - "Failed to write record to storage at 0x{:X}: {:?}", - self.storage_config.start_addr + self.pos, - e + "Failed to write record to storage at 0x{:#X}", + self.storage_config.start_addr + self.pos ) } } diff --git a/rmk/src/eeprom/eeconfig.rs b/rmk/src/eeprom/eeconfig.rs index 5ad8d3ef..6a4a7776 100644 --- a/rmk/src/eeprom/eeconfig.rs +++ b/rmk/src/eeprom/eeconfig.rs @@ -1,7 +1,7 @@ use super::{Eeprom, EepromRecord}; use byteorder::{BigEndian, ByteOrder}; +use defmt::error; use embedded_storage::nor_flash::NorFlash; -use log::error; use packed_struct::prelude::*; /// EEPROM magic value. @@ -107,8 +107,8 @@ impl Eeprom { pub fn set_keymap_config(&mut self, config: EeKeymapConfig) { let mut buf = match config.pack() { Ok(b) => b, - Err(e) => { - error!("Pack keymap config error: {:?}", e); + Err(_) => { + error!("Pack keymap config error"); [0xFF; 2] } }; @@ -121,8 +121,8 @@ impl Eeprom { self.read_byte(KEYMAP_CONFIG_ADDR, KEYMAP_CONFIG_SIZE), ) { Ok(config) => Some(config), - Err(e) => { - error!("Unpack keymap config error: {:?}", e); + Err(_) => { + error!("Unpack keymap config error"); None } } @@ -132,8 +132,8 @@ impl Eeprom { pub fn set_backlight_config(&mut self, config: EeBacklightConfig) { let mut buf = match config.pack() { Ok(b) => b, - Err(e) => { - error!("Pack backlight config error: {:?}", e); + Err(_) => { + error!("Pack backlight config error"); [0xFF; 1] } }; @@ -146,8 +146,8 @@ impl Eeprom { self.read_byte(BACKLIGHT_CONFIG_ADDR, BACKLIGHT_CONFIG_SIZE), ) { Ok(config) => Some(config), - Err(e) => { - error!("Unpack backlight config error: {:?}", e); + Err(_) => { + error!("Unpack backlight config error"); None } } @@ -157,8 +157,8 @@ impl Eeprom { pub fn set_audio_config(&mut self, config: EeAudioConfig) { let mut buf = match config.pack() { Ok(b) => b, - Err(e) => { - error!("Pack audio config error: {:?}", e); + Err(_) => { + error!("Pack audio config error"); [0xFF; 1] } }; @@ -170,8 +170,8 @@ impl Eeprom { match EeAudioConfig::unpack_from_slice(self.read_byte(AUDIO_CONFIG_ADDR, AUDIO_CONFIG_SIZE)) { Ok(config) => Some(config), - Err(e) => { - error!("Unpack audio config error: {:?}", e); + Err(_) => { + error!("Unpack audio config error"); None } } @@ -181,8 +181,8 @@ impl Eeprom { pub fn set_rgb_light_config(&mut self, config: EeRgbLightConfig) { let mut buf = match config.pack() { Ok(b) => b, - Err(e) => { - error!("Pack rgb light config error: {:?}", e); + Err(_) => { + error!("Pack rgb light config error"); [0xFF; 5] } }; @@ -194,8 +194,8 @@ impl Eeprom { match EeRgbLightConfig::unpack_from_slice(self.read_byte(RGB_CONFIG_ADDR, RGB_CONFIG_SIZE)) { Ok(config) => Some(config), - Err(e) => { - error!("Unpack rgb light config error: {:?}", e); + Err(_) => { + error!("Unpack rgb light config error"); None } } diff --git a/rmk/src/keyboard.rs b/rmk/src/keyboard.rs index 5e6cf0f0..326e5e13 100644 --- a/rmk/src/keyboard.rs +++ b/rmk/src/keyboard.rs @@ -6,11 +6,11 @@ use crate::{ usb::descriptor::ViaReport, }; use core::{cell::RefCell, convert::Infallible}; +use defmt::{error, warn}; use embassy_time::Timer; use embassy_usb::{class::hid::HidReaderWriter, driver::Driver}; use embedded_hal::digital::{InputPin, OutputPin}; use embedded_storage::nor_flash::NorFlash; -use log::{debug, error, warn}; use usbd_hid::descriptor::{KeyboardReport, MediaKeyboardReport, SystemControlReport}; pub struct Keyboard< @@ -144,7 +144,7 @@ impl< // usb_device.send_keyboard_report(&self.report).await; match hid_interface.write_serialize(&self.report).await { Ok(()) => {} - Err(e) => error!("Send keyboard report error: {:?}", e), + Err(e) => error!("Send keyboard report error: {}", e), }; // Reset report key states for bit in &mut self.report.keycodes { @@ -159,10 +159,9 @@ impl< hid_interface: &mut HidReaderWriter<'d, D, 1, 8>, ) { if self.need_send_consumer_control_report { - debug!("Sending consumer report: {:?}", self.media_report); match hid_interface.write_serialize(&self.media_report).await { Ok(()) => {} - Err(e) => error!("Send media(consumer control) report error: {:?}", e), + Err(e) => error!("Send media(consumer control) report error: {}", e), }; self.media_report.usage_id = 0; self.need_send_consumer_control_report = false; diff --git a/rmk/src/keycode.rs b/rmk/src/keycode.rs index 0c8faed6..3b7c8c33 100644 --- a/rmk/src/keycode.rs +++ b/rmk/src/keycode.rs @@ -1,3 +1,4 @@ +use defmt::Format; use num_enum::FromPrimitive; use packed_struct::prelude::*; use usbd_hid::descriptor::{MediaKey, SystemControlKey}; @@ -6,7 +7,7 @@ use usbd_hid::descriptor::{MediaKey, SystemControlKey}; /// 1 bit for Left/Right, 4 bits for modifier type. /// | x | x | x | x | x | /// | L/R | GUI | ALT |SHIFT| CTRL| -#[derive(PackedStruct, Clone, Copy, Debug, Default, Eq, PartialEq)] +#[derive(PackedStruct, Clone, Copy, Debug, Format, Default, Eq, PartialEq)] #[packed_struct(bit_numbering = "lsb0", size_bytes = "1")] pub struct ModifierCombination { #[packed_field(bits = "0")] @@ -100,7 +101,7 @@ impl ModifierCombination { /// KeyCode is the internal representation of all keycodes, keyboard operations, etc. /// Use flat representation of keycodes. -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, FromPrimitive)] +#[derive(Debug, Format, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, FromPrimitive)] #[repr(u16)] pub enum KeyCode { /// Reserved, no-key. diff --git a/rmk/src/keymap.rs b/rmk/src/keymap.rs index e6a19692..0f8dd4ff 100644 --- a/rmk/src/keymap.rs +++ b/rmk/src/keymap.rs @@ -5,7 +5,7 @@ use crate::{ }; use embedded_alloc::Heap; use embedded_storage::nor_flash::NorFlash; -use log::warn; +use defmt::warn; #[global_allocator] static HEAP: Heap = Heap::empty(); @@ -170,7 +170,7 @@ impl< /// Activate given layer pub fn activate_layer(&mut self, layer_num: u8) { if layer_num as usize >= NUM_LAYER { - warn!("Not a valid layer {layer_num}, keyboard supports only {NUM_LAYER} layers"); + warn!("Not a valid layer {}, keyboard supports only {} layers", layer_num, NUM_LAYER); return; } self.layer_state[layer_num as usize] = true; @@ -179,7 +179,7 @@ impl< /// Deactivate given layer pub fn deactivate_layer(&mut self, layer_num: u8) { if layer_num as usize >= NUM_LAYER { - warn!("Not a valid layer {layer_num}, keyboard supports only {NUM_LAYER} layers"); + warn!("Not a valid layer {}, keyboard supports only {} layers", layer_num, NUM_LAYER); return; } self.layer_state[layer_num as usize] = false; @@ -188,7 +188,7 @@ impl< /// Toggle given layer pub fn toggle_layer(&mut self, layer_num: u8) { if layer_num as usize >= NUM_LAYER { - warn!("Not a valid layer {layer_num}, keyboard supports only {NUM_LAYER} layers"); + warn!("Not a valid layer {}, keyboard supports only {} layers", layer_num, NUM_LAYER); return; } diff --git a/rmk/src/usb.rs b/rmk/src/usb.rs index ccff0e0c..e27d0649 100644 --- a/rmk/src/usb.rs +++ b/rmk/src/usb.rs @@ -5,7 +5,7 @@ use embassy_usb::{ driver::Driver, Builder, Handler, UsbDevice, }; -use log::info; +use defmt::info; use static_cell::StaticCell; use usbd_hid::descriptor::{KeyboardReport, MediaKeyboardReport, SerializedDescriptor}; @@ -112,21 +112,21 @@ struct MyRequestHandler {} impl RequestHandler for MyRequestHandler { fn get_report(&self, id: ReportId, _buf: &mut [u8]) -> Option { - info!("Get report for {:?}", id); + info!("Get report for {}", id); None } fn set_report(&self, id: ReportId, data: &[u8]) -> OutResponse { - info!("Set report for {:?}: {:?}", id, data); + info!("Set report for {}: {}", id, data); OutResponse::Accepted } fn set_idle_ms(&self, id: Option, dur: u32) { - info!("Set idle rate for {:?} to {:?}", id, dur); + info!("Set idle rate for {} to {}", id, dur); } fn get_idle_ms(&self, id: Option) -> Option { - info!("Get idle rate for {:?}", id); + info!("Get idle rate for {}", id); None } } diff --git a/rmk/src/usb_backup.rs b/rmk/src/usb_backup.rs deleted file mode 100644 index 0df16f58..00000000 --- a/rmk/src/usb_backup.rs +++ /dev/null @@ -1,148 +0,0 @@ -// DEPRECIATED -// use log::error; -// use usb_device::{ -// class_prelude::{UsbBus, UsbBusAllocator}, -// prelude::{UsbDevice, UsbDeviceBuilder, UsbVidPid}, -// UsbError, -// }; -// use usbd_hid::{ -// descriptor::{KeyboardReport, MediaKeyboardReport, SerializedDescriptor, SystemControlReport}, -// hid_class::{ -// HIDClass, HidClassSettings, HidCountryCode, HidProtocol, HidSubClass, ProtocolModeConfig, -// }, -// }; - -// use crate::{config::KeyboardConfig, via::descriptor::ViaReport}; - -// // TODO: Use a composite hid device for Keyboard + Mouse + System control + Consumer control -// // In this case, report id should be used. -// // The keyboard usb device should have 3 hid instances: -// // 1. Boot keyboard: 1 endpoint in -// // 2. Composite keyboard: Keyboard + Mouse + System control + Consumer control: 1 endpoint in -// // 3. Raw hid communication: used to communicate with via: 2 endpoints(in/out) -// pub struct KeyboardUsbDevice<'a, B: UsbBus> { -// /// Usb hid instance -// hid: HIDClass<'a, B>, -// /// Consumer control hid instance -// consumer_control_hid: HIDClass<'a, B>, -// /// System control hid instance -// system_control_hid: HIDClass<'a, B>, -// /// Via communication instance -// via_hid: HIDClass<'a, B>, -// /// Usb device instance -// usb_device: UsbDevice<'a, B>, -// } - -// impl<'a, B: UsbBus> KeyboardUsbDevice<'a, B> { -// pub fn new(usb_allocator: &'a UsbBusAllocator, config: &KeyboardConfig<'a>) -> Self { -// KeyboardUsbDevice { -// hid: HIDClass::new_ep_in_with_settings( -// usb_allocator, -// KeyboardReport::desc(), -// 10, -// HidClassSettings { -// subclass: HidSubClass::Boot, -// protocol: HidProtocol::Keyboard, -// config: ProtocolModeConfig::ForceBoot, -// locale: HidCountryCode::NotSupported, -// }, -// ), -// consumer_control_hid: HIDClass::new_ep_in_with_settings( -// usb_allocator, -// MediaKeyboardReport::desc(), -// 10, -// HidClassSettings { -// subclass: HidSubClass::NoSubClass, -// protocol: HidProtocol::Keyboard, -// config: ProtocolModeConfig::DefaultBehavior, -// locale: HidCountryCode::NotSupported, -// }, -// ), -// system_control_hid: HIDClass::new_ep_in_with_settings( -// usb_allocator, -// SystemControlReport::desc(), -// 10, -// HidClassSettings { -// subclass: HidSubClass::NoSubClass, -// protocol: HidProtocol::Keyboard, -// config: ProtocolModeConfig::DefaultBehavior, -// locale: HidCountryCode::NotSupported, -// }, -// ), -// via_hid: HIDClass::new(usb_allocator, ViaReport::desc(), 10), -// usb_device: UsbDeviceBuilder::new( -// usb_allocator, -// UsbVidPid(config.usb_config.vid, config.usb_config.pid), -// ) -// .manufacturer(config.usb_config.manufacturer) -// .product(config.usb_config.product) -// .serial_number(config.usb_config.serial_number) -// .max_power(500) -// // .composite_with_iads() // Only used when the usb device is a composite device, like HID + MSC -// .supports_remote_wakeup(true) -// .build(), -// } -// } - -// /// Usb polling -// pub fn usb_poll(&mut self) { -// self.usb_device.poll(&mut [ -// &mut self.hid, -// &mut self.consumer_control_hid, -// &mut self.system_control_hid, -// &mut self.via_hid, -// ]); -// } - -// /// Read via report, returns the length of the report, 0 if no report is available. -// pub fn read_via_report(&mut self, report: &mut ViaReport) -> usize { -// // Use output_data: host to device data -// match self.via_hid.pull_raw_output(&mut report.output_data) { -// Ok(l) => l, -// Err(UsbError::WouldBlock) => 0, -// Err(e) => { -// error!("Read via report error: {:?}", e); -// 0 -// } -// } -// } - -// pub fn send_via_report(&self, report: &ViaReport) -> usize { -// // Use output_data: host to device data -// match self.via_hid.push_input(report) { -// Ok(l) => l, -// Err(UsbError::WouldBlock) => 0, -// Err(e) => { -// error!("Send via report error: {:?}", e); -// 0 -// } -// } -// } - -// /// Send keyboard hid report -// pub fn send_keyboard_report(&self, report: &KeyboardReport) { -// match self.hid.push_input(report) { -// Ok(_) => (), -// Err(UsbError::WouldBlock) => (), -// Err(e) => error!("Send keyboard report error: {:?}", e), -// } -// } - -// /// Send consumer control report, commonly used in keyboard media control -// pub fn send_consumer_control_report(&self, report: &MediaKeyboardReport) { -// match self.consumer_control_hid.push_input(report) { -// Ok(_) => (), -// Err(UsbError::WouldBlock) => (), -// Err(e) => error!("Send consumer control report error: {:?}", e), -// } -// } - -// /// Send system control report -// pub fn send_system_control_report(&self, report: &SystemControlReport) { -// match self.system_control_hid.push_input(report) { -// Ok(_) => (), -// Err(UsbError::WouldBlock) => (), -// Err(e) => error!("Send system control report error: {:?}", e), -// } -// } -// } diff --git a/rmk/src/via/keycode_convert.rs b/rmk/src/via/keycode_convert.rs index bd2eb50b..c4b89bb8 100644 --- a/rmk/src/via/keycode_convert.rs +++ b/rmk/src/via/keycode_convert.rs @@ -1,4 +1,4 @@ -use log::warn; +use defmt::warn; use num_enum::FromPrimitive; use crate::{ @@ -92,27 +92,27 @@ pub fn from_via_keycode(via_keycode: u16) -> KeyAction { } 0x5700..=0x57FF => { // TODO: Tap Dance - warn!("Tap dance 0x{:X} not supported", via_keycode); + warn!("Tap dance {:#X} not supported", via_keycode); KeyAction::No } 0x5C00..=0x5CFF => { // TODO: QMK functions, such as reset, swap ctrl/caps, gui on, haptic, music, clicky, combo, RGB, etc - warn!("QMK functions 0x{:X} not supported", via_keycode); + warn!("QMK functions {:#X} not supported", via_keycode); KeyAction::No } 0x5D00..=0x5D0F => { // TODO: DM Rec/Stop/Play - warn!("DM Rec/Stop/Play 0x{:X} not supported", via_keycode); + warn!("DM Rec/Stop/Play {:#X} not supported", via_keycode); KeyAction::No } 0x5F12..=0x5F21 => { // TODO: Macro 1-16 - warn!("Macro 0x{:X} not supported", via_keycode); + warn!("Macro {:#X} not supported", via_keycode); KeyAction::No } 0x5F80..=0x5F8F => { // TODO: User 1-16 - warn!("User 0x{:X} not supported", via_keycode); + warn!("User {:#X} not supported", via_keycode); KeyAction::No } 0x6000..=0x7FFF => { @@ -131,7 +131,7 @@ pub fn from_via_keycode(via_keycode: u16) -> KeyAction { } _ => { - warn!("Via keycode 0x{:X} is not processed", via_keycode); + warn!("Via keycode {:#X} is not processed", via_keycode); KeyAction::No } } diff --git a/rmk/src/via/process.rs b/rmk/src/via/process.rs index 3b2d277d..a8957a00 100644 --- a/rmk/src/via/process.rs +++ b/rmk/src/via/process.rs @@ -7,13 +7,13 @@ use crate::{ via::keycode_convert::{from_via_keycode, to_via_keycode}, }; use byteorder::{BigEndian, ByteOrder, LittleEndian}; +use defmt::{debug, error, info, warn}; use embassy_time::Instant; use embassy_usb::{ class::hid::{HidReaderWriter, ReadError}, driver::Driver, }; use embedded_storage::nor_flash::NorFlash; -use log::{debug, error, info, warn}; use num_enum::{FromPrimitive, TryFromPrimitive}; pub struct VialService< @@ -72,13 +72,13 @@ impl< match hid_interface.write_serialize(&mut via_report).await { Ok(_) => {} Err(e) => { - error!("Send via report error: {:?}", e); + error!("Send via report error: {}", e); } } } Err(e) => { if e != ReadError::Disabled { - error!("Read via report error: {:?}", e); + error!("Read via report error: {}", e); } } } @@ -94,7 +94,7 @@ impl< // `report.input_data` is initialized using `report.output_data` report.input_data = report.output_data; let via_command = ViaCommand::from_primitive(command_id); - // debug!("Received via command: {:?}, report: {:02X?}", via_command, report.output_data); + // debug!("Received via command: {}, report: {:02X?}", via_command, report.output_data); match via_command { ViaCommand::GetProtocolVersion => { BigEndian::write_u16(&mut report.input_data[1..3], VIA_PROTOCOL_VERSION); @@ -152,7 +152,7 @@ impl< let action = keymap.get_action_at(row, col, layer); let keycode = to_via_keycode(action); info!( - "Getting keycode: {:02X?} at ({},{}), layer {}", + "Getting keycode: {:02X} at ({},{}), layer {}", keycode, row, col, layer ); BigEndian::write_u16(&mut report.input_data[4..6], keycode); @@ -164,7 +164,7 @@ impl< let keycode = BigEndian::read_u16(&report.output_data[4..6]); let action = from_via_keycode(keycode); info!( - "Setting keycode: 0x{:02X?} at ({},{}), layer {} as {:?}", + "Setting keycode: 0x{:02X} at ({},{}), layer {} as {}", keycode, row, col, layer, action ); keymap.set_action_at(row, col, layer, action.clone()); @@ -208,7 +208,7 @@ impl< let _offset = BigEndian::read_u16(&report.output_data[1..3]); let size = report.output_data[3]; if size <= 28 { - debug!("Current returned data: {:02X?}", report.input_data); + debug!("Current returned data: {:02X}", report.input_data); } else { report.input_data[0] = 0xFF; } diff --git a/rmk/src/via/vial.rs b/rmk/src/via/vial.rs index 30149a08..738b83f3 100644 --- a/rmk/src/via/vial.rs +++ b/rmk/src/via/vial.rs @@ -1,5 +1,5 @@ use byteorder::{ByteOrder, LittleEndian}; -use log::debug; +use defmt::debug; use num_enum::FromPrimitive; use crate::usb::descriptor::ViaReport; @@ -25,7 +25,7 @@ pub enum VialCommand { Unhandled = 0xFF, } -const VIAL_PROTOCOL_VERSION: u32 = 3; +const VIAL_PROTOCOL_VERSION: u32 = 6; const VIAL_EP_SIZE: usize = 32; /// /// Note: vial uses litte endian, while via uses big endian