OPENSMART 2,8 TFT Change PINOUT on UNO

Using UNO Rev3 and opensmart tft 2.8" tuchscreen. I know shields are designed to be plugged into the header with the defaults pinout, but I want to drive a rgb led with the left over pins that the shield does not use. To change the state need PWM pins and there are only 2 (DIO03 and DIO05) that the shield is not using. Figured I could edit mcufriend_special.h to turn off DIO06 and turn on DIO12. No plans to use the SD card. I did but only get white screen.
Does the mask defines below need to be modified?

#elif defined(__AVR_ATmega328P__) && defined(USE_OPENSMART_SHIELD_PINOUT_UNO)
/*
PORTB        0b    PORTD      0b
XTAL1 - PB7 - 0	   D07 - PD7 - 1
XTAL2 - PB6 - 0    D06 - PD6 - 1 move to D12 - PB4
D13   - PB5 - 1    D05 - PD5 - 0	
D12   - PB4 - 0    D04 - PD4 - 1   
D11   - PB3 - 1    D03 - PD3 - 0   
D10   - PB2 - 1    D02 - PD2 - 0   
D09   - PB1 - 1    D01 - PD1 - 0  
D08   - PB0 - 1    D00 - PD0 - 0
//change TFT D6 from D06 to D12 to free up PWM for rgb LED
XTAL1 - PB7 - 0	   D07 - PD7 - 1
XTAL2 - PB6 - 0    D06 - PD6 - 0 move to D12 - PB4
D13   - PB5 - 1    D05 - PD5 - 0	
D12   - PB4 - 1    D04 - PD4 - 1   
D11   - PB3 - 1    D03 - PD3 - 0   
D10   - PB2 - 1    D02 - PD2 - 0   
D09   - PB1 - 1    D01 - PD1 - 0  
D08   - PB0 - 1    D00 - PD0 - 0

#define BMASK         0x2F   // B00111111
#define DMASK         0xD0   // B10010000
*/
#define RD_PORT PORTC
#define RD_PIN  0
#define WR_PORT PORTC
#define WR_PIN  1
#define CD_PORT PORTC
#define CD_PIN  2
#define CS_PORT PORTC
#define CS_PIN  3
#define RESET_PORT PORTC
#define RESET_PIN  1  // n/a. so mimic WR_PIN

//#define BMASK       B00101111 //PORTB - 0b00101111 = 0x2F
//#define DMASK       B11010000 //PORTD - 0b11010000 = 0xD0
#define BMASK         B00111111 //0x3F
#define DMASK         B10010000 //0x90

#define write_8(x) {                          \
        PORTD = (PORTD & ~DMASK) | ((x) & DMASK); \
        PORTB = (PORTB & ~BMASK) | ((x) & BMASK);} // STROBEs are defined later

#define read_8()   ((PIND & DMASK) | (PINB & BMASK))

#define setWriteDir() { DDRD |=  DMASK; DDRB |=  BMASK; }
#define setReadDir()  { DDRD &= ~DMASK; DDRB &= ~BMASK; }


#define write8(x)     { write_8(x); WR_STROBE; }
#define write16(x)    { uint8_t h = (x)>>8, l = x; write8(h); write8(l); }
#define READ_8(dst)   { RD_STROBE; dst = read_8(); RD_IDLE; }
#define READ_16(dst)  { uint8_t hi; READ_8(hi); READ_8(dst); dst |= (hi << 8); }

#define PIN_LOW(p, b)        (p) &= ~(1<<(b))
#define PIN_HIGH(p, b)       (p) |= (1<<(b))
#define PIN_OUTPUT(p, b)     *(&p-1) |= (1<<(b))

Your read_8() and write_8() macros are wrong.

okay, what is wrong and what would be correct?

Surely that is an exercise for the reader.

Look at other drive blocks. i.e. targets with data bus on random pins.

Looks like a good deal of shifting needs to be done. I can barely make out what the code is doing and have no idea what bits need to be shifted. Any help would be appreciated.

#elif defined(__AVR_ATmega328P__) && defined(USE_OPENSMART_SHIELD_PINOUT_JAYDIENER)
//LCD pins  |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 | |RD |WR |RS |CS |RST|
//AVR   pin |PD7|PD4|PB5|PB4|PB3|PB2|PB1|PB0| |PC0|PC1|PC2|PC3|PD2|
//UNO pins  |7  |4  |13 |12 |11 |10 |9  |8  | |A0 |A1 |A2 |A3 |2  |
#define BMASK         0b00111111
#define DMASK         0b10010000

#define write_8(x) {                          \
        PORTD = (PORTD & ~DMASK) | ((x) & (1<<7) | (((x) & (1<<6)) >> 2); \
        PORTB = (PORTB & ~BMASK) | ((x) & BMASK);} // STROBEs are defined later

#define read_8()   ((PIND & (1<<7)) |((PIND &(1<<4))<<2)| (PINB & BMASK))

You don't provide a link to the actual screen that you have bought. Obviously you have to provide your own level shift buffers if you have bought a 5V shield.

David.

The read/write edits work. The is a missing ")", but that was easily corrected.

Can you explain a little what is going on with the data pins?

I understand that the digital pins cannot be configurable within reason of speed and coding. Which makes it quite handy to be able to change the pin by understanding the macro bit shifting. I think my issue is more that I do not know what certain code means.

For example "(1<<7)" means to move a 1 left 7 bits? What is the reference for the 1?
Allot of bit operators to keep track of.
In the end is the goal to move the pin in the mask and also change the read/write to produce the original mask?

Thanks for your help.

The Uno and the AIR mix PORTB and PORTD bits but they are always in order e.g. bit6 is either on PB6 or on PD6.

Because you have moved bit6 to PD4 it means that you have to extract bit6 and shift it 2 places to fit in PD4.

My apologies about the unmatched parentheses. I just typed straight into the Browser. And this new Forum software is pretty horrible for lining up expressions.

If you are unhappy with bit expressions I suggest that you do some practice with pencil and paper.
Convert everything to full 8 bits binary values,
Line them up vertically. Then you can AND, OR, XOR easily.
With experience you can work in hexadecimal. No one can do Boolean algebra with decimals.

David.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.