00‐deep‐Embedded lvgl link list - JohnHau/mis GitHub Wiki

#include<stdio.h> #include<stdlib.h> #include<stdint.h> #include<unistd.h> #include<fcntl.h>

typedef uint8_t lv_ll_node_t;

typedef struct{ uint32_t n_size; lv_ll_node_t *head; lv_ll_node_t *tail; }lv_ll_t;

#define LL_NODE_META_SIZE (sizeof(lv_ll_node_t*) + sizeof(lv_ll_node_t*)) #define LL_PREV_P_OFFSET(ll_p) (ll_p->n_size) #define LL_NEXT_P_OFFSET(ll_p) (ll_p->n_size + sizeof(lv_ll_node_t*))

typedef struct _lv_task_t {

uint32_t period;
uint32_t last_run;
void* user_data;
int32_t repeat_count;

}lv_task_t;

#define LV_INV_BUF_SIZE 32 typedef struct _disp_t { uint8_t inv_area_joined[LV_INV_BUF_SIZE]; uint32_t last_activity_time; }lv_disp_t;

#define LV_ITERATE_ROOTS(f)
f(lv_ll_t, _lv_task_ll)
f(lv_ll_t, _lv_disp_ll)

#define LV_DEFINE_ROOT(root_type,root_name) root_type root_name; #define LV_ROOTS LV_ITERATE_ROOTS(LV_DEFINE_ROOT)

static void node_set_prev(lv_ll_t* ll_p, lv_ll_node_t* act, lv_ll_node_tprev) { if(act == NULL)return;//cannot set the prev node of NULL uint8_t act8 = (uint8_t*)act; act8 += LL_PREV_P_OFFSET(ll_p); lv_ll_node_t ** act_node_p = (lv_ll_node_t**)act8; lv_ll_node_t ** prev_node_p = (lv_ll_node_t**)&prev; *act_node_p = *prev_node_p;

}

static void node_set_next(lv_ll_t* ll_p, lv_ll_node_t* act, lv_ll_node_tnext) { if(act == NULL)return;//cannot set the prev node of NULL uint8_t act8 = (uint8_t*)act; act8 += LL_NEXT_P_OFFSET(ll_p); lv_ll_node_t ** act_node_p = (lv_ll_node_t**)act8; lv_ll_node_t ** next_node_p = (lv_ll_node_t**)&next; *act_node_p = *next_node_p;

}

/* *Initialize linked list *@param ll_dsc pointer to ll_dsc variable *@param node_size the size of 1 node in bytes / void _lv_ll_init(lv_ll_t ll_p, uint32_t node_size) { ll_p->head = NULL; ll_p->tail = NULL;

//round the size up to 8
node_size = (node_size + 7) & (~0x07);
ll_p->n_size = node_size;

}

/* *Add a new head to a linked list *@param ll_p pointer to linked list *@return pointer to the new head / void * _lv_ll_ins_head(lv_ll_t ll_p)

{ lv_ll_node_t * n_new; n_new = malloc(ll_p->n_size + LL_NODE_META_SIZE);

if(n_new != NULL)
{
	node_set_prev(ll_p,n_new,NULL);//no prev. before the new head
	node_set_next(ll_p,n_new,ll_p->head);//after new comes the old head

	if(ll_p->head != NULL)//if there is old head the before it goes the new
	{
		node_set_prev(ll_p,ll_p->head,n_new);
	}

	ll_p->head = n_new;//set the new head in the dsc.
	if(ll_p->tail == NULL)
	{
		ll_p->tail = n_new;
	}
}
return n_new;

}

/* *Return with head node of the linked list *@param ll_p pointer to the linked list *@return pointer to the head of 'll_p' / void * _lv_ll_get_head(const lv_ll_t ll_p) { void * head = NULL;

if(ll_p != NULL)
{
	head = ll_p->head;
}

return head;

}

/* *Return with tail node of the linked list *@param ll_p pointer to linked list *@return pointer to the head of 'll_p' / void * _lv_ll_get_tail(const lv_ll_t ll_p) { void * tail = NULL; if(ll_p != NULL) { tail = ll_p->tail; }

return tail;

}

/* *Return with the pointer of the next node after 'n_act' *@param ll_p pointer to linked list @param n_act pointer a node @return pointer to the next node / void * _lv_ll_get_next(const lv_ll_t ll_p, const void n_act) { if(ll_p == NULL) return NULL; / *Pointer to the next node is stored in the end of this node. *Go there and return the address found there */

const lv_ll_node_t * n_act_d = n_act;
n_act_d += LL_NEXT_P_OFFSET(ll_p);
return *((lv_ll_node_t**)n_act_d);

}

/* *Return with the pointer of the previous node after 'n_act' *@param ll_p pointer to linked list @param n_act pointer a node @return pointer to the previous node / void * _lv_ll_get_prev(const lv_ll_t ll_p, const void n_act) { if(ll_p == NULL) return NULL; / *Pointer to the prev. node is stored in the end of this node. *Go there and return the address found there */

const lv_ll_node_t * n_act_d = n_act;
n_act_d += LL_PREV_P_OFFSET(ll_p);
return *((lv_ll_node_t**)n_act_d);

}

#define _LV_LL_READ(list,i) for(i = _lv_ll_get_head(&list);i != NULL;i = _lv_ll_get_next(&list,i)) #define _LV_LL_READ_BACK(list,i) for(i = _lv_ll_get_tail(&list);i != NULL;i = _lv_ll_get_prev(&list,i))

int main(int argc,char* argv[]) {

lv_ll_t _lv_disp_ll;

_lv_ll_init(&_lv_disp_ll,sizeof(lv_disp_t));

lv_disp_t*disp; 
disp = _lv_ll_ins_head(&_lv_disp_ll);

disp->last_activity_time = 23;

disp = _lv_ll_ins_head(&_lv_disp_ll);

disp->last_activity_time = 24;

#if 0 lv_disp_t *i = _lv_ll_get_head(&_lv_disp_ll);

if(i != NULL)
{
	printf("last_activity_time is %d\n",i->last_activity_time);
}
else
{
	printf("i is NULL\n");
}

#endif

#if 1 lv_disp_t *i; //_LV_LL_READ(_lv_disp_ll,i) _LV_LL_READ_BACK(_lv_disp_ll,i) { uint32_t m = i->last_activity_time; printf("m is %d\n",m);

}

#endif

//printf("it is %d\n",LL_NODE_META_SIZE);

//printf("it is %d\n",sizeof(uint8_t*));

return 0;

}

⚠️ **GitHub.com Fallback** ⚠️