Senzory 1.0
oled.h
Go to the documentation of this file.
1/*
2 * This file is part of lcd library for ssd1306/ssd1309/sh1106 oled-display.
3 *
4 * lcd library for ssd1306/ssd1309/sh1106 oled-display is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or any later version.
7 *
8 * lcd library for ssd1306/ssd1309/sh1106 oled-display is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Diese Datei ist Teil von lcd library for ssd1306/ssd1309/sh1106 oled-display.
17 *
18 * lcd library for ssd1306/ssd1309/sh1106 oled-display ist Freie Software: Sie können es unter den Bedingungen
19 * der GNU General Public License, wie von der Free Software Foundation,
20 * Version 3 der Lizenz oder jeder späteren
21 * veröffentlichten Version, weiterverbreiten und/oder modifizieren.
22 *
23 * lcd library for ssd1306/ssd1309/sh1106 oled-display wird in der Hoffnung, dass es nützlich sein wird, aber
24 * OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
25 * Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
26 * Siehe die GNU General Public License für weitere Details.
27 *
28 * Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
29 * Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
30 *
31 * lcd.h
32 *
33 * Created by Michael Köhler on 22.12.16.
34 * Copyright 2016 Skie-Systems. All rights reserved.
35 *
36 * lib for OLED-Display with ssd1306/ssd1309/sh1106-Controller
37 * first dev-version only for I2C-Connection
38 * at ATMega328P like Arduino Uno
39 *
40 * at GRAPHICMODE lib needs SRAM for display
41 * DISPLAY-WIDTH * DISPLAY-HEIGHT + 2 bytes
42 */
43
44
58
59
60#ifndef OLED_H
61#define OLED_H
62
63#ifdef __cplusplus
64extern "C" {
65#endif
66
67#if (__GNUC__ * 100 + __GNUC_MINOR__) < 303
68# error "This library requires AVR-GCC 3.3 or later, update to newer AVR-GCC compiler !"
69#endif
70
71#include <inttypes.h>
72#include <avr/pgmspace.h>
73
74 /* TODO: define bus */
75#define I2C // I2C or SPI
76 /* TODO: define displaycontroller */
77#define SH1106 // or SSD1306, check datasheet of your display
78 /* TODO: define displaymode */
79#define GRAPHICMODE // for text and graphic
80 // TEXTMODE // for only text to display,
81 /* TODO: define font */
82#define FONT ssd1306oled_font // Refer font-name at font.h
83
84 // using 7-bit-adress for lcd-library
85 // if you use your own library for twi check I2C-adress-handle
86#define OLED_I2C_ADR (0x3c) // 7 bit slave-adress without r/w-bit
87 // e.g. 8 bit slave-adress:
88 // 0x78 = adress 0x3C with cleared r/w-bit (write-mode)
89
90
91#ifdef I2C
92// # include "i2c.h"
93# include "twi.h"
94#elif defined SPI
95// If you want to use your other lib/function for SPI replace SPI-commands
96# define OLED_PORT PORTB
97# define OLED_DDR DDRB
98# define RES_PIN PB0
99# define DC_PIN PB1
100# define CS_PIN PB2
101#endif
102
103#ifndef YES
104# define YES 1
105#endif
106
107#define NORMALSIZE 1
108#define DOUBLESIZE 2
109
110#define OLED_DISP_OFF 0xAE
111#define OLED_DISP_ON 0xAF
112
113#define WHITE 0x01
114#define BLACK 0x00
115
116#define DISPLAY_WIDTH 128
117#define DISPLAY_HEIGHT 64
118
119// Transmit command or data to display
120void oled_command(uint8_t cmd[], uint8_t size);
121void oled_data(uint8_t data[], uint16_t size);
122void oled_init(uint8_t dispAttr);
123void oled_home(void); // set cursor to 0,0
124void oled_invert(uint8_t invert); // invert display
125void oled_sleep(uint8_t sleep); // display goto sleep (power off)
126void oled_set_contrast(uint8_t contrast); // set contrast for display
127void oled_puts(const char* s); // print string, \n-terminated, from ram on screen (TEXTMODE)
128 // or buffer (GRAPHICMODE)
129void oled_puts_p(const char* progmem_s); // print string from flash on screen (TEXTMODE)
130// or buffer (GRAPHICMODE)
131
132void oled_clrscr(void); // clear screen (and buffer at GRFAICMODE)
133void oled_gotoxy(uint8_t x, uint8_t y); // set curser at pos x, y. x means character,
134// y means line (page, refer lcd manual)
135void oled_goto_xpix_y(uint8_t x, uint8_t y); // set curser at pos x, y. x means pixel,
136// y means line (page, refer lcd manual)
137void oled_putc(char c); // print character on screen at TEXTMODE
138// at GRAPHICMODE print character to buffer
139void oled_charMode(uint8_t mode); // set size of chars
140void oled_flip(uint8_t flipping); // flip display,
141 // flipping == 0: no flip (normal mode)
142 // == 1: flip horizontal & vertical
143 // == 2: flip(mirrored) vertical
144 // == 3: flip(mirrored) horizontal
145#if defined GRAPHICMODE
146 uint8_t oled_drawPixel(uint8_t x, uint8_t y, uint8_t color);
147 uint8_t oled_drawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t color);
148 uint8_t oled_drawRect(uint8_t px1, uint8_t py1, uint8_t px2, uint8_t py2, uint8_t color);
149 uint8_t oled_fillRect(uint8_t px1, uint8_t py1, uint8_t px2, uint8_t py2, uint8_t color);
150 uint8_t oled_drawCircle(uint8_t center_x, uint8_t center_y, uint8_t radius, uint8_t color);
151 uint8_t oled_fillCircle(uint8_t center_x, uint8_t center_y, uint8_t radius, uint8_t color);
152 uint8_t oled_drawBitmap(uint8_t x, uint8_t y, const uint8_t picture[], uint8_t width, uint8_t height, uint8_t color);
153 void oled_display(void); // copy buffer to display RAM
154 void oled_clear_buffer(void); // clear display buffer
155 uint8_t oled_check_buffer(uint8_t x, uint8_t y); // read a pixel value from the display buffer
156 void oled_display_block(uint8_t x, uint8_t line, uint8_t width); // display (part of) a display line
157#endif
158
159#ifdef __cplusplus
160}
161#endif
162
163#endif /* OLED_H */