1- # SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
1+ # SPDX-FileCopyrightText: 2024
22#
33# SPDX-License-Identifier: MIT
44
55"""
66`adafruit_epd.uc8179` - Adafruit UC8179 - ePaper display driver
77====================================================================================
88CircuitPython driver for Adafruit UC8179 display breakouts
9- * Author(s): Liz Clark
9+ * Author(s): Your Name Here
1010"""
1111
1212import time
5252class Adafruit_UC8179 (Adafruit_EPD ):
5353 """driver class for Adafruit UC8179 ePaper display breakouts"""
5454
55- # Default initialization sequence
56- _default_init_code = bytes ([
57- _UC8179_POWERSETTING , 4 ,
58- 0x07 , # VGH=20V
59- 0x07 , # VGL=-20V
60- 0x3F , # VDH=15V
61- 0x3F , # VDL=-15V
62-
63- _UC8179_POWERON , 0 ,
64- 0xFF , 100 , # busy wait
65-
66- _UC8179_PANELSETTING , 1 ,
67- 0b010111 , # BW OTP LUT
68-
69- _UC8179_TRES , 4 ,
70- 0x02 , 0x88 , 0x01 , 0xE0 ,
71-
72- _UC8179_DUALSPI , 1 , 0x00 ,
73-
74- _UC8179_WRITE_VCOM , 2 , 0x10 , 0x07 ,
75- _UC8179_TCON , 1 , 0x22 ,
76-
77- 0xFE # End marker
78- ])
79-
8055 def __init__ (
8156 self ,
8257 width : int ,
@@ -125,32 +100,18 @@ def __init__(
125100 # Set up which frame buffer is which color
126101 self .set_black_buffer (0 , True )
127102 self .set_color_buffer (1 , False )
128-
103+
129104 # UC8179 uses single byte transactions
130105 self ._single_byte_tx = True
131106
132- # Custom init code if needed
133- self ._epd_init_code = None
134-
135107 # Default refresh delay (from Adafruit_EPD base class in Arduino)
136108 self .default_refresh_delay = 15 # seconds
137109 # pylint: enable=too-many-arguments
138110
139111 def begin (self , reset : bool = True ) -> None :
140112 """Begin communication with the display and set basic settings"""
141- # Direct port of Arduino begin() method
142-
143- # Note: Arduino sets _data_entry_mode = THINKINK_UC8179
144- # This appears to be specific to SRAM organization for this chip
145-
146113 if reset :
147114 self .hardware_reset ()
148-
149- # Black buffer defaults to inverted (0 means black)
150- self .set_black_buffer (0 , True )
151- # Red/color buffer defaults to not inverted (1 means red)
152- self .set_color_buffer (1 , False )
153-
154115 self .power_down ()
155116
156117 def busy_wait (self ) -> None :
@@ -170,24 +131,50 @@ def busy_wait(self) -> None:
170131 def power_up (self ) -> None :
171132 """Power up the display in preparation for writing RAM and updating"""
172133 self .hardware_reset ()
173-
174- # Use custom init code if provided, otherwise use default
175- init_code = self ._epd_init_code if self ._epd_init_code else self ._default_init_code
176-
177- # Process initialization sequence
178- self ._command_list (init_code )
179-
180- # Set display resolution (using WIDTH and HEIGHT macros in Arduino)
134+
135+ # Power setting
136+ self .command (
137+ _UC8179_POWERSETTING ,
138+ bytearray (
139+ [
140+ 0x07 , # VGH=20V
141+ 0x07 , # VGL=-20V
142+ 0x3F , # VDH=15V
143+ 0x3F , # VDL=-15V
144+ ]
145+ ),
146+ )
147+
148+ # Power on
149+ self .command (_UC8179_POWERON )
150+ time .sleep (0.1 ) # 100ms delay
151+ self .busy_wait ()
152+
153+ # Panel setting
154+ self .command (_UC8179_PANELSETTING , bytearray ([0b010111 ])) # BW OTP LUT
155+
156+ # Resolution setting
181157 self .command (
182158 _UC8179_TRES ,
183- bytearray ([self ._width >> 8 , self ._width & 0xFF , self ._height >> 8 , self ._height & 0xFF ]),
159+ bytearray (
160+ [self ._width >> 8 , self ._width & 0xFF , self ._height >> 8 , self ._height & 0xFF ]
161+ ),
184162 )
185163
164+ # Dual SPI setting
165+ self .command (_UC8179_DUALSPI , bytearray ([0x00 ]))
166+
167+ # VCOM setting
168+ self .command (_UC8179_WRITE_VCOM , bytearray ([0x10 , 0x07 ]))
169+
170+ # TCON setting
171+ self .command (_UC8179_TCON , bytearray ([0x22 ]))
172+
186173 def power_down (self ) -> None :
187174 """Power down the display - required when not actively displaying!"""
188175 self .command (_UC8179_POWEROFF )
189176 self .busy_wait ()
190-
177+
191178 # Only deep sleep if we have a reset pin to wake it up
192179 if self ._rst :
193180 self .command (_UC8179_DEEPSLEEP , bytearray ([0x05 ]))
@@ -196,12 +183,12 @@ def power_down(self) -> None:
196183 def update (self ) -> None :
197184 """Update the display from internal memory"""
198185 self .command (_UC8179_DISPLAYREFRESH )
199- time .sleep (0.1 )
186+ time .sleep (0.1 ) # 100ms delay
200187 self .busy_wait ()
201-
188+
202189 if not self ._busy :
203190 # If no busy pin, use default refresh delay
204- time .sleep (self .default_refresh_delay / 1000.0 )
191+ time .sleep (self .default_refresh_delay )
205192
206193 def write_ram (self , index : Literal [0 , 1 ]) -> int :
207194 """Send the one byte command for starting the RAM write process. Returns
@@ -224,29 +211,3 @@ def set_ram_window(self, x1: int, y1: int, x2: int, y2: int) -> None: # noqa: P
224211 the superclass"""
225212 # Not used in UC8179 chip
226213 pass
227-
228- def _command_list (self , init_sequence : bytes ) -> None :
229- """Process a command list for initialization"""
230- i = 0
231- while i < len (init_sequence ):
232- cmd = init_sequence [i ]
233- i += 1
234-
235- # Check for end marker
236- if cmd == 0xFE :
237- break
238-
239- # Get number of data bytes
240- num_data = init_sequence [i ]
241- i += 1
242-
243- # Check for delay command (0xFF)
244- if cmd == 0xFF :
245- time .sleep (num_data / 1000.0 )
246- else :
247- # Send command with data if any
248- if num_data > 0 :
249- self .command (cmd , bytearray (init_sequence [i :i + num_data ]))
250- i += num_data
251- else :
252- self .command (cmd )
0 commit comments