ESP32S2_Cal_Demo/main/lib/gdew042t2_epd.c

198 lines
6.3 KiB
C

#include "gdew042t2_epd.h"
static uint8_t gd_epd_042_grayscale_lut[5][44] = {
{ // VCOM -> 0x20
0x00, 0x0A, 0x00, 0x00, 0x00, 0x01,
0x60, 0x14, 0x14, 0x00, 0x00, 0x01,
0x00, 0x14, 0x00, 0x00, 0x00, 0x01,
0x00, 0x13, 0x0A, 0x01, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ // WW -> 0x21
0x40, 0x0A, 0x00, 0x00, 0x00, 0x01,
0x90, 0x14, 0x14, 0x00, 0x00, 0x01,
0x10, 0x14, 0x0A, 0x00, 0x00, 0x01,
0xA0, 0x13, 0x01, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ // BW -> 0x22
0x40, 0x0A, 0x00, 0x00, 0x00, 0x01,
0x90, 0x14, 0x14, 0x00, 0x00, 0x01,
0x00, 0x14, 0x0A, 0x00, 0x00, 0x01,
0x99, 0x0C, 0x01, 0x03, 0x04, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ // WB -> 0x23
0x40, 0x0A, 0x00, 0x00, 0x00, 0x01,
0x90, 0x14, 0x14, 0x00, 0x00, 0x01,
0x00, 0x14, 0x0A, 0x00, 0x00, 0x01,
0x99, 0x0B, 0x04, 0x04, 0x01, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{ // BB -> 0x24
0x80, 0x0A, 0x00, 0x00, 0x00, 0x01,
0x90, 0x14, 0x14, 0x00, 0x00, 0x01,
0x20, 0x14, 0x0A, 0x00, 0x00, 0x01,
0x50, 0x13, 0x01, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}
};
static uint8_t gd_epd_042_normal_lut[5][44] = {
{
0x00, 0x08, 0x00, 0x00, 0x00, 0x02,
0x60, 0x28, 0x28, 0x00, 0x00, 0x01,
0x00, 0x14, 0x00, 0x00, 0x00, 0x01,
0x00, 0x12, 0x12, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{
0x40, 0x08, 0x00, 0x00, 0x00, 0x02,
0x90, 0x28, 0x28, 0x00, 0x00, 0x01,
0x40, 0x14, 0x00, 0x00, 0x00, 0x01,
0xA0, 0x12, 0x12, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{
0x40, 0x17, 0x00, 0x00, 0x00, 0x02,
0x90, 0x0F, 0x0F, 0x00, 0x00, 0x03,
0x40, 0x0A, 0x01, 0x00, 0x00, 0x01,
0xA0, 0x0E, 0x0E, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{
0x80, 0x08, 0x00, 0x00, 0x00, 0x02,
0x90, 0x28, 0x28, 0x00, 0x00, 0x01,
0x80, 0x14, 0x00, 0x00, 0x00, 0x01,
0x50, 0x12, 0x12, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
{
0x80, 0x08, 0x00, 0x00, 0x00, 0x02,
0x90, 0x28, 0x28, 0x00, 0x00, 0x01,
0x80, 0x14, 0x00, 0x00, 0x00, 0x01,
0x50, 0x12, 0x12, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}
};
static uint8_t gd_epd_042_init_data_1[] = {
0x04, 0x01, 0x03, 0x00, 0x2B, 0x2B,
0x03, 0x06, 0x17, 0x17, 0x17,
0x00, 0x04,
};
static uint8_t gd_epd_042_init_data_2[] = {
0x02, 0x00, 0x3F, 0x0D,
0x01, 0x30, 0x3A,
0x04, 0x61, 0x01, 0x90, 0x01, 0x2C,
0x01, 0x82, 0x28,
0x01, 0x50, 0xF7,
};
#define GD_ERROR_CHECK(x) if(x != EPD_OK) return EPD_ERR
static gd_epd_042_ret_t _gd_epd_042_init_seq(gd_epd_042_t *epd) {
uint16_t i = 0;
while(i < sizeof(gd_epd_042_init_data_1)) {
GD_ERROR_CHECK(epd->cb.write_cmd_cb(epd->user_data, &gd_epd_042_init_data_1[i + 1], gd_epd_042_init_data_1[i] + 1));
i += gd_epd_042_init_data_1[i] + 2;
}
GD_ERROR_CHECK(epd->cb.poll_busy_cb(epd->user_data));
i = 0;
while(i < sizeof(gd_epd_042_init_data_2)) {
GD_ERROR_CHECK(epd->cb.write_cmd_cb(epd->user_data, &gd_epd_042_init_data_2[i + 1], gd_epd_042_init_data_2[i] + 1));
i += gd_epd_042_init_data_2[i] + 2;
}
return EPD_OK;
}
static gd_epd_042_ret_t _gd_epd_042_lut(gd_epd_042_t *epd) {
uint8_t cmd = 0x20;
uint8_t data_len[5] = { 44, 42, 42, 42, 42 };
for(uint8_t i = 0; i < 5; i++) {
GD_ERROR_CHECK(epd->cb.write_cmd_cb(epd->user_data, &cmd, 0x01));
GD_ERROR_CHECK(epd->cb.write_data_cb(epd->user_data, gd_epd_042_normal_lut[i], data_len[i]));
cmd++;
}
return EPD_OK;
}
static gd_epd_042_ret_t _gd_epd_042_reset(gd_epd_042_t *epd) {
return epd->cb.reset_cb(epd->user_data);
}
static gd_epd_042_ret_t _gd_epd_042_poll_busy(gd_epd_042_t *epd) {
uint8_t cmd = 0x71;
GD_ERROR_CHECK(epd->cb.write_cmd_cb(epd->user_data, &cmd, 0x01));
return epd->cb.poll_busy_cb(epd->user_data);
}
gd_epd_042_ret_t gd_epd_042_init(gd_epd_042_t *epd) {
GD_ERROR_CHECK(_gd_epd_042_reset(epd));
GD_ERROR_CHECK(_gd_epd_042_init_seq(epd));
GD_ERROR_CHECK(_gd_epd_042_lut(epd));
return EPD_OK;
}
gd_epd_042_ret_t gd_epd_042_deepsleep(gd_epd_042_t *epd) {
uint8_t tx_buf[3] = { 0x50, 0xF7 };
epd->cb.write_cmd_cb(epd->user_data, tx_buf, 0x02);
tx_buf[0] = 0x02;
epd->cb.write_cmd_cb(epd->user_data, tx_buf, 0x01);
GD_ERROR_CHECK(_gd_epd_042_poll_busy(epd));
tx_buf[0] = 0x07;
tx_buf[1] = 0xA5;
epd->cb.write_cmd_cb(epd->user_data, tx_buf, 0x01);
return EPD_OK;
}
gd_epd_042_ret_t gd_epd_042_load(gd_epd_042_t *epd, uint8_t *old_data, uint8_t *new_data) {
uint8_t tx_buf[2] = { 0x10 };
epd->cb.write_cmd_cb(epd->user_data, tx_buf, 0x01);
epd->cb.write_data_cb(epd->user_data, old_data, 400 * 300 / 8);
tx_buf[0] = 0x13;
epd->cb.write_cmd_cb(epd->user_data, tx_buf, 0x01);
epd->cb.write_data_cb(epd->user_data, new_data, 400 * 300 / 8);
return EPD_OK;
}
gd_epd_042_ret_t gd_epd_042_update(gd_epd_042_t *epd) {
uint8_t tx_buf[2] = { 0x12 };
epd->cb.write_cmd_cb(epd->user_data, tx_buf, 0x01);
GD_ERROR_CHECK(_gd_epd_042_poll_busy(epd));
return EPD_OK;
}