ssd1306 stm32l010

Dependents:   oled_test7_16x24_010_1 i2c_HT16K33_test1_767_3 HAL_oled_16x24_010_1

Files at this revision

API Documentation at this revision

Comitter:
caa45040
Date:
Thu Aug 04 14:35:32 2022 +0000
Parent:
0:5d70351255d1
Commit message:
stm32f767 oled hal

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
--- a/SSD1308.cpp	Tue Aug 02 06:48:13 2022 +0000
+++ b/SSD1308.cpp	Thu Aug 04 14:35:32 2022 +0000
@@ -8,7 +8,7 @@
 
 //i2c initialization
 //I2C i2c(I2C_SDA, I2C_SCL); //767
-I2C i2c(PA_10, PA_9); //010
+//I2C i2c(PA_10, PA_9); //010
 
 
 //void fff(char *str1)
@@ -24,8 +24,10 @@
  *@param uint8_t deviceAddress slaveaddress
  */
 //SSD1308::SSD1308(I2C *i2c, uint8_t deviceAddress) : _i2c(i2c) {
-SSD1308::SSD1308( uint8_t deviceAddress)  {
+//SSD1308::SSD1308( uint8_t deviceAddress)  {
+SSD1308::SSD1308( I2C_HandleTypeDef* hi2c , uint8_t deviceAddress )  {
 
+  _hi2c = hi2c;
   
   _writeOpcode = deviceAddress & 0xFE; // low order bit = 0 for write
   _readOpcode  = deviceAddress | 0x01; // low order bit = 1 for read  
@@ -50,11 +52,34 @@
     //fff("\r\n");
     
     //charge pump  add=>ca45040
-    i2c.write(SSD1308_SA0, "\200\215\200\024", 4); //0x80,0x8d,0x80,0x14
+    //i2c.write(SSD1308_SA0, "\200\215\200\024", 4); //0x80,0x8d,0x80,0x14
+    HAL_I2C_Master_Transmit(   _hi2c        , _writeOpcode   , (uint8_t*)"\200\215\200\024", 4, 3000);
     //set access
     //setDisplayFlip(false, false);
 
 
+
+
+//    uint8_t buf[16];
+//
+//
+//            buf[0]=0;
+//            buf[1]= 0x55;
+//            
+//            HAL_I2C_Master_Transmit(   _hi2c        ,  _writeOpcode  , buf, 2, 3000);          
+//            wait_ms(600);
+//
+//            buf[0]=0;
+//            buf[1]= 0xaa;
+//
+//
+//            HAL_I2C_Master_Transmit(   _hi2c       ,  _writeOpcode  , buf, 2, 3000);           
+//            wait_ms(600);
+
+
+
+
+
     
 }//initialize
 
@@ -77,12 +102,12 @@
 */
 
     //128*64/8=1024
-    char databytes[2] = {    DATA_MODE,    0x00 };
+    uint8_t databytes[2] = {    DATA_MODE,    0x00 };
     for (int icount = 0; icount < 1024; icount++) {
         //_sendData(0x00);
         
-        i2c.write(_writeOpcode, databytes, 2);
-        
+        //i2c.write(_writeOpcode, databytes, 2);
+        HAL_I2C_Master_Transmit(   _hi2c       ,  _writeOpcode  , databytes, 2, 3000);
     }
 
     //setDisplayOn();
@@ -104,13 +129,13 @@
 
 
 
-    char databytes[2] = {    DATA_MODE,    0 };
+    uint8_t databytes[2] = {    DATA_MODE,    0 };
     for (int i=0; i<count; i++) {
         //_sendData(data[i]); // Write Data
 
         databytes[1] = data[i];
-        i2c.write(_writeOpcode, databytes, 2);
-        
+        //i2c.write(_writeOpcode, databytes, 2);
+        HAL_I2C_Master_Transmit(   _hi2c       ,  _writeOpcode  , databytes , 2, 3000);
     }
 
 
@@ -233,10 +258,10 @@
     //_sendCommand(SET_MEMORY_ADDRESSING_MODE, mode);
  
  
-    char databytes[4] = {    COMMAND_MODE,    SET_MEMORY_ADDRESSING_MODE,    COMMAND_MODE,    mode              };
+    uint8_t databytes[4] = {    COMMAND_MODE,    SET_MEMORY_ADDRESSING_MODE,    COMMAND_MODE,    mode              };
     
-    i2c.write(_writeOpcode, databytes, 4);
-
+    //i2c.write(_writeOpcode, databytes, 4);
+    HAL_I2C_Master_Transmit(   _hi2c       ,  _writeOpcode  , databytes, 4, 3000);
  
  
 }//setMemoryAddressingMode
@@ -249,9 +274,9 @@
     
     //_sendCommand(SET_PAGE_ADDRESS, start, end);
     
-    char databytes[6] = {    COMMAND_MODE,    SET_PAGE_ADDRESS,    COMMAND_MODE,    start,    COMMAND_MODE,    end              };
-    i2c.write(_writeOpcode, databytes, 6);
-
+    uint8_t databytes[6] = {    COMMAND_MODE,    SET_PAGE_ADDRESS,    COMMAND_MODE,    start,    COMMAND_MODE,    end              };
+    //i2c.write(_writeOpcode, databytes, 6);
+    HAL_I2C_Master_Transmit(   _hi2c       ,  _writeOpcode  , databytes, 6, 3000);
     
     
 }//setPageAddress
@@ -264,9 +289,9 @@
     
     //_sendCommand(SET_COLUMN_ADDRESS, start, end);
     
-    char databytes[6] = {    COMMAND_MODE,    SET_COLUMN_ADDRESS,    COMMAND_MODE,    start,    COMMAND_MODE,    end              };
-    i2c.write(_writeOpcode, databytes, 6);
-
+    uint8_t databytes[6] = {    COMMAND_MODE,    SET_COLUMN_ADDRESS,    COMMAND_MODE,    start,    COMMAND_MODE,    end              };
+    //i2c.write(_writeOpcode, databytes, 6);
+    HAL_I2C_Master_Transmit(   _hi2c       ,  _writeOpcode  , databytes, 6, 3000);
     
 }//setColumnAddress
 
@@ -279,8 +304,9 @@
     //_sendCommand(SET_DISPLAY_POWER_ON);
     
     
-    char databytes[2] = {    COMMAND_MODE,    SET_DISPLAY_POWER_ON             };
-    i2c.write(_writeOpcode,databytes, 2); 
+    uint8_t databytes[2] = {    COMMAND_MODE,    SET_DISPLAY_POWER_ON             };
+    //i2c.write(_writeOpcode,databytes, 2); 
+    HAL_I2C_Master_Transmit(   _hi2c       ,  _writeOpcode  , databytes, 2, 3000);
     
 }//setDisplayOn
 
--- a/SSD1308.h	Tue Aug 02 06:48:13 2022 +0000
+++ b/SSD1308.h	Thu Aug 04 14:35:32 2022 +0000
@@ -228,7 +228,9 @@
   *@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( uint8_t address = SSD1308_DEF_SA);
+    //SSD1308( uint8_t address = SSD1308_DEF_SA);
+    SSD1308( I2C_HandleTypeDef* _hi2c , uint8_t address = SSD1308_DEF_SA );
+
 
 // High Level methods
 
@@ -374,6 +376,9 @@
     uint8_t _writeOpcode;  // contains the I2C address of the device
     
     //bool _inverted;        // inverted or normal text   
+    
+    I2C_HandleTypeDef* _hi2c;
+    
 };
 
 #endif