Adafruit_GrayOLED.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*!
  2. * @file Adafruit_GrayOLED.h
  3. *
  4. * This is part of for Adafruit's GFX library, supplying generic support
  5. * for grayscale 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_GRAYOLED_H_
  24. #define _Adafruit_GRAYOLED_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 GRAYOLED_SETCONTRAST 0x81 ///< Generic contrast for almost all OLEDs
  32. #define GRAYOLED_NORMALDISPLAY 0xA6 ///< Generic non-invert for almost all OLEDs
  33. #define GRAYOLED_INVERTDISPLAY 0xA7 ///< Generic invert for almost all OLEDs
  34. #define MONOOLED_BLACK 0 ///< Default black 'color' for monochrome OLEDS
  35. #define MONOOLED_WHITE 1 ///< Default white 'color' for monochrome OLEDS
  36. #define MONOOLED_INVERSE 2 ///< Default inversion command for monochrome OLEDS
  37. /*!
  38. @brief Class that stores state and functions for interacting with
  39. generic grayscale OLED displays.
  40. */
  41. class Adafruit_GrayOLED : public Adafruit_GFX {
  42. public:
  43. Adafruit_GrayOLED(uint8_t bpp, uint16_t w, uint16_t h, TwoWire *twi = &Wire,
  44. int8_t rst_pin = -1, uint32_t preclk = 400000,
  45. uint32_t postclk = 100000);
  46. Adafruit_GrayOLED(uint8_t bpp, uint16_t w, uint16_t h, int8_t mosi_pin,
  47. int8_t sclk_pin, int8_t dc_pin, int8_t rst_pin,
  48. int8_t cs_pin);
  49. Adafruit_GrayOLED(uint8_t bpp, uint16_t w, uint16_t h, SPIClass *spi,
  50. int8_t dc_pin, int8_t rst_pin, int8_t cs_pin,
  51. uint32_t bitrate = 8000000UL);
  52. ~Adafruit_GrayOLED(void);
  53. /**
  54. @brief The function that sub-classes define that writes out the buffer to
  55. the display over I2C or SPI
  56. **/
  57. virtual void display(void) = 0;
  58. void clearDisplay(void);
  59. void invertDisplay(bool i);
  60. void setContrast(uint8_t contrastlevel);
  61. void drawPixel(int16_t x, int16_t y, uint16_t color);
  62. bool getPixel(int16_t x, int16_t y);
  63. uint8_t *getBuffer(void);
  64. void oled_command(uint8_t c);
  65. bool oled_commandList(const uint8_t *c, uint8_t n);
  66. protected:
  67. bool _init(uint8_t i2caddr = 0x3C, bool reset = true);
  68. Adafruit_SPIDevice *spi_dev = NULL; ///< The SPI interface BusIO device
  69. Adafruit_I2CDevice *i2c_dev = NULL; ///< The I2C interface BusIO device
  70. int32_t i2c_preclk = 400000, ///< Configurable 'high speed' I2C rate
  71. i2c_postclk = 100000; ///< Configurable 'low speed' I2C rate
  72. uint8_t *buffer = NULL; ///< Internal 1:1 framebuffer of display mem
  73. int16_t window_x1, ///< Dirty tracking window minimum x
  74. window_y1, ///< Dirty tracking window minimum y
  75. window_x2, ///< Dirty tracking window maximum x
  76. window_y2; ///< Dirty tracking window maximum y
  77. int dcPin, ///< The Arduino pin connected to D/C (for SPI)
  78. csPin, ///< The Arduino pin connected to CS (for SPI)
  79. rstPin; ///< The Arduino pin connected to reset (-1 if unused)
  80. uint8_t _bpp = 1; ///< Bits per pixel color for this display
  81. private:
  82. TwoWire *_theWire = NULL; ///< The underlying hardware I2C
  83. };
  84. #endif // end __AVR_ATtiny85__
  85. #endif // _Adafruit_GrayOLED_H_