SSD1308 128x64 OLED Driver with I2C interface

Dependents:   sense xadow_m0_ada_gps xadow_m0_SD_Hello sense-DHT11 ... more

See http://mbed.org/users/wim/notebook/oled-display-with-ssd1308-driver/#c6729

Files at this revision

API Documentation at this revision

Comitter:
wim
Date:
Mon Dec 18 18:46:05 2017 +0000
Parent:
4:df92b0c0cb92
Commit message:
Fixed non-copyable issue (Thx kenjiArai)

Changed in this revision

SSD1308.cpp Show annotated file Show diff for this revision Revisions of this file
SSD1308.h Show annotated file Show diff for this revision Revisions of this file
diff -r df92b0c0cb92 -r e564cde8e03e SSD1308.cpp
--- a/SSD1308.cpp	Thu Jan 01 17:53:40 2015 +0000
+++ b/SSD1308.cpp	Mon Dec 18 18:46:05 2017 +0000
@@ -14,12 +14,13 @@
 //   2012-06-19 - Ported to mbed and optimised (WH)
 //   2013-07-12 - Minor comment fix and placeholder for SSD1306 (WH)
 //   2015-01-01 - Switch for optimised I2C calls to test on F401 (WH)
+//   2017-12-18 - Fixed non-copyable issue (Thx kenjiArai)
 //       
 /* 
 ================================================================================
 I2Cdev device library code is placed under the MIT license
 Copyright (c) 2011 Andrew Schamp
-Copyright (c) 2012,2013 WH (mbed port)
+Copyright (c) 2012,2013,2017 WH (mbed port)
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
@@ -59,10 +60,10 @@
 
 /**
  *@brief Constructor
- *@param I2C &i2c reference to i2c
+ *@param I2C *i2c reference to i2c
  *@param uint8_t deviceAddress slaveaddress
  */
-SSD1308::SSD1308(I2C &i2c, uint8_t deviceAddress) : _i2c(i2c) {
+SSD1308::SSD1308(I2C *i2c, uint8_t deviceAddress) : _i2c(i2c) {
   
   _writeOpcode = deviceAddress & 0xFE; // low order bit = 0 for write
   _readOpcode  = deviceAddress | 0x01; // low order bit = 1 for read  
@@ -113,13 +114,13 @@
   setPageAddress(0, MAX_PAGE);  // all pages
   setColumnAddress(0, MAX_COL); // all columns
 
-  _i2c.start();
-  _i2c.write(_writeOpcode);
-  _i2c.write(DATA_MODE);  
+  _i2c->start();
+  _i2c->write(_writeOpcode);
+  _i2c->write(DATA_MODE);  
   for (int i=0; i<(PAGES * COLUMNS); i++) {
-    _i2c.write(0x00);  // Write Data   
+    _i2c->write(0x00);  // Write Data   
   }
-  _i2c.stop();
+  _i2c->stop();
 
   //setDisplayOn();
 }
@@ -169,13 +170,13 @@
   setPageAddress(start_page, end_page);  // set page window
   setColumnAddress(start_col, end_col);  // set column window
  
-  _i2c.start();
-  _i2c.write(_writeOpcode);
-  _i2c.write(DATA_MODE);  
+  _i2c->start();
+  _i2c->write(_writeOpcode);
+  _i2c->write(DATA_MODE);  
   for (int i=0; i<count; i++) {
-    _i2c.write(pattern);  // Write Data   
+    _i2c->write(pattern);  // Write Data   
   }
-  _i2c.stop();
+  _i2c->stop();
 
   //setDisplayOn();
 }
@@ -224,13 +225,13 @@
   setPageAddress(start_page, end_page);  // set page window
   setColumnAddress(start_col, end_col);  // set column window
 
-  _i2c.start();
-  _i2c.write(_writeOpcode);
-  _i2c.write(DATA_MODE);  
+  _i2c->start();
+  _i2c->write(_writeOpcode);
+  _i2c->write(DATA_MODE);  
   for (int i=0; i<count; i++) {
-    _i2c.write(data[i]);  // Write Data       
+    _i2c->write(data[i]);  // Write Data       
   }
-  _i2c.stop();
+  _i2c->stop();
 
   //setDisplayOn();
 }
@@ -306,25 +307,25 @@
   setPageAddress(page, page);  
   setColumnAddress(col, MAX_COL); 
 
