summaryrefslogtreecommitdiffstatshomepage
path: root/drivers
diff options
context:
space:
mode:
authorRadomir Dopieralski <openstack@sheep.art.pl>2016-05-22 22:50:38 +0200
committerDamien George <damien.p.george@gmail.com>2016-06-03 11:13:17 +0100
commit43c8f545d27d41c378b3765bfdb8f8c122d73dfc (patch)
tree00bdcbdba92e1c17bbbfd11d7a03d9fae7047cd3 /drivers
parentddadbaed06913dd05f786a30bca820f8a58c11c3 (diff)
downloadmicropython-43c8f545d27d41c378b3765bfdb8f8c122d73dfc.tar.gz
micropython-43c8f545d27d41c378b3765bfdb8f8c122d73dfc.zip
drivers/display/ssd1306: update SSD1306_SPI to work with new API
Makes it work on the ESP8266.
Diffstat (limited to 'drivers')
-rw-r--r--drivers/display/ssd1306.py31
1 files changed, 20 insertions, 11 deletions
diff --git a/drivers/display/ssd1306.py b/drivers/display/ssd1306.py
index 852e015a5e..3bccf72dae 100644
--- a/drivers/display/ssd1306.py
+++ b/drivers/display/ssd1306.py
@@ -3,6 +3,7 @@
import time
import framebuf
+
# register definitions
SET_CONTRAST = const(0x81)
SET_ENTIRE_ON = const(0xa4)
@@ -22,6 +23,7 @@ SET_PRECHARGE = const(0xd9)
SET_VCOM_DESEL = const(0xdb)
SET_CHARGE_PUMP = const(0x8d)
+
class SSD1306:
def __init__(self, height, external_vcc):
self.width = 128
@@ -91,6 +93,7 @@ class SSD1306:
def text(self, string, x, y, col=1):
self.framebuf.text(string, x, y, col)
+
class SSD1306_I2C(SSD1306):
def __init__(self, height, i2c, addr=0x3c, external_vcc=False):
self.i2c = i2c
@@ -114,27 +117,34 @@ class SSD1306_I2C(SSD1306):
def poweron(self):
pass
-# TODO convert this class to use the new hardware API
+
class SSD1306_SPI(SSD1306):
- def __init__(self, height, spi, dc, res, cs=None, external_vcc=False):
- rate = 10 * 1024 * 1024
- spi.init(spi.MASTER, baudrate=rate, polarity=0, phase=0)
- dc.init(dc.OUT, dc.PULL_NONE, value=0)
- res.init(res.OUT, dc.PULL_NONE, value=0)
- if cs is not None:
- cs.init(cs.OUT, cs.PULL_NONE, value=0)
+ def __init__(self, height, spi, dc, res, cs, external_vcc=False):
+ self.rate = 10 * 1024 * 1024
+ dc.init(dc.OUT, value=0)
+ res.init(res.OUT, value=0)
+ cs.init(cs.OUT, value=1)
self.spi = spi
self.dc = dc
self.res = res
+ self.cs = cs
super().__init__(height, external_vcc)
def write_cmd(self, cmd):
+ self.spi.init(baudrate=self.rate, polarity=0, phase=0)
+ self.cs.high()
self.dc.low()
- self.spi.send(cmd)
+ self.cs.low()
+ self.spi.write(bytearray([cmd]))
+ self.cs.high()
def write_data(self, buf):
+ self.spi.init(baudrate=self.rate, polarity=0, phase=0)
+ self.cs.high()
self.dc.high()
- self.spi.send(buf)
+ self.cs.low()
+ self.spi.write(buf)
+ self.cs.high()
def poweron(self):
self.res.high()
@@ -142,4 +152,3 @@ class SSD1306_SPI(SSD1306):
self.res.low()
time.sleep_ms(10)
self.res.high()
- time.sleep_ms(10)