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

📄 lcd07x1.c

📁 lpc2478+ucosII+ucgui源码
💻 C
📖 第 1 页 / 共 4 页
字号:
    #define XORPIXEL_DATA(x, y,c)  XorPixel_Data(LCD_XSIZE-1-(x),y,c)
  #elif ( LCD_MIRROR_X && !LCD_MIRROR_Y &&  LCD_SWAP_XY) 
    #error This combination of mirroring/swapping not yet supported
  #elif ( LCD_MIRROR_X &&  LCD_MIRROR_Y && !LCD_SWAP_XY) 
    #define SETPIXEL(x, y, c)  _SetPixel(LCD_XSIZE-1-(x), LCD_YSIZE-1-(y), c)
    #define GETPIXEL(x, y)     _GetPixel(LCD_XSIZE-1-(x), LCD_YSIZE-1-(y))
    #define XORPIXEL(x, y)     XorPixel (LCD_XSIZE-1-(x), LCD_YSIZE-1-(y))
    #define XORPIXEL_DATA(x, y,c)  XorPixel_Data(LCD_XSIZE-1-(x), LCD_YSIZE-1-(y),c)
  #elif ( LCD_MIRROR_X &&  LCD_MIRROR_Y &&  LCD_SWAP_XY) 
    #error This combination of mirroring/swapping not yet supported
  #endif
#elif (LCD_SUPPORT_COMTRANS && !LCD_SUPPORT_SEGTRANS)
  #if (!LCD_SWAP_XY)
    #define SETPIXEL(x, y, c)  _SetPixel(x,LCD__aLine2Com0[y], c)
    #define GETPIXEL(x, y)     _GetPixel(x,LCD__aLine2Com0[y])
    #define XORPIXEL(x, y)      XorPixel(x,LCD__aLine2Com0[y])
  #else
    #define SETPIXEL(x, y, c)  _SetPixel(y,LCD__aLine2Com0[x], c)
    #define GETPIXEL(x, y)     _GetPixel(y,LCD__aLine2Com0[x])
    #define XORPIXEL(x, y)      XorPixel(y,LCD__aLine2Com0[x])
  #endif
#elif (!LCD_SUPPORT_COMTRANS && LCD_SUPPORT_SEGTRANS)
  #if (!LCD_SWAP_XY)
    #define SETPIXEL(x, y, c)  _SetPixel(LCD__aRow2Seg0[x],y, c)
    #define GETPIXEL(x, y)     _GetPixel(LCD__aRow2Seg0[x],y)
    #define XORPIXEL(x, y)      XorPixel(LCD__aRow2Seg0[x],y)
  #else
    #define SETPIXEL(x, y, c)  _SetPixel(LCD__aRow2Seg0[y],x, c)
    #define GETPIXEL(x, y)     _GetPixel(LCD__aRow2Seg0[y],x)
    #define XORPIXEL(x, y)      XorPixel(LCD__aRow2Seg0[y],x)
  #endif
#elif (LCD_SUPPORT_COMTRANS && LCD_SUPPORT_SEGTRANS)
  #if (!LCD_SWAP_XY)
    #define SETPIXEL(x, y, c)  _SetPixel(LCD__aRow2Seg0[x],LCD__aLine2Com0[y], c)
    #define GETPIXEL(x, y)     _GetPixel(LCD__aRow2Seg0[x],LCD__aLine2Com0[y])
    #define XORPIXEL(x, y)      XorPixel(LCD__aRow2Seg0[x],LCD__aLine2Com0[y])
  #else
    #define SETPIXEL(x, y, c)  _SetPixel(LCD__aRow2Seg0[y],LCD__aLine2Com0[x], c)
    #define GETPIXEL(x, y)     _GetPixel(LCD__aRow2Seg0[y],LCD__aLine2Com0[x])
    #define XORPIXEL(x, y)      XorPixel(LCD__aRow2Seg0[y],LCD__aLine2Com0[x])
  #endif
#else
  #error This combination of switches not yet supported
