Skip to content

Commit 41b9da4

Browse files
authored
Merge pull request #37 from adafruit/uc8151
Uc8151
2 parents b9fc966 + 35d6783 commit 41b9da4

File tree

9 files changed

+428
-2
lines changed

9 files changed

+428
-2
lines changed

examples/ThinkInk_mono/ThinkInk_mono.ino

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
//ThinkInk_154_Mono_D67 display(EPD_DC, EPD_RESET, EPD_CS, SRAM_CS, EPD_BUSY);
1919
//ThinkInk_154_Mono_D27 display(EPD_DC, EPD_RESET, EPD_CS, SRAM_CS, EPD_BUSY);
2020

21+
// 1.54" Monochrome displays with 152x152 pixels and UC8151D chipset
22+
//ThinkInk_154_Mono_M10 display(EPD_DC, EPD_RESET, EPD_CS, SRAM_CS, EPD_BUSY);
23+
2124
// 2.13" Monochrome displays with 250x122 pixels and SSD1675 chipset
2225
ThinkInk_213_Mono_B72 display(EPD_DC, EPD_RESET, EPD_CS, SRAM_CS, EPD_BUSY);
2326

@@ -27,7 +30,16 @@ ThinkInk_213_Mono_B72 display(EPD_DC, EPD_RESET, EPD_CS, SRAM_CS, EPD_BUSY);
2730
// 2.13" Monochrome displays with 250x122 pixels and SSD1680 chipset
2831
//ThinkInk_213_Mono_BN display(EPD_DC, EPD_RESET, EPD_CS, SRAM_CS, EPD_BUSY);
2932

33+
// 2.13" Monochrome displays with 212x104 pixels and UC8151D chipset
34+
//ThinkInk_213_Mono_M21 display(EPD_DC, EPD_RESET, EPD_CS, SRAM_CS, EPD_BUSY);
35+
36+
// 2.9" 4-level Grayscale (use mono) displays with 296x128 pixels and IL0373 chipset
3037
//ThinkInk_290_Grayscale4_T5 display(EPD_DC, EPD_RESET, EPD_CS, SRAM_CS, EPD_BUSY);
38+
39+
// 2.9" Monochrome displays with 296x128 pixels and UC8151D chipset
40+
//ThinkInk_290_Mono_M06 display(EPD_DC, EPD_RESET, EPD_CS, SRAM_CS, EPD_BUSY);
41+
42+
// 4.2" Monochrome displays with 400x300 pixels and SSD1619 chipset
3143
//ThinkInk_420_Mono_BN display(EPD_DC, EPD_RESET, EPD_CS, SRAM_CS, EPD_BUSY);
3244

