当前位置: 首页 > news >正文

桌面小屏幕实战课程:DesktopScreen 18 FONTPAINT

飞书文档https://x509p6c8to.feishu.cn/docx/doxcnal9G2qYkdp62ZBPN8LJrEe

注意,本章节的代码适配的是GDEW0154T8驱动源码,已经停产,所以只能参考实现思路,此工程在新屏幕中是跑不起来的。

如果需要最新版本的屏幕驱动代码,参考分支dev_17_all_d67中的

dev17_all_d67/main/src/driver/ds_screen.c GDEW0154D67驱动源码(目前使用)

源码下载参考:

源码下载方式

图标生成

准备图片:

[图标.zip]

打开图片取模软件:

[图片取模软件.exe]

编辑->导出代码

图标使用

源码下载方式参考:

源码下载方式

注意:由于厂家前后期提供的墨水屏驱动芯片不一样,所以不同的墨水屏驱动代码需要根据自己购买的屏幕型号进行替换,驱动代码见分支:

dev17_all/main/src/driver/ds_screen.c 为GDEW0154T8驱动源码(停产,此文档的代码)

dev17_all_d67/main/src/driver/ds_screen.c GDEW0154D67驱动源码(目前使用)

#include <string.h>
#include <stdio.h>#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "sdkconfig.h"#include "ds_screen.h"
#include "ds_gpio.h"
#include "ds_spi.h"
#include "ds_data_image.h"/*************************EPD display init function******************************************************/
//LUT download
static void lut(void)
{unsigned int count;spi_send_cmd(0x20);for(count=0;count<44;count++)       {spi_send_data(lut_vcomDC[count]);}spi_send_cmd(0x21);for(count=0;count<42;count++)       {spi_send_data(lut_ww[count]);}  spi_send_cmd(0x22);for(count=0;count<42;count++)       {spi_send_data(lut_bw[count]);}spi_send_cmd(0x23);for(count=0;count<42;count++)       {spi_send_data(lut_wb[count]);}spi_send_cmd(0x24);for(count=0;count<42;count++)       {spi_send_data(lut_bb[count]);}
}static void lut1(void)
{unsigned int count;spi_send_cmd(0x20);for(count=0;count<44;count++)       {spi_send_data(lut_vcom1[count]);}spi_send_cmd(0x21);for(count=0;count<42;count++)       {spi_send_data(lut_ww1[count]);}  spi_send_cmd(0x22);for(count=0;count<42;count++)       {spi_send_data(lut_bw1[count]);}spi_send_cmd(0x23);for(count=0;count<42;count++)       {spi_send_data(lut_wb1[count]);}spi_send_cmd(0x24);for(count=0;count<42;count++)       {spi_send_data(lut_bb1[count]);}   
}//Detection busy
static void lcd_chkstatus(void)
{int busy;do{spi_send_cmd(0x71);busy = ds_gpio_get_screen_busy();   }while(busy);  // vTaskDelay(100 / portTICK_PERIOD_MS);               
}  static void init_display(){vTaskDelay(10 / portTICK_PERIOD_MS);ds_gpio_set_screen_rst(0);      // Module resetvTaskDelay(10 / portTICK_PERIOD_MS);ds_gpio_set_screen_rst(1);spi_send_cmd(0x01);         //POWER SETTINGspi_send_data (0x03);            spi_send_data (0x00);spi_send_data (0x2b);spi_send_data (0x2b);spi_send_data (0x03);spi_send_cmd(0x06);         //boost soft startspi_send_data (0x17);       //Aspi_send_data (0x17);       //Bspi_send_data (0x17);       //C      spi_send_cmd(0x04); lcd_chkstatus();spi_send_cmd(0x00);         //panel settingspi_send_data(0xbf);        //LUT from OTP,128x296spi_send_data(0x0d);        //VCOM to 0V fastspi_send_cmd(0x30);         //PLL settingspi_send_data (0x3a);       // 3a 100HZ   29 150Hz 39 200HZ 31 171HZspi_send_cmd(0x61);         //resolution settingspi_send_data (0x98);           spi_send_data (0x00);      spi_send_data (0x98);spi_send_cmd(0x82);         //vcom_DC setting  spi_send_data (0x28);  spi_send_cmd(0X50);         //VCOM AND DATA INTERVAL SETTING           spi_send_data(0x97);        //WBmode:VBDF 17|D7 VBDW 97 VBDB 57     WBRmode:VBDF F7 VBDW 77 VBDB 37  VBDR B7
}/Enter deep sleep mode
static void deep_sleep(void) //Enter deep sleep mode
{spi_send_cmd(0X50);spi_send_data(0xf7);   spi_send_cmd(0X02);     //power offlcd_chkstatus();spi_send_cmd(0X07);     //deep sleepspi_send_data(0xA5);
}//图片全刷-全白函数
static void ds_screen_display_white(void){unsigned int i;spi_send_cmd(0x10);for(i=0;i<2888;i++){spi_send_data(0x00); }spi_send_cmd(0x13);for(i=0;i<2888;i++){spi_send_data(0xff); }          
}//图片全刷-数据函数
void ds_screen_full_display_data(const uint8_t *data){unsigned int i;spi_send_cmd(0x10);for(i=0;i<2888;i++)     {spi_send_data(0x00); } spi_send_cmd(0x13);for(i=0;i<2888;i++)     {spi_send_data(data[i]); } 
}//全刷 不带数据
void ds_screen_full_display(void pic_display(void)){init_display();pic_display();              //picturelut();                      //Power settingsspi_send_cmd(0x12);         //DISPLAY REFRESH  lcd_chkstatus();deep_sleep();}//全刷 带数据
void ds_screen_full_display_bydata(void display_func(const uint8_t *data),const uint8_t *data){init_display();display_func(data);                 //picturelut();                      //Power settingsspi_send_cmd(0x12);         //DISPLAY REFRESH  lcd_chkstatus();deep_sleep();
}//局部刷 不带数据
void ds_screen_partial_display(unsigned int x_start,unsigned int x_end,unsigned int y_start,unsigned int y_end ,void partial_old(void),void partial_new(void))
{init_display();spi_send_cmd(0x82);         //vcom_DC setting  spi_send_data (0x08);  spi_send_cmd(0X50);spi_send_data(0x47);       lut1();spi_send_cmd(0x91);     //This command makes the display enter partial modespi_send_cmd(0x90);     //resolution settingspi_send_data (x_start);   //x-start    spi_send_data (x_end-1);     //x-end   spi_send_data (y_start/256);spi_send_data (y_start%256);   //y-start   spi_send_data (y_end/256);     spi_send_data (y_end%256-1);  //y-endspi_send_data (0x28);  spi_send_cmd(0x10);        //writes Old data to SRAM for programmingpartial_old();spi_send_cmd(0x13);        //writes New data to SRAM.partial_new();spi_send_cmd(0x12);      //DISPLAY REFRESH      lcd_chkstatus();deep_sleep();vTaskDelay(200 / portTICK_PERIOD_MS); 
}//局部刷 带数据
void ds_screen_partial_display_bydata(unsigned int x_start,unsigned int x_end,unsigned int y_start,unsigned int y_end ,void partial_old(const uint8_t *data),const uint8_t *old_data,void partial_new(const uint8_t *data),const uint8_t *new_data)
{init_display();spi_send_cmd(0x82);         //vcom_DC setting  spi_send_data (0x08);  spi_send_cmd(0X50);spi_send_data(0x47);       lut1();spi_send_cmd(0x91);     //This command makes the display enter partial modespi_send_cmd(0x90);     //resolution settingspi_send_data (x_start);   //x-start    spi_send_data (x_end-1);     //x-end   spi_send_data (y_start/256);spi_send_data (y_start%256);   //y-start   spi_send_data (y_end/256);     spi_send_data (y_end%256-1);  //y-endspi_send_data (0x28);  spi_send_cmd(0x10);        //writes Old data to SRAM for programmingpartial_old(old_data);spi_send_cmd(0x13);        //writes New data to SRAM.partial_new(new_data);spi_send_cmd(0x12);      //DISPLAY REFRESH      lcd_chkstatus();deep_sleep();vTaskDelay(200 / portTICK_PERIOD_MS);  
}uint8_t partial_data[152][19];
uint8_t partial_data_array[2888];void ds_screen_partial_data_init(){for(int index = 0;index < 152 ;index ++){for(int yindex = 0;yindex < 19 ;yindex ++){partial_data[index][yindex] = 0xff;}}
}void ds_screen_partial_data_add(unsigned int x_start,unsigned int x_end,unsigned int y_start,unsigned int y_end ,const uint8_t *data){uint8_t x_len = x_end - x_start;uint8_t x_data_location = x_start/8;  uint8_t x_size = x_len/8;  int data_index = 0;if(x_start % 8 != 0){x_data_location ++;}if(x_len % 8 != 0){x_size ++;}//x_data_location=0 x_size=5 //90 126printf("x_data_location %d x_size%d\n",x_data_location,x_size);printf("ystart %d y_end%d\n",y_start,y_end);for(int x_index = y_start ;x_index < y_end;x_index ++){for(int y_index = x_data_location ;y_index < (x_data_location+x_size);y_index ++){partial_data[x_index][y_index] = (~data[data_index]);data_index++;}}
}//图片全刷-全白函数
static void ds_screen_display_data(void){unsigned int i;spi_send_cmd(0x10);for(i=0;i<2888;i++){spi_send_data(0x00); }spi_send_cmd(0x13);for(i=0;i<2888;i++){spi_send_data(partial_data_array[i]); }          
}void ds_screen_partial_data_copy(){int data_index = 0;for(int index = 0;index < 152 ;index ++){for(int yindex = 0;yindex < 19 ;yindex ++){partial_data_array[data_index] = partial_data[index][yindex];data_index ++;}}ds_screen_full_display(ds_screen_display_data);
}//接口初始化
void init_screen_interface(){ds_screen_gpio_init();screen_spi_init();
}//初始化
void ds_screen_init(){ds_screen_full_display(ds_screen_display_white);
}//清屏为白色
void ds_screen_clean_white(){ds_screen_init();vTaskDelay(2000 / portTICK_PERIOD_MS);     
}const unsigned char gImage_main_page[] = {
/* ͼ�� C:\Users\Administrator\Desktop\������Ļ\image\δ����_����.jpg  152x152 */
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0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xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
};void ds_screen_image_test(){ds_screen_full_display_bydata(ds_screen_full_display_data,gImage_main_page);
}

字库生成

LVGL工具:飞书文档中下载

字体:飞书文档中下载

字库下载

分区设置

分区表 - ESP32 - — ESP-IDF 编程指南 latest 文档

Name, Type, SubType, Offset, Size, Flags

Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap

nvs, data, nvs, 0x9000, 0x6000,

phy_init, data, phy, 0xf000, 0x1000,

factory, app, factory, 0x10000, 1M,

storage, data, spiffs, 0x110000,1M,

storage1, 0x40, 0x01, 0x210000,1M,

使用idf.py menuconfig配置flash大小为4MB

确定分区是否设置成功:

启动打印

I (64) boot: ## Label            Usage          Type ST Offset   Length

I (71) boot:  0 nvs              WiFi data        01 02 00009000 00006000

I (79) boot:  1 phy_init         RF data          01 01 0000f000 00001000

I (86) boot:  2 factory          factory app      00 00 00010000 00100000

I (93) boot:  3 storage          Unknown data     01 82 00110000 00100000

I (101) boot:  4 storage1         unknown          40 01 00210000 00100000

BIN下载

python esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 115200 write_flash -z 0x210000 myFont.bin

在代码中使用字库

源码下载方式参考:

源码下载方式

  1. 1、把字符转为unicode编码
  2. 2、根据编码查询存储位置,数组大小信息,数组偏移信息
  3. 3、根据上一步信息读取显示数据
#include "ds_font.h"
#include "esp_partition.h"
#include <string.h>typedef struct{uint16_t min;uint16_t max;uint8_t  bpp;uint8_t  reserved[3];
}x_header_t;typedef struct{uint8_t adv_w;uint8_t box_w;uint8_t box_h;int8_t  ofs_x;int8_t  ofs_y;uint8_t r;
}glyph_dsc_t;#define FLASH_ADDR_DATA 0x40
#define FLASH_ADDR_NVS 0x01static x_header_t __g_xbf_hd = {.min = 0x0020,.max = 0x9fa0,.bpp = 4,
};static uint8_t __g_font_buf[300];//如bin文件存在SPI FLASH可使用此buffconst esp_partition_t* partition_res=NULL;static uint8_t *user_font_getdata(int offset, int size)
{//如字模保存在SPI FLASH, SPIFLASH_Read(__g_font_buf,offset,size);static uint8_t first_in = 1; if(first_in==1){//查找分区指针//这个函数第一个参数是我们分区表的第四行的,第二列的参数,第二个是第三列的值     partition_res=esp_partition_find_first(FLASH_ADDR_DATA,FLASH_ADDR_NVS,NULL);first_in=0;if (partition_res == NULL){printf("Failed to open file for reading\n");return NULL;}else{printf("Successfully open file for reading\n");}}//flash 分区数据读取esp_err_t res=esp_partition_read(partition_res,offset,__g_font_buf,size);//读取数据if(res!=ESP_OK){printf("Failed to reading %x \n",offset);}return __g_font_buf;
}static uint32_t user_font_get_glyph_dsc(uint32_t unicode_letter,glyph_dsc_t * gdsc) {if( unicode_letter>__g_xbf_hd.max || unicode_letter<__g_xbf_hd.min ) {return 0;}//根据字符unicode码查找索引数据uint32_t unicode_offset = sizeof(x_header_t)+(unicode_letter-__g_xbf_hd.min)*4;uint32_t *p_pos = (uint32_t *)user_font_getdata(unicode_offset, 4);if( p_pos[0] != 0 ) {uint32_t pos = p_pos[0];glyph_dsc_t *mdsc = (glyph_dsc_t*)user_font_getdata(pos, sizeof(glyph_dsc_t));memcpy(gdsc,mdsc,sizeof(glyph_dsc_t));// printf("pos = %x\n",pos);// printf("gdsc->adv_w = %d\n",gdsc->adv_w);// printf("gdsc->box_h = %d\n",gdsc->box_h);// printf("gdsc->box_w = %d\n",gdsc->box_w);// printf("gdsc->ofs_x = %d\n",gdsc->ofs_x);// printf("gdsc->ofs_y = %d\n",gdsc->ofs_y);// printf("__g_xbf_hd.bpp = %d\n",__g_xbf_hd.bpp);return pos;}return 0;
}static const uint8_t * user_font_get_bitmap(uint32_t pos,int size) {return user_font_getdata(pos+sizeof(glyph_dsc_t), size);   
}//获取map数组
int ds_get_bitmap(uint32_t letter,uint8_t *bitmap_buf,uint8_t *box_w,uint8_t *box_h,uint8_t *offset_x,uint8_t *offset_y){glyph_dsc_t gdsc;uint32_t pos = user_font_get_glyph_dsc(letter,&gdsc);if(pos != 0){int size = gdsc.box_w*gdsc.box_h*__g_xbf_hd.bpp/8;*box_w = gdsc.box_w;*box_h = gdsc.box_h;*offset_x = gdsc.ofs_x;*offset_y = gdsc.ofs_y;user_font_get_bitmap(pos,size);memcpy(bitmap_buf,__g_font_buf,size);return size;}return 0;
}void test_ds_font(){// uint8_t buf[300];// uint8_t box_w,box_h = 0;// uint8_t offset_x,offset_y = 0;// int size = ds_get_bitmap(0x0041,buf,&box_w,&box_h,&offset_x,&offset_y);// printf("box_w*h = %d*%d\n",box_w,box_h);// for(int index = 0;index < size ;index ++){//     printf("%x ",buf[index]);// }
}

