diff options
author | David Crocker <dcrocker@eschertech.com> | 2020-07-18 01:03:54 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2020-07-18 01:03:54 +0300 |
commit | e07c897def24151d5beb2dc9dbeae11812a64a7f (patch) | |
tree | f28ce5c3ccfb2c6b339cbe273f04bba9fcdde151 /src/Display | |
parent | 8df4bc3aff7e299bef1854952c987bfb75891957 (diff) |
Fixed for ST7567 display
Diffstat (limited to 'src/Display')
-rw-r--r-- | src/Display/Lcd/ST7567/Lcd7567.cpp | 102 | ||||
-rw-r--r-- | src/Display/Lcd/ST7567/Lcd7567.h | 31 |
2 files changed, 93 insertions, 40 deletions
diff --git a/src/Display/Lcd/ST7567/Lcd7567.cpp b/src/Display/Lcd/ST7567/Lcd7567.cpp index 973080e5..07810116 100644 --- a/src/Display/Lcd/ST7567/Lcd7567.cpp +++ b/src/Display/Lcd/ST7567/Lcd7567.cpp @@ -33,37 +33,62 @@ void Lcd7567::HardwareInit() noexcept device.Select(); delayMicroseconds(1); - // 11100010 System reset - SendByte(SystemReset); +#if 0 + + SendByte(SetBias7); // LCD bias select + SendByte(SetAdcNormal); // ADC select + SendByte(SetComNormal); // SHL select + SendByte(SetDisplayStartLine); // Initial display line + SendByte(SetPowerControl | 0x4); // turn on voltage converter (VC=1, VR=0, VF=0) + delay(50); // wait for 50% rising + + SendByte(SetPowerControl | 0x6); // turn on voltage regulator (VC=1, VR=1, VF=0) + delay(50); // wait >=50ms + + SendByte(SetPowerControl | 0x7); // turn on voltage follower (VC=1, VR=1, VF=1) + delay(10); // wait + + SendByte(SetResistorRatio | 0x6); // set lcd operating voltage (regulator resistor, ref voltage resistor) + +#elif 0 + + SendByte(SetDisplayStartLine); // set display start line + SendByte(SetAdcReverse); // ADC set to reverse + SendByte(SetComNormal); // common output mode: set scan direction normal operation + SendByte(SetDisplayNormal); // display normal (none reverse) + SendByte(SetBias9); // LCD bias 1/9 + SendByte(SetPowerControl | 0x7); // all power control circuits on + SendByte(SetBoosterFirst); // set booster ratio to + SendByte(0x00); // 4x + SendByte(SetResistorRatio | 0x07); // set V0 voltage resistor ratio to large + SendByte(SetVolumeFirst); // set contrast + SendByte(0x018); // contrast value, EA default: 0x016 + SendByte(SetStaticOff); // indicator + SendByte(0x00); // disable + SendByte(PixelOff); // normal display (not all on) + SendByte(DisplayOn); // display on + delay(50); // delay 50 ms + +#else + SendByte(SystemReset); // 11100010 System reset SendByte(DisplayOff); - // 01000000 Set scroll line to 0 (6-bit value) - SendByte(0x40); - // 10100000 Set SEG (column) direction to MX (mirror = 0) - SendByte(0xA0); - // 11001000 Set COM (row) direction not to MY (mirror = 0) - SendByte(0xC8); - // 10100110 Set inverse display to false - SendByte(0xA6); - // 10100010 Set LCD bias ratio BR=0 (1/9th at 1/65 duty) - SendByte(0xA2); - // 00101111 Set power control to enable XV0, V0 and VG charge pumps - SendByte(0x2F); - // 11111000 Set booster ratio (2-byte command) to 4x - SendByte(0xF8); + SendByte(SetDisplayStartLine); // 01000000 Set scroll line to 0 (6-bit value) + SendByte(SetAdcNormal); // 10100000 Set SEG (column) direction to MX (mirror = 0) + SendByte(SetComReverse); // 11001000 Set COM (row) direction not to MY (mirror = 0) + SendByte(SetDisplayNormal); // 10100110 Set inverse display to false + SendByte(SetBias9); // 10100010 Set LCD bias ratio BR=0 (1/9th at 1/65 duty) + SendByte(SetPowerControl | 0x07); // 00101111 Set power control to enable XV0, V0 and VG charge pumps + SendByte(SetBoosterFirst); // 11111000 Set booster ratio (2-byte command) to 4x SendByte(0x00); - // 00100011 Set Vlcd resistor ratio 1+Rb/Ra to 6.5 for the voltage regulator (contrast) - SendByte(0x23); - // 10000001 Set electronic volume (2-byte command) 6-bit contrast value - SendByte(0x81); - SendByte(0x27); - // 10101100 Set static indicator off - SendByte(0xAC); + SendByte(SetResistorRatio | 0x06); // 00100011 Set Vlcd resistor ratio 1+Rb/Ra to 6.5 for the voltage regulator (contrast) + SendByte(SetVolumeFirst); // 10000001 Set electronic volume (2-byte command) 6-bit contrast value + SendByte(0x18); + SendByte(SetStaticOff); // 10101100 Set static indicator off +#if 0 // Enter sleep mode - // 10101110 Set display enable to off - SendByte(DisplayOff); - // 10100101 Set all pixel on - SendByte(PixelOn); + SendByte(DisplayOff); // 10101110 Set display enable to off + SendByte(PixelOn); // 10100101 Set all pixel on delayMicroseconds(1); device.Deselect(); @@ -73,12 +98,13 @@ void Lcd7567::HardwareInit() noexcept device.Select(); delayMicroseconds(1); +#endif // Enable display - // 10100100 Set all pixel off - SendByte(PixelOff); - // 10101111 Set display enable to on - SendByte(DisplayOn); + SendByte(PixelOff); // 10100100 Set all pixel off + SendByte(DisplayOn); // 10101111 Set display enable to on + +#endif delayMicroseconds(1); device.Deselect(); @@ -91,14 +117,10 @@ bool Lcd7567::FlushSome() noexcept if (endCol > startCol && endRow > startRow) { // Decide which row to flush next - if (nextFlushRow < startRow || nextFlushRow >= endRow) - { - nextFlushRow = startRow & ~(TILE_HEIGHT - 1); // start from the beginning, rounding down to the top of a tile - } - - if (nextFlushRow == startRow) // if we are starting from the beginning + if (nextFlushRow <= startRow || nextFlushRow >= endRow) { - startRow += TILE_HEIGHT; // flag this row as flushed because it will be soon + nextFlushRow = startRow & ~(TILE_HEIGHT - 1); // start from the beginning + startRow = nextFlushRow + TILE_HEIGHT; // flag this row as flushed because it will be soon } // Flush that row (which is 8 pixels high) @@ -116,7 +138,7 @@ bool Lcd7567::FlushSome() noexcept // Gather the bits for a vertical line of 8 pixels (LSB is the top pixel) for (uint8_t i = 0; i < 8; i++) { - if (ReadPixel(x, startRow + i)) + if (ReadPixel(x, nextFlushRow + i)) { data |= (1u << i); } @@ -130,7 +152,7 @@ bool Lcd7567::FlushSome() noexcept device.Deselect(); // Check if there is still area to flush - if (startRow != endRow) + if (startRow < endRow) { nextFlushRow += TILE_HEIGHT; return true; diff --git a/src/Display/Lcd/ST7567/Lcd7567.h b/src/Display/Lcd/ST7567/Lcd7567.h index 780658aa..085d22e8 100644 --- a/src/Display/Lcd/ST7567/Lcd7567.h +++ b/src/Display/Lcd/ST7567/Lcd7567.h @@ -56,6 +56,37 @@ private: constexpr static uint8_t PixelOff = 0xA4; // 10100100 Set all pixel off constexpr static uint8_t PixelOn = 0xA5; // 10100101 Set all pixel on + constexpr static uint8_t SetDisplayStartLine = 0x40; + constexpr static uint8_t SetPage = 0xB0; + + constexpr static uint8_t SetColumnUpper = 0x10; + constexpr static uint8_t SetColumnLower = 0x00; + + constexpr static uint8_t SetAdcNormal = 0xA0; + constexpr static uint8_t SetAdcReverse = 0xA1; + + constexpr static uint8_t SetDisplayNormal = 0xA6; + constexpr static uint8_t SetDisplayreverse = 0xA7; + + constexpr static uint8_t SetBias9 = 0xA2; + constexpr static uint8_t SetBias7 = 0xA3; + + constexpr static uint8_t Rmw = 0xE0; + constexpr static uint8_t RmwClear = 0xEE; + constexpr static uint8_t SetComNormal = 0xC0; + constexpr static uint8_t SetComReverse = 0xC8; + constexpr static uint8_t SetPowerControl = 0x28; + constexpr static uint8_t SetResistorRatio = 0x20; + constexpr static uint8_t SetVolumeFirst = 0x81; + constexpr static uint8_t SetStaticOff = 0xAC; + constexpr static uint8_t SetStaticOn = 0xAD; + constexpr static uint8_t SetBoosterFirst = 0xF8; + constexpr static uint8_t SetBooster234 = 0; + constexpr static uint8_t SetBooster5 = 1; + constexpr static uint8_t SetBooster6 = 3; + constexpr static uint8_t Nop = 0xE3; + constexpr static uint8_t Test = 0xF0; + constexpr static unsigned int CommandDelayMicros = 72 - 8; // 72us required, less 7us time to send the command @ 2.0MHz constexpr static unsigned int DataDelayMicros = 4; // delay between sending data bytes constexpr static unsigned int FlushRowDelayMicros = 20; // Delay between sending each rows when flushing all rows @ 2.0MHz (@ 1.0MHz this is not necessary) |