ucos+emWin+RA8875 横屏 竖屏 切换(基于红牛板)

来源:互联网 发布:斑马网络 上汽撤资 编辑:程序博客网 时间:2024/06/07 15:04

原始的例程没有竖屏,

自己做了个四向变换(编译时确定)

有需要的可以拿去,不用打招呼。

基于旺宝红牛版开发板做的。

 修改 LCDConf.h  文件里的 ORIENTATION 宏 则可改变方向。

(注意,横竖屏切换后,对于固定大小显示的emWin界面并不能直接适应屏幕)。


源代码在这里

http://download.csdn.net/detail/godyde/9680713

请使用Keilc MDK打开



如何移植 emWin 网上有大量的列子和教材,我就不在这里说明。


emWin 是不开方源代码的,所以 ucgui 使用三个宏来切换的横竖屏的方法不使用。而且即使可用运行效率也不高。


我说下我的横竖屏切换是如何做到的。


首先我们观察 emWin  和   显示屏驱动之间如何连接的。 emWin 到底调用了那些驱动函数来显示界面。

_SetPixelIndex 里调用了  LCD_PutPixel(x,y,PixelIndex);

_GetPixelIndex 里调用了  LCD_GetPixel(x,y);

_DrawHLine     里调用了  LCD_DrawLineH(x0, y, x1, LCD_COLORINDEX); 

_DrawVLine     里调用了  LCD_DrawLineV(x, y0, y1, LCD_COLORINDEX);//该函数我自己重写的,原例程里没有

_FillRect          里调用了    LCD_SetTarBlock(x0, y0, x1, y1);//该函数我自己重写的,用来替代RA8875_SetTarBlock .让程序更模块化

//这个很多新接触emWin 的人很容易漏掉下面这个地方。如果移植后,基础GUI接口显示正常,而图片,wigt 控件显示不正常,都是下面这个被调用的函数不正确。

_DrawBitLine16BPP 里调用了 LCD_DrawHColorLine(x, y, xsize, (uint16_t *)p);  //这个函数实现最麻烦,RA8875 没有找到垂直自增长的填充方式,最后用的画图的方式实现了。

_DrawBitLine32BPP 里也调用了LCD_DrawHColorLine(x, y, xsize, (uint16_t *)p) //这个调用是错误的,会导致颜色显示不对。但是我用的16位(565)色深,所以不会调用到这个。使用真彩色的需要注意,凡是带了color 的地方都要改成32位才能正确显示颜色。




打开GUIDRV_Template.c 这个文件咱们看看调用关系。

/*********************************************************************
*                SEGGER Microcontroller GmbH & Co. KG                *
*        Solutions for real time microcontroller applications        *
**********************************************************************
*                                                                    *
*        (c) 1996 - 2012  SEGGER Microcontroller GmbH & Co. KG       *
*                                                                    *
*        Internet: www.segger.com    Support:  support@segger.com    *
*                                                                    *
**********************************************************************


** emWin V5.16 - Graphical user interface for embedded applications **
All  Intellectual Property rights  in the Software belongs to  SEGGER.
emWin is protected by  international copyright laws.  Knowledge of the
source code may not be used to write a similar product.  This file may
only be used in accordance with the following terms:


The software has been licensed to  ARM LIMITED whose registered office
is situated at  110 Fulbourn Road,  Cambridge CB1 9NJ,  England solely
for  the  purposes  of  creating  libraries  for  ARM7, ARM9, Cortex-M
series,  and   Cortex-R4   processor-based  devices,  sublicensed  and
distributed as part of the  MDK-ARM  Professional  under the terms and
conditions  of  the   End  User  License  supplied  with  the  MDK-ARM
Professional. 
Full source code is available at: www.segger.com


We appreciate your understanding and fairness.
----------------------------------------------------------------------
File        : GUIDRV_Template.c
Purpose     : Template driver, should be used as starting point
              for new display drivers.
---------------------------END-OF-HEADER------------------------------
*/


#include <stddef.h>
#include "stm32f10x.h"
#include "LCD_Private.h"
#include "GUI_Private.h"
#include "LCD_SIM.h"
#include "LCD_ConfDefaults.h"
#include "LCD_RA8875.h"


#define emWin_Optimize   1   /* used for emWin optimize */


__IO uint8_t RA8875BusyNow = 0;
/*
********************************************************************
*
*       Defines
*
********************************************************************
*/


/*
********************************************************************
*
*       Macros for MIRROR_, SWAP_ and LUT_
*
********************************************************************
*/



//下面的宏,我劝大家别用,越用越乱。 效率也不高。
#if (!defined (LCD_LUT_COM) && !defined(LCD_LUT_SEG))
  #if   (!LCD_MIRROR_X && !LCD_MIRROR_Y && !LCD_SWAP_XY) 
    #define LOG2PHYS_X(x, y) x
    #define LOG2PHYS_Y(x, y) y
  #elif (!LCD_MIRROR_X && !LCD_MIRROR_Y &&  LCD_SWAP_XY) 
    #define LOG2PHYS_X(x, y) y
    #define LOG2PHYS_Y(x, y) x
  #elif (!LCD_MIRROR_X &&  LCD_MIRROR_Y && !LCD_SWAP_XY) 
    #define LOG2PHYS_X(x, y) x
    #define LOG2PHYS_Y(x, y) LCD_YSIZE - 1 - (y)
  #elif (!LCD_MIRROR_X &&  LCD_MIRROR_Y &&  LCD_SWAP_XY) 
    #define LOG2PHYS_X(x, y) y
    #define LOG2PHYS_Y(x, y) LCD_XSIZE - 1 - (x)
  #elif ( LCD_MIRROR_X && !LCD_MIRROR_Y && !LCD_SWAP_XY) 
    #define LOG2PHYS_X(x, y) LCD_XSIZE - 1 - (x)
    #define LOG2PHYS_Y(x, y) y
  #elif ( LCD_MIRROR_X && !LCD_MIRROR_Y &&  LCD_SWAP_XY) 
    #define LOG2PHYS_X(x, y) LCD_YSIZE - 1 - (y)
    #define LOG2PHYS_Y(x, y) x
  #elif ( LCD_MIRROR_X &&  LCD_MIRROR_Y && !LCD_SWAP_XY) 
    #define LOG2PHYS_X(x, y) LCD_XSIZE - 1 - (x)
    #define LOG2PHYS_Y(x, y) LCD_YSIZE - 1 - (y)
  #elif ( LCD_MIRROR_X &&  LCD_MIRROR_Y &&  LCD_SWAP_XY) 
    #define LOG2PHYS_X(x, y) LCD_YSIZE - 1 - (y)
    #define LOG2PHYS_Y(x, y) LCD_XSIZE - 1 - (x)
  #endif
