mbed support for LPC4088 Display Module
Dependencies: DM_FATFileSystem DM_HttpServer DM_USBHost EthernetInterface USBDevice mbed-rpc mbed-rtos mbed-src
Fork of DMSupport by
Display/Display.h@39:e1cb4dd9bfeb, 2015-04-28 (annotated)
- Committer:
- alindvall
- Date:
- Tue Apr 28 11:47:20 2015 +0000
- Revision:
- 39:e1cb4dd9bfeb
- Parent:
- 31:d47cffcb0a3e
Added display frame rate setting. Updated used libraries.
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 | 9:a33326afd686 | 76 | /** Turns the display on with the specified framebuffer showing |
embeddedartists | 0:6b68dac0d986 | 77 | * |
alindvall | 39:e1cb4dd9bfeb | 78 | * @param framebuffer the data to show |
alindvall | 39:e1cb4dd9bfeb | 79 | * @param res the resolution to use |
alindvall | 39:e1cb4dd9bfeb | 80 | * @param rate the frame rate to use |
alindvall | 39:e1cb4dd9bfeb | 81 | * |
embeddedartists | 0:6b68dac0d986 | 82 | * @returns |
embeddedartists | 0:6b68dac0d986 | 83 | * Ok on success |
embeddedartists | 0:6b68dac0d986 | 84 | * An error code on failure |
embeddedartists | 0:6b68dac0d986 | 85 | */ |
alindvall | 39:e1cb4dd9bfeb | 86 | virtual DisplayError powerUp(void* framebuffer, Resolution res = Resolution_16bit_rgb565, FrameRate_t rate = FrameRate_Normal) = 0; |
embeddedartists | 0:6b68dac0d986 | 87 | |
embeddedartists | 9:a33326afd686 | 88 | /** Turns the display off |
embeddedartists | 0:6b68dac0d986 | 89 | * |
embeddedartists | 0:6b68dac0d986 | 90 | * @returns |
embeddedartists | 0:6b68dac0d986 | 91 | * Ok on success |
embeddedartists | 0:6b68dac0d986 | 92 | * An error code on failure |
embeddedartists | 0:6b68dac0d986 | 93 | */ |
embeddedartists | 10:1ac4b213f0f7 | 94 | virtual DisplayError powerDown() = 0; |
embeddedartists | 0:6b68dac0d986 | 95 | |
embeddedartists | 0:6b68dac0d986 | 96 | /** Sets the backlight level. 0% is off and 100% is fully on |
embeddedartists | 0:6b68dac0d986 | 97 | * |
alindvall | 39:e1cb4dd9bfeb | 98 | * @param percent backlight in % |
alindvall | 39:e1cb4dd9bfeb | 99 | * |
embeddedartists | 0:6b68dac0d986 | 100 | * @returns |
embeddedartists | 0:6b68dac0d986 | 101 | * Ok on success |
embeddedartists | 0:6b68dac0d986 | 102 | * An error code on failure |
embeddedartists | 0:6b68dac0d986 | 103 | */ |
embeddedartists | 10:1ac4b213f0f7 | 104 | virtual DisplayError backlight(int percent) = 0; |
embeddedartists | 0:6b68dac0d986 | 105 | |
alindvall | 39:e1cb4dd9bfeb | 106 | /** Returns the width (in pixels) of the display |
alindvall | 39:e1cb4dd9bfeb | 107 | * |
alindvall | 39:e1cb4dd9bfeb | 108 | * @returns the display width |
alindvall | 39:e1cb4dd9bfeb | 109 | */ |
embeddedartists | 10:1ac4b213f0f7 | 110 | virtual uint16_t width() = 0; |
alindvall | 39:e1cb4dd9bfeb | 111 | |
alindvall | 39:e1cb4dd9bfeb | 112 | /** Returns the height (in pixels) of the display |
alindvall | 39:e1cb4dd9bfeb | 113 | * |
alindvall | 39:e1cb4dd9bfeb | 114 | * @returns the display height |
alindvall | 39:e1cb4dd9bfeb | 115 | */ |
embeddedartists | 10:1ac4b213f0f7 | 116 | virtual uint16_t height() = 0; |
alindvall | 39:e1cb4dd9bfeb | 117 | |
alindvall | 39:e1cb4dd9bfeb | 118 | /** Returns the number of bytes used by each pixel |
alindvall | 39:e1cb4dd9bfeb | 119 | * |
alindvall | 39:e1cb4dd9bfeb | 120 | * @returns bytes per pixel |
alindvall | 39:e1cb4dd9bfeb | 121 | */ |
embeddedartists | 10:1ac4b213f0f7 | 122 | virtual uint16_t bytesPerPixel() = 0; |
alindvall | 39:e1cb4dd9bfeb | 123 | |
alindvall | 39:e1cb4dd9bfeb | 124 | /** Returns the number of bytes used for each frame buffer |
alindvall | 39:e1cb4dd9bfeb | 125 | * |
alindvall | 39:e1cb4dd9bfeb | 126 | * @returns width*height*bytesPerPixel |
alindvall | 39:e1cb4dd9bfeb | 127 | */ |
embeddedartists | 10:1ac4b213f0f7 | 128 | virtual uint32_t fbSize() = 0; |
alindvall | 39:e1cb4dd9bfeb | 129 | |
alindvall | 39:e1cb4dd9bfeb | 130 | /** Returns the display orientation |
alindvall | 39:e1cb4dd9bfeb | 131 | * |
alindvall | 39:e1cb4dd9bfeb | 132 | * @returns the display orientation |
alindvall | 39:e1cb4dd9bfeb | 133 | */ |
embeddedartists | 10:1ac4b213f0f7 | 134 | virtual bool landscape() = 0; |
alindvall | 39:e1cb4dd9bfeb | 135 | |
alindvall | 39:e1cb4dd9bfeb | 136 | /** Returns true if the specified resolution can be used |
alindvall | 39:e1cb4dd9bfeb | 137 | * |
alindvall | 39:e1cb4dd9bfeb | 138 | * @returns true if supported, false if not |
alindvall | 39:e1cb4dd9bfeb | 139 | */ |
embeddedartists | 10:1ac4b213f0f7 | 140 | virtual bool isSupported(Resolution res) = 0; |
alindvall | 39:e1cb4dd9bfeb | 141 | |
alindvall | 39:e1cb4dd9bfeb | 142 | /** Returns the current resolution |
alindvall | 39:e1cb4dd9bfeb | 143 | * |
alindvall | 39:e1cb4dd9bfeb | 144 | * @returns the current resolution |
alindvall | 39:e1cb4dd9bfeb | 145 | */ |
embeddedartists | 10:1ac4b213f0f7 | 146 | virtual Resolution currentResolution() = 0; |
embeddedartists | 9:a33326afd686 | 147 | |
embeddedartists | 9:a33326afd686 | 148 | /** Replaces the current framebuffer. |
embeddedartists | 9:a33326afd686 | 149 | * |
embeddedartists | 9:a33326afd686 | 150 | * Note that this requires the caller or someone else to have a |
embeddedartists | 9:a33326afd686 | 151 | * reference to the existing framebuffer, otherwise that memory |
embeddedartists | 9:a33326afd686 | 152 | * is lost. |
embeddedartists | 9:a33326afd686 | 153 | * |
embeddedartists | 9:a33326afd686 | 154 | * @param buff the new framebuffer |
embeddedartists | 9:a33326afd686 | 155 | */ |
embeddedartists | 10:1ac4b213f0f7 | 156 | virtual void setFramebuffer(void* buff) = 0; |
embeddedartists | 9:a33326afd686 | 157 | |
embeddedartists | 9:a33326afd686 | 158 | /** Replaces the current framebuffer with the specified one. |
embeddedartists | 9:a33326afd686 | 159 | * |
embeddedartists | 9:a33326afd686 | 160 | * This function as opposed to the setFramebuffer() one does return |
embeddedartists | 9:a33326afd686 | 161 | * the old framebuffer. This way the caller can save the old one and |
embeddedartists | 9:a33326afd686 | 162 | * then swap it back when done. |
embeddedartists | 9:a33326afd686 | 163 | * |
embeddedartists | 9:a33326afd686 | 164 | * @param buff the new framebuffer |
embeddedartists | 9:a33326afd686 | 165 | * @returns the old framebuffer |
embeddedartists | 9:a33326afd686 | 166 | */ |
embeddedartists | 10:1ac4b213f0f7 | 167 | virtual void* swapFramebuffer(void* buff) = 0; |
embeddedartists | 9:a33326afd686 | 168 | |
embeddedartists | 9:a33326afd686 | 169 | /** Allocate enough memory for one framebuffer |
embeddedartists | 9:a33326afd686 | 170 | * |
embeddedartists | 9:a33326afd686 | 171 | * This function is a to make it easier to allocate memory for framebuffers |
embeddedartists | 9:a33326afd686 | 172 | * as the number of bytes needed depends on width, height and bytes per pixel. |
embeddedartists | 9:a33326afd686 | 173 | * |
embeddedartists | 9:a33326afd686 | 174 | * Free the allocated memory when done using the free() function. |
embeddedartists | 9:a33326afd686 | 175 | * |
embeddedartists | 31:d47cffcb0a3e | 176 | * @param res the resolution (default is the one that the display is using) |
embeddedartists | 9:a33326afd686 | 177 | * @returns a new framebuffer or NULL if out of memory |
embeddedartists | 9:a33326afd686 | 178 | */ |
embeddedartists | 10:1ac4b213f0f7 | 179 | virtual void* allocateFramebuffer(Resolution res=Resolution_16bit_rgb565) = 0; |
embeddedartists | 31:d47cffcb0a3e | 180 | |
embeddedartists | 31:d47cffcb0a3e | 181 | /** Allocate enough memory for one or more consequtive framebuffers |
embeddedartists | 31:d47cffcb0a3e | 182 | * |
embeddedartists | 31:d47cffcb0a3e | 183 | * This function is a to make it easier to allocate memory for framebuffers |
embeddedartists | 31:d47cffcb0a3e | 184 | * as the number of bytes needed depends on width, height and bytes per pixel. |
embeddedartists | 31:d47cffcb0a3e | 185 | * |
embeddedartists | 31:d47cffcb0a3e | 186 | * Free the allocated memory when done using the free() function. |
embeddedartists | 31:d47cffcb0a3e | 187 | * |
embeddedartists | 31:d47cffcb0a3e | 188 | * Use the default parameters to get one framebuffer for the display's current |
embeddedartists | 31:d47cffcb0a3e | 189 | * resolution. |
embeddedartists | 31:d47cffcb0a3e | 190 | * |
embeddedartists | 31:d47cffcb0a3e | 191 | * @param num the number of framebuffers, should be >= 1 |
embeddedartists | 31:d47cffcb0a3e | 192 | * @param res the resolution (default is the one that the display is using) |
embeddedartists | 31:d47cffcb0a3e | 193 | * @returns new framebuffers or NULL if out of memory |
embeddedartists | 31:d47cffcb0a3e | 194 | */ |
embeddedartists | 31:d47cffcb0a3e | 195 | virtual void* allocateFramebuffers(uint32_t num=1, Resolution res=Resolution_16bit_rgb565) = 0; |
embeddedartists | 0:6b68dac0d986 | 196 | }; |
embeddedartists | 0:6b68dac0d986 | 197 | |
embeddedartists | 0:6b68dac0d986 | 198 | #endif |