Stm32 transplanted ucgui + touch screen display without UCOS ⅱ

Source: Internet
Author: User

Lab board -- Li Xiang stm32 Development Board

Development Tool -- Keil uvision5.0 for MDK

This ultimate task is to display the GUI of the oscilloscope. This article simply summarizes the transplantation of ucgui + touch screen, and then adds the Windows Manager and ucos ii.

Next, let's talk about the procedures for porting, which will be interspersed with some simple understandings to help new users like me.

The steps are divided into three major steps:

I. Porting ucgui

2. display Chinese Characters

3. Transplant Touch Screen

I. Porting ucgui

1. Create a project template.

I will first create a project template containing only some system files. The main function is a while (1); loop. Copy the file directly for each project and add the file. (Assuming that you all know how to correctly Add. C and. H files in the project) the project directory is as follows:

CMSIS--CM3 interrupt related and startup files

Delay-latency-related files (required for most projects. Therefore, it is placed in the top-level directory)

Library -- the various library files provided by ST are divided into INC and SRC folders.

MDK-ARM -- compile the generated intermediate file, that is, the output file

My_driver-your own driver files are mainly color screen driver files, personal font files, and files required by other projects, such as SPI and IIC files.

User -- Main. C and other unadded library files

2. Add the color screen driver.

The color screens and driver chips of each development board are not necessarily the same. You must ensure that the color screen can normally display any display pattern without porting ucgui according to your own situation, (Chinese characters are not necessarily displayed ). Here, we will use the Li Xiang stm32 tutorial for the ili93xx. c file in the stm32 ideal smart core technology (library function) and rename its header file LCD. H to the ili93xx. h file. Replace the mian file in the ideal smart core technology (library function) of stm32 with the project, delete unnecessary header files, and delete all content of the main function.

It mainly includes three functions:

1) The color screen initialization file LCD _myinit (); The name is changed from LCD _init () in ili93xx. C;

2) The image point function, the original function LCD _drawpoint (); because the Landscape Display needs to be changed to the following mode: preserve the original function in portrait mode.

Void LCD _drawpoint)
{

LCD _writereg (0x004e, 239-y );
LCD _writereg (0x004f, X );
LCD _wr_reg (0x22); // LCD _writecmd (gramwr );

LCD _wr_data (color );
}

3) The read point function returns the color value of the Set coordinate point. That is, LCD _readpoint () in the ili93xx. c file ();

3. Download the source code of ucgui.

The version 3.98 is used this time. The ucgui file directory is as follows. You can only transplant the files you need, and add all the files you need in case of trouble or the final application of the project.

Copy the config and GUI folders in the ucgui source code to the project directory, and add the required. c file and. h file directory. Complete the following steps:

4. Configure the ucgui File

1) Open lcdconf. h under config, comment all, and change it to the following content (in Landscape mode)

# Ifndef lcdconf_h
# Define lcdconf_h

/*************************************** ******************************
*
* General configuration of LCD
*
**************************************** ******************************
*/

# Define LCD _xsize (320)/* X-resolution of LCD, logical COOR. * // change the portrait screen to 240
# Define LCD _ysize (240)/* Y-resolution of LCD, logical COOR. * // change the landscape to 320


# Define LCD _bitsperpixel (16) // 16-bit color
# Define LCD _controller (-1) // Default Driver (that is, use your own driver function)
# Define LCD _fixedpalette (565) // color palette 565 format
# Define LCD _swap_rb (1) // red/blue reversed color exchange
# Define LCD _init_controller () LCD _myinit (); // LCD _myinit (); initialize function 4 for your own Screen

2) Modify guiconf. h file

# Ifndef guiconf_h
# Define guiconf_h

# Define gui_ OS (0)/* compile with multitasking support * // Operating System Support
# Define gui_support_touch (1)/* support a touch screen (req. Win-manager) * // Touch Screen
# Define gui_support_mouse (1) // mouse
# Define gui_support_unicode (1)/* Support mixed ASCII/Unicode strings * // Unicode support, displaying Chinese Characters

# Define gui_default_font & gui_font6x8 // default GUI font
# Define gui_alloc_size 5000/* size of dynamic memory... For WM and memory devices * // dynamic memory

/*************************************** ******************************
*
* Configuration of available packages
*/

# Define gui_winsupport 1/* Window Manager package available * // 'window Control Support
# Define gui_support_memdev 1/* memory devices available * // memory device support
# Define gui_support_aa 0/* anti aliasing available * // anti-aliasing. The refresh speed is low.

# Endif/* avoid multiple compression sion */

3) Replace the ucgui function body:

The ucgui display is based on the dot display, that is, ucgui will call your own-driven vertices to complete the display of the pattern, therefore, we need to copy the three main driver functions to the ucgui.

I. Open the lcddummy. c file under the lcddriver and set the function body of LCD _l0_setpixelindex to LCD _drawpoint (X, Y, pixelindex );

