ucGUI-nios-ii 移植笔记 华中农业大学工学院 潘军璋 一、SOPC Builder 硬件配置 由于我要用到 uc/OS,故而硬件上要求有定时器,ucGUI 还是相对比加大的,内 存用的是 4M 的 SDRAM,Flash 也为 4M。时钟 100MHz。 二、NIOS ii IDE 工程 由于前期移植 ucGUI,对 ucGUI 的特性不是很了解,要改一些底层。都是直接在 建立的 Nios II Application and BSP from Template 工程中直接包含 ucGUI 的库文件,由于文件太多,编译特别的慢。下面简要的把步骤列出来。 /* ********************************************************************* ************************************ * uC/GUI * Universal graphic software for embedded applications * * (c) Copyright 2002, Micrium Inc., Weston, FL * (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH * * 礐/GUI 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 a license and should not be redistributed * in any way. We appreciate your understanding and fairness. * --------------------------------------------------------------------File Purpose : GUI_TOUCH_X.C : Config / System dependent externals for GUI ---------------------------END-OF-HEADER----------------------------*/ #include "GUI.h" #include "GUI_X.h" /**********************************include*************************** **************************/ //******************************************************************* ***********/ #include"system.h" #include"string.h" #include "alt_types.h" #include "altera_avalon_pio_regs.h" //******************************************************************* *******************/ /******************************************************************** ******** * ADS7843触屏控制器 SPI模式 ********************************************************************* ******/ // A/D 通道选择命令字和工作寄存器 #define CHX 0x90 //通道Y+的选择控制字 //0x94 #define CHY 0xd0 //通道X+的选择控制字 //0xD4 //******************************************************************* ********* #define SPI_MOSI( onebit ) IOWR_ALTERA_AVALON_PIO_DATA( MOSI_BASE ,onebit #define SPI_MISO ) IORD_ALTERA_AVALON_PIO_DATA( MISO_BASE ) #define SPI_SCLK( onebit ) IOWR_ALTERA_AVALON_PIO_DATA( SCLK_BASE ,onebit #define SPI_CS( onebit ) IOWR_ALTERA_AVALON_PIO_DATA( TP_CS_BASE,onebit #define TP_IRQ ) ) IORD_ALTERA_AVALON_PIO_DATA( TP_INT_BASE ) /******************************************************************** ************* * ADS7843 SPI初始化 ********************************************************************* ************/ void ADS7843_SPI_Start( void ) { SPI_SCLK(0); SPI_CS(1); SPI_MOSI(1); SPI_SCLK(1); SPI_CS(0); //芯片允许 } /******************************************************************** ************* * ADS7843 写命令 ********************************************************************* ***********/ void ADS7843_WrCmd(unsigned char cmd) { unsigned char buf, i, j ; SPI_SCLK(0); for( i = 0; i < 8; i++ ) { buf = (cmd >> (7-i)) & 0x1 ; //MSB在前,LSB在后 SPI_MOSI(buf); //时钟上升沿锁存DIN for( j = 0; j < 50; j++ ); //200ns SPI_SCLK(0); //开始发送命令字 for( j = 0; j < 50; j++ ); SPI_SCLK(1); //时钟脉冲,一共8个 for( j = 0; j < 50; j++ ); SPI_SCLK(0); //200ns //200ns //时钟脉冲,一共8个 } } /******************************************************************** *************** * ADS7843 读数据 ********************************************************************* *************/ unsigned int ADS7843_Read(void) { unsigned int buf ; unsigned char i, j ; buf=0; for( i = 0; i < 12; i++ ) { buf = buf << 1 ; SPI_SCLK(1); for( j = 0; j < 50; j++ ); //200ns SPI_SCLK(0); for( j = 0; j < 50; j++ ); //时钟下降沿读取,一共12个,MSB在前,LSB 在后 if ( SPI_MISO ) { buf = buf + 1 ; } for( j = 0; j < 50; j++ ); //200ns } return( buf ) ; } /******************************************************************** ******* * ADS7843初始化 ********************************************************************* ******/ int ADS7843_Init(void) { //SPI_CS -> Output //SPI_SCK -> Output //SPI_MOSI -> Output //SPI_MISO -> Input //IRQ Input -> unsigned char j;// ADS7843_SPI_Start(); ADS7843_WrCmd( CHX ) ; for( j = 0; j < 100; j++ ); //200ns ADS7843_Read() ; ADS7843_WrCmd( CHY ) ; for( j = 0; j < 100; j++ ); ADS7843_Read() ; //200ns return 1; } /******************************************************************** ***************** * ADS7843 读取位置(x,y) ********************************************************************* ****************/ int ADS7843_Rd_Addata(int *X_Addata,int *Y_Addata) { unsigned int i,j, x_addata,y_addata; ADS7843_SPI_Start() ; for( j = 0; j < 10; j++ ); //40ns //while ( TP_BUSY ) ; //如果BUSY,等待直到转换完毕,这个可 以不用 x_addata=0; y_addata=0; for(i=8;i>0;i--) { //采样8次. ADS7843_WrCmd( CHX ) ; for( j = 0; j < 50; j++ ); //200ns y_addata += ADS7843_Read() ; for( j = 0; j < 50; j++ ); //200ns ADS7843_WrCmd( CHY ) ; for( j = 0; j < 50; j++ ); //200ns x_addata += ADS7843_Read() ; for( j = 0; j < 50; j++ ); //200ns } x_addata>>=3; y_addata>>=3; //右移3位 等同于除以8 //AVG. *X_Addata=x_addata; *Y_Addata=y_addata; return 1; } /******************************************************************** ******* * TP_INT 下跳沿为检测到有触屏动作 ********************************************************************* ******/ int ADS7843_IsDown(void) { if(!TP_IRQ) { return 1; } else { return 0; } } /*************************************************************** * ucGUI 触屏相关函数 ************************************************************** */ void GUI_TOUCH_X_ActivateX(void) { } void GUI_TOUCH_X_ActivateY(void) { } /******************************************************************** ** * 测量X轴的ADC值 ********************************************************************* / int GUI_TOUCH_X_MeasureX(void) { unsigned int i,j, x_addata; x_addata=0; ADS7843_SPI_Start() ; for( j = 0; j < 10; j++ ); for(i=8;i>0;i--) { //40ns //采样8次. ADS7843_WrCmd( CHX ) ; for( j = 0; j < 50; j++ ); //200ns x_addata += ADS7843_Read() ; for( j = 0; j < 50; j++ ); } //200ns x_addata>>=3; //右移3位 等同于除以8 return x_addata ; } /******************************************************************** * 测量Y轴的ADC值 ********************************************************************* / int GUI_TOUCH_X_MeasureY(void) { unsigned int i,j, y_addata; y_addata=0; ADS7843_SPI_Start() ; for( j = 0; j < 10; j++ ); //40ns for(i=8;i>0;i--) { //采样8次. ADS7843_WrCmd( CHY ) ; for( j = 0; j < 50; j++ ); //200ns y_addata += ADS7843_Read() ; for( j = 0; j < 50; j++ ); //200ns } y_addata>>=3; //右移3位 return y_addata ; } 等同于除以8 /* ********************************************************************* ************************************ 礐/GUI Universal graphic software for embedded * * applications * * (c) Copyright 2002, Micrium Inc., Weston, FL * (c) Copyright 2000, SEGGER Microcontroller Systeme GmbH * * 礐/GUI 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 a license and should not be redistributed * in any way. We appreciate your understanding and fairness. * * File * Purpose : LCD_X_8080.c : Port routines * * Hardware configuration * Needs to be adopted to your target hardware. ********************************************************************* ************************************ */ /* ********************************************************************* * --------------------------------------------------------------------File : LCDConf.h Purpose Data : SSD1289 LCD控制器的头文件,以8080并行连接方式 : 2010-1-7 21:21 --------------------------------------------------------------------********************************************************************* * */ #include <stddef.h> #include "LCD_Private.H" #include "GUI_Private.H" /* needed for definition of NULL */ /* private modul definitions & config */ #include "GUIDebug.h" #include "LCDConf.h" //#include "LCD_0.h" /* Defines for first display */ /**********************************include*************************** **************************/ //******************************************************************* ***********/ #include"system.h" #include"string.h" #include "alt_types.h" #include "altera_avalon_pio_regs.h" #if (LCD_CONTROLLER == 1289 ) \ && (!defined(WIN32) | defined(LCD_SIMCONTROLLER)) /***************************************The start *******************************************/ //LCD数据读写端口定义 //与硬件相关(都为模拟时序) // FPGA平台 //*********************************PIO define**************************************************** static volatile alt_u16 DQ_DIR =0 ;// IORD_ALTERA_AVALON_PIO_DIRECTION( RGB_DQ16_BASE ) ; #define DAT16_DIR_OUT IOWR_ALTERA_AVALON_PIO_DIRECTION(RGB_DQ16_BASE,DQ_DIR = 0xffff) //端口 数据方向 --定义为输出 #define DAT16_DIR_IN IOWR_ALTERA_AVALON_PIO_DIRECTION(RGB_DQ16_BASE,DQ_DIR = 0x0000 ) 口数据方向 --定义为输入 #define DAT16_WRITE(data16) IOWR_ALTERA_AVALON_PIO_DATA(RGB_DQ16_BASE,data16); #define DAT16_READ IORD_ALTERA_AVALON_PIO_DATA(RGB_DQ16_BASE) #define CS 0x01 // BIT0 #define RS 0x02 // BIT1 #define WR 0x04 // BIT2 #define RD 0x08 // BIT3 #define RESET 1//BIT4 #define EN 1//BIT5 // static volatile alt_u8 #define CONTROL4 = 0 ; CS_SET IOWR_ALTERA_AVALON_PIO_DATA(CONTROL4_BASE,CONTROL4=CONTROL4|CS) //端 #define RS_SET IOWR_ALTERA_AVALON_PIO_DATA(CONTROL4_BASE,CONTROL4=CONTROL4|RS) #define WR_SET IOWR_ALTERA_AVALON_PIO_DATA(CONTROL4_BASE,CONTROL4=CONTROL4|WR) #define RD_SET IOWR_ALTERA_AVALON_PIO_DATA(CONTROL4_BASE,CONTROL4=CONTROL4|RD) #define CS_RSET IOWR_ALTERA_AVALON_PIO_DATA(CONTROL4_BASE,CONTROL4=CONTROL4&(~CS)) #define RS_RSET IOWR_ALTERA_AVALON_PIO_DATA(CONTROL4_BASE,CONTROL4=CONTROL4&(~RS)) #define WR_RSET IOWR_ALTERA_AVALON_PIO_DATA(CONTROL4_BASE,CONTROL4=CONTROL4&(~WR)) #define RD_RSET IOWR_ALTERA_AVALON_PIO_DATA(CONTROL4_BASE,CONTROL4=CONTROL4&(~RD)) #define LCD_RESET_H IOWR_ALTERA_AVALON_PIO_DATA(LCD_RESET_BASE,1) #define LCD_RESET_L IOWR_ALTERA_AVALON_PIO_DATA(LCD_RESET_BASE,0) #define LCD_backlight_on IOWR_ALTERA_AVALON_PIO_DATA( LIGH_EN_BASE,1) #define LCD_backlight_off IOWR_ALTERA_AVALON_PIO_DATA( LIGH_EN_BASE,0) //******************************************************************* ********************/ //底层数据读写时序 /**********************端口相关 *********************************************************/ //端口读取16位数据 //***************************begin*********************************** ****************/ alt_u16 READ_DATA16( ) { if(DQ_DIR != 0x0000) { //DQ_DIR DAT16_DIR_IN ; //端口数据方向 == 0x0000 时为输入状态 --定义为输入 } return DAT16_READ ; } /******************************************************************** ***********/ //端口写16位数据 //******************************************************************* ***********/ void WRITE_DATA16( alt_u16 data16 ) { if(DQ_DIR != 0xffff) //DQ_DIR == 0x0000 时为输入状态 { DAT16_DIR_OUT ; //端口数据方向 --定义为输入 } //IOWR_ALTERA_AVALON_PIO_DIRECTION(RGB_DQ16_BASE,0xffff); //端口数 据方向 --定义为输出 //IOWR_ALTERA_AVALON_PIO_DATA(RGB_DQ16_BASE,data16); //写16位 数据 DAT16_WRITE(data16); } #define COLOR LCD_COLORINDEX #define LCD_DELAY(ms) ; //OSTimeDlyHMSM(0, 0, 0, ms)//GUI_Delay(ms) //向LCD写数据 //********************************begin****************************** *******************/ void wr_dat (unsigned int c) { CS_SET; RD_SET; RS_SET; WR_SET; WRITE_DATA16( c); CS_RSET; WR_RSET; } /******************************************************************** *********** * * 向LCD 写命令 * Parameter: c: command to be written * * Return: * ********************************************************************* **********/ void wr_cmd (unsigned { CS_SET; RD_SET; WR_SET; RS_RSET; int c) WRITE_DATA16( c); CS_RSET; WR_RSET; CS_SET; } /******************************************************************** *********** * Read data from LCD controller * Parameter: * Return: * * read data * ********************************************************************* **********/ unsigned int rd_dat (void) { unsigned int val = 0; RS_SET; WR_SET; RD_RSET; val = READ_DATA16() ; val = READ_DATA16() ; return val; } /******************************************************************** *********** * Write to LCD register * Parameter: reg: * register to be read * * val: value to write to register * ********************************************************************* **********/ void wr_reg (unsigned { /* RD_SET; WR_SET; CS_SET; RS_RSET; */ wr_cmd(reg); CS_RSET; int reg, unsigned int val) WR_RSET; WR_SET; RS_SET; wr_dat(val); WR_RSET; CS_SET; RD_SET; WR_SET; RS_SET; } /******************************************************************** *********** * Read from LCD register * Parameter: reg: * register to be read * * Return: value read from register * ********************************************************************* **********/ unsigned int rd_reg (unsigned int reg) { CS_RSET; wr_cmd(reg); reg = rd_dat(); CS_SET; return reg; } //*****************************the end***********************************************/ /******************************************************** * * * LCD_L0_SetOrg * * * ********************************************************* Purpose: Sets the original position of the virtual display. Has no function at this point with the PC-driver. */ //int OrgX, OrgY; void LCD_L0_SetOrg(int x, int y) { //OrgX = x; //OrgY = y; wr_reg(0x4E,x); wr_reg(0x4F,y); } /* void LCD_L0_SetOrg(int x, int y) { GUI_USE_PARA(x); GUI_USE_PARA(y); } */ /* ********************************************************* * * * LCD_On * * LCD_Off * * * ********************************************************* */ void LCD_L0_On(void) { LCD_DELAY(100); wr_reg(0x07,0x0233); LCD_DELAY(100); LCD_backlight_on; } void LCD_L0_Off(void) { LCD_DELAY(100); wr_reg(0x07,0x0000);//wr_reg(0x07,0x0173); LCD_DELAY(100); LCD_backlight_off; } /* ********************************************************* * * * * LCD_L0_SetLUTEntry * * ********************************************************* */ void LCD_L0_SetLUTEntry(U8 Pos, LCD_COLOR color) { GUI_USE_PARA(Pos); GUI_USE_PARA(color); } /********************************/ /*液晶屏清屏函数 */ /********************************/ void LCD_Clear(void) { unsigned int num = 240*320; wr_cmd(0x22); while(num) { wr_dat(0); //LCD_Write_Data(0); num--; } //LCD_Write_End(); } /* ********************************************************* * * * LCD_Init_Controler: Init the display * * * ********************************************************* */ void LCD_Init_Controler() { //复位LCD LCD_RESET_L; //delay 100ms LCD_DELAY(100); LCD_RESET_H; //delay 10ms LCD_DELAY(10); wr_reg(0x0000,0x0001); wr_reg(0x0003,0xA8A8); //打开晶振 //0xA8A4 wr_reg(0x000C,0x0000); //power control wr_reg(0x000D,0x080C); //power control wr_reg(0x000E,0x2B00); wr_reg(0x001E,0x00B0); wr_reg(0x0001,0x2B3F); wr_reg(0x0002,0x0600); //驱动输出控制320*240 0x6B3F //LCD Driving Waveform control wr_reg(0x0010,0x0000); wr_reg(0x0011,0x6070); 0x6058 //0x4030 //定义数据格式 wr_reg(0x0005,0x0000); wr_reg(0x0006,0x0000); wr_reg(0x0016,0xEF1C); wr_reg(0x0017,0x0003); wr_reg(0x0007,0x0233); //0x0233 wr_reg(0x000B,0x0000); wr_reg(0x000F,0x0000); wr_reg(0x0041,0x0000); wr_reg(0x0042,0x0000); wr_reg(0x0048,0x0000); wr_reg(0x0049,0x013F); wr_reg(0x004A,0x0000); wr_reg(0x004B,0x0000); wr_reg(0x0044,0xEF00); wr_reg(0x0045,0x0000); wr_reg(0x0046,0x013F); wr_reg(0x0030,0x0707); wr_reg(0x0031,0x0204); wr_reg(0x0032,0x0204); wr_reg(0x0033,0x0502); wr_reg(0x0034,0x0507); wr_reg(0x0035,0x0204); wr_reg(0x0036,0x0204); wr_reg(0x0037,0x0502); wr_reg(0x003A,0x0302); wr_reg(0x003B,0x0302); wr_reg(0x0023,0x0000); wr_reg(0x0024,0x0000); wr_reg(0x0025,0xE000); //LCD_On(); // //LCD_Clear();// //扫描开始地址 16位色 横屏 } /* ********************************************************* * * * LCD_L0_ReInit : Re-Init the display * * * ********************************************************* ReInit contains all of the code that can be re-executed at any point without changing or even disturbing what can be seen on the LCD. Note that it is also used as a subroutine by LCD_Init(). */ void LCD_L0_ReInit(void) { LCD_Init_Controler(); /* macro defined in config */ } /* ********************************************************* * * * LCD_Init : Init the display * * * ********************************************************* */ int LCD_L0_Init(void) { GUI_DEBUG_LOG("\nLCD_Init()"); /* Init controllers (except lookup table) */ // LCD_L0_ReInit(); LCD_Init_Controler(); LCD_On(); return 0; /* Init successfull ! */ } /* ********************************************************* * * * LCD_L0_CheckInit * * * * Check if display controller(s) is/are still * properly initialized * * * * ********************************************************* Return value: 0 => No error, init is O.K. */ int LCD_L0_CheckInit(void) { return 0; } /* ********************************************************* * * * Internal set pixel routines * * * ********************************************************* */ static void SetPixel(int x, int y, LCD_PIXELINDEX c) { wr_reg(0x4E,x); wr_reg(0x4F,y); wr_reg(0x22,c); } void LCD_L0_SetPixelIndex(int x, int y, int ColorIndex) { SetPixel(x, y, ColorIndex); } static U32 GetPixelIndex(int x, int y) { LCD_PIXELINDEX col; wr_reg(0x4E,x); wr_reg(0x4F,y); col = rd_reg(0x22); return col; } unsigned int LCD_L0_GetPixelIndex(int x, int y) { return GetPixelIndex(x,y); } /* * ****************************************************** */ /* ********************************************************* * * * LCD_L0_XorPixel * * * ********************************************************* Purpose: This routine is called by emWin. It writes 1 pixel into the display. */ static void XorPixel(int x, int y) { LCD_PIXELINDEX Index = GetPixelIndex(x,y); SetPixel(x,y,LCD_NUM_COLORS-1-Index); } void LCD_L0_XorPixel(int x, int y) { XorPixel(x, y); } /* ********************************************************* * * * LCD_L0_DrawHLine optimized * * * * 16 bit bus, Using BITBLT * * * ********************************************************* */ void LCD_L0_DrawHLine (int x0, int y, int x1) { //wr_reg(0x4E,x0); //wr_reg(0x4F,y); LCD_L0_SetOrg(x0 , y);// wr_reg(0x22,c); wr_cmd(0x0022); if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) { while (x0 <= x1) { LCD_L0_XorPixel(x0, y); x0++; } } else { while (x0 <= x1) { //SetPixel(x0, y, COLOR); wr_dat( COLOR); x0++; } } } /* ********************************************************* * * * LCD_L0_DrawVLine optimized * * * * 16 bit bus, using BITBLT * * * ********************************************************* */ void LCD_L0_DrawVLine (int x, int y0, int y1) { if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) { while (y0 <= y1) { LCD_L0_XorPixel(x, y0); y0++; } } else { while (y0 <= y1) { LCD_L0_SetPixelIndex(x, y0, COLOR); y0++; } } } /* ********************************************************* * * * * LCD_FillRect * * ********************************************************* */ void LCD_L0_FillRect(int x0, int y0, int x1, int y1) { #if !LCD_SWAP_XY for (; y0 <= y1; y0++) { LCD_L0_DrawHLine(x0,y0, x1); } #else for (; x0 <= x1; x0++) { LCD_L0_DrawVLine(x0,y0, y1); } #endif } /* ********************************************************** * * * Draw Bitmap 1 BPP * * * ********************************************************** */ static void DrawBitLine1BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) { // LCD_PIXELINDEX aColor[2]; U16 Pixels = ((*p) << 8) | (*(p + 1)); U8 RemPixels; p++; // aColor[0] = *pTrans; // aColor[1] = *(pTrans + 1); x += Diff; RemPixels = 16 - Diff; Pixels <<= Diff; if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) { do { if (RemPixels==0) { Pixels = ((*(p + 1)) << 8) | (*(p + 2)); p += 2; RemPixels = 16; } if (Pixels & 0x8000) { XorPixel(x, y); } RemPixels--; Pixels <<=1; x++; } while (--xsize); } else { do { if (RemPixels==0) { Pixels = ((*(p + 1)) << 8) | (*(p + 2)); p += 2; RemPixels = 16; } if (Pixels & 0x8000) { SetPixel(x, y, *(pTrans+1)); } RemPixels--; Pixels <<=1; x++; } while (--xsize); } } /* ********************************************* * * * Draw Bitmap 2 BPP * * * ********************************************* */ #if (LCD_MAX_LOG_COLORS > 2) static void DrawBitLine2BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) { LCD_PIXELINDEX pixels; /* // Jump to right entry point */ pixels = *p; if (GUI_Context.DrawMode & LCD_DRAWMODE_TRANS) switch (Diff&3) { case 0: goto WriteTBit0; case 1: goto WriteTBit1; case 2: goto WriteTBit2; default: goto WriteTBit3; } else switch (Diff&3) { case 0: goto WriteBit0; case 1: goto WriteBit1; case 2: goto WriteBit2; default: goto WriteBit3; } /* Write without transparency */ WriteBit0: SetPixel(x+0, y, *(pTrans+(pixels>>6))); if (!--xsize) return; WriteBit1: SetPixel(x+1, y, *(pTrans+(3&(pixels>>4)))); if (!--xsize) return; WriteBit2: SetPixel(x+2, y, *(pTrans+(3&(pixels>>2)))); if (!--xsize) return; WriteBit3: SetPixel(x+3, y, *(pTrans+(3&(pixels)))); if (!--xsize) return; pixels = *(++p); x+=4; goto WriteBit0; /* Write with transparency */ WriteTBit0: if (pixels&(3<<6)) SetPixel(x+0, y, *(pTrans+(pixels>>6))); if (!--xsize) return; WriteTBit1: if (pixels&(3<<4)) SetPixel(x+1, y, *(pTrans+(3&(pixels>>4)))); if (!--xsize) return; WriteTBit2: if (pixels&(3<<2)) SetPixel(x+2, y, *(pTrans+(3&(pixels>>2)))); if (!--xsize) return; WriteTBit3: if (pixels&(3<<0)) SetPixel(x+3, y, *(pTrans+(3&(pixels)))); if (!--xsize) return; pixels = *(++p); x+=4; goto WriteTBit0; } #endif /* ********************************************* * * * Draw Bitmap 4 BPP * * * ********************************************* */ #if (LCD_MAX_LOG_COLORS > 4) static void DrawBitLine4BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) { U8 pixels; /* // Jump to right entry point */ pixels = *p; if (GUI_Context.DrawMode & LCD_DRAWMODE_TRANS) { if ((Diff&1) ==0) goto WriteTBit0; goto WriteTBit1; } else { if ((Diff&1) ==0) goto WriteBit0; goto WriteBit1; } /* Write without transparency */ WriteBit0: SetPixel(x+0, y, *(pTrans+(pixels>>4))); if (!--xsize) return; WriteBit1: SetPixel(x+1, y, *(pTrans+(pixels&0xf))); if (!--xsize) return; x+=2; pixels = *(++p); goto WriteBit0; /* Write with transparency */ WriteTBit0: if (pixels>>4) SetPixel(x+0, y, *(pTrans+(pixels>>4))); if (!--xsize) return; WriteTBit1: if (pixels&0xf) SetPixel(x+1, y, *(pTrans+(pixels&0xf))); if (!--xsize) return; x+=2; pixels = *(++p); goto WriteTBit0; } #endif /* ********************************************* * * * Draw Bitmap 8 BPP (256 colors) * * * ********************************************* */ #if (LCD_MAX_LOG_COLORS > 16) static void DrawBitLine8BPP(int x, int y, U8 const*p, int xsize, const LCD_PIXELINDEX*pTrans) { LCD_PIXELINDEX pixel; if ((GUI_Context.DrawMode & LCD_DRAWMODE_TRANS)==0) { if (pTrans) { for (;xsize > 0; xsize--,x++,p++) { pixel = *p; SetPixel(x, y, *(pTrans+pixel)); } } else { for (;xsize > 0; xsize--,x++,p++) { SetPixel(x, y, *p); } } } else/* Handle transparent bitmap */ { if (pTrans) { for (; xsize > 0; xsize--, x++, p++) { pixel = *p; if (pixel) { SetPixel(x+0, y, *(pTrans+pixel)); } } } else { for (; xsize > 0; xsize--, x++, p++) { pixel = *p; if (pixel) { SetPixel(x+0, y, pixel); } } } } } #endif /* ********************************************************* * * * Universal draw Bitmap routine * * * ********************************************************* */ void LCD_L0_DrawBitmap (int x0, int y0, int xsize, int ysize, int BitsPerPixel, int BytesPerLine, const U8* pData, int Diff, const LCD_PIXELINDEX* pTrans) { int i; for (i=0; i<ysize; i++) { switch (BitsPerPixel) { case 1: DrawBitLine1BPP(x0, i+y0, pData, Diff, xsize, pTrans); break; #if (LCD_MAX_LOG_COLORS > 2) case 2: DrawBitLine2BPP(x0, i+y0, pData, Diff, xsize, pTrans); break; #endif #if (LCD_MAX_LOG_COLORS > 4) case 4: DrawBitLine4BPP(x0, i+y0, pData, Diff, xsize, pTrans); break; #endif #if (LCD_MAX_LOG_COLORS > 16) case 8: DrawBitLine8BPP(x0, i+y0, pData, xsize, pTrans); break; #endif } pData += BytesPerLine; } } #else void LCD13XX(void) { } /* avoid empty object files */ #endif /* (LCD_CONTROLLER == 0) */ 以上是在 Nios II Application and BSP from Template 工程中直接编译,会 非常的慢。还有就是我的是 10.0 的版本,文件包含要在这里设置: 下面为了提高工作效率,建了一个 Nios II Library 工程。 在下面这个页面里面设置没有任何的作用,前面的工程也是一样的。 由于修改的 ucGUI 的驱动里面涉及到用到的 GPIO,所以并不是完全不依赖于硬 件的。设置是要注意: 下面的是不用修改就可以的,此处作为对照。 同样的在自己的工程属性里设置: 确保一切正确以后就可以编译了。。。。。。。。。。。。。。。。。。。。。。。。 当然要先编译库工程了,这个通常比较的大,第一次编译会好一点时间,但后面 有改动再次编译就比较的快了,同样自己的工程编译的速度也相当的快了。
© Copyright 2025 Paperzz