#else
  #if   ( defined (LCD_LUT_COM) && !defined(LCD_LUT_SEG))
    #define LOG2PHYS_X(x, y) x
    #define LOG2PHYS_Y(x, y) LCD__aLine2Com0[y]
  #elif (!defined (LCD_LUT_COM) &&  defined(LCD_LUT_SEG))
    #define LOG2PHYS_X(x, y) LCD__aCol2Seg0[x]
    #define LOG2PHYS_Y(x, y) y
  #elif ( defined (LCD_LUT_COM) &&  defined(LCD_LUT_SEG))
    #define LOG2PHYS_X(x, y) LCD__aCol2Seg0[x]
    #define LOG2PHYS_Y(x, y) LCD__aLine2Com0[y]
  #endif
#endif


/*
**********************************************************************
*
*       Types
*
**********************************************************************
*/
typedef struct {
  U32 VRAMAddr;
  int xSize, ySize;
  int vxSize, vySize;
  int vxSizePhys;
  int BitsPerPixel;
} DRIVER_CONTEXT;


/*
**********************************************************************
*
*       Static functions
*
**********************************************************************
*/


/*
*************************************************************************
*
*       _SetPixelIndex
*
* Purpose:
*   Sets the index of the given pixel. The upper layers
*   calling this routine make sure that the coordinates are in range, so
*   that no check on the parameters needs to be performed.
*
*************************************************************************
*/
static void _SetPixelIndex(GUI_DEVICE * pDevice, int x, int y, int PixelIndex) {
  #ifdef WIN32
    LCDSIM_SetPixelIndex(x, y, PixelIndex, pDevice->LayerIndex);
  #else
    //
    // Convert logical into physical coordinates (Dep. on LCDConf.h)
    //
    #if (LCD_MIRROR_X == 1) || (LCD_MIRROR_Y == 1) || (LCD_SWAP_XY == 1)
      int xPhys, yPhys;


      xPhys = LOG2PHYS_X(x, y);
      yPhys = LOG2PHYS_Y(x, y);
    #else
      #define xPhys x
      #define yPhys y
    #endif
    GUI_USE_PARA(pDevice);
    GUI_USE_PARA(x);
    GUI_USE_PARA(y);
    GUI_USE_PARA(PixelIndex);
    {
      // Write into hardware ... Adapt to your system
      // TBD by customer...
  RA8875BusyNow = 1;
    LCD_PutPixel(x,y,PixelIndex);
  RA8875BusyNow = 0;
    }
    #if (LCD_MIRROR_X == 0) && (LCD_MIRROR_Y == 0) && (LCD_SWAP_XY == 0)
      #undef xPhys
      #undef yPhys
    #endif
  #endif
}


/*
*************************************************************************
*
*       _GetPixelIndex
*
* Purpose:
*   Returns the index of the given pixel. The upper layers
*   calling this routine make sure that the coordinates are in range, so
*   that no check on the parameters needs to be performed.
*
*************************************************************************
*/
static unsigned int _GetPixelIndex(GUI_DEVICE * pDevice, int x, int y) {
  unsigned int PixelIndex;
  #ifdef WIN32
    PixelIndex = LCDSIM_GetPixelIndex(x, y, pDevice->LayerIndex);
  #else
    //
    // Convert logical into physical coordinates (Dep. on LCDConf.h)
    //
    #if (LCD_MIRROR_X == 1) || (LCD_MIRROR_Y == 1) || (LCD_SWAP_XY == 1)
      int xPhys, yPhys;


      xPhys = LOG2PHYS_X(x, y);
      yPhys = LOG2PHYS_Y(x, y);
    #else
      #define xPhys x
      #define yPhys y
    #endif
    GUI_USE_PARA(pDevice);
    GUI_USE_PARA(x);
    GUI_USE_PARA(y);
    {
      //
      // Write into hardware ... Adapt to your system
      //
      // TBD by customer...
      //
 RA8875BusyNow = 1;
 PixelIndex = LCD_GetPixel(x,y);
 RA8875BusyNow = 0;
    }
    #if (LCD_MIRROR_X == 0) && (LCD_MIRROR_Y == 0) && (LCD_SWAP_XY == 0)
      #undef xPhys
      #undef yPhys
    #endif
  #endif
  return PixelIndex;
}


/*
********************************************************************
*
*       _XorPixel
*
********************************************************************
*/
static void _XorPixel(GUI_DEVICE * pDevice, int x, int y) {
  LCD_PIXELINDEX PixelIndex;
  LCD_PIXELINDEX IndexMask;


  PixelIndex = _GetPixelIndex(pDevice, x, y);
  IndexMask  = pDevice->pColorConvAPI->pfGetIndexMask();
  _SetPixelIndex(pDevice, x, y, PixelIndex ^ IndexMask);
}


/*
********************************************************************
*
*       _DrawHLine
*
*******************************************************************
*/
static void _DrawHLine  (GUI_DEVICE * pDevice, int x0, int y,  int x1) {
  if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
    for (; x0 <= x1; x0++) {
      _XorPixel(pDevice, x0, y);
    }
  } else {
  #if emWin_Optimize
RA8875BusyNow = 1;
LCD_DrawLineH(x0, y, x1, LCD_COLORINDEX);
RA8875BusyNow = 0;
  #else
    LCD_PIXELINDEX ColorIndex;
    ColorIndex = LCD__GetColorIndex();
    for (; x0 <= x1; x0++) {
      _SetPixelIndex(pDevice, x0, y, ColorIndex);
    }
  #endif
  }
}


/*
*************************************************************************
*
*       _DrawVLine, not optimized
*
*************************************************************************
*/
static void _DrawVLine  (GUI_DEVICE * pDevice, int x, int y0,  int y1) {
  if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
    for (; y0 <= y1; y0++) {
      _XorPixel(pDevice, x, y0);
    }
  } else {


#if emWin_Optimize
RA8875BusyNow = 1;
LCD_DrawLineV(x, y0, y1, LCD_COLORINDEX);
RA8875BusyNow = 0;
#else
LCD_PIXELINDEX ColorIndex;
ColorIndex = LCD__GetColorIndex();
   for (; y0 <= y1; y0++) {
     _SetPixelIndex(pDevice, x, y0, ColorIndex);
   }
#endif
  }
}


