Help understanding SPI controls

Hi guys

Im Getting pretty close to finishing my game console library but I'm stuck at the SPI stuff. The original library uses a different set of SPI code functions than my new screen but both use the same pinouts but the labels are different.

So what I'm asking is....... Can I use the SPI code from the original Gamebuino library or do I have to use the SPI code that came with my oled.

Without seeing your code ....

...R

sorry thought it was a more generalized question. I cant fit all this into one post but here it goes

from lcd's .cpp

LCD_2000_7775::LCD_2000_7775(uint8_t cs,uint8_t wr ,uint8_t rs , uint8_t rest ,uint8_t pmw)
	: Adafruit_GFX(176, 220)
{
	this->_cs = cs;
	//this->_rd = rd;
	this->_wr = wr;
	this->_rs = rs;
	this->_rest = rest;
	this->_pmw = pmw;
	
	pinMode(this->_cs,OUTPUT);
	//pinMode(this->_rd,OUTPUT);
	pinMode(this->_wr,OUTPUT);
	pinMode(this->_rs,OUTPUT);
	pinMode(this->_rest,OUTPUT);
	pinMode(this->_pmw,OUTPUT);
	
	
	this->csport = portOutputRegister(digitalPinToPort(this->_cs));
	//this->pmwport = portOutputRegister(digitalPinToPort(this->_pmw));
	this->wrport = portOutputRegister(digitalPinToPort(this->_wr));
	this->rsport = portOutputRegister(digitalPinToPort(this->_rs));
	this->restport = portOutputRegister(digitalPinToPort(this->_rest));
	
	
	this->cspinmask  = digitalPinToBitMask(this->_cs);
	//this->pmwpinmask  = digitalPinToBitMask(this->_pmw);
	this->wrpinmask  = digitalPinToBitMask(this->_wr);
	this->rspinmask  = digitalPinToBitMask(this->_rs);
	this->restpinmask  = digitalPinToBitMask(this->_rest);
	
	*(this->csport) |= this->cspinmask;
	//*(this->pmwport) |= this->pmwpinmask;
	*(this->wrport) |= this->wrpinmask;
	*(this->rsport) |= this->rspinmask;
	*(this->restport) |= this->restpinmask;		
}

lcd's .cpp

void LCD_2000_7775::begin()
{
		if( this->_rest )
		{
			 	*(this->restport) &= (~this->restpinmask);					
			 	delay(50); //     Delay 50ms
			 	*(this->restport) |= this->restpinmask;		
			 	delay(10); //     Delay 10ms
		}
	
		this->write_cmd(0x0001, 0x011C); // set SS and NL bit
    this->write_cmd(0x0002, 0x0100); // set 1 line inversion
    this->write_cmd(0x0003, 0x1030); // set GRAM write direction and BGR=1,??16BIT 65K?MDT1=0,MDT0=0
    this->write_cmd(0x0008, 0x0808); // set BP and FP
    this->write_cmd(0x000C, 0x0000); // RGB interface setting R0Ch=0x0110 for RGB 18Bit and R0Ch=0111for

    this->write_cmd(0x000F, 0x0e01); // Set frame rate
   
//*************Power On sequence ****************//
    delay(50); //     Delay 50ms
    this->write_cmd(0x0010, 0x0A00); // Set SAP,DSTB,STB
    this->write_cmd(0x0011, 0x1038); // Set APON,PON,AON,VCI1EN,VC
    //delay(50); //     Delay 50ms
    this->write_cmd(0x00ff, 0x0003);    //
    this->write_cmd(0x00b0, 0x1411);    //Set VCOM 1d
    this->write_cmd(0x00b1, 0x0202);    //GVCL/GVDD voltage setting
    this->write_cmd(0x00b2, 0x0313);  //VCL voltage setting

//------------------------ Set GRAM area  set window --------------------------------//
    this->write_cmd (0x0030, 0x0000);//???????
    this->write_cmd (0x0031, 0x00db);
    this->write_cmd (0x0032, 0x0000);
    this->write_cmd (0x0033, 0x0000);//??????
    this->write_cmd (0x0034, 0x00db);
    this->write_cmd (0x0035, 0x0000);//R34H,R35H???????
    this->write_cmd (0x0036, 0x00AF);
    this->write_cmd (0x0037, 0x0000);
    this->write_cmd (0x0038, 0x00DB);
    this->write_cmd (0x0039, 0x0000);
    delay(20);
   
    this->write_cmd(0x00ff, 0x0003);
//    WriteRegister(0x00b0, 0x1d01);
// ----------- Adjust the Gamma Curve ----------//
     this->write_cmd(0x0050, 0x0000);
     this->write_cmd(0x0051, 0x0300);
     this->write_cmd(0x0052, 0x0103);
     this->write_cmd(0x0053, 0x2011);
     this->write_cmd(0x0054, 0x0703);
     this->write_cmd(0x0055, 0x0000);
     this->write_cmd(0x0056, 0x0400);
     this->write_cmd(0x0057, 0x0107);
     this->write_cmd(0x0058, 0x2011);
     this->write_cmd(0x0059, 0x0703);
     delay(50); //     Delay 50ms
     this->write_cmd(0x0020, 0x0000); // Set GRAM Address
     this->write_cmd(0x0021, 0x0000); // Set GRAM Address
     this->write_cmd(0x0007, 0x1017);
	
		
		this->fillRect(0,0,LCD_2000_7775_TFTWIDTH,LCD_2000_7775_TFTHEIGHT,0xffff);
}

