Skip to content

Commit e171791

Browse files
committed
Disabled TE signal handling for now, disabled building of LVGL demos and examples, formatting and small adjustments
1 parent c3be4a8 commit e171791

File tree

6 files changed

+130
-129
lines changed

6 files changed

+130
-129
lines changed

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ SortIncludes: false
1818
Cpp11BracedListStyle: true
1919
ColumnLimit: 120
2020
AllowShortFunctionsOnASingleLine: false
21+
AlignConsecutiveAssignments: Consecutive

Firmware/CMakeLists.deps.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
include(FetchContent)
22
set(FETCHCONTENT_QUIET FALSE)
33
set(FETCHCONTENT_BASE_DIR "${CMAKE_SOURCE_DIR}/3rdParty")
4+
45
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
6+
57
# Fetch LVGL
8+
set(CONFIG_LV_BUILD_EXAMPLES OFF CACHE BOOL "Disable LVGL examples" FORCE)
9+
set(CONFIG_LV_BUILD_DEMOS OFF CACHE BOOL "Disable LVGL demos" FORCE)
10+
611
FetchContent_Declare(
712
lvgl
813
GIT_REPOSITORY https://github.com/lvgl/lvgl.git
914
GIT_TAG master
1015
)
1116
FetchContent_MakeAvailable(lvgl)
12-
13-
#set(CONFIG_LV_BUILD_DEMOS OFF) # for demos
14-
#set(CONFIG_LV_BUILD_EXAMPLES OFF) # for examples
15-
#set(CONFIG_LV_USE_THORVG_INTERNAL OFF) # for ThorVG
16-
17-
set(CONFIG_LV_BUILD_EXAMPLES OFF CACHE BOOL "Disable LVGL examples")
18-
set(CONFIG_LV_BUILD_DEMOS OFF CACHE BOOL "Disable LVGL demos")

Firmware/lv_conf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
*====================*/
8989

9090
/** Default display refresh, input device read and animation step period. */
91-
#define LV_DEF_REFR_PERIOD 33 /**< [ms] */
91+
#define LV_DEF_REFR_PERIOD 5 /**< [ms] */
9292

9393
/** Default Dots Per Inch. Used to initialize default sizes such as widgets sized, style paddings.
9494
* (Not so important, you can adjust it to modify default sizes and spaces.) */
@@ -755,7 +755,7 @@
755755

756756
#define LV_USE_CALENDAR 1
757757
#if LV_USE_CALENDAR
758-
#define LV_CALENDAR_WEEK_STARTS_MONDAY 0
758+
#define LV_CALENDAR_WEEK_STARTS_MONDAY 1
759759
#if LV_CALENDAR_WEEK_STARTS_MONDAY
760760
#define LV_CALENDAR_DEFAULT_DAY_NAMES {"Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"}
761761
#else

Firmware/src/Main.cpp