static void _FillRect(GUI_DEVICE * pDevice, int x0, int y0, int x1, int y1) 
{
#if emWin_Optimize


RA8875BusyNow = 1;
LCD_SetTarBlock(x0, y0, x1, y1);       //ÉèÖÃBTEλÖúͿí¶È¸ß¶È(Õë¶ÔºáÊúÆÁ×öÁËÐ޸ģ©
BTE_SetOperateCode(0x0C);         //É趨BTE ²Ù×÷ÂëºÍ¹âÕ¤ÔËËãÂë  REG[51h] Bit[3:0] = 0Ch 
RA8875_SetFrontColor(LCD_COLORINDEX);//ÉèÖÃBTEÇ°¾°É« 
BTE_Start();                //¿ªÆôBTE ¹¦ÄÜ 
BTE_Wait();                //µÈ´ý²Ù×÷½áÊø 
RA8875BusyNow = 0;

#else
for (; y0 <= y1; y0++) 
{
_DrawHLine(pDevice, x0, y0, x1);
}
#endif 
}


/*
********************************************************************
*
*       Draw Bitmap 1 BPP
*
********************************************************************
*/
static void _DrawBitLine1BPP(GUI_DEVICE * pDevice, unsigned x, unsigned y, U8 const GUI_UNI_PTR * p, int Diff, int xsize, const LCD_PIXELINDEX * pTrans) {
  LCD_PIXELINDEX IndexMask, Index0, Index1, Pixel;


  Index0 = *(pTrans + 0);
  Index1 = *(pTrans + 1);
  x += Diff;
  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
  case 0:
    do {
      _SetPixelIndex(pDevice, x++, y, (*p & (0x80 >> Diff)) ? Index1 : Index0);
      if (++Diff == 8) {
        Diff = 0;
        p++;
      }
    } while (--xsize);
    break;
  case LCD_DRAWMODE_TRANS:
    do {
      if (*p & (0x80 >> Diff))
        _SetPixelIndex(pDevice, x, y, Index1);
      x++;
      if (++Diff == 8) {
        Diff = 0;
        p++;
      }
    } while (--xsize);
    break;
  case LCD_DRAWMODE_XOR | LCD_DRAWMODE_TRANS:
  case LCD_DRAWMODE_XOR:
    IndexMask = pDevice->pColorConvAPI->pfGetIndexMask();
    do {
      if (*p & (0x80 >> Diff)) {
        Pixel = _GetPixelIndex(pDevice, x, y);
        _SetPixelIndex(pDevice, x, y, Pixel ^ IndexMask);
      }
      x++;
      if (++Diff == 8) {
        Diff = 0;
        p++;
      }
    } while (--xsize);
    break;
  }
}


/*
**************************************************************************
*
*       Draw Bitmap 2 BPP
*
**************************************************************************
*/
static void  _DrawBitLine2BPP(GUI_DEVICE * pDevice, int x, int y, U8 const GUI_UNI_PTR * p, int Diff, int xsize, const LCD_PIXELINDEX * pTrans) {
  LCD_PIXELINDEX Pixels, PixelIndex;
  int CurrentPixel, Shift, Index;


  Pixels = *p;
  CurrentPixel = Diff;
  x += Diff;
  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
  case 0:
    if (pTrans) {
      do {
        Shift = (3 - CurrentPixel) << 1;
        Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
        PixelIndex = *(pTrans + Index);
        _SetPixelIndex(pDevice, x++, y, PixelIndex);
        if (++CurrentPixel == 4) {
          CurrentPixel = 0;
          Pixels = *(++p);
        }
      } while (--xsize);
    } else {
      do {
        Shift = (3 - CurrentPixel) << 1;
        Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
        _SetPixelIndex(pDevice, x++, y, Index);
        if (++CurrentPixel == 4) {
          CurrentPixel = 0;
          Pixels = *(++p);
        }
      } while (--xsize);
    }
    break;
  case LCD_DRAWMODE_TRANS:
    if (pTrans) {
      do {
        Shift = (3 - CurrentPixel) << 1;
        Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
        if (Index) {
          PixelIndex = *(pTrans + Index);
          _SetPixelIndex(pDevice, x, y, PixelIndex);
        }
        x++;
        if (++CurrentPixel == 4) {
          CurrentPixel = 0;
          Pixels = *(++p);
        }
      } while (--xsize);
    } else {
      do {
        Shift = (3 - CurrentPixel) << 1;
        Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
        if (Index) {
          _SetPixelIndex(pDevice, x, y, Index);
        }
        x++;
        if (++CurrentPixel == 4) {
          CurrentPixel = 0;
          Pixels = *(++p);
        }
      } while (--xsize);
    }
    break;
  }
}


/*
**************************************************************************
*
*       Draw Bitmap 4 BPP
*
**************************************************************************
*/
static void  _DrawBitLine4BPP(GUI_DEVICE * pDevice, int x, int y, U8 const GUI_UNI_PTR * p, int Diff, int xsize, const LCD_PIXELINDEX * pTrans) {
  LCD_PIXELINDEX Pixels, PixelIndex;
  int CurrentPixel, Shift, Index;


  Pixels = *p;
  CurrentPixel = Diff;
  x += Diff;
  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
  case 0:
    if (pTrans) {
      do {
        Shift = (1 - CurrentPixel) << 2;
        Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
        PixelIndex = *(pTrans + Index);
        _SetPixelIndex(pDevice, x++, y, PixelIndex);
        if (++CurrentPixel == 2) {
          CurrentPixel = 0;
          Pixels = *(++p);
        }
      } while (--xsize);
    } else {
      do {
        Shift = (1 - CurrentPixel) << 2;
        Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
        _SetPixelIndex(pDevice, x++, y, Index);
        if (++CurrentPixel == 2) {
          CurrentPixel = 0;
          Pixels = *(++p);
        }
      } while (--xsize);
    }
    break;
  case LCD_DRAWMODE_TRANS:
    if (pTrans) {
      do {
        Shift = (1 - CurrentPixel) << 2;
        Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
        if (Index) {
          PixelIndex = *(pTrans + Index);
          _SetPixelIndex(pDevice, x, y, PixelIndex);
        }
        x++;
        if (++CurrentPixel == 2) {
          CurrentPixel = 0;
          Pixels = *(++p);
        }
      } while (--xsize);
    } else {
      do {
        Shift = (1 - CurrentPixel) << 2;
        Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
        if (Index) {
          _SetPixelIndex(pDevice, x, y, Index);
        }
        x++;
        if (++CurrentPixel == 2) {
          CurrentPixel = 0;
          Pixels = *(++p);
        }
      } while (--xsize);
    }
    break;
  }
}


/*
**************************************************************************
*
*       Draw Bitmap 8 BPP
*
**************************************************************************
*/
static void  _DrawBitLine8BPP(GUI_DEVICE * pDevice, int x, int y, U8 const GUI_UNI_PTR * p, int xsize, const LCD_PIXELINDEX * pTrans) {
  LCD_PIXELINDEX Pixel;


  switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
  case 0:
    if (pTrans) {
      for (; xsize > 0; xsize--, x++, p++) {
        Pixel = *p;
        _SetPixelIndex(pDevice, x, y, *(pTrans + Pixel));
      }
    } else {
      for (; xsize > 0; xsize--, x++, p++) {
        _SetPixelIndex(pDevice, x, y, *p);
      }
    }
    break;
  case LCD_DRAWMODE_TRANS:
    if (pTrans) {
      for (; xsize > 0; xsize--, x++, p++) {
        Pixel = *p;
        if (Pixel) {
          _SetPixelIndex(pDevice, x, y, *(pTrans + Pixel));
        }
      }
    } else {
      for (; xsize > 0; xsize--, x++, p++) {
        Pixel = *p;
        if (Pixel) {
          _SetPixelIndex(pDevice, x, y, Pixel);
        }
      }
    }
    break;
  }
}


/*
**************************************************************************
*
*       Draw Bitmap 16 BPP, not optimized
*
**************************************************************************
*/
static void _DrawBitLine16BPP(GUI_DEVICE * pDevice, int x, int y, U16 const GUI_UNI_PTR * p, int xsize) 
{
#if emWin_Optimize

// RA8875_SetCursor(x,y);
// RA8875_REG = 0x02;
// for (;xsize > 0; xsize--,p++)
// {
// RA8875_RAM = *p;
// }
RA8875BusyNow = 1;
LCD_DrawHColorLine(x, y, xsize, (uint16_t *)p);
RA8875BusyNow = 0;
#else
for (;xsize > 0; xsize--, x++, p++) 
{
_SetPixelIndex(pDevice, x, y, *p);
}
#endif


}


/*
**************************************************************************
*
*       Draw Bitmap 32 BPP, not optimized
*
**************************************************************************
*/
static void _DrawBitLine32BPP(GUI_DEVICE * pDevice, int x, int y, U32 const GUI_UNI_PTR * p, int xsize) 
{
#if emWin_Optimize
// RA8875_SetCursor(x,y);
// RA8875_REG = 0x02;
// for (;xsize > 0; xsize--,p++)
// {
// RA8875_RAM = *p;
// }
RA8875BusyNow = 1;
LCD_DrawHColorLine(x, y, xsize, (uint16_t *)p);
RA8875BusyNow = 0;
#else
for (;xsize > 0; xsize--, x++, p++) 
{
_SetPixelIndex(pDevice, x, y, *p);
}
#endif
}


/*
**************************************************************************
*
*       _DrawBitmap
*
**************************************************************************
*/
static void _DrawBitmap(GUI_DEVICE * pDevice, int x0, int y0,
                       int xSize, int ySize,
                       int BitsPerPixel, 
                       int BytesPerLine,
                       const U8 GUI_UNI_PTR * pData, int Diff,
                       const LCD_PIXELINDEX* pTrans) {
  int i;


  switch (BitsPerPixel) {
  case 1:
    for (i = 0; i < ySize; i++) {
      _DrawBitLine1BPP(pDevice, x0, i + y0, pData, Diff, xSize, pTrans);
      pData += BytesPerLine;
    }
    break;
  case 2:
    for (i = 0; i < ySize; i++) {
      _DrawBitLine2BPP(pDevice, x0, i + y0, pData, Diff, xSize, pTrans);
      pData += BytesPerLine;
    }
    break;
  case 4:
    for (i = 0; i < ySize; i++) {
      _DrawBitLine4BPP(pDevice, x0, i + y0, pData, Diff, xSize, pTrans);
      pData += BytesPerLine;
    }
    break;
  case 8:
    for (i = 0; i < ySize; i++) {
      _DrawBitLine8BPP(pDevice, x0, i + y0, pData, xSize, pTrans);
      pData += BytesPerLine;
    }
    break;
  case 16:
    for (i = 0; i < ySize; i++) {
      _DrawBitLine16BPP(pDevice, x0, i + y0, (const U16 *)pData, xSize);
      pData += BytesPerLine;
    }
    break;
  case 32:
    for (i = 0; i < ySize; i++) {
      _DrawBitLine32BPP(pDevice, x0, i + y0, (const U32 *)pData, xSize);
      pData += BytesPerLine;
    }
    break;
  }
}


/*
********************************************************************
*
*       _InitOnce
*
* Purpose:
*   Allocates a fixed block for the context of the driver
*
* Return value:
*   0 on success, 1 on error
*
********************************************************************
*/
static int _InitOnce(GUI_DEVICE * pDevice) {
  DRIVER_CONTEXT * pContext;


  if (pDevice->u.pContext == NULL) {
    pDevice->u.pContext = GUI_ALLOC_GetFixedBlock(sizeof(DRIVER_CONTEXT));
    pContext = (DRIVER_CONTEXT *)pDevice->u.pContext;
    pContext->BitsPerPixel = LCD__GetBPP(pDevice->pColorConvAPI->pfGetIndexMask());
  }
  return pDevice->u.pContext ? 0 : 1;
}


/*
**************************************************************************
*
*       _GetDevProp
*
**************************************************************************
*/
static I32 _GetDevProp(GUI_DEVICE * pDevice, int Index) {
  DRIVER_CONTEXT * pContext;


  pContext = (DRIVER_CONTEXT *)pDevice->u.pContext;
  switch (Index) {
  case LCD_DEVCAP_XSIZE:
    return pContext->xSize;
  case LCD_DEVCAP_YSIZE:
    return pContext->ySize;
  case LCD_DEVCAP_VXSIZE:
    return pContext->vxSize;
  case LCD_DEVCAP_VYSIZE:
    return pContext->vySize;
  case LCD_DEVCAP_BITSPERPIXEL:
    return pContext->BitsPerPixel;
  case LCD_DEVCAP_NUMCOLORS:
    return 0;
  case LCD_DEVCAP_XMAG:
    return 1;
  case LCD_DEVCAP_YMAG:
    return 1;
  case LCD_DEVCAP_MIRROR_X:
    return 0;
  case LCD_DEVCAP_MIRROR_Y:
    return 0;
  case LCD_DEVCAP_SWAP_XY:
    return 0;
  }
  return -1;
}


