ic_md/lib.rs
1//! Driver for the iC-MD quadrature counter.
2//! Built fully in Rust, uses [embedded_hal] and [device_driver].
3//!
4//! # Introduction
5//!
6//! The `IcMd` struct provides a high-level interface to interact with the iC-MD quadrature
7//! counter. However, you can also access the underlying device driver directly via the `device`
8//! field. Please read the device driver documentation for more information on what to expect
9//! when interfacing with the device driver directly.
10//! This low-level access is a temporary solution until the high-level interface is fully
11//! developed. When this well be the case is unclear. If you are interested in it, please let me
12//! know and I'm happy to prioritize the high-level features that are interesting to you.
13//!
14//! # Limitations
15//!
16//! The following capabilities are currently only accessible via the low-level interface:
17//!
18//! - Reference register readout: It is unclear if this currently works, see code comment.
19//!
20//! The following features are currently not yet implemented:
21//!
22//! - Differential or TTL inputs (Address 0x01, bit 7)
23//! - Configuration to have Z signal clear counters 0 and/or 1 (Address 0x01, bits 5 and 6)
24//! - Z signal configuration (Address 0x01, bits 3 and 4)
25//! - Touch probe and AB registers (Address 0x01, bits 1 and 2)
26//! - Differential input configuration selection (RS-422 (default) or LVDS) (Address 0x03, bit 7)
27//!
28//! # Example Usage
29//!
30//! This example requires the "blocking" feature to be activated, which it is by default.
31//!
32#![cfg_attr(not(feature = "blocking"), doc = "```ignore")]
33#![cfg_attr(feature = "blocking", doc = "```")]
34//! # use embedded_hal_mock::eh1::spi::{Mock, Transaction};
35//! # use ic_md::IcMd;
36//! # let expectations = [
37//! # Transaction::transaction_start(),
38//! # Transaction::write(0x00),
39//! # Transaction::write(0x02),
40//! # Transaction::transaction_end(),
41//! # Transaction::transaction_start(),
42//! # Transaction::write(0x80 | 0x08),
43//! # Transaction::read_vec(vec![0x00, 0x00, 0x00, 0x00, 0x00, 0x2A, 0xC0]),
44//! # Transaction::transaction_end(),
45//! # ];
46//! // Initialize your SPIDevice, here we are mocking a device!
47//! let mut spi_device = Mock::new(&expectations);
48//!
49//! // Get a handle to the counter with the default setup
50//! let mut icmd = IcMd::new(&mut spi_device);
51//!
52//! // Initialize the counter
53//! icmd.init().unwrap();
54//!
55//! // Read out the counter
56//! let counter_value = icmd.read_counter().unwrap();
57//!
58//! // We can use the get counter methods to access the values. This will return an `Option`
59//! // containing an `i64` value of the count (if the counter is setup, otherwise `None`).
60//! let cnt_0 = counter_value
61//! .get_cnt0()
62//! .expect("Counter 0 should always be set up");
63//!
64//! assert_eq!(cnt_0, 42);
65//!
66//! // Last, let us ensure that there are no errors or warnings in the device status. We can use
67//! // the `.is_ok()` method on the `DeviceStatus` struct to do this.
68//! assert!(icmd.get_device_status().is_ok());
69//! #
70//! # // Check that all our expectations are met - testing only
71//! # spi_device.done();
72//! ```
73//!
74//! # Crate features
75//!
76//! By default, the blocking interface is activated (feature "blocking").
77//! However, an async interface is also available when you activate the "async" feature.
78//!
79//! # Further help
80//!
81//! For further help and examples, please have a look at the `test` directory in the GitHub
82//! repository, which you can find [here](https://github.com/trappitsch/ic-md/).
83//! There you will find various integration tests that show how to use the driver in practice and
84//! that contain detailed comments on for you.
85
86#![deny(warnings)]
87#![cfg_attr(not(test), no_std)]
88
89pub use configs::*;
90
91#[cfg(feature = "blocking")]
92pub mod hl_blocking;
93#[cfg(feature = "blocking")]
94pub use hl_blocking::IcMd;
95
96#[cfg(feature = "async")]
97pub mod hl_async;
98#[cfg(feature = "async")]
99pub use hl_async::IcMdAsync;
100
101pub mod configs;
102pub mod dd;