Driver for the Seeedstudio RGB OLED module for the xadow M0

Files at this revision

API Documentation at this revision

Comitter:
messi1
Date:
Thu Nov 12 23:23:33 2015 +0000
Parent:
2:e033aab5daad
Child:
4:1707ca53e7d5
Commit message:
Replaced unsigned char with uint8_t

Changed in this revision

include/SGL.h Show annotated file Show diff for this revision Revisions of this file
include/SSD1331.h Show annotated file Show diff for this revision Revisions of this file
src/SSD1331.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/include/SGL.h	Thu Nov 12 22:31:58 2015 +0000
+++ b/include/SGL.h	Thu Nov 12 23:23:33 2015 +0000
@@ -144,7 +144,7 @@
  
 public:
     SGL(uint16_t width, uint16_t height);
-    virtual void drawPixel(uint16_t x, uint16_t y, uint16_t color) = 0; // implemented by subclass
+    virtual void drawPixel(uint8_t x, uint8_t y, uint16_t color) = 0; // implemented by subclass
     virtual void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
     virtual void drawVerticalLine(uint16_t x, uint16_t y, uint16_t height,uint16_t color);
     virtual void drawHorizontalLine(uint16_t x, uint16_t y, uint16_t width, uint16_t color);
--- a/include/SSD1331.h	Thu Nov 12 22:31:58 2015 +0000
+++ b/include/SSD1331.h	Thu Nov 12 23:23:33 2015 +0000
@@ -2,6 +2,7 @@
 * SSD1331.h
 * A library for RGB OLED module
 *
+* Copyright (c) 2015 Juergen Messerer
 * Copyright (c) 2014 seeed technology inc.
 * Copyright (c) 2012, Adafruit Industries.
 *
@@ -182,39 +183,38 @@
 };
 
 
-class SSD1331 : public mbed::Stream, public virtual SGL {
-public:
-    SSD1331(PinName cs, PinName rst, PinName dc, PinName mosi, PinName miso, PinName sclk);
-    void init(void);
-    virtual void drawPixel(uint16_t x, uint16_t y, uint16_t color);
-    virtual void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
-    void drawFrame(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t outColor, uint16_t fillColor);
-    void copyWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,uint16_t x2, uint16_t y2);
-    void dimWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
-    void clearWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
-    void setScolling(ScollingDirection direction, uint8_t rowAddr, uint8_t rowNum, uint8_t timeInterval);
-    void enableScolling(bool enable);
-    void setDisplayMode(DisplayMode mode);
-    void setDisplayPower(DisplayPower power);
-    void Draw_Dot(uint8_t x, uint8_t y,unsigned int Color);
-    
-    void RegWriteM(unsigned char *Command, int count);
-protected:
-     // Stream implementation functions
-     virtual int _putc( int c );
-     virtual int _getc();
-    
-private:
-    void sendCmd(unsigned char cmd);
-    void sendCmd(unsigned char cmd, unsigned char arg1);
-    void sendCmd(unsigned char cmd, unsigned char arg1, unsigned char arg2);
-    void sendCmd(unsigned char *cmd, int count);
-    void sendData(uint16_t data);
-    
-private:
-    mbed::DigitalOut _cs;
-    mbed::DigitalOut _dc;
-    mbed::SPI        _spiPort;
+class SSD1331 : public mbed::Stream, public virtual SGL 
+{
+    public:
+        SSD1331(PinName cs, PinName rst, PinName dc, PinName mosi, PinName miso, PinName sclk);
+        void init(void);
+        virtual void drawPixel(uint8_t x, uint8_t y, uint16_t color);
+        virtual void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
+        void drawFrame(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t outColor, uint16_t fillColor);
+        void copyWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,uint16_t x2, uint16_t y2);
+        void dimWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
+        void clearWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
+        void setScolling(ScollingDirection direction, uint8_t rowAddr, uint8_t rowNum, uint8_t timeInterval);
+        void enableScolling(bool enable);
+        void setDisplayMode(DisplayMode mode);
+        void setDisplayPower(DisplayPower power);
+        
+    protected:
+         // Stream implementation functions
+         virtual int _putc( int c );
+         virtual int _getc();
+        
+    private:
+        void sendCmd(uint8_t cmd);
+        void sendCmd(uint8_t cmd,  uint8_t arg1);
+        void sendCmd(uint8_t cmd,  uint8_t arg1, uint8_t arg2);
+        void sendCmd(uint8_t *cmd, uint8_t count);
+        void sendData(uint16_t data);
+        
+    private:
+        mbed::DigitalOut _cs;
+        mbed::DigitalOut _dc;
+        mbed::SPI        _spiPort;
 };
 
 #endif
