#include "hdw_lcd_st7735s_ips096.h"
#include "main.h"
#define HDW_IPS_RST_Clr() LL_GPIO_ResetOutputPin(HDW_IPS_RST_PORT, HDW_IPS_RST_PIN)
#define HDW_IPS_RST_Set() LL_GPIO_SetOutputPin(HDW_IPS_RST_PORT, HDW_IPS_RST_PIN)
#define HDW_IPS_DC_Clr() LL_GPIO_ResetOutputPin(HDW_IPS_DC_PORT, HDW_IPS_DC_PIN)
#define HDW_IPS_DC_Set() LL_GPIO_SetOutputPin(HDW_IPS_DC_PORT, HDW_IPS_DC_PIN)
#define HDW_IPS_CS_Clr() LL_GPIO_ResetOutputPin(HDW_IPS_CS_PORT, HDW_IPS_CS_PIN)
#define HDW_IPS_CS_Set() LL_GPIO_SetOutputPin(HDW_IPS_CS_PORT, HDW_IPS_CS_PIN)
#define HDW_BLK_Clr() LL_GPIO_ResetOutputPin(HDW_BLK_PORT, HDW_BLK_PIN)
#define HDW_BLK_Set() LL_GPIO_SetOutputPin(HDW_BLK_PORT, HDW_BLK_PIN)
///////////////////////////////////////////////////////////////////////////////
static void _ips_pin_init(void)
{
//TODO:初始化引脚
//CS持续使能
HDW_IPS_CS_Clr();
//复位信号
HDW_IPS_RST_Set();
delay_ms_block(200);
HDW_IPS_RST_Clr();
delay_ms_block(200);
HDW_IPS_RST_Set();
delay_ms_block(200);
}
///////////////////////////////////////////////////////////////////////////////
void _spi_write_command(unsigned char index)
{
HDW_IPS_DC_Clr();
HDW_IPS_CS_Clr();
hdw_spi_transmit_byte(index);
HDW_IPS_CS_Set();
}
void _spi_write_data8(unsigned char dat)
{
HDW_IPS_DC_Set();
HDW_IPS_CS_Clr();
hdw_spi_transmit_byte(dat);
HDW_IPS_CS_Set();
}
void _spi_write_data16(unsigned short dat)
{
HDW_IPS_DC_Set();
HDW_IPS_CS_Clr();
hdw_spi_transmit_byte(dat >> 8);
hdw_spi_transmit_byte(dat);
HDW_IPS_CS_Set();
}
///////////////////////////////////////////////////////////////////////////////
void hdw_lcd_ips096_init(void)
{
_ips_pin_init();
HDW_BLK_Set(); //点亮背光
delay_ms_block(100); //ms
//************* ST7735S初始化**********//
//软件重启
_spi_write_command(ST7735S_SWRESET);
delay_ms_block(100);
//离开睡眠模式
_spi_write_command(ST7735S_SLPOUT);
delay_ms_block(100);
//显示关闭
_spi_write_command(ST7735S_DISPOFF);
delay_ms_block(1);
//设置帧频率 frame frequency normal mode (highest frame rate in normal mode)
//850k/((0*2+40)*(LINE+63+63+2))=850k/(40*(LINE+128))
_spi_write_command(ST7735S_FRMCTR1);
_spi_write_data8(0x00);
_spi_write_data8(0x3c);
_spi_write_data8(0x3c);
delay_ms_block(1);
//设置帧频率 /* frame frequency idle mode */
_spi_write_command(ST7735S_FRMCTR2);
_spi_write_data8(0x0F);
_spi_write_data8(0x01);
_spi_write_data8(0x01);
delay_ms_block(1);
//设置帧频率 /* Frame Rate Control in partial mode) full colors */
_spi_write_command(ST7735S_FRMCTR3);
_spi_write_data8(0x05);
_spi_write_data8(0x3c);
_spi_write_data8(0x3c);
_spi_write_data8(0x05);
_spi_write_data8(0x3c);
_spi_write_data8(0x3c);
delay_ms_block(1);
//设置反白 /* display inversion control: 3-bit 0=dot, 1=col */
_spi_write_command(ST7735S_INVCTR);
_spi_write_data8(0x00);
delay_ms_block(1);
//设置电源 /* power control */
_spi_write_command(ST7735S_PWCTR1);
_spi_write_data8(0xFC);
_spi_write_data8(0x08);
_spi_write_data8(0x02);
_spi_write_command(ST7735S_PWCTR2);
_spi_write_data8(0xc0);
_spi_write_command(ST7735S_PWCTR3);
_spi_write_data8(0x0d);
_spi_write_data8(0x00);
_spi_write_command(ST7735S_PWCTR4);
_spi_write_data8(0x8d);
_spi_write_data8(0x2a);
_spi_write_command(ST7735S_PWCTR5); /* partial */
_spi_write_data8(0x8d);
_spi_write_data8(0xee);
delay_ms_block(1);
//设置明度和gamma值 /* display brightness and gamma */
_spi_write_command(ST7735S_GCV);/* auto gate pump freq, max power save */
_spi_write_data8(0xcc);
_spi_write_command(ST7735S_NVFCTR1);/* automatic adjust gate pumping clock for saving power consumption */
_spi_write_data8(0x40);
_spi_write_command(ST7735S_VMCTR1);/* VCOM voltage setting */
_spi_write_data8(0x0f);
_spi_write_command(ST7735S_VMOFCTR);/* ligthness of black color 0-0x1f */
_spi_write_data8(0x10);
_spi_write_command(ST7735S_GAMSET);/* gamma 1, 2, 4, 8 */
_spi_write_data8(0x01);
delay_ms_block(1);
//显示设置 /* row oder, col order, row colum xchange, vert refr order, rgb/bgr, hor refr order, 0, 0 */
_spi_write_command(ST7735S_MADCTL);
_spi_write_data8(MADCTL(0, 1, 1, 0, 1, 0)); //屏幕正
delay_ms_block(1);
//设置色彩模式
_spi_write_command(ST7735S_COLMOD);
_spi_write_data8(COLOR_MODE_16B);
delay_ms_block(1);
//伽玛(' + '极性)校正特性设置
_spi_write_command(ST7735S_GMCTRP1);
_spi_write_data8(0x02);
_spi_write_data8(0x1c);
_spi_write_data8(0x07);
_spi_write_data8(0x12);
_spi_write_data8(0x37);
_spi_write_data8(0x32);
_spi_write_data8(0x29);
_spi_write_data8(0x2c);
_spi_write_data8(0x29);
_spi_write_data8(0x25);
_spi_write_data8(0x2b);
_spi_write_data8(0x39);
_spi_write_data8(0x00);
_spi_write_data8(0x01);
_spi_write_data8(0x03);
_spi_write_data8(0x10);
delay_ms_block(1);
//伽玛(' - '极性)校正特性设置
_spi_write_command(ST7735S_GMCTRN1);
_spi_write_data8(0x03);
_spi_write_data8(0x1d);
_spi_write_data8(0x07);
_spi_write_data8(0x06);
_spi_write_data8(0x2E);
_spi_write_data8(0x2C);
_spi_write_data8(0x29);
_spi_write_data8(0x2c);
_spi_write_data8(0x2e);
_spi_write_data8(0x2e);
_spi_write_data8(0x37);
_spi_write_data8(0x3f);
_spi_write_data8(0x00);
_spi_write_data8(0x00);
_spi_write_data8(0x02);
_spi_write_data8(0x10);
delay_ms_block(1);
//反白显示 /* display inversion on/off */
_spi_write_command(ST7735S_INVON);
delay_ms_block(1);
//关闭空闲模式 /* idle mode off */
_spi_write_command(ST7735S_IDMOFF);
delay_ms_block(1);
//开启正常显示模式(关闭部分显示) /* normal display mode on */
_spi_write_command(ST7735S_NORON);
delay_ms_block(1);
//显示开启
_spi_write_command(ST7735S_DISPON);
delay_ms_block(1);
hdw_lcd_ips096_clear(BLACK);
delay_ms_block(1);
}
///////////////////////////////////////////////////////////////////////////////
void hdw_lcd_ips096_display_on(void) //屏幕显示开启
{
_spi_write_command(ST7735S_DISPON); //显示开启
}
void hdw_lcd_ips096_display_off(void) //屏幕显示关闭
{
_spi_write_command(ST7735S_DISPOFF); //显示关闭
}
void hdw_lcd_ips096_set_region(unsigned short x, unsigned short y, unsigned short x_end, unsigned short y_end)
{
_spi_write_command(ST7735S_CASET); //行地址设置
_spi_write_data16(x + 1);
_spi_write_data16(x_end + 1);
_spi_write_command(ST7735S_RASET); //列地址设置
_spi_write_data16(y + 26);
_spi_write_data16(y_end + 26);
_spi_write_command(ST7735S_RAMWR); //写显存
}
void hdw_lcd_ips096_fill(unsigned short x, unsigned short y, unsigned short x_len, unsigned short y_len, unsigned short color)
{
unsigned int i, j;
if (x_len != 0 && y_len != 0)
{
hdw_lcd_ips096_set_region(x, y, x + x_len - 1, y + y_len - 1);
//这里与扫描方向有关
for (i = x; i < x + x_len; i++)
{
for (j = y; j < y + y_len; j++)
{
_spi_write_data16(color);
}
}
}
}
#define HDW_IPS_X_WIDTH (160)
#define HDW_IPS_Y_WIDTH (80)
void hdw_lcd_ips096_clear(unsigned short color)
{
hdw_lcd_ips096_fill(0, 0, HDW_IPS_X_WIDTH, HDW_IPS_Y_WIDTH, color);
}
void hdw_lcd_show_picture(unsigned short x, unsigned short y, unsigned short x_len, unsigned short y_len, const unsigned char *bmp)
{
int i ,j;
if (x_len != 0 && y_len != 0)
{
hdw_lcd_ips096_set_region(x, y, x + x_len - 1, y + y_len - 1);
for (i = 0; i < y_len; i++)
{
for (j = 0; j < x_len; j++)
{
_spi_write_data8(bmp[2 * (i * x_len + j)]); //高位
_spi_write_data8(bmp[2 * (i * x_len + j) + 1]); //低位
}
}
}
}
void hdw_lcd_draw_point(unsigned short x, unsigned short y, unsigned short color)
{
hdw_lcd_ips096_set_region(x, y, x, y);
_spi_write_data16(color);
}
///////////////////////////////////////////////////////////////////////////////////
static Color g_x_ips096_gram[HDW_IPS_X_WIDTH * HDW_IPS_Y_WID
评论0