Subversion Repositories libSSD1306

Rev

Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/*********************************************************************
2
This is a library for our Monochrome OLEDs based on SSD1306 drivers
3
 
4
  Pick one up today in the adafruit shop!
5
  ------> http://www.adafruit.com/category/63_98
6
 
7
These displays use SPI to communicate, 4 or 5 pins are required to  
8
interface
9
 
10
Adafruit invests time and resources providing this open source code,
11
please support Adafruit and open-source hardware by purchasing
12
products from Adafruit!
13
 
14
Written by Limor Fried/Ladyada  for Adafruit Industries.  
15
BSD license, check license.txt for more information
16
All text above, and the splash screen must be included in any redistribution
17
*********************************************************************/
18
 
3 mjames 19
#include "ssd1306_config.h"
2 mjames 20
 
21
typedef uint8_t boolean;
22
static const boolean true = 1;
23
static const boolean false = 0;
24
 
25
#define BLACK  0
26
#define WHITE  1
27
#define INVERT 2
28
 
29
// this driver can cope with more than one physical display of the same type.
30
 
3 mjames 31
#define MAX_PHYS_DISPLAYS 1
2 mjames 32
 
3 mjames 33
extern void ssd1306spiInit(void);
34
 
35
extern void ssd1306fastSPIwrite(uint8_t d);
36
 
37
extern void ssd1306commandSPIwrite(uint8_t c);
38
 
39
extern void ssd1306resetDisplay(void);
40
 
41
extern void ssd1306SendDisplay(uint8_t * buff, uint8_t len);
42
 
2 mjames 43
/*=========================================================================
44
    SSD1306 Displays
45
    -----------------------------------------------------------------------
46
    The driver is used in multiple displays (128x64, 128x32, etc.).
47
    Select the appropriate display below to create an appropriately
48
    sized framebuffer, etc.
49
 
50
    SSD1306_128_64  128x64 pixel display
51
 
52
    SSD1306_128_32  128x32 pixel display
53
 
54
    -----------------------------------------------------------------------*/
55
/*=========================================================================*/
56
 
57
 
3 mjames 58
// the 1106 has a RAM width of 128
2 mjames 59
#if defined SSD1306_128_64
4 mjames 60
// 0.9 inch display
61
  #define SSD1306_LCDWIDTH                 128
2 mjames 62
  #define SSD1306_LCDHEIGHT                 64
3 mjames 63
  #define SSD1306_RAMWIDTH                 128
4 mjames 64
#elif defined SSD1306_132_64
65
// 1.3 inch display
66
  #define SSD1306_LCDWIDTH                 128
67
  #define SSD1306_LCDHEIGHT                 64
68
  #define SSD1306_RAMWIDTH                 132
3 mjames 69
#elif defined SSD1306_128_32
4 mjames 70
  #define SSD1306_LCDWIDTH                 128
2 mjames 71
  #define SSD1306_LCDHEIGHT                 32
3 mjames 72
  #define SSD1306_RAMWIDTH                 128
73
#else
74
  #error "At least one SSD1306 display must be specified in SSD1306.h"
2 mjames 75
#endif
76
 
77
#define SSD1306_SETCONTRAST 0x81
78
#define SSD1306_DISPLAYALLON_RESUME 0xA4
79
#define SSD1306_DISPLAYALLON 0xA5
80
#define SSD1306_NORMALDISPLAY 0xA6
81
#define SSD1306_INVERTDISPLAY 0xA7
82
#define SSD1306_DISPLAYOFF 0xAE
83
#define SSD1306_DISPLAYON 0xAF
84
 
85
#define SSD1306_SETDISPLAYOFFSET 0xD3
86
#define SSD1306_SETCOMPINS 0xDA
87
 
88
#define SSD1306_SETVCOMDETECT 0xDB
89
 
90
#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
91
#define SSD1306_SETPRECHARGE 0xD9
92
 
93
#define SSD1306_SETMULTIPLEX 0xA8
94
 
95
#define SSD1306_SETLOWCOLUMN 0x00
96
#define SSD1306_SETHIGHCOLUMN 0x10
97
 
98
#define SSD1306_SETSTARTLINE 0x40
99
 
100
#define SSD1306_MEMORYMODE 0x20
101
#define SSD1306_COLUMNADDR 0x21
102
#define SSD1306_PAGEADDR   0x22
103
 
104
#define SSD1306_COMSCANINC 0xC0
105
#define SSD1306_COMSCANDEC 0xC8
106
 
107
#define SSD1306_SEGREMAP 0xA0
108
 
109
#define SSD1306_CHARGEPUMP 0x8D
110
 
111
#define SSD1306_EXTERNALVCC 0x1
112
#define SSD1306_SWITCHCAPVCC 0x2
113
 
114
// Scrolling #defines
115
#define SSD1306_ACTIVATE_SCROLL 0x2F
116
#define SSD1306_DEACTIVATE_SCROLL 0x2E
117
#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3
118
#define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26
119
#define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27
120
#define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
121
#define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A
122
 
123
extern const uint16_t WIDTH;
124
extern const uint16_t HEIGHT;
3 mjames 125
extern uint8_t display_buffer[];
2 mjames 126
 
127
extern uint8_t getRotation(void);
128
extern int16_t width(void);
129
extern int16_t height(void);
130
 
131
/* stolen from AdaFruit class and converted to C */
132
void ssd1306_begin(uint8_t vccstate, uint8_t i2caddr);
133
 
134
extern  void clearDisplay(void);
135
extern  void invertDisplay(uint8_t i);
136
extern  void display();
137
 
138
extern  void startscrollright(uint8_t start, uint8_t stop);
139
extern  void startscrollleft(uint8_t start, uint8_t stop);
140
 
141
extern  void startscrolldiagright(uint8_t start, uint8_t stop);
142
extern  void startscrolldiagleft(uint8_t start, uint8_t stop);
143
extern  void stopscroll(void);
144
 
145
extern void dim(uint8_t contrast);
146
 
4 mjames 147
extern void drawPixel(int16_t x, int16_t y, uint16_t color);
2 mjames 148
 
4 mjames 149
extern void drawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color);
2 mjames 150
 
4 mjames 151
extern  void select_display(int i) ; // select physical display [i]
2 mjames 152
 
4 mjames 153
extern  inline uint8_t * display_address(void) ;