UBlox M10 Support
[openXsensor.git] / locator_receiver / SSD1306AsciiWire.h
bloba1530fde847b05dff25ac75ec0c5edb07829b014
1 /* Arduino SSD1306Ascii Library
2 * Copyright (C) 2015 by William Greiman
4 * This file is part of the Arduino SSD1306Ascii Library
6 * This Library 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.
11 * This Library 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.
16 * You should have received a copy of the GNU General Public License
17 * along with the Arduino SSD1306Ascii Library. If not, see
18 * <http://www.gnu.org/licenses/>.
20 /**
21 * @file SSD1306AsciiWire.h
22 * @brief Class for I2C displays using Wire.
24 #ifndef SSD1306AsciiWire_h
25 #define SSD1306AsciiWire_h
26 #include <Wire.h>
27 #include "SSD1306Ascii.h"
28 /**
29 * @class SSD1306AsciiWire
30 * @brief Class for I2C displays using Wire.
32 class SSD1306AsciiWire : public SSD1306Ascii {
33 public:
34 /**
35 * @brief Initialize the display controller.
37 * @param[in] dev A device initialization structure.
38 * @param[in] i2cAddr The I2C address of the display controller.
40 void begin(const DevType* dev, uint8_t i2cAddr) {
41 #if OPTIMIZE_I2C
42 m_nData = 0;
43 #endif // OPTIMIZE_I2C
44 m_i2cAddr = i2cAddr;
45 init(dev);
47 /**
48 * @brief Initialize the display controller.
50 * @param[in] dev A device initialization structure.
51 * @param[in] i2cAddr The I2C address of the display controller.
52 * @param[in] rst The display controller reset pin.
54 void begin(const DevType* dev, uint8_t i2cAddr, uint8_t rst) {
55 oledReset(rst);
56 begin(dev, i2cAddr);
58 /**
59 * @brief Set the I2C clock rate to 400 kHz.
60 * Deprecated use Wire.setClock(400000L)
62 void set400kHz() __attribute__((deprecated("use Wire.setClock(400000L)"))) {
63 Wire.setClock(400000L);
66 protected:
67 void writeDisplay(uint8_t b, uint8_t mode) {
68 #if OPTIMIZE_I2C
69 if (m_nData > 16 || (m_nData && mode == SSD1306_MODE_CMD)) {
70 Wire.endTransmission();
71 m_nData = 0;
73 if (m_nData == 0) {
74 Wire.beginTransmission(m_i2cAddr);
75 Wire.write(mode == SSD1306_MODE_CMD ? 0X00 : 0X40);
77 Wire.write(b);
78 if (mode == SSD1306_MODE_RAM_BUF) {
79 m_nData++;
80 } else {
81 Wire.endTransmission();
82 m_nData = 0;
84 #else // OPTIMIZE_I2C
85 Wire.beginTransmission(m_i2cAddr);
86 Wire.write(mode == SSD1306_MODE_CMD ? 0X00: 0X40);
87 Wire.write(b);
88 Wire.endTransmission();
89 #endif // OPTIMIZE_I2C
92 protected:
93 uint8_t m_i2cAddr;
94 #if OPTIMIZE_I2C
95 uint8_t m_nData;
96 #endif // OPTIMIZE_I2C
98 #endif // SSD1306AsciiWire_h