framebuffer things

This commit is contained in:
Dylan Smith
2026-01-15 16:49:53 -05:00
parent c77baa9724
commit 6711b5dcc1
7 changed files with 67 additions and 19 deletions

View File

@@ -1,4 +1,40 @@
#include "main.h"
#include "display.h"
__attribute__((section(".sdram")))
volatile pixel_t framebuffer[DISPLAY_HEIGHT * DISPLAY_WIDTH];
volatile pixel_t framebuffer1[DISPLAY_HEIGHT * DISPLAY_WIDTH];
volatile pixel_t framebuffer2[DISPLAY_HEIGHT * DISPLAY_WIDTH];
volatile pixel_t *current_framebuffer = framebuffer1;
volatile pixel_t *next_framebuffer = framebuffer2;
extern LTDC_HandleTypeDef hltdc;
extern DMA2D_HandleTypeDef hdma2d;
void HAL_LTDC_LineEventCallback(LTDC_HandleTypeDef *hltdc)
{
// Swap the LTDC's active framebuffer address to the back buffer
HAL_LTDC_SetAddress(hltdc, (uint32_t)current_framebuffer, 0);
// Clear the Line Interrupt pending bit
HAL_NVIC_DisableIRQ(LTDC_IRQn);
}
void copy_current_to_next_framebuffer(void)
{
for (uint32_t i = 0; i < DISPLAY_HEIGHT * DISPLAY_WIDTH; i++)
{
next_framebuffer[i] = current_framebuffer[i];
}
}
void swap_framebuffers(void)
{
volatile pixel_t *temp = current_framebuffer;
current_framebuffer = next_framebuffer;
next_framebuffer = temp;
HAL_LTDC_ProgramLineEvent(&hltdc, 296);
HAL_NVIC_EnableIRQ(LTDC_IRQn);
copy_current_to_next_framebuffer();
}

View File

@@ -1,4 +1,5 @@
#include "graphics.h"
#include "display.h"
void DisplayTest(pixel_t color)
{
@@ -6,7 +7,7 @@ void DisplayTest(pixel_t color)
{
for (uint16_t w = 0; w < DISPLAY_WIDTH; w++)
{
framebuffer[(h * DISPLAY_WIDTH) + w] = color;
next_framebuffer[(h * DISPLAY_WIDTH) + w] = color;
}
}
@@ -20,7 +21,7 @@ void DrawBox(uint32_t topleft_x_loc, uint32_t topleft_y_loc, uint32_t width, uin
{
if (x < DISPLAY_WIDTH && y < DISPLAY_HEIGHT)
{
framebuffer[(y * DISPLAY_WIDTH) + x] = color;
next_framebuffer[(y * DISPLAY_WIDTH) + x] = color;
}
}
}

View File

@@ -6,10 +6,10 @@
static const uint16_t entry_height = 40;
static const uint16_t padding_x = 10;
static const uint16_t padding_y = 0;
static const pixel_t enabled_text_color = MAKE_PIXEL(0, 0, 0);
static const pixel_t enabled_text_color = MAKE_PIXEL(255, 255, 255);
static const pixel_t disabled_text_color = MAKE_PIXEL(128, 128, 128);
static const pixel_t entry_bg_color = MAKE_PIXEL(255, 255, 255);
static const pixel_t highlighted_bg_color = MAKE_PIXEL(0, 0, 0);
static const pixel_t entry_bg_color = MAKE_PIXEL(0, 0, 0);
static const pixel_t highlighted_bg_color = MAKE_PIXEL(50, 50, 50);
static const pixel_t highlighted_text_color = MAKE_PIXEL(255, 255, 0);
void draw_menu_entry(volatile pixel_t *const framebuffer, const graphical_menu_t *const menu, uint8_t entry_idx)
@@ -112,7 +112,7 @@ void set_selected_menu_entry_idx(volatile pixel_t *const framebuffer, graphical_
partial_redraw_menu(framebuffer, menu, old_highlighted_entry_idx, idx);
}
void decrement_selected_menu_entry_idx(graphical_menu_t *const menu)
void decrement_selected_menu_entry_idx(volatile pixel_t *const framebuffer, graphical_menu_t *const menu)
{
if (menu->selected_entry_idx == 0)
{
@@ -122,7 +122,7 @@ void decrement_selected_menu_entry_idx(graphical_menu_t *const menu)
set_selected_menu_entry_idx(framebuffer, menu, menu->selected_entry_idx - 1);
}
void increment_selected_menu_entry_idx(graphical_menu_t *const menu)
void increment_selected_menu_entry_idx(volatile pixel_t *const framebuffer, graphical_menu_t *const menu)
{
if (menu->selected_entry_idx == menu->layout->num_entries - 1)
{