hydrotower-mainboard/src/buffer/buffer.h

43 lines
1.6 KiB
C

// Copyright (C) 2025 Thies Lennart Alff
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA
#pragma once
#include <stdbool.h>
#include <stdint.h>
typedef struct {
uint32_t head;
uint32_t tail;
uint32_t length;
uint8_t *data;
bool full;
} buffer_t;
typedef buffer_t *buffer_handle_t;
void buffer_init(buffer_handle_t handle, uint8_t *raw_buffer, uint32_t length);
bool buffer_is_full(const buffer_handle_t);
bool buffer_is_empty(const buffer_handle_t);
uint32_t buffer_capacity(const buffer_handle_t);
uint32_t buffer_size(const buffer_handle_t);
uint32_t buffer_read_byte(buffer_handle_t, uint8_t *data);
uint32_t buffer_read(buffer_handle_t, uint8_t *data, uint32_t length);
uint32_t buffer_read2(buffer_handle_t, uint8_t *data, uint32_t length);
uint32_t buffer_write_byte(buffer_handle_t, uint8_t byte);
uint32_t buffer_write(buffer_handle_t, uint8_t *data, uint32_t length);
bool buffer_find(const buffer_handle_t, uint8_t byte, uint32_t *index);