void Adafruit_SSD1306::ssd1306_command(uint8_t c0, uint8_t c1, uint8_t c2) {
  uint8_t buff[4] ;
  
  buff[0] = 0x00;
  buff[1] = c0;
  buff[2] = c1;
  buff[3] = c2;

  if (sid != -1)
  {
    // SPI
    //digitalWrite(cs, HIGH);
    *csport |= cspinmask;
    //digitalWrite(dc, LOW);
    *dcport &= ~dcpinmask;
    //digitalWrite(cs, LOW);
    *csport &= ~cspinmask;
    fastSPIwrite(c0);
    fastSPIwrite(c1);
    fastSPIwrite(c2);
    //digitalWrite(cs, HIGH);
    *csport |= cspinmask;
  }
  else
  {
    // I2C
    //uint8_t control = 0x00;   // Co = 0, D/C = 0
    Wire.beginTransmission(_i2caddr);
    //WIRE_WRITE(control);
    WIRE_WRITE(buff, sizeof(buff));
    Wire.endTransmission();
  }
}
void SSD1306_96x16::ssd1306_command(uint8_t c)
{
	if (sid != -1)
	{
		// SPI
		//digitalWrite(cs, HIGH);
		*csport |= cspinmask;
		//digitalWrite(dc, LOW);
		*dcport &= ~dcpinmask;
		//digitalWrite(cs, LOW);
		*csport &= ~cspinmask;
		fastSPIwrite(c);
		//digitalWrite(cs, HIGH);
		*csport |= cspinmask;
	}
	else
	{
		// I2C
		uint8_t control = 0x00;   // Co = 0, D/C = 0
		Wire.beginTransmission(_i2caddr);
		Wire.write(control);
		Wire.write(c);
		Wire.endTransmission();
	}
}
void ESP_SSD1306::ssd1306_command(uint8_t c) { 
  if (sid != -1)
  {
    // SPI
    digitalWrite(cs, HIGH);		//uncommented for ESP8266 compatibility
//    *csport |= cspinmask;		//commented for ESP8266 compatibility
    digitalWrite(dc, LOW);		//uncommented for ESP8266 compatibility
//    *dcport &= ~dcpinmask;	//commented for ESP8266 compatibility
    digitalWrite(cs, LOW);		//uncommented for ESP8266 compatibility
//    *csport &= ~cspinmask;	//commented for ESP8266 compatibility
    fastSPIwrite(c);
    digitalWrite(cs, HIGH);		//uncommented for ESP8266 compatibility
//    *csport |= cspinmask;		//commented for ESP8266 compatibility
  }
  else
  {
    // I2C
    uint8_t control = 0x00;   // Co = 0, D/C = 0
    Wire.beginTransmission(_i2caddr);
    WIRE_WRITE(control);
    WIRE_WRITE(c);
    Wire.endTransmission();
    yield();
  }
}
void Adafruit_SSD1306::ssd1306_data(uint8_t c) {
  if (sid != -1)
  {
    // SPI
#ifdef PortReg
    *csport |= cspinmask;
    *dcport |= dcpinmask;
    *csport &= ~cspinmask;
#else
    digitalWrite(cs, HIGH);
    digitalWrite(dc, HIGH);
    digitalWrite(cs, LOW);
#endif
    fastSPIwrite(c);
#ifdef PortReg
    *csport |= cspinmask;
#else
    digitalWrite(cs, HIGH);
#endif
  }
  else
  {
    // I2C
    uint8_t control = 0x40;   // Co = 0, D/C = 1
    Wire.beginTransmission(_i2caddr);
    WIRE_WRITE(control);
    WIRE_WRITE(c);
    Wire.endTransmission();
  }
}
Beispiel #5
0
void ArduiPi_OLED::sendCommand(uint8_t c0, uint8_t c1, uint8_t c2) 
{ 
  char buff[4] ;
    
  buff[1] = c0;
  buff[2] = c1;
  buff[3] = c2;

  // Is SPI
  if (isSPI())
  {
    // Setup D/C line to low to switch to command mode
    bcm2835_gpio_write(dc, LOW);

    // Write Data
    fastSPIwrite(&buff[1], 3);
  }
  // I2C
  else
  {
    // Clear D/C to switch to command mode
    buff[0] = SSD_Command_Mode; 

    // Write Data on I2C
    fastI2Cwrite(buff, sizeof(buff))  ;
  }
}
Beispiel #6
0
void ArduiPi_OLED::sendData(uint8_t c) 
{
  // SPI
  if ( isSPI())
  {
    // SPI
    // Setup D/C line to high to switch to data mode
    bcm2835_gpio_write(dc, HIGH);

    // write value
    fastSPIwrite(c);
  }
  // I2C
  else
  {
    char buff[2] ;
    
    // Setup D/C to switch to data mode
    buff[0] = SSD_Data_Mode; 
    buff[1] = c;

    // Write on i2c
    fastI2Cwrite( buff, sizeof(buff)) ;
  }
}
void Adafruit_SSD1306::ssd1306_command(uint8_t c) {
    if (sid != -1)
    {
        // SPI
#ifdef HAVE_PORTREG
        *csport |= cspinmask;
        *dcport &= ~dcpinmask;
        *csport &= ~cspinmask;
#else
        digitalWrite(cs, HIGH);
        digitalWrite(dc, LOW);
        digitalWrite(cs, LOW);
#endif
        fastSPIwrite(c);
#ifdef HAVE_PORTREG
        *csport |= cspinmask;
#else
        digitalWrite(cs, HIGH);
#endif
    }
    else
    {
        // I2C
        uint8_t control = 0x00;   // Co = 0, D/C = 0
        Wire.beginTransmission(_i2caddr);
        Wire.write(control);
        Wire.write(c);
        Wire.endTransmission();
    }
}
void Adafruit_PCD8544::data(uint8_t c) {
  digitalWrite(_dc, HIGH);
  if (_cs > 0)
    digitalWrite(_cs, LOW);
  fastSPIwrite(c);
  if (_cs > 0)
    digitalWrite(_cs, HIGH);
}
Beispiel #9
0
void Adafruit_SSD1306::display(void) {
  ssd1306_command(SSD1306_COLUMNADDR);
  ssd1306_command(0);   // Column start address (0 = reset)
  ssd1306_command(SSD1306_LCDWIDTH-1); // Column end address (127 = reset)

  ssd1306_command(SSD1306_PAGEADDR);
  ssd1306_command(0); // Page start address (0 = reset)
  #if SSD1306_LCDHEIGHT == 64
    ssd1306_command(7); // Page end address
  #endif
  #if SSD1306_LCDHEIGHT == 32
    ssd1306_command(3); // Page end address
  #endif
  #if SSD1306_LCDHEIGHT == 16
    ssd1306_command(1); // Page end address
  #endif

  if (sid != -1)
  {
    // SPI
    *csport |= cspinmask;
    *dcport |= dcpinmask;
    *csport &= ~cspinmask;

    for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
      fastSPIwrite(buffer[i]);
      //ssd1306_data(buffer[i]);
    }
    *csport |= cspinmask;
  }
  else
  {
    // save I2C bitrate
#if !defined(__SAM3X8E__) && !defined(__ESP8266_EX__)
    uint8_t twbrbackup = TWBR;
    TWBR = 12; // upgrade to 400KHz!
#endif

    //Serial.println(TWBR, DEC);
    //Serial.println(TWSR & 0x3, DEC);

    // I2C
    for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
      // send a bunch of data in one xmission
      Wire.beginTransmission(_i2caddr);
      WIRE_WRITE(0x40);
      for (uint8_t x=0; x<16; x++) {
  WIRE_WRITE(buffer[i]);
  i++;
      }
      i--;
      Wire.endTransmission();
    }
