This is test library which translated from code for arduino. Original code, and their product can be found in the link below. http://www.adafruit.com/products/250

Dependents:   CH12864F-SPI2_Test

ST7565 LCD

!This is the test library.!

I translated arduino code to mbed. You can find the product and datasheet from the following link.

http://www.adafruit.com/products/250

void begin(uint8_t contrast);

  • Initialize data with Adafruit Logo.
  • contrast is needed

void clear_display(void);

  • Clears only display data. RAM data kept remained.

void clear();

  • Clears display data and RAM data.

void display();

  • Update display with RAM data.

void setpixel(uint8_t x, uint8_t y, uint8_t color);

  • Set a dot at (x, y)

void fillcircle(uint8_t x0, uint8_t y0, uint8_t r, uint8_t color);

  • Draw a filled circle with its center coordinate (x0, y0) and radius r.

void fillrect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t color);

  • Draw a filled rectangular with its top-left coordinate (x, y) and its width (w) and height (h).

void drawcircle(uint8_t x0, uint8_t y0, uint8_t r, uint8_t color);

  • Draw a circle with its center coordinate (x0, y0) and radius r.

void drawrect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t color);

  • Draw a rectangular with its top-left coordinate (x, y) and its width (w) and height (h).

void drawline(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color);

  • Draw a line starts from (x0, y0) to (x1, y1)

void drawchar(uint8_t x, uint8_t line, char c);

  • Set a character

void drawstring(uint8_t x, uint8_t line, char *c);

  • Set string

Example code for main.cpp:

#include "mbed.h"
#include "st7565LCD.h"


ST7565 st7565(p11, p13, p21, p22, p23); // mosi, sclk, cs, rst, a0
int main()
{
//0x18 defines cntrast
    st7565.begin(0x18);
//show initial data (Adafruit logo)
    st7565.display();
    wait(1.0);
//Clear all data
    st7565.clear();
//test code
        st7565.drawstring(1,1,"test");
//update RAM data
        st7565.display();
    while(1) {
    }
}

Committer:
imachooon
Date:
Tue Mar 18 09:26:16 2014 +0000
Revision:
0:f2eba6cbd093
This is test library for ST7565 LCD.; http://www.adafruit.com/products/250; This library is translated from arduino code they offered to mbed.;

Who changed what in which revision?

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