Skip to content

Commit

Permalink
Change max7456 driver to only perform stall check once a second… (#9111)
Browse files Browse the repository at this point in the history
Change max7456 driver to only perform stall check once a second instead of every drawScreen call
  • Loading branch information
mikeller committed Oct 27, 2019
2 parents 887a913 + d155dc0 commit 9b2fd4c
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/main/drivers/max7456.c
Expand Up @@ -119,6 +119,7 @@
#define VIN_IS_NTSC_alt(val) (!STAT_IS_LOS(val) && !STAT_IS_PAL(val))

#define MAX7456_SIGNAL_CHECK_INTERVAL_MS 1000 // msec
#define MAX7456_STALL_CHECK_INTERVAL_MS 1000 // msec

// DMM special bits
#define CLEAR_DISPLAY 0x04
Expand Down Expand Up @@ -613,19 +614,24 @@ bool max7456BuffersSynced(void)
return true;
}

void max7456ReInitIfRequired(void)
void max7456ReInitIfRequired(bool forceStallCheck)
{
static uint32_t lastSigCheckMs = 0;
static uint32_t videoDetectTimeMs = 0;
static timeMs_t lastSigCheckMs = 0;
static timeMs_t videoDetectTimeMs = 0;
static uint16_t reInitCount = 0;

__spiBusTransactionBegin(busdev);
const uint8_t stallCheck = max7456Send(MAX7456ADD_VM0|MAX7456ADD_READ, 0x00);
__spiBusTransactionEnd(busdev);
static timeMs_t lastStallCheckMs = MAX7456_STALL_CHECK_INTERVAL_MS / 2; // offset so that it doesn't coincide with the signal check

const timeMs_t nowMs = millis();

if (stallCheck != videoSignalReg) {
bool stalled = false;
if (forceStallCheck || (lastStallCheckMs + MAX7456_STALL_CHECK_INTERVAL_MS < nowMs)) {
lastStallCheckMs = nowMs;
__spiBusTransactionBegin(busdev);
stalled = (max7456Send(MAX7456ADD_VM0|MAX7456ADD_READ, 0x00) != videoSignalReg);
__spiBusTransactionEnd(busdev);
}

if (stalled) {
max7456ReInit();
} else if ((videoSignalCfg == VIDEO_SYSTEM_AUTO)
&& ((nowMs - lastSigCheckMs) > MAX7456_SIGNAL_CHECK_INTERVAL_MS)) {
Expand Down Expand Up @@ -671,7 +677,7 @@ void max7456DrawScreen(void)

// (Re)Initialize MAX7456 at startup or stall is detected.

max7456ReInitIfRequired();
max7456ReInitIfRequired(false);

int buff_len = 0;
for (int k = 0; k < MAX_CHARS2UPDATE; k++) {
Expand Down Expand Up @@ -751,7 +757,7 @@ void max7456RefreshAll(void)
while (dmaTransactionInProgress);
#endif

max7456ReInitIfRequired();
max7456ReInitIfRequired(true);
max7456DrawScreenSlow();
}

Expand Down

0 comments on commit 9b2fd4c

Please sign in to comment.