SSD1306 only uses I2C pins
[hackover2013-badge-firmware.git] / drivers / displays / bitmap / ssd1306 / ssd1306.h
1 /**************************************************************************/
2 /*!
3 @file ssd1306.h
4 @author K. Townsend (microBuilder.eu)
5 @date 18 January 2012
6 @version 0.10
7
8 @section LICENSE
9
10 Software License Agreement (BSD License)
11
12 Copyright (c) 2012, microBuilder SARL
13 All rights reserved.
14
15 Redistribution and use in source and binary forms, with or without
16 modification, are permitted provided that the following conditions are met:
17 1. Redistributions of source code must retain the above copyright
18 notice, this list of conditions and the following disclaimer.
19 2. Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the distribution.
22 3. Neither the name of the copyright holders nor the
23 names of its contributors may be used to endorse or promote products
24 derived from this software without specific prior written permission.
25
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
27 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
30 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
33 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37 /**************************************************************************/
38 #ifndef __SSD1306_H__
39 #define __SSD1306_H__
40
41 #include "projectconfig.h"
42
43 #include "drivers/displays/smallfonts.h"
44
45 /*=========================================================================
46 Bus Select
47 -----------------------------------------------------------------------
48 The SSD1306 can be driven using either SPI or I2C. Select the
49 appropriate bus below to indicate which one you wish to use.
50
51 SSD1306_BUS_SPI Use bit-banged SPI
52
53 SSD1306_BUS_I2C Use HW I2C
54
55 -----------------------------------------------------------------------*/
56 // #define SSD1306_BUS_SPI
57 #define SSD1306_BUS_I2C
58
59 #if defined SSD1306_BUS_SPI && defined SSD1306_BUS_I2C
60 #error "Only one SSD1306 bus interface can be specified at once in ssd1306.h"
61 #endif
62 #if !defined SSD1306_BUS_SPI && !defined SSD1306_BUS_I2C
63 #error "At least one SSD1306 bus interface must be specified in ssd1306.h"
64 #endif
65 /*=========================================================================*/
66
67
68 #if defined SSD1306_BUS_I2C
69 /*=========================================================================
70 I2C Address - 011110+SA0+RW ... 0x78 for SA0 = 0, 0x7A for SA0 = 1
71 ---------------------------------------------------------------------*/
72 #define SSD1306_I2C_ADDRESS (0x78)
73 #define SSD1306_I2C_READWRITE (0x01)
74 /*=========================================================================*/
75 #endif
76
77 /*=========================================================================
78 Display Size
79 -----------------------------------------------------------------------
80 The driver is used in multiple displays (128x64, 128x32, etc.).
81 Select the appropriate display below to create an appropriately
82 sized framebuffer, etc.
83
84 SSD1306_128_64 128x64 pixel display
85
86 SSD1306_128_32 128x32 pixel display
87
88 You also need to set the LCDWIDTH and LCDHEIGHT defines to an
89 appropriate size
90
91 -----------------------------------------------------------------------*/
92 #define SSD1306_128_64
93 // #define SSD1306_128_32
94
95 #if defined SSD1306_128_64 && defined SSD1306_128_32
96 #error "Only one SSD1306 display can be specified at once in ssd1306.h"
97 #endif
98 #if !defined SSD1306_128_64 && !defined SSD1306_128_32
99 #error "At least one SSD1306 display must be specified in ssd1306.h"
100 #endif
101
102 #if defined SSD1306_128_64
103 #define SSD1306_LCDWIDTH 128
104 #define SSD1306_LCDHEIGHT 64
105 #endif
106 #if defined SSD1306_128_32
107 #define SSD1306_LCDWIDTH 128
108 #define SSD1306_LCDHEIGHT 32
109 #endif
110 /*=========================================================================*/
111
112
113 // Pin Definitions
114 // ---------------
115 // The following are only relevant for SPI mode!
116 // For I2C, connect Reset to the LPC1114 reset pin, and HW DC for 1 or 0
117 // to set last I2C address but to 1 or 0. This means the OLED can not
118 // be reset in SW seperate from the MCU, but allows the OLED to be used
119 // with only the two I2C pins
120
121 #define SSD1306_DC_PORT (2) // Data/Command ... also used as SA0 for I2C
122 #define SSD1306_DC_PIN (1)
123 #define SSD1306_RST_PORT (2) // Reset
124 #define SSD1306_RST_PIN (2)
125 #define SSD1306_CS_PORT (2) // Select
126 #define SSD1306_CS_PIN (3)
127 #define SSD1306_SCLK_PORT (2) // Serial Clock
128 #define SSD1306_SCLK_PIN (5)
129 #define SSD1306_SDAT_PORT (2) // Serial Data
130 #define SSD1306_SDAT_PIN (6)
131
132 // Commands
133 #define SSD1306_SETCONTRAST 0x81
134 #define SSD1306_DISPLAYALLON_RESUME 0xA4
135 #define SSD1306_DISPLAYALLON 0xA5
136 #define SSD1306_NORMALDISPLAY 0xA6
137 #define SSD1306_INVERTDISPLAY 0xA7
138 #define SSD1306_DISPLAYOFF 0xAE
139 #define SSD1306_DISPLAYON 0xAF
140 #define SSD1306_SETDISPLAYOFFSET 0xD3
141 #define SSD1306_SETCOMPINS 0xDA
142 #define SSD1306_SETVCOMDETECT 0xDB
143 #define SSD1306_SETDISPLAYCLOCKDIV 0xD5
144 #define SSD1306_SETPRECHARGE 0xD9
145 #define SSD1306_SETMULTIPLEX 0xA8
146 #define SSD1306_SETLOWCOLUMN 0x00
147 #define SSD1306_SETHIGHCOLUMN 0x10
148 #define SSD1306_SETSTARTLINE 0x40
149 #define SSD1306_MEMORYMODE 0x20
150 #define SSD1306_COMSCANINC 0xC0
151 #define SSD1306_COMSCANDEC 0xC8
152 #define SSD1306_SEGREMAP 0xA0
153 #define SSD1306_CHARGEPUMP 0x8D
154 #define SSD1306_EXTERNALVCC 0x1
155 #define SSD1306_INTERNALVCC 0x2
156 #define SSD1306_SWITCHCAPVCC 0x2
157
158 // Initialisation/Config Prototypes
159 void ssd1306Init ( uint8_t vccstate );
160 void ssd1306DrawPixel ( uint8_t x, uint8_t y );
161 void ssd1306ClearPixel ( uint8_t x, uint8_t y );
162 uint8_t ssd1306GetPixel ( uint8_t x, uint8_t y );
163 void ssd1306ClearScreen ( void );
164 void ssd1306Refresh ( void );
165 void ssd1306DrawString( uint16_t x, uint16_t y, char* text, struct FONT_DEF font );
166 void ssd1306ShiftFrameBuffer( uint8_t height );
167
168 #endif
This page took 0.078987 seconds and 5 git commands to generate.