Ii. Set the function body of LCD _l0_getpixelindex to return LCD _readpoint (x, y), and include ili93xx. h.

Iii. Modify the main function

Rcc_configuration ();
Gpio_configuration ();
Delay_init (72 );
Gui_init ();
Gui_setbkcolor (gui_blue );
Gui_setcolor (gui_red );
Gui_dispstringat ("Hello my world! ", 150,150 );

5. Compile and download to display the image on a horizontal screen.

2. display Chinese Characters

Chinese character display requires font files. The standard font files are too large and many fonts are not used, which wastes a lot of memory space. Therefore, you generally choose to customize your font. A small software ucgui_font.exe.

1. Open the software, select the font, select the desired font format, and click OK. Enter your own font name in the text box, which cannot contain Chinese characters. Export the GBK code within a specified range, enter the Chinese character you want to display and confirm that the task is waiting for completion. The folder contains one more file. For example, if the font name is defined as my_font and contains the text "Chinese Character Display Test", a my_font.c file is generated, copied to the project directory, and added to the font directory.

2. Copy extern gui_flash const gui_font gui_fonthz_my_font;

Change to extern const gui_font gui_fonthz_my_font;

3. Modify the main function

Rcc_configuration ();
Gpio_configuration ();
Delay_init (72 );
Gui_init ();
Gui_setbkcolor (gui_blue );
Gui_setcolor (gui_red );
Gui_dispstringat ("Hello my world! ", 150,150 );
Gui_setfont (& gui_fonthz_my_font );
Gui_dispstringat ("Chinese Character Display Test", 50, 50 );

4. Compilation and download, successfully displayed

3. Transplant Touch Screen

1. Add the lixiang folder in the smart core 1 touch screen test program to the project as needed, for example:

                      

2. modify the configuration and driver File

1) because the original project is a register version and now it is a library function version, change all header files stm32f10x_lib.h to stm32f10x. h.

2) copy the SYS. c file

My_nvic_init (u8 nvic_preemptionpriority, u8 nvic_subpriority, u8 nvic_channel, u8 nvic_group)

In the last sentence of the function, change IPR to IP, that is, ipvc-> IP [ipraddr] | = temp <iproffset; // set the response priority to preemptible.

In the touch. c file, change my_nvic_init (2, 0, exti1_irqchannel, 2) to my_nvic_init (2, 0, exti1_irqn, 2 );

3) Because of the horizontal screen driver, change the drow_touch_point (u8 x, y) under the touch. c file to drow_touch_point (x, u8 y); and

Modify the corresponding declaration, the draw_big_point (u8 X, 2010y) function is the same, and the two function bodies can be changed to use ucgui painting, such as the LCD _drawline (x-12, y, X + 13, Y); // horizontal line

Change to LCD _l0_drawhline (x-12, Y, x + 13); // crossline

4) Because UCOS ⅱ is not transplanted and tasks are not supported, You need to rely on the gui_touch_exec () function to regularly refresh and the driver function to obtain the coordinate value.

Therefore, gui_touch_exec () is added to the timer interrupt extistmirqhandler to implement coordinate acquisition.

5) in the horizontal screen display, the coefficient and offset of the LCD coordinates need to be reset. In the actual detection, the touch screen in the upper right corner is insensitive and the calibration fails, therefore, change the relatively punctual point to the middle part of the screen in touch_adjust.

Change the actual four coordinate points on the screen to (50, 50), (50,190), (270,190)

And set

