embedded_c_sdk_bind_hal/
lib.rs

1#![no_std]
2
3#[macro_use]
4mod common;
5mod ll_api;
6mod tick_freq_hz;
7
8pub mod adc;
9pub mod dma;
10pub mod gpio;
11pub mod i2c;
12pub mod print;
13pub mod pwm;
14pub mod spi;
15pub mod tick;
16pub mod usart;
17
18pub use common::format;
19pub use ll_api::ll_cmd::*;
20
21#[cfg(feature = "print-log-csdk")]
22pub use embedded_c_sdk_bind_print_macros::{print, println};
23
24#[macro_export]
25macro_rules! ll_invoke {
26    ( $( $x:expr ),* ) => {
27        {
28            unsafe { $crate::ll_invoke( $( $x as $crate::InvokeParam, )* ) }
29        }
30    };
31}
32
33#[macro_export]
34macro_rules! sys_tick_handler {
35    () => {
36        <$crate::tick::Tick as $crate::tick::HalTickHandler>::on_sys_tick_interrupt();
37    };
38}
39
40/// Macro for setting up a periodic interval to execute a function.
41///
42/// # Syntax
43/// ```rust
44/// setInterval!(function, period_ms);
45/// setInterval!(function, period_ms, param1, param2, ...);
46/// ```
47///
48/// # Examples
49/// ```rust
50/// setInterval!(my_function, 1000);
51/// setInterval!(my_function_with_params, 1000, arg1, arg2);
52/// ```
53///
54/// # Arguments
55/// * `$f` - The function to be executed.
56/// * `$period_ms` - The period in milliseconds after which the function should be called.
57/// * `$( $param:expr ),*` - Optional parameters to pass to the function.
58///
59/// # Behavior
60/// * Initializes a static `Tick` variable.
61/// * Checks if the elapsed time since the last execution is greater than or equal to the specified period.
62/// * If so, resets the `Tick` and calls the function with or without parameters.
63#[macro_export]
64macro_rules! setInterval {
65    ($f:expr, $period_ms:expr) => {
66        {
67            static mut TICK: Tick = Tick::with_value(0);
68
69            if unsafe { TICK.elapsed_time().to_millis() } >= $period_ms {
70                unsafe { TICK = Tick::now(); }
71                $f();
72            }
73        }
74    };
75
76    ($f:expr, $period_ms:expr, $( $param:expr ),*) => {
77        {
78            static mut TICK: Tick = Tick::with_value(0);
79
80            if unsafe { TICK.elapsed_time().to_millis() } >= $period_ms {
81                unsafe { TICK = Tick::now(); }
82                $f($( $param, )*);
83            }
84        }
85    };
86}