-  _i2c.start();
-  _i2c.write(_writeOpcode);
-  _i2c.write(DATA_MODE);  
+  _i2c->start();
+  _i2c->write(_writeOpcode);
+  _i2c->write(DATA_MODE);  
 
-  _i2c.write(PRG_LEFT_EDGE);  // Write Data         
+  _i2c->write(PRG_LEFT_EDGE);  // Write Data         
 
   for (uint8_t col = 0; col < scale_value; col++) {
-     _i2c.write(PRG_ACTIVE);  // Write Data                       
+     _i2c->write(PRG_ACTIVE);  // Write Data                       
   }
 
-  _i2c.write(PRG_ACTIVE);  // Write Data                       
+  _i2c->write(PRG_ACTIVE);  // Write Data                       
      
   for (uint8_t col = (scale_value+1); col < PRG_MAX_SCALE; col++) {
-     _i2c.write(PRG_NOT_ACTIVE);  // Write Data                 
+     _i2c->write(PRG_NOT_ACTIVE);  // Write Data                 
   }
 
-  _i2c.write(PRG_RIGHT_EDGE);  // Write Data           
+  _i2c->write(PRG_RIGHT_EDGE);  // Write Data           
 
-  _i2c.stop();
+  _i2c->stop();
     
   //setDisplayOn();
 }
@@ -389,25 +390,25 @@
   setPageAddress(page, page);  
   setColumnAddress(col, MAX_COL); 
 
-  _i2c.start();
-  _i2c.write(_writeOpcode);
-  _i2c.write(DATA_MODE);  
+  _i2c->start();
+  _i2c->write(_writeOpcode);
+  _i2c->write(DATA_MODE);  
 
-  _i2c.write(PRG_LEFT_EDGE);  // Write Data         
+  _i2c->write(PRG_LEFT_EDGE);  // Write Data         
 
   for (uint8_t col = 0; col < scale_value; col++) {
-     _i2c.write(PRG_NOT_ACTIVE);  // Write Data                       
+     _i2c->write(PRG_NOT_ACTIVE);  // Write Data                       
   }
 
-  _i2c.write(PRG_ACTIVE);  // Write Data at active meterlevel
+  _i2c->write(PRG_ACTIVE);  // Write Data at active meterlevel
   
   for (uint8_t col = scale_value+1; col < PRG_MAX_SCALE; col++) {
-     _i2c.write(PRG_NOT_ACTIVE);  // Write Data                 
+     _i2c->write(PRG_NOT_ACTIVE);  // Write Data                 
   }
 
-  _i2c.write(PRG_RIGHT_EDGE);  // Write Data           
+  _i2c->write(PRG_RIGHT_EDGE);  // Write Data           
 
-  _i2c.stop();
+  _i2c->stop();
     
   //setDisplayOn();
 }
@@ -497,16 +498,16 @@
     
   databytes[0] = COMMAND_MODE;
   databytes[1] = command;    
-  _i2c.write(_writeOpcode, databytes, 2);    // Write command   
+  _i2c->write(_writeOpcode, databytes, 2);    // Write command   
 #else  
 
-  _i2c.start();
-  _i2c.write(_writeOpcode);
+  _i2c->start();
+  _i2c->write(_writeOpcode);
   
-  _i2c.write(COMMAND_MODE);      
-  _i2c.write(command);       // Write Command   
+  _i2c->write(COMMAND_MODE);      
+  _i2c->write(command);       // Write Command   
 
-  _i2c.stop();  
+  _i2c->stop();  
 #endif
 }
 
@@ -523,18 +524,18 @@
   databytes[1] = command;    
   databytes[2] = COMMAND_MODE;
   databytes[3] = param1; 
-  _i2c.write(_writeOpcode, databytes, 4);    // Write command   
+  _i2c->write(_writeOpcode, databytes, 4);    // Write command   
 #else  
 
-  _i2c.start();
-  _i2c.write(_writeOpcode);
+  _i2c->start();
+  _i2c->write(_writeOpcode);
   
-  _i2c.write(COMMAND_MODE);      
-  _i2c.write(command);       // Write Command   
-  _i2c.write(COMMAND_MODE);      
-  _i2c.write(param1);        // Write Param1   
+  _i2c->write(COMMAND_MODE);      
+  _i2c->write(command);       // Write Command   
+  _i2c->write(COMMAND_MODE);      
+  _i2c->write(param1);        // Write Param1   
 
-  _i2c.stop();
+  _i2c->stop();
 #endif  
 }
 
@@ -553,19 +554,19 @@
   databytes[3] = param1; 
   databytes[4] = COMMAND_MODE;
   databytes[5] = param2; 
