Wakeup Light with touch user interface, anti-aliased Font, SD card access and RTC usage on STM32F746NG-DISCO board

Dependencies:   BSP_DISCO_F746NG_patch_fixed LCD_DISCO_F746NG TS_DISCO_F746NG FATFileSystem TinyJpgDec_interwork mbed-src

Committer:
the_sz
Date:
Sun Feb 21 04:26:17 2016 +0000
Revision:
14:2044ad5cd3fe
Parent:
13:811a5c5b3fd6
all fonts are working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
the_sz 13:811a5c5b3fd6 1 //
the_sz 13:811a5c5b3fd6 2 // use http://www.eran.io/the-dot-factory-an-lcd-font-and-image-generator/ to create the font definitions
the_sz 13:811a5c5b3fd6 3 // plus modify output:
the_sz 13:811a5c5b3fd6 4 // - char height: in bits
the_sz 13:811a5c5b3fd6 5 // - font height: don't display
the_sz 13:811a5c5b3fd6 6 // - generate space bitmap
the_sz 13:811a5c5b3fd6 7 //
the_sz 13:811a5c5b3fd6 8 // - remove \ comment from const FONT_CHAR_INFO xxxDescriptors[]
the_sz 13:811a5c5b3fd6 9 // - rename fontxxx.c to fontxxx.cpp file
the_sz 13:811a5c5b3fd6 10 //
the_sz 13:811a5c5b3fd6 11
the_sz 13:811a5c5b3fd6 12 #include "FontX.h"
the_sz 13:811a5c5b3fd6 13
the_sz 13:811a5c5b3fd6 14 #include "stm32746g_discovery_lcd.h"
the_sz 14:2044ad5cd3fe 15 #include "debug.h"
the_sz 13:811a5c5b3fd6 16
the_sz 13:811a5c5b3fd6 17 #define CHAR_SPACE 2
the_sz 13:811a5c5b3fd6 18
the_sz 13:811a5c5b3fd6 19 static bool useAlias=true;
the_sz 13:811a5c5b3fd6 20
the_sz 13:811a5c5b3fd6 21 uint32_t FontX_GetLength(char *Text,const FONT_INFO *pFont)
the_sz 13:811a5c5b3fd6 22 {
the_sz 13:811a5c5b3fd6 23 uint32_t length;
the_sz 13:811a5c5b3fd6 24 uint32_t index;
the_sz 13:811a5c5b3fd6 25
the_sz 13:811a5c5b3fd6 26 length=0;
the_sz 13:811a5c5b3fd6 27
the_sz 13:811a5c5b3fd6 28 while ((*Text)!='\0')
the_sz 13:811a5c5b3fd6 29 {
the_sz 14:2044ad5cd3fe 30 if (((*Text)>=pFont->StartCharacter) && (((*Text)<=pFont->EndCharacter) || ((pFont->EndCharacter>0x80)))) // mbed used a different character table than TheDotFactory.exe
the_sz 13:811a5c5b3fd6 31 {
the_sz 13:811a5c5b3fd6 32 index=(*Text)-pFont->StartCharacter;
the_sz 13:811a5c5b3fd6 33 length+=pFont->Descriptors[index].Charwidth;
the_sz 13:811a5c5b3fd6 34 }
the_sz 13:811a5c5b3fd6 35
the_sz 13:811a5c5b3fd6 36 length+=CHAR_SPACE;
the_sz 13:811a5c5b3fd6 37
the_sz 14:2044ad5cd3fe 38 if (useAlias==true)
the_sz 14:2044ad5cd3fe 39 length+=CHAR_SPACE;
the_sz 14:2044ad5cd3fe 40
the_sz 13:811a5c5b3fd6 41 Text++;
the_sz 13:811a5c5b3fd6 42 }
the_sz 14:2044ad5cd3fe 43
the_sz 14:2044ad5cd3fe 44 if (useAlias==true)
the_sz 14:2044ad5cd3fe 45 length/=2;
the_sz 14:2044ad5cd3fe 46
the_sz 13:811a5c5b3fd6 47 return length;
the_sz 13:811a5c5b3fd6 48 }
the_sz 13:811a5c5b3fd6 49
the_sz 13:811a5c5b3fd6 50 uint32_t FontX_GetHeight(const FONT_INFO *pFont)
the_sz 13:811a5c5b3fd6 51 {
the_sz 14:2044ad5cd3fe 52 uint32_t height;
the_sz 14:2044ad5cd3fe 53
the_sz 14:2044ad5cd3fe 54 height=pFont->Descriptors[0].Charheight;
the_sz 14:2044ad5cd3fe 55
the_sz 14:2044ad5cd3fe 56 if (useAlias==true)
the_sz 14:2044ad5cd3fe 57 height/=2;
the_sz 14:2044ad5cd3fe 58
the_sz 14:2044ad5cd3fe 59 return height;
the_sz 13:811a5c5b3fd6 60 }
the_sz 13:811a5c5b3fd6 61
the_sz 13:811a5c5b3fd6 62 void FontX_DisplayStringAt(uint16_t Xpos,uint16_t Ypos,uint16_t width,char *Text,FONTX_ALIGNMENT_ENUM Alignment,const FONT_INFO *pFont,uint32_t colorText,uint32_t colorBack)
the_sz 13:811a5c5b3fd6 63 {
the_sz 13:811a5c5b3fd6 64 uint32_t xsize = 0;
the_sz 14:2044ad5cd3fe 65
the_sz 13:811a5c5b3fd6 66 /* get pixel length */
the_sz 13:811a5c5b3fd6 67 xsize = FontX_GetLength(Text,pFont);
the_sz 14:2044ad5cd3fe 68
the_sz 13:811a5c5b3fd6 69 switch (Alignment)
the_sz 13:811a5c5b3fd6 70 {
the_sz 13:811a5c5b3fd6 71 case ALIGN_CENTER:
the_sz 13:811a5c5b3fd6 72 Xpos+=(width-xsize)/2;
the_sz 13:811a5c5b3fd6 73 break;
the_sz 13:811a5c5b3fd6 74
the_sz 13:811a5c5b3fd6 75 case ALIGN_RIGHT:
the_sz 13:811a5c5b3fd6 76 Xpos=width-xsize-Xpos;
the_sz 13:811a5c5b3fd6 77 break;
the_sz 13:811a5c5b3fd6 78
the_sz 13:811a5c5b3fd6 79 case ALIGN_LEFT:
the_sz 13:811a5c5b3fd6 80 default:
the_sz 13:811a5c5b3fd6 81 break;
the_sz 13:811a5c5b3fd6 82 }
the_sz 13:811a5c5b3fd6 83
the_sz 13:811a5c5b3fd6 84 /* send the string character by character on LCD */
the_sz 13:811a5c5b3fd6 85 while ((*Text)!='\0')
the_sz 13:811a5c5b3fd6 86 {
the_sz 13:811a5c5b3fd6 87 /* display one character on LCD */
the_sz 13:811a5c5b3fd6 88 Xpos+=FontX_DisplayChar(Xpos,Ypos,*Text,pFont,colorText,colorBack);
the_sz 13:811a5c5b3fd6 89
the_sz 13:811a5c5b3fd6 90 /* point on the next character */
the_sz 13:811a5c5b3fd6 91 Text++;
the_sz 13:811a5c5b3fd6 92 }
the_sz 13:811a5c5b3fd6 93 }
the_sz 13:811a5c5b3fd6 94
the_sz 13:811a5c5b3fd6 95 uint32_t FontX_DisplayChar(uint16_t Xpos,uint16_t Ypos,char Ascii,const FONT_INFO *pFont,uint32_t colorText,uint32_t colorBack)
the_sz 13:811a5c5b3fd6 96 {
the_sz 13:811a5c5b3fd6 97 uint32_t line;
the_sz 14:2044ad5cd3fe 98 uint32_t line2;
the_sz 13:811a5c5b3fd6 99 uint32_t index;
the_sz 13:811a5c5b3fd6 100 uint32_t offset;
the_sz 13:811a5c5b3fd6 101 uint32_t lineOffset;
the_sz 13:811a5c5b3fd6 102 uint32_t i;
the_sz 13:811a5c5b3fd6 103 uint32_t j;
the_sz 14:2044ad5cd3fe 104 uint32_t bits;
the_sz 14:2044ad5cd3fe 105 uint32_t color;
the_sz 14:2044ad5cd3fe 106 uint32_t red;
the_sz 14:2044ad5cd3fe 107 uint32_t green;
the_sz 14:2044ad5cd3fe 108 uint32_t blue;
the_sz 14:2044ad5cd3fe 109 uint32_t transparency;
the_sz 13:811a5c5b3fd6 110
the_sz 13:811a5c5b3fd6 111 if (Ascii<pFont->StartCharacter)
the_sz 13:811a5c5b3fd6 112 return 0;
the_sz 14:2044ad5cd3fe 113 if ((Ascii>pFont->EndCharacter) && (pFont->EndCharacter<0x80)) // mbed used a different character table than TheDotFactory.exe
the_sz 13:811a5c5b3fd6 114 return 0;
the_sz 13:811a5c5b3fd6 115
the_sz 13:811a5c5b3fd6 116 index=Ascii-pFont->StartCharacter;
the_sz 13:811a5c5b3fd6 117
the_sz 13:811a5c5b3fd6 118 lineOffset=8 * ((pFont->Descriptors[index].Charwidth + 7) / 8) - pFont->Descriptors[index].Charwidth;
the_sz 13:811a5c5b3fd6 119
the_sz 13:811a5c5b3fd6 120 offset=pFont->Descriptors[index].Offset;
the_sz 14:2044ad5cd3fe 121
the_sz 13:811a5c5b3fd6 122 for (i=0;i<pFont->Descriptors[index].Charheight;i++)
the_sz 13:811a5c5b3fd6 123 {
the_sz 13:811a5c5b3fd6 124 if (useAlias==true)
the_sz 13:811a5c5b3fd6 125 {
the_sz 13:811a5c5b3fd6 126 // get average of 2x2 pixel array
the_sz 14:2044ad5cd3fe 127 for (j=0;j<pFont->Descriptors[index].Charwidth;j+=2)
the_sz 13:811a5c5b3fd6 128 {
the_sz 14:2044ad5cd3fe 129 line=pFont->Bitmaps[offset+(j /8)];
the_sz 14:2044ad5cd3fe 130 line2=pFont->Bitmaps[offset+(j /8) + ((pFont->Descriptors[index].Charwidth + 7)/8)];
the_sz 14:2044ad5cd3fe 131
the_sz 14:2044ad5cd3fe 132 bits=0;
the_sz 14:2044ad5cd3fe 133 if (line & (1 << ((pFont->Descriptors[index].Charwidth - j + lineOffset - 1) % 8)))
the_sz 14:2044ad5cd3fe 134 bits++;
the_sz 14:2044ad5cd3fe 135 if (line & (1 << ((pFont->Descriptors[index].Charwidth - (j+1) + lineOffset - 1) % 8)))
the_sz 14:2044ad5cd3fe 136 bits++;
the_sz 14:2044ad5cd3fe 137 if (line2 & (1 << ((pFont->Descriptors[index].Charwidth - j + lineOffset - 1) % 8)))
the_sz 14:2044ad5cd3fe 138 bits++;
the_sz 14:2044ad5cd3fe 139 if (line2 & (1 << ((pFont->Descriptors[index].Charwidth - (j+1) + lineOffset - 1) % 8)))
the_sz 14:2044ad5cd3fe 140 bits++;
the_sz 14:2044ad5cd3fe 141
the_sz 14:2044ad5cd3fe 142 // alpha blend it to the current screen
the_sz 14:2044ad5cd3fe 143 if ((colorBack==0x00000000) || (colorBack==0x00000001))
the_sz 14:2044ad5cd3fe 144 color=BSP_LCD_ReadPixel((Xpos+(j/2)),Ypos);
the_sz 13:811a5c5b3fd6 145 else
the_sz 14:2044ad5cd3fe 146 color=colorBack;
the_sz 14:2044ad5cd3fe 147
the_sz 14:2044ad5cd3fe 148 if (colorBack==0x00000000)
the_sz 14:2044ad5cd3fe 149 transparency=255;
the_sz 14:2044ad5cd3fe 150 else if (colorBack==0x00000001)
the_sz 14:2044ad5cd3fe 151 transparency=255*bits/4;
the_sz 14:2044ad5cd3fe 152 else
the_sz 14:2044ad5cd3fe 153 transparency=255;
the_sz 14:2044ad5cd3fe 154
the_sz 14:2044ad5cd3fe 155 red=((color >> 16) & 0xFF)*(4-bits)/4;
the_sz 14:2044ad5cd3fe 156 green=((color >> 8) & 0xFF)*(4-bits)/4;
the_sz 14:2044ad5cd3fe 157 blue=(color & 0xFF)*(4-bits)/4;
the_sz 13:811a5c5b3fd6 158
the_sz 14:2044ad5cd3fe 159 red+=(((colorText >> 16) & 0xFF)*bits/4);
the_sz 14:2044ad5cd3fe 160 if (red>255)
the_sz 14:2044ad5cd3fe 161 red=255;
the_sz 14:2044ad5cd3fe 162 green+=(((colorText >> 8) & 0xFF)*bits/4);
the_sz 14:2044ad5cd3fe 163 if (green>255)
the_sz 14:2044ad5cd3fe 164 green=255;
the_sz 14:2044ad5cd3fe 165 blue+=((colorText & 0xFF)*bits/4);
the_sz 14:2044ad5cd3fe 166 if (blue>255)
the_sz 14:2044ad5cd3fe 167 blue=255;
the_sz 13:811a5c5b3fd6 168
the_sz 14:2044ad5cd3fe 169 // write pixel
the_sz 14:2044ad5cd3fe 170 BSP_LCD_DrawPixel((Xpos+(j/2)),Ypos,(transparency << 24) | (red << 16) | (green << 8) | blue);
the_sz 14:2044ad5cd3fe 171 }
the_sz 13:811a5c5b3fd6 172 }
the_sz 13:811a5c5b3fd6 173 else
the_sz 13:811a5c5b3fd6 174 {
the_sz 13:811a5c5b3fd6 175 for (j=0;j<pFont->Descriptors[index].Charwidth;j++)
the_sz 13:811a5c5b3fd6 176 {
the_sz 13:811a5c5b3fd6 177 if (line & (1 << (pFont->Descriptors[index].Charwidth - j + lineOffset - 1)))
the_sz 13:811a5c5b3fd6 178 {
the_sz 13:811a5c5b3fd6 179 BSP_LCD_DrawPixel((Xpos+j),Ypos,colorText);
the_sz 13:811a5c5b3fd6 180 }
the_sz 13:811a5c5b3fd6 181 else
the_sz 13:811a5c5b3fd6 182 {
the_sz 14:2044ad5cd3fe 183 if ((colorBack!=0x00000000) && (colorBack!=0x00000001))
the_sz 13:811a5c5b3fd6 184 BSP_LCD_DrawPixel((Xpos+j),Ypos,colorBack);
the_sz 13:811a5c5b3fd6 185 }
the_sz 13:811a5c5b3fd6 186 }
the_sz 13:811a5c5b3fd6 187 }
the_sz 13:811a5c5b3fd6 188
the_sz 13:811a5c5b3fd6 189 // fill char space area
the_sz 14:2044ad5cd3fe 190 if ((colorBack!=0x00000000) && (colorBack!=0x00000001))
the_sz 13:811a5c5b3fd6 191 {
the_sz 13:811a5c5b3fd6 192 for (j=0;j<CHAR_SPACE;j++)
the_sz 14:2044ad5cd3fe 193 BSP_LCD_DrawPixel((Xpos+(pFont->Descriptors[index].Charwidth/2)+j),Ypos,colorBack);
the_sz 13:811a5c5b3fd6 194 }
the_sz 13:811a5c5b3fd6 195
the_sz 13:811a5c5b3fd6 196 Ypos++;
the_sz 14:2044ad5cd3fe 197
the_sz 14:2044ad5cd3fe 198 offset+=((pFont->Descriptors[index].Charwidth + 7)/8);
the_sz 14:2044ad5cd3fe 199 if (useAlias==true)
the_sz 14:2044ad5cd3fe 200 offset+=((pFont->Descriptors[index].Charwidth + 7)/8);
the_sz 14:2044ad5cd3fe 201
the_sz 14:2044ad5cd3fe 202 if (useAlias==true)
the_sz 14:2044ad5cd3fe 203 i++;
the_sz 13:811a5c5b3fd6 204 }
the_sz 13:811a5c5b3fd6 205
the_sz 14:2044ad5cd3fe 206 i=pFont->Descriptors[index].Charwidth;
the_sz 14:2044ad5cd3fe 207
the_sz 14:2044ad5cd3fe 208 if (useAlias==true)
the_sz 14:2044ad5cd3fe 209 i/=2;
the_sz 14:2044ad5cd3fe 210
the_sz 14:2044ad5cd3fe 211 return i+CHAR_SPACE;
the_sz 13:811a5c5b3fd6 212 }