Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vroland committed Sep 4, 2021
1 parent b9fc186 commit a9fa3bd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
15 changes: 8 additions & 7 deletions src/epd_driver/epd_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,18 @@ Coord_xy _rotate(uint16_t x, uint16_t y) {
}

void epd_draw_pixel(int x, int y, uint8_t color, uint8_t *framebuffer) {
if (x < 0 || x >= epd_rotated_display_width()) {
return;
}
if (y < 0 || y >= epd_rotated_display_height()) {
return;
}
// Check rotation and move pixel around if necessary
Coord_xy coord = _rotate(x, y);
x = coord.x;
y = coord.y;

if (x < 0 || x >= EPD_WIDTH) {
return;
}
if (y < 0 || y >= EPD_HEIGHT) {
return;
}

uint8_t *buf_ptr = &framebuffer[y * EPD_WIDTH / 2 + x / 2];
if (x % 2) {
*buf_ptr = (*buf_ptr & 0x0F) | (color & 0xF0);
Expand Down Expand Up @@ -418,7 +419,7 @@ int epd_rotated_display_height() {
return display_height;
}

uint8_t epd_get_pixel(int x, int y, int fb_width, int fb_height, const uint8_t *framebuffer) {
uint8_t epd_get_pixel(int x, int y, int fb_width, int fb_height, const uint8_t *framebuffer) {
if (x < 0 || x >= fb_width) {
return 0;
}
Expand Down
15 changes: 4 additions & 11 deletions src/epd_driver/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ static int uncompress(uint8_t *dest, uint32_t uncompressed_size, const uint8_t *
@brief Draw a single character to a pre-allocated buffer.
*/
static enum EpdDrawError IRAM_ATTR draw_char(const EpdFont *font, uint8_t *buffer,
int *cursor_x, int cursor_y, uint16_t buf_width,
uint16_t buf_height, uint32_t cp,
int *cursor_x, int cursor_y, uint32_t cp,
const EpdFontProperties *props) {

assert(props != NULL);
Expand Down Expand Up @@ -155,15 +154,12 @@ static enum EpdDrawError IRAM_ATTR draw_char(const EpdFont *font, uint8_t *buffe

for (int y = 0; y < height; y++) {
int yy = cursor_y - glyph->top + y;
if (yy < 0 || yy >= epd_rotated_display_height()) {
continue;
}
int start_pos = *cursor_x + left;
bool byte_complete = start_pos % 2;
int x = max(0, -start_pos);
int max_x = min(start_pos + width, buf_width * 2);
int max_x = start_pos + width;
uint8_t color;

for (int xx = start_pos; xx < max_x; xx++) {
uint8_t bm = bitmap[y * byte_width + x / 2];
if ((x & 1) == 0) {
Expand Down Expand Up @@ -291,8 +287,6 @@ static enum EpdDrawError epd_write_line(
return EPD_DRAW_NO_DRAWABLE_CHARACTERS;
}

int buf_width = EPD_WIDTH / 2;
int buf_height = EPD_HEIGHT;

uint8_t* buffer = framebuffer;
int local_cursor_x = *cursor_x;
Expand Down Expand Up @@ -327,8 +321,7 @@ static enum EpdDrawError epd_write_line(
}
enum EpdDrawError err = EPD_DRAW_SUCCESS;
while ((c = next_cp((const uint8_t **)&string))) {
err |= draw_char(font, buffer, &local_cursor_x, local_cursor_y, buf_width,
buf_height, c, &props);
err |= draw_char(font, buffer, &local_cursor_x, local_cursor_y, c, &props);
}

*cursor_x += local_cursor_x - cursor_x_init;
Expand Down
10 changes: 6 additions & 4 deletions src/epd_driver/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,10 @@ void epd_deinit() {

gpio_reset_pin(CKH);
rtc_gpio_isolate(CKH);
//gpio_reset_pin(CFG_INTR);
//rtc_gpio_isolate(CFG_INTR);
#endif
epd_base_deinit();
//epd_base_deinit();
}


Expand All @@ -310,7 +312,7 @@ EpdRect epd_difference_image_base(
// OR over all pixels of the "from"-image
*from_or = 0x00;
// AND over all pixels of the "from"-image
*from_and = 0xFF;
*from_and = 0x0F;

uint8_t dirty_cols[EPD_WIDTH] = {0};
int x_end = min(fb_width, crop_to.x + crop_to.width);
Expand All @@ -322,9 +324,9 @@ EpdRect epd_difference_image_base(
uint8_t t = *(to + y*fb_width / 2 + x / 2);
t = (x % 2) ? (t >> 4) : (t & 0x0f);
uint8_t f = *(from + y*fb_width / 2+ x / 2);
f = (x % 2) ? (f >> 4) : (f & 0x0f);
*from_or |= f;
*from_and &= f;
f = (x % 2) ? (f >> 4) : (f & 0x0f);
dirty |= (t ^ f);
dirty_cols[x] |= (t ^ f);
interlaced[y * fb_width + x] = (t << 4) | f;
Expand Down Expand Up @@ -378,7 +380,7 @@ EpdRect epd_difference_image_cropped(

EpdRect result = epd_difference_image_base(to, from, crop_to, EPD_WIDTH, EPD_HEIGHT, interlaced, dirty_lines, &from_or, &from_and);

if (previously_white != NULL) *previously_white = (from_and == 0xFF);
if (previously_white != NULL) *previously_white = (from_and == 0x0F);
if (previously_black != NULL) *previously_black = (from_or == 0x00);
return result;
}

0 comments on commit a9fa3bd

Please sign in to comment.