-  _i2c.write(_writeOpcode, databytes, 6);    // Write command   
+  _i2c->write(_writeOpcode, databytes, 6);    // Write command   
 #else  
-  _i2c.start();
-  _i2c.write(_writeOpcode);
+  _i2c->start();
+  _i2c->write(_writeOpcode);
   
-  _i2c.write(COMMAND_MODE);      
-  _i2c.write(command);       // Write Command   
-  _i2c.write(COMMAND_MODE);      
-  _i2c.write(param1);        // Write Param1   
-  _i2c.write(COMMAND_MODE);      
-  _i2c.write(param2);        // Write Param2   
+  _i2c->write(COMMAND_MODE);      
+  _i2c->write(command);       // Write Command   
+  _i2c->write(COMMAND_MODE);      
+  _i2c->write(param1);        // Write Param1   
+  _i2c->write(COMMAND_MODE);      
+  _i2c->write(param2);        // Write Param2   
 
-  _i2c.stop();
+  _i2c->stop();
  #endif 
 }
 
@@ -592,25 +593,25 @@
   databytes[9] = param4; 
   databytes[10] = COMMAND_MODE;
   databytes[11] = param5;       
-  _i2c.write(_writeOpcode, databytes, 12);    // Write command   
+  _i2c->write(_writeOpcode, databytes, 12);    // Write command   
 #else  
-  _i2c.start();
-  _i2c.write(_writeOpcode);
+  _i2c->start();
+  _i2c->write(_writeOpcode);
   
-  _i2c.write(COMMAND_MODE);      
-  _i2c.write(command);       // Write Command   
-  _i2c.write(COMMAND_MODE);      
-  _i2c.write(param1);        // Write Param1   
-  _i2c.write(COMMAND_MODE);      
-  _i2c.write(param2);        // Write Param2   
-  _i2c.write(COMMAND_MODE);      
-  _i2c.write(param3);        // Write Param3   
-  _i2c.write(COMMAND_MODE);      
-  _i2c.write(param4);        // Write Param4   
-  _i2c.write(COMMAND_MODE);      
-  _i2c.write(param5);        // Write Param5   
+  _i2c->write(COMMAND_MODE);      
+  _i2c->write(command);       // Write Command   
+  _i2c->write(COMMAND_MODE);      
+  _i2c->write(param1);        // Write Param1   
+  _i2c->write(COMMAND_MODE);      
+  _i2c->write(param2);        // Write Param2   
+  _i2c->write(COMMAND_MODE);      
+  _i2c->write(param3);        // Write Param3   
+  _i2c->write(COMMAND_MODE);      
+  _i2c->write(param4);        // Write Param4   
+  _i2c->write(COMMAND_MODE);      
+  _i2c->write(param5);        // Write Param5   
 
-  _i2c.stop();
+  _i2c->stop();
 #endif  
 }
 
@@ -640,27 +641,27 @@
   databytes[11] = param5;   
   databytes[12] = COMMAND_MODE;
   databytes[13] = param6;       
-  _i2c.write(_writeOpcode, databytes, 14);    // Write command   
+  _i2c->write(_writeOpcode, databytes, 14);    // Write command   
 #else  
-  _i2c.start();
-  _i2c.write(_writeOpcode);
+  _i2c->start();
+  _i2c->write(_writeOpcode);
   
-  _i2c.write(COMMAND_MODE);      
-  _i2c.write(command);       // Write Command   
-  _i2c.write(COMMAND_MODE);      
-  _i2c.write(param1);        // Write Param1   
-  _i2c.write(COMMAND_MODE);      
-  _i2c.write(param2);        // Write Param2   
-  _i2c.write(COMMAND_MODE);      
-  _i2c.write(param3);        // Write Param3   
-  _i2c.write(COMMAND_MODE);      
-  _i2c.write(param4);        // Write Param4   
-  _i2c.write(COMMAND_MODE);      
-  _i2c.write(param5);        // Write Param5   
-  _i2c.write(COMMAND_MODE);      
-  _i2c.write(param6);        // Write Param6   
+  _i2c->write(COMMAND_MODE);      
+  _i2c->write(command);       // Write Command   
+  _i2c->write(COMMAND_MODE);      
+  _i2c->write(param1);        // Write Param1   
+  _i2c->write(COMMAND_MODE);      
+  _i2c->write(param2);        // Write Param2   
+  _i2c->write(COMMAND_MODE);      
+  _i2c->write(param3);        // Write Param3   
+  _i2c->write(COMMAND_MODE);      
+  _i2c->write(param4);        // Write Param4   
+  _i2c->write(COMMAND_MODE);      
+  _i2c->write(param5);        // Write Param5   
+  _i2c->write(COMMAND_MODE);      
+  _i2c->write(param6);        // Write Param6   
 