#endif


/*
        *********************************************************
        *                                                       *
        *       Next pixel routines                             *
        *                                                       *
        *********************************************************
*/

#if 0 /* Not yet defined ! */
     (LCD_OPTIMIZE)             \
      && (LCD_BUSWIDTH == 8)        \
      && (LCD_MIRROR_X)             \
      && (!LCD_MIRROR_Y)            \
      && (LCD_SWAP_XY)              \
      && (!LCD_SUPPORT_COMTRANS)    \
      && (!LCD_SUPPORT_SEGTRANS)    \
      && (LCD_BITSPERPIXEL == 4)

static int CurPosY;    /* Physical x position !!! */
static int CurOff;

static void SetPosXY(int x, int y) {
  y = LCD_YSIZE-1-y;
  CurPosY = y;
  CurOff = XY2OFF(y,x);
}

static void SetNextPixel(PIXELCOLOR c) {
  U8 Data = LCD_READ_MEM(Off);
  if (CurPosY&1) {
    Data = (Data & ~(15<<0)) | (c<<0);
    CurOff++;
  } else {
    Data = (Data & ~(15<<4)) | (c<<4);
  }
  LCD_WRITE_MEM(Off, Data);
  CurPosY++;
}

#define SETNEXTPIXEL(c) SetNextPixel(c)
#endif


/*
        *********************************************************
        *                                                       *
        *       Palette info                                    *
        *                                                       *
        *********************************************************

The following are "sample" palettes. You might have to create
a table yourself containing the entries corresponding to the
colors which your LCD can display.

*/

#if (LCD_FIXEDPALETTE==0)
  static const LCD_COLOR PhysColors[] = {
    #if (LCD_REVERSE)
      #if   (LCD_BITSPERPIXEL == 1)                   /* black/white */
        0xffffff, 0x000000
      #elif (LCD_BITSPERPIXEL == 2)                   /* 4 gray scales */
        0xffffff, 0xaaaaaa, 0x555555, 0x000000
      #endif
    #else
      #if   (LCD_BITSPERPIXEL == 1)                   /* black/white */
        0x000000, 0xffffff
      #elif (LCD_BITSPERPIXEL == 2)                   /* 4 gray scales */
        0x000000, 0x555555, 0xaaaaaa, 0xffffff
      #endif
    #endif
  };
#endif


/*
        *********************************************************
        *                                                       *
        *                   LCD_SetPaletteEntry                 *
        *                                                       *
        *********************************************************

*/

void LCD_L0_SetLUTEntry(U8 Pos, LCD_COLOR color) {
  Pos=Pos;
  color=color;
}


/*
        *********************************************************
        *                                                       *
        *       ID translation table                            *
        *                                                       *
        *********************************************************

This table contains 0, 1, 2, ... and serves as translation table for DDBs

*/

#define INTS(Base)  Base+0,Base+1,Base+2,Base+3,Base+4,Base+5,   \
                    Base+6,Base+7,Base+8,Base+9,Base+10,Base+11, \
                    Base+12,Base+13,Base+14,Base+15

static const PIXELCOLOR TransId[] = {
  INTS(0*16)
};


/*
  ********************************************************************
  *                                                                  *
  *                  Hardware access, register level                 *
  *                                                                  *
  *           Write Page / Column                                    *
  *                                                                  *
  ********************************************************************

 The following routines are used for all access to the
 LCD-controller(s).

*/

static U8 PageCache, ColCache;            /* Page / column of cache byte */


/*
        *****************************************
        *                                       *
        *         Set Column routines           *
        *                                       *
        *****************************************

These routines set the page-register of their respective
LCD-controller. Note that page is not what you might imagine,
but is a section of the controllers internal video RAM.
For details, please refer to the datasheet.

*/

