SSD1306 OLED display driver  1.3.1
This library is developed to control SSD1306 i2c/spi OLED display
ssd1306_i2c_wire.cpp
1 /*
2  Copyright (C) 2016-2017 Alexey Dynda
3 
4  This file is part of SSD1306 library.
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "ssd1306_i2c_wire.h"
21 #include "intf/ssd1306_interface.h"
22 #include "ssd1306_i2c_conf.h"
23 #include "ssd1306_i2c.h"
24 
25 #ifdef SSD1306_WIRE_SUPPORTED
26 
27 #include <Wire.h>
28 
29 static uint8_t s_bytesWritten = 0;
30 static uint8_t s_sa = SSD1306_SA;
31 
33 {
34  Wire.beginTransmission(s_sa);
35  s_bytesWritten = 0;
36 }
37 
39 {
40  Wire.endTransmission();
41 }
42 
43 void ssd1306_i2cConfigure_Wire(int8_t scl, int8_t sda)
44 {
45 #ifdef ESP8266
46  if ((scl>=0) && (sda >=0))
47  {
48  Wire.begin(sda, scl);
49  }
50  else
51 #endif
52  {
53  Wire.begin();
54  }
55  #ifdef SSD1306_WIRE_CLOCK_CONFIGURABLE
56  Wire.setClock(400000);
57  #endif
58 }
59 
64 void ssd1306_i2cSendByte_Wire(uint8_t data)
65 {
66  // Do not write too many bytes for standard Wire.h. It may become broken
67 #ifdef BUFFER_LENGTH
68  if (s_bytesWritten >= (BUFFER_LENGTH >> 1))
69 #else
70  if (s_bytesWritten >= (USI_BUF_SIZE -2))
71 #endif
72  {
75  /* Commands never require many bytes. Thus assume that user tries to send data */
76  Wire.write(0x40);
77  s_bytesWritten++;
78  }
79  Wire.write(data);
80  s_bytesWritten++;
81 }
82 
83 void ssd1306_i2cInit_Wire(uint8_t sa)
84 {
85  if (sa) s_sa = sa;
91 }
92 
93 #endif
94 
95 
void(* ssd1306_sendByte)(uint8_t data)
void ssd1306_i2cStop_Wire(void)
void(* ssd1306_dataStart)()
void(* ssd1306_endTransmission)()
void ssd1306_i2cCommandStart()
void ssd1306_i2cStart_Wire(void)
void ssd1306_i2cDataStart()
void ssd1306_i2cConfigure_Wire(int8_t scl, int8_t sda)
void(* ssd1306_startTransmission)()
void ssd1306_i2cInit_Wire(uint8_t sa)
void(* ssd1306_commandStart)()
void ssd1306_i2cSendByte_Wire(uint8_t data)
#define SSD1306_SA