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

📄 ddi_display_controller_s6b0724.c

📁 sigmatel STMP36XX MP4方案下1289控制器和HX8347控制器
💻 C
📖 第 1 页 / 共 3 页
字号:
////////////////////////////////////////////////////////////////////////////////
//! \addtogroup ddi_display
//! @{
//
// Copyright (c) 2004-2005 SigmaTel, Inc.
//
//! \file ddi_display_controller_s6b33b0a.c
//! \brief Structures and code specific to the Samsung s6b33b0a controller
//! \version 0.1
//! \date 08/2005
//!
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Includes and external references
////////////////////////////////////////////////////////////////////////////////
#include <types.h>
#include <drivers\ddi_display.h>
#include <stdarg.h>
#include <registers\regspower.h>  // need this to check for alkaline battery 
#include "..\ddi_display_controller.h"
#include <components\gfx.h>
#include <hw\hw_lcdif.h>
#include <hw\hw_gpio.h>
#include <drivers\ddi_gpio.h>
#include <drivers\ddi_pwm.h>
#include <drivers\ddi_lcdif.h>
#include <string.h>
#if defined(RTOS_THREADX)
#include <os\os_thi_api.h>
#endif
#include <registers\regspwm.h>
#include <registers\regspinctrl.h>
#include <hw\vmemory.h>
#include <drivers\ddi_etm.h>

////////////////////////////////////////////////////////////////////////////////
// Externs
////////////////////////////////////////////////////////////////////////////////
ddi_display_Rotation_t g_ddi_display_eRotation = DDI_DISPLAY_ROTATION_NONE;
gfx_BitmapTypeEnum_t g_ddi_display_eBitmapType = BITMAP_TYPE_1BPP_VERTICAL;

#if defined(RTOS_THREADX)
//! Handler for the DMA completion callback
extern void g_ddi_display_DmaCompletionCallback(void *);
#endif

////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////

#ifndef DDI_DISPLAY_BACKLIGHT_PWM_CHANNEL
#define DDI_DISPLAY_BACKLIGHT_PWM_CHANNEL 2
#endif

#ifndef DDI_DISPLAY_DATA_SETUP_XCLKS 
#define DDI_DISPLAY_DATA_SETUP_XCLKS 0xff
#endif

#ifndef DDI_DISPLAY_DATA_HOLD_XCLKS
#define DDI_DISPLAY_DATA_HOLD_XCLKS 0xff
#endif

#ifndef DDI_DISPLAY_CMD_SETUP_XCLKS 
#define DDI_DISPLAY_CMD_SETUP_XCLKS 0xff
#endif

#ifndef DDI_DISPLAY_CMD_HOLD_XCLKS 
#define DDI_DISPLAY_CMD_HOLD_XCLKS 0xff
#endif

#ifndef DDI_DISPLAY_DEFAULT_SIZE_HORIZONTAL 
#define DDI_DISPLAY_DEFAULT_SIZE_HORIZONTAL DDI_DISPLAY_SIZE_HORIZONTAL
#endif

#ifndef DDI_DISPLAY_DEFAULT_SIZE_VERTICAL
#define DDI_DISPLAY_DEFAULT_SIZE_VERTICAL DDI_DISPLAY_SIZE_VERTICAL
#endif


//! Minimum contrast value set in hardware
#define MIN_CONTRAST 0x9

//! Maximum contrast value set in hardware
#define MAX_CONTRAST 0x3F

//! Min allowed brightness percentage
#define MIN_BRIGHTNESS_PERCENTAGE 0
//! Alkaline batttery can't support the power needed for high brightness
#define ALKALINE_MIN_BRIGHTNESS_PERCENTAGE 10

//! Max allowed brightness percentage
#define MAX_BRIGHTNESS_PERCENTAGE 70
//! Alkaline batttery can't support the power needed for high brightness
#define ALKALINE_MAX_BRIGHTNESS_PERCENTAGE 20



#if defined(DDI_DISPLAY_ALL_TX_DRIVERS) && defined(RTOS_THREADX)

//! Defines the frequency of the backlight PWM control signal
#define BACKLIGHT_PWM_FREQ 12000000

#else 

//! Defines the CDIV value for OS independent PWM control
#define BACKLIGHT_PWM_CDIV BV_PWMn_PERIOD_CDIV__DIV_1
//! Defines the period in divided clocks for OS independent PWM control
#define BACKLIGHT_PWM_PERIOD 200

#endif

// Max width for the controller
#define DDI_DISPLAY_CONTROLLER_MAX_WIDTH 132

// Max height for the controller
#define DDI_DISPLAY_CONTROLLER_MAX_HEIGHT 64

#define CMD_SET_LOWER_COLUMN_ADDRESS(x)     (x&0xf)
#define CMD_SET_HIGHER_COLUMN_ADDRESS(x)    0x10|((x>>4)&0xf)
#define CMD_SET_PAGE_ADDRESS(x)             0xb0|(x&0xf)

#define DDI_DISPLAY_WORD_TYPE uint8_t
#define DDI_DISPLAY_WORDLENGTH WORDLENGTH_8BITS
#define DDI_DISPLAY_DATA_SWIZZLE NO_SWAP//HWD_BYTE_SWAP 

#define MAX_PAGE_ADDRESS    ((DDI_DISPLAY_CONTROLLER_MAX_HEIGHT+7)/8)