#define SETCOL(col) {                                             \
  if (ColCache != col) {                                          \
    U8 temp_NewCol = 0x0+(col&15);    /* Set low nibble */        \
    LCD_WRITECMD(temp_NewCol);        /* Send low nibble */       \
    temp_NewCol = 0x10+(col>>4);   /* Set high nibble */       \
    LCD_WRITECMD(temp_NewCol);        /* Send high nibble */      \
    ColCache = col;                                            \
  }                                                               \
}

void SetCol(U8 col) {
  SETCOL(col);
}

#define SETCOL_IF_NEEDED(c) { if (c != ColCache) SETCOL(c); }


/*
        *****************************************
        *                                       *
        *         Set Page routines             *
        *                                       *
        *****************************************

These routines set the page-register of their respective
LCD-controller. Note that page is not what you might imagine,
but is a section of the controllers internal video RAM.
For details, please refer to the datasheet.

*/

#define SETPAGE(p) {              \
  U8 temp_NewPage;                \
  if (PageCache != p) {     \
    PageCache = p;          \
    temp_NewPage = 0xb0+ PageCache; \
    LCD_WRITECMD(temp_NewPage);   \
  }                               \
}

#define SETPAGE_IF_NEEDED(p) { if (p != PageCache) SETPAGE(p); }

void SetPage(U8 p) {
  SETPAGE(p);
}

#define WRITE_VMEM_PAIR(page, col, ptr)  { \
  if (!CacheLocked) {                      \
    SETPAGE_IF_NEEDED(page);               \
    SETCOL_IF_NEEDED(col);                 \
    LCD_WRITEMDATA(ptr,2);                 \
    ColCache++;                            \
  } else {                                 \
    aCacheDirty[page] = CacheStat=1;       \
  }                                        \
}


/*
        *********************************************************
        *                                                       *
        *       Internal set pixel routines                     *
        *                                                       *
        *********************************************************
*/

static void _SetPixel(int x, int y, PIXELCOLOR c) {
  U8 page = (y+LCD_FIRSTSEG0)>>3;
  U8 mask = 1<<((y+LCD_FIRSTSEG0)&7);
  U8 aData[2];
  U8* pCache = &Cache[page][x][0];
/* Read data from cache into 2 byte array */
  aData[0] = *pCache;
  aData[1] = *(pCache+1);
/* Write Data into array */
  if (c&(1<<1))
    aData[0] |= mask;
  else
    aData[0] &= ~mask;
  if (c&(1<<0))
    aData[1] |=  mask;
  else
    aData[1] &= ~mask;
/* Check if we need to write */
  if ((*pCache == aData[0]) &&  (*(pCache+1) == aData[1]))
    return;
/* Write modified data back into cache */
  *pCache    = aData[0];
  *(pCache+1) = aData[1];
/* Write data from cache into 2 byte array */
  WRITE_VMEM_PAIR(page, x, &aData[0]);
}

static PIXELCOLOR _GetPixel(int x, int y) {
  PIXELCOLOR col=0;
  U8 page = (y+LCD_FIRSTSEG0)>>3;
  U8 mask = 1<<((y+LCD_FIRSTSEG0)&7);
  if (Cache[page][x][0] & mask)
    col|=(1<<1);
  if (Cache[page][x][1] & mask)
    col|=(1<<0);
  return col;
}

static void XorPixel   (int x, int y) {
  PIXELCOLOR Index = _GetPixel(x,y);
  _SetPixel(x,y, LCD_NUM_COLORS-1-Index);
}

static void XorPixel_Data(int x, int y, PIXELCOLOR c) {
  PIXELCOLOR Index = _GetPixel(x,y);
  _SetPixel(x,y,Index^c);
}

/*
        *********************************************************
        *                                                       *
        *                  LCD_GetPixelIndex                    *
        *                                                       *
        *********************************************************
*/
unsigned LCD_L0_GetPixelIndex(int x, int y) {
  return GETPIXEL(x,y);
  /*return _GetPixel(x,y);*/
}

/*
        *********************************************************
        *                                                       *
        *       LCD_L0_XorPixel                                 *
        *                                                       *
        *********************************************************

Purpose:  This routine is called by emWin. It writes 1 pixel into the
          display.

*/

