From 564d05b183ac03cd7492807191dbd78d117895be Mon Sep 17 00:00:00 2001 From: Andy Killorin <37423245+Speedy6451@users.noreply.github.com> Date: Sat, 12 Apr 2025 17:25:21 -0400 Subject: [PATCH] implemented graphics --- main.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/main.c b/main.c index f389e6e..0c8fe10 100644 --- a/main.c +++ b/main.c @@ -34,6 +34,8 @@ uint32_t gSystemClock = 120000000; // [Hz] system clock frequency +tContext sContext; + #define LOCAL_BUF_LEN 128 uint16_t adc_buffer_sample[LOCAL_BUF_LEN]; // copy of g adc buffer uint8_t adc_buffer_processed[LOCAL_BUF_LEN]; // copy of g adc buffer @@ -109,6 +111,12 @@ int main(void) start_signal(); start_sampler(); + Crystalfontz128x128_Init(); // Initialize the LCD display driver + Crystalfontz128x128_SetOrientation(LCD_ORIENTATION_UP); // set screen orientation + + GrContextInit(&sContext, &g_sCrystalfontz128x128); // Initialize the grlib graphics context + GrContextFontSet(&sContext, &g_sFontFixed6x8); // select font + /* Start BIOS */ BIOS_start(); @@ -171,8 +179,73 @@ void process_waveform(UArg arg1, UArg arg2) { void display_waveform(UArg arg1, UArg arg2) { + char str[50]; // string buffer + tRectangle rectFullScreen = {0, 0, GrContextDpyWidthGet(&sContext)-1, GrContextDpyHeightGet(&sContext)-1}; + while(1) { Semaphore_pend(display_sem, BIOS_WAIT_FOREVER); + + GrContextForegroundSet(&sContext, ClrBlack); + GrRectFill(&sContext, &rectFullScreen); // fill screen with black + + GrContextForegroundSet(&sContext, ClrBlue); + + // draw gridlines from the center out + uint8_t xy_pos; + for (xy_pos = HEIGHT/2; xy_pos < HEIGHT; xy_pos += PIXELS_PER_DIV) { + GrLineDrawV(&sContext, xy_pos, 0, 128); // right + GrLineDrawV(&sContext, HEIGHT - xy_pos, 0, 128); // left + + GrLineDrawH(&sContext, 0, 128, xy_pos); // down + GrLineDrawH(&sContext, 0, 128, HEIGHT - xy_pos); // up + } + + + // info + GrContextForegroundSet(&sContext, ClrWheat); + GrStringDraw(&sContext, gVoltageScaleStr[voltage_scale], /*length*/ -1, /*x*/ 0, /*y*/ 0, /*opaque*/ false); + GrStringDraw(&sContext, gTimeScaleStr[time_scale], /*length*/ -1, /*x*/ 60, /*y*/ 0, /*opaque*/ false); + //snprintf(str, sizeof(str), "CPU Load %.1f%%", usage_percent); + //GrStringDraw(&sContext, str, /*length*/ -1, /*x*/ 0, /*y*/ HEIGHT - 10, /*opaque*/ false); + + switch (trigger_mode) { + case 1: + GrStringDraw(&sContext, "^", /*length*/ -1, /*x*/ WIDTH - 10, /*y*/ 0, /*opaque*/ false); + break; + case 0: + GrStringDraw(&sContext, "v", /*length*/ -1, /*x*/ WIDTH - 10, /*y*/ 0, /*opaque*/ false); + break; + case 2: + GrStringDraw(&sContext, "-", /*length*/ -1, /*x*/ WIDTH - 10, /*y*/ 0, /*opaque*/ false); + break; + } + + // display graph + GrContextForegroundSet(&sContext, ClrYellow); + int j; + for(j=0; j(b))?(a):(b)) + uint32_t upper,lower, current, last; + + if (j==0) { + upper = adc_buffer_processed[j]; + lower = upper; + last = upper; + } else { + current = adc_buffer_processed[j]; + + upper = MAX(current, last); + lower = MIN(current, last); + + last = current; + } + + GrLineDrawV(&sContext, j, lower, upper); + } + + GrFlush(&sContext); // flush the frame buffer to the LCD + } }