15 vRingbufferDelete(this->
handle_());
22 std::unique_ptr<RingBuffer> rb = make_unique<RingBuffer>();
30 rb->storage_ = allocator.
allocate(rb->size_);
31 if (rb->storage_ ==
nullptr) {
36 if (xRingbufferCreateStatic(rb->size_, RINGBUF_TYPE_BYTEBUF, rb->storage_, &rb->structure_) != rb->handle_()) {
38 rb->storage_ =
nullptr;
41 ESP_LOGD(TAG,
"Created ring buffer with size %u",
len);
48 void *buffer_data = xRingbufferReceiveUpTo(this->
handle_(), &length, ticks_to_wait, max_length);
55 size_t bytes_read = 0;
57 void *buffer_data = xRingbufferReceiveUpTo(this->
handle_(), &bytes_read, ticks_to_wait,
len);
59 if (buffer_data ==
nullptr) {
63 std::memcpy(data, buffer_data, bytes_read);
65 vRingbufferReturnItem(this->
handle_(), buffer_data);
67 if (bytes_read <
len) {
69 size_t follow_up_bytes_read = 0;
70 size_t bytes_remaining =
len - bytes_read;
72 buffer_data = xRingbufferReceiveUpTo(this->
handle_(), &follow_up_bytes_read, 0, bytes_remaining);
74 if (buffer_data ==
nullptr) {
78 std::memcpy((
void *) ((uint8_t *) (data) + bytes_read), buffer_data, follow_up_bytes_read);
80 vRingbufferReturnItem(this->
handle_(), buffer_data);
81 bytes_read += follow_up_bytes_read;
98 if (!xRingbufferSend(this->
handle_(), data,
len, ticks_to_wait)) {
103 size_t free = std::min(this->
free(), len);
104 if (xRingbufferSend(this->
handle_(), data,
free, 0)) {
113 UBaseType_t ux_items_waiting = 0;
114 vRingbufferGetInfo(this->
handle_(),
nullptr,
nullptr,
nullptr,
nullptr, &ux_items_waiting);
115 return ux_items_waiting;
126 size_t bytes_read = 0;
128 void *buffer_data = xRingbufferReceiveUpTo(this->
handle_(), &bytes_read, 0, discard_bytes);
129 if (buffer_data !=
nullptr)
130 vRingbufferReturnItem(this->
handle_(), buffer_data);
132 if (bytes_read < discard_bytes) {
133 size_t wrapped_bytes_read = 0;
134 buffer_data = xRingbufferReceiveUpTo(this->
handle_(), &wrapped_bytes_read, 0, discard_bytes - bytes_read);
135 if (buffer_data !=
nullptr) {
136 vRingbufferReturnItem(this->
handle_(), buffer_data);
137 bytes_read += wrapped_bytes_read;
141 return (bytes_read == discard_bytes);
An STL allocator that uses SPI or internal RAM.
void deallocate(T *p, size_t n)
BaseType_t reset()
Resets the ring buffer, discarding all stored data.
size_t write(const void *data, size_t len)
Writes to the ring buffer, overwriting oldest data if necessary.
RingbufHandle_t handle_() const
size_t write_without_replacement(const void *data, size_t len, TickType_t ticks_to_wait=0, bool write_partial=true)
Writes to the ring buffer without overwriting oldest data.
size_t free() const
Returns the number of free bytes in the ring buffer.
size_t available() const
Returns the number of available bytes in the ring buffer.
bool discard_bytes_(size_t discard_bytes)
Discards data from the ring buffer.
void receive_release(void *item)
Releases a previously acquired ring buffer item.
static std::unique_ptr< RingBuffer > create(size_t len, MemoryPreference preference=MemoryPreference::EXTERNAL_FIRST)
size_t read(void *data, size_t len, TickType_t ticks_to_wait=0)
Reads from the ring buffer, waiting up to a specified number of ticks if necessary.
void * receive_acquire(size_t &length, size_t max_length, TickType_t ticks_to_wait=0)
Acquires a pointer into the ring buffer's internal storage without copying.
ESPHOME_LOG_TAG(TAG, "ring_buffer")