#include "hdw_lcd_st7789v_ips114.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_ips114_init(void)
{
_ips_pin_init();
HDW_BLK_Set(); //点亮背光
delay_ms_block(100); //ms
//************* ST7789V初始化**********//
//软件重启
_spi_write_command(ST7789V_SWRESET);
delay_ms_block(100);
//离开睡眠模式
_spi_write_command(ST7789V_SLPOUT);
delay_ms_block(100);
//显示关闭
_spi_write_command(ST7789V_DISPOFF);
//显示设置 /* row oder, col order, row colum xchange, vert refr order, rgb/bgr, hor refr order, 0, 0 */
_spi_write_command(ST7789V_MADCTL);
_spi_write_data8(MADCTL(0, 1, 1, 0, 0, 0));
//设置色彩模式
_spi_write_command(ST7789V_COLMOD);
_spi_write_data8(COLOR_MODE_65K|COLOR_MODE_16B);
//反白显示 /* display inversion on/off */
_spi_write_command(ST7789V_INVON);
_spi_write_command(ST7789V_PORCTRL);
_spi_write_data8(0x05);
_spi_write_data8(0x05);
_spi_write_data8(0x00);
_spi_write_data8(0x33);
_spi_write_data8(0x33);
_spi_write_command(ST7789V_GCTRL);
_spi_write_data8(0x23);
_spi_write_command(ST7789V_VCOMS);
_spi_write_data8(0x20);
_spi_write_command(ST7789V_LCMCTRL);
_spi_write_data8(0x2C);
_spi_write_command(ST7789V_VDVVRHEN);
_spi_write_data8(0x01);
_spi_write_command(ST7789V_VRHS);
_spi_write_data8(0x13);
_spi_write_command(ST7789V_VDVSET);
_spi_write_data8(0x20);
_spi_write_command(ST7789V_FRCTR2);
_spi_write_data8(0x0F);
_spi_write_command(ST7789V_PWCTRL1);
_spi_write_data8(0xA4);
_spi_write_data8(0xA1);
//伽玛(' + '极性)校正特性设置
_spi_write_command(ST7789V_PVGAMCTRL);
_spi_write_data8(0x70);
_spi_write_data8(0x06);
_spi_write_data8(0x0C);
_spi_write_data8(0x08);
_spi_write_data8(0x09);
_spi_write_data8(0x27);
_spi_write_data8(0x2E);
_spi_write_data8(0x34);
_spi_write_data8(0x46);
_spi_write_data8(0x37);
_spi_write_data8(0x13);
_spi_write_data8(0x13);
_spi_write_data8(0x25);
_spi_write_data8(0x2A);
//伽玛(' - '极性)校正特性设置
_spi_write_command(ST7789V_NVGAMCTRL);
_spi_write_data8(0x70);
_spi_write_data8(0x04);
_spi_write_data8(0x08);
_spi_write_data8(0x09);
_spi_write_data8(0x07);
_spi_write_data8(0x03);
_spi_write_data8(0x2C);
_spi_write_data8(0x42);
_spi_write_data8(0x42);
_spi_write_data8(0x38);
_spi_write_data8(0x14);
_spi_write_data8(0x14);
_spi_write_data8(0x27);
_spi_write_data8(0x2C);
//显示开启
_spi_write_command(ST7789V_DISPON);
//背景
hdw_lcd_ips114_clear(BLACK);
}
///////////////////////////////////////////////////////////////////////////////
void hdw_lcd_ips114_display_on(void) //屏幕显示开启
{
_spi_write_command(ST7789V_DISPON); //显示开启
}
void hdw_lcd_ips114_display_off(void) //屏幕显示关闭
{
_spi_write_command(ST7789V_DISPOFF); //显示关闭
}
void hdw_lcd_ips114_set_region(unsigned short x, unsigned short y, unsigned short x_end, unsigned short y_end)
{
_spi_write_command(ST7789V_CASET); //行地址设置
_spi_write_data16(x + 40);
_spi_write_data16(x_end + 40);
_spi_write_command(ST7789V_RASET); //列地址设置
_spi_write_data16(y + 53);
_spi_write_data16(y_end + 53);
_spi_write_command(ST7789V_RAMWR); //写显存
}
void hdw_lcd_ips114_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_ips114_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 (240)
#define HDW_IPS_Y_WIDTH (135)
void hdw_lcd_ips114_clear(unsigned short color)
{
hdw_lcd_ips114_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_ips114_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_ips114_set_region(x, y, x, y);
_spi_write_data16(color);
}
///////////////////////////////////////////////////////////////////////////////////
static Color g_x_ips114_gram[HDW_IPS_X_WIDTH * HDW_IPS_Y_WIDTH]; //足够描述每一个点
void portal_draw_point(Crood x, Crood y, Color color)
{
if (x >= HDW_IPS_X_WIDTH) return;
if (y >= HDW_IPS_Y_WIDTH) return;
g_x_ips114_gram[x * HDW_IPS_Y_WIDTH + y] = color;
}
void portal_refresh(void)
{
unsigned int i, j;
hdw_lcd_ips114_set_region(0, 0, HDW_IPS_X_WIDTH - 1, HDW_IPS_Y_WIDTH - 1);
for (i = 0; i < HDW_IPS_Y_WIDTH; i++)
{
for (j = 0; j < HDW_IPS_X_WIDTH; j++)
{
_spi_write_data16((unsigned short)g_x_ips114_gram[j * HDW_IPS_Y_WIDTH + i]);
}
}
}
void portal_clear(void)
{
memset(g_x_ips114_gram, 0, sizeof(g_x_ips114_gram));
}
DeviceScreen_t g_x_st7789v_ips114 = {
//长度
.pixel_length_x = HDW_IPS_X_WIDTH, //X方向像素长度
.pixel_length_y = HDW_IPS_Y_WIDTH, //Y方向像素长度
//坐标范围
.crood_x_min = 0, //X方向像素坐标
.crood_x_max = HDW_IPS_X_WIDTH - 1, //X方向像素坐标
.crood_y_min = 0, //Y方向像素坐标
.crood_y_max = HDW_IPS_Y_WIDTH - 1, //Y方向像素坐标
.pixel_set = portal_draw_point, //在屏幕/显存上绘制点
.pixel_get = (void *)0, //获取屏幕/显存上的点
}; //屏幕硬件抽象类
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
IPS彩屏1.14寸135240_7线SPI.rar (4个子文件)
IPS彩屏1.14寸135240_7线SPI
hdw_lcd_st7789v_ips114.c 7KB
hdw_lcd_st7789v_ips114.h 8KB
hdw_spi.h 622B
hdw_spi.c 3KB
共 4 条
- 1
MaxwellXyao
- 粉丝: 2
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0