Rev 2 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2 | Rev 3 | ||
|---|---|---|---|
| Line 14... | Line 14... | ||
| 14 | Written by Limor Fried/Ladyada for Adafruit Industries. |
14 | Written by Limor Fried/Ladyada for Adafruit Industries. |
| 15 | BSD license, check license.txt for more information |
15 | BSD license, check license.txt for more information |
| 16 | All text above, and the splash screen must be included in any redistribution |
16 | All text above, and the splash screen must be included in any redistribution |
| 17 | *********************************************************************/ |
17 | *********************************************************************/ |
| 18 | 18 | ||
| - | 19 | #include "ssd1306_config.h" |
|
| 19 | 20 | ||
| 20 | typedef uint8_t boolean; |
21 | typedef uint8_t boolean; |
| 21 | static const boolean true = 1; |
22 | static const boolean true = 1; |
| 22 | static const boolean false = 0; |
23 | static const boolean false = 0; |
| 23 | 24 | ||
| Line 25... | Line 26... | ||
| 25 | #define WHITE 1 |
26 | #define WHITE 1 |
| 26 | #define INVERT 2 |
27 | #define INVERT 2 |
| 27 | 28 | ||
| 28 | // this driver can cope with more than one physical display of the same type. |
29 | // this driver can cope with more than one physical display of the same type. |
| 29 | 30 | ||
| 30 | #define MAX_PHYS_DISPLAYS 2 |
31 | #define MAX_PHYS_DISPLAYS 1 |
| - | 32 | ||
| - | 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); |
|
| 31 | 42 | ||
| 32 | /*========================================================================= |
43 | /*========================================================================= |
| 33 | SSD1306 Displays |
44 | SSD1306 Displays |
| 34 | ----------------------------------------------------------------------- |
45 | ----------------------------------------------------------------------- |
| 35 | The driver is used in multiple displays (128x64, 128x32, etc.). |
46 | The driver is used in multiple displays (128x64, 128x32, etc.). |
| Line 39... | Line 50... | ||
| 39 | SSD1306_128_64 128x64 pixel display |
50 | SSD1306_128_64 128x64 pixel display |
| 40 | 51 | ||
| 41 | SSD1306_128_32 128x32 pixel display |
52 | SSD1306_128_32 128x32 pixel display |
| 42 | 53 | ||
| 43 | -----------------------------------------------------------------------*/ |
54 | -----------------------------------------------------------------------*/ |
| 44 | #define SSD1306_128_64 |
- | |
| 45 | /*=========================================================================*/ |
55 | /*=========================================================================*/ |
| 46 | 56 | ||
| 47 | #if defined SSD1306_128_64 && defined SSD1306_128_32 |
- | |
| 48 | #error "Only one SSD1306 display can be specified at once in SSD1306.h" |
- | |
| 49 | #endif |
- | |
| 50 | #if !defined SSD1306_128_64 && !defined SSD1306_128_32 |
- | |
| 51 | #error "At least one SSD1306 display must be specified in SSD1306.h" |
- | |
| 52 | #endif |
- | |
| 53 | 57 | ||
| - | 58 | // the 1106 has a RAM width of 128 |
|
| 54 | #if defined SSD1306_128_64 |
59 | #if defined SSD1306_128_64 |
| 55 | #define SSD1306_LCDWIDTH 128 |
60 | #define SSD1306_LCDWIDTH 128 |
| 56 | #define SSD1306_LCDHEIGHT 64 |
61 | #define SSD1306_LCDHEIGHT 64 |
| 57 | #endif |
62 | #define SSD1306_RAMWIDTH 128 |
| 58 | #if defined SSD1306_128_32 |
63 | #elif defined SSD1306_128_32 |
| 59 | #define SSD1306_LCDWIDTH 128 |
64 | #define SSD1306_LCDWIDTH 128 |
| 60 | #define SSD1306_LCDHEIGHT 32 |
65 | #define SSD1306_LCDHEIGHT 32 |
| - | 66 | #define SSD1306_RAMWIDTH 128 |
|
| - | 67 | #elif defined SSD1306_132_64 |
|
| - | 68 | #define SSD1306_LCDWIDTH 128 |
|
| - | 69 | #define SSD1306_LCDHEIGHT 64 |
|
| - | 70 | #define SSD1306_RAMWIDTH 132 |
|
| - | 71 | #else |
|
| - | 72 | #error "At least one SSD1306 display must be specified in SSD1306.h" |
|
| 61 | #endif |
73 | #endif |
| 62 | 74 | ||
| 63 | #define SSD1306_SETCONTRAST 0x81 |
75 | #define SSD1306_SETCONTRAST 0x81 |
| 64 | #define SSD1306_DISPLAYALLON_RESUME 0xA4 |
76 | #define SSD1306_DISPLAYALLON_RESUME 0xA4 |
| 65 | #define SSD1306_DISPLAYALLON 0xA5 |
77 | #define SSD1306_DISPLAYALLON 0xA5 |
| Line 107... | Line 119... | ||
| 107 | #define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A |
119 | #define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A |
| 108 | 120 | ||
| 109 | 121 | ||
| 110 | extern const uint16_t WIDTH; |
122 | extern const uint16_t WIDTH; |
| 111 | extern const uint16_t HEIGHT; |
123 | extern const uint16_t HEIGHT; |
| 112 | extern uint8_t display_buffer[MAX_PHYS_DISPLAYS][SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8]; |
124 | extern uint8_t display_buffer[]; |
| 113 | 125 | ||
| 114 | extern uint8_t getRotation(void); |
126 | extern uint8_t getRotation(void); |
| 115 | extern int16_t width(void); |
127 | extern int16_t width(void); |
| 116 | extern int16_t height(void); |
128 | extern int16_t height(void); |
| 117 | 129 | ||
| 118 | extern void fastSPIwrite(uint8_t d); |
- | |
| 119 | - | ||
| 120 | 130 | ||
| 121 | /* stolen from AdaFruit class and converted to C */ |
131 | /* stolen from AdaFruit class and converted to C */ |
| 122 | void ssd1306_begin(uint8_t vccstate, uint8_t i2caddr); |
132 | void ssd1306_begin(uint8_t vccstate, uint8_t i2caddr); |
| 123 | extern void ssd1306_command(uint8_t c); |
- | |
| 124 | extern void ssd1306_data(uint8_t c); |
- | |
| 125 | 133 | ||
| 126 | extern void clearDisplay(void); |
134 | extern void clearDisplay(void); |
| 127 | extern void invertDisplay(uint8_t i); |
135 | extern void invertDisplay(uint8_t i); |
| 128 | extern void display(); |
136 | extern void display(); |
| 129 | 137 | ||
| Line 136... | Line 144... | ||
| 136 | 144 | ||
| 137 | extern void dim(uint8_t contrast); |
145 | extern void dim(uint8_t contrast); |
| 138 | 146 | ||
| 139 | extern void drawPixel(int16_t x, int16_t y, uint16_t color); |
147 | extern void drawPixel(int16_t x, int16_t y, uint16_t color); |
| 140 | 148 | ||
| 141 | void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); |
- | |
| 142 | void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); |
- | |
| 143 | - | ||
| 144 | - | ||
| 145 | inline void drawFastVLineInternal(int16_t x, int16_t y, int16_t h, uint16_t color) __attribute__((always_inline)); |
- | |
| 146 | inline void drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t color) __attribute__((always_inline)); |
- | |
| 147 | - | ||
| 148 | - | ||
| 149 | extern void drawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); |
149 | extern void drawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color); |
| 150 | 150 | ||
| 151 | - | ||
| 152 | extern void select_display(int i) ; // select physical display [i] |
151 | extern void select_display(int i) ; // select physical display [i] |
| 153 | 152 | ||
| 154 | extern inline uint8_t * display_address(void) ; |
153 | extern inline uint8_t * display_address(void) ; |