From 06c7051c3c574e0b74242c2a0a9587be929d96b4 Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Sun, 22 Jan 2023 16:36:23 +0000 Subject: [PATCH 1/3] Update speaker API docs. --- neotron-bmc-commands/README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/neotron-bmc-commands/README.md b/neotron-bmc-commands/README.md index f4e1971..7d25d64 100644 --- a/neotron-bmc-commands/README.md +++ b/neotron-bmc-commands/README.md @@ -211,16 +211,20 @@ TODO ### Address 0x70 - Speaker Tone Duration -TODO +Sets the duration of the tone to be played, and starts the tone playing. You +should set the other three registers (if required) before setting this register. + +There is no way to know when the tone is ended; the host should keep track of +the duration it set and wait the appropriate period of time. ### Address 0x71 - Speaker Tone Period (High) -TODO +Sets the upper 8 bits of the tone period. This is the inverse of frequency, in 48 kHz units. ### Address 0x72 - Speaker Tone Period (Low) -TODO +Sets the lower 8 bits of the tone period. See *Speaker Tone Period (High)* for details. ### Address 0x73 - Speaker Tone Duty Cycle -TODO +Sets the duty-cycle of the speaker tone. A value of 127 is 50:50 (a square wave). From f6f664a62ea76c94e4be802e0115b3e24437c07b Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Sun, 22 Jan 2023 16:39:22 +0000 Subject: [PATCH 2/3] Fix handling of alt commands. A Read and a ReadAlt should be treated the same, and now are. The alt only exists so you don't think a repeated read is a duplicate read. But after duplicates have been checked, we don't care. --- CHANGELOG.md | 2 +- neotron-bmc-pico/src/main.rs | 17 ++++++++++------- neotron-bmc-protocol/src/lib.rs | 13 +++++++++++++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ffb54c..29f6175 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased Changes -* None +* Handle 'Alt' reads and writes. ## v0.5.1 diff --git a/neotron-bmc-pico/src/main.rs b/neotron-bmc-pico/src/main.rs index c3683d6..25389cd 100644 --- a/neotron-bmc-pico/src/main.rs +++ b/neotron-bmc-pico/src/main.rs @@ -825,9 +825,8 @@ where let mut data = [0u8; 1]; // What do they want? - let rsp = match (req.request_type, Command::try_from(req.register)) { - (proto::RequestType::Read, Ok(Command::ProtocolVersion)) - | (proto::RequestType::ReadAlt, Ok(Command::ProtocolVersion)) => { + let rsp = match (req.request_type.flatten(), Command::try_from(req.register)) { + (proto::RequestType::Read, Ok(Command::ProtocolVersion)) => { defmt::trace!("Reading ProtocolVersion"); // They want the Protocol Version we support. Give them v0.1.1. let length = req.length_or_data as usize; @@ -838,8 +837,7 @@ where proto::Response::new_without_data(proto::ResponseResult::BadLength) } } - (proto::RequestType::Read, Ok(Command::FirmwareVersion)) - | (proto::RequestType::ReadAlt, Ok(Command::FirmwareVersion)) => { + (proto::RequestType::Read, Ok(Command::FirmwareVersion)) => { defmt::trace!("Reading FirmwareVersion"); // They want the Firmware Version string. let length = req.length_or_data as usize; @@ -851,8 +849,7 @@ where proto::Response::new_without_data(proto::ResponseResult::BadLength) } } - (proto::RequestType::Read, Ok(Command::Ps2KbBuffer)) - | (proto::RequestType::ReadAlt, Ok(Command::Ps2KbBuffer)) => { + (proto::RequestType::Read, Ok(Command::Ps2KbBuffer)) => { defmt::trace!("Reading Ps2KbBuffer"); let length = req.length_or_data as usize; if length > 0 && length <= register_state.scratch.len() { @@ -882,6 +879,7 @@ where } (proto::RequestType::ShortWrite, Ok(Command::SpeakerDuration)) => { defmt::debug!("Writing speaker duration ({})", req.length_or_data); + // This update actually causes the speaker to beep register_state .speaker .set_duration(req.length_or_data as u16 * 10); @@ -919,6 +917,11 @@ where } _ => { // Sorry, that register / request type is not supported + defmt::warn!( + "Unknown register operation {:?} on 0x{:02x}", + req.request_type, + req.register + ); proto::Response::new_without_data(proto::ResponseResult::BadRegister) } }; diff --git a/neotron-bmc-protocol/src/lib.rs b/neotron-bmc-protocol/src/lib.rs index 124300c..a555005 100644 --- a/neotron-bmc-protocol/src/lib.rs +++ b/neotron-bmc-protocol/src/lib.rs @@ -134,6 +134,19 @@ pub struct ProtocolVersion { // Impls // ============================================================================ +impl RequestType { + /// Converts an 'alt' command into a regular command. + /// + /// Once you've checked for duplicates, you don't care which you've got. + pub fn flatten(self) -> Self { + match self { + RequestType::LongWrite | RequestType::LongWriteAlt => RequestType::LongWrite, + RequestType::ShortWrite | RequestType::ShortWriteAlt => RequestType::ShortWrite, + RequestType::Read | RequestType::ReadAlt => RequestType::Read, + } + } +} + impl Request { /// Make a new Read Request, requesting the given register and number of /// bytes. From b020f2566545f97303f18e6a51c19752cd807669 Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Sun, 22 Jan 2023 16:46:41 +0000 Subject: [PATCH 3/3] Update version to 0.5.2 --- CHANGELOG.md | 4 ++++ neotron-bmc-pico/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29f6175..c2f55d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased Changes +* None + +## v0.5.2 + * Handle 'Alt' reads and writes. ## v0.5.1 diff --git a/neotron-bmc-pico/Cargo.toml b/neotron-bmc-pico/Cargo.toml index 0e52dc4..89cdc79 100644 --- a/neotron-bmc-pico/Cargo.toml +++ b/neotron-bmc-pico/Cargo.toml @@ -2,7 +2,7 @@ authors = ["Jonathan 'theJPster' Pallant "] name = "neotron-bmc-pico" edition = "2018" -version = "0.5.1" +version = "0.5.2" [dependencies] cortex-m = { version = "0.7.5", features = ["inline-asm", "critical-section-single-core"] }