Skip to content

Commit 8fa03fe

Browse files
peterhinchdpgeorge
authored andcommitted
drivers/display/ssd1306.py: Improve performance of graphics methods.
It removes the need for a wrapper Python function to dispatch to the framebuf method which makes each function call a bit faster, roughly 2.5x. This patch also adds the rest of the framebuf methods to the SSD class.
1 parent d29b709 commit 8fa03fe

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

drivers/display/ssd1306.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,21 @@ def __init__(self, width, height, external_vcc):
3232
self.external_vcc = external_vcc
3333
self.pages = self.height // 8
3434
self.buffer = bytearray(self.pages * self.width)
35-
self.framebuf = framebuf.FrameBuffer(self.buffer, self.width, self.height, framebuf.MVLSB)
35+
fb = framebuf.FrameBuffer(self.buffer, self.width, self.height, framebuf.MONO_VLSB)
36+
self.framebuf = fb
37+
# Provide methods for accessing FrameBuffer graphics primitives. This is a
38+
# workround because inheritance from a native class is currently unsupported.
39+
# http://docs.micropython.org/en/latest/pyboard/library/framebuf.html
40+
self.fill = fb.fill
41+
self.pixel = fb.pixel
42+
self.hline = fb.hline
43+
self.vline = fb.vline
44+
self.line = fb.line
45+
self.rect = fb.rect
46+
self.fill_rect = fb.fill_rect
47+
self.text = fb.text
48+
self.scroll = fb.scroll
49+
self.blit = fb.blit
3650
self.poweron()
3751
self.init_display()
3852

@@ -88,18 +102,6 @@ def show(self):
88102
self.write_cmd(self.pages - 1)
89103
self.write_data(self.buffer)
90104

91-
def fill(self, col):
92-
self.framebuf.fill(col)
93-
94-
def pixel(self, x, y, col):
95-
self.framebuf.pixel(x, y, col)
96-
97-
def scroll(self, dx, dy):
98-
self.framebuf.scroll(dx, dy)
99-
100-
def text(self, string, x, y, col=1):
101-
self.framebuf.text(string, x, y, col)
102-
103105

104106
class SSD1306_I2C(SSD1306):
105107
def __init__(self, width, height, i2c, addr=0x3c, external_vcc=False):

0 commit comments

Comments
 (0)