📄 ddi_display_controller_ssd133x.c
字号:
return SUCCESS;
}
////////////////////////////////////////////////////////////////////////////////
//! \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, 0xAF); // display on
// else
// WriteDirect(CMD_MODE, 0xAE); // display off
HW_PINCTRL_DOUT3_RD();
if( bOn )
{
if( !( HW_PINCTRL_DOUT3_RD() & (1<<(10+DDI_DISPLAY_VCCSHUTDOWN_PWM_CHANNEL)) ) )
{
// turn on Vcc step-up
HW_PINCTRL_DOUT3_SET(1<<(10+DDI_DISPLAY_VCCSHUTDOWN_PWM_CHANNEL));
delay(20);
WriteDirect(CMD_MODE, 0xAF); // Display On
}
}
else
{
if( ( HW_PINCTRL_DOUT3_RD() & (1<<(10+DDI_DISPLAY_VCCSHUTDOWN_PWM_CHANNEL)) ) )
{
WriteDirect(CMD_MODE, 0xAE); // Display off
delay(1);
// turn off Vcc step-up
HW_PINCTRL_DOUT3_CLR(1<<(10+DDI_DISPLAY_VCCSHUTDOWN_PWM_CHANNEL));
delay(20);
}
}
// 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
}
////////////////////////////////////////////////////////////////////////////////
//! \fn static void SendControllerContrast(uint32_t u32Percentage)
//!
//! \brief Sets the specified contrast 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 ContrastRed = MIN_CONTRAST_RED + (((u32Percentage * (MAX_CONTRAST_RED - MIN_CONTRAST_RED))) / 100);
DDI_DISPLAY_WORD_TYPE ContrastGreen = MIN_CONTRAST_GREEN + (((u32Percentage * (MAX_CONTRAST_GREEN - MIN_CONTRAST_GREEN))) / 100);
DDI_DISPLAY_WORD_TYPE ContrastBlue = MIN_CONTRAST_BLUE + (((u32Percentage * (MAX_CONTRAST_BLUE - MIN_CONTRAST_BLUE))) / 100);
#ifdef DDI_DISPLAY_CONTROLLER_SSD1332
WriteDirect(CMD_MODE, 0x81); // Contrast for color A
WriteDirect(PARAM_MODE, ContrastRed);
WriteDirect(CMD_MODE, 0x82); // Contrast for color B
WriteDirect(PARAM_MODE, ContrastGreen);
WriteDirect(CMD_MODE, 0x83); // Contrast for color C
WriteDirect(PARAM_MODE, ContrastBlue);
#else
WriteDirect(CMD_MODE, 0xc1); // Contrast for color A, B, and C
WriteDirect(PARAM_MODE, ContrastRed);
WriteDirect(PARAM_MODE, ContrastGreen);
WriteDirect(PARAM_MODE, ContrastBlue);
#endif
}
////////////////////////////////////////////////////////////////////////////////
//! \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
}
#if 0
////////////////////////////////////////////////////////////////////////////////
//! \fn static void SendControllerBrightness(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 master current setting for the controller. The higher the
//! master current, the steeper the contrast response slope.
//!
////////////////////////////////////////////////////////////////////////////////
static void SendControllerBrightness(uint32_t u32Percentage)
{
DDI_DISPLAY_WORD_TYPE Brightness = MIN_BRIGHTNESS + (((u32Percentage * (MAX_BRIGHTNESS - MIN_BRIGHTNESS))) / 100);
WriteDirect(CMD_MODE, 0x87); // Master current control / attenuation
WriteDirect(PARAM_MODE, Brightness);
}
#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;
uint32_t u32TotalHeight;
RtStatus_t ret = SUCCESS;
DDI_DISPLAY_WORD_TYPE HorzCommand; // Command byte for horizontal setup
DDI_DISPLAY_WORD_TYPE XStart; // X region start
DDI_DISPLAY_WORD_TYPE XStop; // X region stop
DDI_DISPLAY_WORD_TYPE VertCommand; // Command byte for vertical setup
DDI_DISPLAY_WORD_TYPE YStart; // Y region start
DDI_DISPLAY_WORD_TYPE YStop; // Y region stop
switch(eRotation)
{
case DDI_DISPLAY_ROTATION_NONE:
case DDI_DISPLAY_ROTATION_180:
VertCommand = DDI_DISPLAY_VERT_REGION_CMD;
HorzCommand = DDI_DISPLAY_HORZ_REGION_CMD;
//! Currently set width of the display, used for the rotation feature
u32TotalWidth = DDI_DISPLAY_SIZE_HORIZONTAL;
//! Currently set height of the display, used for the rotation feature
u32TotalHeight = DDI_DISPLAY_SIZE_VERTICAL;
break;
case DDI_DISPLAY_ROTATION_90:
case DDI_DISPLAY_ROTATION_270:
// Swap the vertical and horizontal commands
VertCommand = DDI_DISPLAY_HORZ_REGION_CMD;
HorzCommand = DDI_DISPLAY_VERT_REGION_CMD;
//! Currently set width of the display, used for the rotation feature
u32TotalWidth = DDI_DISPLAY_SIZE_VERTICAL;
//! Currently set height of the display, used for the rotation feature
u32TotalHeight = DDI_DISPLAY_SIZE_HORIZONTAL;
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;
}
XStart = u32XDst;
XStop = u32XDst + *pu32Width - 1;
YStart = u32YDst;
YStop = u32YDst + *pu32Height - 1;
WriteDirect(CMD_MODE, HorzCommand); // Set column address
WriteDirect(PARAM_MODE, XStart);
WriteDirect(PARAM_MODE, XStop);
WriteDirect(CMD_MODE, VertCommand); // Set row address
WriteDirect(PARAM_MODE, YStart);
WriteDirect(PARAM_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
//!
////////////////////////////////////////////////////////////////////////////////
RtStatus_t SendControllerBitmapType(gfx_BitmapTypeEnum_t eBitmapType)
{
#ifdef DDI_DISPLAY_CONTROLLER_SSD1332
// Only 16-bit 565 mode supported
if( eBitmapType != BITMAP_TYPE_16BPP_565 )
return ERROR_DDI_DISPLAY_CONTROLLER_BITMAP_TYPE_UNSUPPORTED;
#elif defined(DDI_DISPLAY_CONTROLLER_SSD1339)
//! \todo Add 18bpp support
if( eBitmapType != BITMAP_TYPE_16BPP_565 )
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -