Skip to content

Update to SSD1331 driver #11

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 3 commits into from
Dec 28, 2017
Merged
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
83 changes: 49 additions & 34 deletions adafruit_rgb_display/ssd1331.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
"""A simple driver for the SSD1331-based displays."""
from adafruit_rgb_display.rgb import DisplaySPI
from micropython import const

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


_DRAWLINE = const(0x21)
Expand Down Expand Up @@ -37,23 +42,21 @@ class SSD1331(DisplaySPI):
"""
A simple driver for the SSD1331-based displays.

>>> import busio
>>> import digitalio
>>> import board
>>> from adafruit_rgb_display import color565
>>> import adafruit_rgb_display.ssd1331 as ssd1331
>>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
>>> display = ssd1331.SSD1331(spi, cs=digitalio.DigitalInOut(board.GPIO0), dc=digitalio.DigitalInOut(board.GPIO15), rst=digitalio.DigitalInOut(board.GPIO16))
>>> display.fill(0x7521)
>>> display.pixel(32, 32, 0)
>>>
from machine import Pin, HSPI
import ssd1331
#spi = SPI(mosi=Pin(13), sck=Pin(14), polarity=1, phase=1)
spi = HSPI(polarity=1, phase=1)
display = ssd1331.SSD1331(spi, dc=Pin(2), cs=Pin(15), rst=Pin(16))
display.fill(0x7521)
display.pixel(32, 32, 0)
.. code-block:: python

import busio
import digitalio
import board
from adafruit_rgb_display import color565
import adafruit_rgb_display.ssd1331 as ssd1331
spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
display = ssd1331.SSD1331(spi, cs=digitalio.DigitalInOut(board.GPIO0),
dc=digitalio.DigitalInOut(board.GPIO15),
rst=digitalio.DigitalInOut(board.GPIO16))

display.fill(0x7521)
display.pixel(32, 32, 0)

"""
_COLUMN_SET = _SETCOLUMN
_PAGE_SET = _SETROW
Expand All @@ -62,31 +65,43 @@ class SSD1331(DisplaySPI):
_INIT = (
(_DISPLAYOFF, b''),
(_LOCK, b'\x0b'),
(_SETREMAP, b'\x72'), # RGB Color
(_SETREMAP, b'\x72'), # RGB Color
(_STARTLINE, b'\x00'),
(_DISPLAYOFFSET, b'\x00'),
(_NORMALDISPLAY, b''),
# (_FILL, b'\x01'),
# (_FILL, b'\x01'),

# (_PHASEPERIOD, b'\x31'),
# (_SETMULTIPLEX, b'\x3f'),
# (_SETMASTER, b'\x8e'),
# (_POWERMODE,b'\x0b'),
# (_PRECHARGE, b'\x31'), #;//0x1F - 0x31
# (_CLOCKDIV, b'\xf0'),
# (_VCOMH, b'\x3e'), #;//0x3E - 0x3F
# (_MASTERCURRENT, b'\x06'), # ;//0x06 - 0x0F
# (_PRECHARGEA, b'\x64'),
# (_PRECHARGEB, b'\x78'),
# (_PRECHARGEC, b'\x64'),
# (_PRECHARGELEVEL, b'\x3a'), # 0x3A - 0x00
# (_CONTRASTA, b'\x91'), #//0xEF - 0x91
# (_CONTRASTB, b'\x50'), #;//0x11 - 0x50
# (_CONTRASTC, b'\x7d'), #;//0x48 - 0x7D
(_PHASEPERIOD, b'\x31'),
(_SETMULTIPLEX, b'\x3f'),
(_SETMASTER, b'\x8e'),
(_POWERMODE, b'\x0b'),
(_PRECHARGE, b'\x31'), # ;//0x1F - 0x31
(_CLOCKDIV, b'\xf0'),
(_VCOMH, b'\x3e'), # ;//0x3E - 0x3F
(_MASTERCURRENT, b'\x0c'), # ;//0x06 - 0x0F
(_PRECHARGEA, b'\x64'),
(_PRECHARGEB, b'\x78'),
(_PRECHARGEC, b'\x64'),
(_PRECHARGELEVEL, b'\x3a'), # 0x3A - 0x00
(_CONTRASTA, b'\x91'), # //0xEF - 0x91
(_CONTRASTB, b'\x50'), # ;//0x11 - 0x50
(_CONTRASTC, b'\x7d'), # ;//0x48 - 0x7D
(_DISPLAYON, b''),
)
_ENCODE_PIXEL = ">H"
_ENCODE_POS = ">BB"

# pylint: disable-msg=useless-super-delegation, too-many-arguments
# super required to allow override of default values
# All arguments needed due to driver requiring all the given data to function
def __init__(self, spi, dc, cs, rst=None, width=96, height=64):
super().__init__(spi, dc, cs, rst, width, height)

def write(self, command=None, data=None):
"""write procedure specific to SSD1331"""
self.dc.value = command is None
with self.spi_device as spi:
if command is not None:
spi.write(bytearray([command]))
if data is not None:
spi.write(data)