uc1701: Add x_offset (Used to add horizontal offset on SSD1306/SH1106 displays) (#3284)

Signed-off-by: RJ Patawaran <rjpatawaran@me.com>
This commit is contained in:
rjpatawaran 2020-09-10 11:07:40 +08:00 committed by GitHub
parent 1f5848fc1a
commit c7ea4b89c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -1901,6 +1901,8 @@
# Set the Vcomh value on SSD1306/SH1106 displays. This value is # Set the Vcomh value on SSD1306/SH1106 displays. This value is
# associated with a "smearing" effect on some OLED displays. # associated with a "smearing" effect on some OLED displays.
# The value may range from 0 to 63. Default is 0. # The value may range from 0 to 63. Default is 0.
#x_offset: 0
# Set the horizontal offset value on SSD1306/SH1106 displays. Default is 0.
#invert: FALSE #invert: FALSE
# TRUE inverts the pixels on certain OLED (SSD1306/SH1106) displays # TRUE inverts the pixels on certain OLED (SSD1306/SH1106) displays
# The default is FALSE # The default is FALSE

View File

@ -13,10 +13,11 @@ BACKGROUND_PRIORITY_CLOCK = 0x7fffffff00000000
TextGlyphs = { 'right_arrow': '\x1a', 'degrees': '\xf8' } TextGlyphs = { 'right_arrow': '\x1a', 'degrees': '\xf8' }
class DisplayBase: class DisplayBase:
def __init__(self, io, columns=128): def __init__(self, io, columns=128, x_offset=0):
self.send = io.send self.send = io.send
# framebuffers # framebuffers
self.columns = columns self.columns = columns
self.x_offset = x_offset
self.vram = [bytearray(self.columns) for i in range(8)] self.vram = [bytearray(self.columns) for i in range(8)]
self.all_framebuffers = [(self.vram[i], bytearray('~'*self.columns), i) self.all_framebuffers = [(self.vram[i], bytearray('~'*self.columns), i)
for i in range(8)] for i in range(8)]
@ -71,6 +72,7 @@ class DisplayBase:
if x + len(data) > 16: if x + len(data) > 16:
data = data[:16 - min(x, 16)] data = data[:16 - min(x, 16)]
pix_x = x * 8 pix_x = x * 8
pix_x += self.x_offset
page_top = self.vram[y * 2] page_top = self.vram[y * 2]
page_bot = self.vram[y * 2 + 1] page_bot = self.vram[y * 2 + 1]
for c in bytearray(data): for c in bytearray(data):
@ -83,6 +85,7 @@ class DisplayBase:
return return
bits_top, bits_bot = self._swizzle_bits(data) bits_top, bits_bot = self._swizzle_bits(data)
pix_x = x * 8 pix_x = x * 8
pix_x += self.x_offset
page_top = self.vram[y * 2] page_top = self.vram[y * 2]
page_bot = self.vram[y * 2 + 1] page_bot = self.vram[y * 2 + 1]
for i in range(8): for i in range(8):
@ -93,6 +96,7 @@ class DisplayBase:
if icon is not None and x < 15: if icon is not None and x < 15:
# Draw icon in graphics mode # Draw icon in graphics mode
pix_x = x * 8 pix_x = x * 8
pix_x += self.x_offset
page_idx = y * 2 page_idx = y * 2
self.vram[page_idx][pix_x:pix_x+16] = icon[0] self.vram[page_idx][pix_x:pix_x+16] = icon[0]
self.vram[page_idx + 1][pix_x:pix_x+16] = icon[1] self.vram[page_idx + 1][pix_x:pix_x+16] = icon[1]
@ -192,7 +196,7 @@ class UC1701(DisplayBase):
# The SSD1306 supports both i2c and "4-wire" spi # The SSD1306 supports both i2c and "4-wire" spi
class SSD1306(DisplayBase): class SSD1306(DisplayBase):
def __init__(self, config, columns=128): def __init__(self, config, columns=128, x_offset=0):
cs_pin = config.get("cs_pin", None) cs_pin = config.get("cs_pin", None)
if cs_pin is None: if cs_pin is None:
io = I2C(config, 60) io = I2C(config, 60)
@ -201,7 +205,7 @@ class SSD1306(DisplayBase):
io = SPI4wire(config, "dc_pin") io = SPI4wire(config, "dc_pin")
io_bus = io.spi io_bus = io.spi
self.reset = ResetHelper(config.get("reset_pin", None), io_bus) self.reset = ResetHelper(config.get("reset_pin", None), io_bus)
DisplayBase.__init__(self, io, columns) DisplayBase.__init__(self, io, columns, x_offset)
self.contrast = config.getint('contrast', 239, minval=0, maxval=255) self.contrast = config.getint('contrast', 239, minval=0, maxval=255)
self.vcomh = config.getint('vcomh', 0, minval=0, maxval=63) self.vcomh = config.getint('vcomh', 0, minval=0, maxval=63)
self.invert = config.getboolean('invert', False) self.invert = config.getboolean('invert', False)
@ -232,4 +236,5 @@ class SSD1306(DisplayBase):
# the SH1106 is SSD1306 compatible with up to 132 columns # the SH1106 is SSD1306 compatible with up to 132 columns
class SH1106(SSD1306): class SH1106(SSD1306):
def __init__(self, config): def __init__(self, config):
SSD1306.__init__(self, config, 132) x_offset = config.getint('x_offset', 0, minval=0, maxval=3)
SSD1306.__init__(self, config, 132, x_offset=x_offset)