diff --git a/main.c b/main.c index a46a2a8..e2e2f12 100644 --- a/main.c +++ b/main.c @@ -30,6 +30,11 @@ uint32_t gSystemClock; // [Hz] system clock frequency volatile uint32_t gTime = 0; // time in hundredths of a second volatile uint8_t drawRequested = 1; +// assumming square lcd +#define HEIGHT LCD_VERTICAL_MAX +#define WIDTH LCD_HORIZONTAL_MAX +#define PIXELS_PER_DIV 20 + // start a pwm test signal void start_signal() { // configure M0PWM2, at GPIO PF2, BoosterPack 1 header C1 pin 2 @@ -96,9 +101,6 @@ int main(void) { GrContextForegroundSet(&sContext, ClrBlack); GrRectFill(&sContext, &rectFullScreen); // fill screen with black - // assumming square lcd - #define HEIGHT LCD_VERTICAL_MAX - #define PIXELS_PER_DIV 20 GrContextForegroundSet(&sContext, ClrBlue); @@ -119,7 +121,9 @@ int main(void) { int32_t adc_current_index; int32_t j; if (drawRequested) { - adc_current_index = gADCBufferIndex - 128; + int trigger = RisingTrigger(); + + adc_current_index = trigger - (WIDTH / 2); for (j=0; j x_stop; x--) { + if ( gADCBuffer[ADC_BUFFER_WRAP(x)] >= ADC_OFFSET && + gADCBuffer[ADC_BUFFER_WRAP(x-1)] < ADC_OFFSET) + break; + } + if (x == x_stop) // for loop ran to the end + x = x = gADCBufferIndex - (WIDTH / 2); // reset x back to how it was initialized + return x; +}