Skip to content

Add a display_offset parameter to SH1107. #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 55 additions & 4 deletions adafruit_displayio_sh1107.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2020 Mark Roberts for Adafruit Industries
# SPDX-FileCopyrightText: 2021 James Carr
#
# SPDX-License-Identifier: MIT
"""
Expand All @@ -9,7 +10,7 @@
DisplayIO driver for SH1107 monochrome displays


* Author(s): Scott Shawcroft, Mark Roberts (mdroberts1243)
* Author(s): Scott Shawcroft, Mark Roberts (mdroberts1243), James Carr

Implementation Notes
--------------------
Expand All @@ -26,10 +27,43 @@
"""

import displayio
from micropython import const

__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SH1107.git"


DISPLAY_OFFSET_ADAFRUIT_FEATHERWING_OLED_4650 = const(0x60)
"""
The hardware display offset to use when configuring the SH1107 for the
`Adafruit Featherwing 128x64 OLED <https://www.adafruit.com/product/4650>`_

.. code-block::

from adafruit_displayio_sh1107 import SH1107, DISPLAY_OFFSET_ADAFRUIT_FEATHERWING_OLED_4650

# Simplest constructor, assumes it is an Adafruit FeatherWing 128x64 OLED
display = SH1107(bus, width=128, height=64,
display_offset=DISPLAY_OFFSET_ADAFRUIT_FEATHERWING_OLED_4650)
# Or as it's the default
display = SH1107(bus, width=128, height=64)
"""

DISPLAY_OFFSET_PIMORONI_MONO_OLED_PIM374 = const(0x00)
"""
The hardware display offset to use when configuring the SH1107 for the
`Pimoroni Mono 128x128 OLED <https://shop.pimoroni.com/products/1-12-oled-breakout>`_

.. code-block::

from adafruit_displayio_sh1107 import SH1107, DISPLAY_OFFSET_PIMORONI_MONO_OLED_PIM374

# Constructor for the Pimoroni Mono 128x128 OLED
display = SH1107(bus, width=128, height=128,
display_offset=DISPLAY_OFFSET_PIMORONI_MONO_OLED_PIM374)
"""


# Sequence from sh1107 framebuf driver formatted for displayio init
_INIT_SEQUENCE = (
b"\xae\x00" # display off, sleep mode
Expand All @@ -51,10 +85,27 @@


class SH1107(displayio.Display):
"""SSD1107 driver"""

def __init__(self, bus, **kwargs):
"""
SSD1107 driver for use with DisplayIO

:param bus: The bus that the display is connected to.
:param int width: The width of the display. Maximum of 128
:param int height: The height of the display. Maximum of 128
:param int rotation: The rotation of the display. 0, 90, 180 or 270.
:param int display_offset: The display offset that the first column is wired to.
This will be dependent on the OLED display and two displays with the
same dimensions could have different offsets. This defaults to
`DISPLAY_OFFSET_ADAFRUIT_FEATHERWING_OLED_4650`
"""

def __init__(
self,
bus,
display_offset=DISPLAY_OFFSET_ADAFRUIT_FEATHERWING_OLED_4650,
**kwargs
):
init_sequence = bytearray(_INIT_SEQUENCE)
init_sequence[19] = display_offset
super().__init__(
bus,
init_sequence,
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Uncomment the below if you use native CircuitPython modules such as
# digitalio, micropython and busio. List the modules you use. Without it, the
# autodoc module docs will fail to generate with a warning.
autodoc_mock_imports = ["displayio"]
autodoc_mock_imports = ["displayio", "micropython"]


intersphinx_mapping = {
Expand Down