Go Down

Topic: MCUFRIEND_kbv Library for Uno 2.4, 2.8, 3.5, 3.6, 3.95 inch mcufriend Shields (Read 440508 times) previous topic - next topic

david_prentice

@ZinggJM,

Here is a SPECIAL for a DUE

Code: [Select]

#define USE_TIKY_ON_DUE
...
#elif defined(__SAM3X8E__) && defined(USE_TIKY_ON_DUE)  //TIKY_ON_DUE
#warning USE_TIKY_ON_DUE
#define USES_16BIT_BUS
// configure macros for the control pins
#define RD_PORT PIOD
#define RD_PIN  0      //D25 PD0
#define WR_PORT PIOA
#define WR_PIN  15      //D24 PA15
#define CD_PORT PIOA
#define CD_PIN  14      //D23 PA14
#define CS_PORT PIOB
#define CS_PIN  26      //D22 PB26
#define RESET_PORT PIOD
#define RESET_PIN  1   //D26 PD1
// configure macros for data bus
//
#define AMASK         ((1<<7)|(1<<19))         //PA7, PA19
#define CMASK         (0x1FF<<1)               //PC1-PC9
#define DMASK         ((3<<2)|(1<<6)|(3<<9))   //PD2-PD3, PD6, PD9-PD10

#define write_16(x)   { PIOA->PIO_CODR = AMASK; PIOC->PIO_CODR = CMASK; PIOD->PIO_CODR = DMASK; \
        PIOD->PIO_SODR = (((x)&(3<<0))<<2); \
        PIOD->PIO_SODR = (((x)&(1<<2))<<4); \
        PIOD->PIO_SODR = (((x)&(1<<3))<<6); \
        PIOA->PIO_SODR = (((x)&(1<<4))<<3); \
        PIOD->PIO_SODR = (((x)&(1<<5))<<5); \
        PIOC->PIO_SODR = (((x)&(0x1FF<<6))>>5); \
        PIOA->PIO_SODR = (((x)&(1<<15))<<4); \
    }

#define read_16()     ( 0\
                        |((PIOD->PIO_PDSR & (1<<2))>>2)\
                        |((PIOD->PIO_PDSR & (1<<3))>>2)\
                        |((PIOD->PIO_PDSR & (1<<6))>>4)\
                        |((PIOD->PIO_PDSR & (1<<9))>>6)\
                        |((PIOA->PIO_PDSR & (1<<7))>>3)\
                        |((PIOD->PIO_PDSR & (1<<10))>>5)\
                        |((PIOC->PIO_PDSR & (0x1FF<<1))<<5)\
                        |((PIOA->PIO_PDSR & (1<<19)>>4))\
                      )
#define read_8()      (read_16() & 0xFF)
#define setWriteDir() {\
        PIOA->PIO_OER = AMASK; PIOA->PIO_PER = AMASK; \
        PIOC->PIO_OER = CMASK; PIOC->PIO_PER = CMASK; \
        PIOD->PIO_OER = DMASK; PIOD->PIO_PER = DMASK; \
    }
#define setReadDir()  { \
        PMC->PMC_PCER0 = (1 << ID_PIOA)|(1 << ID_PIOC)|(1 << ID_PIOD); \
        PIOA->PIO_ODR = AMASK; \
        PIOC->PIO_ODR = CMASK; \
        PIOD->PIO_ODR = DMASK; \
    }
#define write8(x)     { write16(x & 0xFF); }
// ILI9486 is slower than ILI9481
#define write16(x)    { write_16(x); WR_ACTIVE; WR_ACTIVE; WR_STROBE; }
#define READ_16(dst)  { RD_STROBE; RD_ACTIVE; RD_ACTIVE; RD_ACTIVE; RD_ACTIVE; dst = read_16(); RD_IDLE; RD_IDLE; RD_IDLE; }
#define READ_8(dst)   { READ_16(dst); dst &= 0xFF; }

// Shield Control macros.
#define PIN_LOW(port, pin)    (port)->PIO_CODR = (1<<(pin))
#define PIN_HIGH(port, pin)   (port)->PIO_SODR = (1<<(pin))
#define PIN_OUTPUT(port, pin) (port)->PIO_OER = (1<<(pin))



