Skip to content

Commit cfc915f

Browse files
committed
yad
1 parent b9fc966 commit cfc915f

File tree

4 files changed

+291
-2
lines changed

4 files changed

+291
-2
lines changed

src/Adafruit_EPD.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,6 @@ class Adafruit_EPD : public Adafruit_GFX {
184184
#include "drivers/Adafruit_SSD1675B.h"
185185
#include "drivers/Adafruit_SSD1680.h"
186186
#include "drivers/Adafruit_SSD1681.h"
187+
#include "drivers/Adafruit_UC8151D.h"
187188

188189
#endif /* _ADAFRUIT_EPD_H_ */

src/drivers/Adafruit_IL0373.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ Adafruit_IL0373::Adafruit_IL0373(int width, int height, int8_t DC, int8_t RST,
9292
*/
9393
/**************************************************************************/
9494
void Adafruit_IL0373::busy_wait(void) {
95-
Serial.print("Waiting...");
95+
//Serial.print("Waiting...");
9696
if (_busy_pin >= 0) {
9797
while (!digitalRead(_busy_pin)) {
9898
delay(10); // wait for busy high
9999
}
100100
} else {
101101
delay(BUSY_WAIT);
102102
}
103-
Serial.println("OK!");
103+
//Serial.println("OK!");
104104
}
105105

106106
/**************************************************************************/

src/drivers/Adafruit_UC8151D.cpp

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
#include "Adafruit_UC8151D.h"
2+
#include "Adafruit_EPD.h"
3+
4+
#define BUSY_WAIT 500
5+
6+
const unsigned char LUT_DATA[30] = {
7+
0x02, 0x02, 0x01, 0x11, 0x12, 0x12, 0x22, 0x22, 0x66, 0x69,
8+
0x69, 0x59, 0x58, 0x99, 0x99, 0x88, 0x00, 0x00, 0x00, 0x00,
9+
0xF8, 0xB4, 0x13, 0x51, 0x35, 0x51, 0x51, 0x19, 0x01, 0x00};
10+
11+
// clang-format off
12+
13+
const uint8_t uc8151d_default_init_code[] {
14+
UC8151D_PON, 0,
15+
0xFF, 10,
16+
UC8151D_PSR, 1, 0x1F,
17+
UC8151D_CDI, 1, 0x97,
18+
0xFE};
19+
20+
// clang-format on
21+
22+
/**************************************************************************/
23+
/*!
24+
@brief constructor if using external SRAM chip and software SPI
25+
@param width the width of the display in pixels
26+
@param height the height of the display in pixels
27+
@param SID the SID pin to use
28+
@param SCLK the SCLK pin to use
29+
@param DC the data/command pin to use
30+
@param RST the reset pin to use
31+
@param CS the chip select pin to use
32+
@param SRCS the SRAM chip select pin to use
33+
@param MISO the MISO pin to use
34+
@param BUSY the busy pin to use
35+
*/
36+
/**************************************************************************/
37+
Adafruit_UC8151D::Adafruit_UC8151D(int width, int height, int8_t SID,
38+
int8_t SCLK, int8_t DC, int8_t RST,
39+
int8_t CS, int8_t SRCS, int8_t MISO,
40+
int8_t BUSY)
41+
: Adafruit_EPD(width, height, SID, SCLK, DC, RST, CS, SRCS, MISO, BUSY) {
42+
43+
if ((width % 8) != 0) {
44+
width += 8 - (width % 8);
45+
}
46+
buffer1_size = ((uint32_t)width * (uint32_t)height) / 8;
47+
buffer2_size = buffer1_size;
48+
49+
if (SRCS >= 0) {
50+
use_sram = true;
51+
buffer1_addr = 0;
52+
buffer2_addr = buffer1_size;
53+
buffer1 = buffer2 = NULL;
54+
} else {
55+
buffer1 = (uint8_t *)malloc(buffer1_size);
56+
buffer2 = (uint8_t *)malloc(buffer2_size);
57+
}
58+
}
59+
60+
// constructor for hardware SPI - we indicate DataCommand, ChipSelect, Reset
61+
62+
/**************************************************************************/
63+
/*!
64+
@brief constructor if using on-chip RAM and hardware SPI
65+
@param width the width of the display in pixels
66+
@param height the height of the display in pixels
67+
@param DC the data/command pin to use
68+
@param RST the reset pin to use
69+
@param CS the chip select pin to use
70+
@param SRCS the SRAM chip select pin to use
71+
@param BUSY the busy pin to use
72+
*/
73+
/**************************************************************************/
74+
Adafruit_UC8151D::Adafruit_UC8151D(int width, int height, int8_t DC, int8_t RST,
75+
int8_t CS, int8_t SRCS, int8_t BUSY,
76+
SPIClass *spi)
77+
: Adafruit_EPD(width, height, DC, RST, CS, SRCS, BUSY, spi) {
78+
79+
if ((height % 8) != 0) {
80+
height += 8 - (height % 8);
81+
}
82+
buffer1_size = (uint16_t)width * (uint16_t)height / 8;
83+
buffer2_size = buffer1_size;
84+
85+
if (SRCS >= 0) {
86+
use_sram = true;
87+
buffer1_addr = 0;
88+
buffer2_addr = buffer1_size;
89+
buffer1 = buffer2 = NULL;
90+
} else {
91+
buffer1 = (uint8_t *)malloc(buffer1_size);
92+
buffer2 = (uint8_t *)malloc(buffer2_size);
93+
}
94+
}
95+
96+
/**************************************************************************/
97+
/*!
98+
@brief wait for busy signal to end
99+
*/
100+
/**************************************************************************/
101+
void Adafruit_UC8151D::busy_wait(void) {
102+
Serial.print("Waiting...");
103+
if (_busy_pin >= 0) {
104+
EPD_command(UC8151D_FLG);
105+
106+
if (! digitalRead(_busy_pin)) { // wait for busy high
107+
delay(10);
108+
}
109+
} else {
110+
delay(BUSY_WAIT);
111+
}
112+
Serial.println("OK!");
113+
}
114+
115+
/**************************************************************************/
116+
/*!
117+
@brief begin communication with and set up the display.
118+
@param reset if true the reset pin will be toggled.
119+
*/
120+
/**************************************************************************/
121+
void Adafruit_UC8151D::begin(bool reset) {
122+
Adafruit_EPD::begin(reset);
123+
setBlackBuffer(1, true); // black defaults to inverted
124+
setColorBuffer(0, true); // red defaults to inverted
125+
126+
powerDown();
127+
}
128+
129+
/**************************************************************************/
130+
/*!
131+
@brief signal the display to update
132+
*/
133+
/**************************************************************************/
134+
void Adafruit_UC8151D::update() {
135+
EPD_command(UC8151D_DRF);
136+
delay(100);
137+
busy_wait();
138+
}
139+
140+
/**************************************************************************/
141+
/*!
142+
@brief start up the display
143+
*/
144+
/**************************************************************************/
145+
void Adafruit_UC8151D::powerUp() {
146+
uint8_t buf[5];
147+
148+
// Demo code resets 3 times!
149+
hardwareReset();
150+
delay(10);
151+
hardwareReset();
152+
delay(10);
153+
hardwareReset();
154+
delay(10);
155+
156+
const uint8_t *init_code = uc8151d_default_init_code;
157+
158+
if (_epd_init_code != NULL) {
159+
init_code = _epd_init_code;
160+
}
161+
EPD_commandList(init_code);
162+
163+
if (_epd_lut_code) {
164+
EPD_commandList(_epd_lut_code);
165+
}
166+
busy_wait();
167+
}
168+
169+
/**************************************************************************/
170+
/*!
171+
@brief wind down the display
172+
*/
173+
/**************************************************************************/
174+
175+
void Adafruit_UC8151D::powerDown(void) {
176+
uint8_t buf[1];
177+
178+
buf[0] = 0xF7;
179+
EPD_command(UC8151D_CDI, buf, 1);
180+
181+
EPD_command(UC8151D_POF); //power off
182+
busy_wait();
183+
184+
buf[0] = 0xA5;
185+
EPD_command(UC8151D_DSLP, buf, 1);
186+
}
187+
188+
/**************************************************************************/
189+
/*!
190+
@brief Send the specific command to start writing to EPD display RAM
191+
@param index The index for which buffer to write (0 or 1 or tri-color
192+
displays) Ignored for monochrome displays.
193+
@returns The byte that is read from SPI at the same time as sending the
194+
command
195+
*/
196+
/**************************************************************************/
197+
uint8_t Adafruit_UC8151D::writeRAMCommand(uint8_t index) {
198+
if (index == 0) {
199+
return EPD_command(UC8151D_DTM1, false);
200+
}
201+
if (index == 1) {
202+
return EPD_command(UC8151D_DTM2, false);
203+
}
204+
return 0;
205+
}
206+
207+
/**************************************************************************/
208+
/*!
209+
@brief Some displays require setting the RAM address pointer
210+
@param x X address counter value
211+
@param y Y address counter value
212+
*/
213+
/**************************************************************************/
214+
void Adafruit_UC8151D::setRAMAddress(uint16_t x, uint16_t y) {
215+
}

src/drivers/Adafruit_UC8151D.h

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#ifndef LIB_ADAFRUIT_UC8151D
2+
#define LIB_ADAFRUIT_UC8151D
3+
4+
#include "Adafruit_EPD.h"
5+
#include <Arduino.h>
6+
7+
#define EPD_RAM_BW 0x10
8+
9+
#define UC8151D_PSR 0x00
10+
#define UC8151D_PWR 0x01
11+
#define UC8151D_POF 0x02
12+
#define UC8151D_PFS 0x03
13+
#define UC8151D_PON 0x04
14+
#define UC8151D_PMEAS 0x05
15+
#define UC8151D_BTST 0x06
16+
#define UC8151D_DSLP 0x07
17+
#define UC8151D_DTM1 0x10
18+
#define UC8151D_DSP 0x11
19+
#define UC8151D_DRF 0x12
20+
#define UC8151D_DTM2 0x13
21+
#define UC8151D_AUTO 0x17
22+
#define UC8151D_LUTOPT 0x2A
23+
#define UC8151D_PLL 0x30
24+
#define UC8151D_TSC 0x40
25+
#define UC8151D_TSE 0x41
26+
#define UC8151D_TSW 0x42
27+
#define UC8151D_TSR 0x43
28+
#define UC8151D_PBC 0x44
29+
#define UC8151D_CDI 0x50
30+
#define UC8151D_LPD 0x51
31+
#define UC8151D_TRES 0x65
32+
#define UC8151D_GSST 0x70
33+
#define UC8151D_REV 0x70
34+
#define UC8151D_FLG 0x71
35+
#define UC8151D_AMV 0x80
36+
#define UC8151D_VV 0x81
37+
#define UC8151D_VDCS 0x82
38+
#define UC8151D_PTL 0x90
39+
#define UC8151D_PTIN 0x91
40+
#define UC8151D_PTOUT 0x92
41+
#define UC8151D_PGM 0xA0
42+
#define UC8151D_APG 0xA1
43+
#define UC8151D_ROTP 0xA2
44+
#define UC8151D_CCSET 0xE0
45+
#define UC8151D_PWS 0xE3
46+
#define UC8151D_LVSEL 0xE4
47+
#define UC8151D_TSSET 0xE5
48+
49+
/**************************************************************************/
50+
/*!
51+
@brief Class for interfacing with UC8151D EPD drivers
52+
*/
53+
/**************************************************************************/
54+
class Adafruit_UC8151D : public Adafruit_EPD {
55+
public:
56+
Adafruit_UC8151D(int width, int height, int8_t SID, int8_t SCLK, int8_t DC,
57+
int8_t RST, int8_t CS, int8_t SRCS, int8_t MISO,
58+
int8_t BUSY = -1);
59+
Adafruit_UC8151D(int width, int height, int8_t DC, int8_t RST, int8_t CS,
60+
int8_t SRCS, int8_t BUSY = -1, SPIClass *spi = &SPI);
61+
62+
void begin(bool reset = true);
63+
void powerUp();
64+
void powerDown();
65+
void update();
66+
67+
protected:
68+
uint8_t writeRAMCommand(uint8_t index);
69+
void setRAMAddress(uint16_t x, uint16_t y);
70+
void busy_wait();
71+
};
72+
73+
#endif

0 commit comments

Comments
 (0)