81 lines
2.7 KiB
C
81 lines
2.7 KiB
C
/**
|
|
* 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 <stdint.h>
|
|
#include <stdbool.h>
|
|
#include "driverlib/fpu.h"
|
|
#include "driverlib/sysctl.h"
|
|
#include "driverlib/interrupt.h"
|
|
#include "Crystalfontz128x128_ST7735.h"
|
|
#include <stdio.h>
|
|
#include "buttons.h"
|
|
|
|
uint32_t gSystemClock; // [Hz] system clock frequency
|
|
volatile uint32_t gTime = 0; // time in hundredths of a second
|
|
|
|
int main(void)
|
|
{
|
|
IntMasterDisable();
|
|
|
|
// 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[5][4] = {"sw1", "sw2", "s1", "s2", "sel"};
|
|
char statuses[2][15] = {"not pressed", "pressed"};
|
|
int offset = 20;
|
|
uint32_t buttons = gButtons;
|
|
|
|
uint8_t i;
|
|
for (i = 0; i < 5; 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
|
|
}
|
|
}
|