Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/dmdreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,23 @@ void start_spi() { digitalWrite(SPI0_CS, HIGH); }
*/
void finish_spi() { digitalWrite(SPI0_CS, LOW); }

/**
* @brief Cleanly exit SPI by stopping the DMD pio and sending a blank dummy
* frame.
*
*/
void spi_clean_exit() {
static bool exit_executed = false;
if (spi_busy() || exit_executed) {
return;
}

pio_sm_set_enabled(dmd_pio, dmd_sm, false);
memset(framebuf1, 0, target_bytes);
memset(framebuf2, 0, target_bytes);
frame_received = exit_executed = true;
}

/**
* @brief Send a pix buffer via SPI
*
Expand Down Expand Up @@ -1544,12 +1561,14 @@ void dmdreader_spi_init() {
irq_set_enabled(DMA_IRQ_1, true);
}

bool dmdreader_spi_send() {
bool dmdreader_spi_send(bool is_restarting) {
Comment thread
PastorL69 marked this conversation as resolved.
if (!loopback && frame_received) {
frame_received = false;
spi_send_pix(framebuf_to_send, frame_crc, true);

return true;
} else if (is_restarting) {
spi_clean_exit();
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion src/dmdreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ enum DmdType : uint8_t {
bool dmdreader_init(bool return_on_no_detection = false);

void dmdreader_spi_init();
bool dmdreader_spi_send();
bool dmdreader_spi_send(bool is_restarting = false);

void dmdreader_loopback_init(uint8_t *buffer1, uint8_t *buffer2, Color color);
void dmdreader_loopback_stop();
Expand Down