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

📄 ddi_display_controller_ssd1289.c

📁 LCD驱动源代码 应用于手机的话,需要改写,找了好久,网上下的,将就一下了,参考参考,自己动手改一下吧.有在MTK平台上改成功的,放上来给大家参考一下啊
💻 C
📖 第 1 页 / 共 4 页
字号:
    //    |                     |
    //    |                     | G319
    //     ---------------------
    //        |Ribbon cable |
    //        ---------------
    //
    switch(eRotation)
    {
        case DDI_DISPLAY_ROTATION_NONE:
            u8SourceWinStart = u32YDst;
            u8SourceWinStop = u32YDst + *pu32Height - 1;
            u8SourceAddrPos = u8SourceWinStart;

            u16GateWinStart = g_ddi_display_u16ScreenWidth - u32XDst - *pu32Width;
            u16GateWinStop = g_ddi_display_u16ScreenWidth - u32XDst - 1;
            u16GateAddrPos = u16GateWinStop;
            break;
        case DDI_DISPLAY_ROTATION_90:
            u8SourceWinStart = u32XDst;
            u8SourceWinStop = u32XDst + *pu32Width - 1;
            u8SourceAddrPos = u8SourceWinStart;

            u16GateWinStart = u32YDst;
            u16GateWinStop = u32YDst + *pu32Height - 1;
            u16GateAddrPos = u16GateWinStart;
            break;
        case DDI_DISPLAY_ROTATION_180:
            u8SourceWinStart = g_ddi_display_u16ScreenHeight - u32YDst - *pu32Height;
            u8SourceWinStop = g_ddi_display_u16ScreenHeight - u32YDst - 1;
            u8SourceAddrPos = u8SourceWinStop;

            u16GateWinStart = u32XDst;
            u16GateWinStop = u32XDst + *pu32Width - 1;
            u16GateAddrPos = u16GateWinStart;
            break;
        case DDI_DISPLAY_ROTATION_270:
            u8SourceWinStart = g_ddi_display_u16ScreenWidth - u32XDst - *pu32Width;
            u8SourceWinStop = g_ddi_display_u16ScreenWidth - u32XDst - 1;
            u8SourceAddrPos = u8SourceWinStop;

            u16GateWinStart = g_ddi_display_u16ScreenHeight - u32YDst - *pu32Height;
            u16GateWinStop = g_ddi_display_u16ScreenHeight - u32YDst - 1;
            u16GateAddrPos = u16GateWinStop;
            break;
    }

    WriteDirect(CMD_MODE, 0x44);    // Source RAM address window
    WriteDirect(DATA_MODE, (u8SourceWinStop << 8) | u8SourceWinStart);
    WriteDirect(CMD_MODE, 0x45);    // Gate RAM address window
    WriteDirect(DATA_MODE, u16GateWinStart);
    WriteDirect(CMD_MODE, 0x46);    // Gate RAM address window
    WriteDirect(DATA_MODE, u16GateWinStop);

    WriteDirect(CMD_MODE, 0x4e);    // Source address set
    WriteDirect(DATA_MODE, u8SourceAddrPos);
    WriteDirect(CMD_MODE, 0x4f);    // Gate address set
    WriteDirect(DATA_MODE, u16GateAddrPos);

    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;
    SSD1289EntryMode EntryMode = {0};
    EntryMode.B.LG     = 0;
    EntryMode.B.AM     = 1;
    EntryMode.B.ID     = 3;
    EntryMode.B.TY     = 0;
    EntryMode.B.DMode  = 0;
    EntryMode.B.WMode  = 0;
    EntryMode.B.OEDef  = 0;
    EntryMode.B.TRANS  = 0;
    EntryMode.B.DFM    = 3;
    EntryMode.B.VSMode = 0;

    // Gate/Source diagram
    //
    //              240
    //   S719                  S0
    //     ---------------------
    //    |                     | G0
    //    |                     |
    //    |                     |
    //    |                     |
    //    |                     |
    //    |                     |
    //    |                     |    320
    //    |                     |
    //    |                     |
    //    |                     |
    //    |                     |
    //    |                     |
    //    |                     | G319
    //     ---------------------
    //        |Ribbon cable |
    //        ---------------
    //
    switch(eRotation)
    {
        case DDI_DISPLAY_ROTATION_NONE:
            EntryMode.B.AM = 1; // Address shift gate
            EntryMode.B.ID = 1; // Gate inc, Source inc
            break;
        case DDI_DISPLAY_ROTATION_90:
            EntryMode.B.AM = 0; // Address shift source
            EntryMode.B.ID = 3; // Source inc, Gate inc
            break;
        case DDI_DISPLAY_ROTATION_180:
            EntryMode.B.AM = 1; // Address shift gate
            EntryMode.B.ID = 2; // Gate dec, Source dec
            break;
        case DDI_DISPLAY_ROTATION_270:
            EntryMode.B.AM = 0; // Address shift source
            EntryMode.B.ID = 0; // Source dec, Gate dec
            break;
        default:
            ret = ERROR_DDI_DISPLAY_CONTROLLER_ROTATION;
            break;
    }

    if( !ret )
    {
        WriteDirect(CMD_MODE, 0x11);    // 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 + -