Skip to content

Instantly share code, notes, and snippets.

@smiler
Forked from alterscape/gist:6009019
Created July 16, 2013 14:30
Show Gist options
  • Save smiler/6009255 to your computer and use it in GitHub Desktop.
Save smiler/6009255 to your computer and use it in GitHub Desktop.
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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment