📄 ddi_display_controller.c
字号:
uint32_t u32TotalWidth = g_ddi_display_u16ScreenWidth;
uint32_t u32TotalHeight = g_ddi_display_u16ScreenHeight;
RtStatus_t ret = SUCCESS;
uint32_t u32StartRow;
uint32_t u32StartColumn;
DDI_DISPLAY_WORD_TYPE VertCommand; // Command byte for vertical setup
DDI_DISPLAY_WORD_TYPE XStart; // X region start
DDI_DISPLAY_WORD_TYPE XStop; // X region stop
DDI_DISPLAY_WORD_TYPE HorzCommand; // Command byte for horizontal setup
DDI_DISPLAY_WORD_TYPE YStart; // Y region start
DDI_DISPLAY_WORD_TYPE YStop; // Y region stop
switch(eRotation)
{
case DDI_DISPLAY_ROTATION_NONE:
VertCommand = DDI_DISPLAY_VERT_REGION_CMD;
HorzCommand = DDI_DISPLAY_HORZ_REGION_CMD;
u32StartRow = DDI_DISPLAY_START_ROW;
u32StartColumn = DDI_DISPLAY_START_COLUMN;
break;
case DDI_DISPLAY_ROTATION_90:
// Swap the vertical and horizontal commands
VertCommand = DDI_DISPLAY_HORZ_REGION_CMD;
HorzCommand = DDI_DISPLAY_VERT_REGION_CMD;
u32StartRow = DDI_DISPLAY_START_COLUMN;
u32StartColumn = DDI_DISPLAY_START_ROW;
break;
default:
ret = ERROR_DDI_DISPLAY_CONTROLLER_ROTATION;
break;
}
if( !ret )
{
// 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;
}
// Stuff the Y dimension in the X params
XStart = u32YDst + u32StartColumn;
XStop = u32YDst + u32StartColumn + *pu32Height - 1;
// Stuff the X dimension in the Y params
YStart = u32XDst + u32StartRow;
YStop = u32XDst + u32StartRow + *pu32Width - 1;
// Write the command bytes now
WriteDirect(CMD_MODE, HorzCommand);
WriteDirect(CMD_MODE, XStart);
WriteDirect(CMD_MODE, XStop);
WriteDirect(CMD_MODE, VertCommand);
WriteDirect(CMD_MODE, YStart);
WriteDirect(CMD_MODE, YStop);
}
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;
switch(eRotation)
{
case DDI_DISPLAY_ROTATION_90:
WriteDirect(CMD_MODE, 0x10); // Driver output mode set
WriteDirect(CMD_MODE, 0x20); // -----
WriteDirect(CMD_MODE, 0x40); // Entry Mode Set
WriteDirect(CMD_MODE, 0x00); // ----- Y address counter mode
break;
case DDI_DISPLAY_ROTATION_NONE:
WriteDirect(CMD_MODE, 0x10); // Driver output mode set
WriteDirect(CMD_MODE, 0x24); // -----
WriteDirect(CMD_MODE, 0x40); // Entry Mode Set
WriteDirect(CMD_MODE, 0x02); // ----- X address counter mode
break;
default:
ret = ERROR_DDI_DISPLAY_CONTROLLER_ROTATION;
break;
}
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);
if( hw_lcdif_IsInSoftReset() && (eType != DDI_DISPLAY_CONTROLLER_SET_LOW_POWER_MODE)){
return ERROR_DDI_DISPLAY_CONTROLLER_LOW_POWER_MODE;
}
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);
SendControllerInitSeq(eBitmapType, u32ScreenWidth, u32ScreenHeight);
InitPwmBacklight();
}
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 + -