// Copyright (C) 2026 Hector van der Aa <hector@h3cx.dev>
// Copyright (C) 2026 Association Exergie <association.exergie@gmail.com>
// SPDX-License-Identifier: GPL-3.0-or-later

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

void ringBufferPush(volatile ring_buffer_t *rb, uint32_t value) {
  rb->buffer[rb->w_head] = value;
  rb->w_head++;
  return;
}

uint32_t ringBufferRead(volatile ring_buffer_t *rb, uint8_t neg_idx) {
  uint8_t idx = (uint8_t)(rb->w_head - 1u - neg_idx);
  return rb->buffer[idx];
}

void ringBufferRevert(volatile ring_buffer_t *rb, uint8_t val) {
  rb->w_head -= val;
  return;
}
