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

📄 ddi_display_controller_ssd1339.c

📁 LCD驱动源代码 应用于手机的话,需要改写,找了好久,网上下的,将就一下了,参考参考,自己动手改一下吧.有在MTK平台上改成功的,放上来给大家参考一下啊
💻 C
📖 第 1 页 / 共 3 页
字号:
#endif
}


////////////////////////////////////////////////////////////////////////////////
//! \fn static RtStatus_t SendControllerRegion(uint32_t u32XDst, uint32_t u32YDst, uint32_t *pu32Width, uint32_t *pu32Height, ddi_display_Rotation_t eRotation)
//!
//! \brief Sets up the region on the controller where pixels are to be placed
//!
//! \fntype Function
//!
//! \param[in] u32XDst - X coordinate of upper left corner of the destination region
//! \param[in] u32YDst - Y coordinate of upper left corner of the destination region
//! \param[in] pu32Width - Width of the destination region
//! \param[in] pu32Height - Height of the destination region
//! \param[in] eRotation - Desired orientation of the display
//!
//! This function sends commands to the controller to set up the destination
//! region (or "box") where pixels are to be placed.  The rotation is specified
//! here as well as with the SendControllerRotation function because some
//! controllers handle rotation on a per region basis.
//!
//! \retval SUCCESS No error
//!
//! \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.
//!
////////////////////////////////////////////////////////////////////////////////
static RtStatus_t SendControllerRegion(uint32_t u32XDst, uint32_t u32YDst, 
                                       uint32_t *pu32Width, uint32_t *pu32Height,
                                       ddi_display_Rotation_t eRotation)
{
    uint32_t u32TotalWidth = g_ddi_display_u16ScreenWidth;
    uint32_t u32TotalHeight = g_ddi_display_u16ScreenHeight;
    uint32_t u32StartRow;
    uint32_t u32StartColumn;
    uint8_t u8VertFlipAdjust = 0;
    DDI_DISPLAY_WORD_TYPE VertCommand = DDI_DISPLAY_VERT_REGION_CMD;  // Command byte for vertical setup
    DDI_DISPLAY_WORD_TYPE HorzCommand = DDI_DISPLAY_HORZ_REGION_CMD;  // Command byte for horizontal setup
    RtStatus_t ret = SUCCESS;

    switch(eRotation)
    {
        case DDI_DISPLAY_ROTATION_NONE:
            u32StartRow = DDI_DISPLAY_START_ROW;
            u32StartColumn = DDI_DISPLAY_START_COLUMN;
            u32TotalWidth = g_ddi_display_u16ScreenWidth;
            u32TotalHeight = g_ddi_display_u16ScreenHeight;
            VertCommand = DDI_DISPLAY_VERT_REGION_CMD;
            HorzCommand = DDI_DISPLAY_HORZ_REGION_CMD;
            u8VertFlipAdjust = 4;
            break;

        case DDI_DISPLAY_ROTATION_90:
            u32StartRow = DDI_DISPLAY_START_COLUMN;
            u32StartColumn = DDI_DISPLAY_START_ROW;
            u32TotalWidth = g_ddi_display_u16ScreenHeight;
            u32TotalHeight = g_ddi_display_u16ScreenWidth;
            VertCommand = DDI_DISPLAY_HORZ_REGION_CMD;
            HorzCommand = DDI_DISPLAY_VERT_REGION_CMD;
            break;
        
        case DDI_DISPLAY_ROTATION_180:
            u32StartRow = DDI_DISPLAY_START_ROW;
            u32StartColumn = DDI_DISPLAY_START_COLUMN+4;
            u32TotalWidth = g_ddi_display_u16ScreenWidth;
            u32TotalHeight = g_ddi_display_u16ScreenHeight;
            VertCommand = DDI_DISPLAY_VERT_REGION_CMD;
            HorzCommand = DDI_DISPLAY_HORZ_REGION_CMD;
            break;
        
        case DDI_DISPLAY_ROTATION_270:
            u32StartRow = DDI_DISPLAY_START_COLUMN+4;
            u32StartColumn = DDI_DISPLAY_START_ROW;
            u32TotalWidth = g_ddi_display_u16ScreenHeight;
            u32TotalHeight = g_ddi_display_u16ScreenWidth;
            VertCommand = DDI_DISPLAY_HORZ_REGION_CMD;
            HorzCommand = DDI_DISPLAY_VERT_REGION_CMD;
            u8VertFlipAdjust = 4;
            break;
            
        default:
            ret = ERROR_DDI_DISPLAY_CONTROLLER_ROTATION;
            break;
    }

    if(PicAdjust)
    {
        u32StartRow = newStartColumn;
        u32StartColumn = newStartRow;
        u32TotalWidth = newMaxHeight;
        u32TotalHeight = newMaxWidth;
    }


    if( !ret )
    {
        DDI_DISPLAY_WORD_TYPE XStart;
        DDI_DISPLAY_WORD_TYPE XStop;
        DDI_DISPLAY_WORD_TYPE YStart;
        DDI_DISPLAY_WORD_TYPE YStop;

        // Check for zero sized region
        if( !*pu32Width || !*pu32Height 
            || u32XDst >= u32TotalWidth
            || u32YDst >= u32TotalHeight )
        {
            return ERROR_DDI_DISPLAY_PLACEMENT;
        }

        // Check for clipping
        if( u32XDst + *pu32Width > u32TotalWidth)
        {
            // FIXME - Must do a DrawRegion type xfer for this
            // since the clipped pixels will not be contiguous
            return ERROR_DDI_DISPLAY_PLACEMENT;
        }

        // Check for clipping
        if( u32YDst + *pu32Height > u32TotalHeight )
        {
            *pu32Height = u32TotalHeight - u32YDst;
        }

        XStart = u32XDst + u32StartColumn;
        XStop = u32XDst  + u32StartColumn + *pu32Width - 1;

        YStart = u32YDst + u32StartRow;
        YStop = u32YDst + u32StartRow + *pu32Height - 1 + u8VertFlipAdjust;

        WriteDirect(CMD_MODE, HorzCommand);
        WriteDirect(DATA_MODE, XStart);//XS
        WriteDirect(DATA_MODE, XStop);//XE
        
        WriteDirect(CMD_MODE, VertCommand);
        WriteDirect(DATA_MODE, YStart);//YS
        WriteDirect(DATA_MODE, YStop);//YE

        WriteDirect(CMD_MODE, 0x5C);

    }

    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)
{
#ifdef DDI_LCDIF_WORDLENGTH_16BITS
    // Only 16-bit 565 mode supported
    if( eBitmapType != BITMAP_TYPE_16BPP_565 )
        return ERROR_DDI_DISPLAY_CONTROLLER_BITMAP_TYPE_UNSUPPORTED;
#else
    // 8-bit 565 mode and 666 mode supported
    if( eBitmapType != BITMAP_TYPE_16BPP_565 &&  eBitmapType != BITMAP_TYPE_18BPP_666)
        return ERROR_DDI_DISPLAY_CONTROLLER_BITMAP_TYPE_UNSUPPORTED;
#endif
    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:
            u16MaxWidth = DDI_DISPLAY_CONTROLLER_MAX_HEIGHT;
            u16MaxHeight = DDI_DISPLAY_CONTROLLER_MAX_WIDTH;
            break;

        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;
    uint8_t RotateCmd = 0x74;

    switch(eRotation)
    {
        case DDI_DISPLAY_ROTATION_NONE:
            RotateCmd &= ~0x01;    // Horizontal address increment
            RotateCmd &= ~0x02;    // Set SEG direction (no horz flip)
            RotateCmd |= 0x10;    // Set COM direction (vert flip)
            break;
        case DDI_DISPLAY_ROTATION_90:
            RotateCmd |= 0x01;    // Vertical address increment
            RotateCmd &= ~0x02;    // Set SEG direction (no horz flip)
            RotateCmd &= ~0x10;    // Set COM direction (no vert flip)
            break;
        case DDI_DISPLAY_ROTATION_180:
            RotateCmd &= ~0x01;    // Horizontal address increment
            RotateCmd |= 0x02;    // Set SEG direction (horz flip)
            RotateCmd &= ~0x10;    // Set COM direction (no vert flip)
            break;
        case DDI_DISPLAY_ROTATION_270:
            RotateCmd |= 0x01;    // Vertical address increment
            RotateCmd |= 0x02;    // Set SEG direction (horz flip)
            RotateCmd |= 0x10;    // Set COM direction (vert flip)
            break;
        default:
            ret = ERROR_DDI_DISPLAY_CONTROLLER_ROTATION;
            break;
    }
    WriteDirect(CMD_MODE, 0xA0);    // Remap and color depth
    WriteDirect(DATA_MODE, RotateCmd);

    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;

    va_start(valist, eType);

    switch(eType)
    {
        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, uint32_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();
                SendControllerInitSeq(eBitmapType, u32ScreenWidth, u32ScreenHeight);
#if 1 //todo: remove this statement
                SendControllerOutputEnable(TRUE);
#endif
            }
            break;
        case DDI_DISPLAY_CONTROLLER_OUTPUT_ENABLE:
            SendControllerOutputEnable(va_arg(valist, bool));
            break;
        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:
            ret = SendControllerRotation(va_arg(valist, ddi_display_Rotation_t));
            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 + -