Altering a ST7781R TFT Library to work w/ ATmega328P (nano)

I recently purchased a 2.8" TFT Touch Shield (The Seeed variety) from Radioshack, scrounged the web for a good library for ST7781R and got it working wonderfully with my Arduino Mega2560.

I now have a clone Arduino Nano (DCCduino), and would like to connect the same display. So far I have wired the power, reset, and touch screen with a little experimentation and they seem to be working fine.

I am now running into a lack of experience issue where the pin definitions for /cs, cd, wr, and rd are created in the libraries and not in the code. Generally, I think I know where they are being defined, but I don't know how to correctly alter the library for these controls and for the 8 data wires.

Some code:

Part of TFT.h:

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
//==================/CS=====================
#define DDR_CS      DDRB
#define PORT_CS     PORTB
#define CS_BIT      0x10
#define CS_OUTPUT   {DDR_CS|=CS_BIT;}
#define CS_HIGH     {PORT_CS|=CS_BIT;}
#define CS_LOW      {PORT_CS&=~CS_BIT;}

//------------------RS----------------------

#define DDR_RS      DDRB
#define PORT_RS     PORTB
#define RS_BIT      0x20
#define RS_OUTPUT   {DDR_RS|=RS_BIT;}
#define RS_HIGH     {PORT_RS|=RS_BIT;}
#define RS_LOW      {PORT_RS&=~RS_BIT;}

//------------------WR----------------------

#define DDR_WR      DDRB
#define PORT_WR     PORTB
#define WR_BIT      0x40
#define WR_OUTPUT   {DDR_WR|=WR_BIT;}
#define WR_HIGH     {PORT_WR|=WR_BIT;}
#define WR_LOW      {PORT_WR&=~WR_BIT;}
#define WR_RISING   {PORT_WR|=WR_BIT;PORT_WR&=~WR_BIT;}

Seems to define how cs,rs,wr, and rd are handled for certain boards. The only thing differing between this and other boards definitions, (seeeduino is next for example), is this part of each (cs,rs,wr,rd):

#define RD_BIT      0x80

In TFT.cpp there are several areas which appear board specific, but I will list the first function:

#ifdef MEGA

    PORTE |= ((data<<4) & (0x30));
    PORTG |= ((data<<3) & (0x20));
    PORTE |= ((data & 0x08));
    PORTH |= ((data>>1) & (0x78));
#endif

It looks like this is setting ports, but I have almost no experience with C++, and haven't found an good resources on my specific problem.

Is it possible to do this without knowing too much detail about the lcd driver and the mcu? (Do I have to write my own library from scratch?)

The full libraries are in the link above, hopefully someone is willing to look over this with me and determine at the very least if it is feasible to alter the existing library. Please have patience I am def. still very green :grin:

dbugs:
::::SNIP::::
In TFT.cpp there are several areas which appear board specific, but I will list the first function:

#ifdef MEGA

PORTE |= ((data<<4) & (0x30));
    PORTG |= ((data<<3) & (0x20));
    PORTE |= ((data & 0x08));
    PORTH |= ((data>>1) & (0x78));
#endif




It looks like this is setting ports, but I have almost no experience with C++, and haven't found an good resources on my specific problem.

dbugs,
it is NOT setting ports. It is doing a shift of 'data' and extracting some bits. What exactly it is meant to do is hard to say without looking at the whole code section.

Is it possible to do this without knowing too much detail about the lcd driver and the mcu? (Do I have to write my own library from scratch?)

The full libraries are in the link above, hopefully someone is willing to look over this with me and determine at the very least if it is feasible to alter the existing library. Please have patience I am def. still very green :grin:

To do this you do need to know about the LCD, possible the driver, but not the mcu (that's why we have this C++ programming language)

I looked over the code. I can't help you. There is not enough documentation on this. Basically, you should be able to take this library and use it. However, you got to have a similar design.

Your best course of action is to ask the guys at SEEED. They can tell you pretty quickly what you can do, and how much time it should take.

The larger part for me is not programming, but understanding the hardware, how it attaches, how to talk to it. Otherwise, it's simple.

Good Luck,
come back and ask when you have an answer from SEEED.

Jesse