move lv_draw_buf to lv_mem as lv_mem_buf
This way they can be used as general purpose buffers not only for drawing
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
*********************/
|
||||
#include "lv_mem.h"
|
||||
#include "lv_math.h"
|
||||
#include "lv_gc.h"
|
||||
#include <string.h>
|
||||
|
||||
#if LV_MEM_CUSTOM != 0
|
||||
@@ -375,6 +376,73 @@ uint32_t lv_mem_get_size(const void * data)
|
||||
|
||||
#endif /*LV_ENABLE_GC*/
|
||||
|
||||
/**
|
||||
* Get a temporal buffer with the given size.
|
||||
* @param size the required size
|
||||
*/
|
||||
void * lv_mem_buf_get(uint32_t size)
|
||||
{
|
||||
/*Try to find a free buffer with suitable size */
|
||||
uint8_t i;
|
||||
for(i = 0; i < LV_MEM_BUF_MAX_NUM; i++) {
|
||||
if(_lv_mem_buf[i].used == 0 && _lv_mem_buf[i].size >= size) {
|
||||
_lv_mem_buf[i].used = 1;
|
||||
return _lv_mem_buf[i].p;
|
||||
}
|
||||
}
|
||||
|
||||
/*Reallocate a free buffer*/
|
||||
for(i = 0; i < LV_MEM_BUF_MAX_NUM; i++) {
|
||||
if(_lv_mem_buf[i].used == 0) {
|
||||
_lv_mem_buf[i].used = 1;
|
||||
_lv_mem_buf[i].size = size;
|
||||
/*if this fails you probably need to increase your LV_MEM_SIZE/heap size*/
|
||||
_lv_mem_buf[i].p = lv_mem_realloc(_lv_mem_buf[i].p, size);
|
||||
if(_lv_mem_buf[i].p == NULL) {
|
||||
LV_LOG_ERROR("lv_mem_buf_get: Out of memory, can't allocate a new buffer (increase your LV_MEM_SIZE/heap size)")
|
||||
}
|
||||
return _lv_mem_buf[i].p;
|
||||
}
|
||||
}
|
||||
|
||||
LV_LOG_ERROR("lv_mem_buf_get: no free buffer. Increase LV_DRAW_BUF_MAX_NUM.");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release a memory buffer
|
||||
* @param p buffer to release
|
||||
*/
|
||||
void lv_mem_buf_release(void * p)
|
||||
{
|
||||
uint8_t i;
|
||||
for(i = 0; i < LV_MEM_BUF_MAX_NUM; i++) {
|
||||
if(_lv_mem_buf[i].p == p) {
|
||||
_lv_mem_buf[i].used = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LV_LOG_ERROR("lv_mem_buf_release: p is not a known buffer")
|
||||
}
|
||||
|
||||
/**
|
||||
* Free all memory buffers
|
||||
*/
|
||||
void lv_mem_buf_free_all(void)
|
||||
{
|
||||
uint8_t i;
|
||||
for(i = 0; i < LV_MEM_BUF_MAX_NUM; i++) {
|
||||
if(_lv_mem_buf[i].p) {
|
||||
lv_mem_free(_lv_mem_buf[i].p);
|
||||
_lv_mem_buf[i].p = NULL;
|
||||
_lv_mem_buf[i].used = 0;
|
||||
_lv_mem_buf[i].size = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
Reference in New Issue
Block a user