Skip to content

Commit

Permalink
Merge d0dd318 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 + d0dd318 commit 5b1e97e
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ ChangeLog
+------------+---------------------------------------------------------------------+------------+
| Version | Description | Date |
+============+=====================================================================+============+
| **3.4.0** | * Add support for SSD1362 256x64 Greyscale OLED | TBC |
+------------+---------------------------------------------------------------------+------------+
| **3.3.0** | * Namespace fix | 2019/06/19 |
+------------+---------------------------------------------------------------------+------------+
| **3.2.1** | * Fix bug where SSD1325 ``framebuffer=diff_to_prev`` didn't set | 2019/04/30 |
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ luma.oled

Luma.OLED
---------
**Display drivers for SSD1306 / SSD1309 / SSD1322 / SSD1325 / SSD1327 / SSD1331 / SSD1351 / SH1106**
**Display drivers for SSD1306 / SSD1309 / SSD1322 / SSD1325 / SSD1327 / SSD1331 / SSD1351 / SSH1362 / SH1106**

.. image:: https://travis-ci.org/rm-hull/luma.oled.svg?branch=master
:target: https://travis-ci.org/rm-hull/luma.oled
Expand Down
6 changes: 3 additions & 3 deletions doc/index.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Luma.OLED: Display drivers for SSD1306 / SSD1309 / SSD1322 / SSD1325 / SSD1327 / SSD1331 / SSD1351 / SH1106
===========================================================================================================
Luma.OLED: Display drivers for SSD1306 / SSD1309 / SSD1322 / SSD1325 / SSD1327 / SSD1331 / SSD1351 / SSD1362 / SH1106
=====================================================================================================================
.. image:: https://travis-ci.org/rm-hull/luma.oled.svg?branch=master
:target: https://travis-ci.org/rm-hull/luma.oled

.. image:: https://coveralls.io/repos/github/rm-hull/luma.oled/badge.svg?branch=master
:target: https://coveralls.io/github/rm-hull/luma.oled?branch=master

.. image:: https://img.shields.io/maintenance/yes/2019.svg?maxAge=2592000
.. image:: https://img.shields.io/maintenance/yes/2020.svg?maxAge=2592000

.. image:: https://img.shields.io/pypi/pyversions/luma.oled.svg
:target: https://pypi.python.org/pypi/luma.oled
Expand Down
3 changes: 2 additions & 1 deletion doc/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Introduction
------------
Interfacing `OLED matrix displays
<https://github.com/rm-hull/luma.oled/wiki/Usage-&-Benchmarking>`_ with the
SSD1306, SSD1309, SSD1322, SSD1325, SSD1327, SSD1331, SSD1351 or SH1106 driver
SSD1306, SSD1309, SSD1322, SSD1325, SSD1327, SSD1331, SSD1351, SSD1362 or SH1106 driver
in Python 2 or 3 using I2C/SPI on the Raspberry Pi and other linux-based
single-board computers: the library provides a Pillow_-compatible drawing
canvas, and other functionality to support:
Expand Down Expand Up @@ -33,6 +33,7 @@ and will fit neatly inside the RPi case.
- :download:`SSD1327 <tech-spec/SSD1327.pdf>`
- :download:`SSD1331 <tech-spec/SSD1331.pdf>`
- :download:`SSD1351 <tech-spec/SSD1351.pdf>`
- :download:`SSD1362 <tech-spec/SSD1362.pdf>`
- :download:`SH1106 <tech-spec/SH1106.pdf>`

Benchmarks for tested devices can be found in the
Expand Down
6 changes: 3 additions & 3 deletions doc/python-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ to a dithered monochrome effect (see the *3d_box.py* example, below).
There is no such constraint on the SSD1331 or SSD1351 OLEDs, which features
16-bit RGB colors: 24-bit RGB images are downsized to 16-bit using a 565 scheme.

The SSD1322 and SSD1325 OLEDs both support 16 greyscale graduations: 24-bit RGB
images are downsized to 4-bit using a Luma conversion which is approximately
calculated as follows:
The SSD1322, SSD1325 and SSD1362 OLEDs all support 16 greyscale graduations:
24-bit RGB images are downsized to 4-bit using a Luma conversion which is
approximately calculated as follows:

.. code::
Expand Down
Binary file added doc/tech-spec/ELW2106AA.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion luma/oled/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

"""
OLED display driver for SSD1306, SSD1309, SSD1322, SSD1325, SSD1327, SSD1331,
SSD1351 and SH1106 devices.
SSD1351, SSD1362 and SH1106 devices.
"""

__version__ = '3.3.0'
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
63 changes: 62 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,67 @@ 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
.. versionadded:: 3.4.0
"""
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def find_version(*file_paths):
author_email="richard.hull@destructuring-bind.org",
description=("A small library to drive an OLED device with either "
"SSD1306, SSD1309, SSD1322, SSD1325, SSD1327, SSD1331, "
"SSD1351 or SH1106 chipset"),
"SSD1351, SSD1362 or SH1106 chipset"),
long_description="\n\n".join([README, CONTRIB, CHANGES]),
long_description_content_type="text/x-rst",
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4',
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.

91 changes: 91 additions & 0 deletions tests/test_ssd1362.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/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 5b1e97e

Please sign in to comment.