Skip to content

Use saner names for the pin attributes #4

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 16, 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
33 changes: 24 additions & 9 deletions adafruit_ssd1306.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,14 @@ def text(self, string, xpos, ypos, col=1):
self.framebuf.text(string, xpos, ypos, col)

class SSD1306_I2C(_SSD1306):
""" I2C class for SSD1306
"""
I2C class for SSD1306

:param width: the width of the physical screen in pixels,
:param height: the height of the physical screen in pixels,
:param i2c: the I2C peripheral to use,
:param addr: the 8-bit bus address of the device,
:param external_vcc: whether external high-voltage source is connected.
"""

def __init__(self, width, height, i2c, *, addr=0x3c, external_vcc=False):
Expand Down Expand Up @@ -167,7 +174,15 @@ def poweron(self):

#pylint: disable-msg=too-many-arguments
class SSD1306_SPI(_SSD1306):
""" SPI class for SSD1306
"""
SPI class for SSD1306

:param width: the width of the physical screen in pixels,
:param height: the height of the physical screen in pixels,
:param spi: the SPI peripheral to use,
:param dc: the data/command pin to use (often labeled "D/C"),
:param res: the reset pin to use,
:param cs: the chip-select pin to use (sometimes labeled "SS").
"""
def __init__(self, width, height, spi, dc, res, cs, *,
external_vcc=False, baudrate=8000000, polarity=0, phase=0):
Expand All @@ -176,28 +191,28 @@ def __init__(self, width, height, spi, dc, res, cs, *,
res.switch_to_output(value=0)
self.spi_device = spi_device.SPIDevice(spi, cs, baudrate=baudrate,
polarity=polarity, phase=phase)
self.d_or_c = dc
self.res = res
self.dc_pin = dc
self.reset_pin = res
self.buffer = bytearray((height // 8) * width)
framebuffer = framebuf.FrameBuffer1(self.buffer, width, height)
super().__init__(framebuffer, width, height, external_vcc)

def write_cmd(self, cmd):
"""Send a command to the SPI device"""
self.d_or_c.value = 0
self.dc_pin.value = 0
with self.spi_device as spi:
spi.write(bytearray([cmd]))

def write_framebuf(self):
"""write to the frame buffer via SPI"""
self.d_or_c.value = 1
self.dc_pin.value = 1
with self.spi_device as spi:
spi.write(self.buffer)

def poweron(self):
"""Turn power off on the device"""
self.res.value = 1
self.reset_pin.value = 1
time.sleep(0.001)
self.res.value = 0
self.reset_pin.value = 0
time.sleep(0.010)
self.res.value = 1
self.reset_pin.value = 1