Update oXs_out_frsky.cpp
[openXsensor.git] / locator_receiver / SSD1306AsciiAvrI2c.h
blob1d9a67174e63139b8786861b33a312207ff38b34
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 SSD1306AsciiAvrI2c.h
22 * @brief Class for I2C displays using AvrI2c.
24 #ifndef SSD1306AsciiAvrI2c_h
25 #define SSD1306AsciiAvrI2c_h
26 #include "utility/AvrI2c.h"
27 #include "SSD1306Ascii.h"
28 /**
29 * @class SSD1306AsciiAvrI2c
30 * @brief Class for I2C displays on AVR.
32 * Uses the AvrI2c class that is smaller and faster than the
33 * Wire library.
35 class SSD1306AsciiAvrI2c : public SSD1306Ascii {
36 public:
37 /**
38 * @brief Initialize the display controller.
40 * @param[in] dev A device initialization structure.
41 * @param[in] i2cAddr The I2C address of the display controller.
43 void begin(const DevType* dev, uint8_t i2cAddr) {
44 m_nData = 0;
45 m_i2cAddr = i2cAddr;
47 m_i2c.begin(AVRI2C_FASTMODE);
48 init(dev);
50 /**
51 * @brief Initialize the display controller.
53 * @param[in] dev A device initialization structure.
54 * @param[in] i2cAddr The I2C address of the display controller.
55 * @param[in] rst The display controller reset pin.
57 void begin(const DevType* dev, uint8_t i2cAddr, uint8_t rst) {
58 oledReset(rst);
59 begin(dev, i2cAddr);
61 /**
62 * @brief Set the I2C bit rate.
64 * @param[in] frequency Desired frequency in Hz.
65 * Valid range for a 16 MHz board is about 40 kHz to 444,000 kHz.
67 void setI2cClock(uint32_t frequency) {m_i2c.setClock(frequency);}
69 protected:
70 void writeDisplay(uint8_t b, uint8_t mode) {
71 if ((m_nData && mode == SSD1306_MODE_CMD)) {
72 m_i2c.stop();
73 m_nData = 0;
75 if (m_nData == 0) {
76 m_i2c.start((m_i2cAddr << 1) | I2C_WRITE);
77 m_i2c.write(mode == SSD1306_MODE_CMD ? 0X00 : 0X40);
79 m_i2c.write(b);
80 if (mode == SSD1306_MODE_RAM_BUF) {
81 m_nData++;
82 } else {
83 m_i2c.stop();
84 m_nData = 0;
88 protected:
89 AvrI2c m_i2c;
90 uint8_t m_i2cAddr;
91 uint8_t m_nData;
93 #endif // SSD1306AsciiAvrI2c_h