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

📄 config.cpp

📁 Wince4.2 BSP for SH4 engineering development board
💻 CPP
📖 第 1 页 / 共 4 页
字号:

//
//      Copyright (c) 2001-2003 Renesas Technology Corp.
//      All Rights Reserved.
//
//      HD64404 Standard Display Driver
//
//
//  FILE      : CONFIG.CPP
//  CREATED   : 2001. 4.17 (for HD64413 display driver)
//  MODIFIED  : 2003. 6.17
//  AUTHOR    : Renesas Technology Corp.
//  HARDWARE  : US7751-HRPxxC (BigSur with HD64404, ITS-DS2A)
//              HS7751RSTC01H (S1-E, ITS-DS5)
//  TARGET OS : Microsoft(R) Windows(R) CE .NET 4.2
//  FUNCTION  : Driver entry point and physical configurations
//  HISTORY   : (history for H64413 display driver is omitted)
//              2001.10. 5
//              - Initially created for HD64404 by modifying HD64413 driver.
//               Mainly register names and variable names are changed.
//              2001.10.31
//              - Modified for HD64404 standard GPE display driver.
//              2002. 1.28
//              - g_dwLocalMemoryAddress is added to keep top address of
//               HD64404 locally-connected SDRAM.
//              - g_dwVideoMemoryAddress is renamed to g_dwVideoMemoryOffset.
//              2002. 2.28
//              - External dot clock mode is supported. Some address parameter
//               calculations are modified.
//              2002. 6.12
//              - Automatic parameter configuration for HD64404 display clock
//               PLL is implemented.
//              - Registry DisplayClockMode is added to specify display clock
//               generation scheme.
//              2002. 8. 1
//              - Most of RETAILMSGs are replaced with DEBUGMSGs except
//               those which report errors.
//              - Initial value assignment is added for CurErrPermil in
//               CalcInternalPLLParams.
//              2002. 9.25
//              - Header style is changed.
//              2002.11.27
//              - Automatic parameter configuration for Programmable Clock
//               Generator ICD2053B is implemented.
//              - Register base globals for each modules are removed and
//               g_dwRegisterAddress that is the register base global for all
//               HD64404 modules is added. 

//----------------------------------------------------------------------------

#include <windows.h>
#include <types.h>
#include <winddi.h>
#include <gpe.h>
#include "amadisp.h"
#include "dispregs.h"
#include "drvlib.h"
#include "platform.h" // Only for HD64404_BASE
#include "HD64404.h" // Only for HD64404_REGBASE

extern TCHAR* g_szModeString; // used to display video output mode
extern ModeInit AMADispMode[];

// These are default hardware parameter when registry is not defined.
// All of these should be defined properly in registry.
#define DEFAULT_LOCALMEMORY_ADDRESS HD64404_BASE
#define DEFAULT_VIDEOMEMORY_SIZE    0x00200000
#define DEFAULT_VIDEOMEMORY_OFFSET  0x00000000
#define DEFAULT_REGISTER_ADDRESS    HD64404_REGBASE

// These are default screen parameter when registry is not defined.
// All of these should be defined properly in registry.
#define DEFAULT_SCREEN_WIDTH        640 // VGA
#define DEFAULT_SCREEN_HEIGHT       480 // VGA
#define DEFAULT_BPP                 8
#define DEFAULT_DISPLAY_CLOCK_MODE  0 // uses HD64404 display clock PLL
#define DEFAULT_DISPLAY_CLOCK       25000000 // 25.000MHz for VGA
#define DEFAULT_SCAN_FREQUENCY      31500
#define DEFAULT_FRAME_RATE          60
#define DEFAULT_VIDEO_OUTPUT_MODE   0 // RGB only
#define DEFAULT_SCREEN_OFFSET_X     0
#define DEFAULT_SCREEN_OFFSET_Y     0
#define DEFAULT_EXT_PLL_BASE_CLOCK  3579545 // 3.579545MHz (Fsc of NTSC)

// This value means that corresponding registry value is not specified.
#define REG_NOTSPECIFIED    0x80000000

BOOL CalcInternalPLLParams(
    DWORD       dwBaseFreq,
    DWORD       dwTargetFreq,
    DWORD       *pdwOutputFreq,
    DWORD       *pdwDivN,
    DWORD       *pdwDivA,
    DWORD       *pdwDivB,
    DWORD       *pdwDivC,
    DWORD       *pdwDivP );

BOOL CalcICD2053PLLParams(
    DWORD       dwBaseFreq,
    DWORD       dwTargetFreq,
    DWORD       *pdwOutputFreq,
    DWORD       *pdwDivP,
    DWORD       *pdwDivQ,
    DWORD       *pdwMux );

BOOL APIENTRY GPEEnableDriver(
    ULONG          iEngineVersion,
    ULONG          cj,
    DRVENABLEDATA *pded,
    PENGCALLBACKS  pEngCallbacks );

BOOL APIENTRY DrvEnableDriver(
    ULONG          iEngineVersion,
    ULONG          cj,
    DRVENABLEDATA *pded,
    PENGCALLBACKS  pEngCallbacks )
{
    HKEY    hRegKey;
    DWORD   dwRet;
    DWORD   dwType;
    DWORD   dwLen;
    DWORD   dwScreenWidth, dwScreenHeight;
    DWORD   dwBpp;
    DWORD   dwScanFrequency;
    DWORD   dwFrameRate;
    DWORD   dwVideoOutputMode;
    DWORD   dwScreenOffsetX, dwScreenOffsetY;
    DWORD   dwDisplayClockMode;
    DWORD   dwDisplayClock, dwDesiredDisplayClock;
    DWORD   dwPLLBaseClock;
    DWORD   dwPLLDividerN; // HD64404 Built-in PLL
    DWORD   dwPLLDividerP; // HD64404 and external ICD2053B PLL
    DWORD   dwPLLDividerQ, dwPLLOutputMux; // external ICD2053B
    DWORD   dwPLLDividerA, dwPLLDividerB, dwPLLDividerC; // HD64404
    DWORD   dwVCOFrequency; // HD64404 and ICD2053B
    DWORD   dwLocalMemoryAddress; // HD64404 locally-connected SDRAM address
    DWORD   dwVideoMemoryOffset, dwVideoMemorySize;
    DWORD   dwRegisterAddress; // HD64404 register base address
    DWORD   dwVal; // for temporary use
    BOOL    bRet;
    DWORD   dwDsmr2, dwEqwr, dwSpwr;

    int     nHsw, nXs, nXe;
    int     nHOffset, nVOffset;
    int     nHds, nVds, nHc, nVc;
    int     nVsw, nYs;

    // Open the AMADisp registry key.
    dwRet = RegOpenKeyEx(
                HKEY_LOCAL_MACHINE,
                TEXT("Drivers\\Display\\AMADisp"),
                0, 0, &hRegKey);
    if (dwRet == ERROR_SUCCESS) {
        DEBUGMSG(1,
            (TEXT("AMADisp: Reading AMADisp registry key...\r\n")));

        dwLen = sizeof(DWORD);

        // Get screen width.
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("CxScreen"), NULL,
                    &dwType, (PBYTE)&dwScreenWidth, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwScreenWidth = REG_NOTSPECIFIED;

        // Get screen height.
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("CyScreen"), NULL,
                    &dwType, (PBYTE)&dwScreenHeight, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwScreenHeight = REG_NOTSPECIFIED;

        // Get color depth (bit per pixel).
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("Bpp"), NULL,
                    &dwType, (PBYTE)&dwBpp, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwBpp = REG_NOTSPECIFIED;

        // Get scan frequency.
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("ScanFrequency"), NULL,
                    &dwType, (PBYTE)&dwScanFrequency, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwScanFrequency = REG_NOTSPECIFIED;

        // Get frame rate.
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("FrameRate"), NULL,
                    &dwType, (PBYTE)&dwFrameRate, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwFrameRate = REG_NOTSPECIFIED;

        // Get screen offset X.
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("ScreenOffsetX"), NULL,
                    &dwType, (PBYTE)&dwScreenOffsetX, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwScreenOffsetX = REG_NOTSPECIFIED;

        // Get screen offset Y.
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("ScreenOffsetY"), NULL,
                    &dwType, (PBYTE)&dwScreenOffsetY, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwScreenOffsetY = REG_NOTSPECIFIED;

        // Get video output mode.
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("VideoOutputMode"), NULL,
                    &dwType, (PBYTE)&dwVideoOutputMode, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwVideoOutputMode = REG_NOTSPECIFIED;


        // Get display clock mode.
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("DisplayClockMode"), NULL,
                    &dwType, (PBYTE)&dwDisplayClockMode, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwDisplayClockMode = REG_NOTSPECIFIED;

        // Get display clock.
        // This means PLL target frequency when PLL is used. Otherwise,
        // this means externally-supplied display clock frequency.
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("DisplayClock"), NULL,
                    &dwType, (PBYTE)&dwDisplayClock, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwDisplayClock = REG_NOTSPECIFIED;

        // Get PLL base clock frequency. This is refered when HD64404
        // PLL is used or external PLL clock generator ICD2053B is used.
        // In display clock mode 0, normally CPU bus clock frequency in
        // system clock frequency information is used for PLL base clock,
        // but this will be overrided if this is specified in registry.
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("PLLBaseClock"), NULL,
                    &dwType, (PBYTE)&dwPLLBaseClock, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwPLLBaseClock = REG_NOTSPECIFIED;

        // Get PLL divider N. (optional, only for HD64404 PLL)
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("PLLDividerN"), NULL,
                    &dwType, (PBYTE)&dwPLLDividerN, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwPLLDividerN = REG_NOTSPECIFIED;

        // Get PLL divider A. (optional, only for HD64404 PLL)
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("PLLDividerA"), NULL,
                    &dwType, (PBYTE)&dwPLLDividerA, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwPLLDividerA = REG_NOTSPECIFIED;

        // Get PLL divider B. (optional, only for HD64404 PLL)
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("PLLDividerB"), NULL,
                    &dwType, (PBYTE)&dwPLLDividerB, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwPLLDividerB = REG_NOTSPECIFIED;

        // Get PLL divider C. (optional, only for HD64404 PLL)
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("PLLDividerC"), NULL,
                    &dwType, (PBYTE)&dwPLLDividerC, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwPLLDividerC = REG_NOTSPECIFIED;

        // Get PLL divider P. (optional, for both HD64404 and ICD2053B)
        // Note the meanings are different between them.
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("PLLDividerP"), NULL,
                    &dwType, (PBYTE)&dwPLLDividerP, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwPLLDividerP = REG_NOTSPECIFIED;

        // Get PLL divider Q. (optional, only for ICD2053B)
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("PLLDividerQ"), NULL,
                    &dwType, (PBYTE)&dwPLLDividerQ, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwPLLDividerQ = REG_NOTSPECIFIED;

        // Get PLL output multiplexer. (optional, only for ICD2053B)
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("PLLOutputMux"), NULL,
                    &dwType, (PBYTE)&dwPLLOutputMux, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwPLLOutputMux = REG_NOTSPECIFIED;

        // Get HD64404 local memory address.
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("LocalMemoryAddress"), NULL,
                    &dwType, (PBYTE)&dwLocalMemoryAddress, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwLocalMemoryAddress = REG_NOTSPECIFIED;

        // Get video memory offset. (from top of HD64404 local memory)
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("VideoMemoryOffset"), NULL,
                    &dwType, (PBYTE)&dwVideoMemoryOffset, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwVideoMemoryOffset = REG_NOTSPECIFIED;

        // Get video memory size.
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("VideoMemorySize"), NULL,
                    &dwType, (PBYTE)&dwVideoMemorySize, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwVideoMemorySize = REG_NOTSPECIFIED;

        // Get HD64404 register base address.
        dwRet = RegQueryValueEx(
                    hRegKey, TEXT("RegisterAddress"), NULL,
                    &dwType, (PBYTE)&dwRegisterAddress, &dwLen);
        if (dwRet != ERROR_SUCCESS) dwRegisterAddress = REG_NOTSPECIFIED;

        // Close AMADisp registry key.
        RegCloseKey(hRegKey);

    }
    else {
        RETAILMSG(1,
            (TEXT("AMADisp: Failed to open  AMADisp registry key.\r\n")));
        dwScreenWidth = REG_NOTSPECIFIED;
        dwScreenHeight = REG_NOTSPECIFIED;
        dwBpp = REG_NOTSPECIFIED;
        dwScanFrequency = REG_NOTSPECIFIED;
        dwFrameRate = REG_NOTSPECIFIED;
        dwVideoOutputMode = REG_NOTSPECIFIED;
        dwScreenOffsetX = REG_NOTSPECIFIED;
        dwScreenOffsetY = REG_NOTSPECIFIED;
        dwDisplayClockMode = REG_NOTSPECIFIED;
        dwDisplayClock = REG_NOTSPECIFIED;
        dwPLLBaseClock = REG_NOTSPECIFIED;
        dwPLLDividerN = REG_NOTSPECIFIED;
        dwPLLDividerA = REG_NOTSPECIFIED;
        dwPLLDividerB = REG_NOTSPECIFIED;
        dwPLLDividerC = REG_NOTSPECIFIED;
        dwPLLDividerP = REG_NOTSPECIFIED;
        dwPLLDividerQ = REG_NOTSPECIFIED;
        dwPLLOutputMux = REG_NOTSPECIFIED;
        dwLocalMemoryAddress = REG_NOTSPECIFIED;
        dwVideoMemoryOffset = REG_NOTSPECIFIED;
        dwVideoMemorySize = REG_NOTSPECIFIED;
        dwRegisterAddress = REG_NOTSPECIFIED;
    }

    // Set default value to each missed screen parameter.
    if (dwScreenWidth == REG_NOTSPECIFIED) {
        dwScreenWidth = DEFAULT_SCREEN_WIDTH;
        DEBUGMSG(1,
            (TEXT("AMADisp: Failed to get ScreenWidth from registry, ")
            TEXT("using default value %d.\r\n"), dwScreenWidth));
    }
    else DEBUGMSG(1,
        (TEXT("AMADisp: ScreenWidth is found, value is %d.\r\n"),
        dwScreenWidth));

    if (dwScreenHeight == REG_NOTSPECIFIED) {
        dwScreenHeight = DEFAULT_SCREEN_HEIGHT;
        DEBUGMSG(1,
            (TEXT("AMADisp: Failed to get ScreenHeight from registry, ")
            TEXT("using default value %d.\r\n"), dwScreenHeight));
    }
    else DEBUGMSG(1,
        (TEXT("AMADisp: ScreenHeight is found, value is %d.\r\n"),
        dwScreenHeight));

    if (dwBpp == REG_NOTSPECIFIED) {
        dwBpp = DEFAULT_BPP;
        DEBUGMSG(1,
            (TEXT("AMADisp: Failed to get Bpp from registry,")
            TEXT("using default value %d.\r\n"), dwBpp));
    }
    else DEBUGMSG(1,
        (TEXT("AMADisp: Bpp is found, value is %d.\r\n"),
        dwBpp));

⌨️ 快捷键说明

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