Crates.io | dfr0299 |
lib.rs | dfr0299 |
version | 0.1.1 |
source | src |
created_at | 2022-07-17 12:21:40.028186 |
updated_at | 2022-07-17 12:23:25.402653 |
description | Rust implementation of the serial protocol for the DFR0299 MP3 player module |
homepage | |
repository | https://github.com/sciguy16/dfr0299-rs |
max_upload_size | |
id | 627209 |
size | 29,065 |
Rust implementation of the serial protocol for the DFR0299 MP3 player module
This crate provides zero-allocation, no_std
-compatible serialisation
and deserialisation for the commands supported by the DFR02999 MP3
player module.
Communication with the module is via UART at 9600-8-N-1.
Two example are provided: one using mio_serial
and one for the RP2040
cargo run --package serial_port
cargo run --release --package pico --target thumbv6m-none-eabi
Serialise commands into a buffer:
use dfr0299::{Command};
let mut buf = [0u8; 10];
Command::Reset.serialise(&mut buf)?;
// do something with the buffer, e.g. write to a uart peripheral
Command::Track(1).serialise(&mut buf)?;
// send the buffer, e.g.
// uart.write_full_blocking(&buf)?;
Parse response messages:
use dfr0299::{Parser, ParseResult};
fn process<R: std::io::Read>(mut uart: R) ->
Result<(), Box<dyn std::error::Error>> {
let mut parser = Parser::new();
let mut buf = [0u8; 1];
loop {
uart.read_exact(&mut buf)?;
match parser.process_byte(buf[0]) {
Ok(ParseResult::Incomplete) => {}
Ok(ParseResult::Complete(msg)) => {
println!("Message received: {msg:?}");
}
Err(e) => {
println!("Parse error: {e}");
}
}
}
}
Note that the example serialised messages in the datasheet are have incorrect checksums. The checksum algorithm is not described in the datasheet but is present in the official Arduino library code
This crate is distributed under the terms of the Mozilla Public License Version 2.0.