bw add partial mode example

This commit is contained in:
YXZhu
2022-12-07 23:29:42 +08:00
parent 3d33fc591c
commit 1e12291272
31 changed files with 4117 additions and 3648 deletions
@@ -22,6 +22,30 @@
EPD_PAINT EPD_Paint;
static uint8_t _hibernating = 1;
static const unsigned char ut_partial[] =
{
0x0, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x80, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x40, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0A, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2,
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x0, 0x0, 0x0,
};
void epd_delay(uint16_t ms)
{
delay(ms);
@@ -141,13 +165,6 @@ void epd_write_data(uint8_t data)
epd_cs_set();
}
void epd_read_data(uint8_t reg, uint8_t *data, uint8_t length)
{
epd_cs_reset();
epd_cs_set();
}
void _epd_write_data(uint8_t data)
{
@@ -176,12 +193,20 @@ uint8_t epd_wait_busy()
}
return 0;
}
uint8_t epd_init(void)
void epd_reset(void)
{
epd_res_reset();
epd_delay(50);
epd_res_set();
epd_delay(50);
_hibernating = 0;
}
uint8_t epd_init(void)
{
if (_hibernating)
epd_reset();
if (epd_wait_busy())
return 1;
@@ -231,10 +256,28 @@ uint8_t epd_init(void)
return 0;
}
uint8_t epd_init_partial(void)
{
if (epd_init())
return 1;
epd_write_reg(0x32);
epd_cs_reset();
for (int j = 0; j < sizeof(ut_partial); j++)
{
_epd_write_data(ut_partial[j]);
}
_epd_write_data_over();
epd_cs_set();
return 0;
}
void epd_enter_deepsleepmode(uint8_t mode)
{
epd_write_reg(0x10);
epd_write_data(mode);
_hibernating = 1;
}
void epd_init_internalTempSensor(void)
@@ -246,34 +289,20 @@ void epd_init_internalTempSensor(void)
epd_write_data(0x7F);
epd_write_data(0xF0);
}
uint8_t data[3];
int32_t epd_get_internalTempSensor(void)
{
uint32_t temp;
epd_read_data(0x1B, data, 3);
temp = data[0];
temp = temp << 4 | data[1] >> 4;
if (temp & (1 << 11))
{
temp = (((~temp) & 0xfff) + 1) * 10 / 16;
temp = -temp;
}
else
{
temp = temp * 10 / 16;
}
return temp;
}
void epd_update(void)
{
{
epd_write_reg(0x22); // Display Update Control
epd_write_data(0xF7);
// epd_write_data(0xFF);
epd_write_reg(0x20); // Activate Display Update Sequence
epd_wait_busy();
}
void epd_update_partial(void)
{
epd_write_reg(0x22); // Display Update Control
epd_write_data(0xCC);
epd_write_reg(0x20); // Activate Display Update Sequence
epd_wait_busy();
@@ -295,26 +324,31 @@ void epd_setpos(uint16_t x, uint16_t y)
epd_write_data(_y >> 8 & 0x01);
}
void epd_writedata(uint8_t *Image1, uint32_t length)
{
epd_cs_reset();
for (uint32_t j = 0; j < length; j++)
{
_epd_write_data(Image1[j]);
}
_epd_write_data_over();
epd_cs_set();
}
void epd_display(uint8_t *Image1, uint8_t *Image2)
{
uint32_t Width, Height, i, j;
uint32_t k = 0;
Width = EPD_H;
Height = EPD_W_BUFF_SIZE;
epd_setpos(0, 0);
epd_write_reg(0x24);
epd_cs_reset();
for (j = 0; j < Height; j++)
{
for (i = 0; i < Width; i++)
{
_epd_write_data(Image1[k]);
k++;
}
}
_epd_write_data_over();
epd_cs_set();
epd_writedata(Image1, Width * Height);
epd_setpos(0, 0);
epd_write_reg(0x26);
k = 0;
epd_cs_reset();
@@ -328,50 +362,58 @@ void epd_display(uint8_t *Image1, uint8_t *Image2)
}
_epd_write_data_over();
epd_cs_set();
epd_update();
}
void epd_displayBW(uint8_t *Image)
{
uint32_t Width, Height, i, j;
uint32_t k = 0;
uint32_t Width, Height;
Width = EPD_H;
Height = EPD_W_BUFF_SIZE;
epd_setpos(0, 0);
epd_write_reg(0x26);
epd_writedata(Image, Width * Height);
epd_setpos(0, 0);
epd_write_reg(0x24);
epd_cs_reset();
for (j = 0; j < Height; j++)
{
for (i = 0; i < Width; i++)
{
_epd_write_data(Image[k]);
k++;
}
}
_epd_write_data_over();
epd_cs_set();
epd_writedata(Image, Width * Height);
epd_update();
}
void epd_displayBW_partial(uint8_t *Image)
{
uint32_t Width, Height;
Width = EPD_H;
Height = EPD_W_BUFF_SIZE;
epd_setpos(0, 0);
epd_write_reg(0x24);
epd_writedata(Image, Width * Height);
epd_update_partial();
epd_setpos(0, 0);
epd_write_reg(0x26);
epd_writedata(Image, Width * Height);
}
void epd_displayRED(uint8_t *Image)
{
uint32_t Width, Height, i, j;
uint32_t k = 0;
uint32_t Width, Height;
Width = EPD_H;
Height = EPD_W_BUFF_SIZE;
epd_setpos(0, 0);
epd_write_reg(0x26);
epd_cs_reset();
for (j = 0; j < Height; j++)
{
for (i = 0; i < Width; i++)
{
_epd_write_data(Image[k]);
k++;
}
}
_epd_write_data_over();
epd_cs_set();
epd_writedata(Image, Width * Height);
epd_update();
}
@@ -62,12 +62,14 @@ extern "C"
void epd_io_init(void);
uint8_t epd_init(void);
uint8_t epd_init_partial(void);
void epd_enter_deepsleepmode(uint8_t mode);
void epd_init_internalTempSensor(void);
int32_t epd_get_internalTempSensor(void);
void epd_update(void);
void epd_update_partial(void);
void epd_display(uint8_t *Image1, uint8_t *Image2);
void epd_displayBW(uint8_t *Image);
void epd_displayBW_partial(uint8_t *Image);
void epd_displayRED(uint8_t *Image);
void epd_paint_newimage(uint8_t *image, uint16_t Width, uint16_t Height, uint16_t Rotate, uint16_t Color);
+31 -4
View File
@@ -68,9 +68,12 @@ int main(void)
epd_paint_showPicture((EPD_H - 250) / 2, (EPD_W - 122) / 2, 250, 122, gImage_4, EPD_COLOR_WHITE);
epd_display(image_bw, image_red);
epd_enter_deepsleepmode(EPD_DEEPSLEEP_MODE1);
delay(8000);
epd_init();
epd_paint_selectimage(image_bw);
epd_paint_clear(EPD_COLOR_WHITE);
#ifdef EPD_213
@@ -104,9 +107,12 @@ int main(void)
epd_paint_showPicture((EPD_H - 250) / 2, (EPD_W - 122) / 2, 250, 122, gImage_4, EPD_COLOR_WHITE);
epd_displayBW(image_bw);
epd_enter_deepsleepmode(EPD_DEEPSLEEP_MODE1);
delay(5000);
epd_init_partial();
epd_paint_selectimage(image_bw);
epd_paint_clear(EPD_COLOR_WHITE);
#ifdef EPD_213
@@ -119,15 +125,36 @@ int main(void)
#endif
epd_paint_showString(10, 29, (uint8_t *)&"Designed By WeAct Studio", EPD_FONT_SIZE16x8, EPD_COLOR_BLACK);
sprintf((char *)&text, ">> Hello World.");
epd_paint_showString(10, 71, text, EPD_FONT_SIZE24x12, EPD_COLOR_BLACK);
#if 0
epd_paint_showString(10,100,(uint8_t *)&"CH32V103C8T6 Example",EPD_FONT_SIZE16x8,EPD_COLOR_BLACK);
#else
epd_paint_drawRectangle(10, 103, EPD_H - 10, 116, EPD_COLOR_BLACK, 1);
#endif
epd_displayBW(image_bw);
sprintf((char *)&text, ">> Partial Mode");
epd_paint_showString(10, 71, text, EPD_FONT_SIZE24x12, EPD_COLOR_BLACK);
epd_displayBW_partial(image_bw);
delay(1000);
for (uint32_t i = 123; i < 8 * 123; i += 123)
{
sprintf((char *)&text, ">> Num=%d ", i);
epd_paint_showString(10, 71, text, EPD_FONT_SIZE24x12, EPD_COLOR_BLACK);
epd_displayBW_partial(image_bw);
delay(100);
}
sprintf((char *)&text, ">> Hello World.");
epd_paint_showString(10, 71, text, EPD_FONT_SIZE24x12, EPD_COLOR_BLACK);
epd_displayBW_partial(image_bw);
delay(1000);
epd_update();
#endif
epd_enter_deepsleepmode(EPD_DEEPSLEEP_MODE1);