#if !defined(__SAM3X8E__) && !defined(__ESP8266_EX__)
    TWBR = twbrbackup;
#endif
  }
}
void Adafruit_PCD8544::data(uint8_t c) {
  pinSetFast(_dc);  //DC HIGH
  //digitalWrite(_dc, HIGH);
  if (_cs > 0)
    pinResetFast(_cs);  //CS LOW
    //digitalWrite(_cs, LOW);
  fastSPIwrite(c);
  if (_cs > 0)
    pinSetFast(_cs);  //CS HIGH
    //digitalWrite(_cs, HIGH);
}
void Adafruit_PCD8544::display(void) {
  uint8_t col, maxcol, p;

  for(p = 0; p < 6; p++) {
#ifdef enablePartialUpdate
    // check if this page is part of update
    if ( yUpdateMin >= ((p+1)*8) ) {
      continue;   // nope, skip it!
    }
    if (yUpdateMax < p*8) {
      break;
    }
#endif

    command(PCD8544_SETYADDR | p);


#ifdef enablePartialUpdate
    col = xUpdateMin;
    maxcol = xUpdateMax;
#else
    // start at the beginning of the row
    col = 0;
    maxcol = LCDWIDTH-1;
#endif

    command(PCD8544_SETXADDR | col);

    digitalWrite(_dc, HIGH);
    if (_cs > 0)
      pinResetFast(_cs);  //CS LOW
      //digitalWrite(_cs, LOW);
    for(; col <= maxcol; col++) {
      //uart_putw_dec(col);
      //uart_putchar(' ');
      fastSPIwrite(pcd8544_buffer[(LCDWIDTH*p)+col]);
    }
    if (_cs > 0)
      pinSetFast(_cs);  //CS HIGH
      //digitalWrite(_cs, HIGH);

  }

  command(PCD8544_SETYADDR );  // no idea why this is necessary but it is to finish the last byte?
#ifdef enablePartialUpdate
  xUpdateMin = LCDWIDTH - 1;
  xUpdateMax = 0;
  yUpdateMin = LCDHEIGHT-1;
  yUpdateMax = 0;
#endif

}
void Adafruit_SSD1306::ssd1306_data(uint8_t c) {
  if (sid != -1)
  {
    // SPI
    digitalWrite(cs, HIGH);
    digitalWrite(dc, HIGH);
    digitalWrite(cs, LOW);
    fastSPIwrite(c);
    digitalWrite(cs, HIGH);
  }
  else
  {
    // I2C
    uint8_t control = 0x40;   // Co = 0, D/C = 1
    Wire.beginTransmission(_i2caddr);
    Wire.write(control);
    Wire.write(c);
    Wire.endTransmission();
  }
}
void Adafruit_SSD1306::display(void) {
  ssd1306_command(SSD1306_COLUMNADDR);
  ssd1306_command(0);   // Column start address (0 = reset)
  ssd1306_command(127); // Column end address (127 = reset)

  ssd1306_command(SSD1306_PAGEADDR);
  ssd1306_command(0); // Page start address (0 = reset)
  ssd1306_command((SSD1306_LCDHEIGHT == 64) ? 7 : 3); // Page end address

  if (sid != -1)
  {
    // SPI
    digitalWrite(cs, HIGH);
    digitalWrite(dc, HIGH);
    digitalWrite(cs, LOW);
	delayMicroseconds(1);		// May not be necessary - needs testing

    for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
      fastSPIwrite(buffer[i]);
      //ssd1306_data(buffer[i]);
    }
	delayMicroseconds(1);		// May not be necessary - needs testing
    digitalWrite(cs, HIGH);
  }
  else
  {
    // I2C
    for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
      // send a bunch of data in one xmission
      Wire.beginTransmission(_i2caddr);
      Wire.write(0x40);
      for (uint8_t x=0; x<16; x++) {
		Wire.write(buffer[i]);
		i++;
		}
	i--;
	Wire.endTransmission();
	}
  }
}
Beispiel #14
0
void ArduiPi_OLED::sendCommand(uint8_t c) 
{ 
  // Is SPI
  if (isSPI())
  {
    // Setup D/C line to low to switch to command mode
    bcm2835_gpio_write(dc, LOW);

    // Write Data on SPI
    fastSPIwrite(c);
  }
  // so I2C
  else
  {
    char buff[2] ;
    
    // Clear D/C to switch to command mode
    buff[0] = SSD_Command_Mode ; 
    buff[1] = c;
    
    // Write Data on I2C
    fastI2Cwrite(buff, sizeof(buff))  ;
  }
}
void Adafruit_SH1106::SH1106_data(uint8_t c) {
  if (sid != -1)
  {
    // SPI
    //digitalWrite(cs, HIGH);
    *csport |= cspinmask;
    //digitalWrite(dc, HIGH);
    *dcport |= dcpinmask;
    //digitalWrite(cs, LOW);
    *csport &= ~cspinmask;
    fastSPIwrite(c);
    //digitalWrite(cs, HIGH);
    *csport |= cspinmask;
  }
  else
  {
    // I2C
    uint8_t control = 0x40;   // Co = 0, D/C = 1
    Wire.beginTransmission(_i2caddr);
    WIRE_WRITE(control);
    WIRE_WRITE(c);
    Wire.endTransmission();
  }
}
Beispiel #16
0
void ArduiPi_OLED::display(void) 
{

#ifdef SEEED_I2C
  if (oled_type == OLED_SEEED_I2C_96x96 )
  {
    sendCommand(SSD1327_Set_Row_Address   , 0x00, 0x5F);
    sendCommand(SSD1327_Set_Column_Address, 0x08, 0x37);
  }
  else
#endif
  {
    sendCommand(SSD1306_Set_Lower_Column_Start_Address  | 0x0); // low col = 0
    sendCommand(SSD1306_Set_Higher_Column_Start_Address | 0x0); // hi col = 0
    sendCommand(SSD1306_Set_Start_Line  | 0x0); // line #0
  }

  uint16_t i=0 ;
  
  // pointer to OLED data buffer
  uint8_t * p = poledbuff;

  // SPI
  if ( isSPI())
  {
    // Setup D/C line to high to switch to data mode
    bcm2835_gpio_write(dc, HIGH);

    // Send all data to OLED
    for ( i=0; i<oled_buff_size; i++) 
    {
      fastSPIwrite(*p++);
    }

    // I wonder why we have to do this (check datasheet)
    if (oled_height == 32) 
    {
      for (uint16_t i=0; i<oled_buff_size; i++) 
      {
        fastSPIwrite(0);
      }
    }
    
  }
  // I2C
  else 
  {
    char buff[17] ;
    uint8_t x ;

    // Setup D/C to switch to data mode
    buff[0] = SSD_Data_Mode; 
    
    if (oled_type == OLED_SH1106_I2C_128x64)
    {
      for (uint8_t k=0; k<8; k++) 
      {
        sendCommand(0xB0+k);//set page addressSSD_Data_Mode;
        sendCommand(0x02) ;//set lower column address
        sendCommand(0x10) ;//set higher column address

       for( i=0; i<8; i++)
       {
          for (x=1; x<=16; x++) 
            buff[x] = *p++;

          fastI2Cwrite(buff, 17);
        }
      }
    }
    else
    {
      // loop trough all OLED buffer and 
      // send a bunch of 16 data byte in one xmission
      for ( i=0; i<oled_buff_size; i+=16 ) 
      {
        for (x=1; x<=16; x++) 
          buff[x] = *p++;

        fastI2Cwrite(buff, 17);
      }
    }
  }
}
void Adafruit_SH1106::display(void) {
	SH1106_command(SH1106_SETLOWCOLUMN | 0x0);  // low col = 0
	SH1106_command(SH1106_SETHIGHCOLUMN | 0x0);  // hi col = 0
	SH1106_command(SH1106_SETSTARTLINE | 0x0); // line #0

  if (sid != -1)
  {
    // SPI
    *csport |= cspinmask;
    *dcport |= dcpinmask;
    *csport &= ~cspinmask;

    for (uint16_t i=0; i<(SH1106_LCDWIDTH*SH1106_LCDHEIGHT/8); i++) {
      fastSPIwrite(buffer[i]);
      //SH1106_data(buffer[i]);
    }
    *csport |= cspinmask;
  }
  else
  {
    // save I2C bitrate
#ifndef __SAM3X8E__
    uint8_t twbrbackup = TWBR;
    TWBR = 12; // upgrade to 400KHz!
#endif

    //Serial.println(TWBR, DEC);
    //Serial.println(TWSR & 0x3, DEC);
	
	byte x=0;
	byte y=0;
	int ind=0;

    // I2C
/*     for (uint16_t i=0; i<(SH1106_LCDWIDTH*SH1106_LCDHEIGHT/8); i++) { //1024
      // send a bunch of data in one xmission
      Wire.beginTransmission(_i2caddr);
      WIRE_WRITE(0x40);
      for (uint8_t x=0; x<16; x++) {
		  WIRE_WRITE(buffer[i]);
		  i++;
      }
      i--;
      Wire.endTransmission();
    } */
	
	for (byte i = 0; i < 8; i++) { //8
      // send a bunch of data in one xmission
        SH1106_command(0xB0 + i + y);//set page address
        SH1106_command((x + 2) & 0xf);//set lower column address
        SH1106_command(0x10 | (x >> 4));//set higher column address

        for(byte j = 0; j < 8; j++){
            Wire.beginTransmission(_i2caddr);
            Wire.write(0x40);
            for (byte k = 0; k < 16; k++) { //16
                WIRE_WRITE(buffer[ind]);
				ind++;
            }
            Wire.endTransmission();
        }
    }
	
#ifndef __SAM3X8E__
    TWBR = twbrbackup;
#endif
  }
}
void Adafruit_SSD1306::display(void) {
  ssd1306_command(SSD1306_COLUMNADDR);
 #if SSD1306_LCDWIDTH == 64 && SSD1306_LCDHEIGHT == 48
    ssd1306_command(32);
    ssd1306_command(32 + SSD1306_LCDWIDTH - 1);
  #else
    ssd1306_command(0);   // Column start address (0 = reset)
    ssd1306_command(SSD1306_LCDWIDTH-1); // Column end address (127 = reset)
#endif
  ssd1306_command(SSD1306_PAGEADDR);
  ssd1306_command(0); // Page start address (0 = reset)
  ssd1306_command((SSD1306_LCDHEIGHT / 8) - 1); // Page end address

  if (sid != -1)
  {
    // SPI
#ifdef HAVE_PORTREG
    *csport |= cspinmask;
    *dcport |= dcpinmask;
    *csport &= ~cspinmask;
#else
    digitalWrite(cs, HIGH);
    digitalWrite(dc, HIGH);
    digitalWrite(cs, LOW);
#endif

    for (uint16_t i=0; i<(SSD1306_FRAMEBUFFER); i++) {
      fastSPIwrite(buffer[i]);
    }
#ifdef HAVE_PORTREG
    *csport |= cspinmask;
#else
    digitalWrite(cs, HIGH);
#endif
  }
  else
  {
    // save I2C bitrate
#ifdef TWBR
    uint8_t twbrbackup = TWBR;
    TWBR = 12; // upgrade to 400KHz!
#endif

    //Serial.println(TWBR, DEC);
    //Serial.println(TWSR & 0x3, DEC);

    // I2C
    for (uint16_t i=0; i<(SSD1306_FRAMEBUFFER); i++) {
      // send a bunch of data in one xmission
      Wire.beginTransmission(_i2caddr);
      WIRE_WRITE(0x40);
      for (uint8_t x=0; x<16; x++) {
        WIRE_WRITE(buffer[i]);
        i++;
      }
      i--;
      Wire.endTransmission();
    }
#ifdef TWBR
    TWBR = twbrbackup;
#endif
  }
}
void ESP_SSD1306::display(void) {
  ssd1306_command(SSD1306_COLUMNADDR);
  ssd1306_command(0);   // Column start address (0 = reset)
  ssd1306_command(SSD1306_LCDWIDTH-1); // Column end address (127 = reset)

  ssd1306_command(SSD1306_PAGEADDR);
  ssd1306_command(0); // Page start address (0 = reset)
  #if SSD1306_LCDHEIGHT == 64
    ssd1306_command(7); // Page end address
  #endif
  #if SSD1306_LCDHEIGHT == 32
    ssd1306_command(3); // Page end address
  #endif
  #if SSD1306_LCDHEIGHT == 16
    ssd1306_command(1); // Page end address
  #endif

  if (sid != -1)
  {
	// SPI
    digitalWrite(cs, HIGH);		//added for ESP8266 compatibility
//	*csport |= cspinmask;		//commented for ESP8266 compatibility
    digitalWrite(dc, HIGH);		//added for ESP8266 compatibility
//	*dcport |= dcpinmask;		//commented for ESP8266 compatibility
    digitalWrite(cs, LOW);		//added for ESP8266 compatibility
//	*csport &= ~cspinmask;		//commented for ESP8266 compatibility

	for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
	  fastSPIwrite(buffer[i]);
      //ssd1306_data(buffer[i]);
	}
    digitalWrite(cs, HIGH);		//added for ESP8266 compatibility
//	*csport |= cspinmask;		//commented for ESP8266 compatibility
  }
  else
  {
    // save I2C bitrate
#ifndef __SAM3X8E__
//    uint8_t twbrbackup = TWBR;			//commented for ESP8266 compatibility
//    TWBR = 12; // upgrade to 400KHz!		//commented for ESP8266 compatibility
#endif

    //Serial.println(TWBR, DEC);
    //Serial.println(TWSR & 0x3, DEC);

    // I2C
    for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
      // send a bunch of data in one xmission
      Wire.beginTransmission(_i2caddr);
      WIRE_WRITE(0x40);
      for (uint8_t x=0; x<16; x++) {
  WIRE_WRITE(buffer[i]);
  i++;
      }
      i--;
      Wire.endTransmission();
      yield();
    }
