Files
Dual-PID/JC_Display_Firmware/display_hal.cpp
raw-designs 453644816f Initiale Bereitstellung
Initiale Bereitstellung der aktuellen Version auf Gitea
2026-07-10 18:13:43 +02:00

77 lines
3.2 KiB
C++

// =====================================================================================
// display_hal.cpp - LVGL-Glue fuer das JC4880P443C-I-W
// =====================================================================================
// Realer Modus: nutzt die Hersteller-Portierung. Der eigentliche esp_lcd-Bringup liegt
// bewusst in board_bringup.c (C). Hier nur die LVGL-/UI-Verdrahtung.
// =====================================================================================
#include <Arduino.h>
#include <lvgl.h>
#include "display_hal.h"
#include "ui.h"
#include "config.h"
static ProtocolClient* g_client = nullptr;
// =====================================================================================
#if JC_USE_REAL_PANEL
// =====================================================================================
// ECHTE HARDWARE - Bringup in board_bringup.c, LVGL-Mutex im Hersteller-Port.
// =====================================================================================
extern "C" {
void jc_board_bringup(void); // board_bringup.c
void jc_backlight_set(int percent); // board_bringup.c
bool lvgl_port_lock(int timeout_ms); // lvgl_port_v9.c (Vendor-BSP)
void lvgl_port_unlock(void); // lvgl_port_v9.c (Vendor-BSP)
}
void hal_init(ProtocolClient* client) {
g_client = client;
jc_board_bringup(); // Panel + Touch + LVGL-Port (eigener Task)
jc_backlight_set(100);
if (lvgl_port_lock(-1)) { // UI im LVGL-Kontext aufbauen
ui_init(g_client);
lvgl_port_unlock();
}
}
void hal_loop() { /* LVGL laeuft im Port-Task - hier nichts zu tun. */ }
void hal_lock() { lvgl_port_lock(-1); }
void hal_unlock(){ lvgl_port_unlock(); }
void hal_backlight(int percent) { jc_backlight_set(percent); }
// =====================================================================================
#else // JC_USE_REAL_PANEL == 0
// =====================================================================================
// STUB-MODUS - minimales LVGL ohne Panel/Touch (zum Testen von Protokoll/Logik).
// =====================================================================================
#define HAL_BUF_LINES 40
#define HAL_BYTES_PER_PX 2
static uint8_t s_buf1[DISP_HOR_RES * HAL_BUF_LINES * HAL_BYTES_PER_PX];
static lv_display_t* s_disp = nullptr;
static uint32_t hal_tick_cb(void) { return (uint32_t)millis(); }
static void stub_flush_cb(lv_display_t* disp, const lv_area_t* area, uint8_t* px_map) {
(void)area; (void)px_map;
lv_display_flush_ready(disp); // Pixel werden verworfen (kein Panel)
}
void hal_init(ProtocolClient* client) {
g_client = client;
lv_init();
lv_tick_set_cb(hal_tick_cb);
s_disp = lv_display_create(DISP_HOR_RES, DISP_VER_RES);
lv_display_set_flush_cb(s_disp, stub_flush_cb);
lv_display_set_buffers(s_disp, s_buf1, nullptr, sizeof(s_buf1),
LV_DISPLAY_RENDER_MODE_PARTIAL);
ui_init(g_client);
}
void hal_loop() { lv_timer_handler(); }
void hal_lock() { /* kein Port-Task -> kein Lock noetig */ }
void hal_unlock(){ }
void hal_backlight(int percent) { (void)percent; /* kein Panel im Stub-Modus */ }
#endif // JC_USE_REAL_PANEL