-  _i2c.stop();
+  _i2c->stop();
 #endif  
 }
 
@@ -674,14 +675,14 @@
 //  Note this original code is not correct, continuationbit is set, 
 //  so COMMAND_MODE must be repeated before each databyte that serves as parameter!
 
-  _i2c.start();
-  _i2c.write(_writeOpcode);
+  _i2c->start();
+  _i2c->write(_writeOpcode);
   
   for (int i=0; i<len ; i++) {
-    _i2c.write(COMMAND_MODE);      
-    _i2c.write(commands[i]);  // Write Commands   
+    _i2c->write(COMMAND_MODE);      
+    _i2c->write(commands[i]);  // Write Commands   
   }
-  _i2c.stop();
+  _i2c->stop();
   
 }
 #endif
@@ -700,14 +701,14 @@
     
   databytes[0] = DATA_MODE;
   databytes[1] = data;    
-  _i2c.write(_writeOpcode, databytes, 2);    // Write Data   
+  _i2c->write(_writeOpcode, databytes, 2);    // Write Data   
 
 #else
-  _i2c.start();
-  _i2c.write(_writeOpcode);
-  _i2c.write(DATA_MODE);  
-  _i2c.write(data); 
-  _i2c.stop();  
+  _i2c->start();
+  _i2c->write(_writeOpcode);
+  _i2c->write(DATA_MODE);  
+  _i2c->write(data); 
+  _i2c->stop();  
 #endif
 
 }
@@ -724,13 +725,13 @@
     _sendData(data[i]);  // Write Data   
   }
 #else  
-  _i2c.start();
-  _i2c.write(_writeOpcode);
-  _i2c.write(DATA_MODE);  
+  _i2c->start();
+  _i2c->write(_writeOpcode);
+  _i2c->write(DATA_MODE);  
   for (int i=0; i<len ; i++) {
-    _i2c.write(data[i]);  // Write Data   
+    _i2c->write(data[i]);  // Write Data   
   }
-  _i2c.stop();
+  _i2c->stop();
 #endif 
 }
 
diff -r df92b0c0cb92 -r e564cde8e03e SSD1308.h
--- a/SSD1308.h	Thu Jan 01 17:53:40 2015 +0000
+++ b/SSD1308.h	Mon Dec 18 18:46:05 2017 +0000
@@ -14,12 +14,13 @@
 //   2012-06-19 - Ported to mbed and optimised (WH)
 //   2013-07-12 - Minor comment fix and placeholder for SSD1306 (WH)
 //   2015-01-01 - Switch for optimised I2C calls to test on F401 (WH)
+//   2017-12-18 - Fixed non-copyable issue (Thx kenjiArai)
 //             
 /* 
 ================================================================================
 I2Cdev device library code is placed under the MIT license
 Copyright (c) 2011 Andrew Schamp
-Copyright (c) 2012,2013 WH (mbed port)
+Copyright (c) 2012,2013,2017 WH (mbed port)
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
@@ -192,7 +193,7 @@
  * Serial pc(USBTX, USBRX); // tx, rx
  *
  * // Instantiate OLED
- * SSD1308 oled = SSD1308(i2c, SSD1308_SA0);
+ * SSD1308 oled = SSD1308(&i2c, SSD1308_SA0);
  * 
  * int main() {
  *   pc.printf("OLED test start\r");  
@@ -224,7 +225,7 @@
   *@param I2C &i2c reference to i2c,
   *@param uint8_t deviceAddress slaveaddress (8bit to use for the controller (0x78 by default, assumes D/C# (pin 13) grounded)
  */    
-    SSD1308(I2C &i2c, uint8_t address = SSD1308_DEF_SA);
+    SSD1308(I2C *i2c, uint8_t address = SSD1308_DEF_SA);
 
 // High Level methods
 
@@ -533,7 +534,7 @@
  */   
     void _init();
 
-    I2C _i2c;              // I2C bus reference
+    I2C *_i2c;             // I2C bus reference
     uint8_t _readOpcode;   // contains the I2C address of the device
     uint8_t _writeOpcode;  // contains the I2C address of the device