lcd's .cpp

void LCD_2000_7775::write_spi(const uint8_t data)
{
	uint8_t bit,i;
	for(bit = 0x01,i = 0 ; bit ; i++,bit <<= 1)	
	{
		if(data & bit) *(this->dataport[i]) |= this->datapinmask[i];
    else   *(this->dataport[i]) &= (~this->datapinmask[i]);
    	
    //write_delay();
  }
}

lcd's .h

LCD_2000_7775(uint8_t cs,uint8_t wr ,uint8_t rs , uint8_t rest ,uint8_t pmw );

void write_spi(const uint8_t data);


#if defined(ARDUINO_ARCH_SAM)
		uint32_t _cs;
		uint32_t _pmw;
		uint32_t _wr;
		uint32_t _rs;
		uint32_t _rest;
		
		volatile uint32_t *csport;
		volatile uint32_t *pmwport;
		volatile uint32_t *wrport;
		volatile uint32_t *rsport;
		volatile uint32_t *restport;
		
		uint32_t cspinmask;
		uint32_t pmwpinmask;
		uint32_t wrpinmask;
		uint32_t rspinmask;
		uint32_t restpinmask;
		
		volatile uint32_t data[8];
		volatile uint32_t datapinmask[8];
		volatile uint32_t* dataport[8];	
			
	#else
		uint8_t _cs;
		uint8_t _pmw;
		uint8_t _wr;
		uint8_t _rs;
		uint8_t _rest;
		
		volatile uint8_t *csport;
		volatile uint8_t *pmwport;
		volatile uint8_t *wrport;
		volatile uint8_t *rsport;
		volatile uint8_t *restport;
		
		uint8_t cspinmask;
		uint8_t pmwpinmask;
		uint8_t wrpinmask;
		uint8_t rspinmask;
		uint8_t restpinmask;
		
		volatile uint8_t data[8];
		volatile uint8_t datapinmask[8];
		volatile uint8_t* dataport[8];
	
	#endif

from gamebuino displa.h

void begin(int8_t SCLK, int8_t DIN, int8_t DC, int8_t CS, int8_t RST);

from gamebuino display cpp

void Display::begin(int8_t SCLK, int8_t DIN, int8_t DC, int8_t CS, int8_t RST) {
    din = DIN;
    sclk = SCLK;
    dc = DC;
    rst = RST;
    cs = CS;

    //cursorY = cursorX = 0;
    fontSize = 1;
    color = BLACK;
	bgcolor = WHITE;
    textWrap = true;
	setFont(font3x5);
	//persistence = false;

    SPI.begin();
    SPI.setBitOrder(MSBFIRST);
    SPI.setClockDivider(SPI_CLOCK_DIV8); //can be set to 4 but some random pixels will start to appear on some displays
    SPI.setDataMode(SPI_MODE3);
    // set pin directions
    pinMode(din, OUTPUT);
    pinMode(sclk, OUTPUT);
    pinMode(dc, OUTPUT);
    if (rst > 0)
        pinMode(rst, OUTPUT);
    if (cs > 0)
        pinMode(cs, OUTPUT);

    // toggle RST low to reset
    if (rst > 0) {
        digitalWrite(rst, LOW);
        delay(10);
        digitalWrite(rst, HIGH);
    }

    clkport = portOutputRegister(digitalPinToPort(sclk));
    clkpinmask = digitalPinToBitMask(sclk);
    mosiport = portOutputRegister(digitalPinToPort(din));
    mosipinmask = digitalPinToBitMask(din);
    csport = portOutputRegister(digitalPinToPort(cs));
    cspinmask = digitalPinToBitMask(cs);
    dcport = portOutputRegister(digitalPinToPort(dc));
    dcpinmask = digitalPinToBitMask(dc);

    // get into the EXTENDED mode!
    command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION);

    // LCD bias select (4 is optimal?)
    command(PCD8544_SETBIAS | 0x4);

    // set VOP
    if (contrast > 0x7f)
        contrast = 0x7f;

    command(PCD8544_SETVOP | contrast); // Experimentally determined


    // normal mode
    command(PCD8544_FUNCTIONSET);

    // Set display to Normal
    command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL);

    // initial display line
    // set page address
    // set column address
    // write display data

    update();
}
void Display::command(uint8_t c) {
    noInterrupts();
    digitalWrite(dc, LOW);
    if (cs > 0)
        digitalWrite(cs, LOW);
    SPI.transfer((char) c);
    if (cs > 0)
        digitalWrite(cs, HIGH);
    interrupts();
}

void Display::data(uint8_t c) {
    noInterrupts();
    digitalWrite(dc, HIGH);
    if (cs > 0)
        digitalWrite(cs, LOW);
    SPI.transfer((char) c);
    if (cs > 0)
        digitalWrite(cs, HIGH);
    interrupts();
}

When your code is too long you can add your .ino file as an attachment. I am not going to join all those pieces as I might make a mistake doing so.

...R

You have answered you own question by looking at the constructor code.
Be aware that some "libraries" have configuration code to make them adaptable to different processors - AVR, Due ,etc. and or shields.
Good luck.
Jim

Decided to just use the LCD's original source but with all the needed functions from gfx. That way theres no question about the spi.

Pretty far along, im now correcting the main gamebuino.cpp file to accept the new stuff which means alot of commenting out un-used bits.

I figure after i fix all those bugs so thr gamebuino is compatible or vice versa, i can then start workinh on getting the tilemap fixed.

I also need to to make an update function for the display.