Skip to content

Commit

Permalink
Add support for different screen sizes (SSD1306 only) - fixes #23
Browse files Browse the repository at this point in the history
Note: the SSD1306 chipset is only supported presently - should there be
a need for SH1106 support, that will be addressed later.
  • Loading branch information
rm-hull committed Dec 7, 2016
1 parent 8404ef2 commit e61de4e
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions oled/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ def __init__(self, serial_interface=None, width=128, height=64):
self.height = height
self._pages = self.height // 8

# FIXME: Delay doing anything here with alternate screen sizes
# until we are able to get a device to test with.
if width != 128 and height != 64:
raise ValueError("Unsupported mode: {0}x{1}".format(width, height))

self.command(
const.DISPLAYOFF,
const.MEMORYMODE,
Expand Down Expand Up @@ -193,10 +198,20 @@ def __init__(self, serial_interface=None, width=128, height=64):
self._buffer = [0] * self.width * self._pages
self._offsets = [n * self.width for n in range(8)]

# Supported modes
settings = {
(128, 64): dict(multiplex=0x3F, displayclockdiv=0x80),
(128, 32): dict(multiplex=0x1F, displayclockdiv=0x80),
(96, 16): dict(multiplex=0x0F, displayclockdiv=0x60)
}.get((width, height))

if settings is None:
raise ValueError("Unsupported mode: {0}x{1}".format(width, height))

self.command(
const.DISPLAYOFF,
const.SETDISPLAYCLOCKDIV, 0x80,
const.SETMULTIPLEX, 0x3F,
const.SETDISPLAYCLOCKDIV, settings.displayclockdiv,
const.SETMULTIPLEX, settings.multiplex,
const.SETDISPLAYOFFSET, 0x00,
const.SETSTARTLINE,
const.CHARGEPUMP, 0x14,
Expand Down

0 comments on commit e61de4e

Please sign in to comment.