Skip to content

Commit bb08ff2

Browse files
committed
Merge branch 'release/v0.5.2'
2 parents 281a1a0 + b020f25 commit bb08ff2

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
* None
66

7+
## v0.5.2
8+
9+
* Handle 'Alt' reads and writes.
10+
711
## v0.5.1
812

913
* Adds a PC speaker driver using TIM14

neotron-bmc-commands/README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,20 @@ TODO
211211

212212
### Address 0x70 - Speaker Tone Duration
213213

214-
TODO
214+
Sets the duration of the tone to be played, and starts the tone playing. You
215+
should set the other three registers (if required) before setting this register.
216+
217+
There is no way to know when the tone is ended; the host should keep track of
218+
the duration it set and wait the appropriate period of time.
215219

216220
### Address 0x71 - Speaker Tone Period (High)
217221

218-
TODO
222+
Sets the upper 8 bits of the tone period. This is the inverse of frequency, in 48 kHz units.
219223

220224
### Address 0x72 - Speaker Tone Period (Low)
221225

222-
TODO
226+
Sets the lower 8 bits of the tone period. See *Speaker Tone Period (High)* for details.
223227

224228
### Address 0x73 - Speaker Tone Duty Cycle
225229

226-
TODO
230+
Sets the duty-cycle of the speaker tone. A value of 127 is 50:50 (a square wave).

neotron-bmc-pico/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
authors = ["Jonathan 'theJPster' Pallant <[email protected]>"]
33
name = "neotron-bmc-pico"
44
edition = "2018"
5-
version = "0.5.1"
5+
version = "0.5.2"
66

77
[dependencies]
88
cortex-m = { version = "0.7.5", features = ["inline-asm", "critical-section-single-core"] }

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)