3345
void setup() {

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/Adafruit_ThinkInk.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ typedef enum {
2323

2424
#include "panels/ThinkInk_154_Mono_D27.h"
2525
#include "panels/ThinkInk_154_Mono_D67.h"
26+
#include "panels/ThinkInk_154_Mono_M10.h"
2627
#include "panels/ThinkInk_213_Mono_B72.h"
2728
#include "panels/ThinkInk_213_Mono_B73.h"
2829
#include "panels/ThinkInk_213_Mono_BN.h"
30+
#include "panels/ThinkInk_213_Mono_M21.h"
31+
#include "panels/ThinkInk_290_Mono_M06.h"
2932
#include "panels/ThinkInk_420_Mono_BN.h"
3033

3134
#endif // _ADAFRUIT_THINKINK_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: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
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+
if (_busy_pin >= 0) {
103+
do {
104+
EPD_command(UC8151D_FLG);
105+
delay(10);
106+
} while (!digitalRead(_busy_pin));
107+
} else {
108+
delay(BUSY_WAIT);
109+
}
110+
}
111+
112+
/**************************************************************************/
113+
/*!
114+
@brief begin communication with and set up the display.
115+
@param reset if true the reset pin will be toggled.
116+
*/
117+
/**************************************************************************/
118+
void Adafruit_UC8151D::begin(bool reset) {
119+
Adafruit_EPD::begin(reset);
120+
setBlackBuffer(1, true); // black defaults to inverted
121+
setColorBuffer(0, true); // red defaults to inverted
122+
123+
powerDown();
124+
}
125+
126+
/**************************************************************************/
127+
/*!
128+
@brief signal the display to update
129+
*/
130+
/**************************************************************************/
131+
void Adafruit_UC8151D::update() {
132+
EPD_command(UC8151D_DRF);
133+
delay(100);
134+
busy_wait();
135+
}
136+
137+
/**************************************************************************/
138+
/*!
139+
@brief start up the display
140+
*/
141+
/**************************************************************************/
142+
void Adafruit_UC8151D::powerUp() {
143+
uint8_t buf[5];
144+
145+
// Demo code resets 3 times!
146+
hardwareReset();
147+
delay(10);
148+
hardwareReset();
149+
delay(10);
150+
hardwareReset();
151+
delay(10);
152+
153+
const uint8_t *init_code = uc8151d_default_init_code;
154+
155+
if (_epd_init_code != NULL) {
156+
init_code = _epd_init_code;
157+
}
158+
EPD_commandList(init_code);
159+
160+
if (_epd_lut_code) {
161+
EPD_commandList(_epd_lut_code);
162+
}
163+
busy_wait();
164+
}
165+
166+
/**************************************************************************/
167+
/*!
168+
@brief wind down the display
169+
*/
170+
/**************************************************************************/
171+
172+
void Adafruit_UC8151D::powerDown(void) {
173+
uint8_t buf[1];
174+
175+
buf[0] = 0xF7;
176+
EPD_command(UC8151D_CDI, buf, 1);
177+
178+
EPD_command(UC8151D_POF); // power off
179+
busy_wait();
180+
181+
buf[0] = 0xA5;
182+
EPD_command(UC8151D_DSLP, buf, 1);
183+
}
184+
185+
/**************************************************************************/
186+
/*!
187+
@brief Send the specific command to start writing to EPD display RAM
188+
@param index The index for which buffer to write (0 or 1 or tri-color
189+
displays) Ignored for monochrome displays.
190+
@returns The byte that is read from SPI at the same time as sending the
191+
command
192+
*/
193+
/**************************************************************************/
194+
uint8_t Adafruit_UC8151D::writeRAMCommand(uint8_t index) {
195+
if (index == 0) {
196+
return EPD_command(UC8151D_DTM1, false);
197+
}
198+
if (index == 1) {
199+
return EPD_command(UC8151D_DTM2, false);
200+
}
201+
return 0;
202+
}
203+
204+
/**************************************************************************/
205+
/*!
206+
@brief Some displays require setting the RAM address pointer
207+
@param x X address counter value
208+
@param y Y address counter value
209+
*/
210+
/**************************************************************************/
211+
void Adafruit_UC8151D::setRAMAddress(uint16_t x, uint16_t y) {}

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

src/panels/ThinkInk_154_Mono_M10.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef _THINKINK_154_MONO_M10_H
2+
#define _THINKINK_154_MONO_M10_H
3+
4+
// This file is #included by Adafruit_ThinkInk.h and does not need to
5+
// #include anything else to pick up the EPD header or ink mode enum.
6+
7+
class ThinkInk_154_Mono_M10 : public Adafruit_UC8151D {
8+
public:
9+
ThinkInk_154_Mono_M10(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST,
10+
int8_t CS, int8_t SRCS, int8_t MISO, int8_t BUSY = -1)
11+
: Adafruit_UC8151D(152, 152, SID, SCLK, DC, RST, CS, SRCS, MISO, BUSY){};
12+
13+
ThinkInk_154_Mono_M10(int8_t DC, int8_t RST, int8_t CS, int8_t SRCS,
14+
int8_t BUSY = -1, SPIClass *spi = &SPI)
15+
: Adafruit_UC8151D(152, 152, DC, RST, CS, SRCS, BUSY, spi){};
16+
17+
void begin(thinkinkmode_t mode = THINKINK_MONO) {
18+
Adafruit_EPD::begin(true);
19+
setColorBuffer(1, true); // layer 1 uninverted
20+
setBlackBuffer(1, true); // only one buffer
21+
22+
inkmode = mode; // Preserve ink mode for ImageReader or others
23+
24+
layer_colors[EPD_WHITE] = 0b00;
25+
layer_colors[EPD_BLACK] = 0b01;
26+
layer_colors[EPD_RED] = 0b01;
27+
layer_colors[EPD_GRAY] = 0b01;
28+
layer_colors[EPD_LIGHT] = 0b00;
29+
layer_colors[EPD_DARK] = 0b01;
30+
31+
default_refresh_delay = 1000;
32+
setRotation(1);
33+
powerDown();
34+
}
35+
36+
thinkinkmode_t getMode(void) { return inkmode; }
37+
38+
private:
39+
thinkinkmode_t inkmode; // Ink mode passed to begin()
40+
};
41+
42+
#endif // _THINKINK_154_MONO_M10_H

0 commit comments

Comments
 (0)