Skip to content

Commit 24232d2

Browse files
committed
updated with master changes
1 parent d6443ce commit 24232d2

File tree

1 file changed

+44
-35
lines changed

1 file changed

+44
-35
lines changed

adafruit_rgb_display/ssd1331.py

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,21 @@ class SSD1331(DisplaySPI):
4242
"""
4343
A simple driver for the SSD1331-based displays.
4444
45-
>>> import busio
46-
>>> import digitalio
47-
>>> import board
48-
>>> from adafruit_rgb_display import color565
49-
>>> import adafruit_rgb_display.ssd1331 as ssd1331
50-
>>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
51-
>>> display = ssd1331.SSD1331(spi, cs=digitalio.DigitalInOut(board.GPIO0),
52-
... dc=digitalio.DigitalInOut(board.GPIO15), rst=digitalio.DigitalInOut(board.GPIO16))
53-
>>> display.fill(0x7521)
54-
>>> display.pixel(32, 32, 0)
55-
>>>
56-
from machine import Pin, HSPI
57-
import ssd1331
58-
#spi = SPI(mosi=Pin(13), sck=Pin(14), polarity=1, phase=1)
59-
spi = HSPI(polarity=1, phase=1)
60-
display = ssd1331.SSD1331(spi, dc=Pin(2), cs=Pin(15), rst=Pin(16))
61-
display.fill(0x7521)
62-
display.pixel(32, 32, 0)
45+
.. code-block:: python
46+
47+
import busio
48+
import digitalio
49+
import board
50+
from adafruit_rgb_display import color565
51+
import adafruit_rgb_display.ssd1331 as ssd1331
52+
spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
53+
display = ssd1331.SSD1331(spi, cs=digitalio.DigitalInOut(board.GPIO0),
54+
dc=digitalio.DigitalInOut(board.GPIO15),
55+
rst=digitalio.DigitalInOut(board.GPIO16))
56+
57+
display.fill(0x7521)
58+
display.pixel(32, 32, 0)
59+
6360
"""
6461
_COLUMN_SET = _SETCOLUMN
6562
_PAGE_SET = _SETROW
@@ -68,31 +65,43 @@ class SSD1331(DisplaySPI):
6865
_INIT = (
6966
(_DISPLAYOFF, b''),
7067
(_LOCK, b'\x0b'),
71-
(_SETREMAP, b'\x72'), # RGB Color
68+
(_SETREMAP, b'\x72'), # RGB Color
7269
(_STARTLINE, b'\x00'),
7370
(_DISPLAYOFFSET, b'\x00'),
7471
(_NORMALDISPLAY, b''),
7572
# (_FILL, b'\x01'),
76-
# (_PHASEPERIOD, b'\x31'),
77-
# (_SETMULTIPLEX, b'\x3f'),
78-
# (_SETMASTER, b'\x8e'),
79-
# (_POWERMODE,b'\x0b'),
80-
# (_PRECHARGE, b'\x31'), #;//0x1F - 0x31
81-
# (_CLOCKDIV, b'\xf0'),
82-
# (_VCOMH, b'\x3e'), #;//0x3E - 0x3F
83-
# (_MASTERCURRENT, b'\x06'), # ;//0x06 - 0x0F
84-
# (_PRECHARGEA, b'\x64'),
85-
# (_PRECHARGEB, b'\x78'),
86-
# (_PRECHARGEC, b'\x64'),
87-
# (_PRECHARGELEVEL, b'\x3a'), # 0x3A - 0x00
88-
# (_CONTRASTA, b'\x91'), #//0xEF - 0x91
89-
# (_CONTRASTB, b'\x50'), #;//0x11 - 0x50
90-
# (_CONTRASTC, b'\x7d'), #;//0x48 - 0x7D
73+
74+
(_PHASEPERIOD, b'\x31'),
75+
(_SETMULTIPLEX, b'\x3f'),
76+
(_SETMASTER, b'\x8e'),
77+
(_POWERMODE, b'\x0b'),
78+
(_PRECHARGE, b'\x31'), # ;//0x1F - 0x31
79+
(_CLOCKDIV, b'\xf0'),
80+
(_VCOMH, b'\x3e'), # ;//0x3E - 0x3F
81+
(_MASTERCURRENT, b'\x0c'), # ;//0x06 - 0x0F
82+
(_PRECHARGEA, b'\x64'),
83+
(_PRECHARGEB, b'\x78'),
84+
(_PRECHARGEC, b'\x64'),
85+
(_PRECHARGELEVEL, b'\x3a'), # 0x3A - 0x00
86+
(_CONTRASTA, b'\x91'), # //0xEF - 0x91
87+
(_CONTRASTB, b'\x50'), # ;//0x11 - 0x50
88+
(_CONTRASTC, b'\x7d'), # ;//0x48 - 0x7D
9189
(_DISPLAYON, b''),
9290
)
9391
_ENCODE_PIXEL = ">H"
9492
_ENCODE_POS = ">BB"
9593

96-
#pylint: disable-msg=useless-super-delegation, too-many-arguments
94+
# pylint: disable-msg=useless-super-delegation, too-many-arguments
95+
# super required to allow override of default values
96+
# All arguments needed due to driver requiring all the given data to function
9797
def __init__(self, spi, dc, cs, rst=None, width=96, height=64):
9898
super().__init__(spi, dc, cs, rst, width, height)
99+
100+
def write(self, command=None, data=None):
101+
"""write procedure specific to SSD1331"""
102+
self.dc.value = command is None
103+
with self.spi_device as spi:
104+
if command is not None:
105+
spi.write(bytearray([command]))
106+
if data is not None:
107+
spi.write(data)

0 commit comments

Comments
 (0)