UNTESTED.

David.

david_prentice

@ZinggJM,

Here is a SPECIAL for your STM32F103V
Code: [Select]

#define USE_XINGGJM_BLUEDEV
...
// #################################### XINGIJM #######################################
#elif defined(__STM32F1__) && defined(USE_XINGGJM_BLUEDEV) // Uno Shield on Blue Controller board
#warning Uno Shield on USE_XINGJM_BLUEDEV
#define USES_16BIT_BUS
// be wise to clear all four mode bits properly.
#define GROUP_MODE(port, reg, mask, val)  {port->regs->reg = (port->regs->reg & ~(mask)) | ((mask)&(val)); }
#define GP_OUT(port, reg, mask)           GROUP_MODE(port, reg, mask, 0x33333333)
#define GP_INP(port, reg, mask)           GROUP_MODE(port, reg, mask, 0x44444444)

#define RD_PORT GPIOB
#define RD_PIN  13
#define WR_PORT GPIOD
#define WR_PIN  5
#define CD_PORT GPIOD
#define CD_PIN  11
#define CS_PORT GPIOD
#define CS_PIN  7
#define RESET_PORT GPIOD
#define RESET_PIN  13

// configure macros for the data pins
#define write_16(d) { \
        GPIOD->regs->BSRR = (0xC703) << 16; \
        GPIOE->regs->BSRR = (0xFF80) << 16; \
        GPIOD->regs->BSRR = 0 \
                            | (((d) & (3<<0)) << 14) \
                            | (((d) & (3<<2)) >> 2) \
                            | (((d) & (7<<13)) >> 5); \
        GPIOE->regs->BSRR = 0 \
                            | (((d) & (0x1FF<<4)) << 3); \
    }

#define read_16 (          (((GPIOD->regs->IDR & (3<<14)) >> 14) \
                            | ((GPIOD->regs->IDR & (3<<0)) << 2) \
                            | ((GPIOE->regs->IDR & (0x1FF<<7)) >> 3) \
                            | ((GPIOD->regs->IDR & (7<<13)) >> 5)))

//                                    PD15-14,PD10-8                         PD1-PD0                        PE15-PE8                     PE7
#define setWriteDir() {GP_OUT(GPIOD, CRH, 0xFF000FFF); GP_OUT(GPIOD, CRL, 0x000000FF); GP_OUT(GPIOE, CRH, 0xFFFFFFFF); GP_OUT(GPIOE, CRL, 0xF0000000); }
#define setReadDir()  {GP_INP(GPIOD, CRH, 0xFF000FFF); GP_INP(GPIOD, CRL, 0x000000FF); GP_INP(GPIOE, CRH, 0xFFFFFFFF); GP_INP(GPIOE, CRL, 0xF0000000); }

#define write8(x)     { write16(x & 0xFF); }
#define write16(x)    { write_16(x); WR_ACTIVE; WR_STROBE; WR_IDLE; WR_IDLE; }
#define READ_16(dst)  { RD_STROBE; RD_ACTIVE; RD_ACTIVE; RD_ACTIVE; RD_ACTIVE; dst = read_16(); RD_IDLE; RD_IDLE; RD_IDLE; }
#define READ_8(dst)   { READ_16(dst); dst &= 0xFF; }

#define PIN_HIGH(port, pin)   (port)->regs->BSRR = (1<<(pin))
//#define PIN_LOW(port, pin)    (port)->regs->BSRR = (1<<((pin)+16))
#define PIN_LOW(port, pin)    (port)->regs->ODR &= ~(1<<(pin))
#define PIN_OUTPUT(port, pin) gpio_set_mode(port, pin, GPIO_OUTPUT_PP)   //50MHz push-pull only 0-7
#define PIN_INPUT(port, pin)  gpio_set_mode(port, pin, GPIO_INPUT_FLOATING)   //digital input



UNTESTED.   Note that I have made an edit to the case 0x9806: that I posted earlier.

David.

