SSD1306 OLED display driver  1.3.2
This library is developed to control SSD1306 i2c/spi OLED display
ssd1306_spi_hw.cpp
1 /*
2  Copyright (C) 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_spi_hw.h"
21 #include "ssd1306_spi.h"
22 
23 #include "intf/ssd1306_interface.h"
24 #include "ssd1306_spi_conf.h"
25 #include "lcd/lcd_common.h"
26 
27 #ifdef SSD1306_SPI_SUPPORTED
28 /* STANDARD branch */
29  #include <SPI.h>
30 
31 void ssd1306_spiConfigure_hw()
32 {
33  SPI.begin();
34 }
35 
36 
37 void ssd1306_spiInit_hw(int8_t cesPin, int8_t dcPin)
38 {
39  if (cesPin >=0) pinMode(cesPin, OUTPUT);
40  if (dcPin >= 0) pinMode(dcPin, OUTPUT);
41  if (cesPin) s_ssd1306_cs = cesPin;
42  if (dcPin) s_ssd1306_dc = dcPin;
43  ssd1306_startTransmission = ssd1306_spiStart_hw;
44  ssd1306_endTransmission = ssd1306_spiStop_hw;
45  ssd1306_sendByte = ssd1306_spiSendByte_hw;
48 }
49 
50 void ssd1306_spiStart_hw()
51 {
52  SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
53  if (s_ssd1306_cs >= 0)
54  {
55  digitalWrite(s_ssd1306_cs,LOW);
56  }
57 }
58 
59 void ssd1306_spiStop_hw()
60 {
61  if (s_ssd1306_cs >= 0)
62  {
63  digitalWrite(s_ssd1306_cs, HIGH);
64  }
66  {
67  digitalWrite(s_ssd1306_dc, LOW);
68  SPI.transfer( 0x00 ); // Send NOP command to allow last data byte to pass (bug in PCD8544?)
69  // ssd1306 E3h is NOP command
70  }
71  SPI.endTransaction();
72 }
73 
74 void ssd1306_spiSendByte_hw(uint8_t data)
75 {
76  SPI.transfer(data);
77 }
78 
79 #endif
80 
81 
void(* ssd1306_sendByte)(uint8_t data)
void(* ssd1306_dataStart)()
void(* ssd1306_endTransmission)()
void ssd1306_spiDataStart()
Definition: ssd1306_spi.cpp:44
void(* ssd1306_startTransmission)()
int8_t s_ssd1306_cs
Definition: ssd1306_spi.cpp:27
void(* ssd1306_commandStart)()
uint8_t g_lcd_type
Definition: ssd1306.cpp:32
void ssd1306_spiCommandStart()
Definition: ssd1306_spi.cpp:38
int8_t s_ssd1306_dc
Definition: ssd1306_spi.cpp:28