Uboot LCD 添加进度条功能

使用Uboot自动烧写镜像时,通常会在LCD屏幕上显示当前工作的进度条,下面给出一种画进度条的方法(仅支持32位和16位LCD):

1. 宏定义声明


#define PROBAR_WIDTH    600 //进度条宽度  
#define PROBAR_HEIGHT   30  //进度条高度  
#define PROBAR__PIEXL   2   //边框像素  
  
#define EDGING_COLOR    CONSOLE_COLOR_WHITE //边框颜色  
#define PROBAR_COLOR    CONSOLE_COLOR_GREEN //进度条颜色    
#define BACKGD_COLOR    CONSOLE_COLOR_BLACK //背景颜色

1. 画进度条边框函数

/*画进度条边框*/
void LCD_draw_pb_edging(ushort x,ushort y) 
{   
    int  i, j;
    uchar *lcd_base, *dest;
#if (LCD_BPP == LCD_COLOR32)
    uint *tmp;
#else
    ushort *tmp;
#endif 

    lcd_get_size(&lcd_line_length);  
    lcd_base = map_sysmem(gd->fb_base, 0); 
     
    dest = (uchar *)( lcd_base + y * lcd_line_length + x * sizeof(*tmp));  
  
    for(i=0; i<PROBAR_HEIGHT; i++) 
    {   tmp = dest;
        for(j=0; j<PROBAR_WIDTH; j++) 
        {  
            if((i < PROBAR_PIEXL) || (i >= (PROBAR_HEIGHT - PROBAR_PIEXL)) || 
               (j < PROBAR_PIEXL) || (j >= (PROBAR_WIDTH  - PROBAR_PIEXL)))  
                *tmp = EDGING_COLOR;  
            tmp++;  
        }  
        dest += lcd_line_length;  
    }  
}  

2.画进度条

/*画进度条*/
void LCD_draw_progress_bar(ushort x,ushort y,int percent_age) 
{   
    int  i, j;
    int current_bar_width, current_bar_color;
    uchar *lcd_base, dest;
#if (LCD_BPP == LCD_COLOR32)
    uint *tmp;
#else
    ushort *tmp;
#endif 

    lcd_get_size(&lcd_line_length);  
    lcd_width = lcd_get_pixel_eidth();
    lcd_base = map_sysmem(gd->fb_base, 0); 
     
    dest = (uchar *)( lcd_base + (y + PROBAR__PIEXL + 1) * lcd_line_length  \
           + (x + PROBAR__PIEXL + 1)* sizeof(*tmp));
    
    if(percent_age == 0)
    {
        current_bar_width = PROBAR_WIDTH - PG_PIEXL - 1;
        current_bar_color = BACKGD_COLOR;
    }    
    else
    {   
        current_bar_width = (PROBAR_WIDTH - PG_PIEXL - 1) * percent_age / 100;
        current_bar_color = PROBAR_COLOR; 
    } 
 
    for(i=0; i<(PROBAR_HEIGHT - PROBAR_PIEXL - 1); i++) 
    {  
        tmp = dest;  
        for(j=0; j<current_bar_width; j++) 
            *tmp++ = color;  
 
        dest += lcd_line_length;  
    }
}  

猜你喜欢

转载自blog.csdn.net/sean_8180/article/details/82285127