Skip to content

Commit 43c8f54

Browse files
deshipudpgeorge
authored andcommitted
drivers/display/ssd1306: update SSD1306_SPI to work with new API
Makes it work on the ESP8266.
1 parent ddadbae commit 43c8f54

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

drivers/display/ssd1306.py

+20-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import time
44
import framebuf
55

6+
67
# register definitions
78
SET_CONTRAST = const(0x81)
89
SET_ENTIRE_ON = const(0xa4)
@@ -22,6 +23,7 @@
2223
SET_VCOM_DESEL = const(0xdb)
2324
SET_CHARGE_PUMP = const(0x8d)
2425

26+
2527
class SSD1306:
2628
def __init__(self, height, external_vcc):
2729
self.width = 128
@@ -91,6 +93,7 @@ def scroll(self, dx, dy):
9193
def text(self, string, x, y, col=1):
9294
self.framebuf.text(string, x, y, col)
9395

96+
9497
class SSD1306_I2C(SSD1306):
9598
def __init__(self, height, i2c, addr=0x3c, external_vcc=False):
9699
self.i2c = i2c
@@ -114,32 +117,38 @@ def write_data(self, buf):
114117
def poweron(self):
115118
pass
116119

117-
# TODO convert this class to use the new hardware API
120+
118121
class SSD1306_SPI(SSD1306):
119-
def __init__(self, height, spi, dc, res, cs=None, external_vcc=False):
120-
rate = 10 * 1024 * 1024
121-
spi.init(spi.MASTER, baudrate=rate, polarity=0, phase=0)
122-
dc.init(dc.OUT, dc.PULL_NONE, value=0)
123-
res.init(res.OUT, dc.PULL_NONE, value=0)
124-
if cs is not None:
125-
cs.init(cs.OUT, cs.PULL_NONE, value=0)
122+
def __init__(self, height, spi, dc, res, cs, external_vcc=False):
123+
self.rate = 10 * 1024 * 1024
124+
dc.init(dc.OUT, value=0)
125+
res.init(res.OUT, value=0)
126+
cs.init(cs.OUT, value=1)
126127
self.spi = spi
127128
self.dc = dc
128129
self.res = res
130+
self.cs = cs
129131
super().__init__(height, external_vcc)
130132

131133
def write_cmd(self, cmd):
134+
self.spi.init(baudrate=self.rate, polarity=0, phase=0)
135+
self.cs.high()
132136
self.dc.low()
133-
self.spi.send(cmd)
137+
self.cs.low()
138+
self.spi.write(bytearray([cmd]))
139+
self.cs.high()
134140

135141
def write_data(self, buf):
142+
self.spi.init(baudrate=self.rate, polarity=0, phase=0)
143+
self.cs.high()
136144
self.dc.high()
137-
self.spi.send(buf)
145+
self.cs.low()
146+
self.spi.write(buf)
147+
self.cs.high()
138148

139149
def poweron(self):
140150
self.res.high()
141151
time.sleep_ms(1)
142152
self.res.low()
143153
time.sleep_ms(10)
144154
self.res.high()
145-
time.sleep_ms(10)

0 commit comments

Comments
 (0)