Basically i glued Peter Drescher and Simon Ford libs in a GraphicsDisplay class, then derived TFT or LCD class (which inherits Protocols class), then the most derived ones (Inits), which are per-display and are the only part needed to be adapted to diff hw.
Display/LCD.cpp@21:ae0a4eedfc90, 2015-03-31 (annotated)
- Committer:
- Geremia
- Date:
- Tue Mar 31 21:14:48 2015 +0000
- Revision:
- 21:ae0a4eedfc90
- Parent:
- 20:14daa48ffd4c
- Child:
- 25:daacdcf34e52
Add BUS_8 and BUS_16 (slow as expected)
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 | { |
Geremia | 0:75ec1b3cde17 | 31 | if(displayproto==PAR_8) proto = new PAR8(port, CS, reset, DC, WR, RD); |
Geremia | 1:ff019d22b275 | 32 | useNOP=false; |
Geremia | 7:bb0383b91104 | 33 | buffer = (unsigned char*) malloc (screensize_X*_LCDPAGES); |
Geremia | 1:ff019d22b275 | 34 | buffer16 = (unsigned short*)buffer; |
Geremia | 0:75ec1b3cde17 | 35 | draw_mode = NORMAL; |
Geremia | 0:75ec1b3cde17 | 36 | set_orientation(1); |
Geremia | 4:12ba0ecc2c1f | 37 | foreground(White); |
Geremia | 4:12ba0ecc2c1f | 38 | background(Black); |
Geremia | 2:713844a55c4e | 39 | set_auto_up(true); |
Geremia | 7:bb0383b91104 | 40 | tftID=0; |
Geremia | 0:75ec1b3cde17 | 41 | // cls(); |
Geremia | 0:75ec1b3cde17 | 42 | // locate(0,0); |
Geremia | 0:75ec1b3cde17 | 43 | } |
Geremia | 21:ae0a4eedfc90 | 44 | 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 | 45 | : 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 | 46 | { |
Geremia | 21:ae0a4eedfc90 | 47 | if(displayproto==BUS_8) |
Geremia | 21:ae0a4eedfc90 | 48 | { |
Geremia | 21:ae0a4eedfc90 | 49 | PinName pins[16]; |
Geremia | 21:ae0a4eedfc90 | 50 | for(int i=0; i<16; i++) pins[i]=NC; |
Geremia | 21:ae0a4eedfc90 | 51 | for(int i=0; i<8; i++) pins[i]=buspins[i]; |
Geremia | 21:ae0a4eedfc90 | 52 | proto = new BUS8(pins, CS, reset, DC, WR, RD); |
Geremia | 21:ae0a4eedfc90 | 53 | } |
Geremia | 21:ae0a4eedfc90 | 54 | useNOP=false; |
Geremia | 21:ae0a4eedfc90 | 55 | buffer = (unsigned char*) malloc (screensize_X*_LCDPAGES); |
Geremia | 21:ae0a4eedfc90 | 56 | buffer16 = (unsigned short*)buffer; |
Geremia | 21:ae0a4eedfc90 | 57 | draw_mode = NORMAL; |
Geremia | 21:ae0a4eedfc90 | 58 | set_orientation(1); |
Geremia | 21:ae0a4eedfc90 | 59 | foreground(White); |
Geremia | 21:ae0a4eedfc90 | 60 | background(Black); |
Geremia | 21:ae0a4eedfc90 | 61 | set_auto_up(true); |
Geremia | 21:ae0a4eedfc90 | 62 | tftID=0; |
Geremia | 21:ae0a4eedfc90 | 63 | // cls(); |
Geremia | 21:ae0a4eedfc90 | 64 | // locate(0,0); |
Geremia | 21:ae0a4eedfc90 | 65 | } |
Geremia | 1:ff019d22b275 | 66 | 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 | 67 | : 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 | 68 | { |
Geremia | 1:ff019d22b275 | 69 | if(displayproto==SPI_8) |
Geremia | 1:ff019d22b275 | 70 | { |
Geremia | 1:ff019d22b275 | 71 | proto = new SPI8(Hz, mosi, miso, sclk, CS, reset, DC); |
Geremia | 1:ff019d22b275 | 72 | useNOP=false; |
Geremia | 1:ff019d22b275 | 73 | } |
Geremia | 1:ff019d22b275 | 74 | else if(displayproto==SPI_16) |
Geremia | 1:ff019d22b275 | 75 | { |
Geremia | 1:ff019d22b275 | 76 | proto = new SPI16(Hz, mosi, miso, sclk, CS, reset, DC); |
Geremia | 1:ff019d22b275 | 77 | useNOP=true; |
Geremia | 1:ff019d22b275 | 78 | } |
Geremia | 7:bb0383b91104 | 79 | buffer = (unsigned char*) malloc (screensize_X*_LCDPAGES); |
Geremia | 1:ff019d22b275 | 80 | buffer16 = (unsigned short*)buffer; |
Geremia | 0:75ec1b3cde17 | 81 | draw_mode = NORMAL; |
Geremia | 0:75ec1b3cde17 | 82 | // cls(); |
Geremia | 0:75ec1b3cde17 | 83 | set_orientation(1); |
Geremia | 4:12ba0ecc2c1f | 84 | foreground(White); |
Geremia | 4:12ba0ecc2c1f | 85 | background(Black); |
Geremia | 2:713844a55c4e | 86 | set_auto_up(true); |
Geremia | 7:bb0383b91104 | 87 | tftID=0; |
Geremia | 0:75ec1b3cde17 | 88 | // locate(0,0); |
Geremia | 1:ff019d22b275 | 89 | |
Geremia | 0:75ec1b3cde17 | 90 | } |
Geremia | 0:75ec1b3cde17 | 91 | LCD::~LCD() |
Geremia | 0:75ec1b3cde17 | 92 | { |
Geremia | 0:75ec1b3cde17 | 93 | free(buffer); |
Geremia | 0:75ec1b3cde17 | 94 | } |
Geremia | 0:75ec1b3cde17 | 95 | |
Geremia | 1:ff019d22b275 | 96 | void LCD::wr_cmd8(unsigned char cmd) |
Geremia | 0:75ec1b3cde17 | 97 | { |
Geremia | 2:713844a55c4e | 98 | if(useNOP) proto->wr_cmd16(0xE300|cmd); // E3 is NOP cmd for LCD |
Geremia | 1:ff019d22b275 | 99 | else proto->wr_cmd8(cmd); |
Geremia | 0:75ec1b3cde17 | 100 | } |
Geremia | 1:ff019d22b275 | 101 | void LCD::wr_data8(unsigned char data) |
Geremia | 0:75ec1b3cde17 | 102 | { |
Geremia | 1:ff019d22b275 | 103 | proto->wr_data8(data); |
Geremia | 1:ff019d22b275 | 104 | } |
Geremia | 1:ff019d22b275 | 105 | void LCD::wr_cmd16(unsigned short cmd) |
Geremia | 1:ff019d22b275 | 106 | { |
Geremia | 1:ff019d22b275 | 107 | proto->wr_cmd16(cmd); |
Geremia | 0:75ec1b3cde17 | 108 | } |
Geremia | 4:12ba0ecc2c1f | 109 | void LCD::wr_gram(unsigned short data, unsigned int count) |
Geremia | 0:75ec1b3cde17 | 110 | { |
Geremia | 4:12ba0ecc2c1f | 111 | proto->wr_gram(data, count); |
Geremia | 1:ff019d22b275 | 112 | } |
Geremia | 4:12ba0ecc2c1f | 113 | void LCD::wr_grambuf(unsigned short* data, unsigned int lenght) |
Geremia | 1:ff019d22b275 | 114 | { |
Geremia | 4:12ba0ecc2c1f | 115 | proto->wr_grambuf(data, lenght); |
Geremia | 0:75ec1b3cde17 | 116 | } |
Geremia | 0:75ec1b3cde17 | 117 | void LCD::hw_reset() |
Geremia | 0:75ec1b3cde17 | 118 | { |
Geremia | 0:75ec1b3cde17 | 119 | proto->hw_reset(); |
Geremia | 0:75ec1b3cde17 | 120 | } |
Geremia | 0:75ec1b3cde17 | 121 | void LCD::BusEnable(bool enable) |
Geremia | 0:75ec1b3cde17 | 122 | { |
Geremia | 0:75ec1b3cde17 | 123 | proto->BusEnable(enable); |
Geremia | 0:75ec1b3cde17 | 124 | } |
Geremia | 0:75ec1b3cde17 | 125 | |
Geremia | 0:75ec1b3cde17 | 126 | |
Geremia | 0:75ec1b3cde17 | 127 | |
Geremia | 0:75ec1b3cde17 | 128 | // monochrome LCD driver ICs does not have ram rotate in hw (swap raw<->columns) like TFT displays |
Geremia | 0:75ec1b3cde17 | 129 | // for portrait views, XY swap will be done in sw in pixel() function |
Geremia | 0:75ec1b3cde17 | 130 | void LCD::set_orientation(int o) |
Geremia | 0:75ec1b3cde17 | 131 | { |
Geremia | 0:75ec1b3cde17 | 132 | orientation = o; |
Geremia | 0:75ec1b3cde17 | 133 | switch (o) { |
Geremia | 0:75ec1b3cde17 | 134 | case (0):// portrait view -90° |
Geremia | 0:75ec1b3cde17 | 135 | mirrorXY(Y); |
Geremia | 0:75ec1b3cde17 | 136 | col_offset = 0; |
Geremia | 7:bb0383b91104 | 137 | page_offset = _IC_PAGES-_LCDPAGES; |
Geremia | 7:bb0383b91104 | 138 | set_width(screensize_Y); |
Geremia | 7:bb0383b91104 | 139 | set_height(screensize_X); |
Geremia | 0:75ec1b3cde17 | 140 | // portrait = true; |
Geremia | 0:75ec1b3cde17 | 141 | break; |
Geremia | 0:75ec1b3cde17 | 142 | case (1): // default, landscape view 0° |
Geremia | 0:75ec1b3cde17 | 143 | mirrorXY(NONE); |
Geremia | 0:75ec1b3cde17 | 144 | col_offset = 0; |
Geremia | 0:75ec1b3cde17 | 145 | page_offset = 0; |
Geremia | 7:bb0383b91104 | 146 | set_width(screensize_X); |
Geremia | 7:bb0383b91104 | 147 | set_height(screensize_Y); |
Geremia | 0:75ec1b3cde17 | 148 | // portrait = false; |
Geremia | 0:75ec1b3cde17 | 149 | break; |
Geremia | 0:75ec1b3cde17 | 150 | case (2):// portrait view +90° |
Geremia | 0:75ec1b3cde17 | 151 | mirrorXY(X); |
Geremia | 7:bb0383b91104 | 152 | col_offset = _IC_X_SEGS-screensize_X; // some displays have less pixels than IC ram |
Geremia | 0:75ec1b3cde17 | 153 | page_offset = 0; |
Geremia | 7:bb0383b91104 | 154 | set_width(screensize_Y); |
Geremia | 7:bb0383b91104 | 155 | set_height(screensize_X); |
Geremia | 0:75ec1b3cde17 | 156 | // portrait = true; |
Geremia | 0:75ec1b3cde17 | 157 | break; |
Geremia | 0:75ec1b3cde17 | 158 | case (3):// landscape view +180° |
Geremia | 0:75ec1b3cde17 | 159 | mirrorXY(XY); |
Geremia | 7:bb0383b91104 | 160 | col_offset = _IC_X_SEGS-screensize_X; |
Geremia | 7:bb0383b91104 | 161 | page_offset = _IC_PAGES-_LCDPAGES; |
Geremia | 7:bb0383b91104 | 162 | set_width(screensize_X); |
Geremia | 7:bb0383b91104 | 163 | set_height(screensize_Y); |
Geremia | 0:75ec1b3cde17 | 164 | // portrait = false; |
Geremia | 0:75ec1b3cde17 | 165 | break; |
Geremia | 0:75ec1b3cde17 | 166 | } |
Geremia | 0:75ec1b3cde17 | 167 | } |
Geremia | 0:75ec1b3cde17 | 168 | void LCD::mirrorXY(mirror_t mode) |
Geremia | 0:75ec1b3cde17 | 169 | { |
Geremia | 0:75ec1b3cde17 | 170 | switch (mode) |
Geremia | 0:75ec1b3cde17 | 171 | { |
Geremia | 0:75ec1b3cde17 | 172 | case(NONE): |
Geremia | 1:ff019d22b275 | 173 | // wr_cmd8(0xA0); |
Geremia | 1:ff019d22b275 | 174 | 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 | 175 | break; |
Geremia | 0:75ec1b3cde17 | 176 | case(X): |
Geremia | 1:ff019d22b275 | 177 | // wr_cmd8(0xA1); |
Geremia | 1:ff019d22b275 | 178 | wr_cmd16(0xA1C8); |
Geremia | 0:75ec1b3cde17 | 179 | break; |
Geremia | 0:75ec1b3cde17 | 180 | case(Y): |
Geremia | 1:ff019d22b275 | 181 | // wr_cmd8(0xA0); |
Geremia | 1:ff019d22b275 | 182 | wr_cmd16(0xA0C0); |
Geremia | 0:75ec1b3cde17 | 183 | break; |
Geremia | 0:75ec1b3cde17 | 184 | case(XY): |
Geremia | 1:ff019d22b275 | 185 | // wr_cmd8(0xA1); |
Geremia | 1:ff019d22b275 | 186 | wr_cmd16(0xA1C0); |
Geremia | 0:75ec1b3cde17 | 187 | break; |
Geremia | 0:75ec1b3cde17 | 188 | } |
Geremia | 0:75ec1b3cde17 | 189 | } |
Geremia | 0:75ec1b3cde17 | 190 | void LCD::invert(unsigned char o) |
Geremia | 0:75ec1b3cde17 | 191 | { |
Geremia | 1:ff019d22b275 | 192 | if(o == 0) wr_cmd8(0xA6); |
Geremia | 1:ff019d22b275 | 193 | else wr_cmd8(0xA7); |
Geremia | 0:75ec1b3cde17 | 194 | } |
Geremia | 0:75ec1b3cde17 | 195 | |
Geremia | 0:75ec1b3cde17 | 196 | void LCD::set_contrast(int o) |
Geremia | 0:75ec1b3cde17 | 197 | { |
Geremia | 0:75ec1b3cde17 | 198 | contrast = o; |
Geremia | 1:ff019d22b275 | 199 | // wr_cmd8(0x81); // set volume |
Geremia | 1:ff019d22b275 | 200 | wr_cmd16(0x8100|(o&0x3F)); |
Geremia | 0:75ec1b3cde17 | 201 | } |
Geremia | 2:713844a55c4e | 202 | |
Geremia | 0:75ec1b3cde17 | 203 | int LCD::get_contrast(void) |
Geremia | 0:75ec1b3cde17 | 204 | { |
Geremia | 0:75ec1b3cde17 | 205 | return(contrast); |
Geremia | 0:75ec1b3cde17 | 206 | } |
Geremia | 0:75ec1b3cde17 | 207 | void LCD::window(int x, int y, int w, int h) { |
Geremia | 0:75ec1b3cde17 | 208 | // current pixel location |
Geremia | 0:75ec1b3cde17 | 209 | cur_x = x; |
Geremia | 0:75ec1b3cde17 | 210 | cur_y = y; |
Geremia | 0:75ec1b3cde17 | 211 | // window settings |
Geremia | 0:75ec1b3cde17 | 212 | win_x1 = x; |
Geremia | 0:75ec1b3cde17 | 213 | win_x2 = x + w - 1; |
Geremia | 0:75ec1b3cde17 | 214 | win_y1 = y; |
Geremia | 0:75ec1b3cde17 | 215 | win_y2 = y + h - 1; |
Geremia | 0:75ec1b3cde17 | 216 | } |
Geremia | 0:75ec1b3cde17 | 217 | void LCD::window_pushpixel(unsigned short color) { |
Geremia | 0:75ec1b3cde17 | 218 | pixel(cur_x, cur_y, color); |
Geremia | 0:75ec1b3cde17 | 219 | cur_x++; |
Geremia | 0:75ec1b3cde17 | 220 | if(cur_x > win_x2) { |
Geremia | 0:75ec1b3cde17 | 221 | cur_x = win_x1; |
Geremia | 0:75ec1b3cde17 | 222 | cur_y++; |
Geremia | 0:75ec1b3cde17 | 223 | if(cur_y > win_y2) { |
Geremia | 0:75ec1b3cde17 | 224 | cur_y = win_y1; |
Geremia | 0:75ec1b3cde17 | 225 | } |
Geremia | 0:75ec1b3cde17 | 226 | } |
Geremia | 0:75ec1b3cde17 | 227 | } |
Geremia | 2:713844a55c4e | 228 | void LCD::window_pushpixel(unsigned short color, unsigned int count) { |
Geremia | 2:713844a55c4e | 229 | while(count) |
Geremia | 2:713844a55c4e | 230 | { |
Geremia | 2:713844a55c4e | 231 | pixel(cur_x, cur_y, color); |
Geremia | 2:713844a55c4e | 232 | cur_x++; |
Geremia | 2:713844a55c4e | 233 | if(cur_x > win_x2) |
Geremia | 2:713844a55c4e | 234 | { |
Geremia | 2:713844a55c4e | 235 | cur_x = win_x1; |
Geremia | 2:713844a55c4e | 236 | cur_y++; |
Geremia | 2:713844a55c4e | 237 | if(cur_y > win_y2) |
Geremia | 2:713844a55c4e | 238 | { |
Geremia | 2:713844a55c4e | 239 | cur_y = win_y1; |
Geremia | 2:713844a55c4e | 240 | } |
Geremia | 2:713844a55c4e | 241 | } |
Geremia | 2:713844a55c4e | 242 | count--; |
Geremia | 2:713844a55c4e | 243 | } |
Geremia | 2:713844a55c4e | 244 | } |
Geremia | 2:713844a55c4e | 245 | void LCD::window_pushpixelbuf(unsigned short* color, unsigned int lenght) { |
Geremia | 2:713844a55c4e | 246 | while(lenght) |
Geremia | 2:713844a55c4e | 247 | { |
Geremia | 2:713844a55c4e | 248 | pixel(cur_x, cur_y, *color++); |
Geremia | 2:713844a55c4e | 249 | cur_x++; |
Geremia | 2:713844a55c4e | 250 | if(cur_x > win_x2) |
Geremia | 2:713844a55c4e | 251 | { |
Geremia | 2:713844a55c4e | 252 | cur_x = win_x1; |
Geremia | 2:713844a55c4e | 253 | cur_y++; |
Geremia | 2:713844a55c4e | 254 | if(cur_y > win_y2) |
Geremia | 2:713844a55c4e | 255 | { |
Geremia | 2:713844a55c4e | 256 | cur_y = win_y1; |
Geremia | 2:713844a55c4e | 257 | } |
Geremia | 2:713844a55c4e | 258 | } |
Geremia | 2:713844a55c4e | 259 | lenght--; |
Geremia | 2:713844a55c4e | 260 | } |
Geremia | 2:713844a55c4e | 261 | } |
Geremia | 0:75ec1b3cde17 | 262 | void LCD::pixel(int x, int y, unsigned short color) |
Geremia | 0:75ec1b3cde17 | 263 | { |
Geremia | 0:75ec1b3cde17 | 264 | if(!(orientation&1)) SWAP(x,y); |
Geremia | 0:75ec1b3cde17 | 265 | // first check parameter |
Geremia | 7:bb0383b91104 | 266 | if((x >= screensize_X) || (y >= screensize_Y)) return; |
Geremia | 0:75ec1b3cde17 | 267 | |
Geremia | 20:14daa48ffd4c | 268 | if(color) buffer[(x + ((y>>3)*screensize_X))^1] &= ~(1 << (y&7)); // erase pixel |
Geremia | 20:14daa48ffd4c | 269 | else buffer[(x + ((y>>3)*screensize_X))^1] |= (1 << (y&7)); //Black=0000, set pixel |
Geremia | 20:14daa48ffd4c | 270 | } |
Geremia | 20:14daa48ffd4c | 271 | unsigned short LCD::pixelread(int x, int y) |
Geremia | 20:14daa48ffd4c | 272 | { |
Geremia | 20:14daa48ffd4c | 273 | if(!(orientation&1)) SWAP(x,y); |
Geremia | 20:14daa48ffd4c | 274 | // first check parameter |
Geremia | 20:14daa48ffd4c | 275 | if((x >= screensize_X) || (y >= screensize_Y)) return 0; |
Geremia | 20:14daa48ffd4c | 276 | |
Geremia | 20:14daa48ffd4c | 277 | if((buffer[(x + ((y>>3)*screensize_X))^1] & (1 << (y&7)))==0) return 0xFFFF ; // pixel not set, White |
Geremia | 20:14daa48ffd4c | 278 | else return 0; // pixel set, Black |
Geremia | 0:75ec1b3cde17 | 279 | } |
Geremia | 0:75ec1b3cde17 | 280 | void LCD::copy_to_lcd(void) |
Geremia | 0:75ec1b3cde17 | 281 | { |
Geremia | 0:75ec1b3cde17 | 282 | unsigned short i=0; |
Geremia | 1:ff019d22b275 | 283 | unsigned short setcolcmd = 0x0010 | ((col_offset&0xF)<<8) | (col_offset>>4); |
Geremia | 7:bb0383b91104 | 284 | for(int page=0; page<_LCDPAGES; page++) |
Geremia | 0:75ec1b3cde17 | 285 | { |
Geremia | 1:ff019d22b275 | 286 | // wr_cmd8(col_offset&0xF); // set column low nibble |
Geremia | 1:ff019d22b275 | 287 | // wr_cmd8(0x10|(col_offset>>4)); // set column hi nibble |
Geremia | 1:ff019d22b275 | 288 | wr_cmd16(setcolcmd); |
Geremia | 1:ff019d22b275 | 289 | wr_cmd8(0xB0|(page+page_offset)); // set page |
Geremia | 7:bb0383b91104 | 290 | wr_grambuf(buffer16+i, screensize_X>>1); // send whole page pixels |
Geremia | 7:bb0383b91104 | 291 | i+=screensize_X>>1; |
Geremia | 0:75ec1b3cde17 | 292 | } |
Geremia | 0:75ec1b3cde17 | 293 | } |
Geremia | 0:75ec1b3cde17 | 294 | void LCD::cls(void) |
Geremia | 0:75ec1b3cde17 | 295 | { |
Geremia | 4:12ba0ecc2c1f | 296 | unsigned short tmp = _background^0xFFFF; |
Geremia | 7:bb0383b91104 | 297 | memset(buffer,tmp,screensize_X*_LCDPAGES); // clear display buffer |
Geremia | 1:ff019d22b275 | 298 | unsigned short setcolcmd = 0x0010 | ((col_offset&0xF)<<8) | (col_offset>>4); |
Geremia | 7:bb0383b91104 | 299 | for(int page=0; page<_LCDPAGES; page++) |
Geremia | 0:75ec1b3cde17 | 300 | { |
Geremia | 1:ff019d22b275 | 301 | // wr_cmd8((unsigned char)col_offset&0xF); // set column low nibble |
Geremia | 1:ff019d22b275 | 302 | // wr_cmd8(0x10|(col_offset>>4)); // set column hi nibble |
Geremia | 1:ff019d22b275 | 303 | wr_cmd16(setcolcmd); |
Geremia | 1:ff019d22b275 | 304 | wr_cmd8(0xB0|(page+page_offset)); // set page |
Geremia | 18:ffa58f1a680a | 305 | wr_gram(tmp, screensize_X>>1); // send whole page pixels = background |
Geremia | 0:75ec1b3cde17 | 306 | } |
Geremia | 7:bb0383b91104 | 307 | } |
Geremia | 7:bb0383b91104 | 308 | int LCD::sizeX() |
Geremia | 7:bb0383b91104 | 309 | { |
Geremia | 7:bb0383b91104 | 310 | return screensize_X; |
Geremia | 7:bb0383b91104 | 311 | } |
Geremia | 7:bb0383b91104 | 312 | int LCD::sizeY() |
Geremia | 7:bb0383b91104 | 313 | { |
Geremia | 7:bb0383b91104 | 314 | return screensize_Y; |
Geremia | 0:75ec1b3cde17 | 315 | } |