Skip to content

Commit 307e529

Browse files
committed
Added show_jpeg example and improved epd row control
1 parent 698edbb commit 307e529

File tree

7 files changed

+4880
-25
lines changed

7 files changed

+4880
-25
lines changed

examples/Linux/compressed_images/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ int main(int argc, char *argv[])
1313
// This configuration for this PCB contians info about the Eink connections and display type
1414
epaper.initPanel(BB_PANEL_RPI);
1515
epaper.setPanelSize(BBEP_DISPLAY_EC060KD1);
16+
epaper.setPasses(4,4);
1617
epaper.fillScreen(BBEP_WHITE);
17-
epaper.fullUpdate();
1818
// The smiley image is 100x100 pixels; draw it at various scales from 0.5 to 2.0
1919
i = 0;
2020
f = 0.5f; // start at 1/2 size (50x50)
@@ -23,7 +23,6 @@ int main(int argc, char *argv[])
2323
i += (int)(100.0f * f);
2424
f += 0.5f;
2525
}
26-
epaper.setPasses(3,3);
2726
epaper.fullUpdate(CLEAR_FAST, false); // the flag (false) tells it to turn off eink power after the update
2827
epaper.einkPower(0);
2928
epaper.deInit(); // save power by shutting down the TI power controller and I/O extender