void LCD_L0_XorPixel(int x, int y) {
  XORPIXEL(x, y);
}

/*
        *********************************************************
        *                                                       *
        *       LCD_L0_SetPixelIndex                            *
        *                                                       *
        *********************************************************

Purpose:  This routine is called by emWin. It writes 1 pixel into the
          display.

*/
void LCD_L0_SetPixelIndex(int x, int y, int ColorIndex) {
  SETPIXEL(x, y, ColorIndex);
}



/*
        *********************************************************
        *                                                       *
        *          LCD_L0_DrawHLine unoptimized                    *
        *                                                       *
        *********************************************************
*/

void LCD_L0_DrawHLine  (int x0, int y,  int x1) {
  LCD_KICK_WATCHDOG();
  if (LCD_DrawMode & LCD_DRAWMODE_XOR) {
    while (x0 <= x1) {
      XORPIXEL(x0, y);
      x0++;
    }
  } else {
    while (x0 <= x1) {
      SETPIXEL(x0, y, COLOR);
      x0++;
    }
  }
}


/*
        *********************************************************
        *                                                       *
        *          LCD_L0_DrawVLine no optimization                *
        *                                                       *
        *********************************************************
*/

void LCD_L0_DrawVLine  (int x, int y0,  int y1) {
  LCD_KICK_WATCHDOG();
  if (LCD_DrawMode & LCD_DRAWMODE_XOR) {
    while (y0 <= y1) {
      XORPIXEL(x, y0);
      y0++;
    }
  } else {
    while (y0 <= y1) {
      SETPIXEL(x, y0, COLOR);
      y0++;
    }
  }
}


/*
        *********************************************************
        *                                                       *
        *          LCD_FillRect, no swap, optimized             *
        *                                                       *
        *********************************************************
*/

#if (!LCD_SWAP_XY) && (LCD_OPTIMIZE)

static const U8 aStartMask[] = { 255, 255-1, 255-3, 255-7, 255-15, 255-31, 255-63, 255-127 };
static const U8 aEndMask[] = { 1,3,7,15,31,63,127,255 };

void LCD_L0_FillRect(int x0, int y0, int x1, int y1) {
  U8 MaskStart, MaskEnd;
  U8 Page, Page0, Page1;
  int x;
  #if LCD_MIRROR_X
    #define X0 (LCD_XSIZE - 1 - x1)
    #define X1 (LCD_XSIZE - 1 - x0)
  #else
    #define X0 x0
    #define X1 x1
  #endif
  #if LCD_MIRROR_Y
    #define Y0 (LCD_YSIZE - 1 - y1)
    #define Y1 (LCD_YSIZE - 1 - y0)
  #else
    #define Y0 y0
    #define Y1 y1
  #endif
  if ((LCD_DrawMode & LCD_DRAWMODE_XOR) ==0) {
    MaskStart = aStartMask[Y0&7];
    MaskEnd   = aEndMask[Y1&7];
    Page0     = Y0>>3;
    Page1     = Y1>>3;
    for (Page =Page0; Page<= Page1; Page++) {
      U8 Mask =0xff;
      if (Page==Page0) {
        Mask  = MaskStart;
      }
      if (Page==Page1) {
        Mask &= MaskEnd;
      }
      for (x=X0; x<=X1; x++) {
        U8 aData[2];
        aData[0] = Cache[Page][x][0];
        aData[1] = Cache[Page][x][1];
        if (COLOR&(1<<1)) {
          aData[0] |= Mask;
        } else {
          aData[0] &= ~Mask;
        }
        if (COLOR&(1<<0)) {
          aData[1] |= Mask;
        } else {
          aData[1] &= ~Mask;
        }
        if (memcmp(&aData[0], &Cache[Page][x],2)) {
          Cache[Page][x][0]      = aData[0];
          Cache[Page][x][1]      = aData[1];
          WRITE_VMEM_PAIR(Page, x, &aData[0]);
        }
      }

⌨️ 快捷键说明

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