Skip to content

Commit 9f577d3

Browse files
committed
feature: implement copyframe
1 parent 9431900 commit 9f577d3

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

src/matrix_panel_fpga.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,49 @@ void MatrixPanel_FPGA_SPI::fillScreenRGB888(uint8_t r, uint8_t g, uint8_t b) {
495495
do_fillScreenRGB888_(r, g, b);
496496
}
497497

498+
void MatrixPanel_FPGA_SPI::do_copyFrame_() {
499+
if (!initialized) {
500+
ESP_LOGI("copyFrame()",
501+
"Tried to execute command before begin()");
502+
return;
503+
}
504+
SpiLockGuard spi_lock(this);
505+
if (!spi_lock.locked())
506+
return;
507+
if (!wait_for_fpga_resetstatus_())
508+
return;
509+
uint8_t buf[1];
510+
uint8_t buf_len = 0;
511+
512+
buf[buf_len++] = 'C'; // Command
513+
// byte
514+
515+
// Send each 8-bit
516+
// chunk
517+
spi_transaction_t t = {
518+
.length = (size_t)(8 * buf_len), // bits
519+
.tx_buffer = buf,
520+
};
521+
esp_err_t err = spi_device_transmit(spi_bus, &t);
522+
if (err != ESP_OK) {
523+
ESP_LOGE("MatrixPanel", "SPI transmit failed: %s",
524+
esp_err_to_name(err));
525+
}
526+
wait_for_fpga_busy_clear_();
527+
};
528+
529+
void MatrixPanel_FPGA_SPI::copyFrame() {
530+
if (use_worker_) {
531+
if (!tx_q_ || !tx_task_)
532+
return;
533+
Job j;
534+
j.op = Op::COPY_FRAME;
535+
(void)xQueueSend(tx_q_, &j, 0);
536+
return;
537+
}
538+
do_copyFrame_();
539+
}
540+
498541
void MatrixPanel_FPGA_SPI::do_clearScreen_() {
499542
if (!initialized) {
500543
ESP_LOGI("clearScreen()",

src/matrix_panel_fpga.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class MatrixPanel_FPGA_SPI {
6363
bool begin(const FPGA_SPI_CFG &cfg);
6464
void clearScreen();
6565

66+
void copyFrame();
6667
// rgb888 overload
6768
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t r,
6869
uint8_t g, uint8_t b);
@@ -130,6 +131,7 @@ class MatrixPanel_FPGA_SPI {
130131
};
131132

132133
void do_clearScreen_();
134+
void do_copyFrame_();
133135
void do_fillRect_(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t r,
134136
uint8_t g, uint8_t b);
135137
void do_fillScreenRGB888_(uint8_t r, uint8_t g, uint8_t b);
@@ -177,6 +179,7 @@ class MatrixPanel_FPGA_SPI {
177179
SET_BRIGHTNESS,
178180
CLEAR,
179181
DRAW_FRAME,
182+
COPY_FRAME,
180183
DRAW_PIXEL,
181184
FILL_RECT
182185
};
@@ -220,6 +223,8 @@ class MatrixPanel_FPGA_SPI {
220223
do_setBrightness8_(j.u8);
221224
else if (j.op == Op::CLEAR)
222225
do_clearScreen_();
226+
else if (j.op == Op::COPY_FRAME)
227+
do_copyFrame_();
223228
else if (j.op == Op::DRAW_FRAME)
224229
do_drawFrameRGB888_(j.data, j.length);
225230
else if (j.op == Op::DRAW_PIXEL)

0 commit comments

Comments
 (0)