Update version of EALib.
Dependencies: FATFileSystem
Fork of EALib by
LcdController.h@27:b623423ad6e2, 2017-12-05 (annotated)
- Committer:
- Brendan McDonnell
- Date:
- Tue Dec 05 12:16:26 2017 -0500
- Branch:
- mbed-os
- Revision:
- 27:b623423ad6e2
- Parent:
- 12:15597e45eea0
created branch mbed-os
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 12:15597e45eea0 | 1 | /* |
embeddedartists | 12:15597e45eea0 | 2 | * Copyright 2013 Embedded Artists AB |
embeddedartists | 12:15597e45eea0 | 3 | * |
embeddedartists | 12:15597e45eea0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
embeddedartists | 12:15597e45eea0 | 5 | * you may not use this file except in compliance with the License. |
embeddedartists | 12:15597e45eea0 | 6 | * You may obtain a copy of the License at |
embeddedartists | 12:15597e45eea0 | 7 | * |
embeddedartists | 12:15597e45eea0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
embeddedartists | 12:15597e45eea0 | 9 | * |
embeddedartists | 12:15597e45eea0 | 10 | * Unless required by applicable law or agreed to in writing, software |
embeddedartists | 12:15597e45eea0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
embeddedartists | 12:15597e45eea0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
embeddedartists | 12:15597e45eea0 | 13 | * See the License for the specific language governing permissions and |
embeddedartists | 12:15597e45eea0 | 14 | * limitations under the License. |
embeddedartists | 12:15597e45eea0 | 15 | */ |
embeddedartists | 0:0fdadbc3d852 | 16 | |
embeddedartists | 0:0fdadbc3d852 | 17 | #ifndef LCDCONTROLLER_H |
embeddedartists | 0:0fdadbc3d852 | 18 | #define LCDCONTROLLER_H |
embeddedartists | 0:0fdadbc3d852 | 19 | |
embeddedartists | 0:0fdadbc3d852 | 20 | /** |
embeddedartists | 0:0fdadbc3d852 | 21 | * A LCD controller interface |
embeddedartists | 0:0fdadbc3d852 | 22 | * |
embeddedartists | 0:0fdadbc3d852 | 23 | * @code |
embeddedartists | 0:0fdadbc3d852 | 24 | * #include "mbed.h" |
embeddedartists | 0:0fdadbc3d852 | 25 | * #include "LcdController.h" |
embeddedartists | 0:0fdadbc3d852 | 26 | * |
embeddedartists | 0:0fdadbc3d852 | 27 | * LcdController::Config innolux( |
embeddedartists | 0:0fdadbc3d852 | 28 | * 45, |
embeddedartists | 0:0fdadbc3d852 | 29 | * 17, |
embeddedartists | 0:0fdadbc3d852 | 30 | * 2, |
embeddedartists | 0:0fdadbc3d852 | 31 | * 800, |
embeddedartists | 0:0fdadbc3d852 | 32 | * 22, |
embeddedartists | 0:0fdadbc3d852 | 33 | * 22, |
embeddedartists | 0:0fdadbc3d852 | 34 | * 2, |
embeddedartists | 0:0fdadbc3d852 | 35 | * 480, |
embeddedartists | 0:0fdadbc3d852 | 36 | * false, |
embeddedartists | 0:0fdadbc3d852 | 37 | * false, |
embeddedartists | 0:0fdadbc3d852 | 38 | * true, |
embeddedartists | 0:0fdadbc3d852 | 39 | * true, |
embeddedartists | 0:0fdadbc3d852 | 40 | * true, |
embeddedartists | 0:0fdadbc3d852 | 41 | * LcdController::Bpp_16_565, |
embeddedartists | 0:0fdadbc3d852 | 42 | * 36000000, |
embeddedartists | 0:0fdadbc3d852 | 43 | * LcdController::Tft, |
embeddedartists | 0:0fdadbc3d852 | 44 | * false); |
embeddedartists | 0:0fdadbc3d852 | 45 | * |
embeddedartists | 0:0fdadbc3d852 | 46 | * int main(void) { |
embeddedartists | 0:0fdadbc3d852 | 47 | * LcdController lcd; |
embeddedartists | 0:0fdadbc3d852 | 48 | * |
embeddedartists | 0:0fdadbc3d852 | 49 | * lcd.open(&innolux); |
embeddedartists | 0:0fdadbc3d852 | 50 | * lcd.setFrameBuffer(frameBuffer); |
embeddedartists | 0:0fdadbc3d852 | 51 | * lcd.setPower(true); |
embeddedartists | 0:0fdadbc3d852 | 52 | * |
embeddedartists | 0:0fdadbc3d852 | 53 | * // draw on the frame buffer |
embeddedartists | 0:0fdadbc3d852 | 54 | * ... |
embeddedartists | 0:0fdadbc3d852 | 55 | * } |
embeddedartists | 0:0fdadbc3d852 | 56 | * @endcode |
embeddedartists | 0:0fdadbc3d852 | 57 | */ |
embeddedartists | 0:0fdadbc3d852 | 58 | class LcdController { |
embeddedartists | 0:0fdadbc3d852 | 59 | public: |
embeddedartists | 0:0fdadbc3d852 | 60 | |
embeddedartists | 0:0fdadbc3d852 | 61 | enum LcdPanel { |
embeddedartists | 0:0fdadbc3d852 | 62 | Tft = 0, // standard TFT |
embeddedartists | 0:0fdadbc3d852 | 63 | AdTft, // advanced TFT |
embeddedartists | 0:0fdadbc3d852 | 64 | HrTft, // highly reflective TFT |
embeddedartists | 0:0fdadbc3d852 | 65 | Mono_4Bit, // 4-bit mono |
embeddedartists | 0:0fdadbc3d852 | 66 | Mono_8Bit, // 8-bit mono |
embeddedartists | 0:0fdadbc3d852 | 67 | ColorStn // Color STN |
embeddedartists | 0:0fdadbc3d852 | 68 | }; |
embeddedartists | 0:0fdadbc3d852 | 69 | |
embeddedartists | 0:0fdadbc3d852 | 70 | enum BitsPerPixel { |
embeddedartists | 0:0fdadbc3d852 | 71 | Bpp_1 = 0, |
embeddedartists | 0:0fdadbc3d852 | 72 | Bpp_2, |
embeddedartists | 0:0fdadbc3d852 | 73 | Bpp_4, |
embeddedartists | 0:0fdadbc3d852 | 74 | Bpp_8, |
embeddedartists | 0:0fdadbc3d852 | 75 | Bpp_16, |
embeddedartists | 0:0fdadbc3d852 | 76 | Bpp_24, |
embeddedartists | 0:0fdadbc3d852 | 77 | Bpp_16_565, |
embeddedartists | 0:0fdadbc3d852 | 78 | Bpp_12_444 |
embeddedartists | 0:0fdadbc3d852 | 79 | }; |
embeddedartists | 0:0fdadbc3d852 | 80 | |
embeddedartists | 0:0fdadbc3d852 | 81 | /** |
embeddedartists | 0:0fdadbc3d852 | 82 | * LCD configuration |
embeddedartists | 0:0fdadbc3d852 | 83 | */ |
embeddedartists | 0:0fdadbc3d852 | 84 | class Config { |
embeddedartists | 0:0fdadbc3d852 | 85 | public: |
embeddedartists | 0:0fdadbc3d852 | 86 | |
embeddedartists | 0:0fdadbc3d852 | 87 | /** Create an empty LCD configuration object |
embeddedartists | 0:0fdadbc3d852 | 88 | * |
embeddedartists | 0:0fdadbc3d852 | 89 | */ |
embeddedartists | 0:0fdadbc3d852 | 90 | Config() { |
embeddedartists | 0:0fdadbc3d852 | 91 | } |
embeddedartists | 0:0fdadbc3d852 | 92 | |
embeddedartists | 0:0fdadbc3d852 | 93 | /** Create a LCD configuration object with specified values |
embeddedartists | 0:0fdadbc3d852 | 94 | * |
embeddedartists | 0:0fdadbc3d852 | 95 | * @param horizontalBackPorch Horizontal back porch in clocks |
embeddedartists | 0:0fdadbc3d852 | 96 | * @param horizontalFrontPorch Horizontal front porch in clocks |
embeddedartists | 0:0fdadbc3d852 | 97 | * @param hsync HSYNC pulse width in clocks |
embeddedartists | 0:0fdadbc3d852 | 98 | * @param width width of display in pixels |
embeddedartists | 0:0fdadbc3d852 | 99 | * @param verticalBackPorch vertical back porch in clocks |
embeddedartists | 0:0fdadbc3d852 | 100 | * @param verticalFrontPorch vertical front porch in clocks |
embeddedartists | 0:0fdadbc3d852 | 101 | * @param vsync VSYNC pulse width in clocks |
embeddedartists | 0:0fdadbc3d852 | 102 | * @param height height of display in pixels |
embeddedartists | 0:0fdadbc3d852 | 103 | * @param invertOutputEnable true to invert output enable |
embeddedartists | 0:0fdadbc3d852 | 104 | * @param invertPanelClock true to invert panel clock |
embeddedartists | 0:0fdadbc3d852 | 105 | * @param invertHsync true to invert HSYNC |
embeddedartists | 0:0fdadbc3d852 | 106 | * @param invertVsync true to invert VSYNC |
embeddedartists | 0:0fdadbc3d852 | 107 | * @param acBias AC bias frequency in clocks |
embeddedartists | 0:0fdadbc3d852 | 108 | * @param bpp bits per pixel |
embeddedartists | 0:0fdadbc3d852 | 109 | * @param optimalClock optimal clock rate (Hz) |
embeddedartists | 0:0fdadbc3d852 | 110 | * @param panelType LCD panel type |
embeddedartists | 0:0fdadbc3d852 | 111 | * @param dualPanel true if it is a dual panel display |
embeddedartists | 0:0fdadbc3d852 | 112 | */ |
embeddedartists | 0:0fdadbc3d852 | 113 | Config(int horizontalBackPorch, |
embeddedartists | 0:0fdadbc3d852 | 114 | int horizontalFrontPorch, |
embeddedartists | 0:0fdadbc3d852 | 115 | int hsync, |
embeddedartists | 0:0fdadbc3d852 | 116 | int width, |
embeddedartists | 0:0fdadbc3d852 | 117 | int verticalBackPorch, |
embeddedartists | 0:0fdadbc3d852 | 118 | int verticalFrontPorch, |
embeddedartists | 0:0fdadbc3d852 | 119 | int vsync, |
embeddedartists | 0:0fdadbc3d852 | 120 | int height, |
embeddedartists | 0:0fdadbc3d852 | 121 | bool invertOutputEnable, |
embeddedartists | 0:0fdadbc3d852 | 122 | bool invertPanelClock, |
embeddedartists | 0:0fdadbc3d852 | 123 | bool invertHsync, |
embeddedartists | 0:0fdadbc3d852 | 124 | bool invertVsync, |
embeddedartists | 0:0fdadbc3d852 | 125 | int acBias, |
embeddedartists | 0:0fdadbc3d852 | 126 | BitsPerPixel bpp, |
embeddedartists | 0:0fdadbc3d852 | 127 | int optimalClock, |
embeddedartists | 0:0fdadbc3d852 | 128 | LcdPanel panelType, |
embeddedartists | 0:0fdadbc3d852 | 129 | bool dualPanel) { |
embeddedartists | 0:0fdadbc3d852 | 130 | |
embeddedartists | 0:0fdadbc3d852 | 131 | this->horizontalBackPorch = horizontalBackPorch; |
embeddedartists | 0:0fdadbc3d852 | 132 | this->horizontalFrontPorch = horizontalFrontPorch; |
embeddedartists | 0:0fdadbc3d852 | 133 | this->hsync = hsync; |
embeddedartists | 0:0fdadbc3d852 | 134 | this->width = width; |
embeddedartists | 0:0fdadbc3d852 | 135 | this->verticalBackPorch = verticalBackPorch; |
embeddedartists | 0:0fdadbc3d852 | 136 | this->verticalFrontPorch = verticalFrontPorch; |
embeddedartists | 0:0fdadbc3d852 | 137 | this->vsync = vsync; |
embeddedartists | 0:0fdadbc3d852 | 138 | this->height = height; |
embeddedartists | 0:0fdadbc3d852 | 139 | this->invertOutputEnable = invertOutputEnable; |
embeddedartists | 0:0fdadbc3d852 | 140 | this->invertPanelClock = invertPanelClock; |
embeddedartists | 0:0fdadbc3d852 | 141 | this->invertHsync = invertHsync; |
embeddedartists | 0:0fdadbc3d852 | 142 | this->invertVsync = invertVsync; |
embeddedartists | 0:0fdadbc3d852 | 143 | this->acBias = acBias; |
embeddedartists | 0:0fdadbc3d852 | 144 | this->bpp = bpp; |
embeddedartists | 0:0fdadbc3d852 | 145 | this->optimalClock = optimalClock; |
embeddedartists | 0:0fdadbc3d852 | 146 | this->panelType = panelType; |
embeddedartists | 0:0fdadbc3d852 | 147 | this->dualPanel = dualPanel; |
embeddedartists | 0:0fdadbc3d852 | 148 | } |
embeddedartists | 0:0fdadbc3d852 | 149 | |
embeddedartists | 0:0fdadbc3d852 | 150 | int horizontalBackPorch; |
embeddedartists | 0:0fdadbc3d852 | 151 | int horizontalFrontPorch; |
embeddedartists | 0:0fdadbc3d852 | 152 | int hsync; |
embeddedartists | 0:0fdadbc3d852 | 153 | int width; |
embeddedartists | 0:0fdadbc3d852 | 154 | int verticalBackPorch; |
embeddedartists | 0:0fdadbc3d852 | 155 | int verticalFrontPorch; |
embeddedartists | 0:0fdadbc3d852 | 156 | int vsync; |
embeddedartists | 0:0fdadbc3d852 | 157 | int height; |
embeddedartists | 0:0fdadbc3d852 | 158 | bool invertOutputEnable; |
embeddedartists | 0:0fdadbc3d852 | 159 | bool invertPanelClock; |
embeddedartists | 0:0fdadbc3d852 | 160 | bool invertHsync; |
embeddedartists | 0:0fdadbc3d852 | 161 | bool invertVsync; |
embeddedartists | 0:0fdadbc3d852 | 162 | int acBias; |
embeddedartists | 0:0fdadbc3d852 | 163 | BitsPerPixel bpp; |
embeddedartists | 0:0fdadbc3d852 | 164 | int optimalClock; |
embeddedartists | 0:0fdadbc3d852 | 165 | LcdPanel panelType; |
embeddedartists | 0:0fdadbc3d852 | 166 | bool dualPanel; |
embeddedartists | 0:0fdadbc3d852 | 167 | }; |
embeddedartists | 0:0fdadbc3d852 | 168 | |
embeddedartists | 0:0fdadbc3d852 | 169 | /** Create a LCD controller interface |
embeddedartists | 0:0fdadbc3d852 | 170 | * |
embeddedartists | 0:0fdadbc3d852 | 171 | */ |
embeddedartists | 0:0fdadbc3d852 | 172 | LcdController(); |
embeddedartists | 0:0fdadbc3d852 | 173 | |
embeddedartists | 0:0fdadbc3d852 | 174 | /** Open and initialize the LCD controller with the given LCD configuration |
embeddedartists | 0:0fdadbc3d852 | 175 | * |
embeddedartists | 0:0fdadbc3d852 | 176 | * @param cfg LCD configuration |
embeddedartists | 0:0fdadbc3d852 | 177 | * |
embeddedartists | 0:0fdadbc3d852 | 178 | * @returns |
embeddedartists | 0:0fdadbc3d852 | 179 | * 0 on success |
embeddedartists | 0:0fdadbc3d852 | 180 | * 1 on failure |
embeddedartists | 0:0fdadbc3d852 | 181 | */ |
embeddedartists | 0:0fdadbc3d852 | 182 | int open(LcdController::Config* cfg); |
embeddedartists | 0:0fdadbc3d852 | 183 | |
embeddedartists | 0:0fdadbc3d852 | 184 | /** Close the LCD controller |
embeddedartists | 0:0fdadbc3d852 | 185 | * |
embeddedartists | 0:0fdadbc3d852 | 186 | * @returns |
embeddedartists | 0:0fdadbc3d852 | 187 | * 0 on success |
embeddedartists | 0:0fdadbc3d852 | 188 | * 1 on failure |
embeddedartists | 0:0fdadbc3d852 | 189 | */ |
embeddedartists | 0:0fdadbc3d852 | 190 | int close(); |
embeddedartists | 0:0fdadbc3d852 | 191 | |
embeddedartists | 0:0fdadbc3d852 | 192 | /** Set and activate the address of the frame buffer to use. |
embeddedartists | 0:0fdadbc3d852 | 193 | * |
embeddedartists | 0:0fdadbc3d852 | 194 | * It is the content of the frame buffer that is shown on the |
embeddedartists | 0:0fdadbc3d852 | 195 | * display. All the drawing on the frame buffer can be done |
embeddedartists | 0:0fdadbc3d852 | 196 | * 'offline' and whenever it should be shown this function |
embeddedartists | 0:0fdadbc3d852 | 197 | * can be called with the address of the offline frame buffer. |
embeddedartists | 0:0fdadbc3d852 | 198 | * |
embeddedartists | 0:0fdadbc3d852 | 199 | * @param address Memory address of the frame buffer |
embeddedartists | 0:0fdadbc3d852 | 200 | * |
embeddedartists | 0:0fdadbc3d852 | 201 | * @returns |
embeddedartists | 0:0fdadbc3d852 | 202 | * 0 on success |
embeddedartists | 0:0fdadbc3d852 | 203 | * 1 on failure |
embeddedartists | 0:0fdadbc3d852 | 204 | */ |
embeddedartists | 0:0fdadbc3d852 | 205 | int setFrameBuffer(uint32_t address); |
embeddedartists | 0:0fdadbc3d852 | 206 | |
embeddedartists | 0:0fdadbc3d852 | 207 | /** Turn on/off the power to the display. |
embeddedartists | 0:0fdadbc3d852 | 208 | * |
embeddedartists | 0:0fdadbc3d852 | 209 | * @param on true to turn on, false to turn off |
embeddedartists | 0:0fdadbc3d852 | 210 | * |
embeddedartists | 0:0fdadbc3d852 | 211 | * @returns |
embeddedartists | 0:0fdadbc3d852 | 212 | * 0 on success |
embeddedartists | 0:0fdadbc3d852 | 213 | * 1 on failure |
embeddedartists | 0:0fdadbc3d852 | 214 | */ |
embeddedartists | 0:0fdadbc3d852 | 215 | int setPower(bool on); |
embeddedartists | 0:0fdadbc3d852 | 216 | |
embeddedartists | 0:0fdadbc3d852 | 217 | |
embeddedartists | 0:0fdadbc3d852 | 218 | private: |
embeddedartists | 0:0fdadbc3d852 | 219 | |
embeddedartists | 0:0fdadbc3d852 | 220 | bool _opened; |
embeddedartists | 0:0fdadbc3d852 | 221 | static bool _lcdControllerUsed; |
embeddedartists | 0:0fdadbc3d852 | 222 | |
embeddedartists | 0:0fdadbc3d852 | 223 | void init(LcdController::Config* cfg); |
embeddedartists | 0:0fdadbc3d852 | 224 | void pinConfig(); |
embeddedartists | 0:0fdadbc3d852 | 225 | uint32_t getClockDivisor(int clock); |
embeddedartists | 0:0fdadbc3d852 | 226 | }; |
embeddedartists | 0:0fdadbc3d852 | 227 | |
embeddedartists | 0:0fdadbc3d852 | 228 | #endif |
embeddedartists | 0:0fdadbc3d852 | 229 | |
embeddedartists | 0:0fdadbc3d852 | 230 |