adapted for ST7567 (aitendo CH12864F-SPI)

Fork of st7565LCD by jun imamura

/media/uploads/masato/ch12864f-spi.jpg

jun imamura さんの st7565 SPI LCD ライブラリを st7567 (aitendo CH12864 SPI) LCD 用にちょっとだけ手をいれたもの。 st7565LCD.cpp 内で #define ST7567 とする。この定義を外せば元の ST7565 用となる。写真は FRDM-KL05Z での動作例。テスト用プログラムは jun imamura のものをそのまま使っている。

aitendo CH12864 SPI の説明には3.3〜5Vで動作するとあるが、ST7567R のドキュメントには 3.3V までとあるから 5V 動作はしないほうが良いだろう。また、手元の製品ではシルクでピンネームが入っていたが、Web ページの表とは異なっている。これはシルクのほうが誤り。aitendo の商品ページには Adafruit の ST7565 ライブラリでの動作例がでているが、これも同じように修正できる。

Committer:
masato
Date:
Sat Jan 09 12:21:39 2016 +0000
Revision:
1:29ff79184a05
Parent:
0:f2eba6cbd093
adapted for ST7567 (aitendo CH12864F-SPI)

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