diff --git a/buttons.c b/buttons.c index bc01f51..22eb0b4 100644 --- a/buttons.c +++ b/buttons.c @@ -28,6 +28,7 @@ uint32_t gADCSamplingRate; // [Hz] actual ADC sampling rate // imported globals extern uint32_t gSystemClock; // [Hz] system clock frequency extern volatile uint32_t gTime; // time in hundredths of a second +extern volatile uint8_t drawRequested; // initialize all button and joystick handling hardware void ButtonInit(void) @@ -189,6 +190,9 @@ void ButtonISR(void) { if (presses & 2) { // EK-TM4C1294XL button 2 pressed gTime = 0; } + if (presses & 4) { // boosterpack button 1 pressed + drawRequested = 1; + } if (running) { if (tic) gTime++; // increment time every other ISR call tic = !tic; diff --git a/main.c b/main.c index f8e7cd9..2b877bf 100644 --- a/main.c +++ b/main.c @@ -15,18 +15,20 @@ #include "driverlib/interrupt.h" #include "Crystalfontz128x128_ST7735.h" #include -#include "buttons.h" #include "grlib/grlib.h" -#include "sampling.h" #include +#include #include "inc/hw_memmap.h" #include "driverlib/gpio.h" #include "driverlib/pwm.h" #include "driverlib/pin_map.h" +#include "sampling.h" +#include "buttons.h" #define PWM_FREQUENCY 20000 // PWM frequency = 20 kHz uint32_t gSystemClock; // [Hz] system clock frequency volatile uint32_t gTime = 0; // time in hundredths of a second +volatile uint8_t drawRequested = 1; // start a pwm test signal void start_signal() { @@ -87,8 +89,8 @@ int main(void) { GrContextForegroundSet(&sContext, ClrBlue); - uint8_t xy_pos; // 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 @@ -98,7 +100,48 @@ int main(void) { } + // display graph + #define LOCAL_BUF_LEN 128 + uint16_t local_adc_buffer[LOCAL_BUF_LEN]; // copy of adc buffer + int32_t adc_current_index; + int32_t j; + if (drawRequested) { + IntMasterDisable(); // critical section + adc_current_index = gADCBufferIndex - 128; + for (j=0; j> 8) + //GrPixelDraw(&sContext, j, TRANSPOSE(local_adc_buffer[j])); + uint32_t upper,lower, current, last; + + if (j==0) { + upper = TRANSPOSE(local_adc_buffer[j]); + lower = upper; + last = upper; + } else { + current = TRANSPOSE(local_adc_buffer[j]); + + // couldn't find these anywhere + #define MIN(a,b) (((a)<(b))?(a):(b)) + #define MAX(a,b) (((a)>(b))?(a):(b)) + + upper = MAX(current, last); + lower = MIN(current, last); + + last = current; + } + + GrLineDrawV(&sContext, j, lower, upper); + } + + // display time time = gTime; // read shared global only once uint32_t hundredths = time % 100; diff --git a/sampling.c b/sampling.c index 96093c8..c03fb79 100644 --- a/sampling.c +++ b/sampling.c @@ -13,12 +13,7 @@ #include "buttons.h" #include "sampling.h" -// index wrapping macro -#define ADC_BUFFER_WRAP(i) ((i) & (ADC_BUFFER_SIZE - 1)) // latest sample index -volatile int32_t gADCBufferIndex = ADC_BUFFER_SIZE - 1; -volatile uint16_t gADCBuffer[ADC_BUFFER_SIZE]; // circular buffer -volatile uint32_t gADCErrors = 0; // number of missed ADC deadlines void ADC_ISR(void) { // clear ADC1 sequence0 interrupt flag in the ADCISC register @@ -37,6 +32,9 @@ void ADC_ISR(void) void start_sampler() { + gADCBufferIndex = ADC_BUFFER_SIZE - 1; + gADCErrors = 0; + SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0); // GPIO setup for analog input AIN3 diff --git a/sampling.h b/sampling.h index 69ea810..06ea538 100644 --- a/sampling.h +++ b/sampling.h @@ -5,6 +5,13 @@ #define ADC_BUFFER_SIZE 2048 // size must be a power of 2 +// index wrapping macro +#define ADC_BUFFER_WRAP(i) ((i) & (ADC_BUFFER_SIZE - 1)) + +volatile int32_t gADCBufferIndex; +volatile uint16_t gADCBuffer[ADC_BUFFER_SIZE]; // circular buffer +volatile uint32_t gADCErrors; // number of missed ADC deadlines + // initialize ADC and ISR void start_sampler(void);