Skip to content

Commit d724d36

Browse files
Add a display_offset parameter to SH1107.
The current init_sequence assumes it is connected to the Adafruit FeatherWing 128x64 OLED screen. This parameter provides a way to set value provided to the Display Offset (D3) command. The value of this cannot be calculated from the size of the screen (except in the maximum case) as a manufacturer can choose where in the 128x128 grid they wire up their screen to. The default value has been kept to the FeatherWing value of 0x60 so this should not be a breaking change. Constants have been included for: * Adafruit FeatherWing 128x64 OLED * Pimoroni Mono 128x128 OLED
1 parent 4a60bb3 commit d724d36

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

adafruit_displayio_sh1107.py

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
22
# SPDX-FileCopyrightText: Copyright (c) 2020 Mark Roberts for Adafruit Industries
3+
# SPDX-FileCopyrightText: 2021 James Carr
34
#
45
# SPDX-License-Identifier: MIT
56
"""
@@ -9,7 +10,7 @@
910
DisplayIO driver for SH1107 monochrome displays
1011
1112
12-
* Author(s): Scott Shawcroft, Mark Roberts (mdroberts1243)
13+
* Author(s): Scott Shawcroft, Mark Roberts (mdroberts1243), James Carr
1314
1415
Implementation Notes
1516
--------------------
@@ -26,10 +27,43 @@
2627
"""
2728

2829
import displayio
30+
from micropython import const
2931

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

35+
36+
DISPLAY_OFFSET_ADAFRUIT_FEATHERWING_OLED_4650 = const(0x60)
37+
"""
38+
The hardware display offset to use when configuring the SH1107 for the
39+
`Adafruit Featherwing 128x64 OLED <https://www.adafruit.com/product/4650>`_
40+
41+
.. code-block::
42+
43+
from adafruit_displayio_sh1107 import SH1107, DISPLAY_OFFSET_ADAFRUIT_FEATHERWING_OLED_4650
44+
45+
# Simplest constructor, assumes it is an Adafruit FeatherWing 128x64 OLED
46+
display = SH1107(bus, width=128, height=64,
47+
display_offset=DISPLAY_OFFSET_ADAFRUIT_FEATHERWING_OLED_4650)
48+
# Or as it's the default
49+
display = SH1107(bus, width=128, height=64)
50+
"""
51+
52+
DISPLAY_OFFSET_PIMORONI_MONO_OLED_PIM374 = const(0x00)
53+
"""
54+
The hardware display offset to use when configuring the SH1107 for the
55+
`Pimoroni Mono 128x128 OLED <https://shop.pimoroni.com/products/1-12-oled-breakout>`_
56+
57+
.. code-block::
58+
59+
from adafruit_displayio_sh1107 import SH1107, DISPLAY_OFFSET_PIMORONI_MONO_OLED_PIM374
60+
61+
# Constructor for the Pimoroni Mono 128x128 OLED
62+
display = SH1107(bus, width=128, height=128,
63+
display_offset=DISPLAY_OFFSET_PIMORONI_MONO_OLED_PIM374)
64+
"""
65+
66+
3367
# Sequence from sh1107 framebuf driver formatted for displayio init
3468
_INIT_SEQUENCE = (
3569
b"\xae\x00" # display off, sleep mode
@@ -51,10 +85,27 @@
5185

5286

5387
class SH1107(displayio.Display):
54-
"""SSD1107 driver"""
55-
56-
def __init__(self, bus, **kwargs):
88+
"""
89+
SSD1107 driver for use with DisplayIO
90+
91+
:param bus: The bus that the display is connected to.
92+
:param int width: The width of the display. Maximum of 128
93+
:param int height: The height of the display. Maximum of 128
94+
:param int rotation: The rotation of the display. 0, 90, 180 or 270.
95+
:param int display_offset: The display offset that the first column is wired to.
96+
This will be dependent on the OLED display and two displays with the
97+
same dimensions could have different offsets. This defaults to
98+
`DISPLAY_OFFSET_ADAFRUIT_FEATHERWING_OLED_4650`
99+
"""
100+
101+
def __init__(
102+
self,
103+
bus,
104+
display_offset=DISPLAY_OFFSET_ADAFRUIT_FEATHERWING_OLED_4650,
105+
**kwargs
106+
):
57107
init_sequence = bytearray(_INIT_SEQUENCE)
108+
init_sequence[19] = display_offset
58109
super().__init__(
59110
bus,
60111
init_sequence,

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Uncomment the below if you use native CircuitPython modules such as
2626
# digitalio, micropython and busio. List the modules you use. Without it, the
2727
# autodoc module docs will fail to generate with a warning.
28-
autodoc_mock_imports = ["displayio"]
28+
autodoc_mock_imports = ["displayio", "micropython"]
2929

3030

3131
intersphinx_mapping = {

0 commit comments

Comments
 (0)