SparkFun SSD168x Library  v1.0.2
Library for SSD1680 / SSD1681 e-paper displays on SPI
Loading...
Searching...
No Matches
sfe_bus.h
Go to the documentation of this file.
1
29#pragma once
30
31#include "sfe_platform.h"
32
34{
35
42 {
43 public:
57 virtual bool writeCommand(uint8_t command, const uint8_t *data, uint16_t length) = 0;
58 };
59
60#if defined(SFE_SSD168X_ARDUINO)
61
65 const uint32_t kDefaultSpiClockHz = 4000000;
66
67 // The SfeSPI class defines behavior for SPI implementation based around the SPIClass class (SPI).
68 // This is Arduino specific.
69 class SfeSPI : public SSD168xDeviceBus
70 {
71 public:
75 SfeSPI(void);
76
84 bool init(int cs, int dc);
85
99 bool init(SPIClass &spiPort, SPISettings &spiSettings, int cs, int dc, bool bInit = false);
100
111 bool init(SPIClass &spiPort, uint32_t spiSpeed, int cs, int dc, bool bInit = false);
112
121 bool writeCommand(uint8_t command, const uint8_t *data, uint16_t length);
122
123 private:
124 SPIClass *_spiPort;
125 // Settings are used for every transaction.
126 SPISettings _sfeSPISettings;
127 int _cs;
128 int _dc;
129 };
130
131 // The sfePrint device defines behavior for Serial diagnostic prints based around the Print class.
132 // This is Arduino specific.
133 class SfePrint
134 {
135 public:
139 SfePrint(void) { _outputPort = nullptr; }
140
146 void init(Print &outputPort) { _outputPort = &outputPort; }
147
154 inline bool operator==(SfePrint const &other) const { return _outputPort == other._outputPort; }
155
162 inline bool operator!=(SfePrint const &other) const { return !(*this == other); }
163
169 void write(uint8_t c)
170 {
171 if (_outputPort != nullptr)
172 _outputPort->write(c);
173 }
179 void print(const char *c)
180 {
181 if (_outputPort != nullptr)
182 _outputPort->print(c);
183 }
189 void print(const __FlashStringHelper *c)
190 {
191 if (_outputPort != nullptr)
192 _outputPort->print(c);
193 }
199 void print(uint32_t c)
200 {
201 if (_outputPort != nullptr)
202 _outputPort->print(c);
203 }
210 void print(uint32_t c, int f)
211 {
212 if (_outputPort != nullptr)
213 _outputPort->print(c, f);
214 }
218 void println()
219 {
220 if (_outputPort != nullptr)
221 _outputPort->println();
222 }
228 void println(const char *c)
229 {
230 if (_outputPort != nullptr)
231 _outputPort->println(c);
232 }
238 void println(const __FlashStringHelper *c)
239 {
240 if (_outputPort != nullptr)
241 _outputPort->println(c);
242 }
248 void println(uint32_t c)
249 {
250 if (_outputPort != nullptr)
251 _outputPort->println(c);
252 }
259 void println(uint32_t c, int f)
260 {
261 if (_outputPort != nullptr)
262 _outputPort->println(c, f);
263 }
264
265 private:
266 Print *_outputPort;
267 };
268
269#endif // SFE_SSD168X_ARDUINO
270
271};
272
273#if defined(SFE_SSD168X_ARDUINO)
274// The type used by the public API for the debug output port: enableDebugging()
275namespace SparkFun_SSD168x
276{
277typedef Print sfe_print_t;
278} // namespace SparkFun_SSD168x
279#elif defined(SFE_SSD168X_ESP_IDF)
280// ESP-IDF bus class (SfeSPI), output ports (SfeOutput) and SfePrint
281#include "sfe_bus_esp_idf.h"
282#endif
The abstract hardware bus interface used by the SSD168x device classes.
Definition: sfe_bus.h:42
virtual bool writeCommand(uint8_t command, const uint8_t *data, uint16_t length)=0
Write a command byte, followed by zero or more data / parameter bytes, in a single CS# assertion.
Definition: sfe_bus.h:34