EasyGUI  v0.1
Platform independent GUI Library
Ring buffer

Generic cyclic buffer library. More...

Data Structures

struct  GUI_BUFFER_t
 Buffer structure. More...
 

Macros

#define GUI_BUFFER_INITIALIZED   0x01
 
#define GUI_BUFFER_MALLOC   0x02
 

Functions

uint8_t gui_buffer_init (GUI_BUFFER_t *Buffer, uint32_t Size, void *BufferPtr)
 Initializes buffer structure for work. More...
 
void gui_buffer_free (GUI_BUFFER_t *Buffer)
 Free memory for buffer allocated using dynamic memory allocation. More...
 
uint32_t gui_buffer_write (GUI_BUFFER_t *Buffer, const void *Data, uint32_t count)
 Writes data to buffer. More...
 
uint32_t gui_buffer_read (GUI_BUFFER_t *Buffer, void *Data, uint32_t count)
 Reads data from buffer. More...
 
uint32_t gui_buffer_getfree (GUI_BUFFER_t *Buffer)
 Gets number of free elements in buffer. More...
 
uint32_t gui_buffer_getfull (GUI_BUFFER_t *Buffer)
 Gets number of elements in buffer. More...
 
void gui_buffer_reset (GUI_BUFFER_t *Buffer)
 Resets (clears) buffer pointers. More...
 

Detailed Description

Generic cyclic buffer library.

This buffer does not only feature basic read/write operations for cyclic buffers, it also has feature to read strings from buffer if needed.

Read string procedure

Each string in buffer has separator character, in most cases, Line Feed (0x0A) is used, and is also default value when buffer is initialized. When reading as string from buffer, you have to know these things:

- Buffer supports fast memory read/write operation using memory copy feature
- Buffer will first check if string delimiter character exists in buffer. 
    - If it exists, characters will be set to user buffer until delimiter is detected. 
    - Delimiter is included in string!
- If string delimiter is not in buffer, but cyclic buffer full, 
    then string will be also filled into user buffer, because we need to free
    some memory for future characters, including string delimiter character
- If user buffer size is less than number of characters in buffer before string delimiter is found, 
    string is also filled in user buffer
- In all other cases, if there is no string delimiter in buffer, buffer will not return anything and will check for it first.

Macro Definition Documentation

#define GUI_BUFFER_INITIALIZED   0x01

Buffer initialized flag

#define GUI_BUFFER_MALLOC   0x02

Buffer uses malloc for memory

Function Documentation

void gui_buffer_free ( GUI_BUFFER_t Buffer)

Free memory for buffer allocated using dynamic memory allocation.

Note
This function has sense only if dynamic allocation was used for memory buffer
Parameters
*BufferPointer to GUI_BUFFER_t structure
Return values
None
uint32_t gui_buffer_getfree ( GUI_BUFFER_t Buffer)

Gets number of free elements in buffer.

Parameters
*BufferPointer to GUI_BUFFER_t structure
Return values
Numberof free elements in buffer
uint32_t gui_buffer_getfull ( GUI_BUFFER_t Buffer)

Gets number of elements in buffer.

Parameters
*BufferPointer to GUI_BUFFER_t structure
Return values
Numberof elements in buffer
uint8_t gui_buffer_init ( GUI_BUFFER_t Buffer,
uint32_t  Size,
void *  BufferPtr 
)

Initializes buffer structure for work.

Parameters
*BufferPointer to GUI_BUFFER_t structure to initialize
SizeSize of buffer in units of bytes
*BufferPtrPointer to array for buffer storage. Its length should be equal to
Sizeparameter. If NULL is passed as parameter, internal memory management will be used to allocate memory
Return values
Bufferinitialization status:
  • 0: Buffer initialized OK
  • > 0: Buffer initialization error. Malloc has failed with allocation
uint32_t gui_buffer_read ( GUI_BUFFER_t Buffer,
void *  Data,
uint32_t  count 
)

Reads data from buffer.

Parameters
*BufferPointer to GUI_BUFFER_t structure
*DataPointer to data where read values will be stored
countNumber of elements of type unsigned char to read
Return values
Numberof elements read from buffer
void gui_buffer_reset ( GUI_BUFFER_t Buffer)

Resets (clears) buffer pointers.

Parameters
*BufferPointer to GUI_BUFFER_t structure
Return values
None
uint32_t gui_buffer_write ( GUI_BUFFER_t Buffer,
const void *  Data,
uint32_t  count 
)

Writes data to buffer.

Parameters
*BufferPointer to GUI_BUFFER_t structure
*DataPointer to data to be written
countNumber of elements of type unsigned char to write
Return values
Numberof elements written in buffer