From e9caddd720a150beb3b56ffe0b3ef7e5ed7fd123 Mon Sep 17 00:00:00 2001 From: Laurence Bank Date: Thu, 14 Nov 2024 10:52:17 +0000 Subject: [PATCH] Added chip type test and feature to panel tester --- .../epd_panel_tester/epd_panel_tester.ino | 57 ++++++++++++++----- src/bb_ep.inl | 21 ++++++- src/bb_ep_gfx.inl | 32 +++++++---- src/bb_epaper.cpp | 8 ++- src/bb_epaper.h | 1 + 5 files changed, 91 insertions(+), 28 deletions(-) diff --git a/examples/epd_panel_tester/epd_panel_tester.ino b/examples/epd_panel_tester/epd_panel_tester.ino index 3884557..174010d 100644 --- a/examples/epd_panel_tester/epd_panel_tester.ino +++ b/examples/epd_panel_tester/epd_panel_tester.ino @@ -95,7 +95,26 @@ enum { // 2 = Black/White, 3 = Black/White/Red const uint8_t u8PanelColors[] = {2,2,2,2,2,2,2,2,2,2,3,2,3,3,3,2,2,2,2,3,2,2,4,4,4}; -void epdBegin() +void WaitForButton(void) +{ + oled.setFont(FONT_6x8); + oled.setCursor(0,56); + oled.println("(Any button to exit)"); + // wait for button release + while (digitalRead(BUTTON1) == 0 || digitalRead(BUTTON2) == 0) { + delay(10); + } + // wait for button press + while (digitalRead(BUTTON1) == 1 && digitalRead(BUTTON2) == 1) { + delay(10); + } + // wait for button release + while (digitalRead(BUTTON1) == 0 || digitalRead(BUTTON2) == 0) { + delay(10); + } +} /* WaitForButton() */ + +int epdBegin() { if (POWER_PIN != -1) { pinMode(POWER_PIN, OUTPUT); @@ -103,6 +122,19 @@ void epdBegin() delay(100); // allow time to settle } epd.initIO(DC_PIN, RESET_PIN, BUSY_PIN, CS_PIN, MOSI_PIN, CLK_PIN); + // Don't let the user choose the wrong controller type + // this can damage some panels because some commands overlap and set the wrong + // power settings + if (epd.testPanelType() != epd.getChip()) { + oled.fillScreen(OBD_WHITE); + oled.setFont(FONT_12x16); + oled.println("Panel does"); + oled.println("not match"); + oled.println("chip type!"); + WaitForButton(); + return 0; + } + return 1; } /* epdBegin() */ // Display info about the currently selected panel @@ -174,7 +206,6 @@ void EPDTest(int iMode) iDataTime = iOpTime = 0; return; } - epdBegin(); if (epd.width() < epd.height()) { epd.setRotation(90); } @@ -199,7 +230,6 @@ void EPDTest(int iMode) epd.fillScreen(BBEP_WHITE); epd.refresh(REFRESH_FULL, true); } else { // slow/fast - epdBegin(); if (epd.width() < epd.height()) { epd.setRotation(90); } @@ -262,7 +292,6 @@ void EPDClear(void) oled.setFont(FONT_12x16); oled.println("Clear EPD"); oled.println("Starting..."); - epdBegin(); if (epd.width() < epd.height() || !epd.getBuffer()) { epd.setRotation(90); } @@ -287,23 +316,19 @@ void ShowTime(void) oled.print((int)iOpTime, DEC); oled.println(" ms"); } - oled.setFont(FONT_6x8); - oled.setCursor(0,56); - oled.println("(Any button to exit)"); - while (digitalRead(BUTTON1) == 1 && digitalRead(BUTTON2) == 1) { - delay(10); - } - // wait for button release - while (digitalRead(BUTTON1) == 0 || digitalRead(BUTTON2) == 0) { - delay(10); - } + WaitForButton(); } /* ShowTime() */ void setup() { +// Serial.begin(115200); +// delay(3000); +// Serial.println("Starting..."); oled.I2Cbegin(); oled.fillScreen(OBD_WHITE); pinMode(BUTTON1, INPUT_PULLUP); pinMode(BUTTON2, INPUT_PULLUP); + epd.setPanelType(1); // set to first panel type to start + // Serial.begin(115200); // delay(3000); // Serial.println("EPD BLE Tester"); @@ -350,6 +375,10 @@ void loop() { } else { // start the operation iTime = millis(); + if (!epdBegin()) { + ShowInfo(true); + continue; // something went wrong + } switch (iMode) { case MODE_FULL_NO_RAM: // full refresh EPD test without using the back buffer case MODE_FULL_RAM: diff --git a/src/bb_ep.inl b/src/bb_ep.inl index dcb4810..bd3608b 100644 --- a/src/bb_ep.inl +++ b/src/bb_ep.inl @@ -1212,12 +1212,15 @@ int bbepCreateVirtual(BBEPDISP *pBBEP, int iWidth, int iHeight, int iFlags) // void bbepWaitBusy(BBEPDISP *pBBEP) { + int iTimeout = 0; + if (!pBBEP) return; if (pBBEP->iBUSYPin == 0xff) return; uint8_t busy_idle = (pBBEP->chip_type == BBEP_CHIP_UC81xx) ? HIGH : LOW; delay(1); // some panels need a short delay before testing the BUSY line - while (1) { + while (iTimeout < 5000) { if (digitalRead(pBBEP->iBUSYPin) == busy_idle) break; + delay(1); } } /* bbepWaitBusy() */ // @@ -1367,6 +1370,22 @@ void bbepSendCMDSequence(BBEPDISP *pBBEP, const uint8_t *pSeq) } // while more commands to send } /* bbepSendCMDSequence() */ +// +// Tests the BUSY line to see if you're connected to a +// SSD16xx or UC81xx panel +// +int bbepTestPanelType(BBEPDISP *pBBEP) +{ + if (!pBBEP) return BBEP_CHIP_NOT_DEFINED; + digitalWrite(pBBEP->iRSTPin, LOW); + delay(40); + digitalWrite(pBBEP->iRSTPin, HIGH); + delay(50); + if (digitalRead(pBBEP->iBUSYPin)) + return BBEP_CHIP_UC81xx; // high state = UltraChip ready + else + return BBEP_CHIP_SSD16xx; // low state = Solomon ready +} /* bbepTestPanelType() */ // // Fill the display with a color or byte pattern // e.g. all black (0x00) or all white (0xff) diff --git a/src/bb_ep_gfx.inl b/src/bb_ep_gfx.inl index 5615267..faeba93 100644 --- a/src/bb_ep_gfx.inl +++ b/src/bb_ep_gfx.inl @@ -987,21 +987,31 @@ int bbepWriteString(BBEPDISP *pBBEP, int x, int y, char *szMsg, int iSize, int i } // stretched 2x } else { // draw in memory #ifndef NO_RAM - uint8_t u8Mask; - for (int ty=0; ty<8; ty++) { - u8Mask = 1<=0; tx--) { + if (s[0] & u8Mask) { + bbepSetPixel(pBBEP, x+ty, y+tx+8, iColor); + } + if (s[1] & u8Mask) { + bbepSetPixel(pBBEP, x+ty, y+tx, iColor); + } + u8Mask >>= 1; + } + } } #endif } diff --git a/src/bb_epaper.cpp b/src/bb_epaper.cpp index c367a95..724cba7 100644 --- a/src/bb_epaper.cpp +++ b/src/bb_epaper.cpp @@ -70,8 +70,8 @@ int BBEPAPER::setPanelType(int iPanel) void BBEPAPER::initIO(int iDC, int iReset, int iBusy, int iCS, int iMOSI, int iSCLK, uint32_t u32Speed) { bbepInitIO(&_bbep, iDC, iReset, iBusy, iCS, iMOSI, iSCLK, u32Speed); - bbepWakeUp(&_bbep); - bbepSendCMDSequence(&_bbep, _bbep.pInitFull); +// bbepWakeUp(&_bbep); +// bbepSendCMDSequence(&_bbep, _bbep.pInitFull); } /* initIO() */ #else // Linux void BBEPAPER::initIO(int iDC, int iReset, int iBusy, int iCS, int iSPIChannel, uint32_t u32Speed) @@ -480,6 +480,10 @@ void BBEPAPER::fillEllipse(int16_t x, int16_t y, int32_t rx, int32_t ry, uint16_ bbepEllipse(&_bbep, x, y, rx, ry, 0xf, color, 1); } +int BBEPAPER::testPanelType(void) +{ + return bbepTestPanelType(&_bbep); +} void BBEPAPER::sleep(int bDeep) { bbepSleep(&_bbep, bDeep); diff --git a/src/bb_epaper.h b/src/bb_epaper.h index c10a69a..9d942c8 100644 --- a/src/bb_epaper.h +++ b/src/bb_epaper.h @@ -335,6 +335,7 @@ class BBEPAPER void drawPixel(int16_t x, int16_t y, uint8_t color); int16_t getCursorX(void); int16_t getCursorY(void); + int testPanelType(void); void getTextBounds(const char *string, int16_t x, int16_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h); #ifdef ARDUINO void getTextBounds(const String &str, int16_t x, int16_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);