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

📄 util.c

📁 epson公司的一个关于s1d13706的低层驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
**===========================================================================
**  util.c
**---------------------------------------------------------------------------
**  Copyright (c) 2000, 2001 Epson Research and Development, Inc.
**  All Rights Reserved.
**===========================================================================
*/

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>

#include "hal.h"
#include "assert.h"
#include "demo.h"

#ifdef INCLUDE_CONIO_H   // Check if it's OK to include conio.h
#include <conio.h>
#endif

/*-----------------------------------------------------------------------*/

static char *szSwivelView[4] =
   { "landscape", "SwivelView 90", "SwivelView 180", "SwivelView 270" };

static char szModeFailed[] = "ERROR: Not enough memory for %s in %d bits-per-pixel.\n";

/*-----------------------------------------------------------------------*/

void DisplayCopyright( void )
{
   const char *szHalVer;
   const char *szHalStatus;
   const char *szHalStatusRev;

   seGetHalVersion( &szHalVer, &szHalStatus, &szHalStatusRev );

   printf("\n13706DEMO.EXE Version %s  [HAL %s%s%s]\n", szVersion, szHalVer, szHalStatus, szHalStatusRev);
   printf("Copyright (c) 2000, 2001 Epson Research and Development, Inc.\n");
   printf("All Rights Reserved.\n\n");

   printf("Register Start Addr:       ");
   if (HalInfo.dwRegisterAddress == 0)
      printf("Configured by system\n");
   else
      printf("%08lX\n", HalInfo.dwRegisterAddress);

   printf("Display Memory Start Addr: ");
   if (HalInfo.dwDisplayMemoryAddress == 0)
      printf("Configured by system\n");
   else
      printf("%08lX\n", HalInfo.dwDisplayMemoryAddress);
}

/*-------------------------------------------------------------------------*/

void DisplayUsage( void )
   {
   printf("Usage:   13706DEMO bmpfile1 bmpfile2\n"
          "         [/k] [/v] [/?]\n");
   printf("   bmpfile1    BMP image used for the main window\n");
   printf("   bmpfile2    BMP image used for the sub-window\n");
   printf("                 If bmpfile2 not given, bmpfile1 is used for the sub-window.\n");
   printf("   /k          Use keyboard to rotate (instead of automatic timing)\n");
   printf("   /v          Verbose mode\n");
   printf("   /?          Display help message\n");
   printf("Command line arguments in [] are optional.\n");
   }

/*-------------------------------------------------------------------------*/

void InitializeGlobalVariables(void)
   {
   int surface;

   gbInitRegisters = TRUE;
   gbImgCompress = FALSE;
   LcdOrientation = LANDSCAPE;
   VerboseMode = FALSE;
   UseKeyboard = FALSE;
   NumberOfSurfaces = 0;
   CommonMemoryBlockForAllDisplays = FALSE;
   ActiveSurfaceNumber = 0;
   BmpCount = 0;

   SubWinBmpWidth = 0;
   SubWinBmpHeight = 0;

   for (surface = 0; surface < MAX_DISP_SURFACE; surface++)
      {
      SurfaceDisplayMode[surface] = 0;   /* indicates which display is attached to which surface */
      filename[surface] = NULL;
      }
   }

/*-----------------------------------------------------------------------*/
// returns 0 if OK
// otherwise returns error value to be returned by main()

int ParseCommandLine(int argc, char *argv[])
   {
   int i;
#ifdef BUILD_WITH_INTERNAL_BMP_IMAGES
   static char szMainWin[] = "mainwin";
   static char szSubWin[] = "subwin";
#endif

   BmpCount = 0;

   /*
   ** Parse the command line.
   */
   for (i = 1; i < argc; ++i)
      {
      strupr(argv[i]);

      if (('/' == *argv[i]) || ('-' == *argv[i]))
         {
         argv[i]++;

         if (!strcmpi( argv[i], "?" ))
            {
            DisplayUsage( );
            exit(0);
            }
         else if ( !strcmpi( argv[i], "K" ))
            {
            UseKeyboard = TRUE;
            }
         else if ( !strcmpi( argv[i], "V" ))
            {
            VerboseMode = TRUE;
            }
         else
            {
            DisplayUsage( );
            return 1;
            }
         }
      else
         {
         if (BmpCount >= 2)
            {
            DisplayUsage( );
            return 1;
            }
               
         filename[BmpCount] = argv[i];
         ++BmpCount;
         }
      }

#ifdef BUILD_WITH_INTERNAL_BMP_IMAGES

   BmpCount = 2;
   filename[0] = szMainWin;
   filename[1] = szSubWin;

#else

   // Requires two BMP files for display
   
   if (BmpCount != 2)
      {
      DisplayUsage();
      return 1;
      }

#endif

   return 0;
   }

/*-----------------------------------------------------------------------*/
// returns 0 if OK
// otherwise returns error value to be returned by main()

int RegisterDevice(LPHAL_STRUCT info)
   {
   switch (seRegisterDevice(info))
      {
      case ERR_OK:
         break;

#ifdef WIN_PCI_DRIVER
      case ERR_PCI_DRIVER_NOT_FOUND:
         printf("ERROR: PCI driver not found.\n");
         return 1;

      case ERR_PCI_BRIDGE_ADAPTER_NOT_FOUND:
         printf("ERROR: PCI bridge adapter not found.\n");
         return 1;
#endif

      case ERR_UNKNOWN_DEVICE:
         printf("ERROR: Could not detect S1D13706.\n");
         return 1;
      
      default:
         printf("ERROR: Could not map memory from evaluation board to host platform.\n");
         return 1;
      }
      
   return 0;
   }

/*-----------------------------------------------------------------------*/
// returns 0 if OK
// otherwise returns error value to be returned by main()

int InitRegisters(void)
   {
   switch (seInitReg(CLEAR_MEM | DISP_BLANK))
      {
      case ERR_OK:
         break;

      case ERR_CLKI_NOT_IN_TABLE:
         printf("WARNING: CLKI frequency not in HAL table.\n"
                "         Program assumes that external oscillator is used.\n");
         break;

      case ERR_CLKI2_NOT_IN_TABLE:
         printf("WARNING: CLKI2 frequency not in HAL table.\n"
                "         Program assumes that external oscillator is used.\n");
         break;

      case ERR_NOT_ENOUGH_MEMORY:
         printf("\nERROR: Not enough display buffer memory.\n");
         return 1;
         break;
      }
      
   return 0;
   }

/*-----------------------------------------------------------------------*/

//
// Returns FALSE if error generated
//
int CheckSwivelViewClocks(unsigned BitsPerPixel, unsigned SwivelViewMode)
   {
   //
   // First check if valid clocks for given mode
   //
   if (seCheckSwivelViewClocks(BitsPerPixel, SwivelViewMode) != ERR_OK)
      {
      printf("\nERROR: Clocks not configured for %s mode.\n", szSwivelView[SwivelViewMode]);
      return FALSE;
      }

   return TRUE;
   }

/*-----------------------------------------------------------------------*/

//
// returns TRUE if OK
// returns FALSE if SwivelView failed
//
int UpdateLcdOrientation(void)
   {
   // If the registers are not initialized, then keep the same register settings for SwivelView

   if (!gbInitRegisters)
      {
      switch (seReadRegByte(REG_SPECIAL_EFFECTS) & 0x03)
         {
         case 0:
            LcdOrientation = LANDSCAPE;
            break;
            
         case 1:
            LcdOrientation = ROTATE90;
            break;
            
         case 2:
            LcdOrientation = ROTATE180;
            break;
            
         case 3:
            LcdOrientation = ROTATE270;
            break;
         }
      }

   //
   // First check if valid clocks for given mode
   //
   if (!CheckSwivelViewClocks(seGetBitsPerPixel(), LcdOrientation))
      return FALSE;

   if (seSetSwivelViewMode(LcdOrientation) == ERR_OK)
      return TRUE;
   else
      {
      printf("ERROR: Not enough memory for %s mode.\n", szSwivelView[LcdOrientation]);
      return FALSE;
      }
   }

/*-----------------------------------------------------------------------*/

void DisplayResolution(void)
{
   unsigned x, y, bpp;
   unsigned regDisplayMode;
   int surface;

   regDisplayMode = seReadRegByte(REG_DISPLAY_MODE);
   bpp = seGetBitsPerPixel();

   surface = CalcDisplaySurfaceCombination();

   switch (surface)
      {
      case SURFACE_NONE:
         break;

      case SURFACE_MAIN_WIN0:
         seGetMainWinResolution(&x, &y);
         printf("MAIN WINDOW (surface 0): %d * %d * %d Bpp\n", x, y, bpp);
         break;

      case SURFACE_MAIN_AND_SUB_WIN0:
      case SURFACE_MAIN_WIN0_SUB_WIN1:
         seGetMainWinResolution(&x, &y);
         printf("MAIN WINDOW (surface 0): %d * %d * %d Bpp\n", x, y, bpp);
         
         seGetSubWinResolution(&x, &y);
         printf("SUB-WINDOW  (surface ");

         if (surface == SURFACE_MAIN_WIN0_SUB_WIN1)
            printf("1");
         else
            printf("0");

         printf("): %d * %d * %d Bpp\n", x, y, bpp);
         break;
      }
}

/*-------------------------------------------------------------------------*/

// returns surface display mode

int GetSurfaceDisplayMode(int surface)
{
   switch (CalcDisplaySurfaceCombination())
      {
      case SURFACE_NONE:
         return 0;
         break;

      case SURFACE_MAIN_WIN0:
         if (surface == 0)
            return MAIN_WIN;
         break;

      case SURFACE_MAIN_WIN0_SUB_WIN1:
         if (surface == 0)
            return MAIN_WIN;
         else if (surface == 1)
            return SUB_WIN;
         break;

      case SURFACE_MAIN_AND_SUB_WIN0:
         if (surface == 0)
            return (MAIN_WIN | SUB_WIN);
         break;
      }

   return 0;
}

/*-----------------------------------------------------------------------*/
// returns surface combination

⌨️ 快捷键说明

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