Embedded HAL Driver for PCB Artists I2C SPL Module
A Rust no_std
embedded-hal driver for the
PCB Artists I2C Sound Level module.
Features
- Read current SPL value averaged over a time window (TAVG register) with a range of 35 dB to 120 dB (+/-2 dB) from 30 Hz to 8 kHz.
- Adjustable time window (TAVG register) for averaging of SPL value from 10 ms to 10,000 ms.
- Read min/max SPL value sensed between power cycle or reset.
Usage
This example uses the SPL module with a STM32F3 Discovery development board and a USB-TTL converter.
See the example project for the complete example.
[]
= "example-read-decibel-value"
= "Example of reading SPL with the pa-spl driver, PCB Artists SPL module, and STM32F3 Discovery"
= ["Jason Scott <>"]
= "2021"
= false
= "README.md"
= "0.1.0"
[]
= "0.7.7"
= "0.7.3"
= "0.5.0"
= "0.2.0"
= { = "0.10.0", = ["ld", "rt", "stm32f303xc"] }
= "0.1.0"
[[]]
= "example-read-decibel-value"
= false
= false
[]
= 1
= true
= true
// Reads the latest decibel value and prints it to UART4.
use asm;
use entry;
// Use halt as the panicking behavior.
//
// A breakpoint can be set on `rust_begin_unwind` to catch panics.
//
use PaSpl;
use panic_halt as _;
use ;
use Write;
// Provide an implementation of a buffer writer in order to use the write!
// macro.
//
// Provide implementation of write_str in order to use the buffer writer with
// the write! formatting macro.
//
!
Tests
Two test suites are included - an off-target unit test suite included in the source of the driver that uses embedded-hal-mock and a hardware-in-the-loop (HIL) test suite that is included as a nested cargo project following the pattern described by Ferrous Systems for testing a driver crate.
To run the off-target tests:
cargo test
The
HIL testing project
is in the target-tests
directory and is configured to use
probe-rs to automatically build the tests, flash the
target, run the tests, and report results.
To run the HIL tests, connect the hardware according to the STM32F3 Discovery example provided in the repo (minus the TTL-USB converter) with a spectrum analysis version of the PCB Artists sensor, firmware version 0x32 or 0x33 (the number read from the VERSION register), then:
cd target-tests
cargo test
The CI configuration runs the tests for every commit and PR against Rust 1.65, stable, beta, and nightly. The HIL tests are run privately due to the security issues with attaching a local GitHub Actions runner to a public respository but anyone is welcome to run them locally on their own hardware.
Minimum Supported Rust Version (MSRV)
This crate is guaranteed to compile on stable Rust 1.65 and up. It might compile with older versions but that may change in any new patch release.
See here for details on how the MSRV may be upgraded.
Minimum Supported Embedded HAL Version
TL;DR: This initial release only supports embedded-hal 0.2 and support for the 1.0 version will be added in a subsequent release.
This crate depends on the embedded-hal crate as it is a driver for use with embedded-hal. Embedded versioning typically moves significantly slower than mainstream, so numerous crates in the repository still depend on the 0.2 version of embedded-hal rather than the recent 1.0 release. Due to this, the minimum supported embedded-hal version of this crate is 0.2 and the 1.0 version is not yet supported in this initial release. Support for the 1.0 version of embedded-hal will be added in a subsequent release.
Glossary
- API: Application Programming Interface.
- HAL: Hardware Abstraction Layer.
- PCB: Printed Circuit Board.
- I2C: Inter-Intergrated Circuit protocol.
- SPL: Sound Pressure Level.