12 static const char *
const TAG =
"ring_buffer";
16 vStreamBufferDelete(this->
handle_);
23 std::unique_ptr<RingBuffer> rb = make_unique<RingBuffer>();
28 rb->storage_ = allocator.
allocate(rb->size_);
29 if (rb->storage_ ==
nullptr) {
33 rb->handle_ = xStreamBufferCreateStatic(rb->size_, 1, rb->storage_, &rb->structure_);
34 ESP_LOGD(TAG,
"Created ring buffer with size %u", len);
39 if (ticks_to_wait > 0)
40 xStreamBufferSetTriggerLevel(this->
handle_, len);
42 size_t bytes_read = xStreamBufferReceive(this->
handle_, data, len, ticks_to_wait);
44 xStreamBufferSetTriggerLevel(this->
handle_, 1);
52 size_t needed = len -
free;
53 uint8_t discard[needed];
54 xStreamBufferReceive(this->
handle_, discard, needed, 0);
56 return xStreamBufferSend(this->
handle_, data, len, 0);
60 return xStreamBufferSend(this->
handle_, data, len, ticks_to_wait);
size_t free() const
Returns the number of free bytes in the ring buffer.
size_t write_without_replacement(const void *data, size_t len, TickType_t ticks_to_wait=0)
Writes to the ring buffer without overwriting oldest data.
BaseType_t reset()
Resets the ring buffer, discarding all stored data.
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.
size_t available() const
Returns the number of available bytes in the ring buffer.
void deallocate(T *p, size_t n)
Implementation of SPI Controller mode.
size_t write(const void *data, size_t len)
Writes to the ring buffer, overwriting oldest data if necessary.
An STL allocator that uses SPI or internal RAM.
static std::unique_ptr< RingBuffer > create(size_t len)
StreamBufferHandle_t handle_