Fork of Adafruit OLED driver to debug integration with RedBear Nano SPI driver

Dependents:   SPI_GFX_nano

Fork of Adafruit_GFX by Neal Horman

Revision:
17:ad8b4fb845ff
Parent:
15:77feec1c0684
Child:
18:515811a6a589
--- a/Adafruit_SSD1306.h	Tue Nov 11 22:08:20 2014 +0000
+++ b/Adafruit_SSD1306.h	Wed Feb 25 20:05:23 2015 +0000
@@ -25,6 +25,7 @@
 
 #include "mbed.h"
 #include "Adafruit_GFX.h"
+#include "spi_master.h"
 
 #include <vector>
 #include <algorithm>
@@ -216,5 +217,73 @@
 	I2C &mi2c;
 	uint8_t mi2cAddress;
 };
+/** This is the SPI SSD1306 display driver transport class
+ *
+ */
+class Adafruit_SSD1306_nrf : 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 - nRF 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_nrf(NRF_SPI_Type *_spi, PinName DC, PinName RST, PinName CS, uint8_t rawHieght = 32, uint8_t rawWidth = 128)
+	    : Adafruit_SSD1306(RST, rawHieght, rawWidth)
+	    , cs(CS,true)
+	    , dc(DC,false)
+	    , mspi(_spi)
+	    {
+		    begin();
+		    splash();
+		    display();
+	    };
 
+	virtual void command(uint8_t c)
+	{
+	    cs = 1;
+	    dc = 0;
+	    cs = 0;
+	    mspi.transfer(c);
+	    cs = 1;
+	};
+
+	virtual void data(uint8_t c)
+	{
+	    cs = 1;
+	    dc = 1;
+	    cs = 0;
+	    mspi.transfer(c);
+	    cs = 1;
+	};
+
+protected:
+	virtual void sendDisplayBuffer()
+	{
+		cs = 1;
+		dc = 1;
+		cs = 0;
+
+		for(uint16_t i=0, q=buffer.size(); i<q; i++)
+			mspi.transfer(buffer[i]);
+
+		if(height() == 32)
+		{
+			for(uint16_t i=0, q=buffer.size(); i<q; i++)
+				mspi.transfer(0);
+		}
+
+		cs = 1;
+	};
+
+	DigitalOut2 cs, dc;
+	SPIClass mspi;
+};
 #endif
\ No newline at end of file