2020-03-23 01:36 AM
I need to display large characters to show the dB of attenuation of my preampl.
I have found a good font but the BSP_LCD_DisplayStringAt and DrawChar are not able to use this font, only half of the left section of the character is print.
So I have develop a new function DrawCharNew().
Here there is also the debug program running on Cygwin64.
#include <stdio.h>
char Shruti_Bold_num_48x70[5044] ={
0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x7F,0xFC,0x00,0x00, 0x00,0x03,0xFF,0xFF,0x80,0x00, 0x00,0x0F,0xFF,0xFF,0xE0,0x00, 0x00,0x1F,0xFF,0xFF,0xF0,0x00, 0x00,0x3F,0xFF,0xFF,0xF8,0x00, 0x00,0x7F,0xFF,0xFF,0xFC,0x00, 0x00,0xFF,0xFF,0xFF,0xFE,0x00, 0x01,0xFF,0xFF,0xFF,0xFF,0x00, 0x03,0xFF,0xF8,0x1F,0xFF,0x80, 0x03,0xFF,0xC0,0x07,0xFF,0x80, 0x07,0xFF,0x80,0x03,0xFF,0xC0, 0x07,0xFF,0x00,0x01,0xFF,0xC0, 0x0F,0xFF,0x00,0x00,0xFF,0xE0, 0x0F,0xFE,0x00,0x00,0xFF,0xE0, 0x0F,0xFE,0x00,0x00,0x7F,0xF0, 0x1F,0xFC,0x00,0x00,0x7F,0xF0, 0x1F,0xFC,0x00,0x00,0x7F,0xF0,0x1F,0xFC,0x00,0x00,0x3F,0xF8,0x1F,0xF8,0x00,0x00,0x3F,0xF8,0x3F,0xF8,0x00,0x00,0x3F,0xF8,0x3F,0xF8,0x00,0x00,0x3F,0xF8,0x3F,0xF8,0x00,0x00,0x3F,0xF8,0x3F,0xF8,0x00,0x00,0x1F,0xFC,0x3F,0xF0,0x00,0x00,0x1F,0xFC,0x3F,0xF0,0x00,0x00,0x1F,0xFC,0x7F,0xF0,0x00,0x00,0x1F,0xFC,0x7F,0xF0,0x00,0x00,0x1F,0xFC,0x7F,0xF0,0x00,0x00,0x1F,0xFC,0x7F,0xF0,0x00,0x00,0x1F,0xFC,0x7F,0xF0,0x00,0x00,0x1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0xFF,0x00,0x00,0x00,0x00,0x3F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 // 0
};
char Font_17x24[] = {
// @1152 '0' (17 pixels wide)
0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, //
0x03, 0xC0, 0x00, // ####
0x07, 0xE0, 0x00, // ######
0x0C, 0x30, 0x00, // ## ##
0x0C, 0x30, 0x00, // ## ##
0x18, 0x18, 0x00, // ## ##
0x18, 0x18, 0x00, // ## ##
0x18, 0x18, 0x00, // ## ##
0x18, 0x18, 0x00, // ## ##
0x18, 0x18, 0x00, // ## ##
0x18, 0x18, 0x00, // ## ##
0x18, 0x18, 0x00, // ## ##
0x0C, 0x30, 0x00, // ## ##
0x0C, 0x30, 0x00, // ## ##
0x07, 0xE0, 0x00, // ######
0x03, 0xC0, 0x00, // ####
0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, //
0x00, 0x00, 0x00, //
};
int main()
{
int i, j;
//int w = 17, h = 24;
int w = 48, h = 70;
int s = (w + 7) / 8;
for (i = j = 0; i < (s * h); i++)
{
//print_bits(Font_17x24[i]);
print_bits(Shruti_Bold_num_48x70[i]);
if (j == (s - 1))
{
printf("\n");
j=0;
}
else
{
j++;
}
}
}
void print_bits(unsigned char x)
{
int i;
for(i=8*sizeof(x)-1; i>=0; i--) {
(x & (1 << i)) ? putchar('X') : putchar(' ');
}
printf(" ");
}
2020-03-23 01:39 AM
Here the STM32 code to solve the problem.
void DrawCharNew(uint16_t Xpos, uint16_t Ypos, uint8_t ind, sFONT * font)
{
uint32_t j = 0, k = 0;
unsigned char x;
int i;
int s;
uint16_t height;
uint16_t width;
uint8_t * c;
height = font->Height;
width = font->Width;
s = (width + 7) / 8;
c = (uint8_t *)&font->table[ind * height * ((width + 7) / 8)];
for (k = j = 0; k < (s * height); k++)
{
x = *((unsigned char *)c + k);
for(i = 7; i >= 0; i--)
{
if (x & (1 << i))
BSP_LCD_DrawPixel((Xpos + (7 - i)) + (j * 8), Ypos, LCD_COLOR_BLACK);
else
BSP_LCD_DrawPixel((Xpos + (7 - i)) + (j * 8), Ypos, LCD_COLOR_WHITE);
}
if (j == (s - 1))
{
Ypos++;
j=0;
}
else
{
j++;
}
}
}
2020-03-23 01:41 AM
const uint8_t Shruti_Bold_num_48x70[] ={
//0x30,0x46,0x30,0x0B,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFC,0x00,0x00,0x00,0x03,0xFF,0xFF,0x80,0x00,0x00,0x0F,0xFF,0xFF,0xE0,0x00,0x00,0x1F,0xFF,0xFF,0xF0,0x00,0x00,0x3F,0xFF,0xFF,0xF8,0x00,0x00,0x7F,0xFF,0xFF,0xFC,0x00,0x00,0xFF,0xFF,0xFF,0xFE,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0x00,0x03,0xFF,0xF8,0x1F,0xFF,0x80,0x03,0xFF,0xC0,0x07,0xFF,0x80,0x07,0xFF,0x80,0x03,0xFF,0xC0,0x07,0xFF,0x00,0x01,0xFF,0xC0,0x0F,0xFF,0x00,0x00,0xFF,0xE0,0x0F,0xFE,0x00,0x00,0xFF,0xE0,0x0F,0xFE,0x00,0x00,0x7F,0xF0,0x1F,0xFC,0x00,0x00,0x7F,0xF0,0x1F,0xFC,0x00,0x00,0x7F,0xF0,0x1F,0xFC,0x00,0x00,0x3F,0xF8,0x1F,0xF8,0x00,0x00,0x3F,0xF8,0x3F,0xF8,0x00,0x00,0x3F,0xF8,0x3F,0xF8,0x00,0x00,0x3F,0xF8,0x3F,0xF8,0x00,0x00,0x3F,0xF8,0x3F,0xF8,0x00,0x00,0x1F,0xFC,0x3F,0xF0,0x00,0x00,0x1F,0xFC,0x3F,0xF0,0x00,0x00,0x1F,0xFC,0x7F,0xF0,0x00,0x00,0x1F,0xFC,0x7F,0xF0,0x00,0x00,0x1F,0xFC,0x7F,0xF0,0x00,0x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F,0xFF,0xFF,0xF0,0x00,0x00,0x07,0xFF,0xFF,0xE0,0x00,0x00,0x01,0xFF,0xFF,0x00,0x00,0x00,0x00,0x3F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0
.....
};
sFONT Font48 = {
Shruti_Bold_num_48x70,
48, /* Width */
70, /* Height */
};