/*
**************************************************************************
*
*       _GetDevData
*
**************************************************************************
*/
static void * _GetDevData(GUI_DEVICE * pDevice, int Index) {
  GUI_USE_PARA(pDevice);
  #if GUI_SUPPORT_MEMDEV
    switch (Index) {
    case LCD_DEVDATA_MEMDEV:
//
// TBD: Has to be adapted to the right memory device depending on the used color depth!
    // 
 return (void *)&GUI_MEMDEV_DEVICE_16; 
    }
  #else
    GUI_USE_PARA(Index);
  #endif
  return NULL;
}


/*
**************************************************************************
*
*       _GetRect
*
**************************************************************************
*/
static void _GetRect(GUI_DEVICE * pDevice, LCD_RECT * pRect) {
  DRIVER_CONTEXT * pContext;


  pContext = (DRIVER_CONTEXT *)pDevice->u.pContext;
  pRect->x0 = 0;
  pRect->y0 = 0;
  pRect->x1 = pContext->vxSize - 1;
  pRect->y1 = pContext->vySize - 1;
}


/*
**************************************************************************
*
*       _SetOrg
*
**************************************************************************
*/
static void _SetOrg(GUI_DEVICE * pDevice, int x, int y) {
  LCD_X_SETORG_INFO Data = {0};


  Data.xPos = x;
  Data.yPos = y;
  LCD_X_DisplayDriver(pDevice->LayerIndex, LCD_X_SETORG, (void *)&Data);
}


/*
**********************************************************************
*
*       Static code: Functions available by _GetDevFunc()
*
**********************************************************************
*/


/*
*********************************************************************
*
*       _SetVRAMAddr
*
*********************************************************************
*/
static void _SetVRAMAddr(GUI_DEVICE * pDevice, void * pVRAM) {
  DRIVER_CONTEXT * pContext;
  LCD_X_SETVRAMADDR_INFO Data = {0};


  _InitOnce(pDevice);
  if (pDevice->u.pContext) {
    pContext = (DRIVER_CONTEXT *)pDevice->u.pContext;
    pContext->VRAMAddr = (U32)pVRAM;
    Data.pVRAM = pVRAM;
    LCD_X_DisplayDriver(pDevice->LayerIndex, LCD_X_SETVRAMADDR, (void *)&Data);
  }
}


/*
********************************************************************
*
*       _SetVSize
*
********************************************************************
*/
static void _SetVSize(GUI_DEVICE * pDevice, int xSize, int ySize) {
  DRIVER_CONTEXT * pContext;


  _InitOnce(pDevice);
  if (pDevice->u.pContext) {
    pContext = (DRIVER_CONTEXT *)pDevice->u.pContext;
    pContext->vxSize = xSize;
    pContext->vySize = ySize;
    pContext->vxSizePhys = xSize;
  }
}


/*
********************************************************************
*
*       _SetSize
*
********************************************************************
*/
static void _SetSize(GUI_DEVICE * pDevice, int xSize, int ySize) {
  DRIVER_CONTEXT * pContext;
  LCD_X_SETSIZE_INFO Data = {0};


  _InitOnce(pDevice);
  if (pDevice->u.pContext) {
    pContext = (DRIVER_CONTEXT *)pDevice->u.pContext;
    pContext->vxSizePhys = (pContext->vxSizePhys == 0) ? xSize : pContext->vxSizePhys;
    pContext->xSize = xSize;
    pContext->ySize = ySize;
    Data.xSize = xSize;
    Data.ySize = ySize;
    LCD_X_DisplayDriver(pDevice->LayerIndex, LCD_X_SETSIZE, (void *)&Data);
  }
}


/*
*********************************************************************
*
*       _Init
*
*********************************************************************
*/
static int  _Init(GUI_DEVICE * pDevice) {
  int r;


  r = _InitOnce(pDevice);
  r |= LCD_X_DisplayDriver(pDevice->LayerIndex, LCD_X_INITCONTROLLER, NULL);
  return r;
}


/*
*********************************************************************
*
*       _On
*
*********************************************************************
*/
static void _On (GUI_DEVICE * pDevice) {
  LCD_X_DisplayDriver(pDevice->LayerIndex, LCD_X_ON, NULL);
}


/*
*********************************************************************
*
*       _Off
*
*********************************************************************
*/
static void _Off (GUI_DEVICE * pDevice) {
  LCD_X_DisplayDriver(pDevice->LayerIndex, LCD_X_OFF, NULL);
}


/*
*********************************************************************
*
*       _SetLUTEntry
*
*********************************************************************
*/
static void _SetLUTEntry(GUI_DEVICE * pDevice, U8 Pos, LCD_COLOR Color) {
  LCD_X_SETLUTENTRY_INFO Data = {0};


  Data.Pos   = Pos;
  Data.Color = Color;
  LCD_X_DisplayDriver(pDevice->LayerIndex, LCD_X_SETLUTENTRY, (void *)&Data);
}


/*
*********************************************************************
*
*       _GetDevFunc
*
*********************************************************************
*/
static void (* _GetDevFunc(GUI_DEVICE ** ppDevice, int Index))(void) {
  GUI_USE_PARA(ppDevice);
  switch (Index) {
  case LCD_DEVFUNC_SET_VRAM_ADDR:
    return (void (*)(void))_SetVRAMAddr;
  case LCD_DEVFUNC_SET_VSIZE:
    return (void (*)(void))_SetVSize;
  case LCD_DEVFUNC_SET_SIZE:
    return (void (*)(void))_SetSize;
  case LCD_DEVFUNC_INIT:
    return (void (*)(void))_Init;
  case LCD_DEVFUNC_ON:
    return (void (*)(void))_On;
  case LCD_DEVFUNC_OFF:
    return (void (*)(void))_Off;
  case LCD_DEVFUNC_SETLUTENTRY:
    return (void (*)(void))_SetLUTEntry;
  }
  return NULL;
}


/*
**********************************************************************
*
*       Public data
*
**********************************************************************
*/


