roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
spi_reg.h
Go to the documentation of this file.
1#pragma once
2
3#include "roo_backport.h"
4#include "roo_backport/byte.h"
6#include "roo_io/data/byte_order.h"
7#include "soc/spi_reg.h"
8
9#if CONFIG_IDF_TARGET_ESP32
10#define ROO_DISPLAY_ESP32_SPI_DEFAULT_PORT 3
11#else
12#define ROO_DISPLAY_ESP32_SPI_DEFAULT_PORT 2
13#ifndef SPI_MOSI_DLEN_REG
14#define SPI_MOSI_DLEN_REG(x) SPI_MS_DLEN_REG(x)
15#endif
16#ifndef SPI_MISO_DLEN_REG
17#define SPI_MISO_DLEN_REG(x) SPI_MS_DLEN_REG(x)
18#endif
19#endif
20
21#if !defined(CONFIG_IDF_TARGET_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32S2)
22#define ROO_DISPLAY_SPI_CMD_UPDATE_REQUIRED 1
23#else
24#define ROO_DISPLAY_SPI_CMD_UPDATE_REQUIRED 0
25#endif
26
27#ifndef SPI_DMA_TX_ENA
28#ifdef SPI_DMA_TX_EN
29#define SPI_DMA_TX_ENA SPI_DMA_TX_EN
30#endif
31#endif
32
33#ifndef SPI_TRANS_DONE_INT_ENA
34#ifdef SPI_OUT_EOF_INT_ENA
35#define SPI_TRANS_DONE_INT_ENA SPI_OUT_EOF_INT_ENA
36#elif defined(SPI_OUT_DONE_INT_ENA)
37#define SPI_TRANS_DONE_INT_ENA SPI_OUT_DONE_INT_ENA
38#endif
39#endif
40
41#ifndef SPI_TRANS_DONE_INT_CLR
42#ifdef SPI_OUT_EOF_INT_CLR
43#define SPI_TRANS_DONE_INT_CLR SPI_OUT_EOF_INT_CLR
44#elif defined(SPI_OUT_DONE_INT_CLR)
45#define SPI_TRANS_DONE_INT_CLR SPI_OUT_DONE_INT_CLR
46#endif
47#endif
48
49#ifndef SPI_TRANS_DONE_INT_ST
50#ifdef SPI_OUT_EOF_INT_ST
51#define SPI_TRANS_DONE_INT_ST SPI_OUT_EOF_INT_ST
52#elif defined(SPI_OUT_DONE_INT_ST)
53#define SPI_TRANS_DONE_INT_ST SPI_OUT_DONE_INT_ST
54#endif
55#endif
56
57#ifndef ROO_TESTING
58
59namespace roo_display {
60namespace esp32 {
61
62// Enters the read-write mode.
63inline void SpiSetReadWriteMode(uint8_t spi_port)
64 __attribute__((always_inline));
65
66// Enters the write-only mode.
67inline void SpiSetWriteOnlyMode(uint8_t spi_port)
68 __attribute__((always_inline));
69
70// Initiates a polling (non-ISR) SPI operation.
71inline void SpiTxStart(uint8_t spi_port) __attribute__((always_inline));
72
73// Waits for the current SPI operation, if any, to complete.
74inline void SpiTxWait(uint8_t spi_port) __attribute__((always_inline));
75
76// Returns true when the SPI DMA transfer-done interrupt is pending.
77inline bool SpiDmaTransferDoneIntPending(uint8_t spi_port)
78 __attribute__((always_inline));
79
80// Clears the SPI DMA transfer-done interrupt.
81inline void SpiDmaTransferDoneIntClear(uint8_t spi_port)
82 __attribute__((always_inline));
83
84// Enables the SPI DMA transfer-done interrupt.
85inline void SpiDmaTransferDoneIntEnable(uint8_t spi_port)
86 __attribute__((always_inline));
87
88// Disables the SPI DMA transfer-done interrupt.
89inline void SpiDmaTransferDoneIntDisable(uint8_t spi_port)
90 __attribute__((always_inline));
91
92// Enables SPI DMA TX.
93inline void SpiDmaTxEnable(uint8_t spi_port)
94 __attribute__((always_inline));
95
96// Disables SPI DMA TX.
97inline void SpiDmaTxDisable(uint8_t spi_port)
98 __attribute__((always_inline));
99
100// Sets the number of bytes in the output buffer for the next SPI operation.
101inline void SpiSetOutBufferSize(uint8_t spi_port, int len)
102 __attribute__((always_inline));
103
104// Sets the number of bytes in the output and input buffers for the next SPI
105// operation.
106inline void SpiSetTxBufferSize(uint8_t spi_port, int len)
107 __attribute__((always_inline));
108
109// Writes 4 bytes to the output registers from the provided uint32 value
110// (assumed byte-swapped to big-endian).
111inline void SpiWrite4(uint8_t spi_port, uint32_t d32)
112 __attribute__((always_inline));
113
114// Reads 4 bytes from the output registers.
115inline uint32_t SpiRead4(uint8_t spi_port) __attribute__((always_inline));
116
117// Writes 64 bytes to the output registers from the 32-bit aligned input buffer.
118inline void SpiWrite64Aligned(uint8_t spi_port, const roo::byte* data)
119 __attribute__((always_inline));
120
121// Writes up to 64 bytes to the output registers, from the 32-bit aligned
122// buffer.
123inline void SpiWriteUpTo64Aligned(uint8_t spi_port, const roo::byte* data,
124 int len) __attribute__((always_inline));
125
126// Fills 64 bytes of the output registers with the specified 32-bit value.
127inline void SpiFill64(uint8_t spi_port, uint32_t d32)
128 __attribute__((always_inline));
129
130// Fills output registers with 1-64 bytes, provided in the 32-bit aligned
131// buffer.
132inline void SpiFillUpTo64(uint8_t spi_port, uint32_t d32, int len)
133 __attribute__((always_inline));
134
135// Fills output registers with up to 60 bytes, repeating the specified 12-byte
136// pattern.
137inline void SpiFill60(uint8_t spi_port, uint32_t d0, uint32_t d1, uint32_t d2)
138 __attribute__((always_inline));
139
140// Fills output registers with 60 bytes, 5x repeating the specified 12-byte
141// pattern.
142inline void SpiFillUpTo60(uint8_t spi_port, uint32_t d0, uint32_t d1,
143 uint32_t d2, int len) __attribute__((always_inline));
144
145// Implementation below.
146
149 }
150}
151
156
160
164
168
172
176
178#if ROO_DISPLAY_SPI_CMD_UPDATE_REQUIRED
181 }
182#endif
183
184 // SET_PERI_REG_MASK(SPI_CMD_REG(spi_port), SPI_USR);
185 // The 'correct' way to set the SPI_USR would be to set just the single bit,
186 // as in the commented-out code above. But the remaining bits of this register
187 // are unused (marked 'reserved'; see
188 // https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf
189 // page 131). Unconditionally setting the entire register brings significant
190 // performance improvements.
192}
193
197
200#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32
202#endif
203}
204
209
213
233
237
241
242inline void SpiWriteUpTo64Aligned(uint8_t spi_port, const roo::byte* data,
243 int len) {
244 const uint32_t* d32 = reinterpret_cast<const uint32_t*>(data);
245 do {
247 if (len <= 4) break;
249 if (len <= 8) break;
251 if (len <= 12) break;
253 if (len <= 16) break;
255 if (len <= 20) break;
257 if (len <= 24) break;
259 if (len <= 28) break;
261 if (len <= 32) break;
263 if (len <= 36) break;
265 if (len <= 40) break;
267 if (len <= 44) break;
269 if (len <= 48) break;
271 if (len <= 52) break;
273 if (len <= 56) break;
275 if (len <= 60) break;
277 } while (false);
278}
279
298
300 do {
302 if (len <= 4) break;
304 if (len <= 8) break;
306 if (len <= 12) break;
308 if (len <= 16) break;
310 if (len <= 20) break;
312 if (len <= 24) break;
314 if (len <= 28) break;
316 if (len <= 32) break;
318 if (len <= 36) break;
320 if (len <= 40) break;
322 if (len <= 44) break;
324 if (len <= 48) break;
326 if (len <= 52) break;
328 if (len <= 56) break;
330 if (len <= 60) break;
332 } while (false);
333}
334
352
354 uint32_t d2, int len) {
355 do {
357 if (len <= 4) break;
359 if (len <= 8) break;
361 if (len <= 12) break;
363 if (len <= 16) break;
365 if (len <= 20) break;
367 if (len <= 24) break;
369 if (len <= 28) break;
371 if (len <= 32) break;
373 if (len <= 36) break;
375 if (len <= 40) break;
377 if (len <= 44) break;
379 if (len <= 48) break;
381 if (len <= 52) break;
383 if (len <= 56) break;
385 } while (false);
386}
387
388} // namespace esp32
389} // namespace roo_display
390
391#endif // ROO_TESTING
void SpiSetWriteOnlyMode(uint8_t spi_port) __attribute__((always_inline))
Definition spi_reg.h:210
void SpiFill60(uint8_t spi_port, uint32_t d0, uint32_t d1, uint32_t d2) __attribute__((always_inline))
Definition spi_reg.h:335
void SpiDmaTransferDoneIntDisable(uint8_t spi_port) __attribute__((always_inline))
Definition spi_reg.h:165
void SpiFill64(uint8_t spi_port, uint32_t d32) __attribute__((always_inline))
Definition spi_reg.h:280
void SpiDmaTransferDoneIntClear(uint8_t spi_port) __attribute__((always_inline))
Definition spi_reg.h:157
void SpiWriteUpTo64Aligned(uint8_t spi_port, const roo::byte *data, int len) __attribute__((always_inline))
Definition spi_reg.h:242
void SpiDmaTxDisable(uint8_t spi_port) __attribute__((always_inline))
Definition spi_reg.h:173
void SpiTxWait(uint8_t spi_port) __attribute__((always_inline))
Definition spi_reg.h:147
void SpiSetOutBufferSize(uint8_t spi_port, int len) __attribute__((always_inline))
Definition spi_reg.h:194
void SpiTxStart(uint8_t spi_port) __attribute__((always_inline))
Definition spi_reg.h:177
void SpiDmaTransferDoneIntEnable(uint8_t spi_port) __attribute__((always_inline))
Definition spi_reg.h:161
void SpiWrite4(uint8_t spi_port, uint32_t d32) __attribute__((always_inline))
Definition spi_reg.h:234
uint32_t SpiRead4(uint8_t spi_port) __attribute__((always_inline))
Definition spi_reg.h:238
void SpiSetTxBufferSize(uint8_t spi_port, int len) __attribute__((always_inline))
Definition spi_reg.h:198
bool SpiDmaTransferDoneIntPending(uint8_t spi_port) __attribute__((always_inline))
Definition spi_reg.h:152
void SpiSetReadWriteMode(uint8_t spi_port) __attribute__((always_inline))
Definition spi_reg.h:205
void SpiWrite64Aligned(uint8_t spi_port, const roo::byte *data) __attribute__((always_inline))
Definition spi_reg.h:214
void SpiDmaTxEnable(uint8_t spi_port) __attribute__((always_inline))
Definition spi_reg.h:169
void SpiFillUpTo60(uint8_t spi_port, uint32_t d0, uint32_t d1, uint32_t d2, int len) __attribute__((always_inline))
Definition spi_reg.h:353
void SpiFillUpTo64(uint8_t spi_port, uint32_t d32, int len) __attribute__((always_inline))
Definition spi_reg.h:299
Defines 140 opaque HTML named colors.
#define SPI_MISO_DLEN_REG(x)
Definition spi_reg.h:17
#define SPI_MOSI_DLEN_REG(x)
Definition spi_reg.h:14