打印
[其他MCU]

【LPC54100】移植TI的图形库

[复制链接]
743|10
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
小狗爱吃骨头|  楼主 | 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 | 只看该作者
{        
画横线的函数:void LineDrawH (void *pvDisplayData,long x1,long x2, long y,unsigned long color);
画竖线的函数:void LineDrawH (void *pvDisplayData,long x1,long x2, long y,unsigned long color);
矩形填充函数:void RectFill (void *pvDisplayData, const tRectangle *pRect,unsigned long ulValue);
以下是我重写的源代码,我用的屏幕是2.4寸的TFT屏,主控是ILI9341,SPI通信的。
画点函数:
void PixelDraw(void *pvDisplayData, long x,long y, unsigned long color)
{
         TFT_setXY(x,y);
         TFT_sendData16(color);
}

使用特权

评论回复
板凳
小狗爱吃骨头|  楼主 | 2015-12-22 20:34 | 只看该作者
画线横线的函数:
void LineDrawH (void *pvDisplayData,longx1,long x2, long y, unsigned long color)
{
         int32_ti = 0;
         int32_tlength = x2 - x1;
         TFT_setCol(x1,x2);
         TFT_setPage(y,y);
         TFT_sendCMD(0x2c);

         TFT_DC_HIGH;
         //TFT_CS_LOW;

         for(; i < length; i++)
         {
                   SPI_transfer8(color>> 8);
                   SPI_transfer8(color& 0xff);
         }

         //TFT_CS_HIGH;   

}

使用特权

评论回复
地板
小狗爱吃骨头|  楼主 | 2015-12-22 20:35 | 只看该作者
画竖线的函数:
void LineDrawV (void *pvDisplayData,longx,long y1, long y2, unsigned long color)
{
int32_t i = 0;
         int32_tlength = y2 - y1;
         TFT_setCol(x,x);
         TFT_setPage(y1,y2);
         TFT_sendCMD(0x2c);
         TFT_DC_HIGH;
         //TFT_CS_LOW;


         for(; i < length; i++)
         {
                   SPI_transfer8(color>> 8);
                   SPI_transfer8(color& 0xff);
         }

         //TFT_CS_HIGH;   
}        

使用特权

评论回复
5
小狗爱吃骨头|  楼主 | 2015-12-22 20:35 | 只看该作者
填充矩形的函数:
void RectFill (void *pvDisplayData, consttRectangle *pRect, unsigned long ulValue)
{

         uint32_tuY;
         for(uY = pRect->sYMin; uY <= pRect->sYMax; uY++)
         {
                   LineDrawH(0,pRect->sXMin, pRect->sXMax, uY, ulValue);
         }

}

使用特权

评论回复
6
小狗爱吃骨头|  楼主 | 2015-12-22 20:36 | 只看该作者
最后的函数有些长的画多点的函数:
void PixelDrawMultiple(void *pvDisplayData,
                                                        longx,
                                                        longy,
                                                        longx0,
                                                        longlCount,
                                                        longBPP,
                                                        constunsigned char  *pucData,
                                                        constunsigned char  *pucPalette)
{        
         uint32_tulPixel = 0;
         uint32_tulColor = 0;
         TFT_setCol(x,DISPLAY_WIDTH);
         TFT_setPage(y,DISPLAY_HEIGHT);
         TFT_sendCMD(0x2c);

使用特权

评论回复
7
小狗爱吃骨头|  楼主 | 2015-12-22 20:36 | 只看该作者
 if(BPP == 1)
         {
                   //1 bit per pixel in pucData
                   //lX0 is the index of the bit processed within a byte
                   //pucPalette holds the pre-translated 32bit display color
                   while(lCount)
                   {
                            ulPixel= *pucData++;

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

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

                            x0= 0;      // process next byte, reset bitcounter
                   }
         }

使用特权

评论回复
8
小狗爱吃骨头|  楼主 | 2015-12-22 20:37 | 只看该作者
elseif (BPP == 4)
         {
                   //4 bits per pixel in pucData
                   //lX0 holds 0/1 to indicate 4-bit nibble within byte
                   //pucPalette holds untranslated 24 bit color
                   while(lCount)
                   {
                            if(x0 == 0)         // read first nibble
                            {
                                     ulPixel= *pucData >> 4;
                                     x0= 1;      // set index to second nibble
                            }
                            else
                            {                                    // readsecond nibble
                                     ulPixel= *pucData & 0x0f;
                                     pucData++;//increase byte pointer as we're done reading this byte
                                     x0= 0;      // set index to first nibble
                            }

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

                            lCount--;  // processed another pixel
                   }
         }

使用特权

评论回复
9
小狗爱吃骨头|  楼主 | 2015-12-22 20:38 | 只看该作者
elseif (BPP == 8)
         {
                   //8 bits per pixel in pucData
                   //pucPalette holds untranslated 24 bit color
                   while(lCount)
                   {
                            ulPixel= *pucData++;               // read pixel
                            ulColor= *(uint32_t *) (pucPalette + (ulPixel * 3)) & 0x00ffffff;// retrieve 24bit color
                            TFT_sendData16(COLOR24TO16BIT(ulColor));//translate and write to display
                            lCount--;  // processed another pixel
                   }
         }

使用特权

评论回复
10
小狗爱吃骨头|  楼主 | 2015-12-22 20:38 | 只看该作者
elseif (BPP == 16)
         {
                   //16 bits per pixel
                   //Pixel is in 16bit color, 5R 6G 5B format
                   //No color translation needed for this display
                   while(lCount)
                   {
                            ulPixel= *((uint16_t *) pucData);
                            TFT_sendData16(ulPixel);
                            pucData+= 2;
                            lCount--;
                   }
         }
}

使用特权

评论回复
11
小狗爱吃骨头|  楼主 | 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

粉丝