forked from adafruit/Adafruit_SSD1305
/
Adafruit_SSD1305.h
134 lines (100 loc) · 4.32 KB
/
Adafruit_SSD1305.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*********************************************************************
This is a library for our Monochrome OLEDs based on SSD1305 drivers
Pick one up today in the adafruit shop!
------> https://www.adafruit.com/products/2675
These displays use I2C or SPI to communicate
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <Adafruit_GFX.h>
#define adagfx_swap(a, b) { uint8_t t = a; a = b; b = t; }
#define BLACK 0
#define WHITE 1
/*=========================================================================
SSD1305 Displays
-----------------------------------------------------------------------
The driver is used in multiple displays (128x64, 128x32, etc.).
Select the appropriate display below to create an appropriately
sized framebuffer, etc.
SSD1305_128_64 128x64 pixel display
SSD1305_128_32 128x32 pixel display
You also need to set the LCDWIDTH and LCDHEIGHT defines to an
appropriate size
-----------------------------------------------------------------------*/
#define SSD1305_128_32
/*=========================================================================*/
#if defined SSD1305_128_64 && defined SSD1305_128_32
#error "Only one SSD1305 display can be specified at once in SSD1305.h"
#endif
#if !defined SSD1305_128_64 && !defined SSD1305_128_32
#error "At least one SSD1305 display must be specified in SSD1305.h"
#endif
#if defined SSD1305_128_64
#define SSD1305_LCDWIDTH 128
#define SSD1305_LCDHEIGHT 64
#endif
#if defined SSD1305_128_32
#define SSD1305_LCDWIDTH 128
#define SSD1305_LCDHEIGHT 32
#endif
#define SSD1305_I2C_ADDRESS 0x3C // 011110+SA0+RW - 0x3C or 0x3D
#define SSD1305_SETLOWCOLUMN 0x00
#define SSD1305_SETHIGHCOLUMN 0x10
#define SSD1305_MEMORYMODE 0x20
#define SSD1305_SETCOLADDR 0x21
#define SSD1305_SETPAGEADDR 0x22
#define SSD1305_SETSTARTLINE 0x40
#define SSD1305_SETCONTRAST 0x81
#define SSD1305_SETBRIGHTNESS 0x82
#define SSD1305_SETLUT 0x91
#define SSD1305_SEGREMAP 0xA0
#define SSD1305_DISPLAYALLON_RESUME 0xA4
#define SSD1305_DISPLAYALLON 0xA5
#define SSD1305_NORMALDISPLAY 0xA6
#define SSD1305_INVERTDISPLAY 0xA7
#define SSD1305_SETMULTIPLEX 0xA8
#define SSD1305_DISPLAYDIM 0xAC
#define SSD1305_MASTERCONFIG 0xAD
#define SSD1305_DISPLAYOFF 0xAE
#define SSD1305_DISPLAYON 0xAF
#define SSD1305_SETPAGESTART 0xB0
#define SSD1305_COMSCANINC 0xC0
#define SSD1305_COMSCANDEC 0xC8
#define SSD1305_SETDISPLAYOFFSET 0xD3
#define SSD1305_SETDISPLAYCLOCKDIV 0xD5
#define SSD1305_SETAREACOLOR 0xD8
#define SSD1305_SETPRECHARGE 0xD9
#define SSD1305_SETCOMPINS 0xDA
#define SSD1305_SETVCOMLEVEL 0xDB
class Adafruit_SSD1305 : public Adafruit_GFX {
public:
Adafruit_SSD1305(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS) :sid(SID), sclk(SCLK), dc(DC), rst(RST), cs(CS), Adafruit_GFX(SSD1305_LCDWIDTH, SSD1305_LCDHEIGHT) {}
Adafruit_SSD1305(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST) :sid(SID), sclk(SCLK), dc(DC), rst(RST), cs(-1), Adafruit_GFX(SSD1305_LCDWIDTH, SSD1305_LCDHEIGHT) {}
Adafruit_SSD1305(int8_t DC, int8_t RST, int8_t CS) :sid(-1), sclk(-1), dc(DC), rst(RST), cs(CS), Adafruit_GFX(SSD1305_LCDWIDTH, SSD1305_LCDHEIGHT) {}
Adafruit_SSD1305(int8_t RST) :sid(-1), sclk(-1), dc(-1), rst(RST), cs(-1), Adafruit_GFX(SSD1305_LCDWIDTH, SSD1305_LCDHEIGHT) {}
void begin(uint8_t i2caddr = SSD1305_I2C_ADDRESS);
void command(uint8_t c);
void data(uint8_t c);
void clearDisplay(void);
void invertDisplay(uint8_t i);
void setBrightness(uint8_t i);
void display();
void drawPixel(int16_t x, int16_t y, uint16_t color);
private:
uint8_t _i2caddr;
int8_t sid, sclk, dc, rst, cs;
void spixfer(uint8_t x);
#ifdef __AVR__
volatile uint8_t *mosiport, *clkport;
uint8_t mosipinmask, clkpinmask;
#endif
};