From 932998a33cb113d7af1ab55bcadfa9986c7c20a4 Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Tue, 1 May 2018 12:02:56 -0400 Subject: [PATCH] Avoid 0xFF character when writing to MAX7456 in auto-increment mode The 0xFF character is used as an "escape" character by the MAX7456 when using auto-increment mode. The last byte of the characters used for the logo is the 0xFF character and this was causing the version and CMS instructions to not display. Changed the logic to avoid the 0xFF character during the auto-increment phase and added a second pass if needed to update those characters in direct addressing mode. --- src/main/drivers/max7456.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/main/drivers/max7456.c b/src/main/drivers/max7456.c index b3f599fb1c..cfdcd208e9 100644 --- a/src/main/drivers/max7456.c +++ b/src/main/drivers/max7456.c @@ -653,18 +653,41 @@ void max7456DrawScreen(void) static void max7456DrawScreenSlow(void) { + bool escapeCharFound; + ENABLE_MAX7456; + + // Enable auto-increment mode and update every character in the screenBuffer. + // The "escape" character 0xFF must be skipped as it causes the MAX7456 to exit auto-increment mode. max7456Send(MAX7456ADD_DMAH, 0); max7456Send(MAX7456ADD_DMAL, 0); max7456Send(MAX7456ADD_DMM, displayMemoryModeReg | 1); - for (int xx = 0; xx < maxScreenSize; ++xx) { - max7456Send(MAX7456ADD_DMDI, screenBuffer[xx]); + for (int xx = 0; xx < maxScreenSize; xx++) { + if (screenBuffer[xx] == END_STRING) { + escapeCharFound = true; + max7456Send(MAX7456ADD_DMDI, ' '); // replace the 0xFF character with a blank in the first pass to avoid terminating auto-increment + } else { + max7456Send(MAX7456ADD_DMDI, screenBuffer[xx]); + } shadowBuffer[xx] = screenBuffer[xx]; } - max7456Send(MAX7456ADD_DMDI, 0xFF); + max7456Send(MAX7456ADD_DMDI, END_STRING); max7456Send(MAX7456ADD_DMM, displayMemoryModeReg); + + // If we found any of the "escape" character 0xFF, then make a second pass + // to update them with direct addressing + if (escapeCharFound) { + for (int xx = 0; xx < maxScreenSize; xx++) { + if (screenBuffer[xx] == END_STRING) { + max7456Send(MAX7456ADD_DMAH, xx >> 8); + max7456Send(MAX7456ADD_DMAL, xx & 0xFF); + max7456Send(MAX7456ADD_DMDI, END_STRING); + } + } + } + DISABLE_MAX7456; }