displaying on SSD1306, 128x64 pixels OLED

Dependencies:   microbit

Revision:
8:5972683a7190
Parent:
6:c69f08f464b5
Child:
10:8bf77efd1579
--- a/OLED.cpp	Mon Feb 24 14:34:14 2020 +0000
+++ b/OLED.cpp	Mon Feb 24 18:31:22 2020 +0000
@@ -2,14 +2,14 @@
 #include "MicroBit.h"
 #include "MicroBitI2C.h"
 
-#include "OLEDGlobals.h"
 #include "OLED.h"
 #include "cppNorm.h"
 
 /**
- * Create a representation of a 128x64 pixels, ssd1306 compatble OLED display
- *
- **/
+  * ssd1306 compatible device of 128x64 pixels OLED display.
+  * Init() must be called after construction.
+  * Works for some untraced circumstances not in fibers
+  */
 OLED::OLED() : 
      i2c(I2C_SDA0,I2C_SCL0)
     ,charX(0)
@@ -26,6 +26,11 @@
     buf[1] = cmd;
     i2c.write(chipAdress,buf,2);
 }
+
+/**
+  * Initialisere display and clears it. A buffer representing charaters are 
+  * filled with space characters
+  */ 
 void OLED::init() {
     init(128, 64);
     }
@@ -67,6 +72,9 @@
     clear();
 }
 
+/**
+  * clears the display
+  */
 void OLED::clear() {
     loadStarted = false;
     loadPercent = 0;
@@ -77,10 +85,9 @@
     command(0x00);
     command(displayHeight - 1);
     char data[17];
-    data[0] = 0x40; // Data Mode;
+    data[0] = 0x40;
     for (int8_t i = 1; i < 17; i++) 
         data[i] = 0x00;
-    // send display buffer in 16 byte chunks;
     for (int16_t  i = 0; i < screenSize; i += 16) { 
         i2c.write(chipAdress, data, 17,false);
     }
@@ -89,7 +96,13 @@
     setTextArea(32,true);
 }
 
-
+/**
+  * Put a char on display. A value in range [0x00,0xFF] i permitted -
+  * 0,0xff and 0x20 are bitpatterns with all null pixels (like space)
+  *
+  * @param x horizontal pixelwise position, range [0,displayWidth - 6]
+  * @param y vertical position, range [0,7]
+  */
 void OLED::drawChar(uint8_t x, uint8_t y, uint8_t chr ) {
     command(SSD1306_SETCOLUMNADRESS);
     command(x);
@@ -117,13 +130,25 @@
                 textArea[xPos][line]=chr;
 }
 
-
+/**
+  * Scroll display one line up. An empty line will arise at bottom.
+  */
 void OLED::scroll() {
     for (int8_t line = 1; line <= 8; line++)
         for (int8_t xPos = 0; xPos < 22; xPos++)
             drawChar(6*xPos,line-1,textArea[xPos][line]);
 }    
 
+/** 
+  * Makes a newline by incrementing charY and assigning xOffset to charX
+  * if charY becomes 8 the display screen is scrolled one line and charY
+  * is decremented to 7. pendingNewline=false is done at last.
+  */
+/** 
+  * Makes a newline by incrementing charY and assigning xOffset to charX
+  * if charY becomes 8 the display screen is scrolled one line and charY
+  * is decremented to 7. pendingNewline=false is done at last.
+  */
 void OLED::newLine() {
     charY++;
     charX = xOffset;
@@ -134,6 +159,13 @@
     pendingNewline=false;
 }
             
+/** 
+  * Writes a string at charX, charY position. Afterwards are
+  * charX, charY set to the new starting point for writting
+  * \n and \r is processed - \n includes \r  functionality
+  *
+  * @param str to be displayed at (charX, charY).   
+  */
 void OLED::puts(string str) {
     for (uint16_t i = 0; i < str.length(); i++) {
         if (str.charAt(i) == '\r')
@@ -151,6 +183,11 @@
     }
 }
 
+/**
+  * printf - the old clasic but don't use \n or \r in format string
+  *  \n and \r is processed - \n includes \r  functionality
+  * This function is the main reason to that OLED not works in fibers.
+  */
 uint8_t OLED::printf(const char * fmt, ...) {
     va_list args;
     va_start(args, fmt);