Skip to content

Commit

Permalink
complete fb variant demo
Browse files Browse the repository at this point in the history
  • Loading branch information
vroland committed Sep 3, 2024
1 parent a1049d6 commit 3c1aefc
Showing 1 changed file with 76 additions and 2 deletions.
78 changes: 76 additions & 2 deletions examples/fb_mode_test/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
* Visual tests for framebuffer modes that are not commonly used by the high-level API.
* Currently, includes 2 pixel per byte (ppB) with static origin color and 8ppB with static origin
* color.
*
* After running this, you should see two identical test images, with a "ladder" of black triangles
* next to a black rectangle with a ladder of white triangles on it.
*/

#include <esp_heap_caps.h>
#include <esp_log.h>
#include <esp_sleep.h>
#include <esp_timer.h>
#include <esp_types.h>
#include <esp_assert.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <epdiy.h>
Expand Down Expand Up @@ -61,7 +67,7 @@ void draw_8bpp_triangles(int start_line, int start_column) {

for (int align = 0; align < 16; align++) {
for (int height = 0; height < 16; height++) {
for (int len = 0; len < height; len++) {
for (int len = 0; len <= height; len++) {
int line = (start_line + 16 * align + height);
int column = align + len;
uint8_t* line_address = framebuffer + (line_bytes * line);
Expand All @@ -71,8 +77,27 @@ void draw_8bpp_triangles(int start_line, int start_column) {
}
}

/**
* Draw triangles at varying alignments into the framebuffer in 2ppB mode.
* start_line, start_column specify the start position.
* color specifies the color to draw in.
*/
void draw_2bpp_triangles(int start_line, int start_column, uint8_t color) {
int height = 16;

for (int align = 0; align < 16; align++) {
int x0 = start_column + align;
int y0 = start_line + height * align;
int x1 = x0;
int y1 = y0 + height - 1;
int x2 = x0 + height - 1;
int y2 = y0 + height - 1;

epd_fill_triangle(x0, y0, x1, y1, x2, y2, color, framebuffer);
}
}

void test_8ppB() {
clear();
EpdRect area = epd_full_screen();

// bytes in a line in 8ppB mode
Expand Down Expand Up @@ -105,18 +130,67 @@ void test_8ppB() {
epd_poweroff();
}

void test_2ppB() {
EpdRect area = epd_full_screen();
int start_column = 500;
int start_line = 100;

// draw differently aligned black triangles to check for uniformity
draw_2bpp_triangles(start_line, start_column, 0);

int black_start_column = start_column + 60;

// draw a black area
EpdRect black_area = { .x = black_start_column, .y = 100, .width = 256, .height = 300 };
epd_fill_rect(black_area, 0, framebuffer);

// draw white triangles on the black background
draw_2bpp_triangles(start_line, black_start_column + 16, 255);

// Do not overdraw the 8ppB image
uint8_t* drawn_columns = malloc(epd_width() / 2);
assert(drawn_columns != NULL);
memset(drawn_columns, 0, epd_width() / 2);
memset(drawn_columns + start_column / 2, 255, (epd_width() - start_column) / 2);

// update the display. In the first update, white pixels are no-opps,
// in the second update, black pixels are no-ops.
enum EpdDrawMode mode;
epd_poweron();
mode = MODE_PACKING_2PPB | MODE_DU | PREVIOUSLY_WHITE;
checkError(
epd_draw_base(area, framebuffer, area, mode, 25, NULL, drawn_columns, &epdiy_ED047TC2)
);
mode = MODE_PACKING_2PPB | MODE_DU | PREVIOUSLY_BLACK;
checkError(
epd_draw_base(area, framebuffer, area, mode, 25, NULL, drawn_columns, &epdiy_ED047TC2)
);
epd_poweroff();

free(drawn_columns);
}

void app_main() {
epd_init(&DEMO_BOARD, &ED060XC3, EPD_OPTIONS_DEFAULT);

// Set VCOM for boards that allow to set this in software (in mV).
// This will print an error if unsupported. In this case,
// set VCOM using the hardware potentiometer and delete this line.
epd_set_vcom(2100);

epd_set_lcd_pixel_clock_MHz(10);

fb_size = epd_width() * epd_height() / 2;
framebuffer = heap_caps_aligned_alloc(16, fb_size, MALLOC_CAP_SPIRAM);

clear();

test_8ppB();

memset(framebuffer, 0xFF, fb_size);

test_2ppB();

printf("going to sleep...\n");
epd_deinit();
esp_deep_sleep_start();
Expand Down

0 comments on commit 3c1aefc

Please sign in to comment.