From 8fa03fee77ff5ac49a0daa544951468f4c193b68 Mon Sep 17 00:00:00 2001 From: Peter Hinch Date: Fri, 15 Sep 2017 14:51:49 +0100 Subject: [PATCH] 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. --- drivers/display/ssd1306.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/display/ssd1306.py b/drivers/display/ssd1306.py index 53bcb0d2de..d65f2d3502 100644 --- a/drivers/display/ssd1306.py +++ b/drivers/display/ssd1306.py @@ -32,7 +32,21 @@ class SSD1306: self.external_vcc = external_vcc self.pages = self.height // 8 self.buffer = bytearray(self.pages * self.width) - self.framebuf = framebuf.FrameBuffer(self.buffer, self.width, self.height, framebuf.MVLSB) + fb = framebuf.FrameBuffer(self.buffer, self.width, self.height, framebuf.MONO_VLSB) + self.framebuf = fb + # Provide methods for accessing FrameBuffer graphics primitives. This is a + # workround because inheritance from a native class is currently unsupported. + # http://docs.micropython.org/en/latest/pyboard/library/framebuf.html + self.fill = fb.fill + self.pixel = fb.pixel + self.hline = fb.hline + self.vline = fb.vline + self.line = fb.line + self.rect = fb.rect + self.fill_rect = fb.fill_rect + self.text = fb.text + self.scroll = fb.scroll + self.blit = fb.blit self.poweron() self.init_display() @@ -88,18 +102,6 @@ class SSD1306: self.write_cmd(self.pages - 1) self.write_data(self.buffer) - def fill(self, col): - self.framebuf.fill(col) - - def pixel(self, x, y, col): - self.framebuf.pixel(x, y, col) - - def scroll(self, dx, dy): - self.framebuf.scroll(dx, dy) - - def text(self, string, x, y, col=1): - self.framebuf.text(string, x, y, col) - class SSD1306_I2C(SSD1306): def __init__(self, width, height, i2c, addr=0x3c, external_vcc=False):