#module #mp3 #player #protocols #serial #command #uart

no-std dfr0299

Rust implementation of the serial protocol for the DFR0299 MP3 player module

2 releases

0.1.1 Jul 17, 2022
0.1.0 Jul 17, 2022

#1080 in Embedded development

MPL-2.0 license

30KB
480 lines

dfr0299

Crates.io docs.rs

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.

Examples

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

License

This crate is distributed under the terms of the Mozilla Public License Version 2.0.

Dependencies

~1.5MB
~38K SLoC