.
Display/LCD.cpp@25:daacdcf34e52, 2015-10-18 (annotated)
- Committer:
- dreschpe
- Date:
- Sun Oct 18 13:53:20 2015 +0000
- Revision:
- 25:daacdcf34e52
- Parent:
- 21:ae0a4eedfc90
- Child:
- 27:acb2594b8aa4
Add check if platform supports par port mode
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Geremia | 4:12ba0ecc2c1f | 1 | /* mbed UniGraphic library - universal LCD driver class |
Geremia | 4:12ba0ecc2c1f | 2 | * Copyright (c) 2015 Giuliano Dianda |
Geremia | 4:12ba0ecc2c1f | 3 | * Released under the MIT License: http://mbed.org/license/mit |
Geremia | 4:12ba0ecc2c1f | 4 | * |
Geremia | 4:12ba0ecc2c1f | 5 | * Derived work of: |
Geremia | 4:12ba0ecc2c1f | 6 | * |
Geremia | 4:12ba0ecc2c1f | 7 | * mbed library for the mbed Lab Board 128*32 pixel LCD |
Geremia | 3:48f3282c2be8 | 8 | * use C12832 controller |
Geremia | 3:48f3282c2be8 | 9 | * Copyright (c) 2012 Peter Drescher - DC2PD |
Geremia | 3:48f3282c2be8 | 10 | * Released under the MIT License: http://mbed.org/license/mit |
Geremia | 3:48f3282c2be8 | 11 | * |
Geremia | 3:48f3282c2be8 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Geremia | 3:48f3282c2be8 | 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Geremia | 3:48f3282c2be8 | 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
Geremia | 3:48f3282c2be8 | 15 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Geremia | 3:48f3282c2be8 | 16 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Geremia | 3:48f3282c2be8 | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
Geremia | 3:48f3282c2be8 | 18 | * THE SOFTWARE. |
Geremia | 3:48f3282c2be8 | 19 | */ |
Geremia | 3:48f3282c2be8 | 20 | |
Geremia | 0:75ec1b3cde17 | 21 | #include "LCD.h" |
Geremia | 0:75ec1b3cde17 | 22 | |
Geremia | 0:75ec1b3cde17 | 23 | //#include "mbed_debug.h" |
Geremia | 7:bb0383b91104 | 24 | |
Geremia | 0:75ec1b3cde17 | 25 | #define SWAP(a, b) { a ^= b; b ^= a; a ^= b; } |
Geremia | 2:713844a55c4e | 26 | |
Geremia | 0:75ec1b3cde17 | 27 | |
Geremia | 0:75ec1b3cde17 | 28 | LCD::LCD(proto_t displayproto, PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char *name) |
Geremia | 7:bb0383b91104 | 29 | : GraphicsDisplay(name), screensize_X(lcdsize_x), screensize_Y(lcdsize_y), _LCDPAGES(lcdsize_y>>3), _IC_X_SEGS(ic_x_segs), _IC_Y_COMS(ic_y_coms), _IC_PAGES(ic_y_coms>>3) |
Geremia | 0:75ec1b3cde17 | 30 | { |
dreschpe | 25:daacdcf34e52 | 31 | #if DEVICE_PORTINOUT |
Geremia | 0:75ec1b3cde17 | 32 | if(displayproto==PAR_8) proto = new PAR8(port, CS, reset, DC, WR, RD); |
dreschpe | 25:daacdcf34e52 | 33 | #endif |
Geremia | 1:ff019d22b275 | 34 | useNOP=false; |
Geremia | 7:bb0383b91104 | 35 | buffer = (unsigned char*) malloc (screensize_X*_LCDPAGES); |
Geremia | 1:ff019d22b275 | 36 | buffer16 = (unsigned short*)buffer; |
Geremia | 0:75ec1b3cde17 | 37 | draw_mode = NORMAL; |
Geremia | 0:75ec1b3cde17 | 38 | set_orientation(1); |
Geremia | 4:12ba0ecc2c1f | 39 | foreground(White); |
Geremia | 4:12ba0ecc2c1f | 40 | background(Black); |
Geremia | 2:713844a55c4e | 41 | set_auto_up(true); |
Geremia | 7:bb0383b91104 | 42 | tftID=0; |
Geremia | 0:75ec1b3cde17 | 43 | // cls(); |
Geremia | 0:75ec1b3cde17 | 44 | // locate(0,0); |
Geremia | 0:75ec1b3cde17 | 45 | } |
Geremia | 21:ae0a4eedfc90 | 46 | LCD::LCD(proto_t displayproto, PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char *name) |
Geremia | 21:ae0a4eedfc90 | 47 | : GraphicsDisplay(name), screensize_X(lcdsize_x), screensize_Y(lcdsize_y), _LCDPAGES(lcdsize_y>>3), _IC_X_SEGS(ic_x_segs), _IC_Y_COMS(ic_y_coms), _IC_PAGES(ic_y_coms>>3) |
Geremia | 21:ae0a4eedfc90 | 48 | { |
Geremia | 21:ae0a4eedfc90 | 49 | if(displayproto==BUS_8) |
Geremia | 21:ae0a4eedfc90 | 50 | { |
Geremia | 21:ae0a4eedfc90 | 51 | PinName pins[16]; |
Geremia | 21:ae0a4eedfc90 | 52 | for(int i=0; i<16; i++) pins[i]=NC; |
Geremia | 21:ae0a4eedfc90 | 53 | for(int i=0; i<8; i++) pins[i]=buspins[i]; |
Geremia | 21:ae0a4eedfc90 | 54 | proto = new BUS8(pins, CS, reset, DC, WR, RD); |
Geremia | 21:ae0a4eedfc90 | 55 | } |
Geremia | 21:ae0a4eedfc90 | 56 | useNOP=false; |
Geremia | 21:ae0a4eedfc90 | 57 | buffer = (unsigned char*) malloc (screensize_X*_LCDPAGES); |
Geremia | 21:ae0a4eedfc90 | 58 | buffer16 = (unsigned short*)buffer; |
Geremia | 21:ae0a4eedfc90 | 59 | draw_mode = NORMAL; |
Geremia | 21:ae0a4eedfc90 | 60 | set_orientation(1); |
Geremia | 21:ae0a4eedfc90 | 61 | foreground(White); |
Geremia | 21:ae0a4eedfc90 | 62 | background(Black); |
Geremia | 21:ae0a4eedfc90 | 63 | set_auto_up(true); |
Geremia | 21:ae0a4eedfc90 | 64 | tftID=0; |
Geremia | 21:ae0a4eedfc90 | 65 | // cls(); |
Geremia | 21:ae0a4eedfc90 | 66 | // locate(0,0); |
Geremia | 21:ae0a4eedfc90 | 67 | } |
Geremia | 1:ff019d22b275 | 68 | LCD::LCD(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char *name) |
Geremia | 7:bb0383b91104 | 69 | : GraphicsDisplay(name), screensize_X(lcdsize_x), screensize_Y(lcdsize_y), _LCDPAGES(lcdsize_y>>3), _IC_X_SEGS(ic_x_segs), _IC_Y_COMS(ic_y_coms), _IC_PAGES(ic_y_coms>>3) |
Geremia | 0:75ec1b3cde17 | 70 | { |
Geremia | 1:ff019d22b275 | 71 | if(displayproto==SPI_8) |
Geremia | 1:ff019d22b275 | 72 | { |
Geremia | 1:ff019d22b275 | 73 | proto = new SPI8(Hz, mosi, miso, sclk, CS, reset, DC); |
Geremia | 1:ff019d22b275 | 74 | useNOP=false; |
Geremia | 1:ff019d22b275 | 75 | } |
Geremia | 1:ff019d22b275 | 76 | else if(displayproto==SPI_16) |
Geremia | 1:ff019d22b275 | 77 | { |
Geremia | 1:ff019d22b275 | 78 | proto = new SPI16(Hz, mosi, miso, sclk, CS, reset, DC); |
Geremia | 1:ff019d22b275 | 79 | useNOP=true; |
Geremia | 1:ff019d22b275 | 80 | } |
Geremia | 7:bb0383b91104 | 81 | buffer = (unsigned char*) malloc (screensize_X*_LCDPAGES); |
Geremia | 1:ff019d22b275 | 82 | buffer16 = (unsigned short*)buffer; |
Geremia | 0:75ec1b3cde17 | 83 | draw_mode = NORMAL; |
Geremia | 0:75ec1b3cde17 | 84 | // cls(); |
Geremia | 0:75ec1b3cde17 | 85 | set_orientation(1); |
Geremia | 4:12ba0ecc2c1f | 86 | foreground(White); |
Geremia | 4:12ba0ecc2c1f | 87 | background(Black); |
Geremia | 2:713844a55c4e | 88 | set_auto_up(true); |
Geremia | 7:bb0383b91104 | 89 | tftID=0; |
Geremia | 0:75ec1b3cde17 | 90 | // locate(0,0); |
Geremia | 1:ff019d22b275 | 91 | |
Geremia | 0:75ec1b3cde17 | 92 | } |
Geremia | 0:75ec1b3cde17 | 93 | LCD::~LCD() |
Geremia | 0:75ec1b3cde17 | 94 | { |
Geremia | 0:75ec1b3cde17 | 95 | free(buffer); |
Geremia | 0:75ec1b3cde17 | 96 | } |
Geremia | 0:75ec1b3cde17 | 97 | |
Geremia | 1:ff019d22b275 | 98 | void LCD::wr_cmd8(unsigned char cmd) |
Geremia | 0:75ec1b3cde17 | 99 | { |
Geremia | 2:713844a55c4e | 100 | if(useNOP) proto->wr_cmd16(0xE300|cmd); // E3 is NOP cmd for LCD |
Geremia | 1:ff019d22b275 | 101 | else proto->wr_cmd8(cmd); |
Geremia | 0:75ec1b3cde17 | 102 | } |
Geremia | 1:ff019d22b275 | 103 | void LCD::wr_data8(unsigned char data) |
Geremia | 0:75ec1b3cde17 | 104 | { |
Geremia | 1:ff019d22b275 | 105 | proto->wr_data8(data); |
Geremia | 1:ff019d22b275 | 106 | } |
Geremia | 1:ff019d22b275 | 107 | void LCD::wr_cmd16(unsigned short cmd) |
Geremia | 1:ff019d22b275 | 108 | { |
Geremia | 1:ff019d22b275 | 109 | proto->wr_cmd16(cmd); |
Geremia | 0:75ec1b3cde17 | 110 | } |
Geremia | 4:12ba0ecc2c1f | 111 | void LCD::wr_gram(unsigned short data, unsigned int count) |
Geremia | 0:75ec1b3cde17 | 112 | { |
Geremia | 4:12ba0ecc2c1f | 113 | proto->wr_gram(data, count); |
Geremia | 1:ff019d22b275 | 114 | } |
Geremia | 4:12ba0ecc2c1f | 115 | void LCD::wr_grambuf(unsigned short* data, unsigned int lenght) |
Geremia | 1:ff019d22b275 | 116 | { |
Geremia | 4:12ba0ecc2c1f | 117 | proto->wr_grambuf(data, lenght); |
Geremia | 0:75ec1b3cde17 | 118 | } |
Geremia | 0:75ec1b3cde17 | 119 | void LCD::hw_reset() |
Geremia | 0:75ec1b3cde17 | 120 | { |
Geremia | 0:75ec1b3cde17 | 121 | proto->hw_reset(); |
Geremia | 0:75ec1b3cde17 | 122 | } |
Geremia | 0:75ec1b3cde17 | 123 | void LCD::BusEnable(bool enable) |
Geremia | 0:75ec1b3cde17 | 124 | { |
Geremia | 0:75ec1b3cde17 | 125 | proto->BusEnable(enable); |
Geremia | 0:75ec1b3cde17 | 126 | } |
Geremia | 0:75ec1b3cde17 | 127 | |
Geremia | 0:75ec1b3cde17 | 128 | |
Geremia | 0:75ec1b3cde17 | 129 | |
Geremia | 0:75ec1b3cde17 | 130 | // monochrome LCD driver ICs does not have ram rotate in hw (swap raw<->columns) like TFT displays |
Geremia | 0:75ec1b3cde17 | 131 | // for portrait views, XY swap will be done in sw in pixel() function |
Geremia | 0:75ec1b3cde17 | 132 | void LCD::set_orientation(int o) |
Geremia | 0:75ec1b3cde17 | 133 | { |
Geremia | 0:75ec1b3cde17 | 134 | orientation = o; |
Geremia | 0:75ec1b3cde17 | 135 | switch (o) { |
Geremia | 0:75ec1b3cde17 | 136 | case (0):// portrait view -90° |
Geremia | 0:75ec1b3cde17 | 137 | mirrorXY(Y); |
Geremia | 0:75ec1b3cde17 | 138 | col_offset = 0; |
Geremia | 7:bb0383b91104 | 139 | page_offset = _IC_PAGES-_LCDPAGES; |
Geremia | 7:bb0383b91104 | 140 | set_width(screensize_Y); |
Geremia | 7:bb0383b91104 | 141 | set_height(screensize_X); |
Geremia | 0:75ec1b3cde17 | 142 | // portrait = true; |
Geremia | 0:75ec1b3cde17 | 143 | break; |
Geremia | 0:75ec1b3cde17 | 144 | case (1): // default, landscape view 0° |
Geremia | 0:75ec1b3cde17 | 145 | mirrorXY(NONE); |
Geremia | 0:75ec1b3cde17 | 146 | col_offset = 0; |
Geremia | 0:75ec1b3cde17 | 147 | page_offset = 0; |
Geremia | 7:bb0383b91104 | 148 | set_width(screensize_X); |
Geremia | 7:bb0383b91104 | 149 | set_height(screensize_Y); |
Geremia | 0:75ec1b3cde17 | 150 | // portrait = false; |
Geremia | 0:75ec1b3cde17 | 151 | break; |
Geremia | 0:75ec1b3cde17 | 152 | case (2):// portrait view +90° |
Geremia | 0:75ec1b3cde17 | 153 | mirrorXY(X); |
Geremia | 7:bb0383b91104 | 154 | col_offset = _IC_X_SEGS-screensize_X; // some displays have less pixels than IC ram |
Geremia | 0:75ec1b3cde17 | 155 | page_offset = 0; |
Geremia | 7:bb0383b91104 | 156 | set_width(screensize_Y); |
Geremia | 7:bb0383b91104 | 157 | set_height(screensize_X); |
Geremia | 0:75ec1b3cde17 | 158 | // portrait = true; |
Geremia | 0:75ec1b3cde17 | 159 | break; |
Geremia | 0:75ec1b3cde17 | 160 | case (3):// landscape view +180° |
Geremia | 0:75ec1b3cde17 | 161 | mirrorXY(XY); |
Geremia | 7:bb0383b91104 | 162 | col_offset = _IC_X_SEGS-screensize_X; |
Geremia | 7:bb0383b91104 | 163 | page_offset = _IC_PAGES-_LCDPAGES; |
Geremia | 7:bb0383b91104 | 164 | set_width(screensize_X); |
Geremia | 7:bb0383b91104 | 165 | set_height(screensize_Y); |
Geremia | 0:75ec1b3cde17 | 166 | // portrait = false; |
Geremia | 0:75ec1b3cde17 | 167 | break; |
Geremia | 0:75ec1b3cde17 | 168 | } |
Geremia | 0:75ec1b3cde17 | 169 | } |
Geremia | 0:75ec1b3cde17 | 170 | void LCD::mirrorXY(mirror_t mode) |
Geremia | 0:75ec1b3cde17 | 171 | { |
Geremia | 0:75ec1b3cde17 | 172 | switch (mode) |
Geremia | 0:75ec1b3cde17 | 173 | { |
Geremia | 0:75ec1b3cde17 | 174 | case(NONE): |
Geremia | 1:ff019d22b275 | 175 | // wr_cmd8(0xA0); |
Geremia | 1:ff019d22b275 | 176 | wr_cmd16(0xA0C8); // this is in real Y mirror command, but seems most displays have COMs wired inverted, so assume this is the default no-y-mirror |
Geremia | 0:75ec1b3cde17 | 177 | break; |
Geremia | 0:75ec1b3cde17 | 178 | case(X): |
Geremia | 1:ff019d22b275 | 179 | // wr_cmd8(0xA1); |
Geremia | 1:ff019d22b275 | 180 | wr_cmd16(0xA1C8); |
Geremia | 0:75ec1b3cde17 | 181 | break; |
Geremia | 0:75ec1b3cde17 | 182 | case(Y): |
Geremia | 1:ff019d22b275 | 183 | // wr_cmd8(0xA0); |
Geremia | 1:ff019d22b275 | 184 | wr_cmd16(0xA0C0); |
Geremia | 0:75ec1b3cde17 | 185 | break; |
Geremia | 0:75ec1b3cde17 | 186 | case(XY): |
Geremia | 1:ff019d22b275 | 187 | // wr_cmd8(0xA1); |
Geremia | 1:ff019d22b275 | 188 | wr_cmd16(0xA1C0); |
Geremia | 0:75ec1b3cde17 | 189 | break; |
Geremia | 0:75ec1b3cde17 | 190 | } |
Geremia | 0:75ec1b3cde17 | 191 | } |
Geremia | 0:75ec1b3cde17 | 192 | void LCD::invert(unsigned char o) |
Geremia | 0:75ec1b3cde17 | 193 | { |
Geremia | 1:ff019d22b275 | 194 | if(o == 0) wr_cmd8(0xA6); |
Geremia | 1:ff019d22b275 | 195 | else wr_cmd8(0xA7); |
Geremia | 0:75ec1b3cde17 | 196 | } |
Geremia | 0:75ec1b3cde17 | 197 | |
Geremia | 0:75ec1b3cde17 | 198 | void LCD::set_contrast(int o) |
Geremia | 0:75ec1b3cde17 | 199 | { |
Geremia | 0:75ec1b3cde17 | 200 | contrast = o; |
Geremia | 1:ff019d22b275 | 201 | // wr_cmd8(0x81); // set volume |
Geremia | 1:ff019d22b275 | 202 | wr_cmd16(0x8100|(o&0x3F)); |
Geremia | 0:75ec1b3cde17 | 203 | } |
Geremia | 2:713844a55c4e | 204 | |
Geremia | 0:75ec1b3cde17 | 205 | int LCD::get_contrast(void) |
Geremia | 0:75ec1b3cde17 | 206 | { |
Geremia | 0:75ec1b3cde17 | 207 | return(contrast); |
Geremia | 0:75ec1b3cde17 | 208 | } |
Geremia | 0:75ec1b3cde17 | 209 | void LCD::window(int x, int y, int w, int h) { |
Geremia | 0:75ec1b3cde17 | 210 | // current pixel location |
Geremia | 0:75ec1b3cde17 | 211 | cur_x = x; |
Geremia | 0:75ec1b3cde17 | 212 | cur_y = y; |
Geremia | 0:75ec1b3cde17 | 213 | // window settings |
Geremia | 0:75ec1b3cde17 | 214 | win_x1 = x; |
Geremia | 0:75ec1b3cde17 | 215 | win_x2 = x + w - 1; |
Geremia | 0:75ec1b3cde17 | 216 | win_y1 = y; |
Geremia | 0:75ec1b3cde17 | 217 | win_y2 = y + h - 1; |
Geremia | 0:75ec1b3cde17 | 218 | } |
Geremia | 0:75ec1b3cde17 | 219 | void LCD::window_pushpixel(unsigned short color) { |
Geremia | 0:75ec1b3cde17 | 220 | pixel(cur_x, cur_y, color); |
Geremia | 0:75ec1b3cde17 | 221 | cur_x++; |
Geremia | 0:75ec1b3cde17 | 222 | if(cur_x > win_x2) { |
Geremia | 0:75ec1b3cde17 | 223 | cur_x = win_x1; |
Geremia | 0:75ec1b3cde17 | 224 | cur_y++; |
Geremia | 0:75ec1b3cde17 | 225 | if(cur_y > win_y2) { |
Geremia | 0:75ec1b3cde17 | 226 | cur_y = win_y1; |
Geremia | 0:75ec1b3cde17 | 227 | } |
Geremia | 0:75ec1b3cde17 | 228 | } |
Geremia | 0:75ec1b3cde17 | 229 | } |
Geremia | 2:713844a55c4e | 230 | void LCD::window_pushpixel(unsigned short color, unsigned int count) { |
Geremia | 2:713844a55c4e | 231 | while(count) |
Geremia | 2:713844a55c4e | 232 | { |
Geremia | 2:713844a55c4e | 233 | pixel(cur_x, cur_y, color); |
Geremia | 2:713844a55c4e | 234 | cur_x++; |
Geremia | 2:713844a55c4e | 235 | if(cur_x > win_x2) |
Geremia | 2:713844a55c4e | 236 | { |
Geremia | 2:713844a55c4e | 237 | cur_x = win_x1; |
Geremia | 2:713844a55c4e | 238 | cur_y++; |
Geremia | 2:713844a55c4e | 239 | if(cur_y > win_y2) |
Geremia | 2:713844a55c4e | 240 | { |
Geremia | 2:713844a55c4e | 241 | cur_y = win_y1; |
Geremia | 2:713844a55c4e | 242 | } |
Geremia | 2:713844a55c4e | 243 | } |
Geremia | 2:713844a55c4e | 244 | count--; |
Geremia | 2:713844a55c4e | 245 | } |
Geremia | 2:713844a55c4e | 246 | } |
Geremia | 2:713844a55c4e | 247 | void LCD::window_pushpixelbuf(unsigned short* color, unsigned int lenght) { |
Geremia | 2:713844a55c4e | 248 | while(lenght) |
Geremia | 2:713844a55c4e | 249 | { |
Geremia | 2:713844a55c4e | 250 | pixel(cur_x, cur_y, *color++); |
Geremia | 2:713844a55c4e | 251 | cur_x++; |
Geremia | 2:713844a55c4e | 252 | if(cur_x > win_x2) |
Geremia | 2:713844a55c4e | 253 | { |
Geremia | 2:713844a55c4e | 254 | cur_x = win_x1; |
Geremia | 2:713844a55c4e | 255 | cur_y++; |
Geremia | 2:713844a55c4e | 256 | if(cur_y > win_y2) |
Geremia | 2:713844a55c4e | 257 | { |
Geremia | 2:713844a55c4e | 258 | cur_y = win_y1; |
Geremia | 2:713844a55c4e | 259 | } |
Geremia | 2:713844a55c4e | 260 | } |
Geremia | 2:713844a55c4e | 261 | lenght--; |
Geremia | 2:713844a55c4e | 262 | } |
Geremia | 2:713844a55c4e | 263 | } |
Geremia | 0:75ec1b3cde17 | 264 | void LCD::pixel(int x, int y, unsigned short color) |
Geremia | 0:75ec1b3cde17 | 265 | { |
Geremia | 0:75ec1b3cde17 | 266 | if(!(orientation&1)) SWAP(x,y); |
Geremia | 0:75ec1b3cde17 | 267 | // first check parameter |
Geremia | 7:bb0383b91104 | 268 | if((x >= screensize_X) || (y >= screensize_Y)) return; |
Geremia | 0:75ec1b3cde17 | 269 | |
Geremia | 20:14daa48ffd4c | 270 | if(color) buffer[(x + ((y>>3)*screensize_X))^1] &= ~(1 << (y&7)); // erase pixel |
Geremia | 20:14daa48ffd4c | 271 | else buffer[(x + ((y>>3)*screensize_X))^1] |= (1 << (y&7)); //Black=0000, set pixel |
Geremia | 20:14daa48ffd4c | 272 | } |
Geremia | 20:14daa48ffd4c | 273 | unsigned short LCD::pixelread(int x, int y) |
Geremia | 20:14daa48ffd4c | 274 | { |
Geremia | 20:14daa48ffd4c | 275 | if(!(orientation&1)) SWAP(x,y); |
Geremia | 20:14daa48ffd4c | 276 | // first check parameter |
Geremia | 20:14daa48ffd4c | 277 | if((x >= screensize_X) || (y >= screensize_Y)) return 0; |
Geremia | 20:14daa48ffd4c | 278 | |
Geremia | 20:14daa48ffd4c | 279 | if((buffer[(x + ((y>>3)*screensize_X))^1] & (1 << (y&7)))==0) return 0xFFFF ; // pixel not set, White |
Geremia | 20:14daa48ffd4c | 280 | else return 0; // pixel set, Black |
Geremia | 0:75ec1b3cde17 | 281 | } |
Geremia | 0:75ec1b3cde17 | 282 | void LCD::copy_to_lcd(void) |
Geremia | 0:75ec1b3cde17 | 283 | { |
Geremia | 0:75ec1b3cde17 | 284 | unsigned short i=0; |
Geremia | 1:ff019d22b275 | 285 | unsigned short setcolcmd = 0x0010 | ((col_offset&0xF)<<8) | (col_offset>>4); |
Geremia | 7:bb0383b91104 | 286 | for(int page=0; page<_LCDPAGES; page++) |
Geremia | 0:75ec1b3cde17 | 287 | { |
Geremia | 1:ff019d22b275 | 288 | // wr_cmd8(col_offset&0xF); // set column low nibble |
Geremia | 1:ff019d22b275 | 289 | // wr_cmd8(0x10|(col_offset>>4)); // set column hi nibble |
Geremia | 1:ff019d22b275 | 290 | wr_cmd16(setcolcmd); |
Geremia | 1:ff019d22b275 | 291 | wr_cmd8(0xB0|(page+page_offset)); // set page |
Geremia | 7:bb0383b91104 | 292 | wr_grambuf(buffer16+i, screensize_X>>1); // send whole page pixels |
Geremia | 7:bb0383b91104 | 293 | i+=screensize_X>>1; |
Geremia | 0:75ec1b3cde17 | 294 | } |
Geremia | 0:75ec1b3cde17 | 295 | } |
Geremia | 0:75ec1b3cde17 | 296 | void LCD::cls(void) |
Geremia | 0:75ec1b3cde17 | 297 | { |
Geremia | 4:12ba0ecc2c1f | 298 | unsigned short tmp = _background^0xFFFF; |
Geremia | 7:bb0383b91104 | 299 | memset(buffer,tmp,screensize_X*_LCDPAGES); // clear display buffer |
Geremia | 1:ff019d22b275 | 300 | unsigned short setcolcmd = 0x0010 | ((col_offset&0xF)<<8) | (col_offset>>4); |
Geremia | 7:bb0383b91104 | 301 | for(int page=0; page<_LCDPAGES; page++) |
Geremia | 0:75ec1b3cde17 | 302 | { |
Geremia | 1:ff019d22b275 | 303 | // wr_cmd8((unsigned char)col_offset&0xF); // set column low nibble |
Geremia | 1:ff019d22b275 | 304 | // wr_cmd8(0x10|(col_offset>>4)); // set column hi nibble |
Geremia | 1:ff019d22b275 | 305 | wr_cmd16(setcolcmd); |
Geremia | 1:ff019d22b275 | 306 | wr_cmd8(0xB0|(page+page_offset)); // set page |
Geremia | 18:ffa58f1a680a | 307 | wr_gram(tmp, screensize_X>>1); // send whole page pixels = background |
Geremia | 0:75ec1b3cde17 | 308 | } |
Geremia | 7:bb0383b91104 | 309 | } |
Geremia | 7:bb0383b91104 | 310 | int LCD::sizeX() |
Geremia | 7:bb0383b91104 | 311 | { |
Geremia | 7:bb0383b91104 | 312 | return screensize_X; |
Geremia | 7:bb0383b91104 | 313 | } |
Geremia | 7:bb0383b91104 | 314 | int LCD::sizeY() |
Geremia | 7:bb0383b91104 | 315 | { |
Geremia | 7:bb0383b91104 | 316 | return screensize_Y; |
Geremia | 0:75ec1b3cde17 | 317 | } |