pionscor

Hello David.

Maybe you have not seen this ?

There are 4 of the 5 HC541s that are powered in 3.3 volts.
(For display and SD card)

The fifth HC541 (the one on top of the picture) is powered in 5 volts, this HC541 handles the signals from the touch screen and SD card MISO (SD Out).
David
Would not it be better to power the HC541 of the touch screen and SD card MISO (SD Out) in 3.3 volts ?
What do you think?
Thank you very much.
François
Can you give me your opinion.

Thank you.
François.

david_prentice

My opinion is that life is simpler at 3.3V.   You don't need any buffers or level-shifters.   e.g. with a Due.

I would make any Adapter Shield with a solder-bridge to select 5V or 3.3V.   Solder-bridge is safer than jumper pins.

And use 74VHC245 buffers for level shifting.

The XPT2046 runs fine at 3.3V.   It is an SPI device.   So I would put it on the SPI bus along with the SD Card.

Hey-ho.   Most Display Shields are already wired for XPT2046 on digital 3-7 (I think)
And UTFT has no concept of SPI or "bus".

David.

pionscor

This is what I thought.
I wanted to have a confirmation before modifying my shield.

I know the ideal would be to use all the material in 3.3 volts directly, but for now I do not have an Arduino DUE.

Thank you again.
François.

grjonjon

Hi David.

I have two MCUfriend TFT shields: 2.4" and 3.5". The latter arrived couple of days ago.
I attach the LCD_ID_readreg results for both in a text file.
Any clue on how to make them work would be greatly appreciated.

Cheers,
John

david_prentice

Please copy-paste to a CODE window instead of attaching a TXT file.    It is far more convenient for the reader.

Go to the Library Manager.   Check your MCUFRIEND_kbv Library version.

The 3.5 inch shield has an Ilitek ILI9487 which should be identified and work straight out of the box with v2.9.4.

The 2.4 inch shield has a Himax HX8367-A which should be identified as ID=0x6767 and is not supported.
I suggest that you #define SUPPORT_8347D in MCUFRIEND_kbv.cpp
And force tft.begin(0x4747)

Please run the graphictest_kbv.ino sketch with forcing tft.begin(0x4747); on the 2.4".   Let me know how you get on.

David.

ZinggJM

You can handle the rotations on a SSD1963 with the FLIP_Vert and FLIP_Horiz bits in reg(0x36).
Leave MX, MY alone.   Unless you want to draw a Font upside down or backwards.

The MCUFRIEND_kbv rotation code is very messy.   Controllers behave differently.   I do intend to simplify it.

Have you implemented RD yet?
I bet that most of your initialisation is setting registers to their Reset default values.
Most MIPI chips only require VCOM and Power settings.   And their default values will generally work pretty well.

If you have the ILI9806 wired to the same interface as the SSD1963,   I will add a case(0x9806) to begin() if you care to test it.

David.
Take a look at your own code. FLIP_Vert and FLIP_Horiz are defined, but never used. 16bit values do not fit into location 0x36. But I finally understand how your library handles it. Rotation now works in my GxCTRL_SSD1963. And it is quite readable.

I am working on read for my GxIO classes. The wiring is different, but uses parallel wiring for data lines as far as possible.

Jean-Marc
No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

david_prentice

The attributes are declared but currently unused.
The Rotation checks for certaim IDs

I intend to use the attributes in future code.    Then I can avoid the messy conditionals.

Have you tried MCUFRIEND_kbv with your ILI9806 yet?

David.

ZinggJM

I think that we "almost" understand each other.

1.  You asked about Rotations in #1454.  I answered in #1455

..

5.  I am sure that it takes a long time to rewire the Tiky for the Big STM32 or the Due.

6.  I might write a SPECIAL for the Due.   The real mystery is:  why do you use random pins for the data bus?    Running a Mega Shield on a Due forces mixed ports.   But once you choose a wiring scheme,  why not stick to it?

Is there something that you don't understand with reg(0x36) on a MIPI controller like SSD1963 (or ILI9806)?
I want to avoid maths and transformations a la UTFT.   i.e. the same drawing code works in all 4 aspects.

