指定区域填充函数。
void LCD_queue_Windows_Fill(spi_device_handle_t spi, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t *str)
{
esp_err_t ret;
int x;
static spi_transaction_t trans[6];
uint32_t size;
size = (x2 - x1) * (y2 - y1); //字符个数 byte
for (x = 0; x < 6; x++)
{
memset(&trans[x], 0, sizeof(spi_transaction_t));
if ((x & 1) == 0)
{
//Even transfers are commands
trans[x].length = 8;
trans[x].user = (void *)0;
}
else
{
//Odd transfers are data
trans[x].length = 8 * 4;
trans[x].user = (void *)1;
}
trans[x].flags = SPI_TRANS_USE_TXDATA;
}
trans[0].tx_data[0] = 0x2A; //Column Address Set
trans[1].tx_data[0] = x1 >> 8; //Start Col High
trans[1].tx_data[1] = x1 & 0xff; //Start Col Low
trans[1].tx_data[2] = (x2 - 1) >> 8; //End Col High
trans[1].tx_data[3] = (x2 - 1) & 0xff; //End Col Low
trans[2].tx_data[0] = 0x2B; //Page address set
trans[3].tx_data[0] = y1 >> 8; //Start page high
trans[3].tx_data[1] = y1 & 0xff; //start page low
trans[3].tx_data[2] = (y2 - 1) >> 8; //end page high
trans[3].tx_data[3] = (y2 - 1) & 0xff; //end page low
trans[4].tx_data[0] = 0x2C; //memory write
trans[5].tx_buffer = str; //finally send the line data
trans[5].length = size * 2 * 8 * 1; //Data length, in bits
trans[5].flags = 0; //undo SPI_TRANS_USE_TXDATA flag
for (x = 0; x < 6; x++)
{
ret = spi_device_queue_trans(spi, &trans[x], portMAX_DELAY);
assert(ret == ESP_OK);
}
}
指定区域显示英文字符
void GUI_UTF_8_Show_Font_EN(uint16_t x, uint16_t y, uint8_t num, uint8_t size, uint8_t mode)
{
uint8_t temp = 0, t1, t;
// uint8_t csize = (size / 8 + ((size % 8) ? 1 : 0)) * (size / 2); //得到字体一个字符对应点阵集所占的字节数
// uint8_t *dzk = malloc(72);
// uint16_t font_size = 0;
uint8_t dzk[72] = {0x00, 0xE0, 0x9C, 0x82, 0x9C, 0xE0, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00};
uint16_t csize = 0; //得到字体一个字符对应点阵集所占的字节数
uint16_t font_width = 0;
uint16_t *pBuf = malloc(sizeof(uint16_t) * size * size);
uint16_t font_index = 0;
uint16_t stat = 0;
if (pBuf == NULL || dzk == NULL)
{
printf("Maloc FAill !!\n");
return;
}
memset(pBuf, EXC_RGB_Color(BACK_COLOR), (sizeof(uint16_t) * size * size));
if (size == 12)
{
ASCII_GetData(num, ASCII_7X8, dzk);
font_width = 7;
size = 8;
}
else if (size == 16)
{
ASCII_GetData(num, ASCII_8X16, dzk);
font_width = 8;
}
else if (size == 24)
{
font_width = 12;
ASCII_GetData(num, ASCII_12X24_P, dzk);
}
else
return;
csize = size * font_width;
#if (1)
for (uint16_t t = 0; t < csize; t++)
{
if ((stat % 8 == 0) || (stat == font_width))
{
if (stat == font_width)
{
// printf("end = %04d -->\n",stat);
stat = 0;
}
else
{
// printf("<--head = %04d",stat);
}
temp = dzk[font_index++]; //数值点阵
}
stat++;
if (temp & 0x80)
{
// pBuf[t] = EXC_Color(POINT_COLOR);
pBuf[t] = POINT_COLOR;
}
temp <<= 1;
}
LCD_queue_Windows_Fill(lcd_spi, x, y, x + font_width, (y + size), pBuf);
#endif
#if (0)
if (size <= 16)
{
for (t = 0; t < csize; t++)
{
temp = dzk[t];
for (t1 = 0; t1 < font_width; t1++)
{
if (temp & 0x80)
{
//*pBuf++=BACK_COLOR;
// pBuf[t*8+t1] = POINT_COLOR;
pBuf[t * font_width + t1] = EXC_RGB_Color(POINT_COLOR);
}
temp <<= 1;
}
}
}
else
{
for (t = 0; t < csize;)
{
t += 2;
for (t1 = 0; t1 < font_width; t1++)
{
if (t1 == 0)
{
temp = dzk[2 * t];
}
if (t1 == 8)
{
temp = dzk[2 * t + 1];
font_size++;
}
if (temp & 0x80)
{
pBuf[font_size * font_width + t1] = EXC_RGB_Color(POINT_COLOR);
}
temp <<= 1;
}
font_size++;
}
}
printf("\n T= %d \n", t);
#if (1)
printf("\nbuff start %d :\n", font_width);
for (t = 0; t < csize; t++)
{
for (t1 = 0; t1 < font_width; t1++)
{
printf("0X%04x ", pBuf[t * font_width + t1]);
}
printf("\n\n\n");
}
printf("\n\n");
#endif
LCD_queue_Windows_Fill(lcd_spi, x, y, x + font_width, (y + size), pBuf);
#endif
free(pBuf);
// free(dzk);
}
显示中文字符
void GUI_UTF_8_Show_Font_CN(uint16_t x, uint16_t y, uint8_t *font, uint8_t size, uint8_t mode)
{
uint8_t temp = 0, t1;
uint8_t dzk[72];
uint16_t csize; // = (size / 8 + ((size % 8) ? 1 : 0)) * (size); //得到字体一个字符对应点阵集所占的字节数
uint16_t font_widht = 0;
if (size != 12 && size != 16 && size != 24)
return; //不支持的size
uint16_t font_index = 0;
uint16_t stat = 0;
uint16_t *pBuf = malloc(sizeof(uint16_t) * size * size);
memset(pBuf, BACK_COLOR, (sizeof(uint16_t) * size * size));
switch (size) //获取字库
{
case 12:
U2G_GetData_12X12(utf_8_codeSet(font), dzk);
break;
case 16:
U2G_GetData_16X16(utf_8_codeSet(font), dzk);
break;
case 24:
U2G_GetData_24X24(utf_8_codeSet(font), dzk);
break;
default:
U2G_GetData_16X16(utf_8_codeSet(font), dzk);
break;
}
#if (1)
font_widht = size;
csize = size * size; //点阵数
font_widht = size;
temp = dzk[0]; //数值点阵
printf("\n %04d start \n", csize);
for (uint16_t t = 0; t < csize; t++)
{
if ((stat % 8 == 0) || (stat == font_widht))
{
if (stat == font_widht)
{
// printf("end = %04d -->\n",stat);
stat = 0;
}
else
{
// printf("<--head = %04d",stat);
}
temp = dzk[font_index++]; //数值点阵
}
stat++;
if (temp & 0x80)
{
pBuf[t] = POINT_COLOR; // pBuf[t] = EXC_Color(POINT_COLOR);
}
temp <<= 1;
}
//memset(pBuf, EXC_Color(POINT_COLOR), (sizeof(uint16_t) * size * size * 10));
LCD_queue_Windows_Fill(lcd_spi, x, y, (x + size), (y + size), pBuf);
printf("\n end\n ");
printf("font_index == %d\n", font_index);
if (pBuf != NULL)
free(pBuf);
#endif
}