Pen_point.xfac = (float) 200/(pos_temp [1] [0]-pos_temp [0] [0]);
Pen_point.xoff = (240-pen_point.xfac * (pos_temp [1] [0] + pos_temp [0] [0])/2;
Pen_point.yfac = (float) 280/(pos_temp [2] [1]-pos_temp [0] [1]);
Pen_point.yoff = (320-pen_point.yfac * (pos_temp [2] [1] + pos_temp [0] [1])/2;

Change

Pen_point.xfac = (float) 220/(pos_temp [1] [0]-pos_temp [0] [0]);
Pen_point.xoff = (320-pen_point.xfac * (pos_temp [1] [0] + pos_temp [0] [0])/2;
Pen_point.yfac = (float) 140/(pos_temp [2] [1]-pos_temp [0] [1]);
Pen_point.yoff = (240-pen_point.yfac * (pos_temp [2] [1] + pos_temp [0] [1])/2;

 

6) Change gui_x_touch.c to the following program:

# Include "Gui. H"
# Include "gui_x.h"
# Include "touch. H"

Void gui_touch_x_activatex (void ){

}

Void gui_touch_x_activatey (void ){
}
/***************************************

**************************************** ***/
Int gui_touch_x_measurex (void ){

2010x, Y;
Read_ads2 (& X, & Y );
Return X;
}

Int gui_touch_x_measurey (void ){
2010x, Y;
Read_ads2 (& X, & Y );
Return y;
}

7) change the main file

# Include "stm32f10x. H"
# Include <stdio. h>
# Include "delay. H"
# Include "ili93xx. H"
# Include "Gui. H"
# Include "touch. H"
# Include "24cxx. H"

// Const unsigned char my_space [] = "Custom Chinese Character Library ";
/*************************************** **********
Function Name: void rcc_configuration (void)
Function: reset and clock Configuration
Parameter: None
Return: None

**************************************** **********/
Void rcc_configuration (void)
{
Errorstatus hsestartupstatus;
Rcc_deinit ();
Rcc_hseconfig (rcc_hse_on );
Hsestartupstatus = rcc_waitforhsestartup ();
If (hsestartupstatus = success)
{
Flash_prefetchbuffercmd (flash_prefetchbuffer_enable );
Flash_setlatency (flash_latency_2 );

Rcc_hclkconfig (rcc_sysclk_div1 );
Rcc_pclk2config (rcc_hclk_div1 );
Rcc_pclk1config (rcc_hclk_div2 );

Rcc_pllconfig (rcc_pllsource_hse_div1, rcc_pllmul_9 );
Rcc_pllcmd (enable );

While (rcc_getflagstatus (rcc_flag_pllrdy) = reset)
{
}
Rcc_sysclkconfig (rcc_sysclksource_pllclk );
While (rcc_getsysclksource ()! = 0x08)
{
}
}

Rcc_apb2periphclockcmd (rcc_apb2periph_gpiod | rcc_apb2periph_gpioe, enable );

}

/*************************************** **********

Function Name: void gpio_configuration (void)
Function: gpio Configuration
Parameter: None
Return: None
**************************************** **********/
Void gpio_configuration (void)
{
Gpio_inittypedef gpio_initstructure;


Gpio_initstructure.gpio_pin = gpio_pin_12 | gpio_pin_13 | gpio_pin_14 | gpio_pin_15;
Gpio_initstructure.gpio_speed = gpio_speed_50mhz;
Gpio_initstructure.gpio_mode = gpio_mode_out_pp;
Gpio_init (gpiod, & gpio_initstructure );

Gpio_initstructure.gpio_pin = gpio_pin_all;
Gpio_initstructure.gpio_speed = gpio_speed_50mhz;
Gpio_initstructure.gpio_mode = gpio_mode_out_pp;
Gpio_init (gpioe, & gpio_initstructure );
}

/*************************************** **********

Function Name: void gpio_configuration_key (void)
Function: Key Configuration
Parameter: None
Return: None
**************************************** **********/

Void gpio_configuration_key (void)
{
Gpio_inittypedef gpio_initstructure;

Gpio_initstructure.gpio_pin = gpio_pin_7;
Gpio_initstructure.gpio_mode = gpio_mode_ipu;
Gpio_init (gpiod, & gpio_initstructure);/* PC6 */
}

Void load_drow_dialog (void)
{
LCD _clear (white); // clear screen, white
Gui_setfont (& gui_fonthz_my_font );
Gui_setcolor (gui_red );
Gui_dispstringat ("clear",); // you need to add a Chinese Character Library
// Point_color = red; // set the paint brush color
}


/*************************************** **********
Function Name: int main (void)
Function: Main Function
Parameter: None
Return: None
**************************************** **********/
Int main (void)
{
Rcc_configuration ();
Gpio_configuration ();
Delay_init (72 );
Gui_init ();
Touch_init ();
Delay_ms (1500 );
Load_drow_dialog ();

Gpio_configuration_key ();
While (1)
{
If (gpio_readinputdatabit (gpiod, gpio_pin_7) = bit_reset)
{
Delay_ms (10 );
If (gpio_readinputdatabit (gpiod, gpio_pin_7) = bit_reset)
{
Touch_adjust (); // screen Calibration
Save_adjdata ();
Load_drow_dialog ();
}
While (gpio_readinputdatabit (gpiod, gpio_pin_7) = bit_reset ));
}
Else if (pen_point.key_sta = key_down) // the touch screen is pressed
{
Pen_int_set (0); // Guanzhong disconnection
Do
{
Convert_pos ();
Pen_point.key_sta = key_up;
If (pen_point.x0 <40 & pen_point.y0 <20) load_drow_dialog (); // clear
Else
{
Draw_big_point (pen_point.x0, pen_point.y0); // draw
Gpioc-> ODR | = 1 <1; // pull up pC1
}
} While (PEN = 0); // if the pen is always valid, it is always executed
Pen_int_set (1); // enable interrupt
} Else delay_ms (10 );

}
}

7) Compile and download, and the touch screen can be used.

 

Windows Management and ucos ii will be added in the future. I hope this will be a reference for beginners.

Stm32 transplanted ucgui + touch screen display without UCOS ⅱ

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.