📄 ddi_display_controller.c
字号:
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_CLR(1 << DDI_DISPLAY_BACKLIGHT_PWM_CHANNEL);
#endif
}
////////////////////////////////////////////////////////////////////////////////
//! \fn static void SendControllerInitSeq(gfx_BitmapTypeEnum_t eBitmapType, uint32_t u32Width, uint32_t u32Height)
//!
//! \brief Sends commands to initialize the controller from reset
//!
//! \fntype Function
//!
//! \param[in] eBitmapType - Graphics color format specifier
//! \param[in] u32Width - Desired screen width setting
//! \param[in] u32Height - Desired screen height setting
//!
//! This function sends commands to initialize the controller after it has
//! been taken out of reset.
//!
//! \retval SUCCESS No error
//!
//! \retval ERROR_DDI_DISPLAY_CONTROLLER_BITMAP_TYPE_UNSUPPORTED - This
//! controller does not support the given bitmap color type
//!
//! \retval ERROR_DDI_DISPLAY_CONTROLLER_SCREEN_SIZE - This
//! controller does not support the given screen dimensions
//!
////////////////////////////////////////////////////////////////////////////////
static void SendControllerInitSeq(gfx_BitmapTypeEnum_t eBitmapType, uint32_t u32Width, uint32_t u32Height)
{
// Init commands for the LCD hardware
WriteDirect(CMD_MODE, 0x2c); // Standby mode off
WriteDirect(CMD_MODE, 0x02); // Oscillation mode
WriteDirect(CMD_MODE, 0x01); // -----
WriteDirect(CMD_MODE, 0x20); // DC-DC Select
WriteDirect(CMD_MODE, 0x05); // -----
WriteDirect(CMD_MODE, 0x26); // DC-DC and AMP ON/OFF
WriteDirect(CMD_MODE, 0x01); // -----
WriteDirect(CMD_MODE, 0x26); // DC-DC and AMP ON/OFF
WriteDirect(CMD_MODE, 0x09); // -----
WriteDirect(CMD_MODE, 0x26); // DC-DC and AMP ON/OFF
WriteDirect(CMD_MODE, 0x0b); // -----
WriteDirect(CMD_MODE, 0x26); // DC-DC and AMP ON/OFF
WriteDirect(CMD_MODE, 0x0f); // -----
WriteDirect(CMD_MODE, 0x28); // Temperature Compensation Set
WriteDirect(CMD_MODE, 0x02); // -----
WriteDirect(CMD_MODE, 0x2e); // DDRAM Burst mode off
WriteDirect(CMD_MODE, 0x10); // Driver output mode set
WriteDirect(CMD_MODE, 0x24); // -----
WriteDirect(CMD_MODE, 0x22); // Bias Set
WriteDirect(CMD_MODE, 0x11); // -----
WriteDirect(CMD_MODE, 0x24); // DCDC Clock Divisor
WriteDirect(CMD_MODE, 0x22); // -----
WriteDirect(CMD_MODE, 0x42); // X-Address Area Set
WriteDirect(CMD_MODE, 0x00); // ----- XStart
WriteDirect(CMD_MODE, 0x9f); // ----- XStop
WriteDirect(CMD_MODE, 0x43); // Y-Address Area Set
WriteDirect(CMD_MODE, 0x08); // ----- YStart
WriteDirect(CMD_MODE, 0x87); // ----- YStop
WriteDirect(CMD_MODE, 0x2a); // Contrast Control (1)
WriteDirect(CMD_MODE, 0xbf); // -----
WriteDirect(CMD_MODE, 0x2b); // Contrast Control (2)
WriteDirect(CMD_MODE, 0x40); // -----
WriteDirect(CMD_MODE, 0x30); // Addressing mode set
WriteDirect(CMD_MODE, 0x09); // -----
WriteDirect(CMD_MODE, 0x32); // ROW Vector Mode set
WriteDirect(CMD_MODE, 0x0e); // -----
WriteDirect(CMD_MODE, 0x34); // N-line Inversion Set
WriteDirect(CMD_MODE, 0xd3); // -----
WriteDirect(CMD_MODE, 0x40); // Entry Mode Set
WriteDirect(CMD_MODE, 0x02); // ----- X address counter mode
WriteDirect(CMD_MODE, 0x45); // RAM Skip area set
WriteDirect(CMD_MODE, 0x00); // -----
WriteDirect(CMD_MODE, 0x53); // Specified display pattern set
WriteDirect(CMD_MODE, 0x00); // -----
WriteDirect(CMD_MODE, 0x55); // Partial Display Mode Set
WriteDirect(CMD_MODE, 0x00); // -----
WriteDirect(CMD_MODE, 0x56); // Partial Display Start Line Set
WriteDirect(CMD_MODE, 0x00); // -----
WriteDirect(CMD_MODE, 0x57); // Partial Display End Line Set
WriteDirect(CMD_MODE, 0x9f); // -----
WriteDirect(CMD_MODE, 0x59); // Area scroll set
WriteDirect(CMD_MODE, 0x00); // -----
WriteDirect(CMD_MODE, 0x00); // -----
WriteDirect(CMD_MODE, 0xa0); // -----
WriteDirect(CMD_MODE, 0x00); // -----
WriteDirect(CMD_MODE, 0x60); // Data format select
}
////////////////////////////////////////////////////////////////////////////////
//! \fn static void SendControllerOutputEnable(bool bOn)
//!
//! \brief Turns the display on or off
//!
//! \fntype Function
//!
//! \param[in] bOn - true to turn on the display, false to turn it off
//!
//! This function sends commands to the controller to enable the output of the
//! display.
//!
////////////////////////////////////////////////////////////////////////////////
static void SendControllerOutputEnable(bool bOn)
{
if( bOn )
WriteDirect(CMD_MODE, 0x51);
else
WriteDirect(CMD_MODE, 0x50);
// Enable or disable the backlight PWM as necessary
#if defined(DDI_DISPLAY_ALL_TX_DRIVERS) && defined(RTOS_THREADX)
ddi_pwm_ChOutputEnable(1<<DDI_DISPLAY_BACKLIGHT_PWM_CHANNEL, bOn);
#else
if( bOn )
HW_PWM_CTRL_SET(1 << DDI_DISPLAY_BACKLIGHT_PWM_CHANNEL);
else
HW_PWM_CTRL_CLR(1 << DDI_DISPLAY_BACKLIGHT_PWM_CHANNEL);
#endif
}
////////////////////////////////////////////////////////////////////////////////
//! \brief Enters/exits low power mode
//!
//! \fntype Function
//!
//! \param[in] bOn - true to set low power mode, false to exit low power mode
//!
//! FIXME!!! comment me
//!
////////////////////////////////////////////////////////////////////////////////
static void SetControllerLowPowerMode(bool bOn)
{
if( bOn )
{
// Disable backlight PWM
HW_PWM_CTRL_CLR(1 << DDI_DISPLAY_BACKLIGHT_PWM_CHANNEL);
ddi_lcdif_Shutdown(true);
}
else
{
hw_lcdif_Init_t LcdifInit;
// Get the LCDIF init struct to send to the LCDIF DDI init function
ddi_display_controller_GetLcdifInitStruct(&LcdifInit, g_ddi_display_eBitmapType);
// Run the low level init on the LCDIF
ddi_lcdif_Init(&LcdifInit, g_ddi_display_pDmaDescChain, g_ddi_display_NumDmaDesc);
#if defined(RTOS_THREADX)
ddi_lcdif_RegisterCompletionCallback(&g_ddi_display_DmaCompletionCallback);
#endif
// Init the display controller, use last set width/height
ddi_display_controller_SendCommand(DDI_DISPLAY_CONTROLLER_INIT,
g_ddi_display_eBitmapType,
g_ddi_display_u16ScreenWidth,
g_ddi_display_u16ScreenHeight);
}
}
////////////////////////////////////////////////////////////////////////////////
//! \fn static void SendControllerContrast(uint32_t u32Percentage)
//!
//! \brief Sets the specified contrast percentage on the display
//!
//! \fntype Function
//!
//! \param[in] u32Percentage - Percent total contrast from 0 -> 100
//!
//! This function sends commands to the controller to set the desired contrast
//! percentage.
//!
////////////////////////////////////////////////////////////////////////////////
static void SendControllerContrast(uint32_t u32Percentage)
{
DDI_DISPLAY_WORD_TYPE Contrast = MIN_CONTRAST + (((u32Percentage * (MAX_CONTRAST - MIN_CONTRAST))) / 100);
WriteDirect(CMD_MODE, 0x2a);
WriteDirect(CMD_MODE, Contrast);
}
////////////////////////////////////////////////////////////////////////////////
//! \fn static void SetPwmBrightness(uint32_t u32Percentage)
//!
//! \brief Sets the specified brightness percentage on the display
//!
//! \fntype Function
//!
//! \param[in] u32Percentage - Percent total contrast from 0 -> 100
//!
//! Sets the PWM backlight control channel according to the given brightness
//! percentage value.
//!
////////////////////////////////////////////////////////////////////////////////
static void SetPwmBrightness(uint32_t u32Percentage)
{
#if defined(DDI_DISPLAY_ALL_TX_DRIVERS) && defined(RTOS_THREADX)
RtStatus_t ret = SUCCESS;
if( u32Percentage > 100 )
u32Percentage = 100;
ret = ddi_pwm_ChSetDutyCycle((hw_pwm_Channel_t)DDI_DISPLAY_BACKLIGHT_PWM_CHANNEL,
PWM_STATE_HIGH,
PWM_STATE_LOW,
u8MinBrightnessPercentage +
(( u32Percentage *
(u8MaxBrightnessPercentage - u8MinBrightnessPercentage))/100 ));
assert(!ret);
#else
uint32_t u32InactivePeriod;
// Set the raw values in the PWM registers
if( u32Percentage > 100 )
u32Percentage = 100;
u32InactivePeriod = ((BACKLIGHT_PWM_PERIOD * u8MinBrightnessPercentage)/100) +
(( ((BACKLIGHT_PWM_PERIOD * (u8MaxBrightnessPercentage - u8MinBrightnessPercentage))/100)
* u32Percentage)/100);
// Scale the range 0->100% down to 0->70% to protect the hardware
BF_CS2n(PWMn_ACTIVE, DDI_DISPLAY_BACKLIGHT_PWM_CHANNEL,
ACTIVE, 0,// BACKLIGHT_PWM_PERIOD,
INACTIVE, u32InactivePeriod);
HW_PWMn_PERIOD_SET(DDI_DISPLAY_BACKLIGHT_PWM_CHANNEL, 0);
#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)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -