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

📄 sdk7a404_emwin.c

📁 含t h r e a d x,u c o s 的b s p
💻 C
📖 第 1 页 / 共 2 页
字号:
}
#endif

/***********************************************************************
 *
 * Function: LCD_L0_Init
 *
 * Purpose: Initialize the LCD controller
 *
 * Processing:
 *     Initializes the LCD through the Sharp LH7A404 CSP based on the
 *     configured LCDPANEL define.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Always returns 0
 *
 * Notes: None
 *
 **********************************************************************/
int LCD_L0_Init(void)
{
    int xv, yv;
    CMEM_TYPE *vbuf;
    INT_32 regionsize;

    /* Setup LCD muxing for all 16 data bits */
    gpio_lcd_signal_select(GPIO_LCDV_0_15);

    /* Get handle to LCD device */
    lcddev = lcd_open(CLCDC, (INT_32) &LCDPANEL);

    /* Make sure shared JTAG signal on PA2 is not active */
    gpio_set_data_dir(GPIO_PORT_A, 0x04, GPIO_OUTPUT);
    gpio_data_write(GPIO_PORT_A, 0x04);

    /* For displays that require more bandwidth, set DMA to request
       a transfer on 4 words empty instead of the default 8. This may
       help prevent 'display tearing' due to a starved LCD controller */
    regionsize = lcd_ioctl(lcddev, LCD_GET_STATUS, LCD_XSIZE) *
        lcd_ioctl(lcddev, LCD_GET_STATUS, LCD_YSIZE) * 2;
    if (regionsize >= (800 * 600 * 2))
    {
        /* Displays of 800x600 pixels and 16-bits of color (or larger)
           will use faster DMA requests */
        lcd_ioctl(lcddev, LCD_DMA_ON_4MT, 1);
    }

    /* HRTFT/TFT panel board initialization only */
    if ((lcd_ioctl(lcddev, LCD_GET_STATUS, LCD_PANEL_TYPE) == HRTFT) ||
        (lcd_ioctl(lcddev, LCD_GET_STATUS, LCD_PANEL_TYPE) == ADTFT) ||
        (lcd_ioctl(lcddev, LCD_GET_STATUS, LCD_PANEL_TYPE) == TFT))
    {
        /* Enable power to the LCD panel (sets VDDEN on PC3) */
        gpio_set_data_dir(GPIO_PORT_C, 0x08, GPIO_OUTPUT);
        gpio_data_write(GPIO_PORT_C, 0x08);
    }
    else
    {
        /* Other displays - do nothing (yet) */
        ;
    }

    /* Get logical frame buffer address */
#ifdef STATIC_VBUF
    vlogbuf = (CMEM_TYPE *) fbuffer;

#else
    vlogbuf = (CMEM_TYPE *) VBUF_ADDR;
#endif

    /* Set physical frame buffer address in hardware */
    lcd_ioctl(lcddev, LCD_SET_UP_FB,
        (INT_32) cp15_map_virtual_to_physical(vlogbuf));

#if LCD_BITSPERPIXEL == 8
    /* Set color depth to 8 bits per pixel */
    lcd_ioctl(lcddev, LCD_SET_BPP, 8);

    /* Support for 8-bit mode using a palette table will be added
       here */

#else
    /* Set color depth to 16 bits per pixel */
    lcd_ioctl(lcddev, LCD_SET_BPP, 16);
#endif

    /* Before enabling the display, clear video memory */
    vbuf = vlogbuf;
    for (yv = 0; yv < LOCAL_LCD_YSIZE; yv++)
    {
        for (xv = 0; xv < LOCAL_LCD_XSIZE; xv++)
        {
            *vbuf = 0;
            vbuf++;
        }
    }
    
    return 0;
}

/***********************************************************************
 *
 * Function: LCD_L0_Reinit
 *
 * Purpose: Re-initialize the LCD controller
 *
 * Processing:
 *     Does nothing, stub function only.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Always returns 0
 *
 * Notes: None
 *
 **********************************************************************/
int LCD_L0_Reinit(void)
{
    return 0;
}

/***********************************************************************
 *
 * Function: LCD_L0_Off
 *
 * Purpose: Disable the display
 *
 * Processing:
 *     See function.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void LCD_L0_Off(void)
{
    /* Disable LCD controller and power signals */
    lcd_ioctl(lcddev, LCD_PWENABLE, 0);
}

