Skip to content

Commit e4c8ec6

Browse files
committed
feature: check resetstatus prior to writing to bus
1 parent 43c3d18 commit e4c8ec6

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

src/matrix_panel_fpga.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ void MatrixPanel_FPGA_SPI::do_swapFrame_() {
3838
}
3939
SpiLockGuard spi_lock(this);
4040
if (!spi_lock.locked())
41+
if (!wait_for_fpga_resetstatus_())
4142
return;
4243
uint8_t buf[1];
4344
uint16_t buf_len = 0;
@@ -78,6 +79,7 @@ void MatrixPanel_FPGA_SPI::do_fulfillWatchdog_() {
7879
}
7980
SpiLockGuard spi_lock(this);
8081
if (!spi_lock.locked())
82+
if (!wait_for_fpga_resetstatus_())
8183
return;
8284
uint8_t buf[9] = {'W', 0xDE, 0xAD, 0xBE, 0xEF,
8385
0xFE, 0xEB, 0xDA, 0xED}; // 'W' is
@@ -143,6 +145,22 @@ void MatrixPanel_FPGA_SPI::init_fpga_resetstatus_gpio_() {
143145
}
144146
}
145147

148+
bool MatrixPanel_FPGA_SPI::wait_for_fpga_resetstatus_() {
149+
if (!fpga_resetstatus_configured_)
150+
return true;
151+
const TickType_t start = xTaskGetTickCount();
152+
const TickType_t timeout =
153+
pdMS_TO_TICKS(m_cfg.fpga_resetstatus_timeout_ms);
154+
while (gpio_get_level((gpio_num_t)m_cfg.gpio.fpga_resetstatus) == 0) {
155+
if ((xTaskGetTickCount() - start) > timeout) {
156+
ESP_LOGW("fpga_resetstatus", "Timeout waiting for FPGA resetstatus");
157+
return false;
158+
}
159+
vTaskDelay(1);
160+
}
161+
return true;
162+
}
163+
146164
bool MatrixPanel_FPGA_SPI::consume_fpga_reset() {
147165
if (!fpga_resetstatus_configured_)
148166
return false;
@@ -203,6 +221,7 @@ void MatrixPanel_FPGA_SPI::do_drawFrameRGB888_(const uint8_t *data,
203221
}
204222
SpiLockGuard spi_lock(this);
205223
if (!spi_lock.locked())
224+
if (!wait_for_fpga_resetstatus_())
206225
return;
207226

208227
const size_t chunk_bytes =
@@ -283,6 +302,7 @@ void MatrixPanel_FPGA_SPI::do_drawRowRGB888_(const uint8_t y,
283302
}
284303
SpiLockGuard spi_lock(this);
285304
if (!spi_lock.locked())
305+
if (!wait_for_fpga_resetstatus_())
286306
return;
287307

288308
uint8_t buf[expected_row_bytes];
@@ -333,6 +353,7 @@ void MatrixPanel_FPGA_SPI::do_drawPixelRGB888_(int16_t x, int16_t y, uint8_t r,
333353
}
334354
SpiLockGuard spi_lock(this);
335355
if (!spi_lock.locked())
356+
if (!wait_for_fpga_resetstatus_())
336357
return;
337358
uint8_t buf[7];
338359
uint8_t buf_len = 0;
@@ -393,6 +414,7 @@ void MatrixPanel_FPGA_SPI::do_fillScreenRGB888_(uint8_t r, uint8_t g,
393414
}
394415
SpiLockGuard spi_lock(this);
395416
if (!spi_lock.locked())
417+
if (!wait_for_fpga_resetstatus_())
396418
return;
397419
uint8_t buf[4];
398420
uint8_t buf_len = 0;
@@ -438,6 +460,7 @@ void MatrixPanel_FPGA_SPI::do_clearScreen_() {
438460
}
439461
SpiLockGuard spi_lock(this);
440462
if (!spi_lock.locked())
463+
if (!wait_for_fpga_resetstatus_())
441464
return;
442465
uint8_t buf[1];
443466
uint8_t buf_len = 0;
@@ -478,6 +501,7 @@ void MatrixPanel_FPGA_SPI::do_setBrightness8_(const uint8_t b) {
478501
}
479502
SpiLockGuard spi_lock(this);
480503
if (!spi_lock.locked())
504+
if (!wait_for_fpga_resetstatus_())
481505
return;
482506
uint8_t buf[2];
483507
uint8_t buf_len = 0;
@@ -523,6 +547,7 @@ void MatrixPanel_FPGA_SPI::do_fillRect_(int16_t x, int16_t y, int16_t w,
523547
}
524548
SpiLockGuard spi_lock(this);
525549
if (!spi_lock.locked())
550+
if (!wait_for_fpga_resetstatus_())
526551
return;
527552
uint8_t buf[10];
528553
uint8_t buf_len = 0;

src/matrix_panel_fpga.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class MatrixPanel_FPGA_SPI {
136136
void do_fulfillWatchdog_();
137137
void do_setBrightness8_(const uint8_t b);
138138
void init_fpga_resetstatus_gpio_();
139+
bool wait_for_fpga_resetstatus_();
139140
static void fpga_resetstatus_isr_(void *arg);
140141
// Matrix i2s settings
141142
FPGA_SPI_CFG m_cfg;

src/matrix_panel_fpga_config.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,21 @@ struct FPGA_SPI_CFG {
9696
// to get all colour depths displayed with correct BCM time weighting.
9797
uint8_t min_refresh_rate;
9898

99+
// FPGA status timeouts (milliseconds)
100+
uint16_t fpga_resetstatus_timeout_ms;
101+
99102
// struct constructor
100103
FPGA_SPI_CFG(
101104
uint16_t _w = MATRIX_WIDTH, uint16_t _h = MATRIX_HEIGHT,
102105
uint16_t _chain = CHAIN_LENGTH,
103106
spi_pins _pinmap = {SPI_CE_PIN_DEFAULT, SPI_CLK_PIN_DEFAULT,
104107
SPI_MOSI_PIN_DEFAULT, FPGA_RESETSTATUS_PIN_DEFAULT},
105108
clk_speed _spispeed = HZ_8M, uint16_t _min_refresh_rate = 60,
106-
uint8_t _pixel_color_depth_bits = PIXEL_COLOR_DEPTH_BITS_DEFAULT)
109+
uint8_t _pixel_color_depth_bits = PIXEL_COLOR_DEPTH_BITS_DEFAULT,
110+
uint16_t _fpga_resetstatus_timeout_ms = 1000)
107111
: mx_width(_w), mx_height(_h), chain_length(_chain), gpio(_pinmap),
108-
spispeed(_spispeed), min_refresh_rate(_min_refresh_rate) {
112+
spispeed(_spispeed), min_refresh_rate(_min_refresh_rate),
113+
fpga_resetstatus_timeout_ms(_fpga_resetstatus_timeout_ms) {
109114
setPixelColorDepthBits(_pixel_color_depth_bits);
110115
}
111116

0 commit comments

Comments
 (0)