Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: RadarDemo 3DDemo RadarDemoT
RK043FN48H.cpp
00001 // 00002 // RK043FN48H.h - DISCO_F746NG display 00003 // 00004 00005 #include "RK043FN48H.h" 00006 00007 static Layer _selectedLayer = Foreground; 00008 00009 RK043FN48H::RK043FN48H() 00010 { 00011 BSP_LCD_Init(); 00012 00013 FbBackgroundStartAdress = LCD_FB_START_ADDRESS; 00014 FbForegroundStartAdress = LCD_FB_START_ADDRESS+(BSP_LCD_GetXSize()*BSP_LCD_GetYSize()*4); 00015 00016 BSP_LCD_LayerDefaultInit(0, FbBackgroundStartAdress); 00017 BSP_LCD_LayerDefaultInit(1, FbForegroundStartAdress); 00018 00019 BSP_LCD_DisplayOn(); 00020 00021 actualDrawProp[0].TextColor = LCD_COLOR_WHITE; 00022 actualDrawProp[0].BackColor = LCD_COLOR_BLACK; 00023 actualDrawProp[0].pFont = &Font16; // &LCD_DEFAULT_FONT 00024 _selectedFont[0] = GrFont(Courier16); 00025 00026 actualDrawProp[1].TextColor = LCD_COLOR_WHITE; // & ALPHA_MASK; 00027 actualDrawProp[1].BackColor = LCD_COLOR_BLACK & ALPHA_MASK; 00028 actualDrawProp[1].pFont = &Font16; // &LCD_DEFAULT_FONT 00029 _selectedFont[1] = GrFont(Courier16); 00030 00031 // Initialize layer 0 properties 00032 SetActiveLayer(Background); 00033 SetBackgroundColor(actualDrawProp[0].BackColor); 00034 Clear(); 00035 SetForegroundColor(actualDrawProp[0].TextColor); 00036 BSP_LCD_SetFont(&Font16); 00037 00038 // Initialize layer 1 properties 00039 SetActiveLayer(Foreground); 00040 SetBackgroundColor(actualDrawProp[1].BackColor); 00041 Clear(); 00042 SetForegroundColor(actualDrawProp[1].TextColor); 00043 BSP_LCD_SetFont(&Font16); 00044 00045 // Set layers transparency 00046 SetLayersTransparency(0xFF, 0xFF); 00047 SetLayersVisibility(true, true); 00048 00049 _cursorPos[Background].X = 0; 00050 _cursorPos[Background].Y = 0; 00051 _cursorPos[Foreground].X = 0; 00052 _cursorPos[Foreground].Y = 0; 00053 } 00054 00055 00056 RK043FN48H::~RK043FN48H() 00057 { 00058 BSP_LCD_DeInit(); 00059 } 00060 00061 00062 void RK043FN48H::Clear() 00063 { 00064 BSP_LCD_Clear(actualDrawProp[_selectedLayer].BackColor); 00065 } 00066 00067 00068 void RK043FN48H::Clear(uint32_t color) 00069 { 00070 BSP_LCD_Clear(color); 00071 } 00072 00073 00074 void RK043FN48H::ClearLayer(Layer layer, uint32_t color) 00075 { 00076 Layer oldLayer = GetActiveLayer(); 00077 00078 SetActiveLayer(layer); 00079 Clear(color); 00080 SetActiveLayer(oldLayer); 00081 } 00082 00083 00084 void RK043FN48H::SetBackgroundColor(uint32_t color) 00085 { 00086 actualDrawProp[_selectedLayer].BackColor = color; 00087 BSP_LCD_SetBackColor(actualDrawProp[_selectedLayer].BackColor); 00088 } 00089 00090 00091 void RK043FN48H::SetForegroundColor(uint32_t color) 00092 { 00093 actualDrawProp[_selectedLayer].TextColor = color; 00094 BSP_LCD_SetTextColor(actualDrawProp[_selectedLayer].TextColor); 00095 } 00096 00097 00098 void RK043FN48H::SetDrawColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) 00099 { 00100 // Calculate display pixel value for selected color 00101 uint32_t color = red << 16 | green << 8 | blue | alpha << 24; 00102 SetForegroundColor(color); 00103 } 00104 00105 uint32_t RK043FN48H::GetDrawColor() 00106 { 00107 return actualDrawProp[_selectedLayer].TextColor; 00108 } 00109 00110 void RK043FN48H::SetClearColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) 00111 { 00112 // Calculate display pixel value for selected color 00113 uint32_t color = red << 16 | green << 8 | blue | alpha << 24; 00114 SetBackgroundColor(color); 00115 } 00116 00117 uint32_t RK043FN48H::GetClearColor() 00118 { 00119 return actualDrawProp[_selectedLayer].BackColor; 00120 } 00121 00122 void RK043FN48H::DrawPoint(int posX, int posY, uint32_t colorMask) 00123 { 00124 if( posX >= 0 && posX < DisplayWidth() && posY >=0 && posY < DisplayHeight()) { 00125 BSP_LCD_DrawPixel(posX, posY, colorMask); 00126 } 00127 } 00128 00129 00130 //void RK043FN48H::DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) 00131 //{ 00132 // BSP_LCD_DrawLine(x1, y1, x2, y2); 00133 //} 00134 00135 00136 void RK043FN48H::CopyBitmap(Layer layer, uint8_t * bitmap, uint32_t width, uint32_t height, uint32_t rgbGolorCode) 00137 { 00138 // Check size 00139 if(width > DisplayWidth() || height > DisplayHeight()) 00140 return; 00141 00142 ClearLayer(layer, 0x00000000); 00143 00144 uint16_t maxCol = width / 8; // 60 columns 00145 if ((width % 8) != 0) 00146 { 00147 maxCol++; 00148 } 00149 00150 for (int y = 0; y < height; y++) { 00151 for (int col = 0; col < maxCol; col++) { 00152 uint8_t shift = bitmap[y*maxCol + col]; 00153 for (int pos = 0; pos < 8; pos++) { 00154 int x = (col << 3) + pos; // x = col * 8 + pos 00155 if (x >= width) 00156 break; 00157 00158 if(shift & 1 << pos) 00159 { 00160 DrawPoint(x, y, rgbGolorCode); 00161 } 00162 } 00163 } 00164 } 00165 } 00166 00167 00168 uint16_t RK043FN48H::DisplayWidth() 00169 { 00170 return BSP_LCD_GetXSize(); 00171 } 00172 00173 00174 uint16_t RK043FN48H::DisplayHeight() 00175 { 00176 return BSP_LCD_GetYSize(); 00177 } 00178 00179 00180 void RK043FN48H::SetActiveLayer(Layer layer) 00181 { 00182 _selectedLayer = layer; 00183 00184 BSP_LCD_SelectLayer((uint32_t)layer); 00185 } 00186 00187 00188 Layer RK043FN48H::GetActiveLayer() 00189 { 00190 return _selectedLayer; 00191 } 00192 00193 00194 void RK043FN48H::SetLayersTransparency( uint8_t background, uint8_t foreground) 00195 { 00196 BSP_LCD_SetTransparency(0, background); 00197 BSP_LCD_SetTransparency(1, foreground); 00198 } 00199 00200 00201 void RK043FN48H::SetLayersVisibility( bool background, bool foreground) 00202 { 00203 BSP_LCD_SetLayerVisible(0, background ? ENABLE : DISABLE); 00204 BSP_LCD_SetLayerVisible(1, foreground ? ENABLE : DISABLE); 00205 } 00206 00207 00208 //============================================================================== 00209 // 00210 // Text output 00211 // 00212 //============================================================================== 00213 00214 void RK043FN48H::GotoXY(int x, int y) 00215 { 00216 _cursorPos[_selectedLayer].X = x; 00217 _cursorPos[_selectedLayer].Y = y; 00218 } 00219 00220 void RK043FN48H::gotoNewLine(int width, int height) 00221 { 00222 GotoXY(0, _cursorPos[_selectedLayer].X + height >= DisplayHeight() ? 0 : _cursorPos[_selectedLayer].Y + height); 00223 } 00224 00225 void RK043FN48H::putch(char ch) 00226 { 00227 int fontHeight = _selectedFont[_selectedLayer].Height(); 00228 int fontWidth = _selectedFont[_selectedLayer].Width(); 00229 00230 if(ch == 0x0A) // '/r' 00231 return; 00232 00233 if(ch == 0x0D) { // '/n' 00234 gotoNewLine(fontWidth, fontHeight); 00235 return; 00236 } 00237 00238 // Check that the character will fit on the screen 00239 if(_cursorPos[_selectedLayer].X + fontWidth >= DisplayWidth()) 00240 { 00241 gotoNewLine(fontWidth, fontHeight); 00242 } 00243 00244 BSP_LCD_DisplayChar(_cursorPos[_selectedLayer].X, _cursorPos[_selectedLayer].Y, ch); 00245 GotoXY(_cursorPos[_selectedLayer].X + fontWidth, _cursorPos[_selectedLayer].Y); 00246 } 00247 00248 00249 void RK043FN48H::puts(const char * str) 00250 { 00251 for(int i=0; i < strlen(str); i++) 00252 putch(*(str+i)); 00253 } 00254 00255 00256 void RK043FN48H::DrawText(int posX, int posY, char * str) 00257 { 00258 // Draw text horizontaly 00259 int fontWidth = _selectedFont[_selectedLayer].Width(); 00260 int x = posX; 00261 00262 for(int i=0; i < strlen(str); i++) 00263 { 00264 BSP_LCD_DisplayChar(x, posY, str[i]); 00265 x += fontWidth; 00266 } 00267 } 00268 00269 00270
Generated on Thu Jul 14 2022 02:25:58 by
