#ifndef RING_BUFFER_H
#define RING_BUFFER_H

#include <stdint.h>
#include <stdbool.h>

#define RB_SIZE (1U << 13U)  // must be power of 2 for efficiency

typedef struct
{
    uint8_t buffer[RB_SIZE];
    volatile uint16_t head;
    volatile uint16_t tail;
} ring_buffer_t;

void rb_init(ring_buffer_t* rb);
bool rb_push(ring_buffer_t* rb, uint8_t data);
bool rb_pop(ring_buffer_t* rb, uint8_t* data);
uint16_t rb_available(const ring_buffer_t* rb);
bool rb_peek(const ring_buffer_t* const rb, uint8_t* const data);
bool rb_peek_at(const ring_buffer_t* const rb, uint16_t index, uint8_t* data);

#endif