⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd.c

📁 嵌入式系统
💻 C
📖 第 1 页 / 共 5 页
字号:

    for (; p1.y <= y_max; p1.y++) {
        APD_LCD_LINE_WIDTH  lw_bak = current_gc.lw;

        p2.y = p1.y;
        current_gc.lw = APD_LCD_LINE_THIN;
        apd_LCDDrawHline(&p1, &p2);
        current_gc.lw = lw_bak;
    }
#if 0
    if (lt.y < 0 && p1.y > 0) {
/* If a part of horizontal line segment is in LCD graphic area */
        int     y_max = p1.y;
        unsigned char   lw_bak = current_gc.lw;
        current_gc.lw = 1;
        for (p1.y = 0; p1.y < y_max; p1.y++)
            apd_LCDDrawHline(&p1, &p2);

        current_gc.lw = lw_bak;
//      p1.y = y_max;
    } else {
/* If all of horizontal line segment is in LCD graphic area */
        p1.y = lt.y;
        apd_LCDDrawHline(&p1, &p2);
    }
#endif
/* Draw the lower horizontal line segment of a rectangle */
    p1.y = rb.y;

    if (current_gc.lw >> 1) {
        p1.y -= current_gc.lw >> 1;
        y_max = rb.y + (current_gc.lw % 2);
    } else
        y_max = rb.y;

    for (; p1.y <= y_max; p1.y++) {
        APD_LCD_LINE_WIDTH  lw_bak = current_gc.lw;

        p2.y = p1.y;
        current_gc.lw = APD_LCD_LINE_THIN;
        apd_LCDDrawHline(&p1, &p2);
        current_gc.lw = lw_bak;
    }
    return;
}

/******************************************************************************
@@ [Name]       : apd_LCDFillRect
@@ [Summary]    : The function to draw over a rectangle
@@ [Argument]   : point : Coordinate data
@@                dim   : Length and width
@@ [Return]     : None
@@ [Desc]       : Draw over the specific rectangle data according to
@@                the current attribute.
@@                Valid attribute : Color, Raster operation, Fill type
@@ [History]    : Date      Modifier    Comment
******************************************************************************/

void apd_LCDFillRect(APD_LCD_POINT *point,APD_LCD_DIM *dim)
{
    APD_LCD_POINT lt, rb;   /* The upper left and the lower right point
                               of a rectangle */
    APD_LCD_POINT p1, p2;   /* The start and end point of the straight line */
    unsigned long  *adrs;      /* The half word address of the start point
                               for one horaizontal line */
    unsigned char   hword, byte, bit;   /* Half word, byte, bit offset */
    unsigned short  fill_ofst;
    int     i;
    short   size;       /* The number of pixels on one horizontal line */

/* Check the area to draw */
    if (dim->width < 0) {
        lt.x = point->x + dim->width;
        rb.x = point->x + 1;
    } else {
        lt.x = point->x;
        rb.x = point->x + dim->width;
    }
    if (dim->height < 0) {
        lt.y = point->y + dim->height;
        rb.y = point->y + 1;
    } else {
        lt.y = point->y;
        rb.y = point->y + dim->height;
    }

/* If the area is specified out of LCD */
    if (rb.y < 0 || rb.x < 0 || lt.y >= APD_LCD_HEIGHT ||
        lt.x >= APD_LCD_WIDTH)
        return;

/* Set the lower horizontal line segment of a rectangle */
    p1 = lt;    /* The start point */
    p2.x = rb.x;    /* The end point */
    p2.y = lt.y;

    if (p1.x < 0)
        p1.x = 0;
    if (p2.x > APD_LCD_WIDTH)
        p2.x = APD_LCD_WIDTH;
    if (p1.y < 0)
        p1.y = 0;
    if (p2.y > APD_LCD_HEIGHT)
        p2.y = APD_LCD_HEIGHT;

    fill_ofst = 0;

/* Get the address of The start point  */
    LCDGetPixelAdrs(&p1, &adrs, &hword, &byte, &bit);
    size = p2.x - p1.x;
/* Draw over a rectangle by drawing horizontal line segments */
    for (; p1.y < rb.y; ) {
        for (i = 0; p1.y < rb.y && i < LCD_SIZE_FILLPAT_H; i++) {
/* If raster operation is APD_LCD_ROP_S or APD_LCD_ROP_nS,
   and fill pattern is APD_LCD_FILL_SOLID */
            if (((current_gc.rop == APD_LCD_ROP_S) ||
                 (current_gc.rop == APD_LCD_ROP_nS)) &&
                (current_gc.ft == APD_LCD_FILL_SOLID)) {
                APD_LCD_COLOR   color;
                if (current_gc.rop == APD_LCD_ROP_nS)
                    color = ~current_gc.c;
                else
                    color = current_gc.c;
                    LCDOverwriteHline(adrs, hword, byte, bit, size, color);
            }
/* The others */
            else {
            /* Set the current fill bit pattern */
#if (APD_LCD_BPP == 16)
                unsigned short  fill_pat;

                if ((char)LCD_FILL_NONE != LCD_FILL_PAT_H[current_gc.ft][i]) {
                    fill_pat = LCD_FILL_PAT_H[current_gc.ft][i]
                        * LCD_SIZE_FILLPAT;
                    current_line_pat = LCD_FILL_PAT[fill_pat+fill_ofst];

                    LCDFillHline(adrs, hword, byte, bit, size);
                }
#else
                if ((char)LCD_FILL_NONE != LCD_FILL_PAT_H[current_gc.ft][i]) {
                    current_line_pat = LCD_FILL_PAT_H[current_gc.ft][i];

                    LCDFillHline(adrs, hword, byte, bit, size);
                }
#endif
            }
/* Renew the next horizontal line */
            (p1.y)++;
            p2.y = p1.y;
/* Renew fill pattern */
            fill_ofst++;
            if (fill_ofst >= LCD_SIZE_FILLPAT)
                fill_ofst = 0;
/* Renew the start half word address of the next line */
            adrs += LCD_OFSTPL/2;
        }
    }

    /* Return the current bit pattern of bit pattern */
    current_line_pat = LCD_LINE_PAT[current_gc.lt];

    return;
}

