roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
dma_buffer_pool.h
Go to the documentation of this file.
1#pragma once
2
3#include "freertos/FreeRTOS.h"
4#include "freertos/semphr.h"
5#include "roo_backport.h"
6#include "roo_backport/byte.h"
7
8#ifndef ROO_DISPLAY_ESP32_DMA_BUFFER_CAPACITY
9#define ROO_DISPLAY_ESP32_DMA_BUFFER_CAPACITY 1024
10#endif
11
12#ifndef ROO_DISPLAY_ESP32_DMA_BUFFER_COUNT
13#define ROO_DISPLAY_ESP32_DMA_BUFFER_COUNT 4
14#endif
15
16namespace roo_display {
17namespace esp32 {
18
19static constexpr size_t kDmaBufferCapacity =
21
23
24// Assumes a single producer (the SPI transaction code), acquiring the buffers,
25// and a single consumer (the SPI ISR), releasing the buffers. The producer can
26// get blocked if all buffers are in use.
28 public:
29 struct Buffer {
30 roo::byte* data;
31 };
32
34
35 // Allocates buffer data, in a contiguous block of DMA-capable DRAM.
36 void begin();
37
38 // Deallocates the buffer data.
39 void end();
40
41 // Returns a pointer to a buffer to write to. If no buffer is currently
42 // available, the caller task gets blocked until one becomes available.
44
45 // Marks the buffer as available for reuse. The buffer must have been
46 // previously returned by acquire() and not yet released.
47 void release(Buffer buffer);
48
49 size_t pool_capacity() const { return kDmaBufferCount; }
50 size_t buffer_size() const { return kDmaBufferCapacity; }
51
52 private:
53 void lockState();
54 void unlockState();
55 size_t acquireFreeSlot();
56 bool markSlotFree(size_t index);
57
58 roo::byte* buffer_data_;
59 StaticSemaphore_t available_storage_;
60 SemaphoreHandle_t available_;
61 bool in_use_[kDmaBufferCount];
62 portMUX_TYPE mux_;
63};
64
65} // namespace esp32
66} // namespace roo_display
#define ROO_DISPLAY_ESP32_DMA_BUFFER_CAPACITY
#define ROO_DISPLAY_ESP32_DMA_BUFFER_COUNT
static constexpr size_t kDmaBufferCount
static constexpr size_t kDmaBufferCapacity
Defines 140 opaque HTML named colors.