This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320C6748: TMS320C6748 TFT LCD显示问题

Part Number: TMS320C6748

Hi Ti Team,

我客户在使用TMS320C6748 遇到TFT LCD显示问题如附件.

TFT LCD显示问题描述(Lu).docx

lcd_drv.h

lcd_drv.c
#include <xdc/std.h>
#include <ti/sysbios/knl/Queue.h>
#include <ti/sysbios/knl/Task.h>

#include "hw_types.h"
#include "soc_C6748.h"
#include "hw_psc_C6748.h"
#include "hw_syscfg0_C6748.h"

#include "psc.h"
#include "gpio.h"
#include "spi.h"
#include "lidd.h"
#include "raster.h"

#include "lcd_drv.h"
#include "Drv_SpiFlash.h"

#include "board.h"

#include "DEBUG_config.h"

/************************外部变量******************************/
//无

/************************全局变量******************************/
//无

/************************模块局部变量******************************/
//无

#define GrOffScreen16BPPSize(lWidth, lHeight)            \
        (4 + (16*2) + (lWidth * lHeight * 2))

#pragma DATA_ALIGN(g_pucBuffer0, 4);
unsigned char g_pucBuffer0[GrOffScreen16BPPSize(LCD_WIDTH, LCD_HEIGHT)];

// 图形库显示结构
// tDisplay g_s800x480x16Display;

// 调色板
unsigned short palette_32b[PALETTE_SIZE/2] =
			{0x4000u, 0x0000u, 0x0000u, 0x0000u, 0x0000u, 0x0000u, 0x0000u, 0x0000u,
			 0x0000u, 0x0000u, 0x0000u, 0x0000u, 0x0000u, 0x0000u, 0x0000u, 0x0000u};

// 全局显示上下文
// tContext g_sContext;
/****************************************************************************/
/*                                                                          */
/*              LCD 中断服务函数                                            */
/*                                                                          */
/****************************************************************************/
void LCDIsr(void)
{
    unsigned int  status;

    status = RasterIntStatus(SOC_LCDC_0_REGS,RASTER_END_OF_FRAME0_INT_STAT |
                                             RASTER_END_OF_FRAME1_INT_STAT );

    RasterClearGetIntStatus(SOC_LCDC_0_REGS, status);
}

// 输入频率的单位是MHz
void lcdc_raster_init(unsigned int cpu_freq)
{
    // 禁用光栅
    RasterDisable(SOC_LCDC_0_REGS);
    
    // 时钟配置
    RasterClkConfig(SOC_LCDC_0_REGS,10000000, cpu_freq*1000000/2);

    // 配置 LCD DMA 控制器
    RasterDMAConfig(SOC_LCDC_0_REGS, RASTER_DOUBLE_FRAME_BUFFER,
                    RASTER_BURST_SIZE_16, RASTER_FIFO_THRESHOLD_8,
                    RASTER_BIG_ENDIAN_DISABLE);

    // 模式配置(例如:TFT 或者 STN,彩色或者黑白 等等)
    RasterModeConfig(SOC_LCDC_0_REGS, RASTER_DISPLAY_MODE_TFT,
                     RASTER_PALETTE_DATA, RASTER_COLOR, RASTER_RIGHT_ALIGNED);

    // 帧缓存数据以 LSB 方式排列
    RasterLSBDataOrderSelect(SOC_LCDC_0_REGS);
    
    // 禁用 Nibble 模式
    RasterNibbleModeDisable(SOC_LCDC_0_REGS);
   
    // 配置光栅控制器极性
    RasterTiming2Configure(SOC_LCDC_0_REGS, RASTER_FRAME_CLOCK_LOW |
                                            RASTER_LINE_CLOCK_LOW  |
                                            RASTER_PIXEL_CLOCK_LOW |
                                            RASTER_SYNC_EDGE_RISING|
                                            RASTER_SYNC_CTRL_ACTIVE|
                                            RASTER_AC_BIAS_HIGH     , 0, 255);

	// RasterHparamConfig(baseAddr,     numOfppl, hsw,hfp,hbp);
    RasterHparamConfig(SOC_LCDC_0_REGS, LCD_WIDTH, 10, 4, 10);
	// RasterVparamConfig( baseAddr,    Lpp,       vsw,vfp,vbp);
	RasterVparamConfig(SOC_LCDC_0_REGS, LCD_HEIGHT, 4, 8, 12);

	// 配置 FIFO DMA 延时
	RasterFIFODMADelayConfig(SOC_LCDC_0_REGS, 2);

    unsigned int i = 0, j = 0;
	unsigned char *src, *dest;

  	// 配置基本框架
	RasterDMAFBConfig(SOC_LCDC_0_REGS,
					  (unsigned int)(g_pucBuffer0+PALETTE_OFFSET),
					  (unsigned int)(g_pucBuffer0+PALETTE_OFFSET) + sizeof(g_pucBuffer0) - 2 - PALETTE_OFFSET,
					  0);

	RasterDMAFBConfig(SOC_LCDC_0_REGS,
					  (unsigned int)(g_pucBuffer0+PALETTE_OFFSET),
					  (unsigned int)(g_pucBuffer0+PALETTE_OFFSET) + sizeof(g_pucBuffer0) - 2 - PALETTE_OFFSET,
					  1);

	// 拷贝调色板到离屏显存中
	src = (unsigned char *)palette_32b;
	dest = (unsigned char *)(g_pucBuffer0+PALETTE_OFFSET);
	for( i = 4; i < (PALETTE_SIZE+4); i++)
	{
		*dest++ = *src++;
	}

	// 使能LCD帧结束中断
	RasterEndOfFrameIntEnable(SOC_LCDC_0_REGS);

	// 使能光栅
	RasterEnable(SOC_LCDC_0_REGS);
}

