📄 dispdrvr.c
字号:
/*
** INTEL CONFIDENTIAL
** Copyright 2000-2003 Intel Corporation All Rights Reserved.
**
** The source code contained or described herein and all documents
** related to the source code (Material) are owned by Intel Corporation
** or its suppliers or licensors. Title to the Material remains with
** Intel Corporation or its suppliers and licensors. The Material contains
** trade secrets and proprietary and confidential information of Intel
** or its suppliers and licensors. The Material is protected by worldwide
** copyright and trade secret laws and treaty provisions. No part of the
** Material may be used, copied, reproduced, modified, published, uploaded,
** posted, transmitted, distributed, or disclosed in any way without Intel抯
** prior express written permission.
** No license under any patent, copyright, trade secret or other intellectual
** property right is granted to or conferred upon you by disclosure or
** delivery of the Materials, either expressly, by implication, inducement,
** estoppel or otherwise. Any license under such intellectual property rights
** must be express and approved by Intel in writing.
*/
#include <windows.h>
#include <types.h>
#include <string.h>
#include <stdio.h>
#include <tchar.h>
#include <nkintr.h>
#include <oalintr.h>
#include "bvd1.h"
#include "bvd1bd.h"
#include "drv_glob.h"
#include "DispDrvr.h"
#include "palette.h"
#define DEFINE_CURSOR_GLOBALS
#include "cursor.h"
#include "xllp_defs.h"
#include "xllp_serialization.h"
#include "xllp_lcd.h"
#include "camera.h"
///////
#include "xllp_camera.h"
#include "xllp_ADCM2650.h"
#include "xllp_bcr.h"
#include "xllp_ost.h"
#include "xllp_dmac.h"
#include "xllp_ci.h"
#include "xllp_i2c.h"
#include "xllp_camera_os_depend.h"
extern XLLP_STATUS_T XllpDmacInit(void);
///////
#include "dbgtrace.h"
extern XLLP_UINT32_T XllpLock(XLLP_PROTECTED_REGISTER Xllp_RegisterID);
extern void XllpUnlock(XLLP_UINT32_T Xllp_LockID);
extern XLLP_STATUS_T XllpLCDInit(P_XLLP_LCD_T pXllpLCD);
extern void XllpLCDLoadPalette(P_XLLP_LCD_T pXllpLCD);
extern void XllpLCDSuspend(P_XLLP_LCD_T pXllpLCD, int SuspendType);
extern void XllpLCDResume(P_XLLP_LCD_T pXllpLCD);
#define NUM_FRAME_BUFFERS 1
XLLP_LCD_T XllpLCD;
XLLP_STATUS_T status;
#define FRAME_BUFFER_BASE_PHYSICAL FRAME_BUFFER_0_BASE_PHYSICAL
BOOL gDrawCursorFlag = FALSE;
BOOL gInPowerHandler = FALSE;
BOOL bDoRotation = FALSE;
CRITICAL_SECTION displayMutex;
CRITICAL_SECTION frameDescriptorMutex;
CRITICAL_SECTION CameraMutex;
int DispDrvr_cxScreen;
int DispDrvr_cyScreen;
int DispDrvr_cdwStride;
int activeFrameBuffer=0;
unsigned int frameBufferSize = 0;
PBYTE gDibBuffer = NULL; // pointer to first byte of composition buffer
PBYTE gFrameBuffer = NULL; // pointer to first byte of screen memory
PBYTE gBlankFrameBuffer=NULL; // pointer to first byte of screen memory
RECT gCursorRect;
UINT nDisplayType;
volatile LCDRegs *v_pLcdRegs = NULL;
volatile XLLP_CLKMGR_T *v_pClkRegs = NULL;
volatile XLLP_GPIO_T *v_pGPIORegs = NULL;
volatile LCD_FRAME_DESCRIPTOR *frameDescriptorCh0fd1=NULL;
volatile LCD_FRAME_DESCRIPTOR *frameDescriptorCh0fd2=NULL;
volatile LCD_FRAME_DESCRIPTOR *frameDescriptorCh1=NULL;
volatile LCD_FRAME_DESCRIPTOR *frameDescriptorPalette=NULL;
volatile LCD_FRAME_DESCRIPTOR *frameDescriptorTemp=NULL;
volatile LCD_FRAME_DESCRIPTOR *frameDescriptorCh2_YCbCr_Y=NULL;
volatile LCD_FRAME_DESCRIPTOR *frameDescriptorCh3_YCbCr_Cb=NULL;
volatile LCD_FRAME_DESCRIPTOR *frameDescriptorCh4_YCbCr_Cr=NULL;
volatile LCD_PALETTE *v_pPaletteBuffer=NULL;
volatile BLR_REGS *v_pBoardLevelRegister;
volatile unsigned int *pOSCR = NULL;
///
volatile unsigned int * v_pOSTRegs = NULL;
volatile unsigned int * v_pCIRegs = NULL;
volatile unsigned int * v_pCameraDescriptors = NULL;
volatile unsigned int * v_pCameraDMABuffers = NULL;
volatile unsigned int * v_pI2C = NULL;
volatile XLLP_DMAC_T * v_pDMAC = NULL;
XLLP_Camera_Function_T ADCM2650_Functions;
XLLP_Camera_Context_T XllpCAMERA;
HANDLE hCameraFrameComplete;
HANDLE hIntEventKnown;
HANDLE hIntEvent;
///
// Instantiate the 8 bit palette
INSTANTIATE_PALETTE
void LCDClearStatusReg();
void LcdSetupGPIOs();
void Cleanup();
void InitLCDController();
void EnableLCDController();
void DisableLCDController();
void InitCursor();
BOOL MapVirtualAddress();
BOOL ReadRegistryData(VOID);
void CopyFrameBuffer(BOOL gDirection);
void ClearFrameBuffer(BOOL color);
void ScrollBuffer(int direction);
extern PVOID VirtualAllocCopy(unsigned size,char *str,PVOID pVirtualAddress);
void ConfigureFrameBufferSectionDescriptor(unsigned int descriptor);
unsigned int GetDescriptorAddress(unsigned int physical_address);
void Overlay2_Enable(P_XLLP_OVERLAY_T pXllpOverlay);
void Overlay2_Disable(P_XLLP_OVERLAY_T pXllpOverlay);
void Overlay2_DMA_Length(P_XLLP_OVERLAY_T pXllpOverlay);
//
void CameraInterruptHandler(void);
void ClearDMACInterrupt(int channel);
unsigned int halted = 0;
XLLP_OVERLAY_T XllpOverlay;
PBYTE pOverlay2_Y = NULL;
PBYTE pOverlay2_Cb = NULL;
PBYTE pOverlay2_Cr = NULL;
unsigned char *fbpY;
unsigned char *fbpCr;
unsigned char *fbpCb;
void CameraStartVideoCapture(void);
void CameraStopVideoCapture(void);
int CameraInit(P_CAMERA_APP_T pCameraApp);
void CameraCaptureStillImage(void);
void CameraReleaseFrame(P_CAMERA_APP_T pCameraApp);
//
extern BOOL VirtualSetAttributes(LPVOID lpvAddress, DWORD cbSize, DWORD dwNewFlags, DWORD dwMask, LPDWORD lpdwOldFlags);
extern void msWait(unsigned int);
#define _OPT_ASM
#ifdef _OPT_ASM
void dirtyRectDump_core_ASM(WORD *pwSrc, WORD *pwDst,int rowLen, DWORD srcWidthB,
DWORD bytesPerRow, DWORD srcMarginWidth, DWORD dstMarginWidth);
void DirtyRectDumpPortraitLoop_C(BYTE *pDstBuf, BYTE *pSrcBuf, DWORD yTop, DWORD yBottom,
DWORD srcWidthB, DWORD bytesPerRow, DWORD bytesPerPixel, DWORD srcMarginWidth, DWORD dstMarginWidth);
void ellipse_core_ASM(WORD srcColor,DWORD margin,DWORD width,WORD* pDstBuf);
void DispDrvrDirtyRectDump2(LPCRECT prc,DWORD color);
void DirtyRectDumpPortraitLoop_C_rectfill(BYTE *pDstBuf, WORD srcColor,DWORD yTop,DWORD yBottom,
DWORD srcWidthB, DWORD bytesPerRow, DWORD bytesPerPixel, DWORD srcMarginWidth, DWORD dstMarginWidth);
void DispDrvrDirtyRectDump_rectfill(LPCRECT prc, DWORD color);
#endif
void DispDrvrSetDibBuffer(void *data)
{
gDibBuffer = data;
}
void CameraInterruptHandler()
{
if (XllpCAMERA.capture_status & XLLP_CAMERA_STATUS_VIDEO_CAPTURE_IN_PROCESS)
{
EnterCriticalSection(&CameraMutex);
if (!XllpCameraNextBufferAvailable(&XllpCAMERA))
{
// need to complete current DMA and halt the next one.
XllpCameraStopVideoCapture(&XllpCAMERA);
halted++;
//v_pBoardLevelRegister->hex_led = halted;
}
LeaveCriticalSection(&CameraMutex);
}
}
void DispDrvrSetPalette (const PALETTEENTRY source[],unsigned short firstEntry,unsigned short numEntries)
{
int i;
int end = firstEntry + numEntries;
EnterCriticalSection(&frameDescriptorMutex);
// Store the palette entries into palette ram
for(i=firstEntry;i<end;i++)
{
// store 5 bits red, 6 bits green, and 5 bits blue
v_pPaletteBuffer->palette[i] = (
(source[i].peBlue) >> 3 |
((source[i].peGreen & 0xfc) << 3) |
((source[i].peRed & 0xf8) << 8)
);
}
XllpLCDLoadPalette(&XllpLCD);
LeaveCriticalSection(&frameDescriptorMutex);
}
void DispDrvrInitialize (void)
{
// Read display driver configuration from system registry
ReadRegistryData();
frameBufferSize = bpp / 8 * DispDrvr_cxScreen * DispDrvr_cyScreen;
// Map registers, the frame buffer, and frame descriptors from Kernel mode virtual address
// into our user mode virtual address space
if (!MapVirtualAddress())
return;
// Initialize for use with Suspend resume macros
msWait(1);
XllpLCD.GPIO = (XLLP_VUINT32_T *) v_pGPIORegs;
XllpLCD.CLKMan = (XLLP_VUINT32_T *) v_pClkRegs;
XllpLCD.LCDC = (XLLP_VUINT32_T *) v_pLcdRegs;
XllpLCD.DisplayType = nDisplayType;
XllpLCD.FrameBufferWidth = DispDrvr_cxScreen;
XllpLCD.FrameBufferHeight = DispDrvr_cyScreen;
XllpLCD.BPP = BPP_16;
XllpLCD.PixelDataFormat = PDFOR_00; //with overlays enabled use PDFOR_11 for 16bpp
XllpLCD.CurrentPage = 0;
XllpLCD._FRAME_BUFFER_BASE_PHYSICAL = FRAME_BUFFER_BASE_PHYSICAL;
XllpLCD._PALETTE_BUFFER_BASE_PHYSICAL = PALETTE_BUFFER_BASE_PHYSICAL;
XllpLCD._DMA_CHANNEL_0_FRAME_DESCRIPTOR_BASE_PHYSICAL = DMA_CHANNEL_0_FRAME_DESCRIPTOR_BASE_PHYSICAL;
XllpLCD._DMA_CHANNEL_1_FRAME_DESCRIPTOR_BASE_PHYSICAL = DMA_CHANNEL_1_FRAME_DESCRIPTOR_BASE_PHYSICAL;
XllpLCD._DMA_CHANNEL_0_ALT_FRAME_DESCRIPTOR_BASE_PHYSICAL = DMA_CHANNEL_0_ALT_FRAME_DESCRIPTOR_BASE_PHYSICAL;
XllpLCD._PALETTE_FRAME_DESCRIPTOR_BASE_PHYSICAL = PALETTE_FRAME_DESCRIPTOR_BASE_PHYSICAL;
XllpLCD.frameDescriptorCh0fd1 = frameDescriptorCh0fd1;
XllpLCD.frameDescriptorCh0fd2 = frameDescriptorCh0fd2;
XllpLCD.frameDescriptorCh1 = frameDescriptorCh1;
XllpLCD.frameDescriptorPalette = frameDescriptorPalette;
XllpLCD.frameDescriptorTemp = frameDescriptorTemp;
InitializeCriticalSection(&displayMutex);
InitializeCriticalSection(&frameDescriptorMutex);
InitializeCriticalSection(&CameraMutex);
// Initialize Cursor
InitCursor();
ClearFrameBuffer(TRUE);
// Initialize the LCD Controller and Board Control Register
XllpLCDInit(&XllpLCD);
InitRegs((XLLP_OST_T *)v_pOSTRegs, (P_XLLP_I2C_T)v_pI2C);
XllpI2cInit((P_XLLP_I2C_T)v_pI2C, (P_XLLP_GPIO_T) v_pGPIORegs, (P_XLLP_CLKMGR_T) v_pClkRegs, (XLLP_UINT32_T) 0);
pOSCR = v_pOSTRegs + 4;
// Use this event to signal the IST that we now know the dynamically assigned DMA channel
// And with that information, we know which event to wait on for the interrupt.
hIntEventKnown = CreateEvent(NULL,FALSE,FALSE,NULL);
NKDbgPrintfW(TEXT("\r\nDisplay Driver Initialization Complete\r\n"));
RETAILMSG(1,(TEXT("Display Driver Initialization Complete\r\n")));
//RETAILMSG(1,(TEXT("Display Driver----------------e\r\n")));
return;
}
// Initialize the XllpCAMERA structure with driver and application specific parameters.
int CameraInit(P_CAMERA_APP_T pCameraApp)
{
volatile DMA_GLOBALS *pDMAGlobals = NULL;
int n,i;
//
// sensor info
XllpCAMERA.sensor_type = XLLP_CAMERA_TYPE_ADCM_2650;
// capture image info
XllpCAMERA.capture_width = pCameraApp->VideoWidth;
XllpCAMERA.capture_height = pCameraApp->VideoHeight;
/*
XllpCAMERA.Video_capture_width = pCameraApp->VideoWidth;
XllpCAMERA.Video_capture_height = pCameraApp->VideoHeight;
XllpCAMERA.Still_capture_width = pCameraApp->StillWidth;
XllpCAMERA.Still_capture_height = pCameraApp->StillHeight;
*/
switch (pCameraApp->CaptureFormat)
{
case FORMAT_PLANAR_422:
XllpCAMERA.capture_input_format = XLLP_CAMERA_IMAGE_FORMAT_YCBCR422_PACKED;
XllpCAMERA.capture_output_format = XLLP_CAMERA_IMAGE_FORMAT_YCBCR422_PLANAR;
break;
case FORMAT_RGB:
XllpCAMERA.capture_input_format = XLLP_CAMERA_IMAGE_FORMAT_RGB888_PACKED;
XllpCAMERA.capture_output_format = XLLP_CAMERA_IMAGE_FORMAT_RGB565;
break;
default:
return 1;
}
// frame rate control
XllpCAMERA.frame_rate = pCameraApp->FrameRate;
// ring buffers
// note: must pass in 8 bytes aligned address
XllpCAMERA.buffer_virtual = (void *)v_pCameraDMABuffers;
XllpCAMERA.buffer_physical = (void *)CAM_DMA_BUFFER_PHYSICAL;
XllpCAMERA.buf_size = XllpCAMERA.capture_width * XllpCAMERA.capture_height * 2 * MAX_FRAMES; //CAMERA_DMA_BUFFER_SIZE;
// memory for dma descriptors, layout:
// dma descriptor chain 0,
// dma descriptor chain 1,
// ...
XllpCAMERA.dma_descriptors_virtual = (void *)v_pCameraDescriptors;
XllpCAMERA.dma_descriptors_physical = (void *)CAM_DMA_DESCRIPTOR_BASE_PHYSICAL;
XllpCAMERA.dma_descriptors_size = 1024;
// os mapped register address
XllpCAMERA.clk_reg_base = (unsigned int)v_pClkRegs;
XllpCAMERA.ost_reg_base = (unsigned int)v_pOSTRegs;
XllpCAMERA.gpio_reg_base = (unsigned int)v_pGPIORegs;
XllpCAMERA.ci_reg_base = (unsigned int)v_pCIRegs;
XllpCAMERA.board_reg_base = (unsigned int)v_pBoardLevelRegister;
ADCM2650_Functions.init = CameraFuncADCM2650Init;
ADCM2650_Functions.deinit = CameraFuncADCM2650DeInit;
ADCM2650_Functions.set_capture_format = CameraFuncADCM2650SetCaptureFormat;
ADCM2650_Functions.start_capture = CameraFuncADCM2650StartCapture;
ADCM2650_Functions.stop_capture = CameraFuncADCM2650StopCapture;
XllpCAMERA.camera_functions = &ADCM2650_Functions;
XllpDmacInit();
status = XllpCameraInit(&XllpCAMERA);
XllpCameraSetInterruptMask(&XllpCAMERA,
XLLP_CAMERA_INTMASK_END_OF_DMA |
XLLP_CI_CICR0_FOM |
XLLP_CI_CICR0_EOFM |
XLLP_CI_CICR0_SOFM |
XLLP_CI_CICR0_CDM |
XLLP_CI_CICR0_QDM |
XLLP_CI_CICR0_PERRM |
XLLP_CI_CICR0_EOLM |
XLLP_CI_CICR0_FEM );
n = XllpCameraGetNumFrameBuffers(&XllpCAMERA);
for (i = 0; i < n; i++)
{
// XllpCameraGetFrameBufferAddress would return a user mode virtual address, because it's based
// on XllpCamera.buffer_virtual. We really want to pass back a kernel mode virtual address
// because the application will need to map this address into its own address space.
//pCameraApp->ring_buffer_address[i] = XllpCameraGetFrameBufferAddress(&XllpCAMERA, i);
pCameraApp->ring_buffer_address[i] = (void*)((unsigned)CAM_DMA_BUFFER_U_VIRTUAL + i * XllpCAMERA.block_size);
}
pDMAGlobals = (volatile DMA_GLOBALS *)VirtualAllocCopy(sizeof(DMA_GLOBALS),"pDMAGlobals",(PVOID)(GDE_BUFFER_VIRTUAL));
hIntEvent = pDMAGlobals->hDMAEvent[XllpCAMERA.dma_channels[0]];
// Now that we know the event we are going to use, signal the IST thread so that it can start waiting on the
// new synchronization object.
SetEvent(hIntEventKnown);
return 0;
}
void CameraReleaseFrame(P_CAMERA_APP_T pCameraApp)
{
EnterCriticalSection(&CameraMutex);
XllpCameraReleaseFrameBuffer(&XllpCAMERA, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -