Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cyacc] Add convenience macros to simplify calling delay functions #33

Open
wants to merge 1 commit into
base: cycacc
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,55 @@ pub fn delay_cycles<const CYCLES: u64>() {
Delayer::<CYCLES, 1, 1>::delay_impl()
}

#[macro_export]
macro_rules! delay_cycles {
($t:expr) => {
$crate::delay_cycles::<{ $t }>()
};
}

/// Maximum value is (25_769_803_784 * 1_000_000 / CPU_FREQUENCY_HZ).
/// Almost 18 minutes at 24Mhz.
#[inline(always)]
pub fn delay_us<const US: u64>() {
Delayer::<US, {avr_config::CPU_FREQUENCY_HZ as u64}, 1_000_000>::delay_impl()
}

#[macro_export]
macro_rules! delay_us {
($t:expr) => {
$crate::delay_us::<{ $t }>()
};
}

/// Maximum value is (25_769_803_784 * 1_000 / CPU_FREQUENCY_HZ).
/// Almost 18 minutes at 24Mhz.
#[inline(always)]
pub fn delay_ms<const MS: u64>() {
Delayer::<MS, {avr_config::CPU_FREQUENCY_HZ as u64}, 1_000>::delay_impl()
}

#[macro_export]
macro_rules! delay_ms {
($t:expr) => {
$crate::delay_ms::<{ $t }>()
};
}

/// Maximum value is (25_769_803_784 * 1 / CPU_FREQUENCY_HZ).
/// Almost 18 minutes at 24Mhz.
#[inline(always)]
pub fn delay_sec<const SEC: u64>() {
Delayer::<SEC, {avr_config::CPU_FREQUENCY_HZ as u64}, 1>::delay_impl()
}

#[macro_export]
macro_rules! delay_sec {
($t:expr) => {
$crate::delay_sec::<{ $t }>()
};
}

#[cfg(test)]
mod tests {
#[test]
Expand Down