examples/Linux/gif_player/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ printf("gif_player - optionally pass the name of a GIF to play\n");
105105
epaper.getStringBox("FastEPD GIF Demo", &rect); // get the rectangle around the text
106106
epaper.drawString("FastEPD GIF Demo", (epaper.width() - rect.w)/2, 90); // center horizontally
107107
epaper.fullUpdate(CLEAR_SLOW, true); // start with a full update and leave the power ON
108-
epaper.setPasses(4, 4);
108+
epaper.setPasses(1, 1);
109109
iFrame = 0;
110110
if (argc == 2) { // use passed a name
111111
FILE * ihandle = fopen(argv[1], "r+b");

examples/Linux/show_jpeg/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CFLAGS=-D__LINUX__ -Wall -O2 -I../../
2+
LIBS=-lFastEPD -lJPEGDEC -lgpiod
3+
4+
all: show_jpeg
5+
6+
show_jpeg: main.o
7+
$(CXX) main.o $(LIBS) -o show_jpeg
8+
9+
main.o: main.cpp
10+
$(CXX) $(CFLAGS) -c main.cpp
11+
12+
clean:
13+
rm -rf *.o show_jpeg

examples/Linux/show_jpeg/it_cartoon.h

Lines changed: 4773 additions & 0 deletions
Large diffs are not rendered by default.

examples/Linux/show_jpeg/main.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//
2+
// Example to show a JPEG image
3+
// as 16-gray levels
4+
//
5+
#include <FastEPD.h>
6+
#include <JPEGDEC.h>
7+
#include "it_cartoon.h"
8+
JPEGDEC jpg;
9+
FASTEPD epaper;
10+
11+
int JPEGDraw(JPEGDRAW *pDraw)
12+
{
13+
int x, y, iPitch = epaper.width()/2;
14+
uint8_t *s, *d, *pBuffer = epaper.currentBuffer();
15+
for (y=0; y<pDraw->iHeight; y++) {
16+
d = &pBuffer[((pDraw->y + y)*iPitch) + (pDraw->x/2)];
17+
s = (uint8_t *)pDraw->pPixels;
18+
s += (y * pDraw->iWidth);
19+
for (x=0; x<pDraw->iWidth; x+=2) {
20+
*d++ = (s[0] & 0xf0) | (s[1] >> 4);
21+
s += 2;
22+
} // for x
23+
} // for y
24+
return 1;
25+
} /* JPEGDraw() */
26+
27+
int main(int argc, char *argv[]) {
28+
// If a filename is passed on the command line, open it, otherwise use the
29+
// pre-loaded cartoon image
30+
uint8_t *pData;
31+
int iDataSize, iCenterX, iCenterY;
32+
33+
epaper.initPanel(BB_PANEL_RPI);
34+
epaper.setPanelSize(BBEP_DISPLAY_EC060KD1);
35+
epaper.setMode(BB_MODE_4BPP);
36+
epaper.fillScreen(0xf);
37+
if (argc == 2) { // load from file
38+
FILE *ihandle;
39+
ihandle = fopen(argv[1], "r+b");
40+
if (!ihandle) {
41+
printf("Error opening file: %s\n", argv[1]);
42+
return -1;
43+
}
44+
fseek(ihandle, 0, SEEK_END);
45+
iDataSize = (int)ftell(ihandle);
46+
fseek(ihandle, 0, SEEK_SET);
47+
pData = (uint8_t *)malloc(iDataSize);
48+
fread(pData, 1, iDataSize, ihandle);
49+
fclose(ihandle);
50+
} else { // use internal image
51+
pData = (uint8_t *)it_cartoon;
52+
iDataSize = sizeof(it_cartoon);
53+
}
54+
if (jpg.openFLASH(pData, iDataSize, JPEGDraw)) {
55+
if (jpg.getWidth() > epaper.width() || jpg.getHeight() > epaper.height()) {
56+
printf("Image larger than display; exiting...\n");
57+
return -1;
58+
}
59+
iCenterX = (epaper.width() - jpg.getWidth()) / 2;
60+
iCenterY = (epaper.height() - jpg.getHeight()) / 2;
61+
jpg.setPixelType(EIGHT_BIT_GRAYSCALE);
62+
jpg.decode(iCenterX, iCenterY, 0);
63+
jpg.close();
64+
epaper.fullUpdate(CLEAR_FAST);
65+
}
66+
return 0;
67+
} /* main() */
68+

src/FastEPD.inl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,9 +1621,9 @@ void bbepClear(FASTEPDSTATE *pState, uint8_t val, uint8_t count, BB_RECT *pRect)
16211621
memcpy(pState->dma_buf, u8Cache, pState->native_width / 4);
16221622
}
16231623
bbepWriteRow(pState, pState->dma_buf, pState->native_width / 4, (i!=0));
1624-
}
1625-
delayMicroseconds(230);
1626-
}
1624+
} // for i
1625+
bbepRowControl(pState, ROW_END);
1626+
} // for k
16271627
} /* bbepClear() */
16281628
//
16291629
// Perform a full update with a single color transition (user selected)
@@ -1679,7 +1679,7 @@ int bbepSmoothUpdate(FASTEPDSTATE *pState, bool bKeepOn, uint8_t u8Color)
16791679
bbepWriteRow(pState, pState->dma_buf, (pState->native_width / 4), 0);
16801680
bbepRowControl(pState, ROW_STEP);
16811681
}
1682-
delayMicroseconds(230);
1682+
bbepRowControl(pState, ROW_END);
16831683
} // for pass
16841684
} else { // must be 4BPP mode
16851685
int dy, iPasses = (pState->panelDef.iMatrixSize / 16); // number of passes
@@ -1715,7 +1715,7 @@ int bbepSmoothUpdate(FASTEPDSTATE *pState, bool bKeepOn, uint8_t u8Color)
17151715
bbepWriteRow(pState, pState->dma_buf, (pState->native_width / 4), 0);
17161716
bbepRowControl(pState, ROW_STEP);
17171717
} // for i
1718-
delayMicroseconds(230);
1718+
bbepRowControl(pState, ROW_END);
17191719
} // for pass
17201720
} // 4bpp
17211721
// Set the drivers inside epaper panel into discharge state.
@@ -1846,7 +1846,7 @@ int bbepFullUpdate(FASTEPDSTATE *pState, int iClearMode, bool bKeepOn, BB_RECT *
18461846
bbepWriteRow(pState, d, (pState->native_width / 4), (i!=0));
18471847
iDMAOff ^= (pState->native_width/4);
18481848
}
1849-
delayMicroseconds(230);
1849+
bbepRowControl(pState, ROW_END);
18501850
} // for pass
18511851
} else { // must be 4BPP mode
18521852
int dy, iPasses = (pState->panelDef.iMatrixSize / 16); // number of passes
@@ -1894,9 +1894,8 @@ int bbepFullUpdate(FASTEPDSTATE *pState, int iClearMode, bool bKeepOn, BB_RECT *
18941894
}
18951895
bbepWriteRow(pState, d, (pState->native_width / 4), (i!=0));
18961896
iDMAOff ^= (pState->native_width / 4); // toggle offset
1897-
//bbepRowControl(pState, ROW_STEP);
18981897
} // for i
1899-
delayMicroseconds(230);
1898+
bbepRowControl(pState, ROW_END);
19001899
} // for pass
19011900
} // 4bpp
19021901
// Set the drivers inside epaper panel into discharge state.
@@ -2009,6 +2008,7 @@ int bbepPartialUpdate(FASTEPDSTATE *pState, bool bKeepOn, int iStartLine, int iE
20092008
dp += iDelta;
20102009
iDMAOff ^= (pState->native_width/4);
20112010
}
2011+
bbepRowControl(pState, ROW_END);
20122012
} // for each pass
20132013

