SSD1306: Fix driver color-compatibility.

pull/9/merge
peterhinch 2023-02-13 19:01:35 +00:00
rodzic f970a95cd0
commit 17d0d9e3f6
3 zmienionych plików z 12 dodań i 8 usunięć

Wyświetl plik

@ -44,12 +44,12 @@ Width and height are pixels.
Monochrome OLED displays based on the SSD1306 chip are supported via the
[official driver][3d]. Displays are available from various sources and can use
I2C or SPI interfaces. An example is [Adafruit 938][4m]. The SSD1306 driver in
this repo has a minor addition to enable it to support demos intended for color
displays.
I2C or SPI interfaces. An example is [Adafruit 938][4m]. The [SSD1306 driver][14d]
in this repo has minor additions to support demos intended for color displays.
Monochrome OLED displays based on the SH1106 chip are supported via the
[unofficial driver](https://github.com/robert-hh/SH1106).
[unofficial driver](https://github.com/robert-hh/SH1106). The [SH1106 driver][13d]
in this repo has minor additions to support demos intended for color displays.
Displays are available from various sources and can use I2C or SPI interfaces.
An exmaple is the [Inland IIC SPI 1.3" 128x64 OLED V2.0](https://www.microcenter.com/product/643965/inland-iic-spi-13-128x64-oled-v20-graphic-display-module-for-arduino-uno-r3)
AKA [KeyStudio](https://wiki.keyestudio.com/Ks0056_keyestudio_1.3%22_128x64_OLED_Graphic_Display).
@ -103,6 +103,8 @@ simple. See [this doc](./DRIVERS.md#7-writing-device-drivers) for details.
[10d]: https://github.com/peterhinch/micropython-nano-gui/blob/master/DRIVERS.md#53-waveshare-400x300-pi-pico-display
[11d]: https://github.com/peterhinch/micropython-nano-gui/blob/master/DRIVERS.md#23-drivers-for-ssd1327
[12d]: https://github.com/peterhinch/micropython-nano-gui/blob/master/DRIVERS.md#34-driver-for-ili9486
[13d]: https://github.com/peterhinch/micropython-nano-gui/blob/master/drivers/sh1106/sh1106.py
[14d]: https://github.com/peterhinch/micropython-nano-gui/blob/master/drivers/ssd1306/ssd1306.py
[1m]: https://www.adafruit.com/product/684
[2m]: https://www.adafruit.com/product/1673

Wyświetl plik

@ -113,7 +113,7 @@ my GUI's employ the American spelling of `color`.
## 1.1 Change log
12 Feb 2023 Add support for sh1106 driver.
12 Feb 2023 Add support for sh1106 driver. Fix color compatibility of SSD1306.
5 Sep 2022 Add support for additional Pico displays.
8 Aug 2022 Typo and grammar fixes from @bfiics.
10 May 2022 Support Waveshare Pi Pico displays.

Wyświetl plik

@ -2,7 +2,7 @@
from micropython import const
import framebuf
from drivers.boolpalette import BoolPalette
# register definitions
SET_CONTRAST = const(0x81)
@ -27,7 +27,7 @@ SET_CHARGE_PUMP = const(0x8D)
# http://docs.micropython.org/en/latest/pyboard/library/framebuf.html
class SSD1306(framebuf.FrameBuffer):
@staticmethod
def rgb(r, g, b):
def rgb(r, g, b): # Color compatibility
return int((r > 127) or (g > 127) or (b > 127))
def __init__(self, width, height, external_vcc):
@ -36,7 +36,9 @@ class SSD1306(framebuf.FrameBuffer):
self.external_vcc = external_vcc
self.pages = self.height // 8
self.buffer = bytearray(self.pages * self.width)
super().__init__(self.buffer, self.width, self.height, framebuf.MONO_VLSB)
mode = framebuf.MONO_VLSB
self.palette = BoolPalette(mode) # Ensure color compatibility
super().__init__(self.buffer, self.width, self.height, mode)
self.init_display()
def init_display(self):