1 /**
2  * @file lv_timer.h
3  */
4 
5 #ifndef LV_TIMER_H
6 #define LV_TIMER_H
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 /*********************
13  *      INCLUDES
14  *********************/
15 #include "../lv_conf_internal.h"
16 
17 #include <stdint.h>
18 #include <stdbool.h>
19 
20 /*********************
21  *      DEFINES
22  *********************/
23 #ifndef LV_ATTRIBUTE_TIMER_HANDLER
24 #define LV_ATTRIBUTE_TIMER_HANDLER
25 #endif
26 
27 #define LV_NO_TIMER_READY 0xFFFFFFFF
28 
29 /**********************
30  *      TYPEDEFS
31  **********************/
32 
33 struct _lv_timer_t;
34 
35 /**
36  * Timers execute this type of functions.
37  */
38 typedef void (*lv_timer_cb_t)(struct _lv_timer_t *);
39 
40 /**
41  * Descriptor of a lv_timer
42  */
43 typedef struct _lv_timer_t {
44     uint32_t period; /**< How often the timer should run*/
45     uint32_t last_run; /**< Last time the timer ran*/
46     lv_timer_cb_t timer_cb; /**< Timer function*/
47     void * user_data; /**< Custom user data*/
48     int32_t repeat_count; /**< 1: One time;  -1 : infinity;  n>0: residual times*/
49     uint32_t paused : 1;
50 } lv_timer_t;
51 
52 /**********************
53  * GLOBAL PROTOTYPES
54  **********************/
55 
56 /**
57  * Init the lv_timer module
58  */
59 void _lv_timer_core_init(void);
60 
61 //! @cond Doxygen_Suppress
62 
63 /**
64  * Call it periodically to handle lv_timers.
65  * @return time till it needs to be run next (in ms)
66  */
67 LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void);
68 
69 //! @endcond
70 
71 /**
72  * Create an "empty" timer. It needs to initialized with at least
73  * `lv_timer_set_cb` and `lv_timer_set_period`
74  * @return pointer to the created timer
75  */
76 lv_timer_t * lv_timer_create_basic(void);
77 
78 /**
79  * Create a new lv_timer
80  * @param timer_xcb a callback to call periodically.
81  *                 (the 'x' in the argument name indicates that it's not a fully generic function because it not follows
82  *                  the `func_name(object, callback, ...)` convention)
83  * @param period call period in ms unit
84  * @param user_data custom parameter
85  * @return pointer to the new timer
86  */
87 lv_timer_t * lv_timer_create(lv_timer_cb_t timer_xcb, uint32_t period, void * user_data);
88 
89 /**
90  * Delete a lv_timer
91  * @param timer pointer to an lv_timer
92  */
93 void lv_timer_del(lv_timer_t * timer);
94 
95 /**
96  * Pause/resume a timer.
97  * @param timer pointer to an lv_timer
98  */
99 void lv_timer_pause(lv_timer_t * timer);
100 
101 void lv_timer_resume(lv_timer_t * timer);
102 
103 /**
104  * Set the callback the timer (the function to call periodically)
105  * @param timer pointer to a timer
106  * @param timer_cb the function to call periodically
107  */
108 void lv_timer_set_cb(lv_timer_t * timer, lv_timer_cb_t timer_cb);
109 
110 /**
111  * Set new period for a lv_timer
112  * @param timer pointer to a lv_timer
113  * @param period the new period
114  */
115 void lv_timer_set_period(lv_timer_t * timer, uint32_t period);
116 
117 /**
118  * Make a lv_timer ready. It will not wait its period.
119  * @param timer pointer to a lv_timer.
120  */
121 void lv_timer_ready(lv_timer_t * timer);
122 
123 /**
124  * Set the number of times a timer will repeat.
125  * @param timer pointer to a lv_timer.
126  * @param repeat_count -1 : infinity;  0 : stop ;  n>0: residual times
127  */
128 void lv_timer_set_repeat_count(lv_timer_t * timer, int32_t repeat_count);
129 
130 /**
131  * Reset a lv_timer.
132  * It will be called the previously set period milliseconds later.
133  * @param timer pointer to a lv_timer.
134  */
135 void lv_timer_reset(lv_timer_t * timer);
136 
137 /**
138  * Enable or disable the whole lv_timer handling
139  * @param en true: lv_timer handling is running, false: lv_timer handling is suspended
140  */
141 void lv_timer_enable(bool en);
142 
143 /**
144  * Get idle percentage
145  * @return the lv_timer idle in percentage
146  */
147 uint8_t lv_timer_get_idle(void);
148 
149 /**
150  * Iterate through the timers
151  * @param timer NULL to start iteration or the previous return value to get the next timer
152  * @return the next timer or NULL if there is no more timer
153  */
154 lv_timer_t * lv_timer_get_next(lv_timer_t * timer);
155 
156 /**********************
157  *      MACROS
158  **********************/
159 
160 #ifdef __cplusplus
161 } /*extern "C"*/
162 #endif
163 
164 #endif
165