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

📄 ddi_display_controller_hx8347a.c

📁 LCD驱动源代码 应用于手机的话,需要改写,找了好久,网上下的,将就一下了,参考参考,自己动手改一下吧.有在MTK平台上改成功的,放上来给大家参考一下啊
💻 C
📖 第 1 页 / 共 4 页
字号:
    //     ---------------------
    //    |                     | G0
    //    |                     |
    //    |                     |
    //    |                     |
    //    |                     |
    //    |                     |
    //    |                     |    320
    //    |                     |
    //    |                     |
    //    |                     |
    //    |                     |
    //    |                     |
    //    |                     | G319
    //     ---------------------
    //        |Ribbon cable |
    //        ---------------
    //
    switch(eRotation)
    {//11 03 12 00
       case DDI_DISPLAY_ROTATION_NONE: 
	     u16SourceWinStart_high=(uint16_t)(((u32XDst)&0x0000FF00)>>8);
             u16SourceWinStart_low=(uint16_t)((u32XDst)&0x000000FF);
             u16SourceWinStop_high=(uint16_t)(((u32XDst + *pu32Width - 1)&0x0000FF00)>>8);
             u16SourceWinStop_low=(uint16_t)((u32XDst + *pu32Width - 1)&0x000000FF);

             u16GateWinStart_high=(uint16_t)(((u32YDst)&0x0000FF00)>>8);
             u16GateWinStart_low=(uint16_t)((u32YDst)&0x000000FF);
             u16GateWinStop_high=(uint16_t)(((u32YDst + *pu32Height - 1)&0x0000FF00)>>8);
             u16GateWinStop_low=(uint16_t)((u32YDst + *pu32Height - 1)&0x000000FF);
            break;
        case DDI_DISPLAY_ROTATION_90:
            u16SourceWinStart_high=(uint16_t)(((u32XDst)&0x0000FF00)>>8);
            u16SourceWinStart_low=(uint16_t)((u32XDst)&0x000000FF);
            u16SourceWinStop_high=(uint16_t)(((u32XDst + *pu32Width - 1)&0x0000FF00)>>8);
            u16SourceWinStop_low=(uint16_t)((u32XDst + *pu32Width - 1)&0x000000FF);

            u16GateWinStart_high=(uint16_t)(((u32YDst)&0x0000FF00)>>8);
            u16GateWinStart_low=(uint16_t)((u32YDst)&0x000000FF);
            u16GateWinStop_high=(uint16_t)(((u32YDst + *pu32Height - 1)&0x0000FF00)>>8);
            u16GateWinStop_low=(uint16_t)((u32YDst + *pu32Height - 1)&0x000000FF);
            break;
        case DDI_DISPLAY_ROTATION_180:
	    u16SourceWinStart_high=(uint16_t)(((u32XDst)&0x0000FF00)>>8);
            u16SourceWinStart_low=(uint16_t)((u32XDst)&0x000000FF);
            u16SourceWinStop_high=(uint16_t)(((u32XDst + *pu32Width - 1)&0x0000FF00)>>8);
            u16SourceWinStop_low=(uint16_t)((u32XDst + *pu32Width - 1)&0x000000FF);

            u16GateWinStart_high=(uint16_t)(((u32YDst)&0x0000FF00)>>8);
            u16GateWinStart_low=(uint16_t)((u32YDst)&0x000000FF);
            u16GateWinStop_high=(uint16_t)(((u32YDst + *pu32Height - 1)&0x0000FF00)>>8);
            u16GateWinStop_low=(uint16_t)((u32YDst + *pu32Height - 1)&0x000000FF);
            break;
        case DDI_DISPLAY_ROTATION_270:
	    u16SourceWinStart_high=(uint16_t)(((u32XDst)&0x0000FF00)>>8);
            u16SourceWinStart_low=(uint16_t)((u32XDst)&0x000000FF);
            u16SourceWinStop_high=(uint16_t)(((u32XDst + *pu32Width - 1)&0x0000FF00)>>8);
            u16SourceWinStop_low=(uint16_t)((u32XDst + *pu32Width - 1)&0x000000FF);

            u16GateWinStart_high=(uint16_t)(((u32YDst)&0x0000FF00)>>8);
            u16GateWinStart_low=(uint16_t)((u32YDst)&0x000000FF);
            u16GateWinStop_high=(uint16_t)(((u32YDst + *pu32Height - 1)&0x0000FF00)>>8);
            u16GateWinStop_low=(uint16_t)((u32YDst + *pu32Height - 1)&0x000000FF);
            break;
    }
    WriteDirect(CMD_MODE,0x02);   
    WriteDirect(DATA_MODE,u16SourceWinStart_high);
	
    WriteDirect(CMD_MODE,0x03);     
    WriteDirect(DATA_MODE,u16SourceWinStart_low );
	
    WriteDirect(CMD_MODE,0x04);    
    WriteDirect(DATA_MODE,u16SourceWinStop_high);
	
    WriteDirect(CMD_MODE,0x05);   
    WriteDirect(DATA_MODE,u16SourceWinStop_low);

    WriteDirect(CMD_MODE,0x06);    
    WriteDirect(DATA_MODE,u16GateWinStart_high);
	
    WriteDirect(CMD_MODE,0x07);   
    WriteDirect(DATA_MODE,u16GateWinStart_low);
	
    WriteDirect(CMD_MODE,0x08);    
    WriteDirect(DATA_MODE,u16GateWinStop_high);
	
    WriteDirect(CMD_MODE,0x09);   
    WriteDirect(DATA_MODE,u16GateWinStop_low);

    WriteDirect(CMD_MODE,0x22);   
    return ret;
}


