Skip to content

Commit 3996665

Browse files
authored
Merge pull request #64 from Neotron-Compute/fix-speaker-logic
Fix commands for speaker period-high and period-low
2 parents 8e75d18 + 83de427 commit 3996665

File tree

10 files changed

+104
-26
lines changed

10 files changed

+104
-26
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
*/target
22
target/
33
/Cargo.lock
4+
/neotron-bmc-protocol/Cargo.lock
5+
/neotron-bmc-command/Cargo.lock

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ line and a dedicated IRQ line. It provides to the system:
2222
* two analog inputs for monitoring for the 3.3V and 5.0V rails,
2323
* two GPIO inputs for a power button and a reset button, and
2424
* three GPIO outputs - nominally used for
25-
* the main DC/DC enable signal, and
26-
* the power LED
25+
* the main DC/DC enable signal, and
26+
* the power LED
2727

2828
## Hardware Interface
2929

@@ -57,7 +57,7 @@ Build requirements are available for
5757

5858
## Licence
5959

60-
This code is licenced under the GNU Public Licence version 3. See:
60+
This repository as a whole is licenced under the GNU Public Licence version 3. See:
6161

6262
* [The LICENSE file](./LICENSE)
6363
* [The GPL Website](http://www.gnu.org/licenses/gpl-3.0.html)
@@ -86,4 +86,7 @@ firmware (or products that contain it):
8686
Note that this firmware image incorporates a number of third-party modules. You
8787
should review the output of `cargo tree` and ensure that any licence terms for
8888
those modules are upheld. You should also be aware that this application was
89-
based on the Knurling Template at https://github.com/knurling-rs/app-template.
89+
based on the Knurling Template at <https://github.com/knurling-rs/app-template>.
90+
91+
Note also that some crates within this tree are made available individually
92+
under different licences. See each individual crate for details.

neotron-bmc-commands/Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
[package]
2+
description = "Commands that are supported by the Neotron BMC"
3+
edition = "2021"
4+
license = "BlueOak-1.0.0"
25
name = "neotron-bmc-commands"
6+
repository = "https://github.com/neotron-compute/neotron-bmc"
37
version = "0.1.0"
4-
edition = "2021"
8+
homepage = "https://github.com/neotron-compute"
9+
readme = "README.md"
510

611
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7-
812
[dependencies]
9-
num_enum = { version = "0.5", default-features=false }
13+
num_enum = { version = "0.5", default-features = false }

neotron-bmc-commands/README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,27 @@ should set the other three registers (if required) before setting this register.
217217
There is no way to know when the tone is ended; the host should keep track of
218218
the duration it set and wait the appropriate period of time.
219219

220-
### Address 0x71 - Speaker Tone Period (High)
220+
### Address 0x71 - Speaker Tone Period (Low)
221221

222-
Sets the upper 8 bits of the tone period. This is the inverse of frequency, in 48 kHz units.
222+
Sets the lower 8 bits of the tone period. See *Speaker Tone Period (High)* for details.
223223

224-
### Address 0x72 - Speaker Tone Period (Low)
224+
### Address 0x72 - Speaker Tone Period (High)
225225

226-
Sets the lower 8 bits of the tone period. See *Speaker Tone Period (High)* for details.
226+
Sets the upper 8 bits of the tone period. This is the inverse of frequency, in
227+
48 kHz units. A value of `48000 / 440 = 109 = 0x006D` will give you a
228+
Concert-pitch A (440 Hz). Write that value as `0x00` in the high register and
229+
`0x6D` in the low register.
227230

228231
### Address 0x73 - Speaker Tone Duty Cycle
229232

230233
Sets the duty-cycle of the speaker tone. A value of 127 is 50:50 (a square wave).
234+
235+
## Licence
236+
237+
This code is licenced under the Blue Oak Model License 1.0.0. See:
238+
239+
* [The LICENSE file](./LICENSE)
240+
* [The Blue Oak Licence Website](https://blueoakcouncil.org/license/1.0.0)
241+
242+
Our intent behind picking this licence is to allow this code to be freely
243+
reused, both in open-source and commercially licensed products.

neotron-bmc-commands/src/lib.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
//! # Neotron BMC Commands
2-
//!
3-
//! Definitions of all the commands supported by the BMC.
1+
#![doc = include_str!("../README.md")]
42

53
#![no_std]
64

@@ -142,16 +140,16 @@ pub enum Command {
142140
/// * Length: 1
143141
/// * Mode: R/W
144142
SpeakerDuration = 0x70,
145-
/// # Speaker Period (High byte)
146-
/// High byte of period (in 48kHz ticks)
143+
/// # Speaker Period (Low byte)
144+
/// Low byte of 16-bit period (in 48kHz ticks)
147145
/// * Length: 1
148146
/// * Mode: R/W
149-
SpeakerPeriodHigh = 0x71,
147+
SpeakerPeriodLow = 0x71,
150148
/// # Speaker Period (High byte)
151-
/// High byte of period (in 48kHz ticks)
149+
/// High byte of 16-bit period (in 48kHz ticks)
152150
/// * Length: 1
153151
/// * Mode: R/W
154-
SpeakerPeriodLow = 0x72,
152+
SpeakerPeriodHigh = 0x72,
155153
/// # Speaker Duty Cycle
156154
/// Speaker Duty cycle, in 1/255
157155
/// * Length: 1

neotron-bmc-pico/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ where
892892
}
893893
(proto::RequestType::ShortWrite, Ok(Command::SpeakerPeriodHigh)) => {
894894
defmt::debug!("Writing speaker period (high = {})", req.length_or_data);
895-
register_state.speaker.set_period_low(req.length_or_data);
895+
register_state.speaker.set_period_high(req.length_or_data);
896896
proto::Response::new_without_data(proto::ResponseResult::Ok)
897897
}
898898
(proto::RequestType::Read, Ok(Command::SpeakerPeriodLow)) => {
@@ -902,7 +902,7 @@ where
902902
}
903903
(proto::RequestType::ShortWrite, Ok(Command::SpeakerPeriodLow)) => {
904904
defmt::debug!("Writing speaker period (low = {})", req.length_or_data);
905-
register_state.speaker.set_period_high(req.length_or_data);
905+
register_state.speaker.set_period_low(req.length_or_data);
906906
proto::Response::new_without_data(proto::ResponseResult::Ok)
907907
}
908908
(proto::RequestType::Read, Ok(Command::SpeakerDutyCycle)) => {

neotron-bmc-protocol/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
[package]
2-
name = "neotron-bmc-protocol"
3-
version = "0.1.0"
2+
description = "The SPI protocol supported by the Neotron BMC"
43
edition = "2021"
54
license = "BlueOak-1.0.0"
5+
name = "neotron-bmc-protocol"
66
repository = "https://github.com/neotron-compute/neotron-bmc"
7+
version = "0.1.0"
8+
homepage = "https://github.com/neotron-compute"
79
readme = "README.md"
810

911
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

neotron-bmc-protocol/LICENSE

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Blue Oak Model License
2+
3+
Version 1.0.0
4+
5+
## Purpose
6+
7+
This license gives everyone as much permission to work with
8+
this software as possible, while protecting contributors
9+
from liability.
10+
11+
## Acceptance
12+
13+
In order to receive this license, you must agree to its
14+
rules. The rules of this license are both obligations
15+
under that agreement and conditions to your license.
16+
You must not do anything with this software that triggers
17+
a rule that you cannot or will not follow.
18+
19+
## Copyright
20+
21+
Each contributor licenses you to do everything with this
22+
software that would otherwise infringe that contributor's
23+
copyright in it.
24+
25+
## Notices
26+
27+
You must ensure that everyone who gets a copy of
28+
any part of this software from you, with or without
29+
changes, also gets the text of this license or a link to
30+
<https://blueoakcouncil.org/license/1.0.0>.
31+
32+
## Excuse
33+
34+
If anyone notifies you in writing that you have not
35+
complied with [Notices](#notices), you can keep your
36+
license by taking all practical steps to comply within 30
37+
days after the notice. If you do not do so, your license
38+
ends immediately.
39+
40+
## Patent
41+
42+
Each contributor licenses you to do everything with this
43+
software that would otherwise infringe any patent claims
44+
they can license or become able to license.
45+
46+
## Reliability
47+
48+
No contributor can revoke this license.
49+
50+
## No Liability
51+
52+
***As far as the law allows, this software comes as is,
53+
without any warranty or condition, and no contributor
54+
will be liable to anyone for any damages related to this
55+
software or this license, under any kind of legal claim.***

neotron-bmc-protocol/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Neotron-BMC-Protocol
22

3-
Protocol code for communication with the Neotron Board Management Controller (NBMC).
3+
The SPI protocol for communication with the Neotron Board Management Controller
4+
(NBMC).
45

56
## Introduction
67

@@ -13,7 +14,7 @@ soft power button, and it also ensures that all power rails come up before the
1314
system is taken out of reset.
1415

1516
The NBMC sits on the SPI bus, receives *Requests* and sends *Responses* in
16-
reply. It can also raise an IRQ line.
17+
reply. It can also activate an IRQ line.
1718

1819
This crate describes the protocol run over the SPI bus and provides some basic
1920
helper code for implementing the protocol in Rust.
@@ -66,7 +67,7 @@ the `nCS` signal in-between.
6667

6768
* `0xC0`: Read
6869
* `0xC1`: Read (alternate)
69-
* `0xC2`: Short Write
70+
* `0xC2`: Short Write
7071
* `0xC3`: Long Write
7172

7273
### Response Results

0 commit comments

Comments
 (0)