S5PV210 Development Series Four Ucgui porting
Chess Boy 1048272975
GUI (graphical user interface) greatly facilitates the use of non-professional users, users do not have to memorize a large number of commands, instead of the window, menus, buttons and other ways to operate. In some cases, the design of a human-machine interface rich and friendly embedded products can win more users. The author here is a simple introduction to the use of s5pv210 based on the Ucgui graphical user interface.
1. Ucgui Porting Overview 1.1. s5pv210 Bootloader
The author of the s5pv210 bootloader set the highest CPU frequency 1ghz,mmu 1:1 memory space linear mapping, and open L1 i/d cache, L2 cache, Hardware branch prediction function, so that the CPU can achieve maximum throughput performance. Initialize memory, be able to recognize SD/MMC boot and NAND flash boot, automatically load application code to RAM location. A unified interrupt management architecture, redirection of underlying IO operations, support for direct code download of memory runs and Nandflash downloads, can be more focused on application development.
1.2. Ucgui Source code
The author of Ucgui 3.98 This version of the transplant as a description, this version of the Ucgui is the highest version of open source, after the version only provides library files, no longer open source, about Ucgui overview, use, porting and other details, you can directly read Ucgui user manual.
1.3. Ucgui Interface Implementation
Ucgui according to the functions it uses, it must first implement its corresponding function interface. For Ucgui, both the display and the time-base timings are necessary, so they must be implemented with their interfaces. Display is the implementation of the corresponding screen driver, time-base timing is to achieve 1ms/tick timing count, Ucgui used to achieve timing. The Ucgui touchscreen feature is also used here, so the corresponding touchscreen driver should also be implemented.
2. Interface porting Driver 2.1. Screen Drive
Screen driver mainly provides the setting of a pixel color interface display_setpixel and from a coordinate readout pixel color interface display_getpixel to Ucgui. S5PV210 has an RGB interface, so the screen driver is also mainly the initialization of the RGB interface, according to the specific screen, set its level resolution, vertical resolution, pixel clock, cache location and so on. The RGB controller is DMA to the memory frame data transfer to the external interface, so the CPU changes to the memory data should be written back to the physical memory memory, or there will be cache data consistency problem.
The bootloader provides four memory allocation strategies for the cache:
Cached, Write-back, writeback mode, every time the CPU reads and writes to the cache, it reads and writes only the cache and does not read and write main memory. This mode does not have to read and write the slow main memory, so the CPU has the highest performance, the default memory allocation method.
Cached, Write-through, write-through mode, CPU per read if the cache hit read cache, do not read main memory, each write even if the cache hit update cache, will be subsequently written to main memory, reducing the system's write speed, The memory field in Bootloader is ". MEM_CNB".
Non-cached, buffered, non-cached, write cache open. Each time the CPU reads and writes, the cache is not hit, the CPU writes the data to the cache as soon as it resumes execution, and the caches are subsequently updated to main memory. The cache function is not used, the CPU read/write performance is relatively low, the memory domain in Bootloader is ". MEM_NCB".
Non-cached, non-buffered, non-cached, write cache not turned on. Every time the CPU reads and writes from main memory, due to the slowness of main memory, this mode of reading and writing performance is low, the memory domain in Bootloader is ". MEM_NCNB".
For RGB memory, in addition to the writeback mode, the other mode of writing will update main memory, there is no consistency problem of display, in order to achieve the highest CPU performance, RGB memory should be allocated in the write-mode memory area.
-Bit (565)
Uint16_tdisplaybuffer[hsize*vsize] @ ". MEM_CNB"; Cached, write through
At the same time, for data DMA, in order to ensure data consistency is always, the simplest way, the DMA region memory allocation to the non-cached, non-buffered domain, although sacrificing performance, but there is no cache consistency problem.
UINT32_TDMA_BUFFER[XXX] @ ". MEM_NCNB";
2.2. Touch Screen Driver
Touch screen driver mainly provides touch point x position interface tp_getpoint1_x and return touch point Y position interface tp_getpoint1_y to Ucgui. The author uses the capacitive screen, the general capacitive screen is the use of I²c interface, it must first realize the I²c drive. The capacitive screen generally supports multi-touch, but the Ucgui only supports single touch, so the capacitive screen interrupt output is configured as a query method to determine whether there is a touch event by querying the level state of the interrupt line.
Int32_ttp_getpoint1_x (void)
{
uint8_t point1_x[2];
if (! ( Gph0dat_reg & Ft5206_int)) {//touch screen when pressed, INT pull low
Get 12-bit x-axis coordinates
Tp_readregs (Ft5206_touch1_xh, point1_x,2);
if (! ( Gph0dat_reg & Ft5206_int)) {
The ad should remain pressed when it is acquired, or the ad value may be inaccurate and should be discarded
Return ((((int32_t) (POINT1_X[0]&0XF) << 8) | POINT1_X[1]);
}
}
return-1; Returns an invalid value, the table is not pressed or released
}
Int32_ttp_getpoint1_y (void)
{
uint8_t point1_y[2];
if (! ( Gph0dat_reg & Ft5206_int)) {//touch screen when pressed, INT pull low
Get 12-bit y-axis coordinates
Tp_readregs (Ft5206_touch1_yh, point1_y,2);
if (! ( Gph0dat_reg & Ft5206_int)) {
The ad should remain pressed when it is acquired, or the ad value may be inaccurate and should be discarded
Return ((((int32_t) (POINT1_Y[0]&0XF) << 8) | POINT1_Y[1]);
}
}
return-1; Returns an invalid value, the table is not pressed or released
}
Int32_ttp_writeregs (uint8_t writeaddr, uint8_t *pdata,uint8_t Len)
{
uint8_t packet[64];
uint8_t i;
if (Len >= sizeof (Packet)) {
return-1;
}
Packet[0] = writeaddr;
for (i=0; i<len; i++) {
PACKET[I+1] = Pdata[i];
}
Return I2c_writebytes (FT5206_ADDR, packet,len+1);
}
Int32_ttp_readregs (uint8_t readaddr, uint8_t *pdata, uint8_t Len)
{
int32_t Ret;
Write the internal register address to be read
Ret = I2c_writebytes (ft5206_addr,&readaddr, 1);
if (Ret = = 0) {
Return I2c_readbytes (FT5206_ADDR, Pdata,len);
}
return Ret;
}
2.3. Timer Driver
Ucgui is used as the time base by Os_timems, so a timer is required to implement the 1ms/tick update Os_timems this time base counter. The s5pv210 Timer4 is used here to initialize and register the corresponding interrupt after the interrupt callback function is updated os_timems, while processing Ucgui about 100HZ frequency Query touch screen input task.
Uint8_ttp_period;
Staticvoid timer4_callback (void)
{
extern volatile int os_timems;
os_timems++; 1ms count, defined in gui_x.c, used to Ucgui delay count
#ifGUI_SUPPORT_TOUCH
tp_period++;
if (Tp_period >= 10) {//Every 10ms check touch screen input
Tp_period = 0;
Irq_disableint (INT_TIMER4); Disable the same interrupt re-entry
Irq_enable (); Allow i²c nesting interrupts in timer interrupt handling
Gui_touch_exec (); Guaranteed 100HZ touch-screen input check
Irq_enableint (INT_TIMER4);
}
#endif
}
3. Ucgui Modification 3.1. Guiconfig Directory
Enter the Guiconfig directory, open the GUIConf.h to the GUI for overall configuration, due to sufficient memory, you can set up a large dynamic memory and support memory devices, the operating system and mouse are not supported here. The revised content is as follows:
#ifndef Guiconf_h
#define Guiconf_h
#define GUI_OS (0)/* does not support multitasking */
#defineGUI_SUPPORT_TOUCH (1)/* Support a TOUCH screen (req. win-manager) */
#define GUI_SUPPORT_MOUSE (0)/* does not support mouse */
#defineGUI_SUPPORT_UNICODE (1)/* Support mixed ascii/unicode strings */
#defineGUI_DEFAULT_FONT &gui_font6x8
#defineGUI_ALLOC_SIZE (4*1024*1024)/* Dynamic memory 4m*/
/*********************************************************************
*
* Configuration of available packages
*/
#defineGUI_WINSUPPORT 1/* Window Manager Package Available */
#defineGUI_SUPPORT_MEMDEV 1/* Memory devices available */
#defineGUI_SUPPORT_AA 1/* Anti aliasing Available */
#endif/* avoidmultiple inclusion */
Open LCDConf.h to the LCD configuration, the author uses a 16-bit (r:5-g:6-b:5) color deep 800*480 RGB screen, empty all the contents of LCDConf.h, because this is the configuration of other LCD screen, and the screen is completely inconsistent with the modified content as follows:
#ifndef Lcdconf_h
#define Lcdconf_h
/*********************************************************************
* Generalconfiguration of LCD
**********************************************************************
*/
#define LCD_XSIZE (800)/* screen x horizontal pixels */
#define LCD_YSIZE (480)/* screen y horizontal pixels */
#define LCD_BITSPERPIXEL (16)/* 16-bit color depth */
#define Lcd_controller (-1)/* Macro switch, use the template under Lcddriver */
#define Lcd_fixedpalette (565)/* R:5-g:6-b:5 */
#define LCD_SWAP_RB (1)/*RB Color Swap */
#define LCD_SWAP_XY (0)/* screen x, y direction not reversed */
#define Lcd_init_controller () Display_init ()/* Screen Driver initialization interface */
#endif/* Lcdconf_h */
Open GUITouchConf.h To configure the touch screen, the author uses a capacitive screen, the driver IC has been processed to return the touch coordinate value corresponding to the screen pixel coordinates one by one, can also be calibrated after the transplant.
#ifndefGUITOUCH_CONF_H
#defineGUITOUCH_CONF_H
#define GUI_TOUCH_AD_LEFT 0/* touch screen to return to the leftmost value */
#defineGUI_TOUCH_AD_RIGHT 800/* touch screen to return to the rightmost value */
#defineGUI_TOUCH_AD_TOP 0/* touch screen to return the topmost value */
#defineGUI_TOUCH_AD_BOTTOM 480/* touch screen to return to the bottom of the value */
#defineGUI_TOUCH_SWAP_XY 0/* touch screen x, y direction not reversed */
#defineGUI_TOUCH_MIRROR_X 0/* No mirror swap in the X-direction of the touchscreen */
#defineGUI_TOUCH_MIRROR_Y 0/* Touch screen Y direction does not mirror swap */
#endif/*guitouch_conf_h * *
3.2. Lcddriver Directory
To enter the Gui->lcddriver directory, you need to modify Ucgui's underlying interface call about the actual LCD. Since we configured Lcd_controller in LCDConf.h to 1, this macro switch will choose LCDTEMPLATE.C This template file to compile, the other interface files will not be compiled. LCDTEMPLATE.C already have the relevant template code, just add Lcd_l0_setpixelindex () and lcd_l0_getpixelindex () implementation can, lcd_l0_ Setpixelindex sets the pixel value of a coordinate of the LCD, lcd_l0_getpixelindex the pixel value from a certain coordinate of the LCD, respectively, corresponding to the RGB screen driver underlying function display_setpixel () and Display_getpixel ()。 Add the two underlying functions.
Lcd_l0_setpixelindex () The modified code is as follows:
void Lcd_l0_setpixelindex (int x, int y, int pixelindex) {
Gui_use_para (x);
Gui_use_para (y);
Gui_use_para (Pixelindex);
/* Convert logical to Physicalcoordinates (DEP. On LCDConf.h) */
#if Lcd_swap_xy | Lcd_mirror_x| Lcd_mirror_y
int Xphys = log2phys_x (X, y);
int Yphys = log2phys_y (x, Y);
#else
#define Xphys X
#define Yphys y
#endif
/* Write into hardware ... ADAPT toyour System */
{
Display_setpixel (x, Y, (unsignedshort) pixelindex);
}
}
Lcd_l0_getpixelindex () The modified code is as follows:
unsigned int lcd_l0_getpixelindex (int x, int y) {
Lcd_pixelindex Pixelindex;
Gui_use_para (x);
Gui_use_para (y);
/* Convert logical to Physicalcoordinates (DEP. On LCDConf.h) */
#if Lcd_swap_xy | Lcd_mirror_x| Lcd_mirror_y
int Xphys = log2phys_x (X, y);
int Yphys = log2phys_y (x, Y);
#else
#define Xphys X
#define Yphys y
#endif
/* Read from hardware ... ADAPT toyour System */
{
pixelindex= (Lcd_pixelindex) (Display_getpixel (x, y));
}
return pixelindex;
}
3.3. gui_x Directory
Before the GUI starts, in addition to the LCD may have other required to initialize the hardware devices, such as Ucgui to use LCD and touch screen, then the GUI should be initialized before the use of these devices, which is processed in the Gui_x_init () function, in the Gui_x_init () function is implemented as follows:
void Gui_x_init (void)
{
#if Gui_support_touch
Tp_init ();//Initialize touch screen when using Ucgui
#endif
}
GUI_X_TOUCH.C for Ucgui touch screen access interface, as long as the implementation of Gui_touch_x_measurex () and Gui_touch_x_measurey (). These two functions correspond to the underlying function tp_getpoint1_x () and tp_getpoint1_y () of the first touch point x, y position of the capacitive screen driver.
int Gui_touch_x_measurex (void) {
return tp_getpoint1_x ();
}
int Gui_touch_x_measurey (void) {
return tp_getpoint1_y ();
}
4. Ucgui Demo Application
The application invokes the corresponding Ucgui routine demo, which has the following effects:
5. Appendix
S5pv210_ucgui.rar,ucgui in the IAR under the transplant project, including s5pv210 Bootloader, Ucgui source code, and the corresponding RGB, TP, i²c, timer driver.
Http://pan.baidu.com/s/1sj1F2W1
S5PV210 Development Series Four _ucgui porting