////////////////////////////////////////////////////////////////////////////////
//! \fn RtStatus_t SendControllerBitmapType(gfx_BitmapTypeEnum_t eBitmapType)
//!
//! \brief Sets up the controller for the specified bitmap format
//!
//! \fntype Function
//!
//! \param[in] eBitmapType - The new bitmap format
//!
//! This function sends the appropriate commands to the display controller 
//! to set it up for the new bitmap type format.
//!
//! \retval SUCCESS No error
//!
//! \retval ERROR_DDI_DISPLAY_CONTROLLER_BITMAP_TYPE_UNSUPPORTED - The specified bitmap
//!         type is not supported by the controller
//!
////////////////////////////////////////////////////////////////////////////////
static RtStatus_t SendControllerBitmapType(gfx_BitmapTypeEnum_t eBitmapType)
{
    // Only 16-bit 565 mode supported
    if( eBitmapType != BITMAP_TYPE_16BPP_565 )
        return ERROR_DDI_DISPLAY_CONTROLLER_BITMAP_TYPE_UNSUPPORTED;
    return SUCCESS;
}

////////////////////////////////////////////////////////////////////////////////
//! \fn static RtStatus_t SendControllerResolution(uint16_t u16Width, uint16_t u16Height, ddi_display_Rotation_t eRotation)
//!
//! \brief Sets up the controller for the specified resolution
//!
//! \fntype Function
//!
//! \param[in] u16Width - Desired width of the display
//! \param[in] u16Height - Desired height of the display
//! \param[in] eRotation Desired orientation of the display
//!
//! The display driver is built with a default width and height for each
//! controller.  Most controllers support displays of varying screen
//! dimensions.  In order to support all possible dimensions without rebuilding
//! the display libraries, this function can set the dimensions of the display
//! to match the actual display in use.  This function only needs to be called
//! once to set the dimensions for the currently set screen orientation.  If the 
//! display is rotated after the dimensions are set, then the dimensions will
//! be adjusted accordingly in the display driver.  There is no need to reset
//! the dimensions after rotating the display.
//!
//! \retval SUCCESS No error
//!
//! \retval ERROR_DDI_DISPLAY_CONTROLLER_RESOLUTION - The specified resolution is
//!         not supported by the controller
//!
////////////////////////////////////////////////////////////////////////////////
static RtStatus_t SendControllerResolution(uint16_t u16Width, uint16_t u16Height, ddi_display_Rotation_t eRotation)
{
    uint16_t u16MaxWidth;
    uint16_t u16MaxHeight;

    // max dimensions are rotation specific
    switch(eRotation)
    {
        case DDI_DISPLAY_ROTATION_NONE:
        case DDI_DISPLAY_ROTATION_180:
            u16MaxWidth = DDI_DISPLAY_CONTROLLER_MAX_WIDTH;
            u16MaxHeight = DDI_DISPLAY_CONTROLLER_MAX_HEIGHT;
            break;

        case DDI_DISPLAY_ROTATION_90:
        case DDI_DISPLAY_ROTATION_270:
            u16MaxWidth = DDI_DISPLAY_CONTROLLER_MAX_HEIGHT;
            u16MaxHeight = DDI_DISPLAY_CONTROLLER_MAX_WIDTH;
            break;
    }

    // Check for out of bounds
    if( u16Width > u16MaxWidth || u16Height > u16MaxHeight )
        return ERROR_DDI_DISPLAY_CONTROLLER_RESOLUTION;

    return SUCCESS;
}

