Driver for the Seeedstudio RGB OLED module for the xadow M0

Revision:
6:06c211302c93
Parent:
5:9de43186f5ea
Child:
7:5250c825c7bb
--- a/src/SSD1331.cpp	Fri Nov 13 23:29:59 2015 +0000
+++ b/src/SSD1331.cpp	Sat Nov 14 21:18:26 2015 +0000
@@ -138,8 +138,8 @@
 //------------------------------------------------------------------------------------
 void SSD1331::drawPixel(uint8_t x, uint8_t y, uint16_t color)
 {
-    if (x >= RGB_OLED_WIDTH)  x = RGB_OLED_WIDTH  - 1;
-    if (y >= RGB_OLED_HEIGHT) y = RGB_OLED_HEIGHT - 1;
+    if (x >= RGB_OLED_WIDTH)  x = RGB_OLED_XMAX;
+    if (y >= RGB_OLED_HEIGHT) y = RGB_OLED_YMAX;
     //                         set column point               set row point
     uint8_t cmdBuffer[6] = { CMD_SET_COLUMN_ADDRESS, x, x,  CMD_SET_ROW_ADDRESS, y, y };
     sendCmd(cmdBuffer, 6); //Send buffer  
@@ -149,10 +149,10 @@
 //------------------------------------------------------------------------------------
 void SSD1331::drawLine(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint16_t color)
 {
-    if (x0 >= RGB_OLED_WIDTH)  x0 = RGB_OLED_WIDTH  - 1;
-    if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_HEIGHT - 1;
-    if (x1 >= RGB_OLED_WIDTH)  x1 = RGB_OLED_WIDTH  - 1;
-    if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_HEIGHT - 1;
+    if (x0 >= RGB_OLED_WIDTH)  x0 = RGB_OLED_XMAX;
+    if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_YMAX;
+    if (x1 >= RGB_OLED_WIDTH)  x1 = RGB_OLED_XMAX;
+    if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_YMAX;
     
     uint8_t cmd[8] = { CMD_DRAW_LINE, x0, y0, x1, y1, (uint8_t)((color>>11)&0x1F), (uint8_t)((color>>5)&0x3F), (uint8_t)(color&0x1F) };
     sendCmd(cmd, 8);
@@ -161,10 +161,10 @@
 //------------------------------------------------------------------------------------
 void SSD1331::drawFrame(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint16_t outColor, uint16_t fillColor)
 {
-    if (x0 >= RGB_OLED_WIDTH)  x0 = RGB_OLED_WIDTH  - 1;
-    if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_HEIGHT - 1;
-    if (x1 >= RGB_OLED_WIDTH)  x1 = RGB_OLED_WIDTH  - 1;
-    if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_HEIGHT - 1;
+    if (x0 >= RGB_OLED_WIDTH)  x0 = RGB_OLED_XMAX;
+    if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_YMAX;
+    if (x1 >= RGB_OLED_WIDTH)  x1 = RGB_OLED_XMAX;
+    if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_YMAX;
     
     uint8_t cmd[11] = { CMD_DRAW_RECTANGLE, x0, y0, x1, y1, 
                      (uint8_t)((outColor>>11)&0x1F), (uint8_t)((outColor>>5)&0x3F), (uint8_t)(outColor&0x1F),
@@ -178,10 +178,12 @@
 //------------------------------------------------------------------------------------
 void SSD1331::copyArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,uint8_t x2, uint8_t y2)
 {
-    if (x0 >= RGB_OLED_WIDTH)  x0 = RGB_OLED_WIDTH  - 1;
-    if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_HEIGHT - 1;
-    if (x1 >= RGB_OLED_WIDTH)  x1 = RGB_OLED_WIDTH  - 1;
-    if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_HEIGHT - 1;
+    if (x0 >= RGB_OLED_WIDTH)  x0 = RGB_OLED_XMAX;
+    if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_YMAX;
+    if (x1 >= RGB_OLED_WIDTH)  x1 = RGB_OLED_XMAX;
+    if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_YMAX;
+    if (x2 >= RGB_OLED_WIDTH)  x2 = RGB_OLED_XMAX;
+    if (y2 >= RGB_OLED_HEIGHT) y2 = RGB_OLED_YMAX;
     
     uint8_t cmd[7] = { CMD_COPY_WINDOW, x0, y0, x1, y1, x2, y2};
     sendCmd(cmd, 7);
@@ -191,10 +193,10 @@
 //------------------------------------------------------------------------------------
 void SSD1331::dimArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1)
 {
-    if (x0 >= RGB_OLED_WIDTH)  x0 = RGB_OLED_WIDTH  - 1;
-    if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_HEIGHT - 1;
-    if (x1 >= RGB_OLED_WIDTH)  x1 = RGB_OLED_WIDTH  - 1;
-    if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_HEIGHT - 1;
+    if (x0 >= RGB_OLED_WIDTH)  x0 = RGB_OLED_XMAX;
+    if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_YMAX;
+    if (x1 >= RGB_OLED_WIDTH)  x1 = RGB_OLED_XMAX;
+    if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_YMAX;
     
     uint8_t cmdBuffer[5] = { CMD_DIM_WINDOW, x0, y0, x1, y1 };
     sendCmd(cmdBuffer, 5); //Send buffer
@@ -204,10 +206,10 @@
 //------------------------------------------------------------------------------------
 void SSD1331::clearArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1)
 {
-    if (x0 >= RGB_OLED_WIDTH)  x0 = RGB_OLED_WIDTH  - 1;
-    if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_HEIGHT - 1;
-    if (x1 >= RGB_OLED_WIDTH)  x1 = RGB_OLED_WIDTH  - 1;
-    if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_HEIGHT - 1;
+    if (x0 >= RGB_OLED_WIDTH)  x0 = RGB_OLED_XMAX;
+    if (y0 >= RGB_OLED_HEIGHT) y0 = RGB_OLED_YMAX;
+    if (x1 >= RGB_OLED_WIDTH)  x1 = RGB_OLED_XMAX;
+    if (y1 >= RGB_OLED_HEIGHT) y1 = RGB_OLED_YMAX;
     
     uint8_t cmdBuffer[5] = { CMD_CLEAR_WINDOW, x0, y0, x1, y1 };
     sendCmd(cmdBuffer, 5); //Send buffer
@@ -215,6 +217,13 @@
 }
 
 //------------------------------------------------------------------------------------
+void SSD1331::moveArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2)
+{  
+    copyArea(x0, y0, x1, y1, x2, y2);
+    clearArea(x0, y0, x1, y1);
+}
+
+//------------------------------------------------------------------------------------
 void SSD1331::setScolling(ScollingDirection direction, uint8_t rowAddr, uint8_t rowNum, uint8_t timeInterval)
 {
     uint8_t scolling_horizontal = 0x0;