LCD Driver - OLD

mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: LCD Driver

Post by mobyfab »

@badger

Your LCD: http://cgi.ebay.fr/3-2-TFT-LCD-Module-D ... 0451748066
You can get the LCD datasheet on the page.

it is specific to the panel mostly. I was thinking about things like resolution, front/back porch, pixel clock frequency

For example these are my panel's properties:

Code: Select all

#ifdef TFT480272
   #define TFT_WIDTH            480ULL
   #define TFT_HSYNC_BACK_PORCH   2ULL
   #define TFT_HSYNC_FRONT_PORCH   2ULL
   #define TFT_HSYNC_PULSE      41ULL
   
   #define TFT_HEIGHT            272ULL
   #define TFT_VSYNC_BACK_PORCH   2ULL
   #define TFT_VSYNC_FRONT_PORCH   2ULL
   #define TFT_VSYNC_PULSE      10ULL
#endif


And some calculated properties

Code: Select all

#define TFT_FPS 100ULL
#define   TFT_HSYNC_PERIOD   (TFT_HSYNC_PULSE + TFT_HSYNC_BACK_PORCH + TFT_WIDTH  + TFT_HSYNC_FRONT_PORCH)
#define   TFT_VSYNC_PERIOD   (TFT_VSYNC_PULSE + TFT_VSYNC_BACK_PORCH + TFT_HEIGHT + TFT_VSYNC_FRONT_PORCH)

#define TFT_PCLK   (TFT_HSYNC_PERIOD * TFT_VSYNC_PERIOD * TFT_FPS)
#define LCD_FPR      ((TFT_PCLK * 1048576)/100000000)


These are the values that are used to configure the controller for a specific LCD.

The idea is to abstract everything up to the primitives (drawing lines, pixels, selecting area, clearing FB...)
Anything more complex should call the primitive functions.
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: LCD Driver

Post by mobyfab »

Can't get the FSMC to work on the discovery board :(

Nothing happens when I select FSMC_Bank1_NORSRAM1...
Strangely when I use FSMC_Bank1_NORSRAM2/3/4 I can see some activity,
but since only NORSRAM1 can be used on the LQFP100 chips, it's useless... (there's only FSMC_NE1)

Also, I had to remove R50 since it was connected to PD5. (it's the USB overcurrent feedback)

Could someone try on its board?

edit: after checking with a scope is seems that only the RS pin doesn't works...
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: LCD Driver

Post by Badger »

Is that the F4 discovery? the code I posted was for an F1 chip.

Something we should also think about is managing some sort of frame buffer and using DMA to do the brunt work.. but first we must sort out the abstraction of screens / panels, I'll look into how X11 does it ;)

edit: this appnote looks interesting: http://www.st.com/internet/com/TECHNICA ... 278141.pdf
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: LCD Driver

Post by mobyfab »

hehe i've read all of those ;)

The code has been modified to work on the F4.
I'm also using the FW lib structures and init functions/macros.

I guess I'll have it work by this weekend.

Code: Select all

rccEnableAHB3(RCC_AHB3ENR_FSMCEN, 0); // Enable FSMC Clock

   FSMC_NORSRAMInitTypeDef  q;
   FSMC_NORSRAMTimingInitTypeDef  p;
   
   p.FSMC_AddressSetupTime = 5;
   p.FSMC_AddressHoldTime = 0;
   p.FSMC_DataSetupTime = 9;
   p.FSMC_BusTurnAroundDuration = 0;
   p.FSMC_CLKDivision = 0;
   p.FSMC_DataLatency = 0;
   p.FSMC_AccessMode = FSMC_AccessMode_A;

   q.FSMC_Bank = FSMC_Bank1_NORSRAM1;
   q.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
   q.FSMC_MemoryType = FSMC_MemoryType_SRAM;
   q.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
   q.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
   q.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
   q.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
   q.FSMC_WrapMode = FSMC_WrapMode_Disable;
   q.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
   q.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
   q.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
   q.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
   q.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
   q.FSMC_ReadWriteTimingStruct = &p;
   q.FSMC_WriteTimingStruct = &p;

   FSMC_NORSRAMInit(&q);

    /* Enable FSMC Bank1_SRAM Bank */
    FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE );
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: LCD Driver

