diff --git a/adafruit_epd/uc8151d.py b/adafruit_epd/uc8151d.py new file mode 100644 index 0000000..e0a0c6c --- /dev/null +++ b/adafruit_epd/uc8151d.py @@ -0,0 +1,150 @@ +# SPDX-FileCopyrightText: 2018 Dean Miller for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +""" +`adafruit_epd.uc8151d` - Adafruit UC8151D - ePaper display driver +==================================================================================== +CircuitPython driver for Adafruit UC8151D display breakouts +* Author(s): Dean Miller +""" + +import time +from micropython import const +import adafruit_framebuf +from adafruit_epd.epd import Adafruit_EPD + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git" + +_UC8151D_PANEL_SETTING = const(0x00) +_UC8151D_POWER_SETTING = const(0x01) +_UC8151D_POWER_OFF = const(0x02) +_UC8151D_POWER_OFF_SEQUENCE = const(0x03) +_UC8151D_POWER_ON = const(0x04) +_UC8151D_POWER_ON_MEASURE = const(0x05) +_UC8151D_BOOSTER_SOFT_START = const(0x06) +_UC8151D_DEEP_SLEEP = const(0x07) +_UC8151D_DTM1 = const(0x10) +_UC8151D_DATA_STOP = const(0x11) +_UC8151D_DISPLAY_REFRESH = const(0x12) +_UC8151D_DTM2 = const(0x13) +_UC8151D_AUTO = const(0x17) +_UC8151D_LUTOPT = const(0x2A) +_UC8151D_PLL = const(0x30) +_UC8151D_TSC = const(0x40) +_UC8151D_TSE = const(0x41) +_UC8151D_TSW = const(0x42) +_UC8151D_TSR = const(0x43) +_UC8151D_PBC = const(0x44) +_UC8151D_CDI = const(0x50) +_UC8151D_LPD = const(0x51) +_UC8151D_TRES = const(0x65) +_UC8151D_GSST = const(0x70) +_UC8151D_REV = const(0x70) +_UC8151D_FLG = const(0x71) +_UC8151D_AMV = const(0x80) +_UC8151D_VV = const(0x81) +_UC8151D_VCM_DC_SETTING = const(0x82) +_UC8151D_PTL = const(0x90) +_UC8151D_PTIN = const(0x91) +_UC8151D_PTOUT = const(0x92) +_UC8151D_PGM = const(0xA0) +_UC8151D_APG = const(0xA1) +_UC8151D_ROTP = const(0xA2) +_UC8151D_CCSET = const(0xE0) +_UC8151D_PWS = const(0xE3) +_UC8151D_LVSEL = const(0xE4) +_UC8151D_TSSET = const(0xE5) + + +class Adafruit_UC8151D(Adafruit_EPD): + """driver class for Adafruit UC8151D ePaper display breakouts""" + + # pylint: disable=too-many-arguments + def __init__( + self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin + ): + super().__init__( + width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin + ) + + self._buffer1_size = int(width * height / 8) + self._buffer2_size = int(width * height / 8) + + if sramcs_pin: + self._buffer1 = self.sram.get_view(0) + self._buffer2 = self.sram.get_view(self._buffer1_size) + else: + self._buffer1 = bytearray((width * height) // 8) + self._buffer2 = bytearray((width * height) // 8) + # since we have *two* framebuffers - one for red and one for black + # we dont subclass but manage manually + self._framebuf1 = adafruit_framebuf.FrameBuffer( + self._buffer1, width, height, buf_format=adafruit_framebuf.MHMSB + ) + self._framebuf2 = adafruit_framebuf.FrameBuffer( + self._buffer2, width, height, buf_format=adafruit_framebuf.MHMSB + ) + self.set_black_buffer(0, True) + self.set_color_buffer(1, True) + # pylint: enable=too-many-arguments + + def begin(self, reset=True): + """Begin communication with the display and set basic settings""" + if reset: + self.hardware_reset() + self.power_down() + + def busy_wait(self): + """Wait for display to be done with current task, either by polling the + busy pin, or pausing""" + if self._busy: + while not self._busy.value: + time.sleep(0.01) + else: + time.sleep(0.5) + + def power_up(self): + """Power up the display in preparation for writing RAM and updating""" + self.hardware_reset() + self.busy_wait() + + self.command(_UC8151D_POWER_ON) + + self.busy_wait() + time.sleep(0.01) + + self.command(_UC8151D_PANEL_SETTING, bytearray([0x1F])) + self.command(_UC8151D_CDI, bytearray([0x97])) + time.sleep(0.05) + + def power_down(self): + """Power down the display - required when not actively displaying!""" + self.command(_UC8151D_CDI, bytearray([0xF7])) + self.command(_UC8151D_POWER_OFF) + self.busy_wait() + self.command(_UC8151D_DEEP_SLEEP, bytearray([0xA5])) + + def update(self): + """Update the display from internal memory""" + self.command(_UC8151D_DISPLAY_REFRESH) + time.sleep(0.1) + self.busy_wait() + if not self._busy: + time.sleep(15) # wait 15 seconds + + def write_ram(self, index): + """Send the one byte command for starting the RAM write process. Returns + the byte read at the same time over SPI. index is the RAM buffer, can be + 0 or 1 for tri-color displays.""" + if index == 0: + return self.command(_UC8151D_DTM1, end=False) + if index == 1: + return self.command(_UC8151D_DTM2, end=False) + raise RuntimeError("RAM index must be 0 or 1") + + def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use + """Set the RAM address location, not used on this chipset but required by + the superclass""" + return # on this chip it does nothing diff --git a/examples/epd_bitmap.py b/examples/epd_bitmap.py index f5f19ad..03a36e3 100644 --- a/examples/epd_bitmap.py +++ b/examples/epd_bitmap.py @@ -12,6 +12,7 @@ from adafruit_epd.ssd1675 import Adafruit_SSD1675 # pylint: disable=unused-import from adafruit_epd.ssd1680 import Adafruit_SSD1680 # pylint: disable=unused-import from adafruit_epd.ssd1681 import Adafruit_SSD1681 # pylint: disable=unused-import +from adafruit_epd.uc8151d import Adafruit_UC8151D # pylint: disable=unused-import # create the spi device and pins we will need @@ -30,6 +31,7 @@ # display = Adafruit_SSD1681(200, 200, # 1.54" HD Tri-color display # display = Adafruit_IL91874(176, 264, # 2.7" Tri-color display # display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display +# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display # display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display # display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display display = Adafruit_IL0373( @@ -43,10 +45,14 @@ busy_pin=busy, ) -# IF YOU HAVE A FLEXIBLE DISPLAY (2.13" or 2.9") uncomment these lines! +# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY uncomment these lines! # display.set_black_buffer(1, False) # display.set_color_buffer(1, False) +# IF YOU HAVE A 2.9" FLEXIBLE DISPLAY uncomment these lines! +# display.set_black_buffer(1, True) +# display.set_color_buffer(1, True) + display.rotation = 0 FILENAME = "blinka.bmp" diff --git a/examples/epd_blinka.py b/examples/epd_blinka.py index 275871a..78c1e31 100644 --- a/examples/epd_blinka.py +++ b/examples/epd_blinka.py @@ -17,6 +17,7 @@ from adafruit_epd.ssd1675b import Adafruit_SSD1675B # pylint: disable=unused-import from adafruit_epd.ssd1680 import Adafruit_SSD1680 # pylint: disable=unused-import from adafruit_epd.ssd1681 import Adafruit_SSD1681 # pylint: disable=unused-import +from adafruit_epd.uc8151d import Adafruit_UC8151D # pylint: disable=unused-import # create the spi device and pins we will need spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) @@ -32,15 +33,16 @@ # give them all to our driver print("Creating display") -# display = Adafruit_SSD1608(200, 200, # 1.54" HD mono display +# display = Adafruit_SSD1608(200, 200, # 1.54" HD mono display # display = Adafruit_SSD1680(122, 250, # 2.13" HD Tri-color display -# display = Adafruit_SSD1681(200, 200, # 1.54" HD Tri-color display -# display = Adafruit_SSD1675(122, 250, # 2.13" HD mono display -# display = Adafruit_IL91874(176, 264, # 2.7" Tri-color display -# display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display -# display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display -# display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display -# display = Adafruit_IL0373(104, 212, # 2.13" Tri-color display +# display = Adafruit_SSD1681(200, 200, # 1.54" HD Tri-color display +# display = Adafruit_SSD1675(122, 250, # 2.13" HD mono display +# display = Adafruit_IL91874(176, 264, # 2.7" Tri-color display +# display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display +# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display +# display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display +# display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display +# display = Adafruit_IL0373(104, 212, # 2.13" Tri-color display display = Adafruit_SSD1675B( 122, 250, @@ -52,6 +54,14 @@ busy_pin=busy, ) +# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY uncomment these lines! +# display.set_black_buffer(1, False) +# display.set_color_buffer(1, False) + +# IF YOU HAVE A 2.9" FLEXIBLE DISPLAY uncomment these lines! +# display.set_black_buffer(1, True) +# display.set_color_buffer(1, True) + display.rotation = 3 # Create blank image for drawing. # Make sure to create image with mode '1' for 1-bit color. diff --git a/examples/epd_pillow_demo.py b/examples/epd_pillow_demo.py index ab37bb1..a9bc290 100644 --- a/examples/epd_pillow_demo.py +++ b/examples/epd_pillow_demo.py @@ -17,6 +17,7 @@ from adafruit_epd.ssd1675 import Adafruit_SSD1675 # pylint: disable=unused-import from adafruit_epd.ssd1680 import Adafruit_SSD1680 # pylint: disable=unused-import from adafruit_epd.ssd1681 import Adafruit_SSD1681 # pylint: disable=unused-import +from adafruit_epd.uc8151d import Adafruit_UC8151D # pylint: disable=unused-import # First define some color constants WHITE = (0xFF, 0xFF, 0xFF) @@ -45,6 +46,7 @@ # display = Adafruit_SSD1681(200, 200, # 1.54" HD Tri-color display # display = Adafruit_IL91874(176, 264, # 2.7" Tri-color display # display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display +# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display # display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display # display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display display = Adafruit_IL0373( @@ -58,10 +60,14 @@ busy_pin=busy, ) -# IF YOU HAVE A FLEXIBLE DISPLAY (2.13" or 2.9") uncomment these lines! +# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY uncomment these lines! # display.set_black_buffer(1, False) # display.set_color_buffer(1, False) +# IF YOU HAVE A 2.9" FLEXIBLE DISPLAY uncomment these lines! +# display.set_black_buffer(1, True) +# display.set_color_buffer(1, True) + display.rotation = 1 image = Image.new("RGB", (display.width, display.height)) diff --git a/examples/epd_pillow_image.py b/examples/epd_pillow_image.py index 9051155..454ccaf 100644 --- a/examples/epd_pillow_image.py +++ b/examples/epd_pillow_image.py @@ -19,6 +19,7 @@ from adafruit_epd.ssd1675 import Adafruit_SSD1675 # pylint: disable=unused-import from adafruit_epd.ssd1680 import Adafruit_SSD1680 # pylint: disable=unused-import from adafruit_epd.ssd1681 import Adafruit_SSD1681 # pylint: disable=unused-import +from adafruit_epd.uc8151d import Adafruit_UC8151D # pylint: disable=unused-import # create the spi device and pins we will need @@ -36,6 +37,7 @@ # display = Adafruit_SSD1681(200, 200, # 1.54" HD Tri-color display # display = Adafruit_IL91874(176, 264, # 2.7" Tri-color display # display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display +# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display # display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display # display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display display = Adafruit_IL0373( @@ -49,10 +51,14 @@ busy_pin=busy, ) -# IF YOU HAVE A FLEXIBLE DISPLAY (2.13" or 2.9") uncomment these lines! +# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY uncomment these lines! # display.set_black_buffer(1, False) # display.set_color_buffer(1, False) +# IF YOU HAVE A 2.9" FLEXIBLE DISPLAY uncomment these lines! +# display.set_black_buffer(1, True) +# display.set_color_buffer(1, True) + display.rotation = 1 image = Image.open("blinka.png") diff --git a/examples/epd_simpletest.py b/examples/epd_simpletest.py index 7f469a7..39cbb62 100644 --- a/examples/epd_simpletest.py +++ b/examples/epd_simpletest.py @@ -12,6 +12,7 @@ from adafruit_epd.ssd1675 import Adafruit_SSD1675 # pylint: disable=unused-import from adafruit_epd.ssd1680 import Adafruit_SSD1680 # pylint: disable=unused-import from adafruit_epd.ssd1681 import Adafruit_SSD1681 # pylint: disable=unused-import +from adafruit_epd.uc8151d import Adafruit_UC8151D # pylint: disable=unused-import # create the spi device and pins we will need spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) @@ -29,6 +30,7 @@ # display = Adafruit_SSD1681(200, 200, # 1.54" HD Tri-color display # display = Adafruit_IL91874(176, 264, # 2.7" Tri-color display # display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display +# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display # display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display # display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display display = Adafruit_IL0373( @@ -42,10 +44,14 @@ busy_pin=busy, ) -# IF YOU HAVE A FLEXIBLE DISPLAY (2.13" or 2.9") uncomment these lines! +# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY uncomment these lines! # display.set_black_buffer(1, False) # display.set_color_buffer(1, False) +# IF YOU HAVE A 2.9" FLEXIBLE DISPLAY uncomment these lines! +# display.set_black_buffer(1, True) +# display.set_color_buffer(1, True) + display.rotation = 1 # clear the buffer