Port manipulation - LCD 8bit parallel

Working libraries, libraries being ported and related hardware
User avatar
iwalpola
Posts: 24
Joined: Tue Jun 21, 2016 1:08 pm
Location: Silchar, India
Contact:

Re: Port manipulation - LCD 8bit parallel

Postby iwalpola » Wed Jul 06, 2016 6:59 am



epic.

User avatar
diger67
Posts: 24
Joined: Thu Sep 10, 2015 12:13 am
Location: Russia, Sankt- Piterburg

Re: Port manipulation - LCD 8bit parallel

Postby diger67 » Wed Aug 03, 2016 9:23 pm

Hi!
I do not work in an environment with Arduino STM. But can someone come in handy. Here are a few defines. Their work is checked in Keil. Binding conclusions made to the standard location pins Shild TFT for Arduino. New definition write8inline (d) is faster than the previous version.


Code: Select all

//Port data |D7 | D6 |D5 |D4 |D3 | D2 |D1 |D0 |
//Pin stm32 |PA8|PB10|PB4|PB5|PB3|PA10|PC7|PA9|
//control port |RST| CS | RS | WR| RD|
//Pin stm32    |PC0|PB0|PA4|PA1|PA0|

#define write8inline(d) {\
                               GPIOA->BSRR = (data & (1<<0)) ? GPIO_BSRR_BS9  : GPIO_BSRR_BR9;\
                               GPIOC->BSRR = (data & (1<<1)) ? GPIO_BSRR_BS7  : GPIO_BSRR_BR7;\
                               GPIOA->BSRR = (data & (1<<2)) ? GPIO_BSRR_BS10 : GPIO_BSRR_BR10;\
                               GPIOB->BSRR = (data & (1<<3)) ? GPIO_BSRR_BS3  : GPIO_BSRR_BR3;\
                               GPIOB->BSRR = (data & (1<<4)) ? GPIO_BSRR_BS5  : GPIO_BSRR_BR5;\
                               GPIOB->BSRR = (data & (1<<5)) ? GPIO_BSRR_BS4  : GPIO_BSRR_BR4;\
                               GPIOB->BSRR = (data & (1<<6)) ? GPIO_BSRR_BS10 : GPIO_BSRR_BR10;\
                               GPIOA->BSRR = (data & (1<<7)) ? GPIO_BSRR_BS8  : GPIO_BSRR_BR8;\
                               WR_STROBE;\
}

#define enportrcc() {\
            RCC->APB2ENR |= ((RCC->APB2ENR &= 0xFFFFFFFF) | RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_AFIOEN);\
            AFIO->MAPR |= ((AFIO->MAPR &= 0xFFFFFFFF) | AFIO_MAPR_SWJ_CFG_JTAGDISABLE);\
            GPIOA->CRL = ((GPIOA->CRL &= 0xFFF0FF00) | 0x00030033);      \
            GPIOC->CRL = ((GPIOC->CRL &= 0xFFFFFF0F) | 0x00000030);   \
            GPIOB->CRL = ((GPIOB->CRL &= 0xFFFFFFF0) | 0x00000003);   \
         }
         

#define setWriteDirInline() { \
        GPIOA->CRH = ((GPIOA->CRH &= 0xFFFFF000) | 0x00000333);      \
        GPIOC->CRL = ((GPIOC->CRL &= 0x0FFFFFFF) | 0x30000000);   \
        GPIOB->CRL = ((GPIOB->CRL &= 0xFF000FFF) | 0x00333000);   \
        GPIOB->CRH = ((GPIOB->CRH &= 0xFFFFF0FF) | 0x00000300);   \
      }

#define setReadDirInline() { \
            GPIOA->CRH = ((GPIOA->CRH &= 0xFFFFF000) | 0x00000444);     \
        GPIOC->CRL = ((GPIOC->CRL &= 0x0FFFFFFF) | 0x40000000);   \
        GPIOB->CRL = ((GPIOB->CRL &= 0xFF000FFF) | 0x00444000);    \
        GPIOB->CRH = ((GPIOB->CRH &= 0xFFFFF0FF) | 0x00000400);   \
      }


Add drawChar function can now rewrite the symbol on top of the old one.

Code: Select all

void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size)
{
   int8_t i, j;
  if((x >= _width)            || // Clip right
     (y >= _height)           || // Clip bottom
     ((x + 6 * size - 1) < 0) || // Clip left
     ((y + 8 * size - 1) < 0))   // Clip top
    return;

  //if(!_cp437 && (c >= 176)) c++; // Handle 'classic' charset behavior

  for (i=0; i<6; i++ )
  {
    uint8_t line;
    if (i == 5)
      line = 0x0;
    else
      line = pgm_read_byte(font+(c*5)+i);
    for (j = 0; j<8; j++)
    {
      if (line & 0x1)
      {
        if (size == 1) // default size
          drawPixel(x+i, y+j, color);
        else {  // big size
          fillRect(x+(i*size), y+(j*size), size, size, color);
        }
      } else if (bg != color) {
        if (size == 1) // default size
          drawPixel(x+i, y+j, bg);
        else {  // big size
          fillRect(x+i*size, y+j*size, size, size, bg);
        }
      }
      //addiding
   if (line & 0)
   {
      if (size == 1)
      drawPixel(x+i, y+j, bg);
   else {  // big size
          fillRect(x+(i*size), y+(j*size), size, size, bg);
        }
         }//end addiding
         line >>= 1;
    }
  }
}

Here is an example stm32f103 bitbang http://178.130.34.198/tft.mp4
Here is an exemple stm32f429 SPI with DMA picture http://178.130.34.198/tft_001.mp4
Here is an exemple stm32f103 FSMC with out DMA moving rectangle http://178.130.34.198/tft_002.mp4
Attachments
tft.jpg
Resolution of 320x240
tft.jpg (194.28 KiB) Viewed 674 times
Last edited by diger67 on Wed Aug 03, 2016 11:14 pm, edited 7 times in total.

