-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into parse-cfg-through-syn
- Loading branch information
Showing
34 changed files
with
495 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use riot_sys::dac_t; | ||
|
||
#[derive(Debug)] | ||
pub struct DACLine { | ||
line: dac_t, | ||
} | ||
|
||
#[derive(Debug)] | ||
#[non_exhaustive] | ||
pub enum DACError { | ||
/// The given dac_t line did not exist | ||
NoLine, | ||
/// An unknown error did occur | ||
Unknown, | ||
} | ||
|
||
impl DACLine { | ||
/// Creates and intializes a new [`DACLine`]. | ||
/// | ||
/// The `index` indicates which dac device from the current board should be used. | ||
/// For information on how many such devices are available for this board please | ||
/// refer to its RIOT documentation. | ||
/// | ||
/// Returns an Error if the given line does not exist | ||
/// on the board. | ||
pub fn new(index: usize) -> Result<Self, DACError> { | ||
let line = unsafe { riot_sys::macro_DAC_LINE(index as u32) }; | ||
let res = unsafe { riot_sys::dac_init(line) } as i32; | ||
|
||
const DAC_OK: i32 = riot_sys::DAC_OK as i32; | ||
const DAC_NOLINE: i32 = riot_sys::DAC_NOLINE as i32; | ||
|
||
match res { | ||
DAC_OK => Ok(DACLine { line }), | ||
DAC_NOLINE => Err(DACError::NoLine), | ||
_ => Err(DACError::Unknown), | ||
} | ||
} | ||
|
||
/// Builds a [`DACLine`] from an already initialized [`dac_t`]. | ||
/// | ||
/// Providing a not initialized [`dac_t`] results in undefined behavior. | ||
pub unsafe fn new_without_init(line: dac_t) -> Self { | ||
DACLine { line } | ||
} | ||
|
||
/// Writes the given value to this [`DACLine`] | ||
/// | ||
/// The `value` is internally scaled to the underlying | ||
/// dac device so that the maximum voltage output | ||
/// is always equivalent to [`u16::MAX`] | ||
pub fn set(&mut self, value: u16) { | ||
unsafe { riot_sys::dac_set(self.line, value) } | ||
} | ||
|
||
/// Turns the [`DACLine`] on after `DACLine::power_off` | ||
pub fn power_on(&mut self) { | ||
unsafe { riot_sys::dac_poweron(self.line) } | ||
} | ||
|
||
/// Turns the [`DACLine`] off | ||
pub fn power_off(&mut self) { | ||
unsafe { riot_sys::dac_poweroff(self.line) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.