|
47 | 47 | from luma.core.virtual import character |
48 | 48 | from luma.core.bitmap_font import embedded_fonts |
49 | 49 |
|
50 | | -__all__ = ["pcd8544", "st7735", "ht1621", "uc1701x", "st7567", "ili9341", "ili9486", "hd44780"] |
| 50 | +__all__ = ["pcd8544", "st7735", "st7789", "ht1621", "uc1701x", "st7567", "ili9341", "ili9486", "hd44780"] |
51 | 51 |
|
52 | 52 |
|
53 | 53 | class GPIOBacklight: |
@@ -292,6 +292,64 @@ def contrast(self, value): |
292 | 292 | self.command(0x21, 0x14, value | 0x80, 0x20) |
293 | 293 |
|
294 | 294 |
|
| 295 | +class st7789(backlit_device): |
| 296 | + """ |
| 297 | + Serial interface to a colour ST7789 240x240 pixel LCD display. |
| 298 | +
|
| 299 | + .. versionadded:: 2.9.0 |
| 300 | + """ |
| 301 | + def __init__(self, serial_interface=None, rotate=0, **kwargs): |
| 302 | + super(st7789, self).__init__(luma.lcd.const.st7789, serial_interface, **kwargs) |
| 303 | + self.capabilities(240, 240, rotate, mode="RGB") |
| 304 | + |
| 305 | + self.command(0x36, 0x70) # MADCTL (36h): Memory Data Access Control: Bottom to Top, Right to Left, Reverse Mode |
| 306 | + self.command(0x3A, 0x06) # COLMOD (3Ah): Interface Pixel Format: 18bit/pixel |
| 307 | + self.command(0xB2, # PORCTRL (B2h): Porch Setting: Disable separate porch control, 0xC in normal mode, 0x3 in idle and partial modes |
| 308 | + 0x0C, 0x0C, 0x00, 0x33, 0x33) |
| 309 | + self.command(0xB7, 0x35) # GCTRL (B7h): Gate Control: VGH = 13.26V, VGL = -10.43V |
| 310 | + self.command(0xBB, 0x19) # VCOMS (BBh): VCOM Setting: 0.725V |
| 311 | + self.command(0xC0, 0x2C) # LCMCTRL (C0h): LCM Control: XBGR, XMX, XMH |
| 312 | + self.command(0xC2, 0x01) # VDVVRHEN (C2h): VDV and VRH Command Enable: VDV and VRH register value comes from command write |
| 313 | + self.command(0xC3, 0x12) # VRHS (C3h): VRH Set: 4.45V + (vcom + vcom offset + vdv) |
| 314 | + self.command(0xC4, 0x20) # VDVS (C4h): VDV Set: 0V |
| 315 | + self.command(0xC6, 0x0F) # FRCTRL2 (C6h): Frame Rate Control in Normal Mode: 60Hz |
| 316 | + self.command(0xD0, # PWCTRL1 (D0h): Power Control 1: AVDD = 6.8V, AVCL = -4.8V, VDDS = 2.3V |
| 317 | + 0xA4, 0xA1) |
| 318 | + self.command(0xE0, # PVGAMCTRL (E0h): Positive Voltage Gamma Control |
| 319 | + 0xD0, 0x04, 0x0D, 0x11, 0x13, 0x2B, 0x3F, 0x54, 0x4C, 0x18, 0x0D, 0x0B, 0x1F, 0x23) |
| 320 | + self.command(0xE1, # NVGAMCTRL (E1h): Negative Voltage Gamma Control |
| 321 | + 0xD0, 0x04, 0x0C, 0x11, 0x13, 0x2C, 0x3F, 0x44, 0x51, 0x2F, 0x1F, 0x1F, 0x20, 0x23) |
| 322 | + self.command(0x21) # INVON (21h): Display Inversion On |
| 323 | + self.command(0x11) # SLPOUT (11h): Sleep Out |
| 324 | + self.command(0x29) # DISPON (29h): Display On |
| 325 | + |
| 326 | + self.clear() |
| 327 | + self.show() |
| 328 | + |
| 329 | + def set_window(self, x1, y1, x2, y2): |
| 330 | + self.command(0x2A, # CASET (2Ah): Column Address Set |
| 331 | + x1 >> 8, x1 & 0xFF, (x2 - 1) >> 8, (x2 - 1) & 0xFF) |
| 332 | + self.command(0x2B, # RASET (2Bh): Row Address Set |
| 333 | + y1 >> 8, y1 & 0xFF, (y2 - 1) >> 8, (y2 - 1) & 0xFF) |
| 334 | + self.command(0x2C) # RAMWR (2Ch): Memory Write |
| 335 | + |
| 336 | + def display(self, image): |
| 337 | + w, h = 240, 240 |
| 338 | + self.set_window(0, 0, w, h) |
| 339 | + |
| 340 | + image = self.preprocess(image) |
| 341 | + self.data(list(image.convert("RGB").tobytes())) |
| 342 | + |
| 343 | + def contrast(self, level): |
| 344 | + """ |
| 345 | + NOT SUPPORTED |
| 346 | +
|
| 347 | + :param level: Desired contrast level in the range of 0-255. |
| 348 | + :type level: int |
| 349 | + """ |
| 350 | + assert(0 <= level <= 255) |
| 351 | + |
| 352 | + |
295 | 353 | class st7567(backlit_device): |
296 | 354 | """ |
297 | 355 | Serial interface to a monochrome ST7567 128x64 pixel LCD display. |
|
0 commit comments