20142014
// This clear to neutral step is necessary; do not remove

src/linux_io.inl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ void RPIRowControl(void *pBBEP, int iType)
230230
gpio_num_t le = (gpio_num_t)pState->panelDef.ioLE;
231231

232232
if (iType == ROW_START) {
233+
gpio_set_level(ckv, 1); // CKV on
234+
delayMicroseconds(5);
235+
gpio_set_level(ckv, 0); // CKV off
236+
gpio_set_level(pState->panelDef.ioShiftMask, 1); // EP_MODE on
237+
delayMicroseconds(4);
233238
gpio_set_level(ckv, 1); // CKV on
234239
delayMicroseconds(7);
235240
gpio_set_level(spv, 0); // SPV off
@@ -240,24 +245,22 @@ void RPIRowControl(void *pBBEP, int iType)
240245
delayMicroseconds(8);
241246
gpio_set_level(spv, 1); // SPV on
242247
delayMicroseconds(10);
243-
gpio_set_level(ckv, 0); // CKV off
244-
delayMicroseconds(1);
245-
gpio_set_level(ckv, 1); // CKV on
246-
delayMicroseconds(18);
247-
gpio_set_level(ckv, 0); // CKV off
248-
delayMicroseconds(1);
249-
gpio_set_level(ckv, 1); // CKV on
250-
delayMicroseconds(18);
251-
gpio_set_level(ckv, 0); // CKV off
252-
delayMicroseconds(1);
253-
gpio_set_level(ckv, 1); // CKV on
248+
for (int i=0; i<3; i++) {
249+
gpio_set_level(ckv, 0); // CKV off
250+
delayMicroseconds(1);
251+
gpio_set_level(ckv, 1); // CKV on
252+
delayMicroseconds(18);
253+
}
254254
wait_cycles(100);
255255
} else if (iType == ROW_STEP) {
256256
gpio_set_level(ckv, 0); // CKV off
257257
gpio_set_level(le, 1); // LE toggle
258-
wait_cycles(1);
258+
wait_cycles(2);
259259
gpio_set_level(le, 0);
260-
wait_cycles(5000);
260+
wait_cycles(15000);
261+
} else if (iType == ROW_END) {
262+
bbepDigitalWrite(pState->panelDef.ioShiftMask, 0); // EP_MODE off
263+
delayMicroseconds(230);
261264
}
262265
}
263266

@@ -384,7 +387,6 @@ int vcom;
384387
if (bOn == pState->pwr_on) return BBEP_SUCCESS;
385388
if (bOn) {
386389
bbepDigitalWrite(pState->panelDef.ioOE, 1); // OE on
387-
bbepDigitalWrite(pState->panelDef.ioShiftMask, 1); // EP_MODE on
388390
bbepDigitalWrite(pState->panelDef.ioPWR, 1); // TPS_PWRUP
389391
bbepDigitalWrite(pState->panelDef.ioShiftSTR, 1); // TPS_WAKEUP
390392
vTaskDelay(1); // allow time to power up

0 commit comments

Comments
 (0)