Skip to content

Commit

Permalink
Merge cb6f432 into b5f15dc
Browse files Browse the repository at this point in the history
  • Loading branch information
rm-hull committed Jan 19, 2020
2 parents b5f15dc + cb6f432 commit 6af750e
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 1 deletion.
Binary file added doc/tech-spec/ELW2106AA.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions luma/oled/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ class ssd1322(common):
DISPLAYON = 0xAF
DISPLAYOFF = 0xAE
SETCONTRAST = 0xC1


class ssd1362(common):
DISPLAYON = 0xAF
DISPLAYOFF = 0xAE
SETCONTRAST = 0x81
62 changes: 61 additions & 1 deletion luma/oled/device/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import luma.oled.const


__all__ = ["ssd1306", "ssd1309", "ssd1322", "ssd1322_nhd", "ssd1325", "ssd1327", "ssd1331", "ssd1351", "sh1106"]
__all__ = ["ssd1306", "ssd1309", "ssd1322", "ssd1362", "ssd1322_nhd", "ssd1325", "ssd1327", "ssd1331", "ssd1351", "sh1106"]


class sh1106(device):
Expand Down Expand Up @@ -496,6 +496,66 @@ def command(self, cmd, *args):
self._serial_interface.data(list(args))


class ssd1362(greyscale_device):
"""
Serial interface to a 4-bit greyscale SSD1362 OLED display.
On creation, an initialization sequence is pumped to the
display to properly configure it. Further control commands can then be
called to affect the brightness and other settings.
:param serial_interface: The serial interface (usually a
:py:class:`luma.core.interface.serial.spi` instance) to delegate sending
data and commands through.
:param width: The number of horizontal pixels (optional, defaults to 96).
:type width: int
:param height: The number of vertical pixels (optional, defaults to 64).
:type height: int
:param rotate: An integer value of 0 (default), 1, 2 or 3 only, where 0 is
no rotation, 1 is rotate 90° clockwise, 2 is 180° rotation and 3
represents 270° rotation.
:type rotate: int
:param mode: Supplying "1" or "RGB" effects a different rendering
mechanism, either to monochrome or 4-bit greyscale.
:type mode: str
:param framebuffer: Framebuffering strategy, currently values of
``diff_to_previous`` or ``full_frame`` are only supported
:type framebuffer: str
"""
def __init__(self, serial_interface=None, width=256, height=64, rotate=0,
mode="RGB", framebuffer="diff_to_previous", **kwargs):
super(ssd1362, self).__init__(luma.oled.const.ssd1362, serial_interface,
width, height, rotate, mode, framebuffer,
nibble_order=1, **kwargs)

def _supported_dimensions(self):
return [(256, 64)]

def _init_sequence(self):
self.command(
0xAB, # Set Vdd Mode
0x01, # ELW2106AA VCI = 3.0V
0xAD, 0x9E, # Set IREF selection
0x15, 0x00, 0x7F, # Set column address
0x75, 0x00, 0x3F, # Set row address
0xA0, 0x43, # Set Re-map
0xA1, 0x00, # Set display start line
0xA2, 0x00, # Set display offset
0xA4, # Set display mode
0xA8, 0x3F, # Set multiplex ratio
0xB1, 0x11, # Set Phase1,2 length
0xB3, 0xF0, # Set display clock divide ratio
0xB9, # Grey scale table
0xBC, 0x04, # Set pre-charge voltage
0xBE, 0x05) # Set VCOMH deselect level, 0.82 * Vcc

def _set_position(self, top, right, bottom, left):
self.command(
0x15, left >> 1, (right - 1) >> 1, # set column addr
0x75, top, bottom - 1) # set row addr


class ssd1322_nhd(greyscale_device):
"""Similar to ssd1322 but several options are hard coded: width, height and
frame buffer"""
Expand Down
1 change: 1 addition & 0 deletions tests/reference/data/demo_ssd1362_greyscale.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/reference/data/demo_ssd1362_monochrome.json

Large diffs are not rendered by default.

92 changes: 92 additions & 0 deletions tests/test_ssd1362.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2014-18 Richard Hull and contributors
# See LICENSE.rst for details.

from luma.oled.device import ssd1362
from luma.core.render import canvas

from baseline_data import get_json_data, primitives
from helpers import call, serial, setup_function, assert_invalid_dimensions # noqa: F401


def test_init_256x64():
"""
SSD1362 OLED with a 256 x 64 resolution works correctly.
"""
ssd1362(serial)
serial.command.assert_has_calls([
call(171, 1, 173, 158, 21, 0, 127, 117, 0, 63, 160, 67, 161, 0, 162, 0, 164, 168, 63, 177, 17, 179, 240, 185, 188, 4, 190, 5),
call(129, 127),
call(21, 0, 127, 117, 0, 63),
call(175)
])

# Next 4096 are all data: zero's to clear the RAM
# (4096 = 128 * 64 / 2)
serial.data.assert_called_once_with([0] * (256 * 64 // 2))


def test_init_invalid_dimensions():
"""
SSD1362 OLED with an invalid resolution raises a
:py:class:`luma.core.error.DeviceDisplayModeError`.
"""
assert_invalid_dimensions(ssd1362, serial, 128, 77)


def test_hide():
"""
SSD1362 OLED screen content can be hidden.
"""
device = ssd1362(serial)
serial.reset_mock()
device.hide()
serial.command.assert_called_once_with(174)


def test_show():
"""
SSD1362 OLED screen content can be displayed.
"""
device = ssd1362(serial)
serial.reset_mock()
device.show()
serial.command.assert_called_once_with(175)


def test_greyscale_display():
"""
SSD1362 OLED screen can draw and display a greyscale image.
"""
device = ssd1362(serial, mode="RGB")
serial.reset_mock()

# Use the same drawing primitives as the demo
with canvas(device) as draw:
primitives(device, draw)

# Initial command to reset the display
serial.command.assert_called_once_with(21, 0, 127, 117, 0, 63)

# Next 4096 bytes are data representing the drawn image
serial.data.assert_called_once_with(get_json_data('demo_ssd1362_greyscale'))


def test_monochrome_display():
"""
SSD1362 OLED screen can draw and display a monochrome image.
"""
device = ssd1362(serial, mode="1")
serial.reset_mock()

# Use the same drawing primitives as the demo
with canvas(device) as draw:
primitives(device, draw)

# Initial command to reset the display
serial.command.assert_called_once_with(21, 0, 127, 117, 0, 63)

# Next 4096 bytes are data representing the drawn image
serial.data.assert_called_once_with(get_json_data('demo_ssd1362_monochrome'))

0 comments on commit 6af750e

Please sign in to comment.