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/Display.h@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 | 0:6b68dac0d986 | 1 | /* |
embeddedartists | 0:6b68dac0d986 | 2 | * Copyright 2014 Embedded Artists AB |
embeddedartists | 0:6b68dac0d986 | 3 | * |
embeddedartists | 0:6b68dac0d986 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
embeddedartists | 0:6b68dac0d986 | 5 | * you may not use this file except in compliance with the License. |
embeddedartists | 0:6b68dac0d986 | 6 | * You may obtain a copy of the License at |
embeddedartists | 0:6b68dac0d986 | 7 | * |
embeddedartists | 0:6b68dac0d986 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
embeddedartists | 0:6b68dac0d986 | 9 | * |
embeddedartists | 0:6b68dac0d986 | 10 | * Unless required by applicable law or agreed to in writing, software |
embeddedartists | 0:6b68dac0d986 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
embeddedartists | 0:6b68dac0d986 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
embeddedartists | 0:6b68dac0d986 | 13 | * See the License for the specific language governing permissions and |
embeddedartists | 0:6b68dac0d986 | 14 | * limitations under the License. |
embeddedartists | 0:6b68dac0d986 | 15 | */ |
embeddedartists | 0:6b68dac0d986 | 16 | |
embeddedartists | 0:6b68dac0d986 | 17 | #ifndef DISPLAY_H |
embeddedartists | 0:6b68dac0d986 | 18 | #define DISPLAY_H |
embeddedartists | 0:6b68dac0d986 | 19 | |
embeddedartists | 0:6b68dac0d986 | 20 | #include "mbed.h" |
embeddedartists | 10:1ac4b213f0f7 | 21 | #include "bios.h" |
embeddedartists | 0:6b68dac0d986 | 22 | |
embeddedartists | 9:a33326afd686 | 23 | /** |
embeddedartists | 9:a33326afd686 | 24 | * Display example |
embeddedartists | 9:a33326afd686 | 25 | * |
embeddedartists | 9:a33326afd686 | 26 | * @code |
embeddedartists | 9:a33326afd686 | 27 | * #include "mbed.h" |
embeddedartists | 9:a33326afd686 | 28 | * #include "DMBoard.h" |
embeddedartists | 9:a33326afd686 | 29 | * |
embeddedartists | 9:a33326afd686 | 30 | * int main(void) { |
embeddedartists | 9:a33326afd686 | 31 | * // initialize the display |
embeddedartists | 9:a33326afd686 | 32 | * DMBoard::instance().init(); |
embeddedartists | 9:a33326afd686 | 33 | * |
embeddedartists | 9:a33326afd686 | 34 | * // allocate one framebuffer |
embeddedartists | 9:a33326afd686 | 35 | * Display* disp = DMBoard::instance().display(); |
embeddedartists | 9:a33326afd686 | 36 | * uint16_t* fb = (uint16_t*)disp->allocateFramebuffer(); |
embeddedartists | 9:a33326afd686 | 37 | * if (fb == NULL) { |
embeddedartists | 9:a33326afd686 | 38 | * DMBoard::instance().logger()->printf("Failed to allocate memory for framebuffer\r\n"); |
embeddedartists | 9:a33326afd686 | 39 | * mbed_die(); |
embeddedartists | 9:a33326afd686 | 40 | * } |
embeddedartists | 9:a33326afd686 | 41 | * |
embeddedartists | 9:a33326afd686 | 42 | * // draw something on the framebuffer |
embeddedartists | 9:a33326afd686 | 43 | * ... |
embeddedartists | 9:a33326afd686 | 44 | * |
embeddedartists | 9:a33326afd686 | 45 | * // turn on the display |
embeddedartists | 9:a33326afd686 | 46 | * disperr = disp->powerUp(fb); |
embeddedartists | 9:a33326afd686 | 47 | * if (disperr != Display::Ok) { |
embeddedartists | 9:a33326afd686 | 48 | * DMBoard::instance().logger()->printf("Failed to initialize the display, got error %d\r\n", disperr); |
embeddedartists | 9:a33326afd686 | 49 | * mbed_die(); |
embeddedartists | 9:a33326afd686 | 50 | * } |
embeddedartists | 9:a33326afd686 | 51 | * |
embeddedartists | 9:a33326afd686 | 52 | * ... |
embeddedartists | 9:a33326afd686 | 53 | * } |
embeddedartists | 9:a33326afd686 | 54 | * @endcode |
embeddedartists | 9:a33326afd686 | 55 | */ |
embeddedartists | 0:6b68dac0d986 | 56 | class Display { |
embeddedartists | 0:6b68dac0d986 | 57 | public: |
embeddedartists | 0:6b68dac0d986 | 58 | enum DisplayError { |
embeddedartists | 10:1ac4b213f0f7 | 59 | DisplayError_Ok = BiosError_Ok, |
embeddedartists | 10:1ac4b213f0f7 | 60 | DisplayError_ConfigError = BiosError_ConfigError, |
embeddedartists | 10:1ac4b213f0f7 | 61 | DisplayError_WrongBPP = BiosError_WrongBPP, |
embeddedartists | 10:1ac4b213f0f7 | 62 | DisplayError_InvalidParam = BiosError_InvalidParam, |
embeddedartists | 10:1ac4b213f0f7 | 63 | DisplayError_NoInit = BiosError_NoInit, |
embeddedartists | 10:1ac4b213f0f7 | 64 | DisplayError_CalibrationError = BiosError_Calibration, |
embeddedartists | 22:1a58a518435c | 65 | DisplayError_Timeout = BiosError_Timeout, |
embeddedartists | 22:1a58a518435c | 66 | DisplayError_TouchNotSupported = BiosError_NotSupported, |
embeddedartists | 10:1ac4b213f0f7 | 67 | DisplayError_MemoryError, |
embeddedartists | 0:6b68dac0d986 | 68 | }; |
embeddedartists | 0:6b68dac0d986 | 69 | |
embeddedartists | 0:6b68dac0d986 | 70 | enum Resolution { |
embeddedartists | 10:1ac4b213f0f7 | 71 | Resolution_16bit_rgb565 = Res_16bit_rgb565, |
embeddedartists | 10:1ac4b213f0f7 | 72 | Resolution_18bit_rgb666 = Res_18bit_rgb666, |
embeddedartists | 10:1ac4b213f0f7 | 73 | Resolution_24bit_rgb888 = Res_24bit_rgb888, |
embeddedartists | 0:6b68dac0d986 | 74 | }; |
embeddedartists | 0:6b68dac0d986 | 75 | |
embeddedartists | 41:e06e764ff4fd | 76 | /** |
embeddedartists | 41:e06e764ff4fd | 77 | * Initialize the display. |
embeddedartists | 41:e06e764ff4fd | 78 | */ |
embeddedartists | 41:e06e764ff4fd | 79 | virtual DisplayError init() = 0; |
embeddedartists | 41:e06e764ff4fd | 80 | |
embeddedartists | 9:a33326afd686 | 81 | /** Turns the display on with the specified framebuffer showing |
embeddedartists | 0:6b68dac0d986 | 82 | * |
alindvall | 39:e1cb4dd9bfeb | 83 | * @param framebuffer the data to show |
alindvall | 39:e1cb4dd9bfeb | 84 | * @param res the resolution to use |
alindvall | 39:e1cb4dd9bfeb | 85 | * @param rate the frame rate to use |
alindvall | 39:e1cb4dd9bfeb | 86 | * |
embeddedartists | 0:6b68dac0d986 | 87 | * @returns |
embeddedartists | 0:6b68dac0d986 | 88 | * Ok on success |
embeddedartists | 0:6b68dac0d986 | 89 | * An error code on failure |
embeddedartists | 0:6b68dac0d986 | 90 | */ |
alindvall | 39:e1cb4dd9bfeb | 91 | virtual DisplayError powerUp(void* framebuffer, Resolution res = Resolution_16bit_rgb565, FrameRate_t rate = FrameRate_Normal) = 0; |
embeddedartists | 0:6b68dac0d986 | 92 | |
embeddedartists | 9:a33326afd686 | 93 | /** Turns the display off |
embeddedartists | 0:6b68dac0d986 | 94 | * |
embeddedartists | 0:6b68dac0d986 | 95 | * @returns |
embeddedartists | 0:6b68dac0d986 | 96 | * Ok on success |
embeddedartists | 0:6b68dac0d986 | 97 | * An error code on failure |
embeddedartists | 0:6b68dac0d986 | 98 | */ |
embeddedartists | 10:1ac4b213f0f7 | 99 | virtual DisplayError powerDown() = 0; |
embeddedartists | 0:6b68dac0d986 | 100 | |
embeddedartists | 0:6b68dac0d986 | 101 | /** Sets the backlight level. 0% is off and 100% is fully on |
embeddedartists | 0:6b68dac0d986 | 102 | * |
alindvall | 39:e1cb4dd9bfeb | 103 | * @param percent backlight in % |
alindvall | 39:e1cb4dd9bfeb | 104 | * |
embeddedartists | 0:6b68dac0d986 | 105 | * @returns |
embeddedartists | 0:6b68dac0d986 | 106 | * Ok on success |
embeddedartists | 0:6b68dac0d986 | 107 | * An error code on failure |
embeddedartists | 0:6b68dac0d986 | 108 | */ |
embeddedartists | 10:1ac4b213f0f7 | 109 | virtual DisplayError backlight(int percent) = 0; |
embeddedartists | 0:6b68dac0d986 | 110 | |
alindvall | 39:e1cb4dd9bfeb | 111 | /** Returns the width (in pixels) of the display |
alindvall | 39:e1cb4dd9bfeb | 112 | * |
alindvall | 39:e1cb4dd9bfeb | 113 | * @returns the display width |
alindvall | 39:e1cb4dd9bfeb | 114 | */ |
embeddedartists | 10:1ac4b213f0f7 | 115 | virtual uint16_t width() = 0; |
alindvall | 39:e1cb4dd9bfeb | 116 | |
alindvall | 39:e1cb4dd9bfeb | 117 | /** Returns the height (in pixels) of the display |
alindvall | 39:e1cb4dd9bfeb | 118 | * |
alindvall | 39:e1cb4dd9bfeb | 119 | * @returns the display height |
alindvall | 39:e1cb4dd9bfeb | 120 | */ |
embeddedartists | 10:1ac4b213f0f7 | 121 | virtual uint16_t height() = 0; |
alindvall | 39:e1cb4dd9bfeb | 122 | |
alindvall | 39:e1cb4dd9bfeb | 123 | /** Returns the number of bytes used by each pixel |
alindvall | 39:e1cb4dd9bfeb | 124 | * |
alindvall | 39:e1cb4dd9bfeb | 125 | * @returns bytes per pixel |
alindvall | 39:e1cb4dd9bfeb | 126 | */ |
embeddedartists | 10:1ac4b213f0f7 | 127 | virtual uint16_t bytesPerPixel() = 0; |
alindvall | 39:e1cb4dd9bfeb | 128 | |
alindvall | 39:e1cb4dd9bfeb | 129 | /** Returns the number of bytes used for each frame buffer |
alindvall | 39:e1cb4dd9bfeb | 130 | * |
alindvall | 39:e1cb4dd9bfeb | 131 | * @returns width*height*bytesPerPixel |
alindvall | 39:e1cb4dd9bfeb | 132 | */ |
embeddedartists | 10:1ac4b213f0f7 | 133 | virtual uint32_t fbSize() = 0; |
alindvall | 39:e1cb4dd9bfeb | 134 | |
alindvall | 39:e1cb4dd9bfeb | 135 | /** Returns the display orientation |
alindvall | 39:e1cb4dd9bfeb | 136 | * |
alindvall | 39:e1cb4dd9bfeb | 137 | * @returns the display orientation |
alindvall | 39:e1cb4dd9bfeb | 138 | */ |
embeddedartists | 10:1ac4b213f0f7 | 139 | virtual bool landscape() = 0; |
alindvall | 39:e1cb4dd9bfeb | 140 | |
alindvall | 39:e1cb4dd9bfeb | 141 | /** Returns true if the specified resolution can be used |
alindvall | 39:e1cb4dd9bfeb | 142 | * |
alindvall | 39:e1cb4dd9bfeb | 143 | * @returns true if supported, false if not |
alindvall | 39:e1cb4dd9bfeb | 144 | */ |
embeddedartists | 10:1ac4b213f0f7 | 145 | virtual bool isSupported(Resolution res) = 0; |
alindvall | 39:e1cb4dd9bfeb | 146 | |
alindvall | 39:e1cb4dd9bfeb | 147 | /** Returns the current resolution |
alindvall | 39:e1cb4dd9bfeb | 148 | * |
alindvall | 39:e1cb4dd9bfeb | 149 | * @returns the current resolution |
alindvall | 39:e1cb4dd9bfeb | 150 | */ |
embeddedartists | 10:1ac4b213f0f7 | 151 | virtual Resolution currentResolution() = 0; |
embeddedartists | 9:a33326afd686 | 152 | |
embeddedartists | 9:a33326afd686 | 153 | /** Replaces the current framebuffer. |
embeddedartists | 9:a33326afd686 | 154 | * |
embeddedartists | 9:a33326afd686 | 155 | * Note that this requires the caller or someone else to have a |
embeddedartists | 9:a33326afd686 | 156 | * reference to the existing framebuffer, otherwise that memory |
embeddedartists | 9:a33326afd686 | 157 | * is lost. |
embeddedartists | 9:a33326afd686 | 158 | * |
embeddedartists | 9:a33326afd686 | 159 | * @param buff the new framebuffer |
embeddedartists | 9:a33326afd686 | 160 | */ |
embeddedartists | 10:1ac4b213f0f7 | 161 | virtual void setFramebuffer(void* buff) = 0; |
embeddedartists | 9:a33326afd686 | 162 | |
embeddedartists | 9:a33326afd686 | 163 | /** Replaces the current framebuffer with the specified one. |
embeddedartists | 9:a33326afd686 | 164 | * |
embeddedartists | 9:a33326afd686 | 165 | * This function as opposed to the setFramebuffer() one does return |
embeddedartists | 9:a33326afd686 | 166 | * the old framebuffer. This way the caller can save the old one and |
embeddedartists | 9:a33326afd686 | 167 | * then swap it back when done. |
embeddedartists | 9:a33326afd686 | 168 | * |
embeddedartists | 9:a33326afd686 | 169 | * @param buff the new framebuffer |
embeddedartists | 9:a33326afd686 | 170 | * @returns the old framebuffer |
embeddedartists | 9:a33326afd686 | 171 | */ |
embeddedartists | 10:1ac4b213f0f7 | 172 | virtual void* swapFramebuffer(void* buff) = 0; |
embeddedartists | 9:a33326afd686 | 173 | |
embeddedartists | 9:a33326afd686 | 174 | /** Allocate enough memory for one framebuffer |
embeddedartists | 9:a33326afd686 | 175 | * |
embeddedartists | 9:a33326afd686 | 176 | * This function is a to make it easier to allocate memory for framebuffers |
embeddedartists | 9:a33326afd686 | 177 | * as the number of bytes needed depends on width, height and bytes per pixel. |
embeddedartists | 9:a33326afd686 | 178 | * |
embeddedartists | 9:a33326afd686 | 179 | * Free the allocated memory when done using the free() function. |
embeddedartists | 9:a33326afd686 | 180 | * |
embeddedartists | 31:d47cffcb0a3e | 181 | * @param res the resolution (default is the one that the display is using) |
embeddedartists | 9:a33326afd686 | 182 | * @returns a new framebuffer or NULL if out of memory |
embeddedartists | 9:a33326afd686 | 183 | */ |
embeddedartists | 10:1ac4b213f0f7 | 184 | virtual void* allocateFramebuffer(Resolution res=Resolution_16bit_rgb565) = 0; |
embeddedartists | 31:d47cffcb0a3e | 185 | |
embeddedartists | 31:d47cffcb0a3e | 186 | /** Allocate enough memory for one or more consequtive framebuffers |
embeddedartists | 31:d47cffcb0a3e | 187 | * |
embeddedartists | 31:d47cffcb0a3e | 188 | * This function is a to make it easier to allocate memory for framebuffers |
embeddedartists | 31:d47cffcb0a3e | 189 | * as the number of bytes needed depends on width, height and bytes per pixel. |
embeddedartists | 31:d47cffcb0a3e | 190 | * |
embeddedartists | 31:d47cffcb0a3e | 191 | * Free the allocated memory when done using the free() function. |
embeddedartists | 31:d47cffcb0a3e | 192 | * |
embeddedartists | 31:d47cffcb0a3e | 193 | * Use the default parameters to get one framebuffer for the display's current |
embeddedartists | 31:d47cffcb0a3e | 194 | * resolution. |
embeddedartists | 31:d47cffcb0a3e | 195 | * |
embeddedartists | 31:d47cffcb0a3e | 196 | * @param num the number of framebuffers, should be >= 1 |
embeddedartists | 31:d47cffcb0a3e | 197 | * @param res the resolution (default is the one that the display is using) |
embeddedartists | 31:d47cffcb0a3e | 198 | * @returns new framebuffers or NULL if out of memory |
embeddedartists | 31:d47cffcb0a3e | 199 | */ |
embeddedartists | 31:d47cffcb0a3e | 200 | virtual void* allocateFramebuffers(uint32_t num=1, Resolution res=Resolution_16bit_rgb565) = 0; |
embeddedartists | 0:6b68dac0d986 | 201 | }; |
embeddedartists | 0:6b68dac0d986 | 202 | |
embeddedartists | 0:6b68dac0d986 | 203 | #endif |