-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOLED_IO_SPI.hh
88 lines (79 loc) · 2.25 KB
/
OLED_IO_SPI.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* @file ?/OLED_IO_SPI.hh
* @version 0.1
*
* @section License
* Copyright (C) 2014-2015, jeditekunum
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*/
#ifndef COSA_X_OLED_IO_SPI_HH
#define COSA_X_OLED_IO_SPI_HH
#include "Cosa/SPI.hh"
#include "Cosa/OutputPin.hh"
#include "OLED_IO.hh"
/**
* IO handler for OLED Controller/Driver when using hardware SPI.
*/
class OLED_IO_SPI : public OLED_IO, public SPI::Driver {
public:
/**
* Construct SSD1306_Text 4-wire serial port connected to given
* enable/chip select pin and data/command pin. Uses the SPI::MOSI
* and SPI::SCK pins.
* @param[in] cs enable (cs) pulse.
* @param[in] dc data/command pin.
*/
#if defined(BOARD_ATTINYX4)
OLED_IO_SPI(Board::DigitalPin cs = Board::D3,
Board::DigitalPin dc = Board::D7) :
#elif defined(BOARD_ATTINYX5)
OLED_IO_SPI(Board::DigitalPin cs = Board::D3,
Board::DigitalPin dc = Board::D4) :
#else
OLED_IO_SPI(Board::DigitalPin cs = Board::D10,
Board::DigitalPin dc = Board::D9) :
#endif
SPI::Driver(cs, SPI::PULSE_HIGH),
m_dc(dc)
{
m_mode = INSTRUCTION;
}
/**
* @override OLED_IO_SPI
* Initiate port for 8-bit serial mode.
* @return true(1).
*/
virtual void setup();
/**
* @override OLED_IO_SPI
* Write byte (8bit) to display.
* @param[in] data (8b) to write.
*/
virtual void write8b(uint8_t data);
/**
* @override OLED_IO_SPI
* Write buffer to display.
* @param[in] buf pointer to buffer.
* @param[in] size number of bytes in buffer.
*/
virtual void write8n(void* buf, size_t size);
protected:
/** Execution time delay (us). */
#if !defined(BOARD_ATTINY)
static const uint16_t SHORT_EXEC_TIME = 24;
#else
static const uint16_t SHORT_EXEC_TIME = 8;
#endif
OutputPin m_dc;
};
#endif