/***********************************************************************
 *
 * Function: LCD_L0_On
 *
 * Purpose: Enable the display
 *
 * Processing:
 *     See function.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void LCD_L0_On(void)
{
    /* Enable LCD controller and power signals */
    lcd_ioctl(lcddev, LCD_PWENABLE, 1);
}

/***********************************************************************
 *
 * Function: LCD_L0_DrawBitMap
 *
 * Purpose: Draw a bitmap on the LCD
 *
 * Processing:
 *     Based on the bitmap depth, call the needed bitmap rendering
 *     function for each bitmap line.
 *
 * Parameters:
 *     x0:           Left edge of location to place bitmap
 *     y0:           Upper edge of location to place bitmap
 *     Xsize:        Horizontal size of bitmap
 *     Ysize:        Vertical size of bitmap
 *     BitsPerPixel: Bits per pixel
 *     BytesPerLine: Bytes per bitmap line
 *     pData:        Pointer to bitmap data
 *     Diff:         Left side pixel skip difference
 *     pTrans:       Pointer to transparency
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void LCD_L0_DrawBitmap(int x0,
                       int y0,
                       int Xsize,
                       int Ysize,
                       int BitsPerPixel,
                       int BytesPerLine,
                       const U8* pData,
                       int Diff,
                       const LCD_PIXELINDEX *pTrans)
{
    int i;

    /* Draw each line through a bit line rendering function */
    for (i = 0; i < Ysize; i++) 
    {
        switch (BitsPerPixel)
        {
            case 1:
                _DrawBitLine1BPP(x0, (i + y0), pData, Diff, Xsize,
                    pTrans);
                break;
#if LCD_MAX_LOG_COLORS > 2
            case 2:
                _DrawBitLine2BPP(x0, (i + y0), pData, Diff, Xsize,
                    pTrans);
                break;
#endif
#if LCD_MAX_LOG_COLORS > 4
            case 4:
                _DrawBitLine4BPP(x0, (i + y0), pData, Diff, Xsize,
                    pTrans);
                break;
#endif
#if LCD_MAX_LOG_COLORS > 16
            case 8:
                _DrawBitLine8BPP(x0, (i + y0), pData, Xsize, pTrans);
                break;
#endif
#if LCD_MAX_LOG_COLORS > 256
            case 16:
                _DrawBitLine16BPP(x0, (i + y0), (U16 *) pData,
                    Xsize, pTrans);
                break;
#endif
        }

        /* Start of next data */
        pData += BytesPerLine;
    }
}

/***********************************************************************
 *
 * Function: LCD_L0_DrawHLine
 *
 * Purpose: Draw a horizontal line on the display
 *
 * Processing:
 *     See function.
 *
 * Parameters:
 *     x0: Left X position of line
 *     y:  Vertical line position
 *     x1: Right X position of line
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void LCD_L0_DrawHLine(int x0, int y, int x1)
{
    CMEM_TYPE *vbuf;

    /* Precompute Y offset for frame buffer to save time during
       rendering */
    vbuf = vlogbuf + (y * LOCAL_LCD_XSIZE);

    /* If this is an XOR line, invert the color for the line */
    if ((GUI_Context.DrawMode & LCD_DRAWMODE_XOR) != 0)
    {
        /* XOR line draw */
        while (x0 <= x1)
        {
            *(vbuf + x0) = (LCD_NUM_COLORS - *(vbuf + x0) - 1);
            x0++;
        }
    }
    else
    {
        /* Normal line draw */
        while (x0 <= x1)
        {
            *(vbuf + x0) = LCD_COLORINDEX;
            x0++;
        }
    }
}

/***********************************************************************
 *
 * Function: LCD_L0_DrawPixel
 *
 * Purpose: Put a single pixel on the display
 *
 * Processing:
 *     See function.
 *
 * Parameters:
 *     x: X position of pixel to set to foreground color
 *     y: Y position of pixel to set to foreground color
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void LCD_L0_DrawPixel(int x, int y)
{
    *(vlogbuf + (y * LOCAL_LCD_XSIZE) + x) = LCD_COLORINDEX;
}

/***********************************************************************
 *
 * Function: LCD_L0_DrawVLine
 *
 * Purpose: Draw a vertical line on the display
 *
 * Processing:
 *     See function.
 *
 * Parameters:
 *     x:  Horizontal line position
 *     y0: Upper Y position of line
 *     y1: Lower Y position of line
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void LCD_L0_DrawVLine(int x, int y0, int y1)
{
    CMEM_TYPE *vbuf;

    /* Precompute X offset for frame buffer to save time during
       rendering */
    vbuf = vlogbuf + x;

    /* If this is an XOR line, invert the color for the line */
    if ((GUI_Context.DrawMode & LCD_DRAWMODE_XOR) != 0)
    {
        /* XOR line draw */
        while (y0 <= y1)
        {
            *(vbuf + (y0 * LOCAL_LCD_XSIZE)) =
                (LCD_NUM_COLORS - *(vbuf + (y0 * LOCAL_LCD_XSIZE)) - 1);
            y0++;
        }
    }
    else
    {
        /* Normal line draw */
        while (y0 <= y1)
        {
            *(vbuf + (y0 * LOCAL_LCD_XSIZE)) = LCD_COLORINDEX;
            y0++;
        }
    }
}