/****************************************************************************/
unsigned int LCDVersionGet(void)
{
    return 1;
}

/**
 * @brief: TFT LCD写一个像素到显存
 * @author: lusd
 * @param [in] x, 横轴坐标, 范围0~479
 * @param [in] y, 纵轴坐标, 范围0~359
 * @param [in] color, RGB565颜色值
 * @return none.
 */
void tft_lcd_draw_pixel(uint16_t x, uint16_t y, uint16_t color)
{
	fb_data_t *fb_dat;

	if ((x < LCD_WIDTH) && (y < LCD_HEIGHT)) {
		fb_dat = (fb_data_t *)(g_pucBuffer0);
		fb_dat->dat[y][x] = color;
	}
}


/**
 * @brief: TFT LCD在显存中画横线
 * @author: lusd
 * @param [in] x, 横轴起始坐标, 范围0~479
 * @param [in] y, 纵轴起始坐标, 范围0~359
 * @param [in] length, 长度, 范围0~479, 超出屏幕部分忽略
 * @param [in] color, RGB565颜色值
 * @return none.
 */
void tft_lcd_draw_xline(uint16_t x, uint16_t y, uint16_t length, uint16_t color)
{
	uint16_t *dest16;
	fb_data_t *fb_dat;

	if ((x < LCD_WIDTH) && (y < LCD_HEIGHT)) {
		fb_dat = (fb_data_t *)(g_pucBuffer0);
		dest16 = &(fb_dat->dat[y][x]);
		if ((x + length) > LCD_WIDTH) {
			length = LCD_WIDTH - x;
		}
		while (length--) {
			*dest16++ = color;
		}		
	}
}

/**
 * @brief: TFT LCD在显存中画竖线
 * @author: lusd
 * @param [in] x, 横轴起始坐标, 范围0~479
 * @param [in] y, 纵轴起始坐标, 范围0~359
 * @param [in] length, 长度, 范围0~359, 超出屏幕部分忽略
 * @param [in] color, RGB565颜色值
 * @return none.
 */
void tft_lcd_draw_yline(uint16_t x, uint16_t y, uint16_t length, uint16_t color)
{
	uint16_t h, y_end;
	fb_data_t *fb_dat;

	if ((x < LCD_WIDTH) && (y < LCD_HEIGHT)) {
		fb_dat = (fb_data_t *)(g_pucBuffer0);
		if ((y + length) > LCD_HEIGHT) {
			length = LCD_HEIGHT - y;
		}
		y_end = y + length;
		for (h=y; h<y_end; h++) {
			fb_dat->dat[h][x] = color;
		}
	}
}

/**
 * @brief: TFT LCD在显存中填充一个矩形区域
 * @author: lusd
 * @param [in] x, 横轴起始坐标, 范围0~479
 * @param [in] y, 纵轴起始坐标, 范围0~359
 * @param [in] width, 宽, 范围0~479, 超出屏幕部分忽略
 * @param [in] height, 高, 范围0~359, 超出屏幕部分忽略
 * @param [in] color, RGB565颜色值
 * @return none.
 */
void tft_lcd_fill_rectangle(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color)
{
	uint16_t w, h, x_end, y_end;
	fb_data_t *fb_dat;

	if ((x < LCD_WIDTH) && (y < LCD_HEIGHT)) {
		fb_dat = (fb_data_t *)(g_pucBuffer0);
		if ((x + width) > LCD_WIDTH) {
			width = LCD_WIDTH - x;
		}
		if ((y + height) > LCD_HEIGHT) {
			height = LCD_HEIGHT - y;
		}
		x_end = x + width;
		y_end = y + height;

		for (h=y; h<y_end; h++) {
			for (w=x; w<x_end; w++) {
				fb_dat->dat[h][w] = color;
			}
		}
	}
}