#ifndef __SAM3X8E__
//    TWBR = twbrbackup;					//commented for ESP8266 compatibility
#endif
  }
}
void Adafruit_SSD1306::display(void) {
  ssd1306_command(SSD1306_SETLOWCOLUMN | 0x0);  // low col = 0
  ssd1306_command(SSD1306_SETHIGHCOLUMN | 0x0);  // hi col = 0
  ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0

  if (sid != -1)
  {
    // SPI
    *csport |= cspinmask;
    *dcport |= dcpinmask;
    *csport &= ~cspinmask;

    for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
      fastSPIwrite(buffer[i]);
      //ssd1306_data(buffer[i]);
    }
    // i wonder why we have to do this (check datasheet)
    if (SSD1306_LCDHEIGHT == 32) {
      for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
        //ssd1306_data(0);
        fastSPIwrite(0);
      }
    }
    *csport |= cspinmask;
  }
  else
  {
    // save I2C bitrate
    uint8_t twbrbackup = TWBR;
    TWBR = 12; // upgrade to 400KHz!

    //Serial.println(TWBR, DEC);
    //Serial.println(TWSR & 0x3, DEC);

    // I2C
    for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
      // send a bunch of data in one xmission
      Wire.beginTransmission(_i2caddr);
      Wire.write(0x40);
      for (uint8_t x=0; x<16; x++) {
	Wire.write(buffer[i]);
	i++;
      }
      i--;
      Wire.endTransmission();
    }
    // i wonder why we have to do this (check datasheet)
    if (SSD1306_LCDHEIGHT == 32) {
      for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
	// send a bunch of data in one xmission
	Wire.beginTransmission(_i2caddr);
	Wire.write(0x40);
	for (uint8_t x=0; x<16; x++) {
	  Wire.write((uint8_t)0x00);
	  i++;
	}
	i--;
	Wire.endTransmission();
      }
    }
    TWBR = twbrbackup;
  }
}