Skip to content

Instantly share code, notes, and snippets.

@alterscape
Created July 16, 2013 14:07
Show Gist options
  • Save alterscape/6009019 to your computer and use it in GitHub Desktop.
Save alterscape/6009019 to your computer and use it in GitHub Desktop.
Debugging LCD font rendering routine..
static void lcd_font_char_xy(int xPos, int yPos, char character, FONT_INFO* fontInfo, uint16_t fgColor, uint16_t bgColor)
{
unsigned short i = 0;
unsigned short j = 0;
unsigned short height = fontInfo->heightPages * 8;
unsigned short width;
unsigned short tableOffset = character - fontInfo->startChar;//32;
FONT_CHAR_INFO fontCharInfo = fontInfo->charInfo[(tableOffset)];
uint16_t offset = fontCharInfo.offset;
uint16_t lineOffset;
unsigned short bitOffset;
unsigned short byteOffset;
width = fontCharInfo.widthBits;
unsigned char *buffer = &fontInfo->data[offset];
//const unsigned char *buffer = //AsciiLib[(c - 32)] ;
unsigned char tmp_char = 0;
// TODO handle space character.
if (character == 32)
{
return;
}
printf("char: '%c'; ascii: %d; table offset: %d; offset: %d; width: %d\n", character, (int)character, tableOffset, offset, width);
for (i = 0; i < height; i++)
{
lineOffset = i * width;
tmp_char=buffer[lineOffset];
for (j = 0; j < width; j++)
{
// iterate over each horiz bit
byteOffset = j / 8;
bitOffset = j % 8;
tmp_char = fontInfo->data[offset + lineOffset + byteOffset]; //*(buffer + lineOffset + byteOffset);
if ( (tmp_char >> 7 - bitOffset) & 0x01)
{
lcd_set_cursor(xPos + j, yPos + i);
lcd_write_ram_prepare();
write_data(fgColor);
}
//uint16_t col = ( (tmp_char >> 7-j) & 0x01) ? charColor : bkColor;
//write_data(col);
}
}
}
@alterscape
Copy link
Author

Definition of FONT_INFO:

// This structure describes a single character's display information
typedef struct
{
const uint8_t widthBits; // width, in bits (or pixels), of the character
const uint16_t offset; // offset of the character's bitmap, in bytes, into the the FONT_INFO's data array

} FONT_CHAR_INFO;

// Describes a single font
typedef struct
{
const uint8_t heightPages; // height, in pages (8 pixels), of the font's characters
const uint8_t startChar; // the first character in the font (e.g. in charInfo and data)
const uint8_t endChar; // the last character in the font
const uint8_t spacePixels; // number of pixels that a space character takes up
const FONT_CHAR_INFO* charInfo; // pointer to array of char information
const uint8_t* data; // pointer to generated array of character visual representation

} FONT_INFO;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment