This commit is contained in:
Andy Killorin 2025-04-03 11:07:16 -04:00
parent ba5421cadd
commit 93c76775ca
Signed by: ank
GPG key ID: 23F9463ECB67FE8C

27
main.c
View file

@ -30,6 +30,11 @@ uint32_t gSystemClock; // [Hz] system clock frequency
volatile uint32_t gTime = 0; // time in hundredths of a second volatile uint32_t gTime = 0; // time in hundredths of a second
volatile uint8_t drawRequested = 1; 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 // start a pwm test signal
void start_signal() { void start_signal() {
// configure M0PWM2, at GPIO PF2, BoosterPack 1 header C1 pin 2 // configure M0PWM2, at GPIO PF2, BoosterPack 1 header C1 pin 2
@ -96,9 +101,6 @@ int main(void) {
GrContextForegroundSet(&sContext, ClrBlack); GrContextForegroundSet(&sContext, ClrBlack);
GrRectFill(&sContext, &rectFullScreen); // fill screen with black GrRectFill(&sContext, &rectFullScreen); // fill screen with black
// assumming square lcd
#define HEIGHT LCD_VERTICAL_MAX
#define PIXELS_PER_DIV 20
GrContextForegroundSet(&sContext, ClrBlue); GrContextForegroundSet(&sContext, ClrBlue);
@ -119,7 +121,9 @@ int main(void) {
int32_t adc_current_index; int32_t adc_current_index;
int32_t j; int32_t j;
if (drawRequested) { if (drawRequested) {
adc_current_index = gADCBufferIndex - 128; int trigger = RisingTrigger();
adc_current_index = trigger - (WIDTH / 2);
for (j=0; j<LOCAL_BUF_LEN; j++) { for (j=0; j<LOCAL_BUF_LEN; j++) {
local_adc_buffer[j] = gADCBuffer[ADC_BUFFER_WRAP(adc_current_index + j)]; local_adc_buffer[j] = gADCBuffer[ADC_BUFFER_WRAP(adc_current_index + j)];
} }
@ -184,3 +188,18 @@ int main(void) {
GrFlush(&sContext); // flush the frame buffer to the LCD GrFlush(&sContext); // flush the frame buffer to the LCD
} }
} }
int RisingTrigger(void) // search for rising edge trigger
{
#define ADC_OFFSET 20
int x = gADCBufferIndex - (WIDTH / 2); // half screen width
int x_stop = x - ADC_BUFFER_SIZE/2;
for (; x > 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;
}