Adafruit_MonoOLED.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*!
  2. * @file Adafruit_MonoOLED.h
  3. *
  4. * This is part of for Adafruit's GFX library, supplying generic support
  5. * for monochrome OLED displays: http://www.adafruit.com/category/63_98
  6. *
  7. * These displays use I2C or SPI to communicate. I2C requires 2 pins
  8. * (SCL+SDA) and optionally a RESET pin. SPI requires 4 pins (MOSI, SCK,
  9. * select, data/command) and optionally a reset pin. Hardware SPI or
  10. * 'bitbang' software SPI are both supported.
  11. *
  12. * Adafruit invests time and resources providing this open source code,
  13. * please support Adafruit and open-source hardware by purchasing
  14. * products from Adafruit!
  15. *
  16. * Written by Limor Fried/Ladyada for Adafruit Industries, with
  17. * contributions from the open source community.
  18. *
  19. * BSD license, all text above, and the splash screen header file,
  20. * must be included in any redistribution.
  21. *
  22. */
  23. #ifndef _Adafruit_MONOOLED_H_
  24. #define _Adafruit_MONOOLED_H_
  25. #if !defined(__AVR_ATtiny85__) // Not for ATtiny, at all
  26. #include <Adafruit_GFX.h>
  27. #include <Adafruit_I2CDevice.h>
  28. #include <Adafruit_SPIDevice.h>
  29. #include <SPI.h>
  30. #include <Wire.h>
  31. #define MONOOLED_BLACK 0 ///< Draw 'off' pixels
  32. #define MONOOLED_WHITE 1 ///< Draw 'on' pixels
  33. #define MONOOLED_INVERSE 2 ///< Invert pixels
  34. /// These seem to be common commands for OLEDs
  35. #define MONOOLED_SETCONTRAST 0x81 ///< See datasheet
  36. #define MONOOLED_NORMALDISPLAY 0xA6 ///< See datasheet
  37. #define MONOOLED_INVERTDISPLAY 0xA7 ///< See datasheet
  38. #define MONOOLED_DISPLAYOFF 0xAE ///< See datasheet
  39. #define MONOOLED_DISPLAYON 0xAF ///< See datasheet
  40. /*!
  41. @brief Class that stores state and functions for interacting with
  42. generic monochrome OLED displays.
  43. */
  44. class Adafruit_MonoOLED : public Adafruit_GFX {
  45. public:
  46. Adafruit_MonoOLED(uint16_t w, uint16_t h, TwoWire *twi = &Wire,
  47. int8_t rst_pin = -1, uint32_t preclk = 400000,
  48. uint32_t postclk = 100000);
  49. Adafruit_MonoOLED(uint16_t w, uint16_t h, int8_t mosi_pin, int8_t sclk_pin,
  50. int8_t dc_pin, int8_t rst_pin, int8_t cs_pin);
  51. Adafruit_MonoOLED(uint16_t w, uint16_t h, SPIClass *spi, int8_t dc_pin,
  52. int8_t rst_pin, int8_t cs_pin,
  53. uint32_t bitrate = 8000000UL);
  54. ~Adafruit_MonoOLED(void);
  55. /**
  56. @brief The function that sub-classes define that writes out the buffer to
  57. the display over I2C or SPI
  58. **/
  59. virtual void display(void) = 0;
  60. void clearDisplay(void);
  61. void invertDisplay(bool i);
  62. void setContrast(uint8_t contrastlevel);
  63. void drawPixel(int16_t x, int16_t y, uint16_t color);
  64. bool getPixel(int16_t x, int16_t y);
  65. uint8_t *getBuffer(void);
  66. void oled_command(uint8_t c);
  67. bool oled_commandList(const uint8_t *c, uint8_t n);
  68. protected:
  69. bool _init(uint8_t i2caddr = 0x3C, bool reset = true);
  70. Adafruit_SPIDevice *spi_dev = NULL; ///< The SPI interface BusIO device
  71. Adafruit_I2CDevice *i2c_dev = NULL; ///< The I2C interface BusIO device
  72. int32_t i2c_preclk = 400000, ///< Configurable 'high speed' I2C rate
  73. i2c_postclk = 100000; ///< Configurable 'low speed' I2C rate
  74. uint8_t *buffer = NULL; ///< Internal 1:1 framebuffer of display mem
  75. int16_t window_x1, ///< Dirty tracking window minimum x
  76. window_y1, ///< Dirty tracking window minimum y
  77. window_x2, ///< Dirty tracking window maximum x
  78. window_y2; ///< Dirty tracking window maximum y
  79. int dcPin, ///< The Arduino pin connected to D/C (for SPI)
  80. csPin, ///< The Arduino pin connected to CS (for SPI)
  81. rstPin; ///< The Arduino pin connected to reset (-1 if unused)
  82. private:
  83. TwoWire *_theWire = NULL; ///< The underlying hardware I2C
  84. };
  85. #endif // end __AVR_ATtiny85__
  86. #endif // _Adafruit_MonoOLED_H_