Created
April 5, 2021 13:48
-
-
Save macbre/8207063f0f775727d9a56cac9e45cc65 to your computer and use it in GitHub Desktop.
Font encoder for MAX7129
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fonts are encoded by columns | |
# first value is the first column from the left | |
# now, we want to have them encode by rows (starting from the botton one) | |
# { 0x00, 0xf8, 0x88, 0x88, 0x88, 0x88, 0x88, 0xf8 }, // 0 | |
# see https://github.com/rm-hull/luma.led_matrix/blob/0.2.3/max7219/font.py#L84-L93 | |
CP437_FONT = [ | |
[0x3E, 0x7F, 0x71, 0x59, 0x4D, 0x7F, 0x3E, 0x00], # '0' | |
[0x40, 0x42, 0x7F, 0x7F, 0x40, 0x40, 0x00, 0x00], # '1' | |
[0x62, 0x73, 0x59, 0x49, 0x6F, 0x66, 0x00, 0x00], # '2' | |
[0x22, 0x63, 0x49, 0x49, 0x7F, 0x36, 0x00, 0x00], # '3' | |
[0x18, 0x1C, 0x16, 0x53, 0x7F, 0x7F, 0x50, 0x00], # '4' | |
[0x27, 0x67, 0x45, 0x45, 0x7D, 0x39, 0x00, 0x00], # '5' | |
[0x3C, 0x7E, 0x4B, 0x49, 0x79, 0x30, 0x00, 0x00], # '6' | |
[0x03, 0x03, 0x71, 0x79, 0x0F, 0x07, 0x00, 0x00], # '7' | |
[0x36, 0x7F, 0x49, 0x49, 0x7F, 0x36, 0x00, 0x00], # '8' | |
[0x06, 0x4F, 0x49, 0x69, 0x3F, 0x1E, 0x00, 0x00], # '9' | |
]; | |
# rotate clockwise, 90-deg | |
for i, columns in enumerate(CP437_FONT): | |
entry = [0] * 8; | |
# rows are numbered from the bottom to the top | |
for row in range(0, 8): | |
# bits are numbered from the left side of the 8x8 led segment | |
for bit in range(0, 8): | |
# which bit to take from the CP437_FONT? | |
if columns[bit] & (1 << row): | |
entry[7-row] |= 1 << bit | |
print(' { ', end='') | |
print(', '.join(map(lambda i: '0x%02x' % i, entry)), end='') | |
print(f' }}, // {i}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment