1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! Rust timer handling logic
//!
//! LVGL allows for an external timer function to be used. This feature enables
//! a generic `LvClock` interface that can be used to build Rust-native timers.
//!
//! # Building
//!
//! Set `LV_TICK_CUSTOM` to `1` and `LV_TICK_CUSTOM_INCLUDE` to `<rs_timer.h>`
//! in `lv_conf.h`, and enable the `rust_timer` feature on the `lvgl` crate to
//! enable this functionality.
//!
//! # Usage
//!
//! Implement the `lvgl::timer::LvClock` trait on a type and initialize it on
//! the first frame. The `since_init()` function should return a `Duration`
//! representing time elapsed since the beginning of the first frame of the
//! program.
//!
//! ```no_run
//! use lvgl::timer::LvClock;
//!
//! struct Clock {
//! start: Instant,
//! }
//!
//! impl Default for Clock {
//! fn default() -> Self {
//! Self {
//! start: Instant::now(),
//! }
//! }
//! }
//!
//! impl LvClock for Clock {
//! fn since_init(&self) -> Duration {
//! Instant::now().duration_since(self.start)
//! }
//! }
//!
//! fn main() {
//! // Initialize displays, etc.
//! let clock = Clock::default();
//! loop {
//! // Looping UI logic
//! lvgl::timer::update_clock(&clock).unwrap();
//! }
//! }
//! ```
//!
//! For a full example implementation similar to the above, see the
//! `rust_timer` example. When running, make sure to modify the config in
//! `examples/include/lv_conf.h` (or your own) as above first.
use TryFromIntError;
use Duration;
static mut RET_VAL: u32 = 0;
/// An LVGL-compatible clock
/// Synchronize the clock with LVGL. FIXME: When to call
unsafe extern "C"