////////////////////////////////////////////////////////////////////////////////
//! \fn static RtStatus_t SendControllerRotation(ddi_display_Rotation_t eRotation)
//!
//! \brief Sets up the controller for the specified rotation
//!
//! \fntype Function
//!
//! \param[in] eRotation - Desired orientation of the display
//!
//! When the display driver is instructed to orient the screen to a new
//! rotation, this function sends a command to the controller to indicate this change.
//!
//! \retval SUCCESS No error
//!
//! \retval ERROR_DDI_DISPLAY_CONTROLLER_ROTATION - The specified rotation is
//!         not supported by the controller
//!
////////////////////////////////////////////////////////////////////////////////
static RtStatus_t SendControllerRotation(ddi_display_Rotation_t eRotation)
{
    RtStatus_t ret = SUCCESS;
    Hx8347aEntryMode EntryMode = {0x00A8};
    //EntryMode.B.Reserved= 0;
    //EntryMode.B.BGR=1;
    //EntryMode.B.ML=0;
    //EntryMode.B.MV=1;
    //EntryMode.B.MX=1;
    //EntryMode.B.MY=0;
    //EntryMode.B.Reserved1=0;
    

    // Gate/Source diagram
    //
    //              240
    //   S719                  S0
    //     ---------------------
    //    |                     | G0
    //    |                     |
    //    |                     |
    //    |                     |
    //    |                     |
    //    |                     |
    //    |                     |    320
    //    |                     |
    //    |                     |
    //    |                     |
    //    |                     |
    //    |                     |
    //    |                     | G319
    //     ---------------------
    //        |Ribbon cable |
    //        ---------------
    //
    switch(eRotation)
    {
        case DDI_DISPLAY_ROTATION_NONE:
	    EntryMode.V=0x00A8;
            break;

	case DDI_DISPLAY_ROTATION_90:
	    EntryMode.V=0x0008;
            break;

	case DDI_DISPLAY_ROTATION_180:
	    EntryMode.V=0x068;
            break;

	case DDI_DISPLAY_ROTATION_270:
	    EntryMode.V=0x00C8;
            break;

	default:
            ret = ERROR_DDI_DISPLAY_CONTROLLER_ROTATION;
            break;
    }

    if( !ret )
    {
        WriteDirect(CMD_MODE, 0x16);    // Entry Mode
        WriteDirect(DATA_MODE, EntryMode.V); 
    }

    return ret;
}

