Add display color inversion flag and logic for Feather TFT

This commit is contained in:
Adolfo Reyna
2026-01-30 23:02:53 -05:00
parent 45cbcc8384
commit d2fd001e70
4 changed files with 28 additions and 14 deletions

View File

@@ -6,8 +6,8 @@
#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), rgb_buffer(nullptr) {
LowLevelDisplayST7796::LowLevelDisplayST7796(const st7796_config* cfg, int w, int h, bool invert)
: config(cfg), width(w), height(h), initialized(false), rgb_buffer(nullptr), invert_color(invert) {
}
LowLevelDisplayST7796::~LowLevelDisplayST7796() {
@@ -38,26 +38,27 @@ bool LowLevelDisplayST7796::init() {
}
void LowLevelDisplayST7796::clear(bool white) {
st7796_fill(white ? COLOR_WHITE : COLOR_BLACK);
bool out_white = invert_color ? !white : white;
st7796_fill(out_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);
bool out_white = invert_color ? !white : white;
st7796_draw_pixel(x, y, out_white ? COLOR_WHITE : COLOR_BLACK);
}
void LowLevelDisplayST7796::draw_buffer(const uint8_t* bit_buffer) {
if (!bit_buffer || !rgb_buffer) return;
// 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;
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;
bool out_white = invert_color ? !pixel_white : pixel_white;
rgb_buffer[y * width + x] = out_white ? COLOR_WHITE : COLOR_BLACK;
}
}
// Draw entire buffer at once
st7796_set_cursor(0, 0);
st7796_write(rgb_buffer, width * height);