for ST7567 LCD

Dependents:   BSM02

Fork of st7565LCD by Masato YAMANISHI

Committer:
ryood
Date:
Tue Aug 30 11:56:52 2016 +0000
Revision:
2:0e21d2f2155a
Parent:
0:f2eba6cbd093
Add function: set_spi_frequency()

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
imachooon 0:f2eba6cbd093 26 #ifndef _st7565LCD_H_
imachooon 0:f2eba6cbd093 27 #define _st7565LCD_H_
imachooon 0:f2eba6cbd093 28
imachooon 0:f2eba6cbd093 29 #include "mbed.h"
imachooon 0:f2eba6cbd093 30
imachooon 0:f2eba6cbd093 31 #define swap(a, b) { uint8_t t = a; a = b; b = t; }
imachooon 0:f2eba6cbd093 32
imachooon 0:f2eba6cbd093 33 #define BLACK 1
imachooon 0:f2eba6cbd093 34 #define WHITE 0
imachooon 0:f2eba6cbd093 35
imachooon 0:f2eba6cbd093 36 #define LCDWIDTH 128
imachooon 0:f2eba6cbd093 37 #define LCDHEIGHT 64
imachooon 0:f2eba6cbd093 38
imachooon 0:f2eba6cbd093 39 #define INITIAL_CONTRAST 0x18
imachooon 0:f2eba6cbd093 40
imachooon 0:f2eba6cbd093 41 #define CMD_DISPLAY_OFF 0xAE
imachooon 0:f2eba6cbd093 42 #define CMD_DISPLAY_ON 0xAF
imachooon 0:f2eba6cbd093 43
imachooon 0:f2eba6cbd093 44 #define CMD_SET_DISP_START_LINE 0x40
imachooon 0:f2eba6cbd093 45 #define CMD_SET_PAGE 0xB0
imachooon 0:f2eba6cbd093 46
imachooon 0:f2eba6cbd093 47 #define CMD_SET_COLUMN_UPPER 0x10
imachooon 0:f2eba6cbd093 48 #define CMD_SET_COLUMN_LOWER 0x00
imachooon 0:f2eba6cbd093 49
imachooon 0:f2eba6cbd093 50 #define CMD_SET_ADC_NORMAL 0xA0
imachooon 0:f2eba6cbd093 51 #define CMD_SET_ADC_REVERSE 0xA1
imachooon 0:f2eba6cbd093 52
imachooon 0:f2eba6cbd093 53 #define CMD_SET_DISP_NORMAL 0xA6
imachooon 0:f2eba6cbd093 54 #define CMD_SET_DISP_REVERSE 0xA7
imachooon 0:f2eba6cbd093 55
imachooon 0:f2eba6cbd093 56 #define CMD_SET_ALLPTS_NORMAL 0xA4
imachooon 0:f2eba6cbd093 57 #define CMD_SET_ALLPTS_ON 0xA5
imachooon 0:f2eba6cbd093 58 #define CMD_SET_BIAS_9 0xA2
imachooon 0:f2eba6cbd093 59 #define CMD_SET_BIAS_7 0xA3
imachooon 0:f2eba6cbd093 60
imachooon 0:f2eba6cbd093 61 #define CMD_RMW 0xE0
imachooon 0:f2eba6cbd093 62 #define CMD_RMW_CLEAR 0xEE
imachooon 0:f2eba6cbd093 63 #define CMD_INTERNAL_RESET 0xE2
imachooon 0:f2eba6cbd093 64 #define CMD_SET_COM_NORMAL 0xC0
imachooon 0:f2eba6cbd093 65 #define CMD_SET_COM_REVERSE 0xC8
imachooon 0:f2eba6cbd093 66 #define CMD_SET_POWER_CONTROL 0x28
imachooon 0:f2eba6cbd093 67 #define CMD_SET_RESISTOR_RATIO 0x20
imachooon 0:f2eba6cbd093 68 #define CMD_SET_VOLUME_FIRST 0x81
imachooon 0:f2eba6cbd093 69 #define CMD_SET_VOLUME_SECOND 0x00
imachooon 0:f2eba6cbd093 70 #define CMD_SET_STATIC_OFF 0xAC
imachooon 0:f2eba6cbd093 71 #define CMD_SET_STATIC_ON 0xAD
imachooon 0:f2eba6cbd093 72 #define CMD_SET_STATIC_REG 0x0
imachooon 0:f2eba6cbd093 73 #define CMD_SET_BOOSTER_FIRST 0xF8
imachooon 0:f2eba6cbd093 74 #define CMD_SET_BOOSTER_234 0
imachooon 0:f2eba6cbd093 75 #define CMD_SET_BOOSTER_5 1
imachooon 0:f2eba6cbd093 76 #define CMD_SET_BOOSTER_6 3
imachooon 0:f2eba6cbd093 77 #define CMD_NOP 0xE3
imachooon 0:f2eba6cbd093 78 #define CMD_TEST 0xF0
imachooon 0:f2eba6cbd093 79
imachooon 0:f2eba6cbd093 80 class ST7565 {
imachooon 0:f2eba6cbd093 81
imachooon 0:f2eba6cbd093 82 private:
imachooon 0:f2eba6cbd093 83 SPI _spi;
imachooon 0:f2eba6cbd093 84 DigitalOut _cs;
imachooon 0:f2eba6cbd093 85 DigitalOut _rst;
imachooon 0:f2eba6cbd093 86 DigitalOut _a0;
imachooon 0:f2eba6cbd093 87 void spiwrite(uint8_t c);
imachooon 0:f2eba6cbd093 88 void my_setpixel(uint8_t x, uint8_t y, uint8_t color);
imachooon 0:f2eba6cbd093 89
imachooon 0:f2eba6cbd093 90 //uint8_t buffer[128*64/8];
imachooon 0:f2eba6cbd093 91 public:
imachooon 0:f2eba6cbd093 92 ST7565(PinName mosi, PinName sclk, PinName cs, PinName rst, PinName a0);
imachooon 0:f2eba6cbd093 93 ~ST7565() {};
imachooon 0:f2eba6cbd093 94 void st7565_init(void);
imachooon 0:f2eba6cbd093 95 void begin(uint8_t contrast);
imachooon 0:f2eba6cbd093 96 void st7565_command(uint8_t c);
imachooon 0:f2eba6cbd093 97 void st7565_data(uint8_t c);
imachooon 0:f2eba6cbd093 98 void st7565_set_brightness(uint8_t val);
imachooon 0:f2eba6cbd093 99 void clear_display(void);
imachooon 0:f2eba6cbd093 100 void clear();
imachooon 0:f2eba6cbd093 101 void display();
imachooon 0:f2eba6cbd093 102
imachooon 0:f2eba6cbd093 103 void setpixel(uint8_t x, uint8_t y, uint8_t color);
imachooon 0:f2eba6cbd093 104 uint8_t getpixel(uint8_t x, uint8_t y);
imachooon 0:f2eba6cbd093 105 void fillcircle(uint8_t x0, uint8_t y0, uint8_t r,
imachooon 0:f2eba6cbd093 106 uint8_t color);
imachooon 0:f2eba6cbd093 107 void drawcircle(uint8_t x0, uint8_t y0, uint8_t r,
imachooon 0:f2eba6cbd093 108 uint8_t color);
imachooon 0:f2eba6cbd093 109 void drawrect(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
imachooon 0:f2eba6cbd093 110 uint8_t color);
imachooon 0:f2eba6cbd093 111 void fillrect(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
imachooon 0:f2eba6cbd093 112 uint8_t color);
imachooon 0:f2eba6cbd093 113 void drawline(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
imachooon 0:f2eba6cbd093 114 uint8_t color);
imachooon 0:f2eba6cbd093 115 void drawchar(uint8_t x, uint8_t line, char c);
imachooon 0:f2eba6cbd093 116 void drawstring(uint8_t x, uint8_t line, char *c);
imachooon 0:f2eba6cbd093 117 /*void drawbitmap(uint8_t x, uint8_t y,
imachooon 0:f2eba6cbd093 118 const uint8_t *bitmap, uint8_t w, uint8_t h,
imachooon 0:f2eba6cbd093 119 uint8_t color);*/
imachooon 0:f2eba6cbd093 120 uint8_t _BV(uint8_t bit);
imachooon 0:f2eba6cbd093 121 uint8_t _nBV(uint8_t bit);
ryood 2:0e21d2f2155a 122
ryood 2:0e21d2f2155a 123 void set_spi_frequency(int frequency);
imachooon 0:f2eba6cbd093 124
imachooon 0:f2eba6cbd093 125 };
imachooon 0:f2eba6cbd093 126
imachooon 0:f2eba6cbd093 127 #endif