Post by Giovanni »

mobyfab wrote:I'm also using the FW lib structures and init functions/macros.


An FSMC STM32-specific driver would not be difficult to add, I am not particularly excited by the FW lib.

Giovanni
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: LCD Driver

Post by mobyfab »

That would help keep the code clean :)
utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Has thanked: 1 time
Been thanked: 20 times

Re: LCD Driver

Post by utzig »

Hey mobyfab,

Are you still working on a GUI for your project? Do you pretend to release the sources?

I'll also have to write a GUI and have been investigating some available options but they always seem to be too big/complex (and in C++). My idea is to write something in pure C (no C++) and very simple.

Att,
Fabio Utzig
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: LCD Driver

Post by mobyfab »

Hi utzig,

I just received my logic analyser and am working on it, but I don't have that much time to spend on it.

The GUI will off course be in C, I will release the source as soon as I have something working with the FSMC interface.
The plan is that the library can draw text, basic shapes and images. (I just need to work on the shapes, everything else is done already)

If someone could write a menu system that would be awesome.
Joerg-SH
Posts: 29
Joined: Mon Feb 20, 2012 9:00 pm

Re: LCD Driver

Post by Joerg-SH »

mobyfab wrote:That's definately something I can help with, I have to write a full GUI for my project anyways.

So far I have written the following functions in my library: (everything works)

Code: Select all

void SSD1963_Init (void);
void SSD1963_WriteCommand(uint16_t commandToWrite);
void SSD1963_WriteData(uint16_t dataToWrite);
void SSD1963_SetArea(unsigned int sx, unsigned int ex, unsigned int sy, unsigned int ey);
void SSD1963_FillArea(unsigned int sx, unsigned int ex, unsigned int sy, unsigned int ey, uint16_t color);
void SSD1963_ClearScreen(uint16_t color);
void SSD1963_SetPixel(int x, int y, uint16_t color);
void SSD1963_Demo(void);
void SSD1963_drawString(uint16_t x, uint16_t y, const char *c, uint16_t color, uint8_t size);
void SSD1963_drawChar(uint16_t x, uint16_t y, const char c, uint16_t color, uint8_t size) ;
void SSD1963_drawBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const unsigned char *bmp);
float SSD1963_FPS(void);


This can easily be abstracted to work on other LCD controllers.


Hello Mobyfab,
I have also a SSD1963 driven 7 inch LCD and want to drive it on a STM32F4, do You share Your code??

greetings

Joerg
kilohercas
Posts: 1
Joined: Mon Feb 27, 2012 10:08 pm

Re: LCD Driver

Post by kilohercas »

i need code for smt32f407 too.
i made it work only with stm32f103 but i need more power, because i have slow fps
if i have code like this which looks very simple http://www.scienceprog.com/wp-content/uploads/2011/11/STM32F103ZET6GLCD.zip
what should be changed to make it work with STM32F4 ? ( 480x272 lcd with SSD1963 controller ic)
first problem is how to fix systic delay program?

Code: Select all

static __IO uint32_t TimingDelay = 0;

void Delay(__IO uint32_t nCount)
{
  TimingDelay = nCount;

  /* Enable the SysTick Counter */
  SysTick_Config(720000);
  while(TimingDelay != 0);
  /* Disable the SysTick Counter */
  SysTick->CTRL &= ~SysTick_CTRL_ENABLE;

   /* Clear the SysTick Counter */
   SysTick->VAL = (uint32_t)0x0;
}
void Decrement_TimingDelay(void)
{
  if (TimingDelay != 0x00)
  {
    TimingDelay--;
  }
}

and second problem how to make code work with my pin assignments ?

