I would like to refer to two postings on this board, related to efficiently using graphical displays, and in particular, rendering fonts. One of them is quite old, in which @pythoncoder was circulating his idea of storing fonts in the flash viewtopic.php?f=3&t=2667&. He also presented a python implementation, which, however, suffered from the fact that it is interpreted, therefore, relatively slow. I mentioned some weeks ago that this issue can be alleviated in a C module, and set out to implement it. I wanted to retain the elegance of Peter's font description, so the C code is really nothing else than an almost literal translation of the relevant parts of https://github.com/peterhinch/micropyth ... /writer.py This also means that the font generator routine in https://github.com/peterhinch/micropyth ... t_to_py.py should still be applicable.
I have dumped my code onto https://github.com/v923z/ufont-micropython. If someone doesn't want to compile the code, I can upload the binary firmware to dropbox or something similar.
Since one of the typical uses of a microcontroller is to display the results of measurements, the module contains a scalable set of seven-segment fonts for numbers. These can be rendered by calling
Code: Select all
from ufont import seven_segment
buffer = bytearray(1000)
memview = memoryview(buffer)
foreground = bytearray([200, 200])
background = bytearray([0, 0])
size, weight = 20, 3
seven_segment(memview, '1', size, weight, foreground, background)
By calling the render method, arbitrary fonts can also be generated, if one passes the font description to the method as
Code: Select all
from ufont import render
buffer = bytearray(1000)
memview = memoryview(buffer)
pattern = get_character_from(character, font_descriptor)
height = 20
foreground = bytearray([200, 200])
background = bytearray([0, 0])
render(memview, pattern, height, foreground, background)
Typical rendering times are 200 us for a 20-point font, thus one should be able to display a single character in less than a ms. As far as I remember, Peter mentioned 10 ms rendering times for colour displays.
A complete high-level implementation of the driver, as well as detailed speed test can be found under https://github.com/v923z/micropython-te ... test.ipynb
I would appreciate any comments or recommendations.
Best,
Zoltán