mcp2210

Crates.iomcp2210
lib.rsmcp2210
version0.2.0
sourcesrc
created_at2018-07-17 20:40:48.946794
updated_at2023-12-12 18:24:41.959707
descriptionMicrochip MCP2210 communication library
homepagehttps://github.com/Gekkio/mcp2210-rs
repositoryhttps://github.com/Gekkio/mcp2210-rs
max_upload_size
id74787
size64,119
Joonas Javanainen (Gekkio)

documentation

README

mcp2210-rs: Microchip MCP2210 library

Minimum Rust version: 1.63

MCP2210 datasheet

Build Status Latest release on crates.io Documentation on docs.rs

To use mcp2210, you'll need to add it and hidapi to your dependencies.

cargo add mcp2210 hidapi

⚠️ WARNING: This code sends 0xaa55 on the MCP2210's SPI bus. If you have a device connected to the SPI bus, ensure this will not harm it. ⚠️

This code sends 0xaa55 on the MCP2210's SPI bus MOSI pin and asserts that the same data is simultaneously recieved at the MISO pin. The circuit required for this is simply a wire between the MOSI and MISO pins of the MCP2210 and no real slave device.

use hidapi::HidApi;
use mcp2210::{open_first, Commands, SpiMode, SpiTransferSettings};

fn main() {
    let hidapi_context = HidApi::new().expect("Could not create hidapi context");
    let mut mcp = open_first(&hidapi_context).expect("Failed to connect");
    mcp.set_spi_transfer_settings(&SpiTransferSettings {
        bit_rate: 1_000,
        bytes_per_tx: 2,
        spi_mode: SpiMode::Mode0,
        ..Default::default()
    })
    .expect("Failed to set settings");
    let mut buf = Vec::new();
    mcp.spi_transfer_to_end(&[0xaa, 0x55], &mut buf)
        .expect("SPI transfer failed");
    assert_eq!(buf, [0xaa, 0x55]);
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 71

cargo fmt