mirror of
https://github.com/usetrmnl/bb_epaper.git
synced 2026-04-29 13:43:26 -07:00
Added chip type test and feature to panel tester
This commit is contained in:
@@ -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:
|
||||
|
||||
+20
-1
@@ -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)
|
||||
|
||||
+21
-11
@@ -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<<ty;
|
||||
for (int tx = 0; tx<iLen; tx++) {
|
||||
if (u8Temp[tx] & u8Mask) {
|
||||
if (iCount == 8) {
|
||||
uint8_t *s, u8Mask;
|
||||
if (iCount == 8) {
|
||||
for (int ty=0; ty<8; ty++) {
|
||||
u8Mask = 1<<ty;
|
||||
for (int tx = 0; tx<iLen; tx++) {
|
||||
if (u8Temp[tx] & u8Mask) {
|
||||
bbepSetPixel(pBBEP, x+tx, y+ty, iColor);
|
||||
} else { // stretched
|
||||
bbepSetPixel(pBBEP, x+tx*2, y+(ty*2), iColor);
|
||||
bbepSetPixel(pBBEP, 1+x+tx*2, y+(ty*2), iColor);
|
||||
bbepSetPixel(pBBEP, x+tx*2, y+1+ty*2, iColor);
|
||||
bbepSetPixel(pBBEP, 1+x+tx*2, y+1+ty*2, iColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // 16x16
|
||||
bbepStretchAndSmooth(u8Temp, u8Cache, 8, 8, 1); // smooth too
|
||||
for (int ty=0; ty<16; ty++) {
|
||||
s = &u8Cache[2*ty];
|
||||
u8Mask = 0x80;
|
||||
for (int tx = 7; tx>=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
|
||||
}
|
||||
|
||||
+6
-2
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user