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

📄 lcd6642x.c

📁 lpc2478+ucosII+ucgui源码
💻 C
📖 第 1 页 / 共 4 页
字号:
    #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                             *
        *                                                       *
        *********************************************************
*/


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

*/

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

/*
********************************************************************
*
*           Hardware access routines
*
********************************************************************
*/

/* Write into controller 0 */
void LCD_WriteReg0(int Reg, U8 Data) {
  LCD_WRITE_REG00(Reg);
  LCD_WRITE_REG01(Data);
}

#if LCD_NUM_CONTROLLERS > 1
void LCD_WriteReg1(int Reg, U8 Data) {
  LCD_WRITE_REG10(Reg);
  LCD_WRITE_REG11(Data);
}
#endif

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

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

*/

#define SET_X_INCREMENT()                    \
  aState[0].ConReg1 = (LCD_INIT_R01) | ( 2); \
  LCD_WriteReg0( 1, aState[0].ConReg1)

#define SET_Y_INCREMENT()                    \
  aState[0].ConReg1 = (LCD_INIT_R01) & (~2); \
  LCD_WriteReg0( 1, aState[0].ConReg1)

#define SET_X0(xNew) \
  if (aState[0].x != xNew) \
  { LCD_WRITE_REG00(2); LCD_WRITE_REG01(xNew); aState[0].x = xNew; }

#define SET_Y0(yNew) \
  if (aState[0].y != yNew) \
  { LCD_WRITE_REG00(3); LCD_WRITE_REG01(yNew); aState[0].y = yNew; }

#define EXEC_INCREMENT()        \
  if (aState[0].ConReg1 & 1<<1) \
    aState[0].x++;              \
  else                          \
    aState[0].y++

#if LCD_CACHE
  #define WRITE_VMEM0(Data) {     \
    aState[0].aaVMem[aState[0].y][aState[0].x] = Data; \
    LCD_WRITE_REG00(4);           \
    LCD_WRITE_REG01(Data);        \
    EXEC_INCREMENT();             \
  }
#else
  #define WRITE_VMEM0(Data) {     \
    LCD_WRITE_REG00(4);           \
    LCD_WRITE_REG01(Data);        \
    EXEC_INCREMENT();             \
  }
#endif

#if LCD_CACHE
  #define READ_VMEM0(Data)  {     \
    Data = aState[0].aaVMem[aState[0].y][aState[0].x]; \
  }
#else
  #define READ_VMEM0(Data)  {     \
    LCD_WRITE_REG00(4);           \
    LCD_READ_REG01(Data);         \
    LCD_READ_REG01(Data);         \
  }
#endif

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

static U8 aAndMask[4] = {255-(3<<6), 255-(3<<4), 255-(3<<2), 255-(3<<0)};

static void _SetPixel0_Phys(int x, int y, PIXELCOLOR c) {
  U8 Data;
  int xByte = x>>2;
  int Pos = x&3;
  #if LCD_CACHE ==0
    SET_X0(xByte);
    SET_Y0(y);
    READ_VMEM0(Data);
    Data &= aAndMask[Pos];
    Data |= c<<(6-(Pos<<1));
    WRITE_VMEM0(Data);
  #else
    U8* pData = &aState[0].aaVMem[y][xByte];
    Data = *pData & aAndMask[Pos];
    Data |= c<<(6-(Pos<<1));
    if (Data != *pData) {
      SET_X0(xByte);
      SET_Y0(y);
      WRITE_VMEM0(Data);
    }
  #endif
}

#define _SetPixel(x,y,c)     _SetPixel0_Phys(LOG2PHYS((x-LCD_XORG0),(y-LCD_YORG0)), c)

static PIXELCOLOR _GetPixel0(int x, int y) {
  int xByte = x>>2;
  int Pos = 3-(x&3);
  U8 Data;
  SET_X0(xByte);
  SET_Y0(y);
  READ_VMEM0(Data);
  return 3&(Data>>(Pos<<1));
}

static PIXELCOLOR _GetPixel(int x, int y) {
  return _GetPixel0(LOG2PHYS((x-LCD_XORG0),(y-LCD_YORG0)));
}

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

unsigned LCD_L0_GetPixelIndex(int x, int 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) {
  if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
    while (x0 <= x1) {
      XORPIXEL(x0, y);
      x0++;
    }
  } else {
    while (x0 <= x1) {
      SETPIXEL(x0, y, COLOR);
      x0++;
    }
  }
}

/*
        *********************************************************
        *
        *          LCD_L0_DrawVLine, optimized
        *
        *********************************************************
*/

#if (LCD_OPTIMIZE)               \
    && (LCD_BITSPERPIXEL == 2)   \
    && (LCD_SWAP_XY ==1)         \
    && (LCD_MIRROR_X==1)         \
    && (LCD_MIRROR_Y==0)         \
    && (!defined (LCD_LUT_SEG))

