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

📄 ddi_display_controller_s6b0724.c

📁 sigmatel STMP36XX MP4方案下1289控制器和HX8347控制器
💻 C
📖 第 1 页 / 共 3 页
字号:
#if defined(DDI_DISPLAY_ALL_TX_DRIVERS) && defined(RTOS_THREADX)
    RtStatus_t ret;
#endif
        
    // 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 0
#if defined(DDI_DISPLAY_ALL_TX_DRIVERS) && defined(RTOS_THREADX)


    // Grab PWM for backlight use
    // Assume GPIO driver has already been initialized
    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
#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)
{
    static uint8_t u8Command = 0;
    static bool bDone = true;
#if 0
    // Init commands for the LCD hardware
    // power control
    WriteDirect(CMD_MODE, 0x28); // Power control VC=0, VR=0, VF=0 
    // display ON/OFF
    WriteDirect(CMD_MODE, 0xAE); // display OFF
    // ADC select
    WriteDirect(CMD_MODE, 0xA0); // normal direction -> SEG0->SEG131
    // SHL select
    WriteDirect(CMD_MODE, 0xC8); // reverse direction COM63->COM0
    // initial display line
    WriteDirect(CMD_MODE, 0x40); // = COM0
    // reverse display ON/OFF
    WriteDirect(CMD_MODE, 0xA6); // normal display
    // entire display ON/OFF
    WriteDirect(CMD_MODE, 0xA4); // normal display
    // power control
    WriteDirect(CMD_MODE, 0x2C); // Power control VC=1, VR=0, VF=0 
    delay(10);
    WriteDirect(CMD_MODE, 0x2E); // Power control VC=1, VR=1, VF=0
    delay(10);
    WriteDirect(CMD_MODE, 0x2F); // Power control VC=1, VR=1, VF=1
    // regulator resistor select
    WriteDirect(CMD_MODE, 0x23); // internal resistor ratio set
    // set reference voltage mode
    WriteDirect(CMD_MODE, 0x81); // set reference voltage mode
    WriteDirect(CMD_MODE, 0x24); // set contrast value
    delay(10);
#else
    WriteDirect(CMD_MODE, 0x2f);
    WriteDirect(CMD_MODE, 0x40);
    WriteDirect(CMD_MODE, 0xa6);
    WriteDirect(CMD_MODE, 0xa4);
    WriteDirect(CMD_MODE, 0xc8);
    WriteDirect(CMD_MODE, 0x23);
    WriteDirect(CMD_MODE, 0xa0);
    WriteDirect(CMD_MODE, 0x81);
    WriteDirect(CMD_MODE, 0x24);
    WriteDirect(CMD_MODE, 0xaf);
    WriteDirect(CMD_MODE, 0xe0);
#endif

    while( !bDone )
        WriteDirect(CMD_MODE, u8Command);
}

////////////////////////////////////////////////////////////////////////////////
//! \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

    // 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 )
    {
        SendControllerOutputEnable(false);

        // power control
        WriteDirect(CMD_MODE, 0x2D); // Power control VC=1, VR=0, VF=1 
        delay(50);
        WriteDirect(CMD_MODE, 0x2C); // Power control VC=1, VR=0, VF=0
        delay(10);
        WriteDirect(CMD_MODE, 0x28); // Power control VC=1, VR=0, VF=0
        delay(10);

        ddi_lcdif_Shutdown(true);
    }
    else
    {
        RtStatus_t ret = SUCCESS;
        hw_lcdif_Init_t LcdifInit;

        // Get the LCDIF init struct to send to the LCDIF DDI init function
        ret = ddi_display_controller_GetLcdifInitStruct(&LcdifInit, g_ddi_display_eBitmapType);
        assert(!ret);

        // Run the low level init on the LCDIF
        ret = ddi_lcdif_Init(&LcdifInit, g_ddi_display_pDmaDescChain, NUM_DMA_DESCRIPTORS);
        assert(!ret);

#if defined(RTOS_THREADX)
        ddi_lcdif_RegisterCompletionCallback(&g_ddi_display_DmaCompletionCallback);
#endif
        // Init the display controller, use last set width/height
        ret = ddi_display_controller_SendCommand(DDI_DISPLAY_CONTROLLER_INIT, 
                                                 g_ddi_display_eBitmapType,
                                                 g_ddi_display_u16ScreenWidth,
                                                 g_ddi_display_u16ScreenHeight);
        assert(!ret);

    }
}


////////////////////////////////////////////////////////////////////////////////
//! \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, 0x81); // set reference voltage mode
    WriteDirect(CMD_MODE, Contrast); // set contrast value
}

////////////////////////////////////////////////////////////////////////////////
//! \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 SetupAndStartDma(hw_lcdif_DmaDesc_t *pLcdifDmaDesc, u8int_t *pu8Buf)
//!
//! \brief Sets up the controller for the specified rotation
//!
//! \fntype Function
//!
//! \param[in] pLcdifDmaDesc - pointer to a lcdif dma descriptor for DMA chain
//! \param[in] pu8Buf - pointer to data buffer for dma
//! 
//! \retval SUCCESS No error
//!
//! \retval ERROR_DDI_DISPLAY_PLACEMENT - if no active region is set
//!     
//!
////////////////////////////////////////////////////////////////////////////////
static RtStatus_t SetupAndStartDma(hw_lcdif_DmaDesc_t *pLcdifDmaDesc, uint8_t *pu8Buf)
{
    hw_lcdif_DmaDesc_t *pThisLcdifDmaDesc;
    hw_lcdif_DmaDesc_t *pPrevLcdifDmaDesc;
    uint16_t  iCmdIdx, iDescIdx;

    if(u32NumActivePage == 0 || u32NumActivePage>MAX_PAGE_ADDRESS)
    {
        return ERROR_DDI_DISPLAY_PLACEMENT;
    }

    //  Init the DMA Descriptors
    memset(g_ddi_display_DmaDescChain, 0, sizeof(g_ddi_display_DmaDescChain));
    for(iDescIdx=0; iDescIdx<MAX_PAGE_ADDRESS*2; iDescIdx++)
    {
        // Minimum set of non-zero settings
        g_ddi_display_DmaDescChain[iDescIdx].m_Command = LCDIF_DMA_READ;
        g_ddi_display_DmaDescChain[iDescIdx].m_WaitForEndCommand = 1;
        g_ddi_display_DmaDescChain[iDescIdx].m_PIOWords = 1;
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -