A.I.Mergence / Adafruit_GFX_AIM
Committer:
evgeniik
Date:
Fri Jul 17 09:26:07 2020 +0000
Revision:
18:6fc8104e8548
Parent:
15:77feec1c0684
not changed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nkhorman 0:c3dcd4c4983a 1 /*********************************************************************
nkhorman 0:c3dcd4c4983a 2 This is a library for our Monochrome OLEDs based on SSD1306 drivers
nkhorman 0:c3dcd4c4983a 3
nkhorman 0:c3dcd4c4983a 4 Pick one up today in the adafruit shop!
nkhorman 0:c3dcd4c4983a 5 ------> http://www.adafruit.com/category/63_98
nkhorman 0:c3dcd4c4983a 6
nkhorman 0:c3dcd4c4983a 7 These displays use SPI to communicate, 4 or 5 pins are required to
nkhorman 0:c3dcd4c4983a 8 interface
nkhorman 0:c3dcd4c4983a 9
nkhorman 0:c3dcd4c4983a 10 Adafruit invests time and resources providing this open source code,
nkhorman 0:c3dcd4c4983a 11 please support Adafruit and open-source hardware by purchasing
nkhorman 0:c3dcd4c4983a 12 products from Adafruit!
nkhorman 0:c3dcd4c4983a 13
nkhorman 0:c3dcd4c4983a 14 Written by Limor Fried/Ladyada for Adafruit Industries.
nkhorman 0:c3dcd4c4983a 15 BSD license, check license.txt for more information
nkhorman 0:c3dcd4c4983a 16 All text above, and the splash screen must be included in any redistribution
nkhorman 0:c3dcd4c4983a 17 *********************************************************************/
nkhorman 0:c3dcd4c4983a 18
nkhorman 0:c3dcd4c4983a 19 /*
nkhorman 9:ddb97c9850a2 20 * Modified by Neal Horman 7/14/2012 for use in mbed
nkhorman 0:c3dcd4c4983a 21 */
nkhorman 0:c3dcd4c4983a 22
nkhorman 0:c3dcd4c4983a 23 #ifndef _ADAFRUIT_SSD1306_H_
nkhorman 0:c3dcd4c4983a 24 #define _ADAFRUIT_SSD1306_H_
nkhorman 0:c3dcd4c4983a 25
nkhorman 0:c3dcd4c4983a 26 #include "mbed.h"
nkhorman 0:c3dcd4c4983a 27 #include "Adafruit_GFX.h"
nkhorman 0:c3dcd4c4983a 28
nkhorman 9:ddb97c9850a2 29 #include <vector>
nkhorman 9:ddb97c9850a2 30 #include <algorithm>
nkhorman 0:c3dcd4c4983a 31
nkhorman 0:c3dcd4c4983a 32 #define SSD1306_EXTERNALVCC 0x1
nkhorman 0:c3dcd4c4983a 33 #define SSD1306_SWITCHCAPVCC 0x2
nkhorman 0:c3dcd4c4983a 34
nkhorman 11:86909e6db3c8 35 /** The pure base class for the SSD1306 display driver.
nkhorman 11:86909e6db3c8 36 *
nkhorman 11:86909e6db3c8 37 * You should derive from this for a new transport interface type,
nkhorman 11:86909e6db3c8 38 * such as the SPI and I2C drivers.
nkhorman 11:86909e6db3c8 39 */
nkhorman 0:c3dcd4c4983a 40 class Adafruit_SSD1306 : public Adafruit_GFX
nkhorman 0:c3dcd4c4983a 41 {
nkhorman 9:ddb97c9850a2 42 public:
evgeniik 18:6fc8104e8548 43 #define SSD_I2C_ADDRESS 0x78
evgeniik 18:6fc8104e8548 44 Adafruit_SSD1306(I2C &i2c, uint8_t i2cAddress = SSD_I2C_ADDRESS, uint8_t rawHeight = 64, uint8_t rawWidth = 128)
nkhorman 9:ddb97c9850a2 45 : Adafruit_GFX(rawWidth,rawHeight)
evgeniik 18:6fc8104e8548 46 , mi2c(i2c)
evgeniik 18:6fc8104e8548 47 , mi2cAddress(i2cAddress)
nkhorman 11:86909e6db3c8 48 {
nkhorman 11:86909e6db3c8 49 buffer.resize(rawHeight * rawWidth / 8);
evgeniik 18:6fc8104e8548 50 begin();
evgeniik 18:6fc8104e8548 51 //splash();
evgeniik 18:6fc8104e8548 52 //display();
nkhorman 11:86909e6db3c8 53 };
nkhorman 9:ddb97c9850a2 54
nkhorman 9:ddb97c9850a2 55 void begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC);
nkhorman 11:86909e6db3c8 56
nkhorman 11:86909e6db3c8 57 // These must be implemented in the derived transport driver
nkhorman 9:ddb97c9850a2 58 virtual void command(uint8_t c)
nkhorman 9:ddb97c9850a2 59 {
nkhorman 9:ddb97c9850a2 60 char buff[2];
nkhorman 9:ddb97c9850a2 61 buff[0] = 0; // Command Mode
nkhorman 9:ddb97c9850a2 62 buff[1] = c;
nkhorman 9:ddb97c9850a2 63 mi2c.write(mi2cAddress, buff, sizeof(buff));
nkhorman 9:ddb97c9850a2 64 }
nkhorman 9:ddb97c9850a2 65
nkhorman 9:ddb97c9850a2 66 virtual void data(uint8_t c)
nkhorman 9:ddb97c9850a2 67 {
nkhorman 9:ddb97c9850a2 68 char buff[2];
nkhorman 9:ddb97c9850a2 69 buff[0] = 0x40; // Data Mode
nkhorman 9:ddb97c9850a2 70 buff[1] = c;
nkhorman 9:ddb97c9850a2 71 mi2c.write(mi2cAddress, buff, sizeof(buff));
nkhorman 9:ddb97c9850a2 72 };
evgeniik 18:6fc8104e8548 73 virtual void drawPixel(int16_t x, int16_t y, uint16_t color);
nkhorman 9:ddb97c9850a2 74
evgeniik 18:6fc8104e8548 75 /// Clear the display buffer
evgeniik 18:6fc8104e8548 76 void clearDisplay(void);
evgeniik 18:6fc8104e8548 77 virtual void invertDisplay(bool i);
evgeniik 18:6fc8104e8548 78
evgeniik 18:6fc8104e8548 79 /// Cause the display to be updated with the buffer content.
evgeniik 18:6fc8104e8548 80 void display();
evgeniik 18:6fc8104e8548 81 /// Fill the buffer with the AdaFruit splash screen.
evgeniik 18:6fc8104e8548 82 virtual void splash();
evgeniik 18:6fc8104e8548 83 virtual void E4_logo();
evgeniik 18:6fc8104e8548 84 virtual void AI_logo();
evgeniik 18:6fc8104e8548 85
nkhorman 9:ddb97c9850a2 86 protected:
evgeniik 18:6fc8104e8548 87 std::vector<uint8_t> buffer;
nkhorman 9:ddb97c9850a2 88 virtual void sendDisplayBuffer()
nkhorman 9:ddb97c9850a2 89 {
nkhorman 9:ddb97c9850a2 90 char buff[17];
nkhorman 9:ddb97c9850a2 91 buff[0] = 0x40; // Data Mode
nkhorman 9:ddb97c9850a2 92
nkhorman 9:ddb97c9850a2 93 // send display buffer in 16 byte chunks
nkhorman 9:ddb97c9850a2 94 for(uint16_t i=0, q=buffer.size(); i<q; i+=16 )
nkhorman 9:ddb97c9850a2 95 { uint8_t x ;
nkhorman 9:ddb97c9850a2 96
nkhorman 9:ddb97c9850a2 97 // TODO - this will segfault if buffer.size() % 16 != 0
nkhorman 9:ddb97c9850a2 98 for(x=1; x<sizeof(buff); x++)
JojoS 15:77feec1c0684 99 buff[x] = buffer[i+x-1];
nkhorman 9:ddb97c9850a2 100 mi2c.write(mi2cAddress, buff, sizeof(buff));
nkhorman 9:ddb97c9850a2 101 }
nkhorman 9:ddb97c9850a2 102 };
evgeniik 18:6fc8104e8548 103
nkhorman 9:ddb97c9850a2 104 I2C &mi2c;
nkhorman 9:ddb97c9850a2 105 uint8_t mi2cAddress;
evgeniik 18:6fc8104e8548 106
evgeniik 18:6fc8104e8548 107 // the memory buffer for the LCD
evgeniik 18:6fc8104e8548 108 //std::vector<uint8_t> buffer;
nkhorman 0:c3dcd4c4983a 109 };
nkhorman 0:c3dcd4c4983a 110
nkhorman 0:c3dcd4c4983a 111 #endif