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
Display/BiosDisplay.cpp@42:bbfe299d4a0c, 2019-11-04 (annotated)
- Committer:
- embeddedartists
- Date:
- Mon Nov 04 14:32:50 2019 +0000
- Revision:
- 42:bbfe299d4a0c
- Parent:
- 41:e06e764ff4fd
More updates related to mbed OS 5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 22:1a58a518435c | 1 | /* |
embeddedartists | 22:1a58a518435c | 2 | * Copyright 2014 Embedded Artists AB |
embeddedartists | 22:1a58a518435c | 3 | * |
embeddedartists | 22:1a58a518435c | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
embeddedartists | 22:1a58a518435c | 5 | * you may not use this file except in compliance with the License. |
embeddedartists | 22:1a58a518435c | 6 | * You may obtain a copy of the License at |
embeddedartists | 22:1a58a518435c | 7 | * |
embeddedartists | 22:1a58a518435c | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
embeddedartists | 22:1a58a518435c | 9 | * |
embeddedartists | 22:1a58a518435c | 10 | * Unless required by applicable law or agreed to in writing, software |
embeddedartists | 22:1a58a518435c | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
embeddedartists | 22:1a58a518435c | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
embeddedartists | 22:1a58a518435c | 13 | * See the License for the specific language governing permissions and |
embeddedartists | 22:1a58a518435c | 14 | * limitations under the License. |
embeddedartists | 22:1a58a518435c | 15 | */ |
embeddedartists | 22:1a58a518435c | 16 | |
embeddedartists | 22:1a58a518435c | 17 | #include "mbed.h" |
embeddedartists | 22:1a58a518435c | 18 | #include "BiosDisplay.h" |
embeddedartists | 22:1a58a518435c | 19 | #include "BiosLoader.h" |
embeddedartists | 22:1a58a518435c | 20 | #include "DMBoard.h" |
embeddedartists | 22:1a58a518435c | 21 | #include "bios.h" |
embeddedartists | 22:1a58a518435c | 22 | |
embeddedartists | 22:1a58a518435c | 23 | |
embeddedartists | 22:1a58a518435c | 24 | /****************************************************************************** |
embeddedartists | 22:1a58a518435c | 25 | * Defines and typedefs |
embeddedartists | 22:1a58a518435c | 26 | *****************************************************************************/ |
embeddedartists | 22:1a58a518435c | 27 | |
embeddedartists | 22:1a58a518435c | 28 | |
embeddedartists | 22:1a58a518435c | 29 | /****************************************************************************** |
embeddedartists | 22:1a58a518435c | 30 | * Local variables |
embeddedartists | 22:1a58a518435c | 31 | *****************************************************************************/ |
embeddedartists | 22:1a58a518435c | 32 | |
embeddedartists | 22:1a58a518435c | 33 | |
embeddedartists | 22:1a58a518435c | 34 | /****************************************************************************** |
embeddedartists | 22:1a58a518435c | 35 | * Private Functions |
embeddedartists | 22:1a58a518435c | 36 | *****************************************************************************/ |
embeddedartists | 22:1a58a518435c | 37 | |
embeddedartists | 22:1a58a518435c | 38 | BiosDisplay::BiosDisplay() : |
embeddedartists | 22:1a58a518435c | 39 | _initialized(false), |
embeddedartists | 22:1a58a518435c | 40 | _poweredOn(false), |
embeddedartists | 22:1a58a518435c | 41 | _bios(NULL), |
embeddedartists | 22:1a58a518435c | 42 | _biosData(NULL), |
embeddedartists | 22:1a58a518435c | 43 | _width(0), |
embeddedartists | 22:1a58a518435c | 44 | _height(0), |
embeddedartists | 22:1a58a518435c | 45 | _bpp(0), |
embeddedartists | 22:1a58a518435c | 46 | _supportedRes(0), |
embeddedartists | 22:1a58a518435c | 47 | _activeRes(Res_16bit_rgb565), |
embeddedartists | 22:1a58a518435c | 48 | _landscape(false) |
embeddedartists | 22:1a58a518435c | 49 | { |
embeddedartists | 22:1a58a518435c | 50 | } |
embeddedartists | 22:1a58a518435c | 51 | |
embeddedartists | 22:1a58a518435c | 52 | BiosDisplay::~BiosDisplay() |
embeddedartists | 22:1a58a518435c | 53 | { |
embeddedartists | 22:1a58a518435c | 54 | // _bios and _biosData are deallocated by BiosLoader |
embeddedartists | 22:1a58a518435c | 55 | } |
embeddedartists | 22:1a58a518435c | 56 | |
embeddedartists | 22:1a58a518435c | 57 | |
embeddedartists | 22:1a58a518435c | 58 | /****************************************************************************** |
embeddedartists | 22:1a58a518435c | 59 | * Public Functions |
embeddedartists | 22:1a58a518435c | 60 | *****************************************************************************/ |
embeddedartists | 22:1a58a518435c | 61 | |
embeddedartists | 22:1a58a518435c | 62 | BiosDisplay::DisplayError BiosDisplay::init() |
embeddedartists | 22:1a58a518435c | 63 | { |
embeddedartists | 22:1a58a518435c | 64 | DisplayError err = DisplayError_Ok; |
embeddedartists | 22:1a58a518435c | 65 | if (!_initialized) { |
embeddedartists | 22:1a58a518435c | 66 | do { |
embeddedartists | 41:e06e764ff4fd | 67 | |
embeddedartists | 41:e06e764ff4fd | 68 | /* |
embeddedartists | 41:e06e764ff4fd | 69 | * With mbed OS 5 the LCD controller is reset by default. This is set in |
embeddedartists | 41:e06e764ff4fd | 70 | * system_LPC407x_8x_177x_8x.c "to prevent strange behavior when doing a |
embeddedartists | 41:e06e764ff4fd | 71 | * partial reset (happens when debugging)". Taking the LCD controller |
embeddedartists | 41:e06e764ff4fd | 72 | * out of reset below. |
embeddedartists | 41:e06e764ff4fd | 73 | */ |
embeddedartists | 41:e06e764ff4fd | 74 | LPC_SC->RSTCON0 &= ~0x1; |
embeddedartists | 41:e06e764ff4fd | 75 | |
embeddedartists | 22:1a58a518435c | 76 | if (BiosLoader::instance().params(&_bios, &_biosData) != DMBoard::Ok) { |
embeddedartists | 22:1a58a518435c | 77 | err = DisplayError_ConfigError; |
embeddedartists | 22:1a58a518435c | 78 | break; |
embeddedartists | 22:1a58a518435c | 79 | } |
embeddedartists | 41:e06e764ff4fd | 80 | |
embeddedartists | 22:1a58a518435c | 81 | err = (DisplayError)_bios->displayInit(_biosData); |
embeddedartists | 22:1a58a518435c | 82 | if (err != DisplayError_Ok) { |
embeddedartists | 22:1a58a518435c | 83 | break; |
embeddedartists | 22:1a58a518435c | 84 | } |
embeddedartists | 22:1a58a518435c | 85 | |
embeddedartists | 22:1a58a518435c | 86 | err = (DisplayError)_bios->displayInformation(_biosData, &_width, &_height, &_bpp, &_landscape, &_supportedRes, &_activeRes); |
embeddedartists | 22:1a58a518435c | 87 | if (err != DisplayError_Ok) { |
embeddedartists | 22:1a58a518435c | 88 | break; |
embeddedartists | 22:1a58a518435c | 89 | } |
embeddedartists | 41:e06e764ff4fd | 90 | |
embeddedartists | 22:1a58a518435c | 91 | _initialized = true; |
embeddedartists | 22:1a58a518435c | 92 | } while(0); |
embeddedartists | 22:1a58a518435c | 93 | } |
embeddedartists | 22:1a58a518435c | 94 | return err; |
embeddedartists | 22:1a58a518435c | 95 | } |
embeddedartists | 22:1a58a518435c | 96 | |
alindvall | 39:e1cb4dd9bfeb | 97 | BiosDisplay::DisplayError BiosDisplay::powerUp(void* framebuffer, Display::Resolution res, FrameRate_t rate) |
embeddedartists | 22:1a58a518435c | 98 | { |
embeddedartists | 22:1a58a518435c | 99 | DisplayError err = DisplayError_Ok; |
embeddedartists | 22:1a58a518435c | 100 | if (!_poweredOn) { |
embeddedartists | 22:1a58a518435c | 101 | err = init(); |
embeddedartists | 22:1a58a518435c | 102 | if (err == DisplayError_Ok) { |
embeddedartists | 22:1a58a518435c | 103 | do { |
embeddedartists | 41:e06e764ff4fd | 104 | |
alindvall | 39:e1cb4dd9bfeb | 105 | err = (DisplayError)_bios->displayPowerUp(_biosData, framebuffer, (Resolution_t)res, rate); |
embeddedartists | 22:1a58a518435c | 106 | |
embeddedartists | 22:1a58a518435c | 107 | if (err != DisplayError_Ok) { |
embeddedartists | 22:1a58a518435c | 108 | break; |
embeddedartists | 22:1a58a518435c | 109 | } |
embeddedartists | 22:1a58a518435c | 110 | |
embeddedartists | 22:1a58a518435c | 111 | err = (DisplayError)_bios->displayInformation(_biosData, &_width, &_height, &_bpp, &_landscape, &_supportedRes, &_activeRes); |
embeddedartists | 22:1a58a518435c | 112 | if (err != DisplayError_Ok) { |
embeddedartists | 22:1a58a518435c | 113 | break; |
embeddedartists | 22:1a58a518435c | 114 | } |
embeddedartists | 22:1a58a518435c | 115 | |
embeddedartists | 22:1a58a518435c | 116 | _poweredOn = true; |
embeddedartists | 22:1a58a518435c | 117 | } while(0); |
embeddedartists | 22:1a58a518435c | 118 | } |
embeddedartists | 22:1a58a518435c | 119 | } |
embeddedartists | 22:1a58a518435c | 120 | return err; |
embeddedartists | 22:1a58a518435c | 121 | } |
embeddedartists | 22:1a58a518435c | 122 | |
embeddedartists | 22:1a58a518435c | 123 | BiosDisplay::DisplayError BiosDisplay::powerDown() |
embeddedartists | 22:1a58a518435c | 124 | { |
embeddedartists | 22:1a58a518435c | 125 | DisplayError err = DisplayError_Ok; |
embeddedartists | 22:1a58a518435c | 126 | if (_poweredOn) { |
embeddedartists | 22:1a58a518435c | 127 | err = (DisplayError)_bios->displayPowerDown(_biosData); |
embeddedartists | 22:1a58a518435c | 128 | _poweredOn = false; |
embeddedartists | 22:1a58a518435c | 129 | } |
embeddedartists | 22:1a58a518435c | 130 | return err; |
embeddedartists | 22:1a58a518435c | 131 | } |
embeddedartists | 22:1a58a518435c | 132 | |
embeddedartists | 22:1a58a518435c | 133 | BiosDisplay::DisplayError BiosDisplay::backlight(int percent) |
embeddedartists | 22:1a58a518435c | 134 | { |
embeddedartists | 22:1a58a518435c | 135 | DisplayError err = DisplayError_Ok; |
embeddedartists | 22:1a58a518435c | 136 | if (!_initialized) { |
embeddedartists | 22:1a58a518435c | 137 | err = DisplayError_NoInit; |
embeddedartists | 22:1a58a518435c | 138 | } else { |
embeddedartists | 22:1a58a518435c | 139 | err = (DisplayError)_bios->displayBacklight(_biosData, percent); |
embeddedartists | 22:1a58a518435c | 140 | } |
embeddedartists | 22:1a58a518435c | 141 | return err; |
embeddedartists | 22:1a58a518435c | 142 | } |
embeddedartists | 22:1a58a518435c | 143 | |
embeddedartists | 22:1a58a518435c | 144 | uint16_t BiosDisplay::width() |
embeddedartists | 22:1a58a518435c | 145 | { |
embeddedartists | 22:1a58a518435c | 146 | return _width; |
embeddedartists | 22:1a58a518435c | 147 | } |
embeddedartists | 22:1a58a518435c | 148 | |
embeddedartists | 22:1a58a518435c | 149 | uint16_t BiosDisplay::height() |
embeddedartists | 22:1a58a518435c | 150 | { |
embeddedartists | 22:1a58a518435c | 151 | return _height; |
embeddedartists | 22:1a58a518435c | 152 | } |
embeddedartists | 22:1a58a518435c | 153 | |
embeddedartists | 22:1a58a518435c | 154 | uint16_t BiosDisplay::bytesPerPixel() |
embeddedartists | 22:1a58a518435c | 155 | { |
embeddedartists | 22:1a58a518435c | 156 | return _bpp; |
embeddedartists | 22:1a58a518435c | 157 | } |
embeddedartists | 22:1a58a518435c | 158 | |
embeddedartists | 22:1a58a518435c | 159 | uint32_t BiosDisplay::fbSize() |
embeddedartists | 22:1a58a518435c | 160 | { |
embeddedartists | 22:1a58a518435c | 161 | return _width * _height * _bpp; |
embeddedartists | 22:1a58a518435c | 162 | } |
embeddedartists | 22:1a58a518435c | 163 | |
embeddedartists | 22:1a58a518435c | 164 | bool BiosDisplay::landscape() |
embeddedartists | 22:1a58a518435c | 165 | { |
embeddedartists | 22:1a58a518435c | 166 | return _landscape; |
embeddedartists | 22:1a58a518435c | 167 | } |
embeddedartists | 22:1a58a518435c | 168 | |
embeddedartists | 22:1a58a518435c | 169 | void* BiosDisplay::allocateFramebuffer(Display::Resolution res) |
embeddedartists | 22:1a58a518435c | 170 | { |
embeddedartists | 22:1a58a518435c | 171 | if (_initialized) { |
alindvall | 39:e1cb4dd9bfeb | 172 | return malloc(_width*_height*bpp(res)); |
embeddedartists | 22:1a58a518435c | 173 | } |
embeddedartists | 22:1a58a518435c | 174 | return NULL; |
embeddedartists | 22:1a58a518435c | 175 | } |
embeddedartists | 22:1a58a518435c | 176 | |
embeddedartists | 31:d47cffcb0a3e | 177 | void* BiosDisplay::allocateFramebuffers(uint32_t num, Display::Resolution res) |
embeddedartists | 31:d47cffcb0a3e | 178 | { |
embeddedartists | 31:d47cffcb0a3e | 179 | if (_initialized && num>0) { |
alindvall | 39:e1cb4dd9bfeb | 180 | return malloc(_width*_height*bpp(res)*num); |
embeddedartists | 31:d47cffcb0a3e | 181 | } |
embeddedartists | 31:d47cffcb0a3e | 182 | return NULL; |
embeddedartists | 31:d47cffcb0a3e | 183 | } |
embeddedartists | 31:d47cffcb0a3e | 184 | |
embeddedartists | 22:1a58a518435c | 185 | void BiosDisplay::setFramebuffer(void* buff) |
embeddedartists | 22:1a58a518435c | 186 | { |
embeddedartists | 22:1a58a518435c | 187 | LPC_LCD->UPBASE = (uint32_t)buff; |
embeddedartists | 22:1a58a518435c | 188 | } |
embeddedartists | 22:1a58a518435c | 189 | |
embeddedartists | 22:1a58a518435c | 190 | void* BiosDisplay::swapFramebuffer(void* buff) |
embeddedartists | 22:1a58a518435c | 191 | { |
embeddedartists | 22:1a58a518435c | 192 | uint32_t old = LPC_LCD->UPBASE; |
embeddedartists | 22:1a58a518435c | 193 | LPC_LCD->UPBASE = (uint32_t)buff; |
embeddedartists | 22:1a58a518435c | 194 | return (void*)old; |
embeddedartists | 22:1a58a518435c | 195 | } |
embeddedartists | 22:1a58a518435c | 196 | |
embeddedartists | 22:1a58a518435c | 197 | bool BiosDisplay::isSupported(Display::Resolution res) |
embeddedartists | 22:1a58a518435c | 198 | { |
embeddedartists | 22:1a58a518435c | 199 | return (_supportedRes & res); |
embeddedartists | 22:1a58a518435c | 200 | } |
embeddedartists | 22:1a58a518435c | 201 | |
embeddedartists | 22:1a58a518435c | 202 | BiosDisplay::Resolution BiosDisplay::currentResolution() |
embeddedartists | 22:1a58a518435c | 203 | { |
embeddedartists | 22:1a58a518435c | 204 | return (Resolution)_activeRes; |
embeddedartists | 22:1a58a518435c | 205 | } |