Back to posts Edit this post
Copy content

24 Jan 11:10

#include <stdint.h> #include <stdbool.h> #include "inc/hw_memmap.h" #include "driverlib/fpu.h" #include "driverlib/sysctl.h" #include "driverlib/rom.h" #include "driverlib/pin_map.h" #include "driverlib/uart.h" #include "grlib/grlib.h" #include "drivers/ili9341_240x320x262K.h" #include "utils/uartstdio.h" #include "driverlib/gpio.h" // TI logo in array form (1 bit per pixel) const unsigned char TI_logo[(16*2)+5] = { IMAGE_FMT_1BPP_UNCOMP, 16,0, 16,0, 0x0f,0xff,0x0f,0xff,0x0f,0xf3,0x0f,0xfa,0x0f,0x8f,0x0f,0x89,0x81,0x99,0x81,0x19,0x03,0x09,0x07,0x89,0x07,0xdf,0x3f,0xee,0x7f,0xf0,0xff,0xf8,0xff,0xf9,0xff,0xfb }; void DrawA(void) { tContext sContext; tRectangle sRect = {0, 0, 320, 240}; // Set background and foreground colors for the rectangle GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrWhite); GrRectFill(&sContext, &sRect); int circleCenterX = 160; int circleCenterY = 120; int radius = 80; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrRed); GrCircleFill(&sContext, circleCenterX, circleCenterY, radius); GrContextForegroundSet(&sContext, ClrWhite); GrContextFontSet(&sContext, g_psFontCmss32b); GrStringDrawCentered(&sContext, "Pole A", -1, circleCenterX, circleCenterY, 0); } void DrawB(void) { tContext sContext; tRectangle sRect = {0, 0, 320, 240}; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrWhite); GrRectFill(&sContext, &sRect); int centerX = 160; int centerY = 120; int radius = 80; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrGreen); GrCircleFill(&sContext, centerX, centerY, radius); GrContextForegroundSet(&sContext, ClrBlack); GrContextFontSet(&sContext, g_psFontCmsc32); GrStringDraw(&sContext, "Pole B", -1, 110, 105, 0); } void DrawC(void) { tContext sContext; tRectangle sRect = {0, 0, 320, 240}; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrWhite); GrRectFill(&sContext, &sRect); int centerX = 160; int centerY = 120; int radius = 80; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrBlue); GrCircleFill(&sContext, centerX, centerY, radius); GrContextForegroundSet(&sContext, ClrBlack); GrContextFontSet(&sContext, g_psFontCm32b); GrStringDraw(&sContext, "Pole C", -1, 110, 105, 0); } void DrawD(void) { tContext sContext; tRectangle sRect = {0, 0, 320, 240}; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrWhite); GrRectFill(&sContext, &sRect); int centerX = 160; int centerY = 120; int radius = 80; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrYellow); GrCircleFill(&sContext, centerX, centerY, radius); GrContextForegroundSet(&sContext, ClrBlack); GrContextFontSet(&sContext, g_psFontCmtt32); GrStringDraw(&sContext, "Pole D", -1, 110, 105, 0); } int main(void) { tContext sContext; tRectangle sRect; ROM_FPULazyStackingEnable(); ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); ILI9341_240x320x262K_Init(); GrContextInit(&sContext, &g_sILI9341_240x320x262K); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_7); GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5); GPIOPinTypeGPIOInput(GPIO_PORTH_AHB_BASE, GPIO_PIN_2); // Initialize display areas sRect.i16XMin = 20; sRect.i16YMin = 20; sRect.i16XMax = 150; sRect.i16YMax = 110; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrRed); GrRectFill(&sContext, &sRect); GrContextForegroundSet(&sContext, ClrWhite); GrContextFontSet(&sContext, g_psFontCmss32b); GrStringDraw(&sContext, "Pole A", -1, 35, 50, 0); GrContextForegroundSet(&sContext, ClrCrimson); sRect.i16XMin = 170; sRect.i16YMin = 20; sRect.i16XMax = 300; sRect.i16YMax = 110; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrGreen); GrRectFill(&sContext, &sRect); GrContextForegroundSet(&sContext, ClrBlack); GrContextFontSet(&sContext, g_psFontCmsc32); GrStringDraw(&sContext, "Pole B", -1, 185, 50, 0); sRect.i16XMin = 20; sRect.i16YMin = 130; sRect.i16XMax = 150; sRect.i16YMax = 210; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrBlue); GrRectFill(&sContext, &sRect); GrContextForegroundSet(&sContext, ClrBlack); GrContextFontSet(&sContext, g_psFontCm32b); GrStringDraw(&sContext, "Pole C", -1, 35, 165, 0); sRect.i16XMin = 170; sRect.i16YMin = 130; sRect.i16XMax = 300; sRect.i16YMax = 210; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrYellow); GrRectFill(&sContext, &sRect); GrContextForegroundSet(&sContext, ClrBlack); GrContextFontSet(&sContext, g_psFontCmtt32); GrStringDraw(&sContext, "Pole D", -1, 185, 165, 0); while(1) { if(GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_0) == 0) { DrawA(); } if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_4) == 0) { DrawB(); } if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_5) == 0) { DrawC(); } if(GPIOPinRead(GPIO_PORTK_BASE, GPIO_PIN_7) == 0) { DrawD(); } if(GPIOPinRead(GPIO_PORTH_AHB_BASE, GPIO_PIN_2) == 0){ sRect.i16XMin = 0; sRect.i16YMin = 0; sRect.i16XMax = 320; sRect.i16YMax = 240; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrWhite); GrRectFill(&sContext, &sRect); sRect.i16XMin = 20; sRect.i16YMin = 20; sRect.i16XMax = 150; sRect.i16YMax = 110; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrRed); GrRectFill(&sContext, &sRect); GrContextForegroundSet(&sContext, ClrWhite); GrContextFontSet(&sContext, g_psFontCmss32b); GrStringDraw(&sContext, "Pole A", -1,35,50,0); GrContextForegroundSet(&sContext, ClrCrimson); sRect.i16XMin = 170; sRect.i16YMin = 20; sRect.i16XMax = 300; sRect.i16YMax = 110; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrGreen); GrRectFill(&sContext, &sRect); GrContextForegroundSet(&sContext, ClrBlack); GrContextFontSet(&sContext, g_psFontCmsc32); GrStringDraw(&sContext, "Pole B", -1,185,50,0); sRect.i16XMin = 20; sRect.i16YMin = 130; sRect.i16XMax = 150; sRect.i16YMax = 210; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrBlue); GrRectFill(&sContext, &sRect); GrContextForegroundSet(&sContext, ClrBlack); GrContextFontSet(&sContext, g_psFontCm32b); GrStringDraw(&sContext, "Pole C", -1,35,165,0); sRect.i16XMin = 170; sRect.i16YMin = 130; sRect.i16XMax = 300; sRect.i16YMax = 210; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrYellow); GrRectFill(&sContext, &sRect); GrContextForegroundSet(&sContext, ClrBlack); GrContextFontSet(&sContext, g_psFontCmtt32); GrStringDraw(&sContext, "Pole D", -1,185,165,0); } ROM_SysCtlDelay(ROM_SysCtlClockGet() / 32); // Delay } return 0; }

No files