Skip to content

Instantly share code, notes, and snippets.

Created April 4, 2018 03:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Generate FPGA code to implement a character set
# Process font file to generate FPGA code
# Font from
import re
chars = []
for line in open('font8x8_basic.h').readlines():
m ='{([\s0-9A-Fa-fx,]*)}', line)
if m:
chars.append([int(x, 16) for x in',')])
# The characters to output
cset = "0123456789BFiuz"
for cnum in range(0, len(cset)):
ch = cset[cnum]
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