mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
lv_task: add user data and pass lv_task_t as task_cb parameter
This commit is contained in:
parent
15c27c8a9b
commit
5243d235a6
@ -68,13 +68,13 @@ void lv_indev_init(void)
|
||||
* Called periodically to read the input devices
|
||||
* @param param pointer to and input device to read
|
||||
*/
|
||||
void lv_indev_read_task(void * param)
|
||||
void lv_indev_read_task(lv_task_t * task)
|
||||
{
|
||||
LV_LOG_TRACE("indev read task started");
|
||||
|
||||
lv_indev_data_t data;
|
||||
|
||||
indev_act = param;
|
||||
indev_act = task->user_data;
|
||||
|
||||
/*Read and process all indevs*/
|
||||
if(indev_act->driver.disp == NULL) return; /*Not assigned to any displays*/
|
||||
|
@ -36,9 +36,9 @@ void lv_indev_init(void);
|
||||
|
||||
/**
|
||||
* Called periodically to read the input devices
|
||||
* @param param pointer to and input device to read
|
||||
* @param task pointer to the task itself
|
||||
*/
|
||||
void lv_indev_read_task(void * param);
|
||||
void lv_indev_read_task(lv_task_t * task);
|
||||
|
||||
/**
|
||||
* Get the currently processed input device. Can be used in action functions too.
|
||||
|
@ -132,15 +132,15 @@ lv_disp_t * lv_refr_get_disp_refreshing(void)
|
||||
|
||||
/**
|
||||
* Called periodically to handle the refreshing
|
||||
* @param param point to a `lv_disp_t` to refresh
|
||||
* @param task pointer to the task itself
|
||||
*/
|
||||
void lv_disp_refr_task(void * param)
|
||||
void lv_disp_refr_task(lv_task_t * task)
|
||||
{
|
||||
LV_LOG_TRACE("lv_refr_task: started");
|
||||
|
||||
uint32_t start = lv_tick_get();
|
||||
|
||||
disp_refr = param;
|
||||
disp_refr = task->user_data;
|
||||
|
||||
lv_refr_join_area();
|
||||
|
||||
|
@ -69,9 +69,9 @@ lv_disp_t * lv_refr_get_disp_refreshing(void);
|
||||
|
||||
/**
|
||||
* Called periodically to handle the refreshing
|
||||
* @param param point to a `lv_disp_t` to refresh
|
||||
* @param task pointer to the task itself
|
||||
*/
|
||||
void lv_disp_refr_task(void * param);
|
||||
void lv_disp_refr_task(lv_task_t * task);
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
|
@ -138,7 +138,7 @@ LV_ATTRIBUTE_TASK_HANDLER void lv_task_handler(void)
|
||||
if(task_deleted)
|
||||
break; /*If a task was deleted then this or the next item might be corrupted*/
|
||||
if(task_created)
|
||||
break; /*If a task was deleted then this or the next item might be corrupted*/
|
||||
break; /*If a task was created then this or the next item might be corrupted*/
|
||||
|
||||
LV_GC_ROOT(_lv_task_act) = next; /*Load the next task*/
|
||||
}
|
||||
@ -165,7 +165,7 @@ LV_ATTRIBUTE_TASK_HANDLER void lv_task_handler(void)
|
||||
* @param task a function which is the task itself
|
||||
* @param period call period in ms unit
|
||||
* @param prio priority of the task (LV_TASK_PRIO_OFF means the task is stopped)
|
||||
* @param user_data free parameter
|
||||
* @param user_data custom parameter
|
||||
* @return pointer to the new task
|
||||
*/
|
||||
lv_task_t * lv_task_create(void (*task)(void *), uint32_t period, lv_task_prio_t prio, void * user_data)
|
||||
@ -198,12 +198,20 @@ lv_task_t * lv_task_create(void (*task)(void *), uint32_t period, lv_task_prio_t
|
||||
}
|
||||
|
||||
new_lv_task->period = period;
|
||||
new_lv_task->task = task;
|
||||
new_lv_task->task_cb = task;
|
||||
new_lv_task->prio = prio;
|
||||
new_lv_task->param = user_data;
|
||||
|
||||
new_lv_task->once = 0;
|
||||
new_lv_task->last_run = lv_tick_get();
|
||||
|
||||
#if LV_USE_USER_DATA_SINGLE
|
||||
new_lv_task->user_data = user_data;
|
||||
#endif
|
||||
|
||||
#if LV_USE_USER_DATA_MULTI
|
||||
new_lv_task->task_user_data = NULL;
|
||||
#endif
|
||||
|
||||
task_created = true;
|
||||
|
||||
return new_lv_task;
|
||||
@ -322,7 +330,7 @@ static bool lv_task_exec(lv_task_t * lv_task_p)
|
||||
lv_task_p->last_run = lv_tick_get();
|
||||
task_deleted = false;
|
||||
task_created = false;
|
||||
lv_task_p->task(lv_task_p->param);
|
||||
lv_task_p->task_cb(lv_task_p);
|
||||
|
||||
/*Delete if it was a one shot lv_task*/
|
||||
if(task_deleted == false) { /*The task might be deleted by itself as well*/
|
||||
|
@ -55,8 +55,16 @@ typedef struct
|
||||
{
|
||||
uint32_t period;
|
||||
uint32_t last_run;
|
||||
void (*task)(void *);
|
||||
void * param;
|
||||
void (*task_cb)(void *);
|
||||
|
||||
#if LV_USE_USER_DATA_SINGLE
|
||||
void * user_data;
|
||||
#endif
|
||||
|
||||
#if LV_USE_USER_DATA_MULTI
|
||||
void * task_user_data;
|
||||
#endif
|
||||
|
||||
uint8_t prio : 3;
|
||||
uint8_t once : 1;
|
||||
} lv_task_t;
|
||||
@ -80,15 +88,14 @@ LV_ATTRIBUTE_TASK_HANDLER void lv_task_handler(void);
|
||||
* @param task a function which is the task itself
|
||||
* @param period call period in ms unit
|
||||
* @param prio priority of the task (LV_TASK_PRIO_OFF means the task is stopped)
|
||||
* @param user_data free parameter
|
||||
* @return pointer to the new task
|
||||
* @param user_data custom parameter
|
||||
* @return pointer to the new task_cb
|
||||
*/
|
||||
lv_task_t * lv_task_create(void (*task)(void *), uint32_t period, lv_task_prio_t prio,
|
||||
void * user_data);
|
||||
lv_task_t * lv_task_create(void (*task)(void *), uint32_t period, lv_task_prio_t prio, void * user_data);
|
||||
|
||||
/**
|
||||
* Delete a lv_task
|
||||
* @param lv_task_p pointer to task created by lv_task_p
|
||||
* @param lv_task_p pointer to task_cb created by lv_task_p
|
||||
*/
|
||||
void lv_task_del(lv_task_t * lv_task_p);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user