ssd1306xled 1.0.0
SSD1306/SSD1315/SSH1106 OLED driver for ATtiny85
Loading...
Searching...
No Matches
ssd1306xled.h
Go to the documentation of this file.
1
16#include <stdint.h>
17#include <Arduino.h>
18#include <util/delay.h>
19
20#ifndef SSD1306XLED_H
21#define SSD1306XLED_H
22
23#define _SSD1306XLED_TINY_INIT_SUPPORTED_
24#define _SSD1306XLED_INIT_VERTICAL_SUPPORTED_
25
26// ----------------------------------------------------------------------------
27// Hardware pin configuration
28// ----------------------------------------------------------------------------
29
40#ifndef SSD1306_SCL
41#define SSD1306_SCL PB2
42#endif
43
46#ifndef SSD1306_SDA
47#define SSD1306_SDA PB0
48#endif
49
52#ifndef SSD1306_SA
53#define SSD1306_SA 0X3C
54#endif
55
// end hw_config
57
58// USI register mappings (ATtiny85-specific)
59#define DDR_USI DDRB
60#define PORT_USI PORTB
61#define PIN_USI PINB
62#define PORT_USI_SDA PORTB0
63#define PORT_USI_SCL PORTB2
64#define PIN_USI_SDA PINB0
65#define PIN_USI_SCL PINB2
66#define DDR_USI_CL DDR_USI
67#define PORT_USI_CL PORT_USI
68#define PIN_USI_CL PIN_USI
69
70// I2C speed mode
71#define TWI_FAST_MODE
72
73#ifdef TWI_FAST_MODE // TWI FAST mode timing limits. SCL = 100-400kHz
74#define DELAY_T2TWI (_delay_us(2)) // >1.3us
75#define DELAY_T4TWI (_delay_us(1)) // >0.6us
76#else // TWI STANDARD mode timing limits. SCL <= 100kHz
77#define DELAY_T2TWI (_delay_us(5)) // >4.7us
78#define DELAY_T4TWI (_delay_us(4)) // >4.0us
79#endif
80
81#define TWI_NACK_BIT 0 // Bit position for (N)ACK bit.
82
83// USI shift register preloads
84const unsigned char USISR_8bit = 1<<USISIF | 1<<USIOIF | 1<<USIPF | 1<<USIDC | 0x0<<USICNT0;
85const unsigned char USISR_1bit = 1<<USISIF | 1<<USIOIF | 1<<USIPF | 1<<USIDC | 0xE<<USICNT0;
86
88#define SSD1306_COMMAND 0x00
90#define SSD1306_DATA 0x40
91
92// ----------------------------------------------------------------------------
93// Opt-out feature flags
94// ----------------------------------------------------------------------------
95
107#ifdef DOXYGEN
111#define SSD1306_NO_FONT_6X8
112
116#define SSD1306_NO_FONT_8X16
117
121#define SSD1306_NO_DRAW_BMP
122
127#define SSD1306_QUICK_BEGIN
128#endif
129
// end opt_out
131
132// ----------------------------------------------------------------------------
133
147{
148 public:
149 SSD1306Device(void);
150
158 void ssd1306_init(void);
159
168 void ssd1306_tiny_init(void);
169
179
189 void ssd1306_send_data_start(void);
190
195 void ssd1306_send_data_stop(void);
196
205 void ssd1306_send_byte(uint8_t byte);
206
217
222 void ssd1306_send_command_stop(void);
223
231 void ssd1306_send_command(uint8_t command);
232
239 void ssd1306_setpos(uint8_t x, uint8_t y);
240
249 void ssd1306_fillscreen(uint8_t fill);
250
263 void ssd1306_set_contrast(uint8_t value);
264
271 void ssd1306_display_off(void);
272
278 void ssd1306_display_on(void);
279
280#ifndef SSD1306_NO_FONT_6X8
289 void ssd1306_char_font6x8(char ch);
290
301 void ssd1306_string_font6x8(const char *s);
302#endif
303
304#ifndef SSD1306_NO_FONT_8X16
316 void ssd1306_string_f8x16(uint8_t x, uint8_t y, const char s[]);
317#endif
318
319#ifndef SSD1306_NO_DRAW_BMP
332 void ssd1306_draw_bmp(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, const uint8_t bitmap[]);
333#endif
334
357 void ssd1306_draw_bmp_px(uint8_t x, uint8_t y_px, uint8_t w, uint8_t h_pages, const uint8_t bitmap[]);
358
373 void ssd1306_clear_area_px(uint8_t x, uint8_t y_px, uint8_t w, uint8_t h_pages);
374
390 void ssd1306_draw_bmp_px_clipped(int16_t x, uint8_t y_px, uint8_t w, uint8_t h_pages, const uint8_t bitmap[]);
391
403 void ssd1306_clear_area_px_clipped(int16_t x, uint8_t y_px, uint8_t w, uint8_t h_pages);
404
434 void ssd1306_compose_bmp_px(uint8_t *buf, uint8_t buf_x, uint8_t buf_w,
435 int16_t sprite_x, uint8_t sprite_y_px,
436 uint8_t sprite_w, uint8_t sprite_h_pages,
437 const uint8_t bitmap[], uint8_t target_page);
438
450 void ssd1306_send_buf(uint8_t x, uint8_t page, const uint8_t *buf, uint8_t w);
451
452 private:
453 void I2CInit();
454 bool I2CStart(uint8_t address);
455 uint8_t I2CTransfer (uint8_t data);
456 void I2CStop (void);
457 bool I2CWrite(uint8_t data);
458 void begin();
459 void _ssd1306_start(uint8_t mode);
460 void _ssd1306_init_from(const uint8_t *seq, uint8_t len);
461};
462
463
475
476// ----------------------------------------------------------------------------
477
478#endif
Driver for SSD1306-family OLED displays over bit-banged I2C.
Definition ssd1306xled.h:147
void ssd1306_draw_bmp_px(uint8_t x, uint8_t y_px, uint8_t w, uint8_t h_pages, const uint8_t bitmap[])
Draw a bitmap at a pixel-level Y position.
Definition ssd1306xled.cpp:403
void ssd1306_init(void)
Initialize the display and clear the screen.
Definition ssd1306xled.cpp:241
void ssd1306_set_contrast(uint8_t value)
Set the display contrast (brightness).
Definition ssd1306xled.cpp:292
void ssd1306_send_command_stop(void)
End an I2C command transmission.
Definition ssd1306xled.cpp:261
void ssd1306_tiny_init(void)
Initialize the display without clearing the screen.
Definition ssd1306xled.cpp:247
void ssd1306_compose_bmp_px(uint8_t *buf, uint8_t buf_x, uint8_t buf_w, int16_t sprite_x, uint8_t sprite_y_px, uint8_t sprite_w, uint8_t sprite_h_pages, const uint8_t bitmap[], uint8_t target_page)
Composite one sprite into a page buffer using OR.
Definition ssd1306xled.cpp:554
SSD1306Device(void)
Definition ssd1306xled.cpp:79
void ssd1306_tiny_init_vertical(void)
Initialize the display in vertical addressing mode.
Definition ssd1306xled.cpp:252
void ssd1306_send_command_start(void)
Begin an I2C command transmission.
Definition ssd1306xled.cpp:257
void ssd1306_draw_bmp_px_clipped(int16_t x, uint8_t y_px, uint8_t w, uint8_t h_pages, const uint8_t bitmap[])
Draw a bitmap with signed X coordinate and automatic clipping.
Definition ssd1306xled.cpp:468
void ssd1306_setpos(uint8_t x, uint8_t y)
Move the write cursor to a given position.
Definition ssd1306xled.cpp:307
void ssd1306_clear_area_px_clipped(int16_t x, uint8_t y_px, uint8_t w, uint8_t h_pages)
Clear a sprite area with signed X clipping.
Definition ssd1306xled.cpp:521
void ssd1306_display_off(void)
Turn the display off (sleep mode).
Definition ssd1306xled.cpp:299
void ssd1306_send_data_stop(void)
End an I2C data transmission.
Definition ssd1306xled.cpp:279
void ssd1306_send_data_start(void)
Begin an I2C data transmission.
Definition ssd1306xled.cpp:275
void ssd1306_clear_area_px(uint8_t x, uint8_t y_px, uint8_t w, uint8_t h_pages)
Clear the area a pixel-positioned sprite occupies.
Definition ssd1306xled.cpp:444
void ssd1306_send_byte(uint8_t byte)
Send one raw byte over I2C.
Definition ssd1306xled.cpp:271
void ssd1306_display_on(void)
Turn the display on (wake from sleep).
Definition ssd1306xled.cpp:303
void ssd1306_send_buf(uint8_t x, uint8_t page, const uint8_t *buf, uint8_t w)
Send a pre-composited buffer to the display.
Definition ssd1306xled.cpp:592
void ssd1306_send_command(uint8_t command)
Send a single command byte (start + byte + stop).
Definition ssd1306xled.cpp:265
void ssd1306_fillscreen(uint8_t fill)
Fill the entire screen with a byte pattern.
Definition ssd1306xled.cpp:283
SSD1306Device SSD1306
Global driver instance.
Definition ssd1306xled.cpp:607
const unsigned char USISR_1bit
Definition ssd1306xled.h:85
const unsigned char USISR_8bit
Definition ssd1306xled.h:84