David.
5. I have "frozen" the DuPoint wiring that I used with long tail connectors.

6. This wiring seem random, but is a perfect parallel wiring for DUE, see pictures.
   Only the supply pins must be taken care of! Caution, do not connect directly!
   I stick to the principle to use parallel wiring as far as possible, as connector shields are no usable with the Tiky display.

Jean-Marc
No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

ZinggJM

The attributes are declared but currently unused.
The Rotation checks for certaim IDs

I intend to use the attributes in future code.    Then I can avoid the messy conditionals.

Have you tried MCUFRIEND_kbv with your ILI9806 yet?

David.
No, this is not high on my agenda. I am working on fixes for GxCTRL_ILI9806 and Tiky IO.
No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

ZinggJM

The attributes are declared but currently unused.
The Rotation checks for certaim IDs

I intend to use the attributes in future code.    Then I can avoid the messy conditionals.

Have you tried MCUFRIEND_kbv with your ILI9806 yet?

David.
Now that I attempt to do that test, first on DUE, the compiler complains.
SAM wants you, but only without stray characters!

I had to shorten the error text heavily:

Code: [Select]
Arduino: 1.8.0 (Windows 10), Board: "Arduino Due (Programming Port)"

MCUFRIEND_kbv.cpp:70: error: stray '\302' in program

   setWriteDir();

   ^

MCUFRIEND_kbv.cpp:70: error: stray '\240' in program

MCUFRIEND_kbv.cpp:70: error: stray '\302' in program

MCUFRIEND_kbv.cpp:70: error: stray '\240' in program

MCUFRIEND_kbv.cpp:71: error: stray '\302' in program

   CTL_INIT();

   ^


MCUFRIEND_kbv.cpp:866: error: stray '\302' in program

MCUFRIEND_kbv.cpp:866: error: stray '\240' in program

MCUFRIEND_kbv.cpp:867: error: stray '\302' in program

       CS_IDLE;

       ^

MCUFRIEND_kbv.cpp:867: error: stray '\240' in program

MCUFRIEND_kbv.cpp:867: error: stray '\302' in program

MCUFRIEND_kbv.cpp:867: error: stray '\240' in program

MCUFRIEND_kbv.cpp:867: error: stray '\302' in program

MCUFRIEND_kbv.cpp:867: error: stray '\240' in program

MCUFRIEND_kbv.cpp:867: error: stray '\302' in program

MCUFRIEND_kbv.cpp:867: error: stray '\240' in program

MCUFRIEND_kbv.cpp:867: error: stray '\302' in program

MCUFRIEND_kbv.cpp:867: error: stray '\240' in program

MCUFRIEND_kbv.cpp:867: error: stray '\302' in program

MCUFRIEND_kbv.cpp:867: error: stray '\240' in program

exit status 1
stray '\302' in program

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


Jean-Marc
No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

david_prentice

I pasted sequences directly to a CODE block in the Forum message.

Where have you got the stray characters?   \302 is 0xC2 which is an unusual character.

As I said when posting,  the blocks were untested.   I am going out with my dog.
When I get back,  I will add the blocks to mcufriend_special.h and see for myself.

I presume you are using GENERIC_STM32F103C in stm32duino.
Or are you using the ST core?

Which target?

David.

ZinggJM

As I wrote, I try on DUE first, and use #define USE_TIKY_ON_DUE

I tried to change the lines:

Code: [Select]
#define CS_PORT PIOB
#define CS_PIN 26


but still get these error messages.

I closed the IDE, and started it again; did not help.

Later I will try the 2 STM32 targets.
No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

david_prentice

I copied the case 0x9806 block into MCUFRIEND_kbv.cpp begin() .
I copied the USE_TIKY_ON_DUE block into mcufriend_special.h

I defined SUPPORT_9806, USE_SPECIAL and USE_TIKY_ON_DUE

and changed #define TFTLCD_DELAY8 0x7F

It compiled just fine.   Of course my private files might be different to yours.

If you prefer,  I will create a test_9806 branch for you on GitHub.

David.

Go Up