/***********************************************************************
 *
 * Function: LCD_L0_FillRect
 *
 * Purpose: Draw a filled rectangle on the display
 *
 * Processing:
 *     See function.
 *
 * Parameters:
 *     x0: Upper left X position of rectangle
 *     y0: Upper left Y position of rectangle
 *     x1: Lower right X position of rectangle
 *     y1: Lower right Y position of rectangle
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void LCD_L0_FillRect(int x0, int y0, int x1, int y1)
{
    CMEM_TYPE *vbuf;
    int x;

    while (y0 < y1)
    {
        /* Precompute Y offset for frame buffer to save time during
           rendering */
        vbuf = vlogbuf + (y0 * LOCAL_LCD_XSIZE);
        y0++;

        x = x0;
        while (x < x1)
        {
            *(vbuf + x) = LCD_COLORINDEX;
            x++;
        }
    }
}

/***********************************************************************
 *
 * Function: LCD_L0_SetPixelIndex
 *
 * Purpose: Draw a pixel in the selected color on the display
 *
 * Processing:
 *     See function.
 *
 * Parameters:
 *     x:          X position of pixel to invert
 *     y:          Y position of pixel to invert
 *     ColorIndex: Color to set pixel
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void LCD_L0_SetPixelIndex(int x, int y, int ColorIndex)
{
    *(vlogbuf + (y * LOCAL_LCD_XSIZE) + x) = (CMEM_TYPE) ColorIndex;
}

/***********************************************************************
 *
 * Function: LCD_L0_XorPixel
 *
 * Purpose: Invert a pixel on the display
 *
 * Processing:
 *     See function.
 *
 * Parameters:
 *     x: X position of pixel to invert
 *     y: Y position of pixel to invert
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void LCD_L0_XorPixel(int x, int y)
{
    *(vlogbuf + (y * LOCAL_LCD_XSIZE) + x) =
        (LCD_NUM_COLORS - *(vlogbuf + (y * LOCAL_LCD_XSIZE) + x) - 1);
}

/***********************************************************************
 *
 * Function: LCD_L0_GetPixelIndex
 *
 * Purpose: Returns the index value of a pixel
 *
 * Processing:
 *     See function.
 *
 * Parameters:
 *     x: X position of pixel to get
 *     y: Y position of pixel to get
 *
 * Outputs: None
 *
 * Returns: The color index value of the selected pixel
 *
 * Notes: None
 *
 **********************************************************************/
unsigned int LCD_L0_GetPixelIndex(int x, int y)
{
    return (int) *(vlogbuf + (y * LOCAL_LCD_XSIZE) + x);
}

/***********************************************************************
 *
 * Function: LCD_L0_SetLUTEntry
 *
 * Purpose: Lookup table set entry function
 *
 * Processing:
 *     Do nothing, stub function only.
 *
 * Parameters:
 *     Pos:   Table position
 *     Color: New color
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void LCD_L0_SetLUTEntry(U8 Pos, LCD_COLOR Color)
{
    ;
}

/***********************************************************************
 *
 * Function: LCD_ControlCache
 *
 * Purpose: Cache flush function
 *
 * Processing:
 *     Do nothing, stub function only.
 *
 * Parameters:
 *     command: Cache command
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
U8 LCD_ControlCache(U8 command)
{
    /* Do nothing for now */
    return command;
}

/***********************************************************************
 *
 * Function: LCD_L0_Palette_Set
 *
 * Purpose: Palette setup function
 *
 * Processing:
 *     Do nothing, stub function only.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void LCD_L0_Palette_Set(void)
{
    ;
}

⌨️ 快捷键说明

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