t
Dependencies: DM_FATFileSystem DM_HttpServer DM_USBHost EthernetInterface USBDevice mbed-rpc mbed-rtos
Fork of DMSupport by
Display/Display.h@9:a33326afd686, 2014-12-11 (annotated)
- Committer:
- embeddedartists
- Date:
- Thu Dec 11 18:23:07 2014 +0000
- Revision:
- 9:a33326afd686
- Parent:
- 0:6b68dac0d986
- Child:
- 10:1ac4b213f0f7
Updated documentation
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 | 0:6b68dac0d986 | 21 | |
embeddedartists | 9:a33326afd686 | 22 | /** |
embeddedartists | 9:a33326afd686 | 23 | * Display example |
embeddedartists | 9:a33326afd686 | 24 | * |
embeddedartists | 9:a33326afd686 | 25 | * @code |
embeddedartists | 9:a33326afd686 | 26 | * #include "mbed.h" |
embeddedartists | 9:a33326afd686 | 27 | * #include "DMBoard.h" |
embeddedartists | 9:a33326afd686 | 28 | * |
embeddedartists | 9:a33326afd686 | 29 | * int main(void) { |
embeddedartists | 9:a33326afd686 | 30 | * // initialize the display |
embeddedartists | 9:a33326afd686 | 31 | * DMBoard::instance().init(); |
embeddedartists | 9:a33326afd686 | 32 | * |
embeddedartists | 9:a33326afd686 | 33 | * // allocate one framebuffer |
embeddedartists | 9:a33326afd686 | 34 | * Display* disp = DMBoard::instance().display(); |
embeddedartists | 9:a33326afd686 | 35 | * uint16_t* fb = (uint16_t*)disp->allocateFramebuffer(); |
embeddedartists | 9:a33326afd686 | 36 | * if (fb == NULL) { |
embeddedartists | 9:a33326afd686 | 37 | * DMBoard::instance().logger()->printf("Failed to allocate memory for framebuffer\r\n"); |
embeddedartists | 9:a33326afd686 | 38 | * mbed_die(); |
embeddedartists | 9:a33326afd686 | 39 | * } |
embeddedartists | 9:a33326afd686 | 40 | * |
embeddedartists | 9:a33326afd686 | 41 | * // draw something on the framebuffer |
embeddedartists | 9:a33326afd686 | 42 | * ... |
embeddedartists | 9:a33326afd686 | 43 | * |
embeddedartists | 9:a33326afd686 | 44 | * // turn on the display |
embeddedartists | 9:a33326afd686 | 45 | * disperr = disp->powerUp(fb); |
embeddedartists | 9:a33326afd686 | 46 | * if (disperr != Display::Ok) { |
embeddedartists | 9:a33326afd686 | 47 | * DMBoard::instance().logger()->printf("Failed to initialize the display, got error %d\r\n", disperr); |
embeddedartists | 9:a33326afd686 | 48 | * mbed_die(); |
embeddedartists | 9:a33326afd686 | 49 | * } |
embeddedartists | 9:a33326afd686 | 50 | * |
embeddedartists | 9:a33326afd686 | 51 | * ... |
embeddedartists | 9:a33326afd686 | 52 | * } |
embeddedartists | 9:a33326afd686 | 53 | * @endcode |
embeddedartists | 9:a33326afd686 | 54 | */ |
embeddedartists | 0:6b68dac0d986 | 55 | class Display { |
embeddedartists | 0:6b68dac0d986 | 56 | public: |
embeddedartists | 0:6b68dac0d986 | 57 | enum Constants { |
embeddedartists | 0:6b68dac0d986 | 58 | NumLEDs = 4, |
embeddedartists | 0:6b68dac0d986 | 59 | }; |
embeddedartists | 0:6b68dac0d986 | 60 | |
embeddedartists | 0:6b68dac0d986 | 61 | enum DisplayError { |
embeddedartists | 0:6b68dac0d986 | 62 | Ok = 0, |
embeddedartists | 0:6b68dac0d986 | 63 | ConfigError = 1, |
embeddedartists | 0:6b68dac0d986 | 64 | WrongBPP = 2, |
embeddedartists | 0:6b68dac0d986 | 65 | InvalidParam = 3, |
embeddedartists | 0:6b68dac0d986 | 66 | NoInit = 4, |
embeddedartists | 0:6b68dac0d986 | 67 | }; |
embeddedartists | 0:6b68dac0d986 | 68 | |
embeddedartists | 0:6b68dac0d986 | 69 | enum Resolution { |
embeddedartists | 0:6b68dac0d986 | 70 | Resolution_16bit_rgb565 = 16, |
embeddedartists | 0:6b68dac0d986 | 71 | Resolution_18bit_rgb666 = 18, |
embeddedartists | 0:6b68dac0d986 | 72 | Resolution_24bit_rgb888 = 24, |
embeddedartists | 0:6b68dac0d986 | 73 | }; |
embeddedartists | 0:6b68dac0d986 | 74 | |
embeddedartists | 9:a33326afd686 | 75 | /** Get the only instance of the Display |
embeddedartists | 9:a33326afd686 | 76 | * |
embeddedartists | 9:a33326afd686 | 77 | * @returns The display |
embeddedartists | 9:a33326afd686 | 78 | */ |
embeddedartists | 0:6b68dac0d986 | 79 | static Display& instance() |
embeddedartists | 0:6b68dac0d986 | 80 | { |
embeddedartists | 0:6b68dac0d986 | 81 | static Display singleton; |
embeddedartists | 0:6b68dac0d986 | 82 | return singleton; |
embeddedartists | 0:6b68dac0d986 | 83 | } |
embeddedartists | 0:6b68dac0d986 | 84 | |
embeddedartists | 0:6b68dac0d986 | 85 | |
embeddedartists | 9:a33326afd686 | 86 | /** Initializes the display but does not turn it on |
embeddedartists | 0:6b68dac0d986 | 87 | * |
embeddedartists | 0:6b68dac0d986 | 88 | * @returns |
embeddedartists | 0:6b68dac0d986 | 89 | * Ok on success |
embeddedartists | 0:6b68dac0d986 | 90 | * An error code on failure |
embeddedartists | 0:6b68dac0d986 | 91 | */ |
embeddedartists | 0:6b68dac0d986 | 92 | DisplayError init(); |
embeddedartists | 0:6b68dac0d986 | 93 | |
embeddedartists | 9:a33326afd686 | 94 | /** Turns the display on with the specified framebuffer showing |
embeddedartists | 0:6b68dac0d986 | 95 | * |
embeddedartists | 0:6b68dac0d986 | 96 | * @returns |
embeddedartists | 0:6b68dac0d986 | 97 | * Ok on success |
embeddedartists | 0:6b68dac0d986 | 98 | * An error code on failure |
embeddedartists | 0:6b68dac0d986 | 99 | */ |
embeddedartists | 0:6b68dac0d986 | 100 | DisplayError powerUp(void* framebuffer, Resolution wanted = Resolution_16bit_rgb565); |
embeddedartists | 0:6b68dac0d986 | 101 | |
embeddedartists | 9:a33326afd686 | 102 | /** Turns the display off |
embeddedartists | 0:6b68dac0d986 | 103 | * |
embeddedartists | 0:6b68dac0d986 | 104 | * @returns |
embeddedartists | 0:6b68dac0d986 | 105 | * Ok on success |
embeddedartists | 0:6b68dac0d986 | 106 | * An error code on failure |
embeddedartists | 0:6b68dac0d986 | 107 | */ |
embeddedartists | 0:6b68dac0d986 | 108 | DisplayError powerDown(); |
embeddedartists | 0:6b68dac0d986 | 109 | |
embeddedartists | 0:6b68dac0d986 | 110 | /** Sets the backlight level. 0% is off and 100% is fully on |
embeddedartists | 0:6b68dac0d986 | 111 | * |
embeddedartists | 0:6b68dac0d986 | 112 | * @returns |
embeddedartists | 0:6b68dac0d986 | 113 | * Ok on success |
embeddedartists | 0:6b68dac0d986 | 114 | * An error code on failure |
embeddedartists | 0:6b68dac0d986 | 115 | */ |
embeddedartists | 0:6b68dac0d986 | 116 | DisplayError backlight(int percent); |
embeddedartists | 0:6b68dac0d986 | 117 | |
embeddedartists | 0:6b68dac0d986 | 118 | uint16_t width() { return _width; } |
embeddedartists | 0:6b68dac0d986 | 119 | uint16_t height() { return _height; } |
embeddedartists | 0:6b68dac0d986 | 120 | uint16_t bpp() { return _bpp; } |
embeddedartists | 0:6b68dac0d986 | 121 | uint32_t fbSize() { return _fbSize; } |
embeddedartists | 0:6b68dac0d986 | 122 | bool landscape() { return _landscape; } |
embeddedartists | 0:6b68dac0d986 | 123 | bool isSupported(Resolution res); |
embeddedartists | 9:a33326afd686 | 124 | |
embeddedartists | 9:a33326afd686 | 125 | /** Replaces the current framebuffer. |
embeddedartists | 9:a33326afd686 | 126 | * |
embeddedartists | 9:a33326afd686 | 127 | * Note that this requires the caller or someone else to have a |
embeddedartists | 9:a33326afd686 | 128 | * reference to the existing framebuffer, otherwise that memory |
embeddedartists | 9:a33326afd686 | 129 | * is lost. |
embeddedartists | 9:a33326afd686 | 130 | * |
embeddedartists | 9:a33326afd686 | 131 | * @param buff the new framebuffer |
embeddedartists | 9:a33326afd686 | 132 | */ |
embeddedartists | 0:6b68dac0d986 | 133 | void setFramebuffer(void* buff); |
embeddedartists | 9:a33326afd686 | 134 | |
embeddedartists | 9:a33326afd686 | 135 | /** Replaces the current framebuffer with the specified one. |
embeddedartists | 9:a33326afd686 | 136 | * |
embeddedartists | 9:a33326afd686 | 137 | * This function as opposed to the setFramebuffer() one does return |
embeddedartists | 9:a33326afd686 | 138 | * the old framebuffer. This way the caller can save the old one and |
embeddedartists | 9:a33326afd686 | 139 | * then swap it back when done. |
embeddedartists | 9:a33326afd686 | 140 | * |
embeddedartists | 9:a33326afd686 | 141 | * @param buff the new framebuffer |
embeddedartists | 9:a33326afd686 | 142 | * @returns the old framebuffer |
embeddedartists | 9:a33326afd686 | 143 | */ |
embeddedartists | 0:6b68dac0d986 | 144 | void* swapFramebuffer(void* buff); |
embeddedartists | 9:a33326afd686 | 145 | |
embeddedartists | 9:a33326afd686 | 146 | /** Allocate enough memory for one framebuffer |
embeddedartists | 9:a33326afd686 | 147 | * |
embeddedartists | 9:a33326afd686 | 148 | * This function is a to make it easier to allocate memory for framebuffers |
embeddedartists | 9:a33326afd686 | 149 | * as the number of bytes needed depends on width, height and bytes per pixel. |
embeddedartists | 9:a33326afd686 | 150 | * |
embeddedartists | 9:a33326afd686 | 151 | * Free the allocated memory when done using the free() function. |
embeddedartists | 9:a33326afd686 | 152 | * |
embeddedartists | 9:a33326afd686 | 153 | * @returns a new framebuffer or NULL if out of memory |
embeddedartists | 9:a33326afd686 | 154 | */ |
embeddedartists | 0:6b68dac0d986 | 155 | void* allocateFramebuffer(Resolution res=Resolution_16bit_rgb565); |
embeddedartists | 0:6b68dac0d986 | 156 | |
embeddedartists | 0:6b68dac0d986 | 157 | private: |
embeddedartists | 0:6b68dac0d986 | 158 | |
embeddedartists | 0:6b68dac0d986 | 159 | bool _initialized; |
embeddedartists | 0:6b68dac0d986 | 160 | bool _poweredOn; |
embeddedartists | 0:6b68dac0d986 | 161 | DigitalOut _pinWP; |
embeddedartists | 0:6b68dac0d986 | 162 | DigitalOut _pin3v3; |
embeddedartists | 0:6b68dac0d986 | 163 | DigitalOut _pin5v; |
embeddedartists | 0:6b68dac0d986 | 164 | DigitalOut _pinDE; |
embeddedartists | 0:6b68dac0d986 | 165 | DigitalOut _pinColDepth; |
embeddedartists | 0:6b68dac0d986 | 166 | PwmOut _pinBacklight; |
embeddedartists | 0:6b68dac0d986 | 167 | |
embeddedartists | 0:6b68dac0d986 | 168 | uint16_t _width; |
embeddedartists | 0:6b68dac0d986 | 169 | uint16_t _height; |
embeddedartists | 0:6b68dac0d986 | 170 | uint16_t _bpp; |
embeddedartists | 0:6b68dac0d986 | 171 | uint32_t _fbSize; |
embeddedartists | 0:6b68dac0d986 | 172 | bool _landscape; |
embeddedartists | 0:6b68dac0d986 | 173 | |
embeddedartists | 0:6b68dac0d986 | 174 | explicit Display(); |
embeddedartists | 0:6b68dac0d986 | 175 | // hide copy constructor |
embeddedartists | 0:6b68dac0d986 | 176 | Display(const Display&); |
embeddedartists | 0:6b68dac0d986 | 177 | // hide assign operator |
embeddedartists | 0:6b68dac0d986 | 178 | Display& operator=(const Display&); |
embeddedartists | 0:6b68dac0d986 | 179 | ~Display(); |
embeddedartists | 0:6b68dac0d986 | 180 | |
embeddedartists | 0:6b68dac0d986 | 181 | void pinInit(bool powerOn, Resolution res=Resolution_16bit_rgb565); |
embeddedartists | 0:6b68dac0d986 | 182 | DisplayError regInit(void* info, Resolution res); |
embeddedartists | 0:6b68dac0d986 | 183 | uint32_t getClockDivisor(uint32_t clock); |
embeddedartists | 0:6b68dac0d986 | 184 | void set3v3(bool on); |
embeddedartists | 0:6b68dac0d986 | 185 | void set5v(bool on); |
embeddedartists | 0:6b68dac0d986 | 186 | void setDisplayEnable(bool enable); |
embeddedartists | 0:6b68dac0d986 | 187 | }; |
embeddedartists | 0:6b68dac0d986 | 188 | |
embeddedartists | 0:6b68dac0d986 | 189 | #endif |