/** * main.c * * ECE 3849 Lab 0 Starter Project * Gene Bogdanov 10/18/2017 * * This version is using the new hardware for B2017: the EK-TM4C1294XL LaunchPad with BOOSTXL-EDUMKII BoosterPack. * */ #include #include #include "driverlib/fpu.h" #include "driverlib/sysctl.h" #include "driverlib/interrupt.h" #include "Crystalfontz128x128_ST7735.h" #include #include "buttons.h" #include "sampling.h" #include #include "inc/hw_memmap.h" #include "driverlib/gpio.h" #include "driverlib/pwm.h" #include "driverlib/pin_map.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 // start a pwm test signal void start_signal() { // configure M0PWM2, at GPIO PF2, BoosterPack 1 header C1 pin 2 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2); GPIOPinConfigure(GPIO_PF2_M0PWM2); GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD); // configure the PWM0 peripheral, gen 1, outputs 2 and 3 SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); // use system clock without division PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_1); PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, roundf((float)gSystemClock / PWM_FREQUENCY)); PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, roundf((float)gSystemClock / PWM_FREQUENCY * 0.4f)); PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT, true); PWMGenEnable(PWM0_BASE, PWM_GEN_1); } int main(void) { IntMasterDisable(); start_signal(); start_sampler(); // Enable the Floating Point Unit, and permit ISRs to use it FPUEnable(); FPULazyStackingEnable(); // Initialize the system clock to 120 MHz gSystemClock = SysCtlClockFreqSet(SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480, 120000000); Crystalfontz128x128_Init(); // Initialize the LCD display driver Crystalfontz128x128_SetOrientation(LCD_ORIENTATION_UP); // set screen orientation tContext sContext; GrContextInit(&sContext, &g_sCrystalfontz128x128); // Initialize the grlib graphics context GrContextFontSet(&sContext, &g_sFontFixed6x8); // select font uint32_t time; // local copy of gTime char str[50]; // string buffer // full-screen rectangle tRectangle rectFullScreen = {0, 0, GrContextDpyWidthGet(&sContext)-1, GrContextDpyHeightGet(&sContext)-1}; ButtonInit(); IntMasterEnable(); while (true) { GrContextForegroundSet(&sContext, ClrBlack); GrRectFill(&sContext, &rectFullScreen); // fill screen with black time = gTime; // read shared global only once uint32_t hundredths = time % 100; uint32_t seconds = (time / 100) % 60; uint32_t minutes = (time / (100 * 60)); snprintf(str, sizeof(str), "Time = %02u:%02u:%02u", minutes, seconds, hundredths); // convert time to string GrContextForegroundSet(&sContext, ClrYellow); // yellow text GrStringDraw(&sContext, str, /*length*/ -1, /*x*/ 0, /*y*/ 0, /*opaque*/ false); // display button statuses char labels[9][7] = {"sw1", "sw2", "s1", "s2", "sel", "right", "left", "up", "down"}; char statuses[2][15] = {"not pressed", "pressed"}; int offset = 20; uint32_t buttons = gButtons; uint8_t i; for (i = 0; i < 9; i++) { snprintf(str, sizeof(str), "%s: %s", labels[i], statuses[buttons & 1] ); GrStringDraw(&sContext, str, /*length*/ -1, /*x*/ 0, /*y*/ offset, /*opaque*/ false); offset += 10; buttons >>= 1; } GrFlush(&sContext); // flush the frame buffer to the LCD } }