[其他MCU] 【LPC54100】移植TI的图形库

[复制链接]
 楼主| 小狗爱吃骨头 发表于 2015-12-22 20:33 | 显示全部楼层 |阅读模式
前几天一直了UCGUI的图形库部分,今天又接着把TIgrlib图形库移植到了LPC54102套件中。显示效果还可以。
图形库其实都是都是由底层的画点,画线等这些基本函数组成。大家以前上数学都有学过点成线,线成面这些的,而图形库也是基于此的。
TI的图形库分3层,如下图:
我们只需要修改显示驱动层即可。上面两层都是在调用最低层的驱动层。
显示驱动层函数要我们重写,不是很多,就只有几个函数而已:
分别是:
画点函数:void PixelDraw(void *pvDisplayData, long x, long y, unsigned longcolor)
画多点的函数:void PixelDrawMultiple(void *pvDisplayData,
                                                        longx,
                                                        longy,
                                                        longx0,
                                                        longlCount,
                                                        longBPP,
                                                        constunsigned char  *pucData,
                                                        constunsigned char  *pucPalette)


 楼主| 小狗爱吃骨头 发表于 2015-12-22 20:33 | 显示全部楼层
  1. {        
  2. 画横线的函数:void LineDrawH (void *pvDisplayData,long x1,long x2, long y,unsigned long color);
  3. 画竖线的函数:void LineDrawH (void *pvDisplayData,long x1,long x2, long y,unsigned long color);
  4. 矩形填充函数:void RectFill (void *pvDisplayData, const tRectangle *pRect,unsigned long ulValue);
  5. 以下是我重写的源代码,我用的屏幕是2.4寸的TFT屏,主控是ILI9341,SPI通信的。
  6. 画点函数:
  7. void PixelDraw(void *pvDisplayData, long x,long y, unsigned long color)
  8. {
  9.          TFT_setXY(x,y);
  10.          TFT_sendData16(color);
  11. }
 楼主| 小狗爱吃骨头 发表于 2015-12-22 20:34 | 显示全部楼层
画线横线的函数:
  1. void LineDrawH (void *pvDisplayData,longx1,long x2, long y, unsigned long color)
  2. {
  3.          int32_ti = 0;
  4.          int32_tlength = x2 - x1;
  5.          TFT_setCol(x1,x2);
  6.          TFT_setPage(y,y);
  7.          TFT_sendCMD(0x2c);

  8.          TFT_DC_HIGH;
  9.          //TFT_CS_LOW;

  10.          for(; i < length; i++)
  11.          {
  12.                    SPI_transfer8(color>> 8);
  13.                    SPI_transfer8(color& 0xff);
  14.          }

  15.          //TFT_CS_HIGH;   

  16. }
 楼主| 小狗爱吃骨头 发表于 2015-12-22 20:35 | 显示全部楼层
画竖线的函数:
  1. void LineDrawV (void *pvDisplayData,longx,long y1, long y2, unsigned long color)
  2. {
  3. int32_t i = 0;
  4.          int32_tlength = y2 - y1;
  5.          TFT_setCol(x,x);
  6.          TFT_setPage(y1,y2);
  7.          TFT_sendCMD(0x2c);
  8.          TFT_DC_HIGH;
  9.          //TFT_CS_LOW;


  10.          for(; i < length; i++)
  11.          {
  12.                    SPI_transfer8(color>> 8);
  13.                    SPI_transfer8(color& 0xff);
  14.          }

  15.          //TFT_CS_HIGH;   
  16. }        
 楼主| 小狗爱吃骨头 发表于 2015-12-22 20:35 | 显示全部楼层
填充矩形的函数:
  1. void RectFill (void *pvDisplayData, consttRectangle *pRect, unsigned long ulValue)
  2. {

  3.          uint32_tuY;
  4.          for(uY = pRect->sYMin; uY <= pRect->sYMax; uY++)
  5.          {
  6.                    LineDrawH(0,pRect->sXMin, pRect->sXMax, uY, ulValue);
  7.          }

  8. }
 楼主| 小狗爱吃骨头 发表于 2015-12-22 20:36 | 显示全部楼层
最后的函数有些长的画多点的函数:
  1. void PixelDrawMultiple(void *pvDisplayData,
  2.                                                         longx,
  3.                                                         longy,
  4.                                                         longx0,
  5.                                                         longlCount,
  6.                                                         longBPP,
  7.                                                         constunsigned char  *pucData,
  8.                                                         constunsigned char  *pucPalette)
  9. {        
  10.          uint32_tulPixel = 0;
  11.          uint32_tulColor = 0;
  12.          TFT_setCol(x,DISPLAY_WIDTH);
  13.          TFT_setPage(y,DISPLAY_HEIGHT);
  14.          TFT_sendCMD(0x2c);
 楼主| 小狗爱吃骨头 发表于 2015-12-22 20:36 | 显示全部楼层
  1. if(BPP == 1)
  2.          {
  3.                    //1 bit per pixel in pucData
  4.                    //lX0 is the index of the bit processed within a byte
  5.                    //pucPalette holds the pre-translated 32bit display color
  6.                    while(lCount)
  7.                    {
  8.                             ulPixel= *pucData++;

  9.                             while(lCount && x0 < 8) // whilethere are pixels in this byte
  10.                             {
  11.                                      ulColor= ((uint32_t *) pucPalette)[ulPixel & 1];// retrieve already translatedcolor
  12.                                      TFT_sendData16(ulColor);

  13.                                      lCount--;            // processed another pixel
  14.                                      x0++;                           // done with this bit
  15.                                      ulPixel>>= 1;   // prepare next bit
  16.                             }

  17.                             x0= 0;      // process next byte, reset bitcounter
  18.                    }
  19.          }
 楼主| 小狗爱吃骨头 发表于 2015-12-22 20:37 | 显示全部楼层
  1. elseif (BPP == 4)
  2.          {
  3.                    //4 bits per pixel in pucData
  4.                    //lX0 holds 0/1 to indicate 4-bit nibble within byte
  5.                    //pucPalette holds untranslated 24 bit color
  6.                    while(lCount)
  7.                    {
  8.                             if(x0 == 0)         // read first nibble
  9.                             {
  10.                                      ulPixel= *pucData >> 4;
  11.                                      x0= 1;      // set index to second nibble
  12.                             }
  13.                             else
  14.                             {                                    // readsecond nibble
  15.                                      ulPixel= *pucData & 0x0f;
  16.                                      pucData++;//increase byte pointer as we're done reading this byte
  17.                                      x0= 0;      // set index to first nibble
  18.                             }

  19.                             ulColor= *(uint32_t *) (pucPalette + (ulPixel * 3)) & 0x00ffffff;// retrieve 24bit color
  20.                             TFT_sendData16(COLOR24TO16BIT(ulColor));//translate and write to display

  21.                             lCount--;  // processed another pixel
  22.                    }
  23.          }
 楼主| 小狗爱吃骨头 发表于 2015-12-22 20:38 | 显示全部楼层
  1. elseif (BPP == 8)
  2.          {
  3.                    //8 bits per pixel in pucData
  4.                    //pucPalette holds untranslated 24 bit color
  5.                    while(lCount)
  6.                    {
  7.                             ulPixel= *pucData++;               // read pixel
  8.                             ulColor= *(uint32_t *) (pucPalette + (ulPixel * 3)) & 0x00ffffff;// retrieve 24bit color
  9.                             TFT_sendData16(COLOR24TO16BIT(ulColor));//translate and write to display
  10.                             lCount--;  // processed another pixel
  11.                    }
  12.          }
 楼主| 小狗爱吃骨头 发表于 2015-12-22 20:38 | 显示全部楼层
  1. elseif (BPP == 16)
  2.          {
  3.                    //16 bits per pixel
  4.                    //Pixel is in 16bit color, 5R 6G 5B format
  5.                    //No color translation needed for this display
  6.                    while(lCount)
  7.                    {
  8.                             ulPixel= *((uint16_t *) pucData);
  9.                             TFT_sendData16(ulPixel);
  10.                             pucData+= 2;
  11.                             lCount--;
  12.                    }
  13.          }
  14. }
 楼主| 小狗爱吃骨头 发表于 2015-12-22 20:39 | 显示全部楼层
如果你的屏幕是控制芯片是其他的,可以拿厂家提供的底层驱动文件整合到TI的图形库的底层驱动中。
ti的图像库可以支持多种文件格式的输出到屏幕显示,还有画图像的函数。我也是参考坛友的帖子进行操作的。TI的图形库有个工具可以把图像转换成c的代码。只不过只支持pnm后缀的图片格式。我们可以用图像编辑软件转换格式。我使用了GIMP的软件进行转换。
具体在目录是StellarisWare\tools\bin;

首先我们打开GMIP软件,然后可以直接把图片拖到编辑区,然后设置导出的参数,步奏如下:
软件默认转化后的文件放值得位置是在图片所在的目录:
软件默认是第一个选项,但这样生成的图片数据太大,转换软件会爆出:颜色太多的信息而导致转换失败。所以我就选择了网页优化版。

我们启动cmd,把目录切换到我们工具所在的位置,这些windows的命令自行百度去。我这里就不多说了,都是常用的命令。
然后打上pnmtoc -c image.pnm > image.c,image是你图片的文件名,回车后就会生成一个c的文本。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

28

主题

286

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部

28

主题

286

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部