画笔相关实现

有了图标、有了文字数据,如何放到同一个页面里面呢?

  1. 1、初始化一个152*152像素的数组
  2. 2、根据UI要求,设置图标和文字的初始位置
  3. 3、根据图标和文字数组内容,把像素数组的对于像素设置为亮灭
#include "ds_paint.h"
#include "ds_screen.h"
#include "ds_spi.h"PAINT Paint;ROTATE_IMAGE Epd_Rotate = ROTATE_90;uint8_t UTF8toUnicode(uint8_t *ch, uint16_t *_unicode)
{uint8_t *p = NULL ,n = 0;int e = 0;p = ch;if(1)//p == NULL{if(*p >= 0xfc){/*6:<11111100>*/e  = (p[0] & 0x01) << 30;e |= (p[1] & 0x3f) << 24;e |= (p[2] & 0x3f) << 18;e |= (p[3] & 0x3f) << 12;e |= (p[4] & 0x3f) << 6;e |= (p[5] & 0x3f);n = 6;}else if(*p >= 0xf8){/*5:<11111000>*/e = (p[0] & 0x03) << 24;e |= (p[1] & 0x3f) << 18;e |= (p[2] & 0x3f) << 12;e |= (p[3] & 0x3f) << 6;e |= (p[4] & 0x3f);n = 5;}else if(*p >= 0xf0){/*4:<11110000>*/e = (p[0] & 0x07) << 18;e |= (p[1] & 0x3f) << 12;e |= (p[2] & 0x3f) << 6;e |= (p[3] & 0x3f);n = 4;}else if(*p >= 0xe0){/*3:<11100000>*/e = (p[0] & 0x0f) << 12;e |= (p[1] & 0x3f) << 6;e |= (p[2] & 0x3f);n = 3;}else if(*p >= 0xc0){/*2:<11000000>*/e = (p[0] & 0x1f) << 6;e |= (p[1] & 0x3f);n = 2;}else{e = p[0];          n = 1;}*_unicode = e;}return n;
}/******************************************************************************
function: Create _Image
parameter:_image   :   Pointer to the _image cachewidth   :   The width of the pictureHeight  :   The height of the pictureColor   :   Whether the picture is inverted
******************************************************************************/
void Paint_NewImage(UBYTE *_image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color)
{Paint._Image = NULL;Paint._Image = _image;Paint.WidthMemory = Width;Paint.HeightMemory = Height;Paint.Color = Color;   Paint.Scale = 2;Paint.WidthByte = (Width % 8 == 0)? (Width / 8 ): (Width / 8 + 1);Paint.HeightByte = Height;   
//    printf("WidthByte = %d, HeightByte = %d\r\n", Paint.WidthByte, Paint.HeightByte);
//    printf(" EPD_WIDTH / 8 = %d\r\n",  122 / 8);Paint.Rotate = Rotate;Paint.Mirror = MIRROR_NONE;if(Rotate == ROTATE_0 || Rotate == ROTATE_180) {Paint.Width = Width;Paint.Height = Height;} else {Paint.Width = Height;Paint.Height = Width;}
}/******************************************************************************
function: Select _Image
parameter:_image : Pointer to the _image cache
******************************************************************************/
void Paint_SelectImage(UBYTE *_image)
{Paint._Image = _image;
}/******************************************************************************
function: Draw Pixels
parameter:Xpoint : At point XYpoint : At point YColor  : Painted colors
******************************************************************************/
void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color)
{if(Xpoint > Paint.Width || Ypoint > Paint.Height){printf("Exceeding display boundaries Xpoint*Ypoint=%d*%d\r\n",Xpoint,Ypoint);return;}     UWORD X, Y;switch(Paint.Rotate) {case 0:X = Xpoint;Y = Ypoint; break;case 90:X = Paint.WidthMemory - Ypoint - 1;Y = Xpoint;break;case 180:X = Paint.WidthMemory - Xpoint - 1;Y = Paint.HeightMemory - Ypoint - 1;break;case 270:X = Ypoint;Y = Paint.HeightMemory - Xpoint - 1;break;default:return;}switch(Paint.Mirror) {case MIRROR_NONE:break;case MIRROR_HORIZONTAL:X = Paint.WidthMemory - X - 1;break;case MIRROR_VERTICAL:Y = Paint.HeightMemory - Y - 1;break;case MIRROR_ORIGIN:X = Paint.WidthMemory - X - 1;Y = Paint.HeightMemory - Y - 1;break;default:return;}if(X > Paint.WidthMemory || Y > Paint.HeightMemory){printf("Exceeding display boundaries X*Y=%d*%d\r\n",X,Y);return;}if(Paint.Scale == 2){UDOUBLE Addr = X / 8 + Y * Paint.WidthByte;UBYTE Rdata = Paint._Image[Addr];if(Color == BLACK)Paint._Image[Addr] = Rdata & ~(0x80 >> (X % 8));elsePaint._Image[Addr] = Rdata | (0x80 >> (X % 8));}else if(Paint.Scale == 4){UDOUBLE Addr = X / 4 + Y * Paint.WidthByte;Color = Color % 4;//Guaranteed color scale is 4  --- 0~3UBYTE Rdata = Paint._Image[Addr];Rdata = Rdata & (~(0xC0 >> ((X % 4)*2)));Paint._Image[Addr] = Rdata | ((Color << 6) >> ((X % 4)*2));}
}/******************************************************************************
function: Clear the color of the picture
parameter:Color : Painted colors
******************************************************************************/
void Paint_Clear(UWORD Color)
{for (UWORD Y = 0; Y < Paint.HeightByte; Y++) {for (UWORD X = 0; X < Paint.WidthByte; X++ ) {//8 pixel =  1 byteUDOUBLE Addr = X + Y*Paint.WidthByte;Paint._Image[Addr] = Color;}}
}/******************************************************************************
function: Clear the color of a window
parameter:Xstart : x starting pointYstart : Y starting pointXend   : x end pointYend   : y end pointColor  : Painted colors
******************************************************************************/
void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color)
{UWORD X, Y;for (Y = Ystart; Y < Yend; Y++) {for (X = Xstart; X < Xend; X++) {//8 pixel =  1 bytePaint_SetPixel(X, Y, Color);}}
}/******************************************************************************
function: Draw Point(Xpoint, Ypoint) Fill the color
parameter:Xpoint    : The Xpoint coordinate of the pointYpoint    : The Ypoint coordinate of the pointColor   : Painted colorDot_Pixel : point sizeDot_Style : point Style
******************************************************************************/
void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color,DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style)
{if (Xpoint > Paint.Width || Ypoint > Paint.Height) {printf("Paint_DrawPoint Input exceeds the normal display range\r\n");printf("Xpoint = %d , Paint.Width = %d  \r\n ",Xpoint,Paint.Width);printf("Ypoint = %d , Paint.Height = %d  \r\n ",Ypoint,Paint.Height);return;}int16_t XDir_Num , YDir_Num;if (Dot_Style == DOT_FILL_AROUND) {for (XDir_Num = 0; XDir_Num < 2 * Dot_Pixel - 1; XDir_Num++) {for (YDir_Num = 0; YDir_Num < 2 * Dot_Pixel - 1; YDir_Num++) {if(Xpoint + XDir_Num - Dot_Pixel < 0 || Ypoint + YDir_Num - Dot_Pixel < 0)break;// printf("x = %d, y = %d\r\n", Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel);Paint_SetPixel(Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel, Color);}}} else {for (XDir_Num = 0; XDir_Num <  Dot_Pixel; XDir_Num++) {for (YDir_Num = 0; YDir_Num <  Dot_Pixel; YDir_Num++) {Paint_SetPixel(Xpoint + XDir_Num - 1, Ypoint + YDir_Num - 1, Color);}}}
}/******************************************************************************
function: Draw a line of arbitrary slope
parameter:Xstart :Starting Xpoint point coordinatesYstart :Starting Xpoint point coordinatesXend   :End point Xpoint coordinateYend   :End point Ypoint coordinateColor  :The color of the line segmentLine_width : Line widthLine_Style: Solid and dotted lines
******************************************************************************/
void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,UWORD Color, DOT_PIXEL Line_width, LINE_STYLE Line_Style)
{if (Xstart > Paint.Width || Ystart > Paint.Height ||Xend > Paint.Width || Yend > Paint.Height) {printf("Paint_DrawLine Input exceeds the normal display range\r\n");return;}UWORD Xpoint = Xstart;UWORD Ypoint = Ystart;int dx = (int)Xend - (int)Xstart >= 0 ? Xend - Xstart : Xstart - Xend;int dy = (int)Yend - (int)Ystart <= 0 ? Yend - Ystart : Ystart - Yend;// Increment direction, 1 is positive, -1 is counter;int XAddway = Xstart < Xend ? 1 : -1;int YAddway = Ystart < Yend ? 1 : -1;//Cumulative errorint Esp = dx + dy;char Dotted_Len = 0;for (;;) {Dotted_Len++;//Painted dotted line, 2 point is really virtualif (Line_Style == LINE_STYLE_DOTTED && Dotted_Len % 3 == 0) {//Debug("LINE_DOTTED\r\n");Paint_DrawPoint(Xpoint, Ypoint, IMAGE_BACKGROUND, Line_width, DOT_STYLE_DFT);Dotted_Len = 0;} else {Paint_DrawPoint(Xpoint, Ypoint, Color, Line_width, DOT_STYLE_DFT);}if (2 * Esp >= dy) {if (Xpoint == Xend)break;Esp += dy;Xpoint += XAddway;}if (2 * Esp <= dx) {if (Ypoint == Yend)break;Esp += dx;Ypoint += YAddway;}}
}/******************************************************************************
function: Draw a rectangle
parameter:Xstart :Rectangular  Starting Xpoint point coordinatesYstart :Rectangular  Starting Xpoint point coordinatesXend   :Rectangular  End point Xpoint coordinateYend   :Rectangular  End point Ypoint coordinateColor  :The color of the Rectangular segmentLine_width: Line widthDraw_Fill : Whether to fill the inside of the rectangle
******************************************************************************/
void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
{if (Xstart > Paint.Width || Ystart > Paint.Height ||Xend > Paint.Width || Yend > Paint.Height) {printf("Input exceeds the normal display range\r\n");return;}if (Draw_Fill) {UWORD Ypoint;for(Ypoint = Ystart; Ypoint < Yend; Ypoint++) {Paint_DrawLine(Xstart, Ypoint, Xend, Ypoint, Color , Line_width, LINE_STYLE_SOLID);}} else {Paint_DrawLine(Xstart, Ystart, Xend, Ystart, Color, Line_width, LINE_STYLE_SOLID);Paint_DrawLine(Xstart, Ystart, Xstart, Yend, Color, Line_width, LINE_STYLE_SOLID);Paint_DrawLine(Xend, Yend, Xend, Ystart, Color, Line_width, LINE_STYLE_SOLID);Paint_DrawLine(Xend, Yend, Xstart, Yend, Color, Line_width, LINE_STYLE_SOLID);}
}/******************************************************************************
function: Use the 8-point method to draw a circle of thespecified size at the specified position->
parameter:X_Center  :Center X coordinateY_Center  :Center Y coordinateRadius    :circle RadiusColor     :The color of the :circle segmentLine_width: Line widthDraw_Fill : Whether to fill the inside of the Circle
******************************************************************************/
void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius,UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
{if (X_Center > Paint.Width || Y_Center >= Paint.Height) {printf("Paint_DrawCircle Input exceeds the normal display range\r\n");return;}//Draw a circle from(0, R) as a starting pointint16_t XCurrent, YCurrent;XCurrent = 0;YCurrent = Radius;//Cumulative error,judge the next point of the logoint16_t Esp = 3 - (Radius << 1 );int16_t sCountY;if (Draw_Fill == DRAW_FILL_FULL) {while (XCurrent <= YCurrent ) { //Realistic circlesfor (sCountY = XCurrent; sCountY <= YCurrent; sCountY ++ ) {Paint_DrawPoint(X_Center + XCurrent, Y_Center + sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//1Paint_DrawPoint(X_Center - XCurrent, Y_Center + sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//2Paint_DrawPoint(X_Center - sCountY, Y_Center + XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//3Paint_DrawPoint(X_Center - sCountY, Y_Center - XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//4Paint_DrawPoint(X_Center - XCurrent, Y_Center - sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//5Paint_DrawPoint(X_Center + XCurrent, Y_Center - sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//6Paint_DrawPoint(X_Center + sCountY, Y_Center - XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//7Paint_DrawPoint(X_Center + sCountY, Y_Center + XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);}if (Esp < 0 )Esp += 4 * XCurrent + 6;else {Esp += 10 + 4 * (XCurrent - YCurrent );YCurrent --;}XCurrent ++;}} else { //Draw a hollow circlewhile (XCurrent <= YCurrent ) {Paint_DrawPoint(X_Center + XCurrent, Y_Center + YCurrent, Color, Line_width, DOT_STYLE_DFT);//1Paint_DrawPoint(X_Center - XCurrent, Y_Center + YCurrent, Color, Line_width, DOT_STYLE_DFT);//2Paint_DrawPoint(X_Center - YCurrent, Y_Center + XCurrent, Color, Line_width, DOT_STYLE_DFT);//3Paint_DrawPoint(X_Center - YCurrent, Y_Center - XCurrent, Color, Line_width, DOT_STYLE_DFT);//4Paint_DrawPoint(X_Center - XCurrent, Y_Center - YCurrent, Color, Line_width, DOT_STYLE_DFT);//5Paint_DrawPoint(X_Center + XCurrent, Y_Center - YCurrent, Color, Line_width, DOT_STYLE_DFT);//6Paint_DrawPoint(X_Center + YCurrent, Y_Center - XCurrent, Color, Line_width, DOT_STYLE_DFT);//7Paint_DrawPoint(X_Center + YCurrent, Y_Center + XCurrent, Color, Line_width, DOT_STYLE_DFT);//0if (Esp < 0 )Esp += 4 * XCurrent + 6;else {Esp += 10 + 4 * (XCurrent - YCurrent );YCurrent --;}XCurrent ++;}}
}/******************************************************************************
function: Display the string
parameter:Xstart  :X coordinateYstart  :Y coordinatepString :The first address of the Chinese string and Englishstring to be displayedFont    :A structure pointer that displays a character sizeColor_Foreground : Select the foreground colorColor_Background : Select the background color
******************************************************************************/
void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString,UWORD Color_Foreground, UWORD Color_Background)
{const char* pstr = pString;int i;uint8_t  bitmap[300];i = 0;uint16_t char_cn_un = 0;//当前中文字数uint16_t cn_data_num = 0;uint16_t cn_box_w = 0;//当前英文字数uint16_t en_data_num = 0;uint16_t en_box_w = 0;while (*(pstr+i) != '\0'){memset(&bitmap,0,sizeof(bitmap));UTF8toUnicode((uint8_t*)pstr+i,&char_cn_un);uint8_t box_w,box_h = 0;uint8_t offset_x,offset_y = 0;ds_get_bitmap(char_cn_un,bitmap,&box_w,&box_h,&offset_x,&offset_y);uint8_t page_len = box_h;  //box_huint8_t colnum_len = box_w/2; //box_w/2printf("page_len %d  colnum_len %d\n",page_len,colnum_len);for(uint8_t Page = 0; Page < page_len; Page ++) //0-127{for (uint8_t Column = 0; Column < colnum_len; Column++) //0-1{uint8_t tmp = bitmap[Page*colnum_len + Column];// printf("%x ",tmp); for(int index = 0;index < 8 ;index += 4){if (((tmp >> index) & 0x0f) >= 1){Paint_SetPixel( Xstart + 2*Column + (1- index/4) + (en_box_w + cn_box_w)+(en_data_num+cn_data_num)*3 + offset_x,Ystart+ Page -offset_y -page_len    , Color_Background);}else{Paint_SetPixel(  Xstart + 2*Column + (1- index/4) + (en_box_w + cn_box_w)+(en_data_num+cn_data_num)*3 + offset_x,Ystart+ Page - offset_y -page_len  , Color_Foreground);}}}// printf("\n");}if (*(pstr+i) >= 128){//中文4bytei+=3;cn_data_num ++;cn_box_w += box_w;}else{i++;en_data_num ++;en_box_w += box_w;}}
}void Paint_DrawString_piture(UWORD Xstart, UWORD Ystart, unsigned char *pbuf ,int plen,int pxsize,UWORD Color_Foreground, UWORD Color_Background)
{uint8_t width = (pxsize%8 == 0) ? (pxsize/8) : (pxsize/8+1);uint8_t height = plen / width;for(int y = 0;y < height; y ++){for(int x = 0;x < width ;x ++){for(int index = 0;index < 8;index ++){if(((pbuf[y*width + x]>>(7-index)) & 0x01) == 1){Paint_SetPixel( Xstart + x*8 + index ,Ystart+ y , Color_Background);}else{Paint_SetPixel(  Xstart + x*8 + index,Ystart+ y , Color_Foreground);}}}}
}//图片全刷
void ds_paint_image(void){unsigned int i;spi_send_cmd(0x10);for(i=0;i<2888;i++){spi_send_data(0x00); }spi_send_cmd(0x13);for(i=0;i<2888;i++){spi_send_data(Paint._Image[i]); }          
}unsigned char gImage_last_page[2888];void ds_paint_last_page(void){unsigned int i;for(i=0;i<2888;i++){spi_send_data(~gImage_last_page[i]); }          
}void ds_paint_image_new(){unsigned int i;for(i=0;i<2888;i++){spi_send_data(~Paint._Image[i]); }      
}void ds_paint_clean(void){unsigned int i;for(i=0;i<2888;i++){spi_send_data(0); }          
}void ds_paint_image_copy(){memcpy(gImage_last_page,Paint._Image,2888);
}#define EPD_2IN9BC_WIDTH       152
#define EPD_2IN9BC_HEIGHT      152
#define IMAGE_SIZE (((EPD_2IN9BC_WIDTH % 8 == 0) ? (EPD_2IN9BC_WIDTH / 8 ) : (EPD_2IN9BC_WIDTH / 8 + 1)) * EPD_2IN9BC_HEIGHT)void ds_ui_show_test(){uint8_t *m_custom_image;printf("IMAGE_SIZE %d\n",IMAGE_SIZE);if ((m_custom_image = (uint8_t *)malloc(IMAGE_SIZE)) == NULL) {printf("Failed to apply for black memory...\r\n");return ;}Paint_NewImage(m_custom_image, EPD_2IN9BC_WIDTH, EPD_2IN9BC_HEIGHT, 0, WHITE);Paint_SelectImage(m_custom_image);Paint_Clear(WHITE);Paint_DrawString_CN(50, 80, "hello", WHITE, BLACK);Paint_DrawString_CN(50, 110, "你好", WHITE, BLACK);ds_screen_partial_display(0,151,0,151 ,ds_paint_clean,ds_paint_image_new);ds_paint_image_copy();free(m_custom_image);
}
http://www.lqws.cn/news/571249.html

相关文章:

  • RAG检索增强生成在垂类AI应用效能优化中的应用
  • 【硬核数学】6. 升级你的线性代数:张量,深度学习的多维数据语言《从零构建机器学习、深度学习到LLM的数学认知》
  • 【Java EE初阶 --- 多线程(进阶)】锁策略
  • 构建创意系统:驾驭Audition与Photoshop的AI之力,洞悉原子化设计哲学
  • Cursor1.1.6安装c++插件
  • MyBatis实战指南(八)MyBatis日志
  • 【数据集处理】基于 3D-GloBFP建筑轮廓数据 栅格化建筑数据(完整Python代码)
  • Day.46
  • 水果维生素含量排名详表
  • 【硬核数学】9. 驯服“梯度下降”:深度学习中的优化艺术与正则化技巧《从零构建机器学习、深度学习到LLM的数学认知》
  • 【JavaSE】反射学习笔记
  • 中州养老:学会设计数据库表
  • WebRTC(十三):信令服务器
  • Spring事件驱动模型核心:ApplicationEventMulticaster初始化全解析
  • 图书管理系统练习项目源码-前后端分离-使用node.js来做后端开发
  • NV064NV065美光固态闪存NV067NV076
  • 申论审题训练
  • DEPTHPRO:一秒内实现清晰的单目度量深度估计
  • 云端可视化耦合电磁场:麦克斯韦方程组的应用-AI云计算数值分析和代码验证
  • Leetcode百题斩-双指针
  • 电容屏触摸不灵敏及跳点问题分析
  • PyEcharts教程(010):天猫订单数据可视化项目
  • ISP Pipeline(9):Noise Filter for Chroma 色度去噪
  • H3C-路由器DHCPV6V4配置标准
  • 如何通过自动化减少重复性工作
  • GitHub vs GitLab 全面对比报告(2025版)
  • Java面试宝典:基础三
  • Vue中keep-alive结合router实现部分页面缓存
  • Spring生态创新应用
  • 【Redis#4】Redis 数据结构 -- String类型