2f4abf14764efe65102ef77844a00afd0292d044
[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 // Pin Definitions
113 #define SSD1306_DC_PORT (2) // Data/Command ... used for SA0 with I2C
114 #define SSD1306_DC_PIN (1)
115 #define SSD1306_RST_PORT (2) // Reset (I2C + SPI)
116 #define SSD1306_RST_PIN (2)
117 #define SSD1306_CS_PORT (2) // Select (SPI only)
118 #define SSD1306_CS_PIN (3)
119 #define SSD1306_SCLK_PORT (2) // Serial Clock (SPI only)
120 #define SSD1306_SCLK_PIN (5)
121 #define SSD1306_SDAT_PORT (2) // Serial Data (SPI only)
122 #define SSD1306_SDAT_PIN (6)
123
124 // Commands
125 #define SSD1306_SETCONTRAST 0x81
126 #define SSD1306_DISPLAYALLON_RESUME 0xA4
127 #define SSD1306_DISPLAYALLON 0xA5
128 #define SSD1306_NORMALDISPLAY 0xA6
129 #define SSD1306_INVERTDISPLAY 0xA7
130 #define SSD1306_DISPLAYOFF 0xAE
131 #define SSD1306_DISPLAYON 0xAF
132 #define SSD1306_SETDISPLAYOFFSET 0xD3
133 #define SSD1306_SETCOMPINS 0xDA
134 #define SSD1306_SETVCOMDETECT 0xDB
135 #define SSD1306_SETDISPLAYCLOCKDIV 0xD5
136 #define SSD1306_SETPRECHARGE 0xD9
137 #define SSD1306_SETMULTIPLEX 0xA8
138 #define SSD1306_SETLOWCOLUMN 0x00
139 #define SSD1306_SETHIGHCOLUMN 0x10
140 #define SSD1306_SETSTARTLINE 0x40
141 #define SSD1306_MEMORYMODE 0x20
142 #define SSD1306_COMSCANINC 0xC0
143 #define SSD1306_COMSCANDEC 0xC8
144 #define SSD1306_SEGREMAP 0xA0
145 #define SSD1306_CHARGEPUMP 0x8D
146 #define SSD1306_EXTERNALVCC 0x1
147 #define SSD1306_INTERNALVCC 0x2
148 #define SSD1306_SWITCHCAPVCC 0x2
149
150 // Initialisation/Config Prototypes
151 void ssd1306Init ( uint8_t vccstate );
152 void ssd1306DrawPixel ( uint8_t x, uint8_t y );
153 void ssd1306ClearPixel ( uint8_t x, uint8_t y );
154 uint8_t ssd1306GetPixel ( uint8_t x, uint8_t y );
155 void ssd1306ClearScreen ( void );
156 void ssd1306Refresh ( void );
157 void ssd1306DrawString( uint16_t x, uint16_t y, char* text, struct FONT_DEF font );
158 void ssd1306ShiftFrameBuffer( uint8_t height );
159
160 #endif
This page took 0.045972 seconds and 3 git commands to generate.