\ No newline at end of file
--- a/src/SSD1331.cpp	Thu Nov 12 22:31:58 2015 +0000
+++ b/src/SSD1331.cpp	Thu Nov 12 23:23:33 2015 +0000
@@ -69,7 +69,7 @@
     init();
 };
 
-void SSD1331::sendCmd(unsigned char cmd)
+void SSD1331::sendCmd(uint8_t cmd)
 {
     _dc = 0;
     _cs = 0;
@@ -77,7 +77,7 @@
     _cs = 1;
 }
 
-void SSD1331::sendCmd(unsigned char cmd, unsigned char arg1)
+void SSD1331::sendCmd(uint8_t cmd, uint8_t arg1)
 {
     _dc = 0;
     _cs = 0;
@@ -86,7 +86,7 @@
     _cs = 1;
 }
     
-void SSD1331::sendCmd(unsigned char cmd, unsigned char arg1, unsigned char arg2)
+void SSD1331::sendCmd(uint8_t cmd, uint8_t arg1, uint8_t arg2)
 {
     _dc = 0;
     _cs = 0;
@@ -96,13 +96,13 @@
     _cs = 1;
 }    
 
-void  SSD1331::sendCmd(unsigned char *cmd, int count)
+void  SSD1331::sendCmd(uint8_t *cmd, uint8_t count)
 {
     if(!cmd) return;
     
     _dc = 0;
     _cs = 0;
-    for(int i=0; i<count; ++i)
+    for(uint8_t i=0; i<count; ++i)
        _spiPort.write(*cmd++);
     _cs = 1;
 }
@@ -198,39 +198,19 @@
 //    sendCmd(CMD_NORMAL_BRIGHTNESS_DISPLAY_ON);//set display on
 }
 
-void SSD1331::drawPixel(uint16_t x, uint16_t y, uint16_t color)
+void SSD1331::drawPixel(uint8_t x, uint8_t y, uint16_t color)
 {
     if ((x >= RGB_OLED_WIDTH) || (y >= RGB_OLED_HEIGHT))
         return;
         
-    //set column point
-    sendCmd(CMD_SET_COLUMN_ADDRESS, x, RGB_OLED_WIDTH-1);
-
-    //set row point
-    sendCmd(CMD_SET_ROW_ADDRESS, y, RGB_OLED_HEIGHT-1);
+    //                      set column point               set row point
+    uint8_t cmd[7] = {CMD_SET_COLUMN_ADDRESS, x, x,  CMD_SET_ROW_ADDRESS, y, y,   0x00};
+    sendCmd(cmd, 6);
 
     //fill 16bit colour
     sendData(color);
 }
 
-//------------------------------------------------------------
-
-
-void SSD1331::Draw_Dot(uint8_t x, uint8_t y,unsigned int Color)
-{
-    x=96-x;
-    
-    unsigned char cmd[7]={0x15,0x00,0x00,0x75,0x00,0x00,0x00};
-
-    cmd[1] = (unsigned char)x; 
-    cmd[2] = (unsigned char)x; 
-    cmd[4] = (unsigned char)y; 
-    cmd[5] = (unsigned char)y; 
-    sendCmd(cmd, 6);
-    sendData(Color);
-}
-
-
 //-------------------------------------------------------------------------
 void SSD1331::drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color)
 {