📄 tft_st7732.c
字号:
ST7732_SEND_COMMAND(0xF6);
ST7732_SEND_DATA(0x4C);
ST7732_SEND_COMMAND( 0x0f8 ); // add 添加指令cmd 0xf8,dat 0x06;关闭自动LOAD功能
ST7732_SEND_DATA( 0x06 ); //IC在SLEEP OUT后,自动LOAD DEFAULT电压参数,造成白屏
ST7732_SEND_COMMAND(0xE0);
ST7732_SEND_DATA(0x04);
ST7732_SEND_DATA(0x05);
ST7732_SEND_DATA(0x14);
ST7732_SEND_DATA(0x16);
ST7732_SEND_DATA(0x13);
ST7732_SEND_DATA(0x11);
ST7732_SEND_DATA(0x05);
ST7732_SEND_DATA(0x03);
ST7732_SEND_DATA(0x05);
ST7732_SEND_DATA(0x06);
ST7732_SEND_DATA(0x0A);
ST7732_SEND_DATA(0x08);
ST7732_SEND_DATA(0x03);
ST7732_SEND_COMMAND(0xE1);
ST7732_SEND_DATA(0x0F);
ST7732_SEND_DATA(0x07);
ST7732_SEND_DATA(0x15);
ST7732_SEND_DATA(0x17);
ST7732_SEND_DATA(0x12);
ST7732_SEND_DATA(0x0F);
ST7732_SEND_DATA(0x03);
ST7732_SEND_DATA(0x00);
ST7732_SEND_DATA(0x01);
ST7732_SEND_DATA(0x01);
ST7732_SEND_DATA(0x0A);
ST7732_SEND_DATA(0x00);
ST7732_SEND_DATA(0x02);
ST7732_SEND_COMMAND( 0x036 ); // add根据客户机型判断
ST7732_SEND_DATA( 0x00 );
ST7732_SEND_COMMAND(0x2A);
ST7732_SEND_DATA(0x00);
ST7732_SEND_DATA(0x00);
ST7732_SEND_DATA(0x00);
ST7732_SEND_DATA(0x7f);
ST7732_SEND_COMMAND(0x2B);
ST7732_SEND_DATA(0x00);
ST7732_SEND_DATA(0x00);
ST7732_SEND_DATA(0x00);
ST7732_SEND_DATA(0x9f);
ST7732_SEND_COMMAND( 0x03a ); // add
ST7732_SEND_DATA( 0x05 );
// ST7732_SEND_COMMAND( 0x035 ); // add
// ST7732_SEND_DATA( 0x00 );
ST7732_SEND_COMMAND( 0x29);
ST7732_SEND_COMMAND( 0x2C);
break;
}
default:
break;
}
}
/******************************************************************************/
// Description: Clear color LCD with one color
// Global resource dependence:
// Author: louis.wei
// Note:
// modify: jim.cui 2005.0728 use dma to transport data
/******************************************************************************/
LOCAL void ST7732_Clear(
uint32 color //color to fill the whole lcd.
)
{
uint32 i;
uint16 *buf_ptr = (uint16 *)LCD_GetLCDBuffer();
uint16 fill_color = color;
ST7732_SEND_DATA(WRITE_GRAM_COMMAND);
#ifndef LCD_USE_DMA // NOTE:ST7732不能使用DMA方式刷屏,否则会有问题
for(i=0; i<(ST7732_HEIGHT ); i++)
{
dma_request(0, (uint32)&fill_color, (uint32)(buf_ptr + i * ST7732_WIDTH), ST7732_WIDTH,
1, 1);
}
#else
for(i=0;i<(ST7732_WIDTH*ST7732_HEIGHT);i++)
*buf_ptr++ = color;
#endif
ST7732_Invalidate();
}
/******************************************************************************/
// Description: Set the windows address to display, in this windows
// color is refreshed.
// Global resource dependence:
// Author: Jim.zhang
// Note:
/******************************************************************************/
__inline void ST7732_set_display_window(
uint8 left, // start Horizon address
uint8 top, // start Vertical address
uint8 right, // end Horizon address
uint8 bottom // end Vertical address
)
{
ST7732_SEND_COMMAND(0x2A);
ST7732_SEND_DATA(0x00);
ST7732_SEND_DATA(left);
ST7732_SEND_DATA(0x00);
ST7732_SEND_DATA(right);
ST7732_SEND_COMMAND(0x2B);
ST7732_SEND_DATA(0x00);
ST7732_SEND_DATA(top);
ST7732_SEND_DATA(0x00);
ST7732_SEND_DATA(bottom);
}
/******************************************************************************/
// Description: Set start RAM address which is write to AC(Address
// Counter) register.
// Input:
// left: start Horizon address of AC
// top: start Vertical address of AC.
// Return:
// None.
// Note:
/******************************************************************************/
__inline void ST7732_set_start_address(
uint8 left,
uint8 top
)
{
//-----不需要设置----------
}
/******************************************************************************/
// Description: invalidate a rectang of in LCD
// Global resource dependence:
// Author: Jim.zhang
// Note:
// modify: jim.cui 2005.0728 use dma to transport data
/******************************************************************************/
LOCAL ERR_LCD_E ST7732_Invalidate(void)
{
uint16 i,j;
uint16 *buf_ptr = (uint16 *)LCD_GetLCDBuffer();
if( LCD_GetRefreshFlag() != TRUE )
{
SCI_TRACE_LOW("LCD_GetReFreshFlag ST7732 Fail");
return ERR_LCD_OPERATE_FAIL;
}
ST7732_set_display_window(0, 0, ST7732_WIDTH-1, ST7732_HEIGHT-1);
ST7732_SEND_COMMAND(WRITE_GRAM_COMMAND);
#ifndef LCD_USE_DMA //不能使用DMA方式刷屏
SCI_TRACE_LOW("tft_ST7732.c ST7732_Invalidate through DMA");
for(j=0; j<(ST7732_HEIGHT ); j++)
{
dma_request(0, (uint32)(buf_ptr + j * ST7732_WIDTH), 0x58020000, ST7732_WIDTH,
1, 0);
}
#else
SCI_TRACE_LOW("tft_ST7732.c ST7732_Invalidate through Line" );
#if 0
for(i=0; i<(ST7732_WIDTH * ST7732_HEIGHT); i++)
{
ST7732_SEND_DATA( *buf_ptr++ );
}
#else
for(i=0 ;i<128;i++)
for(j=0;j<160;j++)
{
ST7732_SEND_DATA(*buf_ptr++);
}
#endif
#endif
return ERR_LCD_NONE;
}
/*****************************************************************************/
// Description: Get the lcd base information..
// Global resource dependence:
// Author: louis.wei
// Note:
/*****************************************************************************/
LOCAL ERR_LCD_E ST7732_GetInfo(
LCD_INFO_T *lcd_info_ptr //lcd information struct pointer
)
{
if ( PNULL == lcd_info_ptr )
{
return ERR_LCD_POINTER_NULL;
}
lcd_info_ptr->r_bitmask = 0xf800;
lcd_info_ptr->g_bitmask = 0x07e0;
lcd_info_ptr->b_bitmask = 0x001f;
lcd_info_ptr->bits_per_pixel = 16;
lcd_info_ptr->contrast_min = 0x00;
lcd_info_ptr->contrast_max = 63;
lcd_info_ptr->contrast_defaut = 0x0A;
lcd_info_ptr->lcd_width = ST7732_WIDTH;
lcd_info_ptr->lcd_height = ST7732_HEIGHT;
lcd_info_ptr->lcdbuff_ptr = (void *)LCD_GetLCDBuffer();
return ERR_LCD_NONE;
}
/******************************************************************************/
// 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.
// modify: jim.cui 2005.0728 use dma to transport data
/******************************************************************************/
LOCAL ERR_LCD_E ST7732_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
)
{
uint32 i, j;
uint32 row, column,rect_width;
uint16 *buf_ptr = (uint16 *)LCD_GetLCDBuffer();
//****************************************************
//**********解决进入摄像模式的问题********************
if (LCD_GetRefreshFlag() != TRUE )
{
SCI_TRACE_LOW(" LCD_GetRefreshFlag Fail");
return ERR_LCD_OPERATE_FAIL ;
}
//*****************************************************
SCI_TRACE_LOW("tft_st7732.c ST7732_InvalidateRect judge Beyond the mark");
left = (left >= ST7732_WIDTH) ? ST7732_WIDTH-1 : left;
right = (right >= ST7732_WIDTH) ? ST7732_WIDTH-1 : right;
top = (top >= ST7732_HEIGHT) ? ST7732_HEIGHT-1 : top;
bottom = (bottom >= ST7732_HEIGHT) ? ST7732_HEIGHT-1 : bottom;
if ( ( right < left ) || ( bottom < top ) )
{
return ERR_LCD_PARAMETER_WRONG;
}
ST7732_set_display_window(left, top, right, bottom);
ST7732_SEND_COMMAND(WRITE_GRAM_COMMAND);
#ifndef LCD_USE_DMA
rect_width = right-left+1;
for (j = top; j <= bottom; j++)
{
dma_request(0, (uint32)(buf_ptr + j * ST7732_WIDTH+left), 0x58020000, rect_width,
1, 0);
}
#else
for (i = top; i <= bottom; i++)
{
for (j = left; j <= right; j++) // real write
ST7732_SEND_DATA( *(buf_ptr + i*ST7732_WIDTH + j) );
}
#endif
return ERR_LCD_NONE;
}
/******************************************************************************/
// Description: for mp4 display
// Global resource dependence:
// Author: juan.zhang
/******************************************************************************/
LOCAL ERR_LCD_E ST7732_InvalidateRectImage(
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,
uint8 is_invert//ignore
)
{
uint32 i, j;
uint32 row, column,rect_width;
SCI_TRACE_LOW("tft_st7732.c ST7732_InvalidateRectImage judge beyond mark");
left = (left >= MP4_MAX_WIDTH) ? MP4_MAX_WIDTH-1 : left;
right = (right >= MP4_MAX_WIDTH) ? MP4_MAX_WIDTH-1 : right;
top = (top >= MP4_MAX_HEIGHT) ? MP4_MAX_HEIGHT-1 : top;
bottom = (bottom >= MP4_MAX_HEIGHT) ? MP4_MAX_HEIGHT-1 : bottom;
left = 0;
right = 127;
top = 0;
bottom = 159;
if ( ( right < left ) || ( bottom < top ) )
{
return ERR_LCD_PARAMETER_WRONG;
}
SCI_TRACE_LOW("tft_ST7732.c ST7732_InvalidateRectImage");
if (is_invert)
{
ST7732_sendcommand1(0x0036,0x0060 );
{
ST7732_SEND_COMMAND(0x2a);
ST7732_SEND_DATA(0x00);
ST7732_SEND_DATA(top);
ST7732_SEND_DATA(0x00);
ST7732_SEND_DATA(bottom);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -