LCD implementation of our project.

Dependencies:   mbed mbed-rtos MLX90614

Committer:
ovidiup13
Date:
Fri Mar 20 23:22:41 2015 +0000
Revision:
0:1e597b0f8b3b
initial menu mock-up st7565

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ovidiup13 0:1e597b0f8b3b 1 /*
ovidiup13 0:1e597b0f8b3b 2 $Id:$
ovidiup13 0:1e597b0f8b3b 3
ovidiup13 0:1e597b0f8b3b 4 ST7565 LCD library!
ovidiup13 0:1e597b0f8b3b 5
ovidiup13 0:1e597b0f8b3b 6 Copyright (C) 2010 Limor Fried, Adafruit Industries
ovidiup13 0:1e597b0f8b3b 7
ovidiup13 0:1e597b0f8b3b 8 This library is free software; you can redistribute it and/or
ovidiup13 0:1e597b0f8b3b 9 modify it under the terms of the GNU Lesser General Public
ovidiup13 0:1e597b0f8b3b 10 License as published by the Free Software Foundation; either
ovidiup13 0:1e597b0f8b3b 11 version 2.1 of the License, or (at your option) any later version.
ovidiup13 0:1e597b0f8b3b 12
ovidiup13 0:1e597b0f8b3b 13 This library is distributed in the hope that it will be useful,
ovidiup13 0:1e597b0f8b3b 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
ovidiup13 0:1e597b0f8b3b 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ovidiup13 0:1e597b0f8b3b 16 Lesser General Public License for more details.
ovidiup13 0:1e597b0f8b3b 17
ovidiup13 0:1e597b0f8b3b 18 You should have received a copy of the GNU Lesser General Public
ovidiup13 0:1e597b0f8b3b 19 License along with this library; if not, write to the Free Software
ovidiup13 0:1e597b0f8b3b 20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
ovidiup13 0:1e597b0f8b3b 21
ovidiup13 0:1e597b0f8b3b 22 // some of this code was written by <cstone@pobox.com> originally; it is in the public domain.
ovidiup13 0:1e597b0f8b3b 23
ovidiup13 0:1e597b0f8b3b 24
ovidiup13 0:1e597b0f8b3b 25 ******the library is modified for mbed**********
ovidiup13 0:1e597b0f8b3b 26 http://www.adafruit.com/products/250
ovidiup13 0:1e597b0f8b3b 27
ovidiup13 0:1e597b0f8b3b 28 *!function drawbitmap(); is left undone!*
ovidiup13 0:1e597b0f8b3b 29
ovidiup13 0:1e597b0f8b3b 30 2014/03/18 by imachooon
ovidiup13 0:1e597b0f8b3b 31 mailto: imachooon@gmail.com
ovidiup13 0:1e597b0f8b3b 32 ************************************************
ovidiup13 0:1e597b0f8b3b 33 */
ovidiup13 0:1e597b0f8b3b 34
ovidiup13 0:1e597b0f8b3b 35 #include "st7565LCD.h"
ovidiup13 0:1e597b0f8b3b 36 #include "st7565LCDfont.h"
ovidiup13 0:1e597b0f8b3b 37
ovidiup13 0:1e597b0f8b3b 38 #define ST7565_STARTBYTES 1
ovidiup13 0:1e597b0f8b3b 39
ovidiup13 0:1e597b0f8b3b 40 uint8_t is_reversed = 0;
ovidiup13 0:1e597b0f8b3b 41
ovidiup13 0:1e597b0f8b3b 42 // a handy reference to where the pages are on the screen
ovidiup13 0:1e597b0f8b3b 43 const uint8_t pagemap[] = { 3, 2, 1, 0, 7, 6, 5, 4 };
ovidiup13 0:1e597b0f8b3b 44
ovidiup13 0:1e597b0f8b3b 45 // a 5x7 font table
ovidiup13 0:1e597b0f8b3b 46 extern const uint8_t font[];
ovidiup13 0:1e597b0f8b3b 47
ovidiup13 0:1e597b0f8b3b 48 // the memory buffer for the LCD
ovidiup13 0:1e597b0f8b3b 49 uint8_t st7565_buffer[1024] = {
ovidiup13 0:1e597b0f8b3b 50 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
ovidiup13 0:1e597b0f8b3b 51 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
ovidiup13 0:1e597b0f8b3b 52 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 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, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
ovidiup13 0:1e597b0f8b3b 116 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
ovidiup13 0:1e597b0f8b3b 117 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
ovidiup13 0:1e597b0f8b3b 118 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
ovidiup13 0:1e597b0f8b3b 119 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
ovidiup13 0:1e597b0f8b3b 120 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
ovidiup13 0:1e597b0f8b3b 121 };
ovidiup13 0:1e597b0f8b3b 122
ovidiup13 0:1e597b0f8b3b 123
ovidiup13 0:1e597b0f8b3b 124
ovidiup13 0:1e597b0f8b3b 125
ovidiup13 0:1e597b0f8b3b 126 // reduces how much is refreshed, which speeds it up!
ovidiup13 0:1e597b0f8b3b 127 // originally derived from Steve Evans/JCW's mod but cleaned up and
ovidiup13 0:1e597b0f8b3b 128 // optimized
ovidiup13 0:1e597b0f8b3b 129 #define enablePartialUpdate
ovidiup13 0:1e597b0f8b3b 130
ovidiup13 0:1e597b0f8b3b 131 #ifdef enablePartialUpdate
ovidiup13 0:1e597b0f8b3b 132 static uint8_t xUpdateMin, xUpdateMax, yUpdateMin, yUpdateMax;
ovidiup13 0:1e597b0f8b3b 133 #endif
ovidiup13 0:1e597b0f8b3b 134
ovidiup13 0:1e597b0f8b3b 135
ovidiup13 0:1e597b0f8b3b 136
ovidiup13 0:1e597b0f8b3b 137 static void updateBoundingBox(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax)
ovidiup13 0:1e597b0f8b3b 138 {
ovidiup13 0:1e597b0f8b3b 139 #ifdef enablePartialUpdate
ovidiup13 0:1e597b0f8b3b 140 if (xmin < xUpdateMin) xUpdateMin = xmin;
ovidiup13 0:1e597b0f8b3b 141 if (xmax > xUpdateMax) xUpdateMax = xmax;
ovidiup13 0:1e597b0f8b3b 142 if (ymin < yUpdateMin) yUpdateMin = ymin;
ovidiup13 0:1e597b0f8b3b 143 if (ymax > yUpdateMax) yUpdateMax = ymax;
ovidiup13 0:1e597b0f8b3b 144 #endif
ovidiup13 0:1e597b0f8b3b 145 }
ovidiup13 0:1e597b0f8b3b 146
ovidiup13 0:1e597b0f8b3b 147 /*
ovidiup13 0:1e597b0f8b3b 148 void ST7565::drawbitmap(uint8_t x, uint8_t y,
ovidiup13 0:1e597b0f8b3b 149 const uint8_t *bitmap, uint8_t w, uint8_t h,
ovidiup13 0:1e597b0f8b3b 150 uint8_t color) {
ovidiup13 0:1e597b0f8b3b 151 for (uint8_t i=0; i<h; i++) {
ovidiup13 0:1e597b0f8b3b 152 for (uint8_t j=0; j<w; j++ ) {
ovidiup13 0:1e597b0f8b3b 153 if (pgm_read_byte(bitmap + j + (j/8)*w) & _BV(j%8)) {
ovidiup13 0:1e597b0f8b3b 154 my_setpixel(x+j, y+i, color);
ovidiup13 0:1e597b0f8b3b 155 }
ovidiup13 0:1e597b0f8b3b 156 }
ovidiup13 0:1e597b0f8b3b 157 }
ovidiup13 0:1e597b0f8b3b 158
ovidiup13 0:1e597b0f8b3b 159 updateBoundingBox(x, y, x+w, y+h);
ovidiup13 0:1e597b0f8b3b 160 }
ovidiup13 0:1e597b0f8b3b 161 */
ovidiup13 0:1e597b0f8b3b 162
ovidiup13 0:1e597b0f8b3b 163 void ST7565::drawstring(uint8_t x, uint8_t line, char *c)
ovidiup13 0:1e597b0f8b3b 164 {
ovidiup13 0:1e597b0f8b3b 165 while (*c != '\0') {
ovidiup13 0:1e597b0f8b3b 166 drawchar(x, line, *c);
ovidiup13 0:1e597b0f8b3b 167 *c++;
ovidiup13 0:1e597b0f8b3b 168 x += 6; // 6 pixels wide
ovidiup13 0:1e597b0f8b3b 169 if (x + 6 >= LCDWIDTH) {
ovidiup13 0:1e597b0f8b3b 170 x = 0; // ran out of this line
ovidiup13 0:1e597b0f8b3b 171 line++;
ovidiup13 0:1e597b0f8b3b 172 }
ovidiup13 0:1e597b0f8b3b 173 if (line >= (LCDHEIGHT/8))
ovidiup13 0:1e597b0f8b3b 174 return; // ran out of space :(
ovidiup13 0:1e597b0f8b3b 175 }
ovidiup13 0:1e597b0f8b3b 176 }
ovidiup13 0:1e597b0f8b3b 177
ovidiup13 0:1e597b0f8b3b 178
ovidiup13 0:1e597b0f8b3b 179 void ST7565::drawchar(uint8_t x, uint8_t line, char c)
ovidiup13 0:1e597b0f8b3b 180 {
ovidiup13 0:1e597b0f8b3b 181 for (uint8_t i =0; i<5; i++ ) {
ovidiup13 0:1e597b0f8b3b 182 *(st7565_buffer + x + line*128) = *(font + (c*5) + i);
ovidiup13 0:1e597b0f8b3b 183 x++;
ovidiup13 0:1e597b0f8b3b 184 }
ovidiup13 0:1e597b0f8b3b 185 updateBoundingBox(x, line*8, x+5, line*8+8); //only updates relevant area of LCD
ovidiup13 0:1e597b0f8b3b 186 }
ovidiup13 0:1e597b0f8b3b 187
ovidiup13 0:1e597b0f8b3b 188
ovidiup13 0:1e597b0f8b3b 189 // bresenham's algorithm - thx wikpedia
ovidiup13 0:1e597b0f8b3b 190 void ST7565::drawline(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
ovidiup13 0:1e597b0f8b3b 191 uint8_t color)
ovidiup13 0:1e597b0f8b3b 192 {
ovidiup13 0:1e597b0f8b3b 193 uint8_t steep = abs(y1 - y0) > abs(x1 - x0);
ovidiup13 0:1e597b0f8b3b 194 if (steep) {
ovidiup13 0:1e597b0f8b3b 195 swap(x0, y0);
ovidiup13 0:1e597b0f8b3b 196 swap(x1, y1);
ovidiup13 0:1e597b0f8b3b 197 }
ovidiup13 0:1e597b0f8b3b 198
ovidiup13 0:1e597b0f8b3b 199 if (x0 > x1) {
ovidiup13 0:1e597b0f8b3b 200 swap(x0, x1);
ovidiup13 0:1e597b0f8b3b 201 swap(y0, y1);
ovidiup13 0:1e597b0f8b3b 202 }
ovidiup13 0:1e597b0f8b3b 203
ovidiup13 0:1e597b0f8b3b 204 // much faster to put the test here, since we've already sorted the points
ovidiup13 0:1e597b0f8b3b 205 updateBoundingBox(x0, y0, x1, y1);
ovidiup13 0:1e597b0f8b3b 206
ovidiup13 0:1e597b0f8b3b 207 uint8_t dx, dy;
ovidiup13 0:1e597b0f8b3b 208 dx = x1 - x0;
ovidiup13 0:1e597b0f8b3b 209 dy = abs(y1 - y0);
ovidiup13 0:1e597b0f8b3b 210
ovidiup13 0:1e597b0f8b3b 211 int8_t err = dx / 2;
ovidiup13 0:1e597b0f8b3b 212 int8_t ystep;
ovidiup13 0:1e597b0f8b3b 213
ovidiup13 0:1e597b0f8b3b 214 if (y0 < y1) {
ovidiup13 0:1e597b0f8b3b 215 ystep = 1;
ovidiup13 0:1e597b0f8b3b 216 } else {
ovidiup13 0:1e597b0f8b3b 217 ystep = -1;
ovidiup13 0:1e597b0f8b3b 218 }
ovidiup13 0:1e597b0f8b3b 219
ovidiup13 0:1e597b0f8b3b 220 for (; x0<=x1; x0++) {
ovidiup13 0:1e597b0f8b3b 221 if (steep) {
ovidiup13 0:1e597b0f8b3b 222 my_setpixel(y0, x0, color);
ovidiup13 0:1e597b0f8b3b 223 } else {
ovidiup13 0:1e597b0f8b3b 224 my_setpixel(x0, y0, color);
ovidiup13 0:1e597b0f8b3b 225 }
ovidiup13 0:1e597b0f8b3b 226 err -= dy;
ovidiup13 0:1e597b0f8b3b 227 if (err < 0) {
ovidiup13 0:1e597b0f8b3b 228 y0 += ystep;
ovidiup13 0:1e597b0f8b3b 229 err += dx;
ovidiup13 0:1e597b0f8b3b 230 }
ovidiup13 0:1e597b0f8b3b 231 }
ovidiup13 0:1e597b0f8b3b 232 }
ovidiup13 0:1e597b0f8b3b 233
ovidiup13 0:1e597b0f8b3b 234 // filled rectangle
ovidiup13 0:1e597b0f8b3b 235 void ST7565::fillrect(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
ovidiup13 0:1e597b0f8b3b 236 uint8_t color)
ovidiup13 0:1e597b0f8b3b 237 {
ovidiup13 0:1e597b0f8b3b 238
ovidiup13 0:1e597b0f8b3b 239 // stupidest version - just pixels - but fast with internal buffer!
ovidiup13 0:1e597b0f8b3b 240 for (uint8_t i=x; i<x+w; i++) {
ovidiup13 0:1e597b0f8b3b 241 for (uint8_t j=y; j<y+h; j++) {
ovidiup13 0:1e597b0f8b3b 242 my_setpixel(i, j, color);
ovidiup13 0:1e597b0f8b3b 243 }
ovidiup13 0:1e597b0f8b3b 244 }
ovidiup13 0:1e597b0f8b3b 245
ovidiup13 0:1e597b0f8b3b 246 updateBoundingBox(x, y, x+w, y+h);
ovidiup13 0:1e597b0f8b3b 247 }
ovidiup13 0:1e597b0f8b3b 248
ovidiup13 0:1e597b0f8b3b 249 // draw a rectangle
ovidiup13 0:1e597b0f8b3b 250 void ST7565::drawrect(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
ovidiup13 0:1e597b0f8b3b 251 uint8_t color)
ovidiup13 0:1e597b0f8b3b 252 {
ovidiup13 0:1e597b0f8b3b 253 // stupidest version - just pixels - but fast with internal buffer!
ovidiup13 0:1e597b0f8b3b 254 for (uint8_t i=x; i<x+w; i++) {
ovidiup13 0:1e597b0f8b3b 255 my_setpixel(i, y, color);
ovidiup13 0:1e597b0f8b3b 256 my_setpixel(i, y+h-1, color);
ovidiup13 0:1e597b0f8b3b 257 }
ovidiup13 0:1e597b0f8b3b 258 for (uint8_t i=y; i<y+h; i++) {
ovidiup13 0:1e597b0f8b3b 259 my_setpixel(x, i, color);
ovidiup13 0:1e597b0f8b3b 260 my_setpixel(x+w-1, i, color);
ovidiup13 0:1e597b0f8b3b 261 }
ovidiup13 0:1e597b0f8b3b 262
ovidiup13 0:1e597b0f8b3b 263 updateBoundingBox(x, y, x+w, y+h);
ovidiup13 0:1e597b0f8b3b 264 }
ovidiup13 0:1e597b0f8b3b 265
ovidiup13 0:1e597b0f8b3b 266 // draw a circle outline
ovidiup13 0:1e597b0f8b3b 267 void ST7565::drawcircle(uint8_t x0, uint8_t y0, uint8_t r,
ovidiup13 0:1e597b0f8b3b 268 uint8_t color)
ovidiup13 0:1e597b0f8b3b 269 {
ovidiup13 0:1e597b0f8b3b 270 updateBoundingBox(x0-r, y0-r, x0+r, y0+r);
ovidiup13 0:1e597b0f8b3b 271
ovidiup13 0:1e597b0f8b3b 272 int8_t f = 1 - r;
ovidiup13 0:1e597b0f8b3b 273 int8_t ddF_x = 1;
ovidiup13 0:1e597b0f8b3b 274 int8_t ddF_y = -2 * r;
ovidiup13 0:1e597b0f8b3b 275 int8_t x = 0;
ovidiup13 0:1e597b0f8b3b 276 int8_t y = r;
ovidiup13 0:1e597b0f8b3b 277
ovidiup13 0:1e597b0f8b3b 278 my_setpixel(x0, y0+r, color);
ovidiup13 0:1e597b0f8b3b 279 my_setpixel(x0, y0-r, color);
ovidiup13 0:1e597b0f8b3b 280 my_setpixel(x0+r, y0, color);
ovidiup13 0:1e597b0f8b3b 281 my_setpixel(x0-r, y0, color);
ovidiup13 0:1e597b0f8b3b 282
ovidiup13 0:1e597b0f8b3b 283 while (x<y) {
ovidiup13 0:1e597b0f8b3b 284 if (f >= 0) {
ovidiup13 0:1e597b0f8b3b 285 y--;
ovidiup13 0:1e597b0f8b3b 286 ddF_y += 2;
ovidiup13 0:1e597b0f8b3b 287 f += ddF_y;
ovidiup13 0:1e597b0f8b3b 288 }
ovidiup13 0:1e597b0f8b3b 289 x++;
ovidiup13 0:1e597b0f8b3b 290 ddF_x += 2;
ovidiup13 0:1e597b0f8b3b 291 f += ddF_x;
ovidiup13 0:1e597b0f8b3b 292
ovidiup13 0:1e597b0f8b3b 293 my_setpixel(x0 + x, y0 + y, color);
ovidiup13 0:1e597b0f8b3b 294 my_setpixel(x0 - x, y0 + y, color);
ovidiup13 0:1e597b0f8b3b 295 my_setpixel(x0 + x, y0 - y, color);
ovidiup13 0:1e597b0f8b3b 296 my_setpixel(x0 - x, y0 - y, color);
ovidiup13 0:1e597b0f8b3b 297
ovidiup13 0:1e597b0f8b3b 298 my_setpixel(x0 + y, y0 + x, color);
ovidiup13 0:1e597b0f8b3b 299 my_setpixel(x0 - y, y0 + x, color);
ovidiup13 0:1e597b0f8b3b 300 my_setpixel(x0 + y, y0 - x, color);
ovidiup13 0:1e597b0f8b3b 301 my_setpixel(x0 - y, y0 - x, color);
ovidiup13 0:1e597b0f8b3b 302
ovidiup13 0:1e597b0f8b3b 303 }
ovidiup13 0:1e597b0f8b3b 304 }
ovidiup13 0:1e597b0f8b3b 305
ovidiup13 0:1e597b0f8b3b 306 void ST7565::fillcircle(uint8_t x0, uint8_t y0, uint8_t r,
ovidiup13 0:1e597b0f8b3b 307 uint8_t color)
ovidiup13 0:1e597b0f8b3b 308 {
ovidiup13 0:1e597b0f8b3b 309 updateBoundingBox(x0-r, y0-r, x0+r, y0+r);
ovidiup13 0:1e597b0f8b3b 310
ovidiup13 0:1e597b0f8b3b 311 int8_t f = 1 - r;
ovidiup13 0:1e597b0f8b3b 312 int8_t ddF_x = 1;
ovidiup13 0:1e597b0f8b3b 313 int8_t ddF_y = -2 * r;
ovidiup13 0:1e597b0f8b3b 314 int8_t x = 0;
ovidiup13 0:1e597b0f8b3b 315 int8_t y = r;
ovidiup13 0:1e597b0f8b3b 316
ovidiup13 0:1e597b0f8b3b 317 for (uint8_t i=y0-r; i<=y0+r; i++) {
ovidiup13 0:1e597b0f8b3b 318 my_setpixel(x0, i, color);
ovidiup13 0:1e597b0f8b3b 319 }
ovidiup13 0:1e597b0f8b3b 320
ovidiup13 0:1e597b0f8b3b 321 while (x<y) {
ovidiup13 0:1e597b0f8b3b 322 if (f >= 0) {
ovidiup13 0:1e597b0f8b3b 323 y--;
ovidiup13 0:1e597b0f8b3b 324 ddF_y += 2;
ovidiup13 0:1e597b0f8b3b 325 f += ddF_y;
ovidiup13 0:1e597b0f8b3b 326 }
ovidiup13 0:1e597b0f8b3b 327 x++;
ovidiup13 0:1e597b0f8b3b 328 ddF_x += 2;
ovidiup13 0:1e597b0f8b3b 329 f += ddF_x;
ovidiup13 0:1e597b0f8b3b 330
ovidiup13 0:1e597b0f8b3b 331 for (uint8_t i=y0-y; i<=y0+y; i++) {
ovidiup13 0:1e597b0f8b3b 332 my_setpixel(x0+x, i, color);
ovidiup13 0:1e597b0f8b3b 333 my_setpixel(x0-x, i, color);
ovidiup13 0:1e597b0f8b3b 334 }
ovidiup13 0:1e597b0f8b3b 335 for (uint8_t i=y0-x; i<=y0+x; i++) {
ovidiup13 0:1e597b0f8b3b 336 my_setpixel(x0+y, i, color);
ovidiup13 0:1e597b0f8b3b 337 my_setpixel(x0-y, i, color);
ovidiup13 0:1e597b0f8b3b 338 }
ovidiup13 0:1e597b0f8b3b 339 }
ovidiup13 0:1e597b0f8b3b 340 }
ovidiup13 0:1e597b0f8b3b 341
ovidiup13 0:1e597b0f8b3b 342 void ST7565::my_setpixel(uint8_t x, uint8_t y, uint8_t color)
ovidiup13 0:1e597b0f8b3b 343 {
ovidiup13 0:1e597b0f8b3b 344 if ((x >= LCDWIDTH) || (y >= LCDHEIGHT))
ovidiup13 0:1e597b0f8b3b 345 return;
ovidiup13 0:1e597b0f8b3b 346
ovidiup13 0:1e597b0f8b3b 347 // x is which column
ovidiup13 0:1e597b0f8b3b 348 if (color)
ovidiup13 0:1e597b0f8b3b 349 st7565_buffer[x+ (y/8)*128] |= _BV(7-(y%8));
ovidiup13 0:1e597b0f8b3b 350 else
ovidiup13 0:1e597b0f8b3b 351 st7565_buffer[x+ (y/8)*128] &= _nBV(7-(y%8));
ovidiup13 0:1e597b0f8b3b 352 }
ovidiup13 0:1e597b0f8b3b 353
ovidiup13 0:1e597b0f8b3b 354 // the most basic function, set a single pixel
ovidiup13 0:1e597b0f8b3b 355 void ST7565::setpixel(uint8_t x, uint8_t y, uint8_t color)
ovidiup13 0:1e597b0f8b3b 356 {
ovidiup13 0:1e597b0f8b3b 357 if ((x >= LCDWIDTH) || (y >= LCDHEIGHT))
ovidiup13 0:1e597b0f8b3b 358 return;
ovidiup13 0:1e597b0f8b3b 359 // x is which column
ovidiup13 0:1e597b0f8b3b 360 if (color)
ovidiup13 0:1e597b0f8b3b 361 st7565_buffer[x+ (y/8)*128] |= _BV(7-(y%8));
ovidiup13 0:1e597b0f8b3b 362 else
ovidiup13 0:1e597b0f8b3b 363 st7565_buffer[x+ (y/8)*128] &= _nBV(7-(y%8));
ovidiup13 0:1e597b0f8b3b 364
ovidiup13 0:1e597b0f8b3b 365 updateBoundingBox(x,y,x,y);
ovidiup13 0:1e597b0f8b3b 366 }
ovidiup13 0:1e597b0f8b3b 367
ovidiup13 0:1e597b0f8b3b 368
ovidiup13 0:1e597b0f8b3b 369 // the most basic function, get a single pixel
ovidiup13 0:1e597b0f8b3b 370 uint8_t ST7565::getpixel(uint8_t x, uint8_t y)
ovidiup13 0:1e597b0f8b3b 371 {
ovidiup13 0:1e597b0f8b3b 372 if ((x >= LCDWIDTH) || (y >= LCDHEIGHT))
ovidiup13 0:1e597b0f8b3b 373 return 0;
ovidiup13 0:1e597b0f8b3b 374
ovidiup13 0:1e597b0f8b3b 375 return (st7565_buffer[x+ (y/8)*128] >> (7-(y%8))) & 0x1;
ovidiup13 0:1e597b0f8b3b 376 }
ovidiup13 0:1e597b0f8b3b 377
ovidiup13 0:1e597b0f8b3b 378
ovidiup13 0:1e597b0f8b3b 379 ST7565::ST7565(PinName mosi, PinName sclk, PinName cs, PinName rst, PinName a0)
ovidiup13 0:1e597b0f8b3b 380 // set pin directions
ovidiup13 0:1e597b0f8b3b 381 : _spi(mosi, NC, sclk), _cs(cs), _rst(rst), _a0(a0)
ovidiup13 0:1e597b0f8b3b 382
ovidiup13 0:1e597b0f8b3b 383 {
ovidiup13 0:1e597b0f8b3b 384 _spi.format(8, 0);
ovidiup13 0:1e597b0f8b3b 385 _spi.frequency(1000000);
ovidiup13 0:1e597b0f8b3b 386 }
ovidiup13 0:1e597b0f8b3b 387
ovidiup13 0:1e597b0f8b3b 388
ovidiup13 0:1e597b0f8b3b 389
ovidiup13 0:1e597b0f8b3b 390 void ST7565::st7565_init(void)
ovidiup13 0:1e597b0f8b3b 391 {
ovidiup13 0:1e597b0f8b3b 392 wait_ms(100);
ovidiup13 0:1e597b0f8b3b 393 _rst = 0;
ovidiup13 0:1e597b0f8b3b 394 wait_ms(100);
ovidiup13 0:1e597b0f8b3b 395 _rst = 1;
ovidiup13 0:1e597b0f8b3b 396
ovidiup13 0:1e597b0f8b3b 397
ovidiup13 0:1e597b0f8b3b 398 // LCD bias select
ovidiup13 0:1e597b0f8b3b 399 st7565_command(CMD_SET_BIAS_7);
ovidiup13 0:1e597b0f8b3b 400 // ADC select
ovidiup13 0:1e597b0f8b3b 401 st7565_command(CMD_SET_ADC_NORMAL);
ovidiup13 0:1e597b0f8b3b 402 // SHL select
ovidiup13 0:1e597b0f8b3b 403 st7565_command(CMD_SET_COM_NORMAL);
ovidiup13 0:1e597b0f8b3b 404
ovidiup13 0:1e597b0f8b3b 405 // turn on voltage converter (VC=1, VR=0, VF=0)
ovidiup13 0:1e597b0f8b3b 406 st7565_command(CMD_SET_POWER_CONTROL | 0x4);
ovidiup13 0:1e597b0f8b3b 407 // wait for 50% rising
ovidiup13 0:1e597b0f8b3b 408 wait_ms(50);
ovidiup13 0:1e597b0f8b3b 409
ovidiup13 0:1e597b0f8b3b 410 // turn on voltage regulator (VC=1, VR=1, VF=0)
ovidiup13 0:1e597b0f8b3b 411 st7565_command(CMD_SET_POWER_CONTROL | 0x6);
ovidiup13 0:1e597b0f8b3b 412 // wait >=50ms
ovidiup13 0:1e597b0f8b3b 413 wait_ms(20);
ovidiup13 0:1e597b0f8b3b 414
ovidiup13 0:1e597b0f8b3b 415 // turn on voltage follower (VC=1, VR=1, VF=1)
ovidiup13 0:1e597b0f8b3b 416 st7565_command(CMD_SET_POWER_CONTROL | 0x7);
ovidiup13 0:1e597b0f8b3b 417 // wait
ovidiup13 0:1e597b0f8b3b 418 wait_ms(10);
ovidiup13 0:1e597b0f8b3b 419
ovidiup13 0:1e597b0f8b3b 420 // set lcd operating voltage (regulator resistor, ref voltage resistor)
ovidiup13 0:1e597b0f8b3b 421 st7565_command(CMD_SET_RESISTOR_RATIO | 0x4);
ovidiup13 0:1e597b0f8b3b 422 wait_ms(10);
ovidiup13 0:1e597b0f8b3b 423
ovidiup13 0:1e597b0f8b3b 424
ovidiup13 0:1e597b0f8b3b 425 // st7565_set_brightness(INITIAL_CONTRAST);
ovidiup13 0:1e597b0f8b3b 426 // set up a bounding box for screen updates
ovidiup13 0:1e597b0f8b3b 427 updateBoundingBox(0, 0, LCDWIDTH-1, LCDHEIGHT-1);
ovidiup13 0:1e597b0f8b3b 428
ovidiup13 0:1e597b0f8b3b 429
ovidiup13 0:1e597b0f8b3b 430 st7565_command(CMD_DISPLAY_ON);
ovidiup13 0:1e597b0f8b3b 431 st7565_command(CMD_SET_ALLPTS_NORMAL);
ovidiup13 0:1e597b0f8b3b 432
ovidiup13 0:1e597b0f8b3b 433
ovidiup13 0:1e597b0f8b3b 434 // reference voltage resistor
ovidiup13 0:1e597b0f8b3b 435 st7565_command(CMD_SET_VOLUME_FIRST);
ovidiup13 0:1e597b0f8b3b 436 wait_ms(10);
ovidiup13 0:1e597b0f8b3b 437 st7565_command(CMD_SET_VOLUME_SECOND);
ovidiup13 0:1e597b0f8b3b 438 wait_ms(10);
ovidiup13 0:1e597b0f8b3b 439
ovidiup13 0:1e597b0f8b3b 440
ovidiup13 0:1e597b0f8b3b 441
ovidiup13 0:1e597b0f8b3b 442 // Initial display line ( = 0)
ovidiup13 0:1e597b0f8b3b 443 st7565_command(CMD_SET_DISP_START_LINE);
ovidiup13 0:1e597b0f8b3b 444 // Initial page address ( = 0)
ovidiup13 0:1e597b0f8b3b 445 st7565_command(CMD_SET_PAGE);
ovidiup13 0:1e597b0f8b3b 446 st7565_command(CMD_SET_COLUMN_UPPER);
ovidiup13 0:1e597b0f8b3b 447 st7565_command(CMD_SET_COLUMN_LOWER);
ovidiup13 0:1e597b0f8b3b 448
ovidiup13 0:1e597b0f8b3b 449 }
ovidiup13 0:1e597b0f8b3b 450
ovidiup13 0:1e597b0f8b3b 451 inline void ST7565::spiwrite(uint8_t c)
ovidiup13 0:1e597b0f8b3b 452 {
ovidiup13 0:1e597b0f8b3b 453 _spi.write(c);
ovidiup13 0:1e597b0f8b3b 454 }
ovidiup13 0:1e597b0f8b3b 455
ovidiup13 0:1e597b0f8b3b 456 void ST7565::st7565_command(uint8_t c)
ovidiup13 0:1e597b0f8b3b 457 {
ovidiup13 0:1e597b0f8b3b 458 _cs = 0;
ovidiup13 0:1e597b0f8b3b 459 _a0 = 0;
ovidiup13 0:1e597b0f8b3b 460 _spi.write(c);
ovidiup13 0:1e597b0f8b3b 461 _cs = 1;
ovidiup13 0:1e597b0f8b3b 462 }
ovidiup13 0:1e597b0f8b3b 463
ovidiup13 0:1e597b0f8b3b 464 void ST7565::st7565_data(uint8_t c)
ovidiup13 0:1e597b0f8b3b 465 {
ovidiup13 0:1e597b0f8b3b 466 _cs = 0;
ovidiup13 0:1e597b0f8b3b 467 _a0 = 1;
ovidiup13 0:1e597b0f8b3b 468 _spi.write(c);
ovidiup13 0:1e597b0f8b3b 469 _cs = 1;
ovidiup13 0:1e597b0f8b3b 470 }
ovidiup13 0:1e597b0f8b3b 471
ovidiup13 0:1e597b0f8b3b 472 void ST7565::st7565_set_brightness(uint8_t val)
ovidiup13 0:1e597b0f8b3b 473 {
ovidiup13 0:1e597b0f8b3b 474 st7565_command(CMD_SET_VOLUME_FIRST);
ovidiup13 0:1e597b0f8b3b 475 st7565_command(CMD_SET_VOLUME_SECOND | (val & 0x3f));
ovidiup13 0:1e597b0f8b3b 476 }
ovidiup13 0:1e597b0f8b3b 477
ovidiup13 0:1e597b0f8b3b 478 void ST7565::begin(uint8_t contrast){
ovidiup13 0:1e597b0f8b3b 479 st7565_init();
ovidiup13 0:1e597b0f8b3b 480 st7565_command(CMD_DISPLAY_ON);
ovidiup13 0:1e597b0f8b3b 481 st7565_command(CMD_SET_ALLPTS_NORMAL);
ovidiup13 0:1e597b0f8b3b 482 st7565_set_brightness(contrast);
ovidiup13 0:1e597b0f8b3b 483 }
ovidiup13 0:1e597b0f8b3b 484
ovidiup13 0:1e597b0f8b3b 485
ovidiup13 0:1e597b0f8b3b 486 void ST7565::display(void)
ovidiup13 0:1e597b0f8b3b 487 {
ovidiup13 0:1e597b0f8b3b 488 uint8_t col, maxcol, p;
ovidiup13 0:1e597b0f8b3b 489
ovidiup13 0:1e597b0f8b3b 490 for(p = 0; p < 8; p++) {
ovidiup13 0:1e597b0f8b3b 491 #ifdef enablePartialUpdate
ovidiup13 0:1e597b0f8b3b 492 // check if this page is part of update
ovidiup13 0:1e597b0f8b3b 493 if ( yUpdateMin >= ((p+1)*8) ) {
ovidiup13 0:1e597b0f8b3b 494 continue; // nope, skip it!
ovidiup13 0:1e597b0f8b3b 495 }
ovidiup13 0:1e597b0f8b3b 496 if (yUpdateMax < p*8) {
ovidiup13 0:1e597b0f8b3b 497 break;
ovidiup13 0:1e597b0f8b3b 498 }
ovidiup13 0:1e597b0f8b3b 499 #endif
ovidiup13 0:1e597b0f8b3b 500 st7565_command(CMD_SET_PAGE | pagemap[p]);
ovidiup13 0:1e597b0f8b3b 501
ovidiup13 0:1e597b0f8b3b 502 #ifdef enablePartialUpdate
ovidiup13 0:1e597b0f8b3b 503 col = xUpdateMin;
ovidiup13 0:1e597b0f8b3b 504 maxcol = xUpdateMax;
ovidiup13 0:1e597b0f8b3b 505 #else
ovidiup13 0:1e597b0f8b3b 506 // start at the beginning of the row
ovidiup13 0:1e597b0f8b3b 507 col = 0;
ovidiup13 0:1e597b0f8b3b 508 maxcol = LCDWIDTH-1;
ovidiup13 0:1e597b0f8b3b 509 #endif
ovidiup13 0:1e597b0f8b3b 510
ovidiup13 0:1e597b0f8b3b 511 st7565_command(CMD_SET_COLUMN_LOWER | ((col+ST7565_STARTBYTES) & 0xf));
ovidiup13 0:1e597b0f8b3b 512 st7565_command(CMD_SET_COLUMN_UPPER | (((col+ST7565_STARTBYTES) >> 4) & 0x0F));
ovidiup13 0:1e597b0f8b3b 513 st7565_command(CMD_RMW);
ovidiup13 0:1e597b0f8b3b 514
ovidiup13 0:1e597b0f8b3b 515 for(; col <= maxcol; col++) {
ovidiup13 0:1e597b0f8b3b 516 st7565_data(st7565_buffer[(128*p)+col]);
ovidiup13 0:1e597b0f8b3b 517 }
ovidiup13 0:1e597b0f8b3b 518 }
ovidiup13 0:1e597b0f8b3b 519
ovidiup13 0:1e597b0f8b3b 520 #ifdef enablePartialUpdate
ovidiup13 0:1e597b0f8b3b 521 xUpdateMin = LCDWIDTH - 1;
ovidiup13 0:1e597b0f8b3b 522 xUpdateMax = 0;
ovidiup13 0:1e597b0f8b3b 523 yUpdateMin = LCDHEIGHT-1;
ovidiup13 0:1e597b0f8b3b 524 yUpdateMax = 0;
ovidiup13 0:1e597b0f8b3b 525 #endif
ovidiup13 0:1e597b0f8b3b 526 }
ovidiup13 0:1e597b0f8b3b 527
ovidiup13 0:1e597b0f8b3b 528 // clear everything
ovidiup13 0:1e597b0f8b3b 529 void ST7565::clear(void)
ovidiup13 0:1e597b0f8b3b 530 {
ovidiup13 0:1e597b0f8b3b 531 memset(st7565_buffer, 0, 1024);
ovidiup13 0:1e597b0f8b3b 532 updateBoundingBox(0, 0, LCDWIDTH-1, LCDHEIGHT-1);
ovidiup13 0:1e597b0f8b3b 533 }
ovidiup13 0:1e597b0f8b3b 534
ovidiup13 0:1e597b0f8b3b 535
ovidiup13 0:1e597b0f8b3b 536 // this doesnt touch the buffer, just clears the display RAM - might be handy
ovidiup13 0:1e597b0f8b3b 537 void ST7565::clear_display(void)
ovidiup13 0:1e597b0f8b3b 538 {
ovidiup13 0:1e597b0f8b3b 539 uint8_t p, c;
ovidiup13 0:1e597b0f8b3b 540
ovidiup13 0:1e597b0f8b3b 541 for(p = 0; p < 8; p++) {
ovidiup13 0:1e597b0f8b3b 542
ovidiup13 0:1e597b0f8b3b 543 st7565_command(CMD_SET_PAGE | p);
ovidiup13 0:1e597b0f8b3b 544 for(c = 0; c < 129; c++) {
ovidiup13 0:1e597b0f8b3b 545 st7565_command(CMD_SET_COLUMN_LOWER | (c & 0xf));
ovidiup13 0:1e597b0f8b3b 546 st7565_command(CMD_SET_COLUMN_UPPER | ((c >> 4) & 0xf));
ovidiup13 0:1e597b0f8b3b 547 st7565_data(0x0);
ovidiup13 0:1e597b0f8b3b 548 }
ovidiup13 0:1e597b0f8b3b 549 }
ovidiup13 0:1e597b0f8b3b 550 }
ovidiup13 0:1e597b0f8b3b 551
ovidiup13 0:1e597b0f8b3b 552 //additional function to set a bit
ovidiup13 0:1e597b0f8b3b 553 uint8_t ST7565::_BV(uint8_t bit)
ovidiup13 0:1e597b0f8b3b 554 {
ovidiup13 0:1e597b0f8b3b 555 return 1 << bit;
ovidiup13 0:1e597b0f8b3b 556 }
ovidiup13 0:1e597b0f8b3b 557
ovidiup13 0:1e597b0f8b3b 558 uint8_t ST7565::_nBV(uint8_t bit)
ovidiup13 0:1e597b0f8b3b 559 {
ovidiup13 0:1e597b0f8b3b 560 return 0 << bit;
ovidiup13 0:1e597b0f8b3b 561 }