////////////////////////////////////////////////////////////////////////////////
//! \fn RtStatus_t ddi_display_controller_SendCommand(ddi_display_controller_CommandType_t eType, ...)
//!
//! \brief Sends the specified command to the controller
//!
//! \fntype Function
//!
//! \param[in] eType - Type of command to send
//! \param[in] ... Variable argument list - The rest of the arguments are specific
//!            to the type of command is to be sent.  Refer to 
//!            ddi_display_controller.h for command types and their
//!            corresponding argument lists.
//!
//! \retval SUCCESS No error
//!
//! \retval ERROR_DDI_DISPLAY_CONTROLLER_COMMAND_UNSUPPORTED - This
//!         controller does not support the given command type
//!
//! \retval ERROR_DDI_DISPLAY_CONTROLLER_BITMAP_TYPE_UNSUPPORTED - This
//!         controller does not support the given bitmap color type
//!
//! \retval ERROR_DDI_DISPLAY_CONTROLLER_ROTATION - The specified rotation is
//!         not supported by the controller
//!
//! \retval ERROR_DDI_DISPLAY_PLACEMENT - There was an error placing the given
//!         region on the display that clipping could not compensate for.
//!
////////////////////////////////////////////////////////////////////////////////
RtStatus_t ddi_display_controller_SendCommand(ddi_display_controller_CommandType_t eType, ...)
{
    RtStatus_t ret = SUCCESS;
    va_list valist;
    ddi_display_controller_CommandType_t eCommandType = eType;

    va_start(valist, eType);

    switch(eCommandType)
    {
        case DDI_DISPLAY_CONTROLLER_SET_REGION:
            {
                uint32_t u32XDst = va_arg(valist, uint32_t);
                uint32_t u32YDst = va_arg(valist, uint32_t);
                uint32_t *pu32Width = va_arg(valist, uint32_t *);
                uint32_t *pu32Height = va_arg(valist, uint32_t *);
                ddi_display_Rotation_t eRotation = (ddi_display_Rotation_t)va_arg(valist, ddi_display_Rotation_t);
                ret = SendControllerRegion(u32XDst, u32YDst, pu32Width, pu32Height, eRotation);
            }
            break;
        case DDI_DISPLAY_CONTROLLER_INIT:
            {
                gfx_BitmapTypeEnum_t eBitmapType = va_arg(valist, gfx_BitmapTypeEnum_t);
                uint32_t u32ScreenWidth = va_arg(valist, uint32_t);
                uint32_t u32ScreenHeight = va_arg(valist, uint32_t);
                InitPwmBacklight();
//                SetPwmBrightness(50);
//                SendControllerOutputEnable(true);
                SendControllerInitSeq(eBitmapType, u32ScreenWidth, u32ScreenHeight);
            }
            break;
        case DDI_DISPLAY_CONTROLLER_OUTPUT_ENABLE:
            SendControllerOutputEnable(va_arg(valist, bool));
            break;
/*
#ifdef RTOS_THREADX
        case DDI_DISPLAY_CONTROLLER_SET_VIDEO_MODE:
            SendControllerVideoMode(va_arg(valist, ddi_display_VideoMode_t));
            break;
        case DDI_DISPLAY_CONTROLLER_WAIT_FOR_VSYNC:
            ret = WaitForControllerVsync();
            break;
#endif
*/
        // Contrast not supported by this controller.  The Solomon Systech
        // engineers say that you need to adjust greyscale and all sorts of
        // voltages that can greatly impact the display's performance.  There's
        // not any simple dedicated contrast register setting.
//        case DDI_DISPLAY_CONTROLLER_SET_CONTRAST:
//            SendControllerContrast(va_arg(valist, uint32_t));
//            break;
        case DDI_DISPLAY_CONTROLLER_SET_BRIGHTNESS:
            SetPwmBrightness(va_arg(valist, uint32_t));
            break;
        case DDI_DISPLAY_CONTROLLER_SET_ROTATION:
            {
                ddi_display_Rotation_t eRotation = va_arg(valist, ddi_display_Rotation_t);
                ret = SendControllerRotation(eRotation);
            }
            break;
        case DDI_DISPLAY_CONTROLLER_SET_RESOLUTION:
            {
                uint16_t u16Width = va_arg(valist, uint16_t);
                uint16_t u16Height = va_arg(valist, uint16_t);
                ddi_display_Rotation_t eRotation = va_arg(valist, ddi_display_Rotation_t);
                ret = SendControllerResolution(u16Width, u16Height, eRotation);
                break;
            }
        case DDI_DISPLAY_CONTROLLER_SET_BITMAP_TYPE:
            ret = SendControllerBitmapType(va_arg(valist, gfx_BitmapTypeEnum_t));
            break;
        case DDI_DISPLAY_CONTROLLER_SET_LOW_POWER_MODE:
            SetControllerLowPowerMode(va_arg(valist, bool));
            break;
        default:
            ret = ERROR_DDI_DISPLAY_CONTROLLER_COMMAND_UNSUPPORTED;
            break;
    }
    va_end(valist);

    return ret;
}

///////////////////////////////////////////////////////////////////////////////
// End of file
///////////////////////////////////////////////////////////////////////////////
//! @}

⌨️ 快捷键说明

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