libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
double_buffer.hpp
1#pragma once
2
3#include <cassert>
4#include <cstddef>
5#include <cstdint>
6#include <cstring>
7
8#include "libxr_type.hpp" // RawData
9
10namespace LibXR
11{
21{
22 public:
29 explicit DoubleBuffer(const LibXR::RawData& raw_data);
30
37 uint8_t* ActiveBuffer();
38
45 uint8_t* PendingBuffer();
46
53 size_t Size() const;
54
62 void Switch();
63
70 bool HasPending() const;
71
81 bool FillPending(const uint8_t* data, size_t len);
82
92 bool FillActive(const uint8_t* data, size_t len);
93
100 void EnablePending();
101
108 size_t GetPendingLength() const;
109
116 void SetPendingLength(size_t size) { pending_len_ = size; }
117
118 private:
119 uint8_t* buffer_[2];
120 size_t size_;
121 int active_ = 0;
123 false;
124 size_t pending_len_ = 0;
125};
126} // namespace LibXR
双缓冲区管理类 / Double buffer manager class
int active_
当前活动缓冲区编号 / Index of active buffer
uint8_t * PendingBuffer()
获取备用缓冲区的指针 Returns the pending (inactive) buffer
DoubleBuffer(const LibXR::RawData &raw_data)
构造函数,使用连续内存构造两个缓冲区 Constructs a double buffer using one continuous memory block
size_t size_
单个缓冲区大小 / Size of each buffer
bool pending_valid_
标记备用区是否准备好 / Whether pending buffer is ready
void EnablePending()
手动启用 pending 状态 Manually sets the pending state to true
bool HasPending() const
判断是否有待切换的缓冲区 Checks whether a pending buffer is ready
size_t Size() const
获取每个缓冲区的大小(单位:字节) Gets the size of each buffer in bytes
size_t pending_len_
备用缓冲区有效数据长度 / Length of pending data
bool FillActive(const uint8_t *data, size_t len)
向当前使用的缓冲区直接写入数据 Fills the active buffer directly
void SetPendingLength(size_t size)
设置备用缓冲区的数据长度 Sets the size of the pending buffer
void Switch()
切换到备用缓冲区(若其有效) Switches to the pending buffer if it's valid
uint8_t * ActiveBuffer()
获取当前正在使用的缓冲区指针 Returns the currently active buffer
size_t GetPendingLength() const
获取 pending 缓冲区中准备好的数据长度 Gets the size of valid data in pending buffer
uint8_t * buffer_[2]
双缓冲区指针 / Double buffer pointers
bool FillPending(const uint8_t *data, size_t len)
向备用缓冲区写入数据(不可重入) Fills the pending buffer with data (non-reentrant)
原始数据封装类。 A class for encapsulating raw data.
LibXR 命名空间
Definition ch32_gpio.hpp:9