11#include " display.h"
2- #include " font5x7.h"
3- #include " nvs_settings.h"
4- #include " esp_log.h"
5- #include " esp_heap_caps.h"
62
73#include < hub75.h>
84
5+ #include " esp_heap_caps.h"
6+ #include " esp_log.h"
7+ #include " font5x7.h"
8+ #include " nvs_settings.h"
9+
910static Hub75Driver *_matrix;
1011static uint8_t _brightness = (CONFIG_HUB75_BRIGHTNESS * 100 ) / 255 ;
1112static const char *TAG = " display" ;
@@ -17,7 +18,8 @@ static uint32_t *_scaled_buffer = NULL;
1718int display_initialize (void ) {
1819#if CONFIG_HUB75_PANEL_WIDTH == 128 && CONFIG_HUB75_PANEL_HEIGHT == 64
1920 if (_scaled_buffer == NULL ) {
20- _scaled_buffer = (uint32_t *)heap_caps_malloc (128 * 64 * 4 , MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
21+ _scaled_buffer = (uint32_t *)heap_caps_malloc (
22+ 128 * 64 * 4 , MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
2123 if (_scaled_buffer == NULL ) {
2224 ESP_LOGE (TAG, " Failed to allocate scaled buffer in PSRAM" );
2325 return 1 ;
@@ -29,7 +31,8 @@ int display_initialize(void) {
2931 bool swap_colors = nvs_get_swap_colors ();
3032
3133 // Initialize pin values based on hardware and swap_colors setting
32- ESP_LOGI (TAG, " Initializing display with swap_colors=%s" , swap_colors ? " true" : " false" );
34+ ESP_LOGI (TAG, " Initializing display with swap_colors=%s" ,
35+ swap_colors ? " true" : " false" );
3336
3437 // Initialize the panel.
3538 Hub75Config mxconfig;
@@ -123,7 +126,7 @@ int display_initialize(void) {
123126 mxconfig.pins .b2 = 39 ;
124127 }
125128 ESP_LOGI (TAG, " Board preset: MatrixPortal S3" );
126- #else // GEN1 from here down.
129+ #else // GEN1 from here down.
127130 mxconfig.pins .a = 26 ;
128131 mxconfig.pins .b = 5 ;
129132 mxconfig.pins .c = 25 ;
@@ -236,7 +239,8 @@ int display_initialize(void) {
236239
237240static inline uint8_t brightness_percent_to_8bit (uint8_t pct) {
238241 if (pct > 100 ) pct = 100 ;
239- return (uint8_t )(((uint32_t )pct * 230 + 50 ) / 100 ); // 230 as MAX 8 BIT HARDCODED
242+ return (uint8_t )(((uint32_t )pct * 230 + 50 ) /
243+ 100 ); // 230 as MAX 8 BIT HARDCODED
240244}
241245
242246void display_set_brightness (uint8_t brightness_pct) {
@@ -247,11 +251,13 @@ void display_set_brightness(uint8_t brightness_pct) {
247251 uint8_t max_brightness_8bit = MAX_BRIGHTNESS_8BIT;
248252 if (brightness_8bit > max_brightness_8bit) {
249253 brightness_8bit = max_brightness_8bit;
250- ESP_LOGI (TAG, " Clamping brightness to MAX_BRIGHTNESS (%d)" , MAX_BRIGHTNESS_8BIT);
254+ ESP_LOGI (TAG, " Clamping brightness to MAX_BRIGHTNESS (%d)" ,
255+ MAX_BRIGHTNESS_8BIT);
251256 }
252257#endif
253258
254- ESP_LOGI (TAG, " Setting brightness to %d%% (%d)" , brightness_pct, brightness_8bit);
259+ ESP_LOGI (TAG, " Setting brightness to %d%% (%d)" , brightness_pct,
260+ brightness_8bit);
255261 _matrix->set_brightness (brightness_8bit);
256262 _matrix->clear ();
257263 _brightness = brightness_pct;
@@ -283,14 +289,16 @@ void display_draw(const uint8_t *pix, int width, int height) {
283289 }
284290 }
285291
286- _matrix->draw_pixels (0 , 0 , 128 , 64 , (uint8_t *)_scaled_buffer, Hub75PixelFormat::RGB888_32, Hub75ColorOrder::BGR);
292+ _matrix->draw_pixels (0 , 0 , 128 , 64 , (uint8_t *)_scaled_buffer,
293+ Hub75PixelFormat::RGB888_32, Hub75ColorOrder::BGR);
287294 _matrix->flip_buffer ();
288295 return ;
289296 }
290297#endif
291298
292299 // Default path: bulk transfer for native resolution
293- _matrix->draw_pixels (0 , 0 , width, height, pix, Hub75PixelFormat::RGB888_32, Hub75ColorOrder::BGR);
300+ _matrix->draw_pixels (0 , 0 , width, height, pix, Hub75PixelFormat::RGB888_32,
301+ Hub75ColorOrder::BGR);
294302 _matrix->flip_buffer ();
295303}
296304
@@ -303,18 +311,18 @@ void display_draw_pixel(int x, int y, uint8_t r, uint8_t g, uint8_t b) {
303311 }
304312}
305313
306- void display_fill_rect (int x, int y, int w, int h, uint8_t r, uint8_t g, uint8_t b) {
314+ void display_fill_rect (int x, int y, int w, int h, uint8_t r, uint8_t g,
315+ uint8_t b) {
307316 if (_matrix != NULL ) {
308317 _matrix->fill (x, y, w, h, r, g, b);
309318 // Note: No flip here, caller must flip
310319 }
311320}
312321
313- void draw_error_indicator_pixel (void ) {
314- display_draw_pixel (0 , 0 , 100 , 0 , 0 );
315- }
322+ void draw_error_indicator_pixel (void ) { display_draw_pixel (0 , 0 , 100 , 0 , 0 ); }
316323
317- void display_text (const char * text, int x, int y, uint8_t r, uint8_t g, uint8_t b, int scale) {
324+ void display_text (const char *text, int x, int y, uint8_t r, uint8_t g,
325+ uint8_t b, int scale) {
318326 if (_matrix == NULL || text == NULL ) {
319327 return ;
320328 }
@@ -328,12 +336,12 @@ void display_text(const char* text, int x, int y, uint8_t r, uint8_t g, uint8_t
328336
329337 // Check if character is in font range
330338 if (c < FONT5X7_FIRST_CHAR || c > FONT5X7_LAST_CHAR) {
331- c = ' ' ; // Replace unsupported characters with space
339+ c = ' ' ; // Replace unsupported characters with space
332340 }
333341
334342 // Get font data for this character
335343 int char_index = c - FONT5X7_FIRST_CHAR;
336- const uint8_t * char_data = font5x7[char_index];
344+ const uint8_t * char_data = font5x7[char_index];
337345
338346 // Draw each column of the character
339347 for (int col = 0 ; col < FONT5X7_CHAR_WIDTH; col++) {
@@ -346,14 +354,15 @@ void display_text(const char* text, int x, int y, uint8_t r, uint8_t g, uint8_t
346354 int py = cursor_y + (row * scale);
347355
348356 if (scale > 1 ) {
349- // Optimize scaled text using fill
350- _matrix->fill (px, py, scale, scale, r, g, b);
357+ // Optimize scaled text using fill
358+ _matrix->fill (px, py, scale, scale, r, g, b);
351359 } else {
352- // Draw pixel(s) based on scale
353- // Check bounds
354- if (px >= 0 && px < CONFIG_HUB75_PANEL_WIDTH && py >= 0 && py < CONFIG_HUB75_PANEL_HEIGHT) {
355- _matrix->set_pixel (px, py, r, g, b);
356- }
360+ // Draw pixel(s) based on scale
361+ // Check bounds
362+ if (px >= 0 && px < CONFIG_HUB75_PANEL_WIDTH && py >= 0 &&
363+ py < CONFIG_HUB75_PANEL_HEIGHT) {
364+ _matrix->set_pixel (px, py, r, g, b);
365+ }
357366 }
358367 }
359368 }
0 commit comments