Lines changed: 65 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
extern "C" {
2222
#endif
2323

24+
#define DEBUG 1
25+
2426
/**
2527
* @brief A custom idle percentage function for LVGL's system monitor.
2628
* Since we are on a bare-metal system without a full OS to track idle time,
@@ -47,8 +49,8 @@ extern volatile bool g_request_lvgl_refresh;
4749

4850
std::unique_ptr<LvglUI> lvglUI;
4951

50-
const int LVGL_TICK_PERIOD_MS = 5; // Original
51-
// const int LVGL_TICK_PERIOD_MS = 17; // Adjusted to match LV_DEF_REFR_PERIOD,
52+
// const int LVGL_TICK_PERIOD_MS = 10; // Original
53+
const int LVGL_TICK_PERIOD_MS = 5; // Adjusted to match LV_DEF_REFR_PERIOD,
5254
// or try 15ms
5355

5456
bool repeating_timer_callback(struct repeating_timer* t)
@@ -137,6 +139,12 @@ void ParseAndProcessCommand(const char* command_str)
137139
}
138140
}
139141

142+
uint32_t my_get_millis(void)
143+
{
144+
return timer_hw->timelr / 1000.0f;
145+
// return (timer_hw->timehr << 32 | timer_hw->timelr) / 1000.0f;
146+
}
147+
140148
int main()
141149
{
142150
stdio_init_all(); // Initialize all stdio (USB, UART, etc.)
@@ -190,31 +198,30 @@ int main()
190198
return -1;
191199
}
192200
printf("LvglUI created.\n");
201+
lv_tick_set_cb(my_get_millis);
193202

194203
// 4. Initialize Theme (if separate from LvglUI creation)
195-
InitializeTheme(); // Make sure this is defined and works
196-
printf("Theme Initialized.\n");
197-
204+
InitializeTheme(); // Make sure this is defined and
198205
// Explicitly invalidate the screen after all UI and theme initialization.
199206
// This ensures that lv_task_handler() or lv_refr_now() sees a dirty screen
200207
// for the first frame.
201-
if (platformDriver && platformDriver->GetLvDisplay()) {
202-
lv_display_t* disp_to_invalidate = platformDriver->GetLvDisplay();
203-
lv_obj_t* active_screen_on_disp = lv_display_get_screen_active(disp_to_invalidate);
204-
if (active_screen_on_disp) {
205-
lv_obj_invalidate(active_screen_on_disp);
206-
printf("Main.cpp: Active screen on display explicitly invalidated for "
207-
"initial draw.\n");
208-
}
209-
}
210-
static struct repeating_timer lvgl_tick_timer;
211-
if (!add_repeating_timer_ms(-LVGL_TICK_PERIOD_MS, // Negative for repeating, positive for one-shot
212-
repeating_timer_callback,
213-
NULL, // No user data passed to callback
214-
&lvgl_tick_timer)) {
215-
printf("FATAL: Failed to add LVGL tick timer\n");
216-
// Handle error, perhaps by falling back to main loop ticking or halting
217-
}
208+
// if (platformDriver && platformDriver->GetLvDisplay()) {
209+
// lv_display_t* disp_to_invalidate = platformDriver->GetLvDisplay();
210+
// lv_obj_t* active_screen_on_disp = lv_display_get_screen_active(disp_to_invalidate);
211+
// if (active_screen_on_disp) {
212+
// lv_obj_invalidate(active_screen_on_disp);
213+
// printf("Main.cpp: Active screen on display explicitly invalidated for "
214+
// "initial draw.\n");
215+
// }
216+
// }
217+
// static struct repeating_timer lvgl_tick_timer;
218+
// if (!add_repeating_timer_ms(LVGL_TICK_PERIOD_MS, // Negative for repeating, positive for one-shot
219+
// repeating_timer_callback,
220+
// NULL, // No user data passed to callback
221+
// &lvgl_tick_timer)) {
222+
// printf("FATAL: Failed to add LVGL tick timer\n");
223+
// // Handle error, perhaps by falling back to main loop ticking or halting
224+
// }
218225

219226
// setup_fps_display(); // Create the FPS label
220227
// fps_last_update_time = std::chrono::steady_clock::now(); // Initialize FPS
@@ -223,68 +230,48 @@ int main()
223230
// --- Main Loop ---
224231
printf("Entering main loop...\n");
225232
while (true) {
226-
// --- Handle Serial Input ---
227-
int c = getchar_timeout_us(0); // Poll USB, no timeout
228-
while (c != PICO_ERROR_TIMEOUT) {
229-
if (c == '\n' || c == '\r') { // End of command
230-
if (cmd_buffer_idx > 0) {
231-
cmd_buffer[cmd_buffer_idx] = '\0'; // Null terminate
232-
// printf("RX: %s\n", cmd_buffer); // Echo received command
233-
ParseAndProcessCommand(cmd_buffer);
234-
}
235-
cmd_buffer_idx = 0; // Reset buffer
236-
}
237-
else if (cmd_buffer_idx < CMD_BUFFER_SIZE - 1 && c >= 32 && c < 127) {
238-
// Store printable characters
239-
cmd_buffer[cmd_buffer_idx++] = (char)c;
240-
}
241-
// Check for next character immediately
242-
c = getchar_timeout_us(0);
243-
}
244-
245-
uint32_t lv_handler_start_us = time_us_32();
246-
lv_task_handler(); // Process LVGL tasks, events, and rendering.
247-
uint32_t lv_handler_duration_us = time_us_32() - lv_handler_start_us;
248-
249-
// Check if TE interrupt requested an LVGL refresh
250-
if (g_request_lvgl_refresh) {
251-
g_request_lvgl_refresh = false; // Consume the flag
252-
if (platformDriver && platformDriver->GetLvDisplay()) {
253-
// printf("MainLoop: Calling lv_display_refr_timer() due to TE
254-
// pulse.\n"); // Verbose lv_refr_now(platformDriver->GetLvDisplay());
255-
// // lv_refr_now is immediate, can be heavy in main loop
256-
lv_display_refr_timer(nullptr); // Schedules a refresh for the next lv_task_handler call
257-
}
258-
}
233+
// uint32_t lv_handler_start_us = time_us_32();
234+
lv_timer_handler(); // Process LVGL tasks, events, and rendering.
235+
// uint32_t lv_handler_duration_us = time_us_32() - lv_handler_start_us;
236+
// printf("LVGL handler took %lu ms\n", lv_handler_duration_us / 1000);
237+
// Check if TE interrupt requested an LVGL refresh
238+
// if (g_request_lvgl_refresh) {
239+
// g_request_lvgl_refresh = false; // Consume the flag
240+
// if (platformDriver && platformDriver->GetLvDisplay()) {
241+
// // printf("MainLoop: Calling lv_display_refr_timer() due to TE
242+
// // pulse.\n"); // Verbose lv_refr_now(platformDriver->GetLvDisplay());
243+
// // // lv_refr_now is immediate, can be heavy in main loop
244+
// lv_display_refr_timer(nullptr); // Schedules a refresh for the next lv_task_handler call
245+
// }
246+
// }
259247

260248
// Periodically print lv_task_handler duration, e.g., once per second along
261249
// with FPS This will be grouped with the FPS update logic below.
262250

263251
// --- FPS Calculation ---
264-
// fps_frame_count++;
265-
// auto current_time = std::chrono::steady_clock::now();
266-
// auto elapsed_ms =
267-
// std::chrono::duration_cast<std::chrono::milliseconds>(current_time -
268-
// fps_last_update_time).count();
269-
270-
// if (elapsed_ms >= 1000) { // Update every second
271-
// float fps_val = static_cast<float>(fps_frame_count * 1000.0f) /
272-
// elapsed_ms; if (fps_label_obj) {
273-
// char fps_buf[32]; // Increased buffer size for handler time
274-
// snprintf(fps_buf, sizeof(fps_buf), "FPS: %.1f\nHandler: %lu us",
275-
// fps_val, lv_handler_duration_us);
276-
// lv_label_set_text(fps_label_obj, fps_buf);
277-
// }
278-
// // Optional: Print to console as well
279-
// // printf("FPS: %.1f, LVGL Handler Time: %lu us\n", fps_val,
280-
// lv_handler_duration_us);
281-
282-
// fps_frame_count = 0;
283-
// fps_last_update_time = current_time;
284-
// }
285-
252+
// #ifdef DEBUG
253+
// fps_frame_count++;
254+
// auto current_time = std::chrono::steady_clock::now();
255+
// auto elapsed_ms =
256+
// std::chrono::duration_cast<std::chrono::milliseconds>(current_time -
257+
// fps_last_update_time).count();
258+
259+
// if (elapsed_ms >= 1000) { // Update every second
260+
// float fps_val = static_cast<float>(fps_frame_count * 1000.0f) / elapsed_ms;
261+
// if (fps_label_obj) {
262+
// char fps_buf[32]; // Increased buffer size for handler time
263+
// snprintf(fps_buf, sizeof(fps_buf), "FPS: %.1f\nHandler: %lu us", fps_val,
264+
// lv_handler_duration_us); lv_label_set_text(fps_label_obj, fps_buf);
265+
// }
266+
// // Optional: Print to console as well
267+
// // printf("FPS: %.1f, LVGL Handler Time: %lu us\n", fps_val, lv_handler_duration_us);
268+
269+
// fps_frame_count = 0;
270+
// fps_last_update_time = current_time;
271+
// }
272+
// #endif
286273
// --- Sleep ---
287-
// sleep_ms(1);
274+
sleep_ms(LVGL_TICK_PERIOD_MS);
288275
}
289276

290277
// Should not reach here

Firmware/src/drivers/ili9341/ILI9341Display.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
// ctrl_base pins are assumed consecutive: RD, WR, DC, CS
1616
#define ILI_PIN_RST 0
1717
#define ILI_PIN_TE 1
18-
#define ILI_PIN_DB0 2 // Base data pin (D0-D7)
19-
#define ILI_PIN_RD 10 // Base control pin (RD=ctrl_base+0, WR=ctrl_base+1, DC=ctrl_base+2, CS=ctrl_base+3)
18+
#define ILI_PIN_DB0 2 // Base data pin (D0-D7)
19+
#define ILI_PIN_RD 10 // Base control pin (RD=ctrl_base+0, WR=ctrl_base+1, DC=ctrl_base+2, CS=ctrl_base+3)
2020
// The following are implicitly defined by ILI_PIN_RD being the base for the 4 side-set pins
2121
// #define ILI_PIN_WR 11 // ctrl_base + 1
2222
// #define ILI_PIN_DC 12 // ctrl_base + 2
@@ -30,27 +30,24 @@
3030
// --- Display Dimensions ---
3131
// Defined in ili_def.h presumably
3232

33-
enum class Orientation : uint8_t
34-
{
35-
PORTRAIT = 0x48, // MY=0, MX=1, MV=0, ML=0, BGR=1
36-
LANDSCAPE_Y_FLIP = 0x28, // MY=0, MX=0, MV=1, ML=0, BGR=1 (Standard Landscape)
37-
LANDSCAPE_X_FLIP = 0xA8, // MY=1, MX=0, MV=1, ML=0, BGR=1 (Landscape 180) - Check datasheet/experiment
38-
LANDSCAPE_90 = 0x28, // Alias for standard landscape
39-
LANDSCAPE_270 = 0xA8, // Alias for landscape 180
40-
PORTRAIT_INVERTED = 0x88, // MY=1, MX=0, MV=0, ML=0, BGR=1
33+
enum class Orientation : uint8_t {
34+
PORTRAIT = 0x48, // MY=0, MX=1, MV=0, ML=0, BGR=1
35+
LANDSCAPE_Y_FLIP = 0x28, // MY=0, MX=0, MV=1, ML=0, BGR=1 (Standard Landscape)
36+
LANDSCAPE_X_FLIP = 0xA8, // MY=1, MX=0, MV=1, ML=0, BGR=1 (Landscape 180) - Check datasheet/experiment
37+
LANDSCAPE_90 = 0x28, // Alias for standard landscape
38+
LANDSCAPE_270 = 0xA8, // Alias for landscape 180
39+
PORTRAIT_INVERTED = 0x88, // MY=1, MX=0, MV=0, ML=0, BGR=1
4140
// Add other orientations based on MADCTL bits (MY, MX, MV, ML, BGR) if needed
4241
// The names below might not map directly to the MADCTL values provided.
4342
// Double-check the MADCTL register description for ILI9341.
4443
// LANDSCAPE_90_INVERTED = 0x60, // Example, verify
4544
// LANDSCAPE_270_INVERTED = 0x90 // Example, verify
4645
};
4746

48-
49-
class ILI9341Display
50-
{
51-
private:
52-
bool pio_initialized = false;
53-
uint16_t currentWidth = ILI9341_TFTWIDTH;
47+
class ILI9341Display {
48+
private:
49+
bool pio_initialized = false;
50+
uint16_t currentWidth = ILI9341_TFTWIDTH;
5451
uint16_t currentHeight = ILI9341_TFTHEIGHT;
5552

5653
// DMA channel and configuration for pixel transfers
@@ -68,13 +65,12 @@ class ILI9341Display
6865
// void WriteData16(uint16_t data); // Not typically used with DMA approach
6966
void FillScreenRaw(uint16_t color);
7067

71-
72-
public:
68+
public:
7369
ILI9341Display();
7470
~ILI9341Display();
75-
71+
7672
void WaitForTearingEffect();
77-
73+
7874
/**
7975
* @brief Initializes the PIO, DMA, and the ILI9341 display controller.
8076
* Must be called before any other display operations.
@@ -133,4 +129,8 @@ class ILI9341Display
133129
*/
134130
uint32_t MeasureTEInterval();
135131

132+
bool IsBusy()
133+
{
134+
return dma_channel_is_busy(tx_dma_chan);
135+
}
136136
};

0 commit comments

Comments
 (0)