/*
***********************************************************************
*
*       GUI_DEVICE_API structure
*
***********************************************************************
*/
const GUI_DEVICE_API GUIDRV_Template_API = {
  //
  // Data
  //
  DEVICE_CLASS_DRIVER,
  //
  // Drawing functions
  //
  _DrawBitmap,
  _DrawHLine,
  _DrawVLine,
  _FillRect,
  _GetPixelIndex,
  _SetPixelIndex,
  _XorPixel,
  //
  // Set origin
  //
  _SetOrg,
  //
  // Request information
  //
  _GetDevFunc,
  _GetDevProp,
  _GetDevData,
  _GetRect,
};


/*************************** End of file ****************************/




好了,所有关联函数都在这了,就是前面提到的六个函数


这六个函数的位置都放置在 bsp_tft_lcd.c 文件里,我们接着看bsp_tft_lcd.c 文件


我用了一个宏_LCD_SWAP_XY .来决定编译时是编译成横屏还是竖屏。_LCD_SWAP_XY =0 时为横屏。


各位可以直接在下面的代码里看看横屏和竖屏执行的代码的不同。


而 横屏和竖屏能正确显示后,剩余的两个方向,只是 XY 轴翻转的问题,我使用RA8875 自带的设置其扫描方向来实现翻转(省了好多事,只需设置好RA8875的0x40h寄存器就可以了)


/*******************************************************************************
  * Company: Wang Electronic Technology Co., Ltd.
  ******************************************************************************
  * ÎļþÃû³Æ£ºbsp_tft_lcd.c
  * ¹¦ÄÜ˵Ã÷£ººìÁú103 7´çLCD  FSMCÅäÖÃ
  * °æ    ±¾£ºV1.0
* ×÷    Õߣºopenmcu
  * ÈÕ    ÆÚ£º2014-09-27
********************************************************************************
  * ÎļþÃû³Æ£º
  * ¹¦ÄÜ˵Ã÷£º
  * °æ    ±¾£º
* ¸üÐÂ×÷Õß:
  * ÈÕ    ÆÚ£º
* ¸üÐÂÄÚÈÝ£º
********************************************************************************/


#include "stm32f10x.h"
#include <stdio.h>
#include <string.h>
#include "LCD_RA8875.h"
#include "fonts.h"








uint16_t g_LcdWidth = 800; // ÏÔʾÆÁ·Ö±æÂÊ-¿í¶È
uint16_t g_LcdHeight = 480; // ÏÔʾÆÁ·Ö±æÂÊ-¸ß¶È 
uint8_t s_ucBright;    //±³¹âÁÁ¶È²ÎÊý 


/**************************************************************************************
** Function name:       void Delay(uint16_t nCount)
** Descriptions:        ÓÃÓÚ³õʼ»¯LCD
** input parameters:    nCount ÑÓʱ¼ÆÊý                 
** output parameters:   ÎÞ
** Returned value:      ÎÞ
***************************************************************************************/
static void Delay(uint16_t nCount)
{
    uint16_t TimingDelay;
    while(nCount--)
    {
      for(TimingDelay=0;TimingDelay<10000;TimingDelay++);
    }
}


/**************************************************************************************
** Function name:       void LCD_GPIOConfig(void)
** Descriptions:        ÅäÖÃLCD¿ØÖÆ¿ÚÏߣ¬FSMC¹Ü½ÅÉèÖÃΪ¸´Óù¦ÄÜ
** input parameters:    ÎÞ
** output parameters:   ÎÞ
** Returned value:      ÎÞ
***************************************************************************************/
static void LCD_GPIOConfig(void)
{

GPIO_InitTypeDef GPIO_InitStructure;
/* Enable FSMC, GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);



RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
                      RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG |
                      RCC_APB2Periph_AFIO, ENABLE);

/* Set  PD.00(D2), PD.01(D3), PD.04(NOE)--LCD_RD £¨¶Á£©, PD.05(NWE)--LCD_WR£¨Ð´£©,
     PD.08(D13),PD.09(D14),PD.10(D15),PD.14(D0),PD.15(D1) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_8 | 
GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15  ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;               //¸´ÓÃÍÆÍìÊä³ö
GPIO_Init(GPIOD, &GPIO_InitStructure);

/* Set PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9), PE.13(D10),
PE.14(D11), PE.15(D12) as alternate function push pull */
GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | 
                           GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | 
                           GPIO_Pin_15;
GPIO_Init(GPIOE, &GPIO_InitStructure);

/* Set PF.00(A0 (RS)) as alternate function push pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOF, &GPIO_InitStructure);

  /* Set PG.12(NE4 (LCD/CS)) as alternate function push pull - CE3(LCD /CS) */
  /* NE4 configuration */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  GPIO_Init(GPIOG, &GPIO_InitStructure);
}


/**************************************************************************************
** Function name:       void LCD_FSMCConfig(void)
** Descriptions:        ÅäÖÃFSMC²¢¿Ú·ÃÎÊʱÐò
** input parameters:    ÎÞ
** output parameters:   ÎÞ
** Returned value:      ÎÞ
***************************************************************************************/
static void LCD_FSMCConfig(void)
{
FSMC_NORSRAMInitTypeDef  Init;
FSMC_NORSRAMTimingInitTypeDef  Time;


/*-- FSMC Configuration ------------------------------------------------------*/
/*----------------------- SRAM Bank 4 ----------------------------------------*/
/* FSMC_Bank1_NORSRAM4 configuration */
Time.FSMC_AddressSetupTime = 1;
Time.FSMC_AddressHoldTime = 1;
Time.FSMC_DataSetupTime = 2;
Time.FSMC_BusTurnAroundDuration = 0;
Time.FSMC_CLKDivision = 0;
Time.FSMC_DataLatency = 0;
Time.FSMC_AccessMode = FSMC_AccessMode_A;


/*
LCD configured as follow:
   - Data/Address MUX = Disable
   - Memory Type = SRAM
   - Data Width = 16bit
   - Write Operation = Enable
   - Extended Mode = Enable
   - Asynchronous Wait = Disable
*/
Init.FSMC_Bank = FSMC_Bank1_NORSRAM4;
Init.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
Init.FSMC_MemoryType = FSMC_MemoryType_SRAM;
Init.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
Init.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
Init.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
Init.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
Init.FSMC_WrapMode = FSMC_WrapMode_Disable;
Init.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
Init.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
Init.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
Init.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
Init.FSMC_WriteBurst = FSMC_WriteBurst_Disable;


Init.FSMC_ReadWriteTimingStruct = &Time;
Init.FSMC_WriteTimingStruct = &Time;


FSMC_NORSRAMInit(&Init);


FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);
}


