diff options
author | Peter Hinch <peter@hinch.me.uk> | 2017-09-15 14:51:49 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-09-25 16:13:32 +1000 |
commit | 8fa03fee77ff5ac49a0daa544951468f4c193b68 (patch) | |
tree | 0c669fec43e0a78d6812ecbe43bcd20dedb8db33 | |
parent | d29b7096424638f89d82a2a4ce295e5fd9325fa2 (diff) |
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.
-rw-r--r-- | drivers/display/ssd1306.py | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/drivers/display/ssd1306.py b/drivers/display/ssd1306.py index 53bcb0d2d..d65f2d350 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): |