/******************************************************************************
@@ [Name]       : apd_LCDDrawImage
@@ [Summary]    : Draw image
@@ [Argument]   : point : Coordinates data
@@                dim   : Length and width
@@                image : Pointer to image data
@@ [Return]     : None
@@ [Desc]       : Draw the specified image according to current attribute.
@@                Image is unrelated to format according to byte
@@                endian of ARM processor and LCD controller, and pixel endian
@@                of LCD controller.
@@                Valid attribute : Raster operation
@@                Coordinates data doesn't take negative value.
@@                If it is negative value, don't draw.
@@                Length and width data doesn't take negative value.
@@                If it is negative value, don't draw.
@@ [History]    : Date      Modifier    Comment
******************************************************************************/

void apd_LCDDrawImage(APD_LCD_POINT *point,APD_LCD_DIM *dim,APD_LCD_IMAGE *image)
{
    unsigned long *adrs;           /* address written pixel data */
    unsigned char hword, byte, bit; /* half word, byte and bit offset */
    APD_LCD_DIM dimWrite;       /* Rectangle data drawn image */

/* check domain drawn */
    if (point->x < 0 || point->x >= APD_LCD_WIDTH ||
        point->y < 0 || point->y >= APD_LCD_HEIGHT ||
        dim->width <= 0 || dim->height <= 0)
        return;
/* get address written pixel data */

    LCDGetPixelAdrs(point, &adrs, &hword, &byte, &bit);

/* write pixel data */
    if ((point->x + dim->width - 1) >= APD_LCD_WIDTH)
        dimWrite.width = APD_LCD_WIDTH - point->x;
    else
        dimWrite.width = dim->width;
    if ((point->y + dim->height - 1) >= APD_LCD_HEIGHT)
        dimWrite.height = APD_LCD_HEIGHT - point->y;
    else
        dimWrite.height = dim->height;
    

    LCDWriteImage(image, dim, &dimWrite, adrs, hword, byte, bit);
    return;
}

/******************************************************************************
@@ [Name]       : apd_LCDDrawBMP
@@ [Summary]    : Draw bit map image
@@ [Argument]   : point : Coordinates data
@@                dim   : Length and width
@@                image : Pointer to monochrome bit map data
@@ [Return]     : None
@@ [Desc]       : Draw the specified monochrome bit map data according to
@@                the current attribute.
@@                Valid attribute : Color, Raster operation
@@                Coordinates data doesn't take negative value.
@@                If it is negative, don't draw.
@@                Length and width data doesn't take negative value.
@@                If it is negative, don't draw.
@@ [History]    : Date      Modifier    Comment
******************************************************************************/

void apd_LCDDrawBMP(APD_LCD_POINT *point,APD_LCD_DIM *dim,APD_LCD_IMAGE *image)
{
    unsigned long *adrs;           /* address written pixel data */
    unsigned char hword, byte, bit; /* Half word, byte and bit offset */
    APD_LCD_DIM dimWrite;       /* Rectangle drawn bit map */

/* Check domain drawn */
    if (point->x < 0 || point->x >= APD_LCD_WIDTH ||
        point->y < 0 || point->y >= APD_LCD_HEIGHT ||
        dim->width <= 0 || dim->height <= 0)
        return;

/* get address written pixel data */
    LCDGetPixelAdrs(point, &adrs, &hword, &byte, &bit);

/* write pixel data */
    if ((point->x + dim->width - 1) >= APD_LCD_WIDTH) {
        dimWrite.width = APD_LCD_WIDTH - point->x;
    } else {
        dimWrite.width = dim->width;
    }
    if ((point->y + dim->height - 1) >= APD_LCD_HEIGHT) {
        dimWrite.height = APD_LCD_HEIGHT - point->y;
    } else {
        dimWrite.height = dim->height;
    }
    LCDWriteBMP(image, dim, &dimWrite, adrs, hword, byte, bit); 
    return;
}

