GLCD and Touchpad Library

User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: GLCD and Touchpad Library

Post by Tectu »

Just added a new GUI function:

Code: Select all

Thread *guiDrawBarGraph(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t orientation, uint16_t frameColor, uint16_t bkColor, uint16_t valueColor, uint16_t interval, uint16_t *percent);


Does draw a bar graph with given place and size with given colors. Orientation is 'horizontal' or 'vertical'. Within an given interval of milliseconds, it checks the percentage value and updates the graph.


Also started creating Wiki page, until we get rid of doing a real ChibiOS LCD library:
http://chibios.org/dokuwiki/doku.php?id=chibios:community:lcddriver_by_tectu



~ Tectu

P.S. Giovanni, can you please move this thread to Development and Feedback, or where ever you ever think it matches best?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: GLCD and Touchpad Library

Post by Giovanni »

Development is OK since it is related to ChibiOS, moved.

Giovanni
indigos
Posts: 14
Joined: Sat Jun 02, 2012 10:46 am

Re: GLCD and Touchpad Library

Post by indigos »

I tested and don't work very well in my environment, STM32F4Discovery + HY32D.

DeviceCode return me 0x8988 and not 0x8989, I checked many times connections on bit 0, but for device code give me 0 e not 1.
I changed the code and added 0x8988 so lcdInit setup my lcd and simple lcdClear works, but all other functions doesn't work, DrawLine, DrawString write some pixels in LCD but is not correct.
My first test on this LCD was with PIC24 (microchip's microcontroller) and yesterday I written code for read DeviceCode and I read 0x8989. There are some errors in my environment STM32F4Discovery.
Maybe Timing Characteristics are not correct.

In attach a patch. Somethings is useful change, and something just ignore.
For example

Code: Select all

       LCD_DATA_PORT->CRH = 0x44444444;
       LCD_DATA_PORT->CRL = 0x44444444;

changed in

Code: Select all

       // Is there a better way for this?
       palSetGroupMode(LCD_DATA_PORT,PAL_PORT_BIT(0)|PAL_PORT_BIT(1)|PAL_PORT_BIT(2)|PAL_PORT_BIT(3)|PAL_PORT_BIT(4)|PAL_PORT_BIT(5)|PAL_PORT_BIT(6)|PAL_PORT_BIT(7)|
                                      PAL_PORT_BIT(8)|PAL_PORT_BIT(9)|PAL_PORT_BIT(10)|PAL_PORT_BIT(11)|PAL_PORT_BIT(12)|PAL_PORT_BIT(13)|PAL_PORT_BIT(14)|PAL_PORT_BIT(15),
                        0,PAL_MODE_INPUT);


I added pin Reset.
So in lcdInit there is:

Code: Select all

    Clr_Reset;
    chThdSleepMilliseconds(100);
    Set_Reset;


In touchpad.c

Code: Select all

#define SET_CS(a)              (TP_PORT->BSRR = 1 << (TP_CS + (a ? 0 : 16)))

replace in

Code: Select all

#define Set_TCS               palSetPad(TP_PORT, TP_CS);
#define Clr_TCS               palClearPad(TP_PORT, TP_CS);


I removed some warnings compiler.

Please, could you send me your main test application? I attach my in lcdtouch.zip

I'm working on brightness pin BLCNT with PWM, is ready I need to test.
Attachments
lcdtouch.zip
(11.62 KiB) Downloaded 612 times
git_diff.gz
(2.5 KiB) Downloaded 636 times
Abhishek
Posts: 266
Joined: Wed May 23, 2012 3:15 pm

Re: GLCD and Touchpad Library

Post by Abhishek »

Hello people,

I have also a simple GUI Library for my 2.4" LCD (S6D1121 controller) in 16-bit bitbang and also a wavePlayer working on my STM32F4 Discovery board.

Please see my forum post in the User Projects Section.
viewtopic.php?f=8&t=468&p=4184

@indigos,
There is a difference between the STM32F1 GPIO (Tectu's code is for STM32F1) and STM32F2 or STM32F4 GPIO cells, code is not intercompatible between the two.

I have found out that it is always better to use HAL functions (or even STM32_StdPeriph_Library functions if you really want to use them, ChibiOS HAL is great) to init GPIOs than direct GPIO access unless time-critical application is required.

You could use:
For Output, Highest Speed (All PE(0-15) pins configured as output):
palSetGroupMode(GPIOE, 0xFFFF, 0, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST);

For Input: (with pull-ups enabled)
palSetGroupMode(GPIOE, 0xFFFF, 0, PAL_MODE_INPUT_PULLUP);

0xFFFF = all pins = can make your code more readable.

STM32F4 GPIOs are very high speed, so LCD may not take it up that fast.

I was getting a few 'dead pixels' in screen fills initially, and inserting NOPs in between toggling WR pin fixed the issue.

I have inserted two NOPs in between toggling WR pin, and I guess reading should take more than two NOPs (according to datasheet). Try Doing that... and see if it works.

To insert a NOP use:

Code: Select all

asm volatile ("nop");
or

Code: Select all

__NOP();


Also in the STM32F4 discovery, some PE pins are connected to the MEMS sensor: Precisely PE0, PE1 and PE3.

So I use PD0-PD3 to DB0-DB3 and PE4-PE15 to DB4-DB15 on the LCD.

Check out my working code in repo https://github.com/abhishek-kakkar/STM3 ... overy_demo in the CLCD_QVGA Sub directory.
(replace the init sequence with the proper one, set window address commands for the SSD1289 with proper index). And my lcd_read function isn't working right now, I'll have to fix it.
Feel free to ask any question regarding it.

Regards
Abhishek
Abhishek
Posts: 266
Joined: Wed May 23, 2012 3:15 pm

Re: GLCD and Touchpad Library

Post by Abhishek »

An advice for Backlight PWM control:
I tried to use ChibiOS HAL Code to drive my LCD Backlight (PWM pin active low), but it doesn't work properly, backlight flickers, especially in low brightness.
If you will try fade effects, it fails miserably.

After a few hours, I came up with a solution: bypassed HAL implementation and implemented the Timer channel directly.

For 256 Steps PWM backlight, you can use this working code from my library:

It initialises Timer4/CH3 connected to PB8 on the discovery board, which you can connect to the BLCNT pin on your module, It's active low, I suppose?

Code: Select all

   // Connect PB8 to timer3
   palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(2));
   
   // Init the timer PWM without HAL
   // 256 Steps @ 31.25 kHz
   // Auto Load Configuration
   // TIM4 / CH3 (PB8)
   rccEnableTIM4(FALSE);
   
   // Set Auto-reload value 255 (256 steps)
   TIM4->ARR = 255;

   // We prescale the clock to 8 MHz ( 8 MHz / 256 = 31.25 kHz)
   TIM4->PSC = (STM32_TIMCLK1 / 8000000) - 1;

   // Now configure OC3 in PWM Mode 1 OC3M[2:0] = 110
   // Enable preload (Set OC3PE bit)
   TIM4->CCMR2 = TIM_CCMR2_OC3M_2 | TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC3PE;

   // Enable OC3 output (CC3E bit set), active low(CC3P bit set)
   TIM4->CCER = TIM_CCER_CC3E | TIM_CCER_CC3P;

   // Finally, enable auto reload and start the timer!
   TIM4->CR1 = TIM_CR1_ARPE | TIM_CR1_CEN;

   // Set initial brightness level
   TIM4->CCR3=255;

You can change TIM4 to TIMx, and other registers accordingly.

Now whenever you need to control backlight intensity, just set TIM4->CCR3 (or whatever channel you want to use) to a value between 0 and 255.

Could this function be added to the graphics library?

Abhishek
indigos
Posts: 14
Joined: Sat Jun 02, 2012 10:46 am

Re: GLCD and Touchpad Library

Post by indigos »

Abhishek wrote:Also in the STM32F4 discovery, some PE pins are connected to the MEMS sensor: Precisely PE0, PE1 and PE3.

So I use PD0-PD3 to DB0-DB3 and PE4-PE15 to DB4-DB15 on the LCD.

I did not know this information. I will try with this configuration. So in STM32F4Discovery doesn't exist a GPIO with 16 Pad free.

Abhishek wrote:Check out my working code in repo https://github.com/abhishek-kakkar/STM3 ... overy_demo in the CLCD_QVGA Sub directory.
I'm studying, also your source code, thank you.
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: GLCD and Touchpad Library

Post by Tectu »

Abhishek wrote:Could this function be added to the graphics library?


Sure! I try to maintain the library as best as I can. Please feel free to pull request every thing you want!


~ Tectu
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: GLCD and Touchpad Library

Post by Tectu »

Okay, I worked out a clean architecture for the GLCD library project.

We have now abstractions per controller type. Whenever you want to use a different type of controller, you just need to copy&paste the xxx_lld.c and xxx_lld.h file of a given controller and make changes matching to your controller (file names: <controller>_lld.c and <controller>_lld.h). Please send a pull request whenever you have a new driver ready :)

I know there is still much of work to do, but I am sure that we can push this straight forward!


~ Tectu
Abhishek
Posts: 266
Joined: Wed May 23, 2012 3:15 pm

Re: GLCD and Touchpad Library

Post by Abhishek »

S6D1121 is now Officially Supported by the ChibiOS Library!

I receive first output now..

Cheers!

Abhishek.
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: GLCD and Touchpad Library

Post by Tectu »

Thanks for the great work! Will merge as soon as I get the pull request.


~ Tectu
Locked