From 8d4a04d3545b5173bea6eeea81be0581e6134dbf Mon Sep 17 00:00:00 2001 From: Mendelt Siebenga Date: Sun, 19 Jul 2020 15:36:07 +0200 Subject: [PATCH 1/2] first naive implementation of dac trait --- src/blocking/dac.rs | 10 ++++++++++ src/blocking/mod.rs | 1 + 2 files changed, 11 insertions(+) create mode 100644 src/blocking/dac.rs diff --git a/src/blocking/dac.rs b/src/blocking/dac.rs new file mode 100644 index 000000000..73289fea8 --- /dev/null +++ b/src/blocking/dac.rs @@ -0,0 +1,10 @@ +//! Trait for digital to analog conversion + +/// Represents a single DAC channel. +pub trait DAC { + /// Error type returned by DAC methods + type Error; + + /// Set the output of the DAC + fn try_set_output(&mut self, value: WORD) -> Result<(), Self::Error>; +} diff --git a/src/blocking/mod.rs b/src/blocking/mod.rs index 3a050f6d2..3255216c9 100644 --- a/src/blocking/mod.rs +++ b/src/blocking/mod.rs @@ -4,6 +4,7 @@ //! traits. To save boilerplate when that's the case a `Default` marker trait may be provided. //! Implementing that marker trait will opt in your type into a blanket implementation. +pub mod dac; pub mod delay; pub mod i2c; pub mod rng; From 3e13ccfec103aba319d18366a614b65734be4dde Mon Sep 17 00:00:00 2001 From: Mendelt Siebenga Date: Thu, 23 Jul 2020 16:00:10 +0200 Subject: [PATCH 2/2] some docstrings --- src/blocking/dac.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/blocking/dac.rs b/src/blocking/dac.rs index 73289fea8..6e99cb947 100644 --- a/src/blocking/dac.rs +++ b/src/blocking/dac.rs @@ -1,6 +1,10 @@ -//! Trait for digital to analog conversion +//! Blocking DAC trait for single channel digital to analog conversion -/// Represents a single DAC channel. +/// A single DAC channel. Word is the type used to represent a single sample, this would typically +/// be u8, u16 or u32. +/// Note that not all bits will always be used. A 12 bit DAC for example will probably use u16 here +/// should we prescribe to use the most significant bits here for compat between word +/// sizes? pub trait DAC { /// Error type returned by DAC methods type Error;