📄 ddi_display_controller_ssd133x.c
字号:
//!
////////////////////////////////////////////////////////////////////////////////
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_NONE:
stc_u8RemapAndColorByte &= ~0x01; // Horizontal address increment
stc_u8RemapAndColorByte &= ~0x02; // Set SEG direction (no horz flip)
stc_u8RemapAndColorByte |= 0x10; // Set COM direction (vert flip)
break;
case DDI_DISPLAY_ROTATION_90:
stc_u8RemapAndColorByte |= 0x01; // Vertical address increment
stc_u8RemapAndColorByte &= ~0x02; // Set SEG direction (no horz flip)
stc_u8RemapAndColorByte &= ~0x10; // Set COM direction (no vert flip)
break;
case DDI_DISPLAY_ROTATION_180:
stc_u8RemapAndColorByte &= ~0x01; // Horizontal address increment
stc_u8RemapAndColorByte |= 0x02; // Set SEG direction (horz flip)
stc_u8RemapAndColorByte &= ~0x10; // Set COM direction (no vert flip)
break;
case DDI_DISPLAY_ROTATION_270:
stc_u8RemapAndColorByte |= 0x01; // Vertical address increment
stc_u8RemapAndColorByte |= 0x02; // Set SEG direction (horz flip)
stc_u8RemapAndColorByte |= 0x10; // Set COM direction (vert flip)
break;
default:
ret = ERROR_DDI_DISPLAY_CONTROLLER_ROTATION;
break;
}
WriteDirect(CMD_MODE, 0xA0); // Remap and color depth
WriteDirect(PARAM_MODE, stc_u8RemapAndColorByte);
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. Reference \ref
//! 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_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);
ret = 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:
// SendControllerBrightness(va_arg(valist, uint32_t));
SetPwmBrightness(va_arg(valist, uint32_t));
break;
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_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_ROTATION:
ret = SendControllerRotation(va_arg(valist, ddi_display_Rotation_t));
break;
case DDI_DISPLAY_CONTROLLER_SET_BITMAP_TYPE:
ret = SendControllerBitmapType(va_arg(valist, gfx_BitmapTypeEnum_t));
break;
default:
ret = ERROR_DDI_DISPLAY_CONTROLLER_COMMAND_UNSUPPORTED;
break;
}
va_end(valist);
return ret;
}
////////////////////////////////////////////////////////////////////////////////
//! \fn RtStatus_t ddi_display_controller_GetLcdifInitStruct(hw_lcdif_Init_t *pInit, gfx_BitmapTypeEnum_t eBitmapType)
//!
//! \brief Copies the LCDIF init struct that corresponds to the given color format
//!
//! \fntype Function
//!
//! \param[in,out] pInit - Pointer to init struct to copy to
//! \param[in] eBitmapType - Graphics color format specifier
//!
//! \retval SUCCESS No error
//!
//! \retval ERROR_DDI_DISPLAY_CONTROLLER_BITMAP_TYPE_UNSUPPORTED - This
//! controller does not support the given bitmap color type
//!
//! This function is implemented per controller or display. The appropriate
//! LCDIF init parameters are copied to the given init struct pointer according
//! to the type of color format is specified. Not all controllers/displays are
//! capable of all color formats, so this function may return an error
//! indicating that the given color format is not supported.
//!
////////////////////////////////////////////////////////////////////////////////
RtStatus_t ddi_display_controller_GetLcdifInitStruct(hw_lcdif_Init_t *pInit, gfx_BitmapTypeEnum_t eBitmapType)
{
// Init structure for LCDIF, may be loaded from a resource
hw_lcdif_Init_t LcdifInit =
{
// No busy line, no byte-swapping, bring LCD module out of reset
false, // m_bBusyEnable
DDI_DISPLAY_DATA_SWIZZLE, // m_eDataSwizzle
LCDRESET_HIGH, // m_eReset
BUSMODE_8080, // m_eBusMode
DDI_DISPLAY_WORDLENGTH, // m_eWordLength
// Bus timing info
// 1XCLK ~= 168ns
{
DDI_DISPLAY_DATA_SETUP_XCLKS, // m_u8DataSetup
DDI_DISPLAY_DATA_HOLD_XCLKS, // m_u8DataHold
DDI_DISPLAY_CMD_SETUP_XCLKS, // m_u8CmdSetup
DDI_DISPLAY_CMD_HOLD_XCLKS, // m_u8CmdHold
}
};
if( BITMAP_TYPE_16BPP_565 != eBitmapType )
return ERROR_DDI_DISPLAY_CONTROLLER_BITMAP_TYPE_UNSUPPORTED;
memcpy(pInit, &LcdifInit, sizeof(hw_lcdif_Init_t));
return SUCCESS;
}
////////////////////////////////////////////////////////////////////////////////
//! \brief Sets up the PWM backlight control signal
//!
//! \fntype Function
//!
//! delay function
//!
//!
////////////////////////////////////////////////////////////////////////////////
static void delay(uint32_t u32DelayValue)
{
#if defined(RTOS_THREADX)
tx_thread_sleep(OS_MSECS_TO_TICKS(u32DelayValue));
#else
int i;
for( i = 0; i < u32DelayValue; i++ );
#endif
}
////////////////////////////////////////////////////////////////////////////////
//! \fn static void InitPwmBacklight(void)
//!
//! \brief Sets up the PWM backlight control signal
//!
//! \fntype Function
//!
//! Inits the PWM hardware block and sets up the GPIOs for PWM mode.
//! The initial backlight frequency is set, but the duty cycle is set to zero
//!
////////////////////////////////////////////////////////////////////////////////
static void InitPwmBacklight(void)
{
// variables for alkaline mode since it can't power full brighness
#if defined(DDI_DISPLAY_ALL_TX_DRIVERS) && defined(RTOS_THREADX)
RtStatus_t ret;
#endif
if( !(ddi_etm_IsPresent()) ) {
// configure VCC SHDN pin to Shutdown
// Do a raw init of the PWM GPIO
// set MUX to GPIO
HW_PINCTRL_MUXSEL6_SET(
0x00300000 << (2*DDI_DISPLAY_VCCSHUTDOWN_PWM_CHANNEL));
// set drive current to 4mA
HW_PINCTRL_DRIVE3_CLR(1<<(10+DDI_DISPLAY_VCCSHUTDOWN_PWM_CHANNEL));
// set output value 0 to turn off step-up
HW_PINCTRL_DOUT3_CLR(1<<(10+DDI_DISPLAY_VCCSHUTDOWN_PWM_CHANNEL));
// enable output value to drive pin
HW_PINCTRL_DOE3_SET(1<<(10+DDI_DISPLAY_VCCSHUTDOWN_PWM_CHANNEL));
}
// Check for boost mode configuration
if(BF_RD(POWER_STS, MODE)==3)
{
u8MinBrightnessPercentage = ALKALINE_MIN_BRIGHTNESS_PERCENTAGE;
u8MaxBrightnessPercentage = ALKALINE_MAX_BRIGHTNESS_PERCENTAGE;
}
else
{
u8MinBrightnessPercentage = MIN_BRIGHTNESS_PERCENTAGE;
u8MaxBrightnessPercentage = MAX_BRIGHTNESS_PERCENTAGE;
}
#if defined(DDI_DISPLAY_ALL_TX_DRIVERS) && defined(RTOS_THREADX)
// Grab PWM for backlight use
// Assume GPIO driver has already been initialized
if( !ddi_etm_IsPresent() ) {
ret = ddi_pwm_ChLock(1<<DDI_DISPLAY_BACKLIGHT_PWM_CHANNEL);
assert(!ret);
}
// Set the initial params, 0% duty cycle
ret = ddi_pwm_ChSetConfig((hw_pwm_Channel_t)DDI_DISPLAY_BACKLIGHT_PWM_CHANNEL,
PWM_STATE_HIGH,
PWM_STATE_LOW,
BACKLIGHT_PWM_FREQ, 0);
assert(!ret);
ddi_pwm_ChOutputEnable(1<<DDI_DISPLAY_BACKLIGHT_PWM_CHANNEL, true);
#else
// Do a raw init of the PWM GPIO
if( !ddi_etm_IsPresent() ) {
HW_PINCTRL_MUXSEL6_CLR(
0x00300000 << (2*DDI_DISPLAY_BACKLIGHT_PWM_CHANNEL));
}
// Set up the backlight
BF_CLR(PWM_CTRL, SFTRST);
BF_CLR(PWM_CTRL, CLKGATE);
HW_PWMn_ACTIVE_WR(DDI_DISPLAY_BACKLIGHT_PWM_CHANNEL, 0);
BF_CS5n(PWMn_PERIOD, DDI_DISPLAY_BACKLIGHT_PWM_CHANNEL,
MATT, 0,
CDIV, BACKLIGHT_PWM_CDIV,
INACTIVE_STATE, BV_PWMn_PERIOD_INACTIVE_STATE__0,
ACTIVE_STATE, BV_PWMn_PERIOD_ACTIVE_STATE__1,
PERIOD, BACKLIGHT_PWM_PERIOD);
HW_PWM_CTRL_SET(1 << DDI_DISPLAY_BACKLIGHT_PWM_CHANNEL);
#endif
}
///////////////////////////////////////////////////////////////////////////////
// End of file
///////////////////////////////////////////////////////////////////////////////
//! @}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -