#![warn(rust_2018_idioms)]
#[cfg(not(any(feature = "rp-sys", feature = "mock")))]
compile_error!("Either feature 'rp-sys' (default) or 'mock' must be enabled for this crate.");
use rp_sys as rp;
pub use rp::rp_channel_t as Channel;
macro_rules! handle_unsafe {
($e:expr) => (
{
match unsafe { $e } as u32 {
$crate::rp::RP_OK => Ok(()),
code => Err(crate::Error::from(code)),
}
}
);
}
macro_rules! convert_string {
($e:expr) => (
{
let buffer = unsafe {
std::ffi::CStr::from_ptr($e)
};
std::str::from_utf8(buffer.to_bytes())
.unwrap()
.to_owned()
}
);
}
pub mod calibration;
pub mod fpga;
pub mod led;
pub mod gpio;
pub mod pin;
pub mod acquire;
pub mod generator;
pub mod cmn;
mod result;
pub use result::{Error, Result};
pub fn init() -> Result<()>
{
handle_unsafe!(
rp::rp_Init()
)
}
pub fn init_reset(reset: bool) -> Result<()>
{
handle_unsafe!(
rp::rp_InitReset(reset)
)
}
pub fn calib_init() -> Result<()>
{
handle_unsafe!(
rp::rp_CalibInit()
)
}
pub fn release() -> Result<()>
{
handle_unsafe!(
rp::rp_Release()
)
}
pub fn reset() -> Result<()>
{
handle_unsafe!(
rp::rp_Reset()
)
}
pub fn version() -> String
{
convert_string!(
rp::rp_GetVersion()
)
}
pub fn enable_digital_loop(enable: bool) -> Result<()>
{
handle_unsafe!(
rp::rp_EnableDigitalLoop(enable)
)
}