/******************************************************************************
@@
@@ [Name]       : apd_LCDGetPixel
@@
@@ [Summary]    : Get pixel data
@@
@@ [Argument]   : point : Coordinates data
@@
@@ [Return]     : Color of pixel
@@
@@ [Desc]       : Read pixel data (color) of the specified coordinate.
@@
@@                If coordinates are outside the range, don't get pixel data
@@                and return 0.
@@
@@ [History]    : Date      Modifier    Comment
@@
@@ [END]
******************************************************************************/
APD_LCD_COLOR apd_LCDGetPixel(APD_LCD_POINT *point)
{
    APD_LCD_COLOR color;            /* pixel data */
    unsigned long *adrs;               /* address read pixel data */
    unsigned char hword, byte, bit;     /* half word, byte, bit offset */

/* Check coordinates data */
    if (point->x < 0 || point->x >= APD_LCD_WIDTH ||
        point->y < 0 || point->y >= APD_LCD_HEIGHT)
        return (APD_LCD_COLOR)0;

/* Get address read pixel data */
    LCDGetPixelAdrs(point, &adrs, &hword, &byte, &bit);

/* Read pixel data */
    color = LCDReadPixel(adrs, hword);	//, byte, bit);

    return(color);
}

/******************************************************************************
@@
@@ [Name]       : apd_LCDGetImage
@@
@@ [Summary]    : Get image data
@@
@@ [Argument]   : point : Coordinates data
@@                dim   : Length and width
@@                image : Pointer to the buffer written image data
@@
@@ [Return]     : none
@@
@@ [Desc]       : Read image data of the specified coordinates and size.
@@                Image data is unrelated to format according to byte endian
@@                of ARM processor and LCD controller, and pixel endian of
@@                LCD controller.
@@
@@                If coordinates are outside the range, don't get image data
@@
@@                If the domain specified by 'dim' is larger than LCD domain,
@@                read image data in data size within LCD domain, and
@@                the value of 'dim' is updated by the size which read.
@@
@@ [History]    : Date      Modifier    Comment
@@
@@ [END]
******************************************************************************/
void apd_LCDGetImage(APD_LCD_POINT *point,APD_LCD_DIM *dim,APD_LCD_IMAGE *image)
{
    unsigned long *adrs;               /* address read pixel data */
    unsigned char hword, byte, bit;     /* half word, byte, bit, offset */

/* Check the domain read */
    if (point->x < 0 || point->x >= APD_LCD_WIDTH ||
        point->y < 0 || point->y >= APD_LCD_HEIGHT)
        return;

    if (point->x + dim->width > APD_LCD_WIDTH)
        dim->width = APD_LCD_WIDTH - point->x - 1;

    if (point->y + dim->height > APD_LCD_HEIGHT)
        dim->height = APD_LCD_HEIGHT - point->y - 1;

/* Get address read pixel data */
    LCDGetPixelAdrs(point, &adrs, &hword, &byte, &bit);

/* Read pixel data */
    LCDReadImage(image, dim, adrs, hword, byte, bit);

    return;
}

/******************************************************************************
@@
@@ [Name]       : apd_LCDSetLineStyle
@@
@@ [Summary]    : Set line type
@@
@@ [Argument]   : line_type : Line type (either of the following)
@@                            APD_LCD_LINE_SOLID
@@                            APD_LCD_LINE_DOT
@@                            APD_LCD_LINE_DASH
@@                            APD_LCD_LINE_DASH_DOT
@@
@@ [Return]     : none
@@
@@ [Desc]       : Specify line type when drawing a line
@@                Valid drawing function : apd_LCDDrawVline, apd_LCDDrawHline,
@@                                         apd_LCDDrawLine, apd_LCDDrawRect
@@
@@ [History]    : Date      Modifier    Comment
@@
@@ [END]
******************************************************************************/
void apd_LCDSetLineStyle(
APD_LCD_LINE_TYPE line_type
)
{
    current_gc.lt = line_type;
    current_line_pat = LCD_LINE_PAT[current_gc.lt];
    return;
}

/******************************************************************************
@@
@@ [Name]       : apd_LCDSetLineWidth
@@
@@ [Summary]    : Set line width
@@
@@ [Argument]   : line_width : Line width (either of the following)
@@                             APD_LCD_LINE_THIN
@@                             APD_LCD_LINE_MID
@@                             APD_LCD_LINE_THICK
@@
@@ [Return]     : None
@@
@@ [Desc]       : Set line width when drawing a line
@@                Valid drawing function : apd_LCDDrawVline, apd_LCDDrawHline,
@@                                         apd_LCDDrawLine, apd_LCDDrawRect
@@
@@ [History]    : Date      Modifier    Comment
@@
@@ [END]
******************************************************************************/
void apd_LCDSetLineWidth(
APD_LCD_LINE_WIDTH line_width
)
{
    current_gc.lw = line_width;
    return;
}

/******************************************************************************
@@
@@ [Name]       : apd_LCDSetColor
@@
@@ [Summary]    : Set color
@@
@@ [Argument]   : color : Pixel color data
@@

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -