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

📄 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 "bmp.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("\n13706BMP.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:   13706BMP bmpfile1 [bmpfile2] [ds=n | ds=?] [move=n]\n"
          "         [/noinit] [/r90 | /r180 | r270] [/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("   ds=n        select predefined display surfaces\n" );
   printf("   ds=?        show available display surfaces\n" );
   printf("   move=n      automatically move sub-window for n seconds\n");
   printf("               (to move forever, use move=-1)\n");
   printf("   /noinit     skips register initialization\n" );
   printf("   /r90        SwivelView 90 degree rotation  (for LCD)\n");
   printf("   /r180       SwivelView 180 degree rotation (for LCD)\n");
   printf("   /r270       SwivelView 270 degree rotation (for LCD)\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;
   NumberOfSurfaces = 0;
   CommonMemoryBlockForAllDisplays = FALSE;
   ActiveSurfaceNumber = 0;
   BmpCount = 0;
   MoveSubWinAroundScreenTime = 0;
   CmdDisplaySurface = -1;
   SubWinWidth = 0;
   SubWinHeight = 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], "R90" ))
            {
            LcdOrientation = ROTATE90;
            }
         else if ( !strcmpi( argv[i], "R180" ))
            {
            LcdOrientation = ROTATE180;
            }
         else if ( !strcmpi( argv[i], "R270" ))
            {
            LcdOrientation = ROTATE270;
            }
         else if ( !strcmpi( argv[i], "V" ))
            {
            VerboseMode = TRUE;
            }
         else if ( !strcmpi( argv[i], "NOINIT" ))
            {
            gbInitRegisters = FALSE;
            }
         else
            {
            DisplayUsage( );
            return 1;
            }
         }
      else if (!strncmp(argv[i], "DS=", 3))
         {
         if (argv[i][3] == '?')
            {
            DisplaySurfaceHelp();
            exit(0);
            }

         CmdDisplaySurface = atoi(&argv[i][3]);

         if (!((CmdDisplaySurface >= 0) && (CmdDisplaySurface < MAX_SURFACE_COMBINATIONS)))
            {
            printf("\nERROR: Invalid number for ds= option.\n");
            return 1;
            }
         }
      else if (!strncmp(argv[i], "MOVE=", 5))
         {
         MoveSubWinAroundScreenTime = atoi(&argv[i][5]);
         }
      else
         {
         if (BmpCount >= 2)
            {
            DisplayUsage( );
            return 1;
            }
               
         filename[BmpCount] = argv[i];
         ++BmpCount;
         }
      }

#ifdef BUILD_WITH_INTERNAL_BMP_IMAGES

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

#endif

   // Require at least one BMP file for display
   
   if (BmpCount == 0)
      {
      DisplayUsage();
      return 1;
      }

   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;
      }
}

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

void DisplaySurfaceHelp(void)
{
   printf("\n"
          "   ds=   |  Surface 0       Surface 1\n"
          "--------------------------------------\n"
          "    0    | MAIN WINDOW         ---\n"
          "    1    | MAIN&SUB-WINDOW     ---\n"
          "    2    | MAIN WINDOW      SUB-WINDOW\n");
}

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

void ShowActiveDisplaySurface(void)
{
   int tmp;

   /*
   ** "Display Surface: 0=MAIN WINDOW, 1=SUB-WINDOW"
   */
   printf("Display Surface: 0=");

   tmp = 0;

   if (SurfaceDisplayMode[0] & MAIN_WIN)
      {
      printf("MAIN WINDOW");
      ++tmp;
      }

   if (SurfaceDisplayMode[0] & SUB_WIN)
      {
      if (tmp > 0)
         printf(" & ");

      printf("SUB-WINDOW");
      ++tmp;
      }

   if (tmp == 0)
      printf("NONE");

   printf(", 1=");

   tmp = 0;

   if (SurfaceDisplayMode[1] & MAIN_WIN)
      {
      printf("MAIN WINDOW");
      ++tmp;
      }

   if (SurfaceDisplayMode[1] & SUB_WIN)
      {
      if (tmp > 0)
         printf(" & ");

      printf("SUB-WINDOW");
      ++tmp;
      }

   if (tmp == 0)
      printf("NONE");

   printf("\n");
}

/*-----------------------------------------------------------------------*/
// 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:

⌨️ 快捷键说明

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