📄 tft_nt3916.c
字号:
/******************************************************************************/
// Description: Set LCD invalidate direction
// Input:
// is_invert: 0, horizontal; 1, vertical
// Return:
// None.
// Note: Application should correct invalidate direction right after current
// image displayed
/******************************************************************************/
ERR_LCD_E NT3916_SetDirection(
uint8 is_invert
)
{
return;
if (is_invert)
{
NT3916_sendcommand1(0x0005,0x1028);
}
else
{
NT3916_sendcommand1(0x0005,0x1030);
}
}
/******************************************************************************/
// Description: Set LCD invalidate direction
// Input:
// is_invert: 0, horizontal; 1, vertical
// Return:
// None.
// Note: Application should correct invalidate direction right after current
// image displayed
/******************************************************************************/
void NT3916_set_invalidate_direction(
uint8 is_invert
)
{
return;
if (is_invert)
{
NT3916_sendcommand1(0x0005,0x1028);
}
else
{
NT3916_sendcommand1(0x0005,0x1030);
}
}
/******************************************************************************/
// Description: Copy a retangle data from clcd_buffer to display RAM.
// then the rectangle display is to be refreshed
// Global resource dependence:
// Author: Jim.zhang
// Note:
// To improve speed, lcd is operate in HIGH SPEED RAM WRITE MODE(4
// uint16 are write continuously always.) So, some dummy uint16
// should be inserted to satisfy this mode. Please refer to spec.
/******************************************************************************/
LOCAL ERR_LCD_E NT3916_InvalidateRect(
uint16 left, //the left value of the rectangel
uint16 top, //top of the rectangle
uint16 right, //right of the rectangle
uint16 bottom //bottom of the rectangle
)
{
uint16 *buf_ptr = (uint16 *)LCD_GetLCDBuffer();
uint32 pPixel = 0;
uint32 width = 0;
uint32 height = 0;
if (LCD_GetRefreshFlag() != TRUE )
{
return ERR_LCD_OPERATE_FAIL ;
}
left = (left >= NT3916_WIDTH) ? NT3916_WIDTH-1 : left;
right = (right >= NT3916_WIDTH) ? NT3916_WIDTH-1 : right;
top = (top >= NT3916_HEIGHT) ? NT3916_HEIGHT-1 : top;
bottom = (bottom >= NT3916_HEIGHT) ? NT3916_HEIGHT-1 : bottom;
if ( ( right < left ) || ( bottom < top ) )
{
return ERR_LCD_PARAMETER_WRONG;
}
NT3916_set_display_window(left, right, top, bottom);
NT3916_set_start_address(left, top);
NT3916_SEND_COMMAND(0x36); // send data.
if((left == 0) && (right == NT3916_WIDTH-1))
{
buf_ptr += top * NT3916_WIDTH; //pointer buffer start address
pPixel = (NT3916_WIDTH) * (bottom - top + 1);
NT3916_SEND_LINE_DATA(buf_ptr, pPixel);
}
else
{
buf_ptr = buf_ptr + top * NT3916_WIDTH + left; //pointer buffer start address
width = right - (left - 1); //calculate width
height = bottom - (top - 1); //calculate height
do
{
pPixel = width;
NT3916_SEND_LINE_DATA(buf_ptr, pPixel);
buf_ptr += NT3916_WIDTH - width; //buffer point to next line
height--; //next line
}while(height > 0);
}
return ERR_LCD_NONE;
}
/******************************************************************************/
// Description: Copy a retangle data from external buffer to display RAM.
// then the rectangle display is to be refreshed
// Global resource dependence:
// Author: Jim.zhang
// Note:
/******************************************************************************/
LOCAL ERR_LCD_E NT3916_InvalidateRect_Image(
uint16 left, //the left value of the rectangel
uint16 top, //top of the rectangle
uint16 right, //right of the rectangle
uint16 bottom, //bottom of the rectangle
uint16 *buf_ptr //buffer pointer of the image to display
)
{
uint32 pPixel = 0;
left = (left >= NT3916_WIDTH) ? NT3916_WIDTH-1 : left;
right = (right >= NT3916_WIDTH) ? NT3916_WIDTH-1 : right;
top = (top >= NT3916_HEIGHT) ? NT3916_HEIGHT-1 : top;
bottom = (bottom >= NT3916_HEIGHT) ? NT3916_HEIGHT-1 : bottom;
if ( ( right < left ) || ( bottom < top ) )
{
return ERR_LCD_PARAMETER_WRONG;
}
NT3916_set_display_window(left, right, top, bottom);
NT3916_set_start_address(right, top);
NT3916_SEND_COMMAND(0x022); // send data.
// write rect image to LCD RAM
pPixel = (bottom-top+1)*(right-left+1);
NT3916_SEND_LINE_DATA(buf_ptr, pPixel);
return ERR_LCD_NONE;
}
static LCD_SPEC_T g_NT3916_spec =
{
// LCM_CYCLE_U start(ns)
10, // CS setup time for LCM read (optional)
150, // low pulse width for LCM read (according spec)
100, // high pulse width for LCM read (according spec)
30, // CS setup time for LCM write (optional)
50, // low pulse width for LCM write (according spec)
70, // high pulse width for LCM write (according spec)
// LCM_CYCLE_U end(ns)
16, // RGB mode support 18: 18bit LCD(666) 16: 16bit LCD(666) 9: 9bit LCD 8: 8bit LCD
0, // interface mode 0: 8080 1: 6800
0, // lcd id:0 main,1 sub
0, // cs index
0, // cd index
1, // reset ms(according spec)
0, // reset level 0:low-level 1:high-level (according spec)
0, // cmd_data_level: 0 c_0_d_1, 1 c_1_d_0
};
/******************************************************************************/
// Description: get the important parameter for digital camera
// Global resource dependence:
// Author: Zhemin.lin
// Note:
/******************************************************************************/
LOCAL ERR_LCD_E NT3916_GetLcdSpec(
LCD_SPEC_T *spec_ptr //spec struct pointer
)
{
if (spec_ptr == PNULL)
{
return 1;
}
memcpy(spec_ptr, &g_NT3916_spec, sizeof(LCD_SPEC_T));
return ERR_LCD_NONE;
}
/******************************************************************************/
// Description: Enter/Exit sleep mode .
// Global resource dependence:
// Author: Jim.zhang
// Note:
/******************************************************************************/
LOCAL ERR_LCD_E NT3916_EnterSleep(
BOOLEAN is_sleep //SCI_TRUE: exter sleep mode;SCI_FALSE:exit sleep mode.
)
{
SCI_TRACE_LOW("NT3916_EnterSleep,%d", is_sleep);
return;
if ( is_sleep ) // enter sleep mode.
{
//Display off
NT3916_sendcommand1(0x000b, 0x0004);
NT3916_sendcommand1(0x0007, 0x0136); //D1-D0=0b10
LCD_Wait(50);
NT3916_sendcommand1(0x0007, 0x0126); //DTE=0 D1-D0=0b10
LCD_Wait(50);
NT3916_sendcommand1(0x0007, 0x0104); //GON=0 PTE=0 D1-D0=0b10
LCD_Wait(100);
NT3916_sendcommand1(0x0003,0x0660); //006c //BT2-0=0b110
NT3916_sendcommand1(0x000d,0x0000);//404 //PON=0 //JUNYI
NT3916_sendcommand1(0x000E,0x0000);//101A //VCOMG=0 //JUNYI
LCD_Wait(40);
// NT3916_sendcommand1(0x0003,0x000C); //BT2-0=0b000
// NT3916_sendcommand1(0x0003,0x0000); //AP2-0=0b000
NT3916_sendcommand1(0x0004,0x0461); //ADD BY JUNYI
LCD_Wait(40);
NT3916_sendcommand1(0x0003,0x0661);//02 //SLP=1 STB=1
LCD_Wait(40);
}
else // out sleep mode
{
#if 0
NT3916_sendcommand1(0x0003,0x0000); //SLP=0 STB=0
LCD_Wait(40);
NT3916_sendcommand1(0x0004,0x8000); //ADD BY JUNYI
LCD_Wait(40);
NT3916_sendcommand1(0x0003,0x000C); //AP2-0 DC2-0 BT2-0 Recovery
LCD_Wait(40);
NT3916_sendcommand1(0x000E,0x301A); //VCOMG=1
LCD_Wait(40);
NT3916_sendcommand1(0x000D,0x0414); //PON=1
LCD_Wait(40);
//Dispaly on
NT3916_sendcommand1(0x0007,0x0105);
LCD_Wait(30);
NT3916_sendcommand1(0x0007,0x0125);
LCD_Wait(30);
NT3916_sendcommand1(0x0007,0x0127);
LCD_Wait(30);
NT3916_sendcommand1(0x0007,0x0137);
#else
NT3916_reset();
#endif
NT3916_Invalidate();
}
return ERR_LCD_NONE;
}
/*****************************************************************************/
// Description: Enable lcd to partial display mode, so can save power.
// Global resource dependence:
// Author: Jim.zhang
// Return: SCI_TRUE:SUCCESS ,SCI_FALSE:failed.
// Note: If all input parameters are 0, exit partial display mode.
/*****************************************************************************/
LOCAL ERR_LCD_E NT3916_SetDisplayWindow(
uint16 left, //left of the window
uint16 top, //top of the window
uint16 right, //right of the window
uint16 bottom //bottom of the window
)
{
//@Zhemin.Lin CR25198, implementation
if (LCD_GetRefreshFlag() != TRUE )
{
return ERR_LCD_OPERATE_FAIL ;
}
SCI_TRACE_LOW("NT3916_SetDisplayWindow:%d,%d,%d,%d",left,top,right,bottom);
left = (left >= NT3916_WIDTH) ? NT3916_WIDTH-1 : left;
right = (right >= NT3916_WIDTH) ? NT3916_WIDTH-1 : right;
top = (top >= NT3916_HEIGHT) ? NT3916_HEIGHT-1 : top;
bottom = (bottom >= NT3916_HEIGHT) ? NT3916_HEIGHT-1 : bottom;
if ( ( right < left ) || ( bottom < top ) )
{
SCI_TRACE_LOW(" NT3916_SetDisplayWindow wrong: right > left or bottom > top");
return ERR_LCD_PARAMETER_WRONG;
}
NT3916_set_display_window(left, right, top, bottom);
NT3916_set_start_address(left, top);
NT3916_SEND_COMMAND(0x36); // send data.
return ERR_LCD_NONE;
}
/*****************************************************************************/
// Description: set start address of lcd
// Global resource dependence:
// Author: Younger.Yang
// Note:
/*****************************************************************************/
LOCAL ERR_LCD_E NT3916_SetStartAddress(
uint16 left, //left of the window
uint16 top //top of the window
)
{
if (LCD_GetRefreshFlag() != TRUE )
{
return ERR_LCD_OPERATE_FAIL ;
}
SCI_TRACE_LOW("NT3916_SetStartAddress:%d,%d",left,top);
left = (left >= NT3916_WIDTH) ? NT3916_WIDTH-1 : left;
top = (top >= NT3916_HEIGHT) ? NT3916_HEIGHT-1 : top;
NT3916_set_start_address(left, top);
NT3916_SEND_COMMAND(0x36); // send data.
return ERR_LCD_NONE;
}
/*********************************************************************/
// Description: Initialize color LCD : HD66773
// Input:
// None.
// Return:
// None.
// Note:
/*********************************************************************/
LOCAL ERR_LCD_E NT3916_Init(void)
{
NT3916_reset();
NT3916_Clear( 0xf25f );
return ERR_LCD_NONE;
}
/******************************************************************************/
// Description: set the contrast value
// Global resource dependence:
// Author: Jim.zhang
// Note:
/******************************************************************************/
LOCAL ERR_LCD_E NT3916_SetContrast(
uint16 contrast //contrast value to set
)
{
return ERR_LCD_FUNC_NOT_SUPPORT;
}
/*****************************************************************************/
// Description: Set the brightness of LCD.
// Global resource dependence:
// Author: Jim.zhang
// Note:
/*****************************************************************************/
LOCAL ERR_LCD_E NT3916_SetBrightness(
uint16 brightness //birghtness to set
)
{
return ERR_LCD_FUNC_NOT_SUPPORT;
}
/******************************************************************************/
// Description: Close the lcd.(include sub lcd.)
// Global resource dependence:
// Author: Jim.zhang
// Note:
/******************************************************************************/
LOCAL void NT3916_Close(void)
{
GPIO_SetLcdBackLight( SCI_FALSE );
NT3916_EnterSleep( SCI_TRUE );
}
LOCAL LCD_OPERATIONS_T NT3916_operations =
{
NT3916_Init,
NT3916_EnterSleep,
NT3916_SetContrast,
NT3916_SetBrightness,
NT3916_SetDisplayWindow,
NT3916_SetStartAddress,
NT3916_GetInfo,
NT3916_InvalidateRect,
NT3916_InvalidateRect_Image,
NT3916_Invalidate,
NT3916_SetDirection,
NT3916_Clear,
NT3916_Close,
NT3916_GetLcdSpec
};
/******************************************************************************/
// Description: return the HD66773 lcd driver funtion pointer
// Global resource dependence:
// Author: Jim.zhang
// Note:
/******************************************************************************/
PUBLIC LCD_OPERATIONS_T* NT3916_GetOperations()
{
return &NT3916_operations;
}
PUBLIC BOOLEAN NT3916_Probe(void)
{
return SCI_TRUE;
}
/**---------------------------------------------------------------------------*
** Compiler Flag *
**---------------------------------------------------------------------------*/
#ifdef __cplusplus
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -