Giter Site home page Giter Site logo

dfr0299-rs's Introduction

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 with-mio-serial
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.

dfr0299-rs's People

Contributors

sciguy16 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.