/**************************************************************************************
** Function name:       void LCD_InitHard(void)
** Descriptions:        ³õʼ»¯8875
** input parameters:    ÎÞ
** output parameters:   ÎÞ
** Returned value:      ÎÞ
***************************************************************************************/
void LCD_InitHard(void)
{
LCD_GPIOConfig();         //ÅäÖÃLCD¿ØÖÆ¿ÚÏßGPIO 
LCD_FSMCConfig();         //ÅäÖÃFSMC½Ó¿Ú£¬Êý¾Ý×ÜÏß 
  Delay(10);
RA8875_InitHard();     //³õʼ»¯RA8875оƬ
RA8875_SetFillV(_LCD_SWAP_XY);//  这里必须根据横屏或竖屏来设置显示屏的绘图填充方向,(实测不设置其实也没啥鸟事)
//下面的代码用来设置显示屏的扫描方向, XY的镜像是通过显示屏的设置实现的。

#if(!_LCD_SWAP_XY && !LCD_FLIP)  
RA8875_SetXY(2<<2);
#elif(_LCD_SWAP_XY && !LCD_FLIP)
RA8875_SetXY(0<<2);
#elif(!_LCD_SWAP_XY && LCD_FLIP)
RA8875_SetXY(1<<2);
#elif(_LCD_SWAP_XY && LCD_FLIP)
RA8875_SetXY(3<<2);
#endif
}




/**************************************************************************************
** Function name:       LCD_PutPixel(uint16_t X, uint16_t Y, uint16_t Color)
** Descriptions:        »æÖÆ1¸öÏñËØ
** input parameters:    x, y  £ºÏñËØ×ø±ê
**                      Color £ºÏñËØÑÕÉ«      
** output parameters:   ÎÞ
** Returned value:      ÎÞ
***************************************************************************************/
void LCD_PutPixel(uint16_t x, uint16_t y, uint16_t Color)
{

#if(!_LCD_SWAP_XY)
RA8875_PutPixel(x, y, Color);//横屏时调用
#else
RA8875_PutPixel(y, x, Color);//竖屏时调用
#endif

}
#if(!_LCD_SWAP_XY)
#else
#endif
/**************************************************************************************
** Function name:       LCD_PutPixel(uint16_t x, uint16_t y, uint16_t Color)
** Descriptions:        ¶ÁÈ¡1¸öÏñËØ
** input parameters:    x, y  £ºÏñËØ×ø±ê                           
** output parameters:   ÎÞ
** Returned value:      RGB £ºÏñËØÑÕÉ« 
***************************************************************************************/
uint16_t LCD_GetPixel(uint16_t x, uint16_t y)
{
uint16_t RGB;

#if(!_LCD_SWAP_XY)
RGB = RA8875_GetPixel(x, y);
#else
RGB = RA8875_GetPixel(y, x);
#endif
return RGB;
}


/**************************************************************************************
** Function name:       void LCD_DrawLine(uint16_t X1 , uint16_t Y1 , uint16_t X2 , uint16_t Y2 , uint16_t Color)
** Descriptions:        ²ÉÓà Bresenham Ëã·¨£¬ÔÚ2µã¼ä»­Ò»ÌõÖ±Ïß¡£
** input parameters:    X1, Y1 £ºÆðʼµã×ø±ê
**                  X2, Y2 £ºÖÕÖ¹µãY×ø±ê
**                      Color:»­ÏßÑÕÉ«
** output parameters:   ÎÞ
** Returned value:      ÎÞ
***************************************************************************************/
void LCD_DrawLine(uint16_t X1 , uint16_t Y1 , uint16_t X2 , uint16_t Y2 , uint16_t Color)
{
#if(!_LCD_SWAP_XY)
RA8875_DrawLine(X1 , Y1 , X2 , Y2 ,Color);
#else
RA8875_DrawLine(Y1 , X1 , Y2 , X2 , Color);
#endif
}


/**************************************************************************************
** Function name:       void LCD_DrawLineH(uint16_t X1 , uint16_t Y1 , uint16_t X2, uint16_t Color)
** Descriptions:        »æÖÆÒ»ÌõˮƽÏß ÓÃÓÚUCGUIµÄ½Ó¿Úº¯Êý
** input parameters:    X1 £ºÆðʼµãX×ø±ê
**                Y1 £ºË®Æ½ÏßµÄY×ø±ê
**                X2 £º½áÊøµãX×ø±ê
**               Color : ÑÕÉ«                      
** output parameters:   ÎÞ
** Returned value:      ÎÞ
***************************************************************************************/
void LCD_DrawLineH(uint16_t X1 , uint16_t Y1 , uint16_t X2, uint16_t Color)
{
#if(!_LCD_SWAP_XY)
RA8875_DrawHLine(X1, Y1, X2, Color);
#else
 RA8875_DrawVLine(Y1, X1, X2, Color);
#endif
#if(!_LCD_SWAP_XY)
#else
#endif
}




/**************************************************************************************
** Function name:       void LCD_DrawHColorLine(uint16_t X1 , uint16_t Y1, uint16_t Width, uint16_t *pColor)
** Descriptions:        »æÖÆÒ»Ìõ²ÊɫˮƽÏß ÓÃÓÚUCGUIµÄ½Ó¿Úº¯Êý
** input parameters:    X1    £ºÆðʼµãX×ø±ê
**                Y1    £ºË®Æ½ÏßµÄY×ø±ê
**                Width £ºÖ±ÏߵĿí¶È
**                pColor : ÑÕÉ«»º³åÇø                
** output parameters:   ÎÞ
** Returned value:      ÎÞ
***************************************************************************************/
void LCD_DrawHColorLine(uint16_t X1 , uint16_t Y1, uint16_t Width, uint16_t *pColor)
{

//这个函数是重点,emWin 所有的控件(wigt) 最终都是通过该函数画出来的。
#if(!_LCD_SWAP_XY)
 RA8875_DrawHColorLine(X1, Y1, Width, pColor);
#else
RA8875_DrawBMP(Y1, X1, Width,1, pColor);//竖屏时,使用RA8875 的画图函数来实现(一个点一个点的画,那刷新效率不敢直视)
#endif



}


