#ifndef TUNDRA_UART_H_ #define TUNDRA_UART_H_ // circular buffer implemented with maximum data count = capacity - 1 // this allows an easy way to differentiate full and empty conditions typedef struct { uint8_t *buffer; // Pointer to the allocated memory for the buffer uint32_t capacity; // Maximum number of elements the buffer can hold uint32_t head; // Index of the next element to be written uint32_t tail; // Index of the next element to be read uint32_t flags; } circular_buffer_t; typedef enum { CBUF_OVERRUN = 1, } circular_buffer_flags_t; inline bool circular_buffer_is_empty(circular_buffer_t* buf) { return (buf->head) == (buf->tail); } inline bool circular_buffer_is_full(circular_buffer_t* buf) { return ((buf->head)+1) == (buf->tail); } inline void circular_buffer_put(circular_buffer_t* buf, uint8_t new_item) { if(circular_buffer_is_full(buf)) { buf->flags |= CBUF_OVERRUN; } buf->buffer[buf->head] = new_item; (buf->head)++; if(buf->head == buf->capacity) buf->head = 0; } inline bool circular_buffer_get(circular_buffer_t* buf, uint8_t* retrieved_item) { bool retval = false; if(!circular_buffer_is_empty(buf)) { *retrieved_item = buf->buffer[buf->tail]; (buf->tail)++; if(buf->tail == buf->capacity) buf->tail = 0; retval = true; } return retval; } void start_tundra_uart_task(void); void send_code_to_tundra_uart_task(uint32_t code); uint8_t* tundra_uart_get_hid_buffer(void); uint32_t tundra_uart_get_hid_buffer_length(void); #endif // TUNDRA_UART_H_