前言
点灯完毕后,下一步是点亮墨水屏,这次DIY的源码中已经提供了基础的墨水屏操作入口(初始化,画点,刷新显示),因此我们在前期使用时,并不需要关注怎么驱屏,只需要关注怎么更新显示内容即可。
另外,源码中有提供16 * 24版的GB2312和ASCII编码的字库,因此前期我们不必再去花心思找字库,转换字库,而可以直接使用。
而过程任务中,有要求显示“Hello EEPW & DigiKey”,因此就先按照显示此字串的目标来实现驱屏
代码编写
main.c
int main(void) {
system_init();
epd_init();
DEV_Delay_ms(2000);
main_EPD_test();
while (true) {
}
return 0;
}my_epd.cvoid clear_fb_point(int x, int y) { drawfb[OLED_H - x - 1][y] = 0; }
void draw_fb_ASCII(int x, int y, char word) {
const uint8_t *pData = epd2_get_font_16_24h(word);
unsigned char idxX, idxY;
int lineData;
for (idxY = 0; idxY < 24; idxY++) {
lineData = pData[idxY * 2 + 1];
lineData = lineData << 8;
lineData = lineData | pData[idxY * 2];
for (idxX = 0; idxX < 16; idxX++) {
if (lineData & (0x01 << idxX)) {
draw_fb_point(x + idxX, y + idxY);
} else {
clear_fb_point(x + idxX, y + idxY);
}
}
}
}
int My_strlen(char *data) {
int i = 0;
while (data[i]) {
i++;
}
return i;
}
void draw_fb(int x, int y, char *data) {
short int word;
int i, dataLen = My_strlen(data);
for (i = 0; i < dataLen;) {
if ((x + ASCII_FONT_H) > EPD_H) {
x = 0;
y += ASCII_FONT_W;
}
draw_fb_ASCII(x, y, data[i]);
x += ASCII_FONT_H;
i++;
}
}
int main_EPD_test(void) {
draw_fb(0, 20, "Hello EEPW & DigiKey");
// updata_to_epd(DISPLAY_ALL);
updata_to_epd(DISPLAY_PART);
return 0;
}epd2.h#define ASCII_FONT_H 16 #define ASCII_FONT_W 24 const uint8_t *epd2_get_font_16_24h(char word);epd2.c
const uint8_t *epd2_get_font_16_24h(char word)
{
return Font_16x24_h + (word - 0x20) * 48;
}遇到问题
单行显示内容超出截断
问题产生的原因其实很清晰,就是显示的内容长度超过了屏幕单行的长度,因此最简单的处理方法便是往buffer送前先判断一下数据是否会超过显示宽度,如果会超过,则更新送数据的位置。
最终效果

我要赚赏金
