Skip to content

Commit f6f664a

Browse files
committed
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.
1 parent 06c7051 commit f6f664a

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Unreleased Changes
44

5-
* None
5+
* Handle 'Alt' reads and writes.
66

77
## v0.5.1
88

neotron-bmc-pico/src/main.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,8 @@ where
825825
let mut data = [0u8; 1];
826826

827827
// What do they want?
828-
let rsp = match (req.request_type, Command::try_from(req.register)) {
829-
(proto::RequestType::Read, Ok(Command::ProtocolVersion))
830-
| (proto::RequestType::ReadAlt, Ok(Command::ProtocolVersion)) => {
828+
let rsp = match (req.request_type.flatten(), Command::try_from(req.register)) {
829+
(proto::RequestType::Read, Ok(Command::ProtocolVersion)) => {
831830
defmt::trace!("Reading ProtocolVersion");
832831
// They want the Protocol Version we support. Give them v0.1.1.
833832
let length = req.length_or_data as usize;
@@ -838,8 +837,7 @@ where
838837
proto::Response::new_without_data(proto::ResponseResult::BadLength)
839838
}
840839
}
841-
(proto::RequestType::Read, Ok(Command::FirmwareVersion))
842-
| (proto::RequestType::ReadAlt, Ok(Command::FirmwareVersion)) => {
840+
(proto::RequestType::Read, Ok(Command::FirmwareVersion)) => {
843841
defmt::trace!("Reading FirmwareVersion");
844842
// They want the Firmware Version string.
845843
let length = req.length_or_data as usize;
@@ -851,8 +849,7 @@ where
851849
proto::Response::new_without_data(proto::ResponseResult::BadLength)
852850
}
853851
}
854-
(proto::RequestType::Read, Ok(Command::Ps2KbBuffer))
855-
| (proto::RequestType::ReadAlt, Ok(Command::Ps2KbBuffer)) => {
852+
(proto::RequestType::Read, Ok(Command::Ps2KbBuffer)) => {
856853
defmt::trace!("Reading Ps2KbBuffer");
857854
let length = req.length_or_data as usize;
858855
if length > 0 && length <= register_state.scratch.len() {
@@ -882,6 +879,7 @@ where
882879
}
883880
(proto::RequestType::ShortWrite, Ok(Command::SpeakerDuration)) => {
884881
defmt::debug!("Writing speaker duration ({})", req.length_or_data);
882+
// This update actually causes the speaker to beep
885883
register_state
886884
.speaker
887885
.set_duration(req.length_or_data as u16 * 10);
@@ -919,6 +917,11 @@ where
919917
}
920918
_ => {
921919
// Sorry, that register / request type is not supported
920+
defmt::warn!(
921+
"Unknown register operation {:?} on 0x{:02x}",
922+
req.request_type,
923+
req.register
924+
);
922925
proto::Response::new_without_data(proto::ResponseResult::BadRegister)
923926
}
924927
};

neotron-bmc-protocol/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,19 @@ pub struct ProtocolVersion {
134134
// Impls
135135
// ============================================================================
136136

137+
impl RequestType {
138+
/// Converts an 'alt' command into a regular command.
139+
///
140+
/// Once you've checked for duplicates, you don't care which you've got.
141+
pub fn flatten(self) -> Self {
142+
match self {
143+
RequestType::LongWrite | RequestType::LongWriteAlt => RequestType::LongWrite,
144+
RequestType::ShortWrite | RequestType::ShortWriteAlt => RequestType::ShortWrite,
145+
RequestType::Read | RequestType::ReadAlt => RequestType::Read,
146+
}
147+
}
148+
}
149+
137150
impl Request {
138151
/// Make a new Read Request, requesting the given register and number of
139152
/// bytes.

0 commit comments

Comments
 (0)