void LCD_L0_DrawVLine  (int x, int y0,  int y1) {
  U8 ColorMask, OrMask, AndMask, Data;
  int y = LCD_XSIZE - x - 1;
  int x0 = y0;
  int x1 = y1;
  int x0Byte = x0 >> 2;
  int x1Byte = (x1 + 1) >> 2;
  int NumBytes = x1Byte - x0Byte;
  SET_X_INCREMENT();
  SET_Y0(y);
  SET_X0(x0Byte);
  ColorMask  = COLOR + (COLOR<<2) + (COLOR<<4) + (COLOR<<6);
  if (x0 & 3) {
    int Pos = (x0 & 3) << 1;
    AndMask = 0xff << (8 - Pos);
    OrMask = ColorMask >> Pos;
    READ_VMEM0(Data);
    if (x0Byte == (x1 >> 2)) {
      if ((x1 & 3) != 3) {
        int Pos = ((x1 + 1) & 3) << 1;
        AndMask |= 0xff >> Pos;
        OrMask &= ColorMask << (8 - Pos);
      }
      NumBytes = 0;
    }
    if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
      Data ^= (0xff & ~AndMask);
    } else {
      Data &= AndMask;
      Data |= OrMask;
    }
    WRITE_VMEM0(Data);
    if (!NumBytes) {
      SET_Y_INCREMENT();
      return;
    }
    --NumBytes;
  }
  if (NumBytes) {
    if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
      do {
        READ_VMEM0(Data);
        Data ^= 0xff;
        WRITE_VMEM0(Data);
      } while(--NumBytes);
    } else {
      LCD_WRITE_REG00(4);
      #if LCD_CACHE
        memset(&aState[0].aaVMem[aState[0].y][aState[0].x], ColorMask, NumBytes);
      #endif
      aState[0].x += NumBytes;
      do {
        LCD_WRITE_REG01(ColorMask);
      } while(--NumBytes);
    }
  }
  if ((x1 + 1) & 3) {
    int Pos = ((x1 + 1) & 3) << 1;
    AndMask = 0xff >> Pos;
    OrMask = ColorMask << (8 - Pos);
    READ_VMEM0(Data);
    if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
      Data ^= (0xff & ~AndMask);
    } else {
      Data &= AndMask;
      Data |= OrMask;
    }
    WRITE_VMEM0(Data);
  }
  SET_Y_INCREMENT();
}

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

#else

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

#endif

/*********************************************************************
*
*          LCD_FillRect
*
**********************************************************************
*/


#if LCD_SWAP_XY
void LCD_L0_FillRect(int x, int y0, int x1, int y1) {
  for (; x <= x1; x++) {
    LCD_L0_DrawVLine(x,y0, y1);
  }
}
#else
void LCD_L0_FillRect(int x0, int y0, int x1, int y1) {
  for (; y0 <= y1; y0++) {
    LCD_L0_DrawHLine(x0,y0, x1);
  }
}
#endif

/*
        *********************************************************
        *
        *  Draw Bitmap 1 BPP, optimized
        *
        *********************************************************
*/

#if (LCD_OPTIMIZE)               \
    && (LCD_BITSPERPIXEL == 2)   \
    && (LCD_SWAP_XY ==1)         \
    && (LCD_MIRROR_X==1)         \
    && (LCD_MIRROR_Y==0)         \
    && (!defined (LCD_LUT_SEG))

static void DrawBitLine1BPP_Swap(
  int x,
  int y,
  U8 const * pData,
  int ysize,
  const U8 * pTrans,
  int BytesPerLine,
  U8 Pos)
{
  LCD_PIXELINDEX Index0 = *(pTrans+0);
  LCD_PIXELINDEX Index1 = *(pTrans+1);
  int i;
  int y0 = LCD_XSIZE - x - 1;
  int x0 = y;
  int x0Byte = y >> 2;
  U8 Buffer, DataMask, Index, Data, ShiftPos, BufferMask, Pixel;
  U8 BufferValid = 0;
  SET_Y0(y0);
  SET_X0(x0Byte);
  ShiftPos = Pos & 7;
  BufferMask = 0xC0 >> ((x0  & 3) << 1);
  DataMask =   0x80 >> ShiftPos;
  for (i = 0; i < ysize; i++, pData += BytesPerLine) {
    if (!BufferValid) {
      READ_VMEM0(Buffer);
      BufferValid = 1;
    }
    switch (GUI_Context.DrawMode) {
    case LCD_DRAWMODE_NORMAL:
    case LCD_DRAWMODE_REV:
      Buffer &= ~BufferMask;
      Index = *(pTrans + ((*pData & DataMask) >> (7 - ShiftPos)));
      Data = Index << (6 - (((i + x0) & 3) << 1));
      Buffer |= Data;
      break;
    case LCD_DRAWMODE_XOR:
      Pixel = (*pData & DataMask) >> (7 - ShiftPos);
      if (Pixel) {
        Data = 3 << (6 - (((i + x0) & 3) << 1));
        Buffer ^= Data;
      }
      break;
    case LCD_DRAWMODE_TRANS:
      Pixel = (*pData & DataMask) >> (7 - ShiftPos);
      if (Pixel) {
        Index = *(pTrans + Pixel);

⌨️ 快捷键说明

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