A board support package for the LPC4088 Display Module.

Dependencies:   DM_HttpServer DM_USBHost

Dependents:   lpc4088_displaymodule_emwin lpc4088_displaymodule_demo_sphere sampleGUI sampleEmptyGUI ... more

Fork of DMSupport by EmbeddedArtists AB

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BiosDisplay.cpp Source File

BiosDisplay.cpp

00001 /*
00002  *  Copyright 2014 Embedded Artists AB
00003  *
00004  *  Licensed under the Apache License, Version 2.0 (the "License");
00005  *  you may not use this file except in compliance with the License.
00006  *  You may obtain a copy of the License at
00007  *
00008  *    http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  *  Unless required by applicable law or agreed to in writing, software
00011  *  distributed under the License is distributed on an "AS IS" BASIS,
00012  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *  See the License for the specific language governing permissions and
00014  *  limitations under the License.
00015  */
00016 
00017 #include "mbed.h"
00018 #include "BiosDisplay.h"
00019 #include "BiosLoader.h"
00020 #include "DMBoard.h"
00021 #include "bios.h"
00022 
00023 
00024 /******************************************************************************
00025  * Defines and typedefs
00026  *****************************************************************************/
00027  
00028 
00029 /******************************************************************************
00030  * Local variables
00031  *****************************************************************************/
00032 
00033 
00034 /******************************************************************************
00035  * Private Functions
00036  *****************************************************************************/
00037 
00038 BiosDisplay::BiosDisplay() : 
00039     _initialized(false),
00040     _poweredOn(false),
00041     _bios(NULL),
00042     _biosData(NULL),
00043     _width(0),
00044     _height(0),
00045     _bpp(0),
00046     _supportedRes(0),
00047     _activeRes(Res_16bit_rgb565),
00048     _landscape(false)
00049 {
00050 }
00051 
00052 BiosDisplay::~BiosDisplay()
00053 {
00054   // _bios and _biosData are deallocated by BiosLoader
00055 }
00056 
00057 
00058 /******************************************************************************
00059  * Public Functions
00060  *****************************************************************************/
00061 
00062 BiosDisplay::DisplayError BiosDisplay::init()
00063 {
00064   DisplayError err = DisplayError_Ok;
00065   if (!_initialized) {
00066     do {
00067 
00068       /* 
00069        * With mbed OS 5 the LCD controller is reset by default. This is set in
00070        * system_LPC407x_8x_177x_8x.c "to prevent strange behavior when doing a
00071        * partial reset (happens when debugging)". Taking the LCD controller
00072        * out of reset below.
00073        */
00074       LPC_SC->RSTCON0 &= ~0x1;      
00075 
00076       if (BiosLoader::instance().params(&_bios, &_biosData) != DMBoard::Ok) {
00077         err = DisplayError_ConfigError;
00078         break;
00079       }
00080 
00081       err = (DisplayError)_bios->displayInit(_biosData);
00082       if (err != DisplayError_Ok) {
00083         break;
00084       }
00085 
00086       err = (DisplayError)_bios->displayInformation(_biosData, &_width, &_height, &_bpp, &_landscape, &_supportedRes, &_activeRes);
00087       if (err != DisplayError_Ok) {
00088         break;
00089       }
00090 
00091       _initialized = true;
00092     } while(0);
00093   }
00094   return err;
00095 }
00096 
00097 BiosDisplay::DisplayError BiosDisplay::powerUp(void* framebuffer, Display::Resolution res, FrameRate_t rate)
00098 {
00099   DisplayError err = DisplayError_Ok;
00100   if (!_poweredOn) {
00101     err = init();
00102     if (err == DisplayError_Ok) {
00103       do {
00104 
00105         err = (DisplayError)_bios->displayPowerUp(_biosData, framebuffer, (Resolution_t)res, rate);
00106           
00107         if (err != DisplayError_Ok) {
00108           break;
00109         }
00110 
00111         err = (DisplayError)_bios->displayInformation(_biosData, &_width, &_height, &_bpp, &_landscape, &_supportedRes, &_activeRes);     
00112         if (err != DisplayError_Ok) {
00113           break;
00114         }
00115         
00116         _poweredOn = true;
00117       } while(0);
00118     }
00119   }
00120   return err;
00121 }
00122 
00123 BiosDisplay::DisplayError BiosDisplay::powerDown()
00124 {
00125   DisplayError err = DisplayError_Ok;
00126   if (_poweredOn) {
00127     err = (DisplayError)_bios->displayPowerDown(_biosData);
00128     _poweredOn = false;
00129   }
00130   return err;
00131 }
00132 
00133 BiosDisplay::DisplayError BiosDisplay::backlight(int percent)
00134 {
00135   DisplayError err = DisplayError_Ok;
00136   if (!_initialized) {
00137       err = DisplayError_NoInit;
00138   } else {
00139     err = (DisplayError)_bios->displayBacklight(_biosData, percent);
00140   }      
00141   return err;
00142 }
00143 
00144 uint16_t BiosDisplay::width()
00145 {
00146   return _width;
00147 }
00148 
00149 uint16_t BiosDisplay::height()
00150 {
00151   return _height;
00152 }
00153 
00154 uint16_t BiosDisplay::bytesPerPixel()
00155 {
00156   return _bpp;
00157 }
00158 
00159 uint32_t BiosDisplay::fbSize()
00160 {
00161   return _width * _height * _bpp;
00162 }
00163 
00164 bool BiosDisplay::landscape()
00165 {
00166   return _landscape;
00167 }
00168 
00169 void* BiosDisplay::allocateFramebuffer(Display::Resolution res)
00170 {
00171   if (_initialized) {
00172     return malloc(_width*_height*bpp(res));
00173   }
00174   return NULL;
00175 }
00176 
00177 void* BiosDisplay::allocateFramebuffers(uint32_t num, Display::Resolution res)
00178 {
00179   if (_initialized && num>0) {
00180     return malloc(_width*_height*bpp(res)*num);
00181   }
00182   return NULL;
00183 }
00184 
00185 void BiosDisplay::setFramebuffer(void* buff)
00186 {
00187   LPC_LCD->UPBASE = (uint32_t)buff;
00188 }
00189 
00190 void* BiosDisplay::swapFramebuffer(void* buff)
00191 {
00192   uint32_t old = LPC_LCD->UPBASE;
00193   LPC_LCD->UPBASE = (uint32_t)buff;
00194   return (void*)old;
00195 }
00196 
00197 bool BiosDisplay::isSupported(Display::Resolution res)
00198 {
00199   return (_supportedRes & res);
00200 }
00201 
00202 BiosDisplay::Resolution BiosDisplay::currentResolution()
00203 {
00204   return (Resolution)_activeRes;
00205 }