Skip to content

Commit

Permalink
Fixed speaker register bug.
Browse files Browse the repository at this point in the history
Also puts the protocol back as it was, and bumps the version to 0.2.0
  • Loading branch information
thejpster committed Jul 15, 2023
1 parent 2dd6959 commit 68dfe41
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion neotron-bmc-commands/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ edition = "2021"
license = "BlueOak-1.0.0"
name = "neotron-bmc-commands"
repository = "https://github.com/neotron-compute/neotron-bmc"
version = "0.1.0"
version = "0.2.0"
homepage = "https://github.com/neotron-compute"
readme = "README.md"

Expand Down
10 changes: 5 additions & 5 deletions neotron-bmc-commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,17 @@ 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 (Low)

Sets the lower 8 bits of the tone period. See *Speaker Tone Period (High)* for details.

### Address 0x72 - Speaker Tone Period (High)
### Address 0x71 - Speaker Tone Period (High)

Sets the upper 8 bits of the tone period. This is the inverse of frequency, in
48 kHz units. A value of `48000 / 440 = 109 = 0x006D` will give you a
Concert-pitch A (440 Hz). Write that value as `0x00` in the high register and
`0x6D` in the low register.

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

Sets the lower 8 bits of the tone period. See *Speaker Tone Period (High)* for details.

### Address 0x73 - Speaker Tone Duty Cycle

Sets the duty-cycle of the speaker tone. A value of 127 is 50:50 (a square wave).
Expand Down
12 changes: 6 additions & 6 deletions neotron-bmc-commands/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,16 @@ pub enum Command {
/// * Length: 1
/// * Mode: R/W
SpeakerDuration = 0x70,
/// # Speaker Period (Low byte)
/// Low byte of 16-bit period (in 48kHz ticks)
/// # Speaker Tone Period (High byte)
/// High byte of 16-bit period (in 48kHz ticks)
/// * Length: 1
/// * Mode: R/W
SpeakerPeriodLow = 0x71,
/// # Speaker Period (High byte)
/// High byte of 16-bit period (in 48kHz ticks)
SpeakerPeriodHigh = 0x71,
/// # Speaker Tone Period (Low byte)
/// Low byte of 16-bit period (in 48kHz ticks)
/// * Length: 1
/// * Mode: R/W
SpeakerPeriodHigh = 0x72,
SpeakerPeriodLow = 0x72,
/// # Speaker Duty Cycle
/// Speaker Duty cycle, in 1/255
/// * Length: 1
Expand Down
2 changes: 1 addition & 1 deletion neotron-bmc-pico/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ heapless= "0.7"
panic-probe = { version = "0.3", features = ["print-defmt"] }
stm32f0xx-hal = { version = "0.18", features = ["stm32f030x6", "rt"] }
neotron-bmc-protocol = { version = "0.1", path = "../neotron-bmc-protocol", features = ["defmt"] }
neotron-bmc-commands = { version = "0.1", path = "../neotron-bmc-commands" }
neotron-bmc-commands = { version = "0.2", path = "../neotron-bmc-commands" }
systick-monotonic = "1.0"
embedded-hal = "*"

Expand Down
4 changes: 2 additions & 2 deletions neotron-bmc-pico/src/speaker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ impl RegisterState {
}

pub fn set_period_high(&mut self, period_high: u8) {
self.period = (self.period & 0xff00) | period_high as u16;
self.period = (self.period & 0x00ff) | ((period_high as u16) << 8);
}

pub fn period_low(&self) -> u8 {
(self.period & 0xff) as u8
}

pub fn set_period_low(&mut self, period_low: u8) {
self.period = (self.period() & 0xff) | ((period_low as u16) << 8);
self.period = (self.period & 0xff00) | period_low as u16;
}

pub fn duration(&self) -> u16 {
Expand Down

0 comments on commit 68dfe41

Please sign in to comment.