User avatar
Rick Kimball
Posts: 754
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Port manipulation - LCD 8bit parallel

Postby Rick Kimball » Wed Aug 03, 2016 10:57 pm

... this line:

#define enportrcc() {\
RCC->APB2ENR |= ((RCC->APB2ENR &= 0xFFFFFFFF) | RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_AFIOEN);\
AFIO->MAPR |= ((AFIO->MAPR &= 0xFFFFFFFF) | AFIO_MAPR_SWJ_CFG_JTAGDISABLE);\

Are you trying to clear the APB2ENR register with the &= ((RCC->APB2ENR &= 0xFFFFFFFF) ?

It is probably easier to set it to zero or use &= ((RCC->APB2ENR &= ~0xFFFFFFFF)

Or maybe I misunderstand what you are doing there.

-rick
-rick

User avatar
diger67
Posts: 24
Joined: Thu Sep 10, 2015 12:13 am
Location: Russia, Sankt- Piterburg

Re: Port manipulation - LCD 8bit parallel

Postby diger67 » Wed Aug 03, 2016 11:22 pm

Rick Kimball wrote:
Are you trying to clear the APB2ENR register with the &= ((RCC->APB2ENR &= 0xFFFFFFFF) ?

It is probably easier to set it to zero or use &= ((RCC->APB2ENR &= ~0xFFFFFFFF)

Or maybe I misunderstand what you are doing there.

-rick



It is understood that after the reset registers are filled with default values. You can not do this operation and immediately set the bits clock ports and bit AFIO_MAPR_SWJ_CFG_ZHTAGDYSABLE it just in case.

stevestrong
Posts: 894
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Port manipulation - LCD 8bit parallel

Postby stevestrong » Fri Aug 26, 2016 11:14 pm

Well, I had to reinvent the wheel and adapt the original lib TFTLCD lib from Adafruit for STM32, because my LCD was an ILI9328, not an ILI9341, as iwalpola's lib.
Also, I had to stick to digital write and read functions, because the pure register writes for pin toggling was too fast and the screen went blank!
Here my benchmark using Adafruit original graphic test ino:

Code: Select all

TFT LCD test
TFT size is 240x320
Found ILI9328 LCD driver

Benchmark                Time (microseconds)
Screen fill              1019555
Text                     115645
Lines                    719977
Horiz/Vert Lines         96056
Rectangles (outline)     69857
Rectangles (filled)      2155387
Circles (filled)         843279
Circles (outline)        313036
Triangles (outline)      228363
Triangles (filled)       993928
Rounded rects (outline)  146794
Rounded rects (filled)   2514008
Done!

I know, it is not a big deal, but as I told, the LCD does not support higher frequencies, it simply goes white. I don't know why...
Last edited by stevestrong on Sat Sep 03, 2016 7:04 pm, edited 1 time in total.

stevestrong
Posts: 894
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Port manipulation - LCD 8bit parallel

Postby stevestrong » Sat Sep 03, 2016 12:50 pm

After getting the LCD reset to work correctly, this is what I achieve using the Adafruit lib ported to STM32:

Code: Select all

TFT LCD test
TFT size is 240x320
Found ILI9328 LCD driver
Benchmark                Time (microseconds)
Screen fill              65561
Text                     24708
Lines                    141805
Horiz/Vert Lines         8723
Rectangles (outline)     7335
Rectangles (filled)      155516
Circles (filled)         134162
Circles (outline)        60283
Triangles (outline)      45012
Triangles (filled)       115087
Rounded rects (outline)  24511
Rounded rects (filled)   206878
Done!
rotation: 0, text runtime: 24708
rotation: 1, text runtime: 24972
rotation: 2, text runtime: 24973
rotation: 3, text runtime: 24985


This lib is different from that of iwalpola, because this supports other LCD-types as well, not only ILI9341.
If you want to try out this lib, please adapt the pin definitions in the "Adafruit_TFTLCD_8bit_STM32.h" header file.

https://github.com/stevstrong/Adafruit_TFTLCD_8bit_STM32
Last edited by stevestrong on Sun Sep 04, 2016 4:51 pm, edited 1 time in total.

VadimEL
Posts: 37
Joined: Sat Aug 13, 2016 1:28 pm
Location: Ukraine Odessa

Re: Port manipulation - LCD 8bit parallel

Postby VadimEL » Sat Sep 03, 2016 5:44 pm

C:\Documents and Settings\Vadim\Мои документы\Arduino\hardware\Arduino_STM32\STM32F1\libraries\Adafruit_TFTLCD_8bit_STM32\Adafruit_TFTLCD_8bit_STM32.h

line 84
#define read8(x) { x = read8_() ;}
===================================

stevestrong
Posts: 894
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Port manipulation - LCD 8bit parallel

Postby stevestrong » Sat Sep 03, 2016 7:03 pm

VadimEL wrote:Adafruit_TFTLCD_8bit_STM32.h
line 84
#define read8(x) { x = read8_() ;}

Yes, this was indeed a bug, it is now corrected and checked in:

https://github.com/stevstrong/Adafruit_TFTLCD_8bit_STM32

Any other bugs please report as issue on the github site.

Itudylla
Posts: 1
Joined: Wed Feb 15, 2017 7:25 am

Re: Port manipulation - LCD 8bit parallel

Postby Itudylla » Wed Feb 15, 2017 7:32 am

thanks a lot for letting us know about these manipulations, they make the workers' lives easier!


Return to “Libraries & Hardware”

Who is online

Users browsing this forum: No registered users and 1 guest