tic tac toe works on touch and eink

This commit is contained in:
Adolfo Reyna
2026-01-29 17:16:59 -05:00
parent 372895fa08
commit 435a5caa56
7 changed files with 450 additions and 145 deletions

View File

@@ -7,11 +7,14 @@
#define COLOR_WHITE 0xFFFF
LowLevelDisplayST7796::LowLevelDisplayST7796(const st7796_config* cfg, int w, int h)
: config(cfg), width(w), height(h), initialized(false) {
: config(cfg), width(w), height(h), initialized(false), rgb_buffer(nullptr) {
}
LowLevelDisplayST7796::~LowLevelDisplayST7796() {
// Cleanup if needed
if (rgb_buffer) {
free(rgb_buffer);
rgb_buffer = nullptr;
}
}
bool LowLevelDisplayST7796::init() {
@@ -20,8 +23,17 @@ bool LowLevelDisplayST7796::init() {
}
st7796_init(config, width, height);
// Allocate RGB565 buffer once (reused for all draw operations)
size_t buffer_size = width * height * sizeof(uint16_t);
rgb_buffer = (uint16_t *)malloc(buffer_size);
if (!rgb_buffer) {
printf("Error: Failed to allocate %zu bytes for RGB buffer\n", buffer_size);
return false;
}
printf("ST7796 display initialized: %dx%d (RGB buffer: %zu bytes)\n", width, height, buffer_size);
initialized = true;
printf("ST7796 display initialized: %dx%d\n", width, height);
return true;
}
@@ -34,16 +46,9 @@ void LowLevelDisplayST7796::draw_pixel(int x, int y, bool white) {
}
void LowLevelDisplayST7796::draw_buffer(const uint8_t* bit_buffer) {
if (!bit_buffer) return;
if (!bit_buffer || !rgb_buffer) return;
// Allocate RGB565 buffer for entire screen
uint16_t *rgb_buffer = (uint16_t *)malloc(width * height * sizeof(uint16_t));
if (!rgb_buffer) {
printf("Error: Failed to allocate RGB buffer\n");
return;
}
// Convert 1-bit buffer to RGB565
// Convert 1-bit buffer to RGB565 using persistent buffer
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int byte_index = (y * width + x) / 8;
@@ -56,8 +61,6 @@ void LowLevelDisplayST7796::draw_buffer(const uint8_t* bit_buffer) {
// Draw entire buffer at once
st7796_set_cursor(0, 0);
st7796_write(rgb_buffer, width * height);
free(rgb_buffer);
}
void LowLevelDisplayST7796::refresh() {