Code: Select all

GPIO_InitTypeDef GPIO_InitStructure;

   // Configures the FSMC GPIOs to interface with the LCD module
   // Enable GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks
      RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOG |
                     RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF,
                     ENABLE);

   // Enable FSMC, GPIOD, GPIOE and AFIO clocks
   RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);

   //-- GPIO Configuration ------------------------------------------------------------
      // SRAM Data lines,  NOE and NWE configuration
   // Connect FSMC pins to AF12
   // +-------------------+--------------------+------------------+-------------------+
    // +                       LCD pins assignment                                     +
    // +-------------------+--------------------+------------------+-------------------+
    // | PD0  <-> FSMC_D2  | PD8   <-> FSMC_D13 | PD15 <-> FSMC_D1 | PE11 <-> FSMC_D8  |
    // | PD1  <-> FSMC_D3  | PD9   <-> FSMC_D14 | PE7  <-> FSMC_D4 | PE12 <-> FSMC_D9  |
    // | PD4  <-> FSMC_NOE | PD10  <-> FSMC_D15 | PE8  <-> FSMC_D5 | PE13 <-> FSMC_D10 |
    // | PD5  <-> FSMC_NWE | PD11  <-> FSMC_A16 | PE9  <-> FSMC_D6 | PE14 <-> FSMC_D11 |
    // | PD7  <-> FSMC_NE1 | PD14  <-> FSMC_D0  | PE10 <-> FSMC_D7 | PE15 <-> FSMC_D12 |
     // +-------------------+--------------------+------------------+-------------------+

   // PORTD
   GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FSMC);         // D2
   GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_FSMC);         // D3
   GPIO_PinAFConfig(GPIOD, GPIO_PinSource4, GPIO_AF_FSMC);         // NOE -> RD
   GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_FSMC);         // NWE -> WR
   GPIO_PinAFConfig(GPIOD, GPIO_PinSource7, GPIO_AF_FSMC);         // NE1 -> CS
   GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_FSMC);         // D13
   GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_FSMC);         // D14
   GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_FSMC);      // D15
   GPIO_PinAFConfig(GPIOD, GPIO_PinSource11, GPIO_AF_FSMC);      // A16 -> RS
   GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FSMC);      // D0
   GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FSMC);      // D1

   // PORTE
   GPIO_PinAFConfig(GPIOE, GPIO_PinSource7, GPIO_AF_FSMC);         // D4
   GPIO_PinAFConfig(GPIOE, GPIO_PinSource8, GPIO_AF_FSMC);         // D5
   GPIO_PinAFConfig(GPIOE, GPIO_PinSource9, GPIO_AF_FSMC);         // D6
   GPIO_PinAFConfig(GPIOE, GPIO_PinSource10, GPIO_AF_FSMC);      // D7
   GPIO_PinAFConfig(GPIOE, GPIO_PinSource11, GPIO_AF_FSMC);      // D8
   GPIO_PinAFConfig(GPIOE, GPIO_PinSource12, GPIO_AF_FSMC);      // D9
   GPIO_PinAFConfig(GPIOE, GPIO_PinSource13, GPIO_AF_FSMC);      // D10
   GPIO_PinAFConfig(GPIOE, GPIO_PinSource14, GPIO_AF_FSMC);      // D11
   GPIO_PinAFConfig(GPIOE, GPIO_PinSource15, GPIO_AF_FSMC);      // D12

   // FSMC GPIO configuration
   // SRAM Data lines,  NOE and NWE configuration
   // PORTD
      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
                                  GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
                                  GPIO_Pin_11 | GPIO_Pin_14 | GPIO_Pin_15;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
      GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
      GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;

   GPIO_Init(GPIOD, &GPIO_InitStructure);

   // PORTE
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
                                  GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |
                                  GPIO_Pin_15;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
      GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
      GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;

   GPIO_Init(GPIOE, &GPIO_InitStructure);


Thank you for any help
Locked