/**************************************************************************************
** Function name:       void LCD_DrawLineV(uint16_t X1 , uint16_t Y1 , uint16_t Y2, uint16_t Color)
** Descriptions:        »æÖÆÒ»Ìõ²ÊÉ«´¹Ö±Ïß ÓÃÓÚUCGUIµÄ½Ó¿Úº¯Êý
** input parameters:    X1    : ´¹Ö±ÏßµÄX×ø±ê
**                Y1    : ÆðʼµãY×ø±ê
**                Y2    : ½áÊøµãY×ø±ê
**                Color : ÑÕÉ«           
** output parameters:   ÎÞ
** Returned value:      ÎÞ
***************************************************************************************/
void LCD_DrawLineV(uint16_t X1 , uint16_t Y1 , uint16_t Y2, uint16_t Color)
{
#if(!_LCD_SWAP_XY)
RA8875_DrawVLine(X1 , Y1 , Y2 , Color);
#else
RA8875_DrawHLine(Y1, X1, Y2, Color); //竖屏时画垂直线实际上时画水平线(从显示屏的角度讲)。
#endif
}




/**************************************************************************************
** Function name:       void LCD_FillRect(uint16_t X, uint16_t Y, uint16_t Height, uint16_t Width, uint16_t Color)
** Descriptions:        »­¾ØÐÎ
** input parameters:    X, Y   £º¾ØÐÎ×óÉϽÇ×ø±ê
**                Height : ¾ØÐÎµÄ¸ß¶È    
**                      Width  £º¾ØÐεĿí¶È
**                   Color  £ºÌî³äÑÕÉ«
** output parameters:   ÎÞ
** Returned value:      ÎÞ
***************************************************************************************/


void LCD_SetTarBlock(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2)
{

//色块填充时用到该函数
#if(!_LCD_SWAP_XY)
BTE_SetTarBlock(X1, Y1, Y2-Y1+1, X2-X1+1, 0);//ÉèÖÃBTEλÖúͿí¶È¸ß¶È
#else
BTE_SetTarBlock(Y1, X1, X2-X1+1, Y2-Y1+1, 0);//ÉèÖÃBTEλÖúͿí¶È¸ß¶È
#endif
}


这个文件完了,我还在 显示屏的驱动文件LCD_RA8875.c 里增加了一个 设置 显示屏扫描方向的函数(RA8875 的 0x40H  寄存器)

/**************************************************************************************
** Function name:       void RA8875_SetXY(uint16_t t)
** Descriptions:        ´¹Ö±·½ÏòºÍˮƽɨÃè·½ÏòÉ趨
** input parameters:    t   : ÉèÖÃ
**              
** output parameters:   ÎÞ
** Returned value:      ÎÞ
***************************************************************************************/


void RA8875_SetXY(uint16_t t)
{
RA8875_WriteReg(0x20, t);   // ´¹Ö±·½ÏòºÍˮƽɨÃè·½ÏòÉ趨

}


接下来就是触摸屏坐标的映射,不同的显示方向。需要映射不同的触摸点 X,Y 的值。否则 触摸就是乱来的。

在触摸屏驱动文件gt9xx.c 中,我将

point_x = ((point_data[5]<<8) | point_data[4]);
point_y = ((point_data[3]<<8) | point_data[2]);

修改为:

#if(!_LCD_SWAP_XY && !LCD_FLIP)
point_x = _LCD_WIDTH - 1 - ((point_data[5]<<8) | point_data[4]);
        point_y = _LCD_HEIGHT - 1 - ((point_data[3]<<8) | point_data[2]);
#elif(_LCD_SWAP_XY && !LCD_FLIP)
point_x =_LCD_WIDTH - 1 - ((point_data[3]<<8) | point_data[2]);
point_y = ((point_data[5]<<8) | point_data[4]);
#elif(!_LCD_SWAP_XY && LCD_FLIP)
point_x = ((point_data[5]<<8) | point_data[4]);
point_y = ((point_data[3]<<8) | point_data[2]);
#elif(_LCD_SWAP_XY && LCD_FLIP)
point_x = ((point_data[3]<<8) | point_data[2]);
point_y =  _LCD_HEIGHT - 1 - ((point_data[5]<<8) | point_data[4]);
#endif


好了,到这里驱动上的修改基本完成。

接下来就是 LCDConf.c 和 LCDConf.H 两个文件。

我在  LCDConf.H 文件中 进行宏定义如下:

#define  ORIENTATION   0   // 屏幕显示方向   取值范围 0 90 180 270

#if  ORIENTATION==0
#define _LCD_SWAP_XY 0
#define LCD_FLIP 0
#elif  ORA==90
#define _LCD_SWAP_XY 0
#define LCD_FLIP 1
#elif  ORA==180
#define _LCD_SWAP_XY 1
#define LCD_FLIP 1
#elif  ORA==270
#define _LCD_SWAP_XY 1
#define LCD_FLIP 0
#endif


#define LCD_HEIGHT 480 //屏幕的高(和显示无关的高度)
#define LCD_WIDTH         800 //屏幕的宽度(和显示无关的宽度)


#if _LCD_SWAP_XY ==0
#define _LCD_HEIGHT  LCD_HEIGHT   //屏幕的高(和显示方向相关)
#define _LCD_WIDTH  LCD_WIDTH  //屏幕的宽(和显示方向相关)
#else
#define _LCD_HEIGHT  LCD_WIDTH  
#define _LCD_WIDTH  LCD_HEIGHT 
#endif

ORIENTATION   宏 即使控制屏幕显示方向的总开关。


在LCDConf.C 中,屏幕(emWin 所感知到的屏幕)的高度和宽度,以及 触摸 的 限值需要根据 宏定义进行调整,

我修改成下面这样。


#define XSIZE_PHYS  _LCD_WIDTH
#define YSIZE_PHYS  _LCD_HEIGHT
#define VXSIZE_PHYS _LCD_WIDTH
#define VYSIZE_PHYS _LCD_HEIGHT


#define GUI_TOUCH_AD_TOP     0  
#define GUI_TOUCH_AD_BOTTOM  _LCD_HEIGHT
#define GUI_TOUCH_AD_LEFT    0   
#define GUI_TOUCH_AD_RIGHT   _LCD_WIDTH


到这里,所有的工作都完成了。

源代码在这里

http://download.csdn.net/detail/godyde/9680713

请使用Keilc MDK打开.
0 0
原创粉丝点击