// Each 8-bit data word written to a 1bpp type display represents 8 vertical pixels 
// A page is a row of these 8-bit vertical pixels
// Each page of the display requires a setup command to setup writes to that page
// We use 2 times the nubmer of pages on the display to chain together the
// page setup commands and corresponding page data in 2 separate descriptors.
// This way, we can update the entire display with one DMA descriptor chain
#define NUM_DMA_DESCRIPTORS (MAX_PAGE_ADDRESS*2)

////////////////////////////////////////////////////////////////////////////////
// Prototypes
////////////////////////////////////////////////////////////////////////////////
static void SendControllerOutputEnable(bool bOn);
static void SetPwmBrightness(uint32_t u32Percentage);

////////////////////////////////////////////////////////////////////////////////
// Variables
////////////////////////////////////////////////////////////////////////////////
// variables for alkaline mode since it can't power full brighness
static uint8_t u8MaxBrightnessPercentage;
static uint8_t u8MinBrightnessPercentage;

static uint32_t u32NumActivePage = 0;
static uint32_t u32NumActiveColumn = 0;

static uint32_t u32ControllerCommandBuf[MAX_PAGE_ADDRESS];



////////////////////////////////////////////////////////////////////////////////
// Globals
////////////////////////////////////////////////////////////////////////////////

//! Current screen width in pixels, modified when display is rotated
uint16_t g_ddi_display_u16ScreenWidth = DDI_DISPLAY_DEFAULT_SIZE_HORIZONTAL;

//! Current screen height in pixels, modified when display is rotated
uint16_t g_ddi_display_u16ScreenHeight = DDI_DISPLAY_DEFAULT_SIZE_VERTICAL;

//! Number of DMA descriptors that the display driver has allocated.  This is
//! calculated with the NUM_DMA_DESCRIPTORS macro.  Even though this will not
//! change during run-time, it is stored as a variable to allow each controller
//! support module to define its own value and build as a lib.
uint8_t g_ddi_display_NumDmaDesc = NUM_DMA_DESCRIPTORS;

//! Array of DMA descriptors.  These descriptors will be chained together as
//! necessary for the amount of data required to transfer for each draw operation
//! DMA descriptor for pixel data transfer
hw_lcdif_DmaDesc_t g_ddi_display_DmaDescChain[MAX_PAGE_ADDRESS*2] __OCRAM_NCNB_DATA;

//! Pointer to the DMA descriptor chain.  Necessary to allow building as a lib
hw_lcdif_DmaDesc_t *g_ddi_display_pDmaDescChain = g_ddi_display_DmaDescChain;

//! Current video mode of the driver.
ddi_display_VideoMode_t g_ddi_display_VideoMode = DDI_DISPLAY_ASYNC_MODE;
////////////////////////////////////////////////////////////////////////////////
// Code
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
//! \brief time delay function
//!
//! \fntype Function
//!
//! This function generate a short delay for controller driver
//!
////////////////////////////////////////////////////////////////////////////////
#if defined(DDI_DISPLAY_ALL_TX_DRIVERS) && defined(RTOS_THREADX)
#include <os\os_thi_api.h>
#endif

static void delay(uint32_t u32DelayValue)
{
/*
#if defined(DDI_DISPLAY_ALL_TX_DRIVERS) && defined(RTOS_THREADX)
    tx_thread_sleep(OS_MSECS_TO_TICKS(u32DelayValue));
#else
*/
    uint32_t i;

    u32DelayValue <<= 8;
    for( i = 0; i < u32DelayValue; i++ )
    {
#pragma asm
       nop
#pragma endasm        
    }
//#endif
}

////////////////////////////////////////////////////////////////////////////////
//! \brief Writes a single command or param/data byte to the controller
//!
//! \fntype Function
//!
//! \param[in] eCommMode - CMD_MODE or DATA_MODE specifier
//! \param[in] u8CommandByte - Command or param/data to send
//!
//! This function sends a single byte to the display controller
//!
////////////////////////////////////////////////////////////////////////////////
void WriteDirect(hw_lcdif_CommMode_t eCommMode, uint8_t u8CommandByte)
{
    uint32_t u32Command = u8CommandByte;
    RtStatus_t ret;
    switch( ddi_lcdif_GetDataSwizzle() )
    {
        case NO_SWAP:
            // Leave the data as is
            break;
        case HWD_BYTE_SWAP:    // Swap bytes within each half-word
            // Move command byte to upper half of lower 16-bit word
            u32Command <<= 8;
            break;
        case HWD_SWAP:         // Swap half-words
            // Move command byte to lower half of upper 16-bit word
            u32Command <<= 16;
            break;
        case SWAP_ALL_BYTES:   // Swap bytes 0,3 and 1,2
            // Move command byte to upper half of upper 16-bit word
            u32Command <<= 24;
            break;
        default:
            SystemHalt();      // Programming error
    }

    ret = ddi_lcdif_WriteDirect(eCommMode, (void *)&u32Command, sizeof(DDI_DISPLAY_WORD_TYPE));
    assert(!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_6800/*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_1BPP_VERTICAL != eBitmapType )
        return ERROR_DDI_DISPLAY_CONTROLLER_BITMAP_TYPE_UNSUPPORTED;

    memcpy(pInit, &LcdifInit, sizeof(hw_lcdif_Init_t));

    return SUCCESS;
}

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

⌨️ 快捷键说明

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