abstracting display, touch and sd
This commit is contained in:
77
display/low_level_display_st7796.cpp
Normal file
77
display/low_level_display_st7796.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "low_level_display_st7796.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// RGB565 color definitions
|
||||
#define COLOR_BLACK 0x0000
|
||||
#define COLOR_WHITE 0xFFFF
|
||||
|
||||
LowLevelDisplayST7796::LowLevelDisplayST7796(const st7796_config* cfg, int w, int h)
|
||||
: config(cfg), width(w), height(h), initialized(false) {
|
||||
}
|
||||
|
||||
LowLevelDisplayST7796::~LowLevelDisplayST7796() {
|
||||
// Cleanup if needed
|
||||
}
|
||||
|
||||
bool LowLevelDisplayST7796::init() {
|
||||
if (initialized) {
|
||||
return true;
|
||||
}
|
||||
|
||||
st7796_init(config, width, height);
|
||||
initialized = true;
|
||||
printf("ST7796 display initialized: %dx%d\n", width, height);
|
||||
return true;
|
||||
}
|
||||
|
||||
void LowLevelDisplayST7796::clear(bool white) {
|
||||
st7796_fill(white ? COLOR_WHITE : COLOR_BLACK);
|
||||
}
|
||||
|
||||
void LowLevelDisplayST7796::draw_pixel(int x, int y, bool white) {
|
||||
st7796_draw_pixel(x, y, white ? COLOR_WHITE : COLOR_BLACK);
|
||||
}
|
||||
|
||||
void LowLevelDisplayST7796::draw_buffer(const uint8_t* bit_buffer) {
|
||||
if (!bit_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
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int byte_index = (y * width + x) / 8;
|
||||
int bit_index = 7 - (x % 8);
|
||||
bool pixel_white = (bit_buffer[byte_index] >> bit_index) & 0x01;
|
||||
rgb_buffer[y * width + x] = pixel_white ? COLOR_WHITE : COLOR_BLACK;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw entire buffer at once
|
||||
st7796_set_cursor(0, 0);
|
||||
st7796_write(rgb_buffer, width * height);
|
||||
|
||||
free(rgb_buffer);
|
||||
}
|
||||
|
||||
void LowLevelDisplayST7796::refresh() {
|
||||
// ST7796 updates immediately, no refresh needed
|
||||
}
|
||||
|
||||
void LowLevelDisplayST7796::set_backlight(bool on) {
|
||||
// ST7796 driver doesn't have backlight control yet
|
||||
// TODO: Add GPIO control for backlight pin
|
||||
(void)on;
|
||||
}
|
||||
|
||||
void LowLevelDisplayST7796::set_rotation(uint8_t rotation) {
|
||||
// ST7796 driver doesn't have rotation control yet
|
||||
// TODO: Add MADCTL register manipulation for rotation
|
||||
(void)rotation;
|
||||
}
|
||||
Reference in New Issue
Block a user