Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: servo_sensor ArchPro_TFT BLE_Display SSD1306_demo ... more
Revision 12:7964c2cfdebc, committed 2014-10-21
- Comitter:
- nkhorman
- Date:
- Tue Oct 21 02:16:49 2014 +0000
- Parent:
- 10:d5aee2d2f8dd
- Parent:
- 11:86909e6db3c8
- Child:
- 13:8f03f908f22a
- Commit message:
- merge documentation
Changed in this revision
| Adafruit_SSD1306.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Adafruit_GFX.h Mon Oct 20 03:16:15 2014 +0000
+++ b/Adafruit_GFX.h Tue Oct 21 02:16:49 2014 +0000
@@ -41,6 +41,15 @@
#define BLACK 0
#define WHITE 1
+/**
+ * This is a Text and Graphics element drawing class.
+ * These functions draw to the display buffer.
+ *
+ * Display drivers should be derived from here.
+ * The Display drivers push the display buffer to the
+ * hardware based on application control.
+ *
+ */
class Adafruit_GFX : public Stream
{
public:
@@ -58,6 +67,7 @@
, wrap(true)
{};
+ /// Paint one BLACK or WHITE pixel in the display buffer
// this must be defined by the subclass
virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
// this is optional
@@ -70,43 +80,96 @@
#ifdef GFX_WANT_ABSTRACTS
// these are 'generic' drawing functions, so we can share them!
+
+ /** Draw a Horizontal Line
+ * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
+ */
virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
+ /** Draw a rectangle
+ * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
+ */
virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
+ /** Fill the entire display
+ * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
+ */
virtual void fillScreen(uint16_t color);
+ /** Draw a circle
+ * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
+ */
void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color);
+
+ /** Draw and fill a circle
+ * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
+ */
void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color);
+ /** Draw a triangle
+ * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
+ */
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
+ /** Draw and fill a triangle
+ * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
+ */
void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
+
+ /** Draw a rounded rectangle
+ * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
+ */
void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
+ /** Draw and fill a rounded rectangle
+ * @note GFX_WANT_ABSTRACTS must be defined in Adafruit_GFX_config.h
+ */
void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);
#endif
#if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT)
+ /** Draw a line
+ * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h
+ */
virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
+ /** Draw a vertical line
+ * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h
+ */
virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
+ /** Draw and fill a rectangle
+ * @note GFX_WANT_ABSTRACTS or GFX_SIZEABLE_TEXT must be defined in Adafruit_GFX_config.h
+ */
virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
#endif
+ /// Draw a bitmap
void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
+ /// Draw a text character at a specified pixel location
void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size);
+ /// Draw a text character at the text cursor location
size_t writeChar(uint8_t);
+ /// Get the width of the display in pixels
int16_t width(void) { return _width; };
+ /// Get the height of the display in pixels
int16_t height(void) { return _height; };
+ /// Set the text cursor location, based on the size of the text
void setTextCursor(int16_t x, int16_t y) { cursor_x = x; cursor_y = y; };
#if defined(GFX_SIZEABLE_TEXT)
+ /** Set the size of the text to be drawn
+ * @note Make sure to enable either GFX_SIZEABLE_TEXT or GFX_WANT_ABSTRACTS
+ */
void setTextSize(uint8_t s) { textsize = (s > 0) ? s : 1; };
#endif
+ /// Set the text foreground and background colors to be the same
void setTextColor(uint16_t c) { textcolor = c; textbgcolor = c; }
+ /// Set the text foreground and background colors independantly
void setTextColor(uint16_t c, uint16_t b) { textcolor = c; textbgcolor = b; };
+ /// Set text wraping mode true or false
void setTextWrap(bool w) { wrap = w; };
+ /// Set the display rotation, 1, 2, 3, or 4
void setRotation(uint8_t r);
+ /// Get the current rotation
uint8_t getRotation(void) { rotation %= 4; return rotation; };
protected:
--- a/Adafruit_SSD1306.cpp Mon Oct 20 03:16:15 2014 +0000 +++ b/Adafruit_SSD1306.cpp Tue Oct 21 02:16:49 2014 +0000 @@ -23,6 +23,9 @@ #include "mbed.h" #include "Adafruit_SSD1306.h" +/// Uncomment this define in __FILE to disable the AdaFruit splash image +//#define NO_SPLASH_ADAFRUIT + #define SSD1306_SETCONTRAST 0x81 #define SSD1306_DISPLAYALLON_RESUME 0xA4 #define SSD1306_DISPLAYALLON 0xA5
--- a/Adafruit_SSD1306.h Mon Oct 20 03:16:15 2014 +0000
+++ b/Adafruit_SSD1306.h Tue Oct 21 02:16:49 2014 +0000
@@ -42,6 +42,11 @@
#define SSD1306_EXTERNALVCC 0x1
#define SSD1306_SWITCHCAPVCC 0x2
+/** The pure base class for the SSD1306 display driver.
+ *
+ * You should derive from this for a new transport interface type,
+ * such as the SPI and I2C drivers.
+ */
class Adafruit_SSD1306 : public Adafruit_GFX
{
public:
@@ -53,16 +58,21 @@
};
void begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC);
+
+ // These must be implemented in the derived transport driver
virtual void command(uint8_t c) = 0;
virtual void data(uint8_t c) = 0;
-
+ virtual void drawPixel(int16_t x, int16_t y, uint16_t color);
+
+ /// Clear the display buffer
void clearDisplay(void);
virtual void invertDisplay(bool i);
+
+ /// Cause the display to be updated with the buffer content.
void display();
+ /// Fill the buffer with the AdaFruit splash screen.
virtual void splash();
- virtual void drawPixel(int16_t x, int16_t y, uint16_t color);
-
protected:
virtual void sendDisplayBuffer() = 0;
DigitalOut2 rst;
@@ -71,9 +81,25 @@
std::vector<uint8_t> buffer;
};
+
+/** This is the SPI SSD1306 display driver transport class
+ *
+ */
class Adafruit_SSD1306_Spi : public Adafruit_SSD1306
{
public:
+ /** Create a SSD1306 SPI transport display driver instance with the specified DC, RST, and CS pins, as well as the display dimentions
+ *
+ * Required parameters
+ * @param spi - a reference to an initialized SPI object
+ * @param DC (Data/Command) pin name
+ * @param RST (Reset) pin name
+ * @param CS (Chip Select) pin name
+ *
+ * Optional parameters
+ * @param rawHeight - the vertical number of pixels for the display, defaults to 32
+ * @param rawWidth - the horizonal number of pixels for the display, defaults to 128
+ */
Adafruit_SSD1306_Spi(SPI &spi, PinName DC, PinName RST, PinName CS, uint8_t rawHieght = 32, uint8_t rawWidth = 128)
: Adafruit_SSD1306(RST, rawHieght, rawWidth)
, cs(CS,true)
@@ -113,6 +139,12 @@
for(uint16_t i=0, q=buffer.size(); i<q; i++)
mspi.write(buffer[i]);
+ if(height() == 32)
+ {
+ for(uint16_t i=0, q=buffer.size(); i<q; i++)
+ mspi.write(0);
+ }
+
cs = 1;
};
@@ -120,10 +152,24 @@
SPI &mspi;
};
+/** This is the I2C SSD1306 display driver transport class
+ *
+ */
class Adafruit_SSD1306_I2c : public Adafruit_SSD1306
{
public:
#define SSD_I2C_ADDRESS 0x78
+ /** Create a SSD1306 I2C transport display driver instance with the specified RST pin name, the I2C address, as well as the display dimensions
+ *
+ * Required parameters
+ * @param i2c - A reference to an initialized I2C object
+ * @param RST - The Reset pin name
+ *
+ * Optional parameters
+ * @param i2cAddress - The i2c address of the display
+ * @param rawHeight - The vertical number of pixels for the display, defaults to 32
+ * @param rawWidth - The horizonal number of pixels for the display, defaults to 128
+ */
Adafruit_SSD1306_I2c(I2C &i2c, PinName RST, uint8_t i2cAddress = SSD_I2C_ADDRESS, uint8_t rawHeight = 32, uint8_t rawWidth = 128)
: Adafruit_SSD1306(RST, rawHeight, rawWidth)
, mi2c(i2c)
Adafruit / SSD1306 OLED 128x32 or 128x64