Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate FPGA code to implement a character set
# Process font file to generate FPGA code
# Font from https://github.com/dhepper/font8x8/blob/master/font8x8_basic.h
import re
chars = []
for line in open('font8x8_basic.h').readlines():
m = re.search('{([\s0-9A-Fa-fx,]*)}', line)
if m:
chars.append([int(x, 16) for x in m.group(1).split(',')])
# The characters to output
cset = "0123456789BFiuz"
for cnum in range(0, len(cset)):
ch = cset[cnum]
print
for row in range(0, 8):
bits = ('{:08b}'.format(chars[ord(ch)][row]))[::-1]
case = '{:04b}{:03b}'.format(cnum, row)
print ' 7\'b%s: pixels = 8\'b%s; // %s' % (case, bits, bits.replace('1', 'X').replace('0', ' '))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment