- #include "stdint.h"
- #include "stdbool.h"
- #include "time.h"
- #include "math.h"
- #include "string.h"
- #include "stdlib.h"
- #include "inc/hw_memmap.h"
- #include "inc/tm4c123gh6pm.h"
- #include "inc/hw_nvic.h"
- #include "inc/hw_sysctl.h"
- #include "inc/hw_types.h"
- #include "driverlib/fpu.h"
- #include "driverlib/gpio.h"
- #include "driverlib/flash.h"
- #include "driverlib/sysctl.h"
- #include "driverlib/systick.h"
- #include "driverlib/uart.h"
- #include "driverlib/udma.h"
- #include "driverlib/rom.h"
- #include "driverlib/interrupt.h" // INT_TIMER0A
- #include "driverlib/timer.h" // timer functions
- #include "driverlib/adc.h" // ADC functions
- #include "grlib/grlib.h"
- #include "grlib/widget.h"
- #include "grlib/canvas.h"
- #include "grlib/checkbox.h"
- #include "grlib/container.h"
- #include "grlib/pushbutton.h"
- #include "grlib/radiobutton.h"
- #include "grlib/slider.h"
- #include "utils/ustdlib.h"
- #include "Kentec320x240x16_ssd2119_8bit.h"
- #include "touch.h"
- #include "images.h"
- #include "stripchartwidget.h"
- //*****************************************************************************
- // The error routine that is called if the driver library encounters an error.
- //*****************************************************************************
- #ifdef DEBUG
- void __error__(char *pcFilename, uint32_t ulLine)
- {
- }
- #endif
- //*****************************************************************************
- // The DMA control structure table.
- //*****************************************************************************
- #ifdef ewarm
- #pragma data_alignment=1024
- tDMAControlTable sDMAControlTable[64];
- #elif defined(ccs)
- #pragma DATA_ALIGN(sDMAControlTable, 1024)
- tDMAControlTable sDMAControlTable[64];
- #else
- tDMAControlTable sDMAControlTable[64] __attribute__ ((aligned(1024)));
- #endif
- #if 1
- //*****************************************************************************
- //
- // Provide a definition for M_PI, if it was not provided by math.h.
- //
- //*****************************************************************************
- #ifndef M_PI
- #define M_PI 3.14159265358979323846
- #endif
- //*****************************************************************************
- //
- // The number of SysTick ticks per second.
- //
- //*****************************************************************************
- #define TICKS_PER_SECOND 20
- #define FSECONDS_PER_TICK (1.0 / (float)TICKS_PER_SECOND)
- //*****************************************************************************
- //
- // A counter for system clock ticks, used for tracking time.
- //
- //*****************************************************************************
- static volatile uint32_t g_ui32TickCount;
- //*****************************************************************************
- //
- // Define an off-screen buffer and display structure. This is used by the
- // strip chart widget for drawing a scrolling display.
- //
- //*****************************************************************************
- #define SCOPE_SCREEN_WIDTH (100)
- #define SCOPE_SCREEN_HIGHT (80)
- #define OFFSCREEN_BUF_SIZE GrOffScreen4BPPSize(SCOPE_SCREEN_WIDTH, SCOPE_SCREEN_HIGHT)
- uint8_t g_pui8OffscreenBuf[OFFSCREEN_BUF_SIZE];
- tDisplay g_sOffscreenDisplay;
- char strBuf[32];
- static uint32_t ui32TempValueC;
- static uint32_t ui32TempValueF;
- static uint32_t ui32TempValueCMax = 0;
- static uint32_t ui32TempValueFMax = 0;
- static uint32_t ui32TempValueCMin = 300;
- static uint32_t ui32TempValueFMin = 300;
- //*****************************************************************************
- //
- // Create a palette for the off-screen buffer that is used by the strip chart.
- //
- //*****************************************************************************
- uint32_t g_pui32Palette[] =
- {
- ClrBlack,
- ClrWhite,
- ClrBlue,
- ClrRed,
- ClrDarkGreen,
- };
- #define NUM_PALETTE_ENTRIES (sizeof(g_pui32Palette) / sizeof(uint32_t))
- //*****************************************************************************
- //
- // Define the series for the strip chart. The SERIES_LENGTH is the maximum
- // number of points that will be shown on the chart.
- //
- //*****************************************************************************
- #define SERIES_LENGTH (SCOPE_SCREEN_HIGHT)
- static tStripChartSeries g_sSeries0 =
- {
- 0, "C", ClrRed, 1, 1, 0, 0
- };
- static tStripChartSeries g_sSeries1 =
- {
- 0, "F", ClrBlue, 1, 1, 0, 0
- };
- //*****************************************************************************
- //
- // Defines the X-axis for the strip chart
- //
- //*****************************************************************************
- static tStripChartAxis i16Axis16X =
- {
- "TIME", // title of axis
- 0, // label for minimum of axis
- 0, // label for maximum of axis
- 0, // minimum value for the axis
- SCOPE_SCREEN_WIDTH-1, // maximum value for the axis
- TICKS_PER_SECOND // grid interval for the axis
- };
- //*****************************************************************************
- //
- // Defines the Y-axis for the strip chart.
- //
- //*****************************************************************************
- static tStripChartAxis i16Axis16Y =
- {
- "T", // title of the axis
- "0", // label for minimum of axis
- "100", // label for maximum of axis
- 0, // minimum value for the axis
- (SCOPE_SCREEN_HIGHT), // maximum value for the axis
- (SCOPE_SCREEN_HIGHT/4) // grid interval for the axis
- };
- //*****************************************************************************
- //
- // Defines the strip chart widget. This structure requires additional
- // run-time initialization.
- //
- //*****************************************************************************
- extern tCanvasWidget g_sBackground;
- extern tPushButtonWidget g_sPushBtn;
- void OnDisplayBoardPaint(tWidget *pWidget, tContext *pContext);
- void OnButtonPress(tWidget *psWidget);
- Canvas(g_sBackground, WIDGET_ROOT, 0, &g_sPushBtn,
- &g_sKentec320x240x16_SSD2119, 10, 25, 300, (240 - 25 -10),
- CANVAS_STYLE_FILL, ClrYellow, 0, 0, 0, 0, 0, 0);
- RectangularButton(g_sPushBtn, &g_sBackground, 0, 0,
- &g_sKentec320x240x16_SSD2119, 60, 60, 200, 40,
- (PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |
- PB_STYLE_FILL | PB_STYLE_RELEASE_NOTIFY),
- ClrDarkBlue, ClrBlue, ClrWhite, ClrWhite,
- g_psFontCmss22b, strBuf, 0, 0, 0, 0, OnButtonPress);
- StripChart(g_sStripChart, WIDGET_ROOT, 0, 0, &g_sKentec320x240x16_SSD2119, 30, 120, SCOPE_SCREEN_WIDTH, SCOPE_SCREEN_HIGHT,
- 0, g_psFontFixed6x8, ClrBlack, ClrYellow, ClrWhite, ClrDarkGreen,
- &i16Axis16X, &i16Axis16Y, &g_sOffscreenDisplay);
- //*****************************************************************************
- //
- // Creates a buffer for holding the values of the data series. It must be
- // large enough to hold the maximum number of data points in the series that
- // will be shown on the strip chart.
- //
- //*****************************************************************************
- static int8_t g_i8SeriesData0[SERIES_LENGTH];
- static int8_t g_i8SeriesData1[SERIES_LENGTH];
- #endif
- #if 0
- //*****************************************************************************
- //
- // Forward declarations for the globals required to define the widgets at
- // compile-time.
- //
- //*****************************************************************************
- void OnPrevious(tWidget *pWidget);
- void OnNext(tWidget *pWidget);
- void OnIntroPaint(tWidget *pWidget, tContext *pContext);
- void OnPrimitivePaint(tWidget *pWidget, tContext *pContext);
- void OnCanvasPaint(tWidget *pWidget, tContext *pContext);
- void OnCheckChange(tWidget *pWidget, uint32_t bSelected);
- void OnButtonPress(tWidget *pWidget);
- void OnRadioChange(tWidget *pWidget, uint32_t bSelected);
- void OnSliderChange(tWidget *pWidget, int32_t lValue);
- extern tCanvasWidget g_psPanels[];
- //*****************************************************************************
- //
- // The first panel, which contains introductory text explaining the
- // application.
- //
- //*****************************************************************************
- Canvas(g_sIntroduction, g_psPanels, 0, 0, &g_sKentec320x240x16_SSD2119, 0, 24,
- 320, 166, CANVAS_STYLE_APP_DRAWN, 0, 0, 0, 0, 0, 0, OnIntroPaint);
- //*****************************************************************************
- //
- // The second panel, which demonstrates the graphics primitives.
- //
- //*****************************************************************************
- Canvas(g_sPrimitives, g_psPanels + 1, 0, 0, &g_sKentec320x240x16_SSD2119, 0,
- 24, 320, 166, CANVAS_STYLE_APP_DRAWN, 0, 0, 0, 0, 0, 0,
- OnPrimitivePaint);
- //*****************************************************************************
- //
- // The third panel, which demonstrates the canvas widget.
- //
- //*****************************************************************************
- Canvas(g_sCanvas3, g_psPanels + 2, 0, 0, &g_sKentec320x240x16_SSD2119, 205,
- 27, 110, 158, CANVAS_STYLE_OUTLINE | CANVAS_STYLE_APP_DRAWN, 0, ClrGray,
- 0, 0, 0, 0, OnCanvasPaint);
- Canvas(g_sCanvas2, g_psPanels + 2, &g_sCanvas3, 0,
- &g_sKentec320x240x16_SSD2119, 5, 109, 195, 76,
- CANVAS_STYLE_OUTLINE | CANVAS_STYLE_IMG, 0, ClrGray, 0, 0, 0, g_pucLogo,
- 0);
- Canvas(g_sCanvas1, g_psPanels + 2, &g_sCanvas2, 0,
- &g_sKentec320x240x16_SSD2119, 5, 27, 195, 76,
- CANVAS_STYLE_FILL | CANVAS_STYLE_OUTLINE | CANVAS_STYLE_TEXT,
- ClrMidnightBlue, ClrGray, ClrSilver, &g_sFontCm22, "Text", 0, 0);
- //*****************************************************************************
- //
- // The fourth panel, which demonstrates the checkbox widget.
- //
- //*****************************************************************************
- tCanvasWidget g_psCheckBoxIndicators[] =
- {
- CanvasStruct(g_psPanels + 3, g_psCheckBoxIndicators + 1, 0,
- &g_sKentec320x240x16_SSD2119, 230, 30, 50, 42,
- CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
- CanvasStruct(g_psPanels + 3, g_psCheckBoxIndicators + 2, 0,
- &g_sKentec320x240x16_SSD2119, 230, 82, 50, 48,
- CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
- CanvasStruct(g_psPanels + 3, 0, 0,
- &g_sKentec320x240x16_SSD2119, 230, 134, 50, 42,
- CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0)
- };
- tCheckBoxWidget g_psCheckBoxes[] =
- {
- CheckBoxStruct(g_psPanels + 3, g_psCheckBoxes + 1, 0,
- &g_sKentec320x240x16_SSD2119, 40, 30, 185, 42,
- CB_STYLE_OUTLINE | CB_STYLE_FILL | CB_STYLE_TEXT, 16,
- ClrMidnightBlue, ClrGray, ClrSilver, &g_sFontCm22, "Select",
- 0, OnCheckChange),
- CheckBoxStruct(g_psPanels + 3, g_psCheckBoxes + 2, 0,
- &g_sKentec320x240x16_SSD2119, 40, 82, 185, 48,
- CB_STYLE_IMG, 16, 0, ClrGray, 0, 0, 0, g_pucLogo,
- OnCheckChange),
- CheckBoxStruct(g_psPanels + 3, g_psCheckBoxIndicators, 0,
- &g_sKentec320x240x16_SSD2119, 40, 134, 189, 42,
- CB_STYLE_OUTLINE | CB_STYLE_TEXT, 16,
- 0, ClrGray, ClrGreen, &g_sFontCm20, "Select",
- 0, OnCheckChange),
- };
- #define NUM_CHECK_BOXES (sizeof(g_psCheckBoxes) / \
- sizeof(g_psCheckBoxes[0]))
- //*****************************************************************************
- //
- // The fifth panel, which demonstrates the container widget.
- //
- //*****************************************************************************
- Container(g_sContainer3, g_psPanels + 4, 0, 0, &g_sKentec320x240x16_SSD2119,
- 210, 47, 105, 118, CTR_STYLE_OUTLINE | CTR_STYLE_FILL,
- ClrMidnightBlue, ClrGray, 0, 0, 0);
- Container(g_sContainer2, g_psPanels + 4, &g_sContainer3, 0,
- &g_sKentec320x240x16_SSD2119, 5, 109, 200, 76,
- (CTR_STYLE_OUTLINE | CTR_STYLE_FILL | CTR_STYLE_TEXT |
- CTR_STYLE_TEXT_CENTER), ClrMidnightBlue, ClrGray, ClrSilver,
- &g_sFontCm22, "Group2");
- Container(g_sContainer1, g_psPanels + 4, &g_sContainer2, 0,
- &g_sKentec320x240x16_SSD2119, 5, 27, 200, 76,
- CTR_STYLE_OUTLINE | CTR_STYLE_FILL | CTR_STYLE_TEXT, ClrMidnightBlue,
- ClrGray, ClrSilver, &g_sFontCm22, "Group1");
- //*****************************************************************************
- //
- // The sixth panel, which contains a selection of push buttons.
- //
- //*****************************************************************************
- tCanvasWidget g_psPushButtonIndicators[] =
- {
- CanvasStruct(g_psPanels + 5, g_psPushButtonIndicators + 1, 0,
- &g_sKentec320x240x16_SSD2119, 40, 85, 20, 20,
- CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
- CanvasStruct(g_psPanels + 5, g_psPushButtonIndicators + 2, 0,
- &g_sKentec320x240x16_SSD2119, 90, 85, 20, 20,
- CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
- CanvasStruct(g_psPanels + 5, g_psPushButtonIndicators + 3, 0,
- &g_sKentec320x240x16_SSD2119, 145, 85, 20, 20,
- CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
- CanvasStruct(g_psPanels + 5, g_psPushButtonIndicators + 4, 0,
- &g_sKentec320x240x16_SSD2119, 40, 165, 20, 20,
- CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
- CanvasStruct(g_psPanels + 5, g_psPushButtonIndicators + 5, 0,
- &g_sKentec320x240x16_SSD2119, 90, 165, 20, 20,
- CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
- CanvasStruct(g_psPanels + 5, g_psPushButtonIndicators + 6, 0,
- &g_sKentec320x240x16_SSD2119, 145, 165, 20, 20,
- CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
- CanvasStruct(g_psPanels + 5, g_psPushButtonIndicators + 7, 0,
- &g_sKentec320x240x16_SSD2119, 190, 35, 110, 24,
- CANVAS_STYLE_TEXT, 0, 0, ClrSilver, &g_sFontCm20, "Non-auto",
- 0, 0),
- CanvasStruct(g_psPanels + 5, g_psPushButtonIndicators + 8, 0,
- &g_sKentec320x240x16_SSD2119, 190, 55, 110, 24,
- CANVAS_STYLE_TEXT, 0, 0, ClrSilver, &g_sFontCm20, "repeat",
- 0, 0),
- CanvasStruct(g_psPanels + 5, g_psPushButtonIndicators + 9, 0,
- &g_sKentec320x240x16_SSD2119, 190, 115, 110, 24,
- CANVAS_STYLE_TEXT, 0, 0, ClrSilver, &g_sFontCm20, "Auto",
- 0, 0),
- CanvasStruct(g_psPanels + 5, 0, 0,
- &g_sKentec320x240x16_SSD2119, 190, 135, 110, 24,
- CANVAS_STYLE_TEXT, 0, 0, ClrSilver, &g_sFontCm20, "repeat",
- 0, 0),
- };
- tPushButtonWidget g_psPushButtons[] =
- {
- RectangularButtonStruct(g_psPanels + 5, g_psPushButtons + 1, 0,
- &g_sKentec320x240x16_SSD2119, 30, 35, 40, 40,
- PB_STYLE_FILL | PB_STYLE_OUTLINE | PB_STYLE_TEXT,
- ClrMidnightBlue, ClrBlack, ClrGray, ClrSilver,
- &g_sFontCm22, "1", 0, 0, 0, 0, OnButtonPress),
- CircularButtonStruct(g_psPanels + 5, g_psPushButtons + 2, 0,
- &g_sKentec320x240x16_SSD2119, 100, 55, 20,
- PB_STYLE_FILL | PB_STYLE_OUTLINE | PB_STYLE_TEXT,
- ClrMidnightBlue, ClrBlack, ClrGray, ClrSilver,
- &g_sFontCm22, "3", 0, 0, 0, 0, OnButtonPress),
- RectangularButtonStruct(g_psPanels + 5, g_psPushButtons + 3, 0,
- &g_sKentec320x240x16_SSD2119, 130, 30, 50, 50,
- PB_STYLE_IMG | PB_STYLE_TEXT, 0, 0, 0, ClrSilver,
- &g_sFontCm22, "5", g_pucBlue50x50,
- g_pucBlue50x50Press, 0, 0, OnButtonPress),
- RectangularButtonStruct(g_psPanels + 5, g_psPushButtons + 4, 0,
- &g_sKentec320x240x16_SSD2119, 30, 115, 40, 40,
- (PB_STYLE_FILL | PB_STYLE_OUTLINE | PB_STYLE_TEXT |
- PB_STYLE_AUTO_REPEAT), ClrMidnightBlue, ClrBlack,
- ClrGray, ClrSilver, &g_sFontCm22, "2", 0, 0, 125,
- 25, OnButtonPress),
- CircularButtonStruct(g_psPanels + 5, g_psPushButtons + 5, 0,
- &g_sKentec320x240x16_SSD2119, 100, 135, 20,
- (PB_STYLE_FILL | PB_STYLE_OUTLINE | PB_STYLE_TEXT |
- PB_STYLE_AUTO_REPEAT), ClrMidnightBlue, ClrBlack,
- ClrGray, ClrSilver, &g_sFontCm22, "4", 0, 0, 125, 25,
- OnButtonPress),
- RectangularButtonStruct(g_psPanels + 5, g_psPushButtonIndicators, 0,
- &g_sKentec320x240x16_SSD2119, 130, 110, 50, 50,
- (PB_STYLE_IMG | PB_STYLE_TEXT |
- PB_STYLE_AUTO_REPEAT), 0, 0, 0, ClrSilver,
- &g_sFontCm22, "6", g_pucBlue50x50,
- g_pucBlue50x50Press, 125, 25, OnButtonPress),
- };
- #define NUM_PUSH_BUTTONS (sizeof(g_psPushButtons) / \
- sizeof(g_psPushButtons[0]))
- uint32_t g_ulButtonState;
- //*****************************************************************************
- //
- // The seventh panel, which contains a selection of radio buttons.
- //
- //*****************************************************************************
- tContainerWidget g_psRadioContainers[];
- tCanvasWidget g_psRadioButtonIndicators[] =
- {
- CanvasStruct(g_psRadioContainers, g_psRadioButtonIndicators + 1, 0,
- &g_sKentec320x240x16_SSD2119, 95, 62, 20, 20,
- CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
- CanvasStruct(g_psRadioContainers, g_psRadioButtonIndicators + 2, 0,
- &g_sKentec320x240x16_SSD2119, 95, 107, 20, 20,
- CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
- CanvasStruct(g_psRadioContainers, 0, 0,
- &g_sKentec320x240x16_SSD2119, 95, 152, 20, 20,
- CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
- CanvasStruct(g_psRadioContainers + 1, g_psRadioButtonIndicators + 4, 0,
- &g_sKentec320x240x16_SSD2119, 260, 62, 20, 20,
- CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
- CanvasStruct(g_psRadioContainers + 1, g_psRadioButtonIndicators + 5, 0,
- &g_sKentec320x240x16_SSD2119, 260, 107, 20, 20,
- CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
- CanvasStruct(g_psRadioContainers + 1, 0, 0,
- &g_sKentec320x240x16_SSD2119, 260, 152, 20, 20,
- CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
- };
- tRadioButtonWidget g_psRadioButtons1[] =
- {
- RadioButtonStruct(g_psRadioContainers, g_psRadioButtons1 + 1, 0,
- &g_sKentec320x240x16_SSD2119, 10, 50, 80, 45,
- RB_STYLE_TEXT, 16, 0, ClrSilver, ClrSilver, &g_sFontCm20,
- "One", 0, OnRadioChange),
- RadioButtonStruct(g_psRadioContainers, g_psRadioButtons1 + 2, 0,
- &g_sKentec320x240x16_SSD2119, 10, 95, 80, 45,
- RB_STYLE_TEXT, 16, 0, ClrSilver, ClrSilver, &g_sFontCm20,
- "Two", 0, OnRadioChange),
- RadioButtonStruct(g_psRadioContainers, g_psRadioButtonIndicators, 0,
- &g_sKentec320x240x16_SSD2119, 10, 140, 80, 45,
- RB_STYLE_TEXT, 24, 0, ClrSilver, ClrSilver, &g_sFontCm20,
- "Three", 0, OnRadioChange)
- };
- #define NUM_RADIO1_BUTTONS (sizeof(g_psRadioButtons1) / \
- sizeof(g_psRadioButtons1[0]))
- tRadioButtonWidget g_psRadioButtons2[] =
- {
- RadioButtonStruct(g_psRadioContainers + 1, g_psRadioButtons2 + 1, 0,
- &g_sKentec320x240x16_SSD2119, 175, 50, 80, 45,
- RB_STYLE_IMG, 16, 0, ClrSilver, 0, 0, 0, g_pucLogo,
- OnRadioChange),
- RadioButtonStruct(g_psRadioContainers + 1, g_psRadioButtons2 + 2, 0,
- &g_sKentec320x240x16_SSD2119, 175, 95, 80, 45,
- RB_STYLE_IMG, 24, 0, ClrSilver, 0, 0, 0, g_pucLogo,
- OnRadioChange),
- RadioButtonStruct(g_psRadioContainers + 1, g_psRadioButtonIndicators + 3,
- 0, &g_sKentec320x240x16_SSD2119, 175, 140, 80, 45,
- RB_STYLE_IMG, 24, 0, ClrSilver, 0, 0, 0, g_pucLogo,
- OnRadioChange)
- };
- #define NUM_RADIO2_BUTTONS (sizeof(g_psRadioButtons2) / \
- sizeof(g_psRadioButtons2[0]))
- tContainerWidget g_psRadioContainers[] =
- {
- ContainerStruct(g_psPanels + 6, g_psRadioContainers + 1, g_psRadioButtons1,
- &g_sKentec320x240x16_SSD2119, 5, 27, 148, 160,
- CTR_STYLE_OUTLINE | CTR_STYLE_TEXT, 0, ClrGray, ClrSilver,
- &g_sFontCm20, "Group One"),
- ContainerStruct(g_psPanels + 6, 0, g_psRadioButtons2,
- &g_sKentec320x240x16_SSD2119, 167, 27, 148, 160,
- CTR_STYLE_OUTLINE | CTR_STYLE_TEXT, 0, ClrGray, ClrSilver,
- &g_sFontCm20, "Group Two")
- };
- //*****************************************************************************
- //
- // The eighth panel, which demonstrates the slider widget.
- //
- //*****************************************************************************
- Canvas(g_sSliderValueCanvas, g_psPanels + 7, 0, 0,
- &g_sKentec320x240x16_SSD2119, 210, 30, 60, 40,
- CANVAS_STYLE_TEXT | CANVAS_STYLE_TEXT_OPAQUE, ClrBlack, 0, ClrSilver,
- &g_sFontCm24, "50%",
- 0, 0);
- tSliderWidget g_psSliders[] =
- {
- SliderStruct(g_psPanels + 7, g_psSliders + 1, 0,
- &g_sKentec320x240x16_SSD2119, 5, 115, 220, 30, 0, 100, 25,
- (SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_OUTLINE |
- SL_STYLE_TEXT | SL_STYLE_BACKG_TEXT),
- ClrGray, ClrBlack, ClrSilver, ClrWhite, ClrWhite,
- &g_sFontCm20, "25%", 0, 0, OnSliderChange),
- SliderStruct(g_psPanels + 7, g_psSliders + 2, 0,
- &g_sKentec320x240x16_SSD2119, 5, 155, 220, 25, 0, 100, 25,
- (SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_OUTLINE |
- SL_STYLE_TEXT),
- ClrWhite, ClrBlueViolet, ClrSilver, ClrBlack, 0,
- &g_sFontCm18, "Foreground Text Only", 0, 0, OnSliderChange),
- SliderStruct(g_psPanels + 7, g_psSliders + 3, 0,
- &g_sKentec320x240x16_SSD2119, 240, 70, 26, 110, 0, 100, 50,
- (SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_VERTICAL |
- SL_STYLE_OUTLINE | SL_STYLE_LOCKED), ClrDarkGreen,
- ClrDarkRed, ClrSilver, 0, 0, 0, 0, 0, 0, 0),
- SliderStruct(g_psPanels + 7, g_psSliders + 4, 0,
- &g_sKentec320x240x16_SSD2119, 280, 30, 30, 150, 0, 100, 75,
- (SL_STYLE_IMG | SL_STYLE_BACKG_IMG | SL_STYLE_VERTICAL |
- SL_STYLE_OUTLINE), 0, ClrBlack, ClrSilver, 0, 0, 0,
- 0, g_pucGettingHotter28x148, g_pucGettingHotter28x148Mono,
- OnSliderChange),
- SliderStruct(g_psPanels + 7, g_psSliders + 5, 0,
- &g_sKentec320x240x16_SSD2119, 5, 30, 195, 37, 0, 100, 50,
- SL_STYLE_IMG | SL_STYLE_BACKG_IMG, 0, 0, 0, 0, 0, 0,
- 0, g_pucGreenSlider195x37, g_pucRedSlider195x37,
- OnSliderChange),
- SliderStruct(g_psPanels + 7, &g_sSliderValueCanvas, 0,
- &g_sKentec320x240x16_SSD2119, 5, 80, 220, 25, 0, 100, 50,
- (SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_TEXT |
- SL_STYLE_BACKG_TEXT | SL_STYLE_TEXT_OPAQUE |
- SL_STYLE_BACKG_TEXT_OPAQUE),
- ClrBlue, ClrYellow, ClrSilver, ClrYellow, ClrBlue,
- &g_sFontCm18, "Text in both areas", 0, 0,
- OnSliderChange),
- };
- #define SLIDER_TEXT_VAL_INDEX 0
- #define SLIDER_LOCKED_INDEX 2
- #define SLIDER_CANVAS_VAL_INDEX 4
- #define NUM_SLIDERS (sizeof(g_psSliders) / sizeof(g_psSliders[0]))
- //*****************************************************************************
- //
- // An array of canvas widgets, one per panel. Each canvas is filled with
- // black, overwriting the contents of the previous panel.
- //
- //*****************************************************************************
- tCanvasWidget g_psPanels[] =
- {
- CanvasStruct(0, 0, &g_sIntroduction, &g_sKentec320x240x16_SSD2119, 0, 24,
- 320, 166, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
- CanvasStruct(0, 0, &g_sPrimitives, &g_sKentec320x240x16_SSD2119, 0, 24,
- 320, 166, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
- CanvasStruct(0, 0, &g_sCanvas1, &g_sKentec320x240x16_SSD2119, 0, 24, 320,
- 166, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
- CanvasStruct(0, 0, g_psCheckBoxes, &g_sKentec320x240x16_SSD2119, 0, 24,
- 320, 166, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
- CanvasStruct(0, 0, &g_sContainer1, &g_sKentec320x240x16_SSD2119, 0, 24,
- 320, 166, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
- CanvasStruct(0, 0, g_psPushButtons, &g_sKentec320x240x16_SSD2119, 0, 24,
- 320, 166, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
- CanvasStruct(0, 0, g_psRadioContainers, &g_sKentec320x240x16_SSD2119, 0,
- 24, 320, 166, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
- CanvasStruct(0, 0, g_psSliders, &g_sKentec320x240x16_SSD2119, 0,
- 24, 320, 166, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
- };
- //*****************************************************************************
- //
- // The number of panels.
- //
- //*****************************************************************************
- #define NUM_PANELS (sizeof(g_psPanels) / sizeof(g_psPanels[0]))
- //*****************************************************************************
- //
- // The names for each of the panels, which is displayed at the bottom of the
- // screen.
- //
- //*****************************************************************************
- char *g_pcPanelNames[] =
- {
- " Introduction ",
- " Primitives ",
- " Canvas ",
- " Checkbox ",
- " Container ",
- " Push Buttons ",
- " Radio Buttons ",
- " Sliders ",
- " S/W Update "
- };
- //*****************************************************************************
- //
- // The buttons and text across the bottom of the screen.
- //
- //*****************************************************************************
- RectangularButton(g_sPrevious, 0, 0, 0, &g_sKentec320x240x16_SSD2119, 0, 190,
- 50, 50, PB_STYLE_FILL, ClrBlack, ClrBlack, 0, ClrSilver,
- &g_sFontCm20, "-", g_pucBlue50x50, g_pucBlue50x50Press, 0, 0,
- OnPrevious);
-
- Canvas(g_sTitle, 0, 0, 0, &g_sKentec320x240x16_SSD2119, 50, 190, 220, 50,
- CANVAS_STYLE_TEXT | CANVAS_STYLE_TEXT_OPAQUE, 0, 0, ClrSilver,
- &g_sFontCm20, 0, 0, 0);
-
- RectangularButton(g_sNext, 0, 0, 0, &g_sKentec320x240x16_SSD2119, 270, 190,
- 50, 50, PB_STYLE_IMG | PB_STYLE_TEXT, ClrBlack, ClrBlack, 0,
- ClrSilver, &g_sFontCm20, "+", g_pucBlue50x50,
- g_pucBlue50x50Press, 0, 0, OnNext);
- //*****************************************************************************
- //
- // The panel that is currently being displayed.
- //
- //*****************************************************************************
- uint32_t g_ulPanel;
- //*****************************************************************************
- //
- // Handles presses of the previous panel button.
- //
- //*****************************************************************************
- void
- OnPrevious(tWidget *pWidget)
- {
- //
- // There is nothing to be done if the first panel is already being
- // displayed.
- //
- if(g_ulPanel == 0)
- {
- return;
- }
- //
- // Remove the current panel.
- //
- WidgetRemove((tWidget *)(g_psPanels + g_ulPanel));
- //
- // Decrement the panel index.
- //
- g_ulPanel--;
- //
- // Add and draw the new panel.
- //
- WidgetAdd(WIDGET_ROOT, (tWidget *)(g_psPanels + g_ulPanel));
- WidgetPaint((tWidget *)(g_psPanels + g_ulPanel));
- //
- // Set the title of this panel.
- //
- CanvasTextSet(&g_sTitle, g_pcPanelNames[g_ulPanel]);
- WidgetPaint((tWidget *)&g_sTitle);
- //
- // See if this is the first panel.
- //
- if(g_ulPanel == 0)
- {
- //
- // Clear the previous button from the display since the first panel is
- // being displayed.
- //
- PushButtonImageOff(&g_sPrevious);
- PushButtonTextOff(&g_sPrevious);
- PushButtonFillOn(&g_sPrevious);
- WidgetPaint((tWidget *)&g_sPrevious);
- }
- //
- // See if the previous panel was the last panel.
- //
- if(g_ulPanel == (NUM_PANELS - 2))
- {
- //
- // Display the next button.
- //
- PushButtonImageOn(&g_sNext);
- PushButtonTextOn(&g_sNext);
- PushButtonFillOff(&g_sNext);
- WidgetPaint((tWidget *)&g_sNext);
- }
- }
- //*****************************************************************************
- //
- // Handles presses of the next panel button.
- //
- //*****************************************************************************
- void
- OnNext(tWidget *pWidget)
- {
- //
- // There is nothing to be done if the last panel is already being
- // displayed.
- //
- if(g_ulPanel == (NUM_PANELS - 1))
- {
- return;
- }
- //
- // Remove the current panel.
- //
- WidgetRemove((tWidget *)(g_psPanels + g_ulPanel));
- //
- // Increment the panel index.
- //
- g_ulPanel++;
- //
- // Add and draw the new panel.
- //
- WidgetAdd(WIDGET_ROOT, (tWidget *)(g_psPanels + g_ulPanel));
- WidgetPaint((tWidget *)(g_psPanels + g_ulPanel));
- //
- // Set the title of this panel.
- //
- CanvasTextSet(&g_sTitle, g_pcPanelNames[g_ulPanel]);
- WidgetPaint((tWidget *)&g_sTitle);
- //
- // See if the previous panel was the first panel.
- //
- if(g_ulPanel == 1)
- {
- //
- // Display the previous button.
- //
- PushButtonImageOn(&g_sPrevious);
- PushButtonTextOn(&g_sPrevious);
- PushButtonFillOff(&g_sPrevious);
- WidgetPaint((tWidget *)&g_sPrevious);
- }
- //
- // See if this is the last panel.
- //
- if(g_ulPanel == (NUM_PANELS - 1))
- {
- //
- // Clear the next button from the display since the last panel is being
- // displayed.
- //
- PushButtonImageOff(&g_sNext);
- PushButtonTextOff(&g_sNext);
- PushButtonFillOn(&g_sNext);
- WidgetPaint((tWidget *)&g_sNext);
- }
- }
- //*****************************************************************************
- //
- // Handles paint requests for the introduction canvas widget.
- //
- //*****************************************************************************
- void
- OnIntroPaint(tWidget *pWidget, tContext *pContext)
- {
- //
- // Display the introduction text in the canvas.
- //
- GrContextFontSet(pContext, &g_sFontCm18);
- GrContextForegroundSet(pContext, ClrSilver);
- GrStringDraw(pContext, "This application demonstrates the Stellaris", -1,
- 0, 32, 0);
- GrStringDraw(pContext, "Graphics Library.", -1, 0, 50, 0);
- GrStringDraw(pContext, "Each panel shows a different feature of", -1, 0,
- 74, 0);
- GrStringDraw(pContext, "the graphics library. Widgets on the panels", -1, 0,
- 92, 0);
- GrStringDraw(pContext, "are fully operational; pressing them will", -1, 0,
- 110, 0);
- GrStringDraw(pContext, "result in visible feedback of some kind.", -1, 0,
- 128, 0);
- GrStringDraw(pContext, "Press the + and - buttons at the bottom", -1, 0,
- 146, 0);
- GrStringDraw(pContext, "of the screen to move between the panels.", -1, 0,
- 164, 0);
- }
- //*****************************************************************************
- //
- // Handles paint requests for the primitives canvas widget.
- //
- //*****************************************************************************
- void
- OnPrimitivePaint(tWidget *pWidget, tContext *pContext)
- {
- uint32_t ulIdx;
- tRectangle sRect;
- //
- // Draw a vertical sweep of lines from red to green.
- //
- for(ulIdx = 0; ulIdx <= 8; ulIdx++)
- {
- GrContextForegroundSet(pContext,
- (((((10 - ulIdx) * 255) / 10) << ClrRedShift) |
- (((ulIdx * 255) / 10) << ClrGreenShift)));
- GrLineDraw(pContext, 115, 120, 5, 120 - (11 * ulIdx));
- }
- //
- // Draw a horizontal sweep of lines from green to blue.
- //
- for(ulIdx = 1; ulIdx <= 10; ulIdx++)
- {
- GrContextForegroundSet(pContext,
- (((((10 - ulIdx) * 255) / 10) <<
- ClrGreenShift) |
- (((ulIdx * 255) / 10) << ClrBlueShift)));
- GrLineDraw(pContext, 115, 120, 5 + (ulIdx * 11), 29);
- }
- //
- // Draw a filled circle with an overlapping circle.
- //
- GrContextForegroundSet(pContext, ClrBrown);
- GrCircleFill(pContext, 185, 69, 40);
- GrContextForegroundSet(pContext, ClrSkyBlue);
- GrCircleDraw(pContext, 205, 99, 30);
- //
- // Draw a filled rectangle with an overlapping rectangle.
- //
- GrContextForegroundSet(pContext, ClrSlateGray);
- sRect.i16XMin = 20;
- sRect.i16YMin = 100;
- sRect.i16XMax = 75;
- sRect.i16YMax = 160;
- GrRectFill(pContext, &sRect);
- GrContextForegroundSet(pContext, ClrSlateBlue);
- sRect.i16XMin += 40;
- sRect.i16YMin += 40;
- sRect.i16XMax += 30;
- sRect.i16YMax += 28;
- GrRectDraw(pContext, &sRect);
- //
- // Draw a piece of text in fonts of increasing size.
- //
- GrContextForegroundSet(pContext, ClrSilver);
- GrContextFontSet(pContext, &g_sFontCm14);
- GrStringDraw(pContext, "Strings", -1, 125, 110, 0);
- GrContextFontSet(pContext, &g_sFontCm18);
- GrStringDraw(pContext, "Strings", -1, 145, 124, 0);
- GrContextFontSet(pContext, &g_sFontCm22);
- GrStringDraw(pContext, "Strings", -1, 165, 142, 0);
- GrContextFontSet(pContext, &g_sFontCm24);
- GrStringDraw(pContext, "Strings", -1, 185, 162, 0);
- //
- // Draw an image.
- //
- GrImageDraw(pContext, g_pucLogo, 270, 80);
- }
- //*****************************************************************************
- //
- // Handles paint requests for the canvas demonstration widget.
- //
- //*****************************************************************************
- void
- OnCanvasPaint(tWidget *pWidget, tContext *pContext)
- {
- uint32_t ulIdx;
- //
- // Draw a set of radiating lines.
- //
- GrContextForegroundSet(pContext, ClrGoldenrod);
- for(ulIdx = 50; ulIdx <= 180; ulIdx += 10)
- {
- GrLineDraw(pContext, 210, ulIdx, 310, 230 - ulIdx);
- }
- //
- // Indicate that the contents of this canvas were drawn by the application.
- //
- GrContextFontSet(pContext, &g_sFontCm12);
- GrStringDrawCentered(pContext, "App Drawn", -1, 260, 50, 1);
- }
- //*****************************************************************************
- //
- // Handles change notifications for the check box widgets.
- //
- //*****************************************************************************
- void
- OnCheckChange(tWidget *pWidget, uint32_t bSelected)
- {
- uint32_t ulIdx;
- //
- // Find the index of this check box.
- //
- for(ulIdx = 0; ulIdx < NUM_CHECK_BOXES; ulIdx++)
- {
- if(pWidget == (tWidget *)(g_psCheckBoxes + ulIdx))
- {
- break;
- }
- }
- //
- // Return if the check box could not be found.
- //
- if(ulIdx == NUM_CHECK_BOXES)
- {
- return;
- }
- //
- // Set the matching indicator based on the selected state of the check box.
- //
- CanvasImageSet(g_psCheckBoxIndicators + ulIdx,
- bSelected ? g_pucLightOn : g_pucLightOff);
- WidgetPaint((tWidget *)(g_psCheckBoxIndicators + ulIdx));
- }
- //*****************************************************************************
- //
- // Handles press notifications for the push button widgets.
- //
- //*****************************************************************************
- void
- OnButtonPress(tWidget *pWidget)
- {
- uint32_t ulIdx;
- //
- // Find the index of this push button.
- //
- for(ulIdx = 0; ulIdx < NUM_PUSH_BUTTONS; ulIdx++)
- {
- if(pWidget == (tWidget *)(g_psPushButtons + ulIdx))
- {
- break;
- }
- }
- //
- // Return if the push button could not be found.
- //
- if(ulIdx == NUM_PUSH_BUTTONS)
- {
- return;
- }
- //
- // Toggle the state of this push button indicator.
- //
- g_ulButtonState ^= 1 << ulIdx;
- //
- // Set the matching indicator based on the selected state of the check box.
- //
- CanvasImageSet(g_psPushButtonIndicators + ulIdx,
- (g_ulButtonState & (1 << ulIdx)) ? g_pucLightOn :
- g_pucLightOff);
- WidgetPaint((tWidget *)(g_psPushButtonIndicators + ulIdx));
- }
- //*****************************************************************************
- //
- // Handles notifications from the slider controls.
- //
- //*****************************************************************************
- void
- OnSliderChange(tWidget *pWidget, int32_t lValue)
- {
- static char pcCanvasText[5];
- static char pcSliderText[5];
- //
- // Is this the widget whose value we mirror in the canvas widget and the
- // locked slider?
- //
- if(pWidget == (tWidget *)&g_psSliders[SLIDER_CANVAS_VAL_INDEX])
- {
- //
- // Yes - update the canvas to show the slider value.
- //
- usprintf(pcCanvasText, "%3d%%", lValue);
- CanvasTextSet(&g_sSliderValueCanvas, pcCanvasText);
- WidgetPaint((tWidget *)&g_sSliderValueCanvas);
- //
- // Also update the value of the locked slider to reflect this one.
- //
- SliderValueSet(&g_psSliders[SLIDER_LOCKED_INDEX], lValue);
- WidgetPaint((tWidget *)&g_psSliders[SLIDER_LOCKED_INDEX]);
- }
- if(pWidget == (tWidget *)&g_psSliders[SLIDER_TEXT_VAL_INDEX])
- {
- //
- // Yes - update the canvas to show the slider value.
- //
- usprintf(pcSliderText, "%3d%%", lValue);
- SliderTextSet(&g_psSliders[SLIDER_TEXT_VAL_INDEX], pcSliderText);
- WidgetPaint((tWidget *)&g_psSliders[SLIDER_TEXT_VAL_INDEX]);
- }
- }
- //*****************************************************************************
- //
- // Handles change notifications for the radio button widgets.
- //
- //*****************************************************************************
- void
- OnRadioChange(tWidget *pWidget, uint32_t bSelected)
- {
- uint32_t ulIdx;
- //
- // Find the index of this radio button in the first group.
- //
- for(ulIdx = 0; ulIdx < NUM_RADIO1_BUTTONS; ulIdx++)
- {
- if(pWidget == (tWidget *)(g_psRadioButtons1 + ulIdx))
- {
- break;
- }
- }
- //
- // See if the radio button was found.
- //
- if(ulIdx == NUM_RADIO1_BUTTONS)
- {
- //
- // Find the index of this radio button in the second group.
- //
- for(ulIdx = 0; ulIdx < NUM_RADIO2_BUTTONS; ulIdx++)
- {
- if(pWidget == (tWidget *)(g_psRadioButtons2 + ulIdx))
- {
- break;
- }
- }
- //
- // Return if the radio button could not be found.
- //
- if(ulIdx == NUM_RADIO2_BUTTONS)
- {
- return;
- }
- //
- // Sind the radio button is in the second group, offset the index to
- // the indicators associated with the second group.
- //
- ulIdx += NUM_RADIO1_BUTTONS;
- }
- //
- // Set the matching indicator based on the selected state of the radio
- // button.
- //
- CanvasImageSet(g_psRadioButtonIndicators + ulIdx,
- bSelected ? g_pucLightOn : g_pucLightOff);
- WidgetPaint((tWidget *)(g_psRadioButtonIndicators + ulIdx));
- }
- #endif
- //*****************************************************************************
- // Handles paint requests for the Message Board canvas widget.
- //*****************************************************************************
- void OnDisplayBoardPaint(tWidget *pWidget, tContext *pContext)
- {
- GrContextFontSet(pContext, &g_sFontCm18);
- GrContextForegroundSet(pContext, ClrSilver);
- GrStringDraw(pContext, strBuf, -1,
- 0, 32, 0);
- GrStringDraw(pContext, "Graphics Library.", -1, 0, 50, 0);
- GrStringDraw(pContext, "Each panel shows a different feature of", -1, 0,
- 74, 0);
- GrStringDraw(pContext, "the graphics library. Widgets on the panels", -1, 0,
- 92, 0);
- GrStringDraw(pContext, "are fully operational; pressing them will", -1, 0,
- 110, 0);
- GrStringDraw(pContext, "result in visible feedback of some kind.", -1, 0,
- 128, 0);
- GrStringDraw(pContext, "Press the + and - buttons at the bottom", -1, 0,
- 146, 0);
- GrStringDraw(pContext, "of the screen to move between the panels.", -1, 0,
- 164, 0);
- WidgetPaint(WIDGET_ROOT);
- }
- void OnButtonPress(tWidget *psWidget)
- {
- static uint32_t flag = 0 ;
- if ( flag == 0 )
- {
- flag = 1;
- sprintf ( strBuf, "T:%3d C[H:%d][L:%d]",ui32TempValueC,ui32TempValueCMax,ui32TempValueCMin);
- } else
- {
- flag = 0;
- sprintf ( strBuf, "T:%3d F[H:%d][L:%d]",ui32TempValueF,ui32TempValueFMax,ui32TempValueFMin);
- }
- PushButtonTextSet(&g_sPushBtn, strBuf);
- }
- void Timer0IntHandler(void)
- {
- static uint32_t counter = 0;
- // Clear the timer interrupt
- TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
- g_ui32TickCount++;
- counter++;
- if (counter > 200 )
- { counter = 0;
- // WidgetPaint(WIDGET_ROOT);
- }
- #if 0
- // Read the current state of the GPIO pin and
- // write back the opposite state
- if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2))
- {
- GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
- }
- else
- {
- GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 4);
- }
- #endif
- }
- //*****************************************************************************
- //
- // A simple demonstration of the features of the Stellaris Graphics Library.
- //
- //*****************************************************************************
- int
- main(void)
- {
- tContext sContext;
- uint_fast16_t ui16ItemCount = 0;
- uint32_t ui32Period;
- uint32_t ui32LastTickCount;
- uint32_t ui32ADC0Value[4];
- volatile uint32_t ui32TempAvg;
- FPUEnable();
- FPULazyStackingEnable();
- // Set the clock to 40Mhz derived from the PLL and the external oscillator
- SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
- // setup timer 0
- SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
- TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
- ui32Period = (SysCtlClockGet() / 100) / 2;
- TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period -1);
- IntEnable(INT_TIMER0A);
- TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
- IntMasterEnable();
- TimerEnable(TIMER0_BASE, TIMER_A);
- // setup ADC
- SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
- ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
- ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
- ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
- ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
- ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);
- ADCSequenceEnable(ADC0_BASE, 1);
- Kentec320x240x16_SSD2119Init(); // Initialize the display driver.
- GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119); // Initialize the graphics context.
- #ifdef BANNER
- // Fill the top 24 rows of the screen with blue to create the banner.
- sRect.i16XMin = 0;
- sRect.i16YMin = 0;
- sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1;
- sRect.i16YMax = 23;
- GrContextForegroundSet(&sContext, ClrDarkGoldenrod);
- GrRectFill(&sContext, &sRect);
- // Put a white box around the banner.
- GrContextForegroundSet(&sContext, ClrWhite);
- GrRectDraw(&sContext, &sRect);
- GrContextFontSet(&sContext, &g_sFontCm20);
- GrStringDrawCentered(&sContext, "grlib demo", -1, GrContextDpyWidthGet(&sContext) / 2, 8, 0);
- #endif
- // Configure and enable uDMA
- SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
- SysCtlDelay(10);
- uDMAControlBaseSet(&sDMAControlTable[0]);
- uDMAEnable();
- // Initialize the touch screen driver and have it route its messages to the
- // widget tree.
- TouchScreenInit();
- TouchScreenCallbackSet(WidgetPointerMessage);
- //
- GrOffScreen4BPPInit(&g_sOffscreenDisplay, g_pui8OffscreenBuf, SCOPE_SCREEN_WIDTH, SCOPE_SCREEN_HIGHT);
- GrOffScreen4BPPPaletteSet(&g_sOffscreenDisplay, g_pui32Palette, 0, NUM_PALETTE_ENTRIES);
- g_sSeries0.pvData = g_i8SeriesData0;
- g_sSeries1.pvData = g_i8SeriesData1;
- StripChartSeriesAdd(&g_sStripChart, &g_sSeries0);
- StripChartSeriesAdd(&g_sStripChart, &g_sSeries1);
- WidgetAdd(WIDGET_ROOT, &g_sStripChart.sBase);
- WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sBackground);
- WidgetPaint(WIDGET_ROOT);
- while(1)
- {
- float fElapsedTime;
- float fRadians;
- float fSine;
- //
- // Wait for the next timer tick.
- //
- while(ui32LastTickCount == g_ui32TickCount)
- {
- }
- ui32LastTickCount = g_ui32TickCount;
- ADCIntClear(ADC0_BASE, 1);
- ADCProcessorTrigger(ADC0_BASE, 1);
- while(!ADCIntStatus(ADC0_BASE, 1, false))
- {
- }
- ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
- ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4;
- ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;
- ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;
- if (ui32TempValueC>ui32TempValueCMax)
- ui32TempValueCMax = ui32TempValueC;
- if (ui32TempValueC<ui32TempValueCMin)
- ui32TempValueCMin = ui32TempValueC;
- if (ui32TempValueF>ui32TempValueFMax)
- ui32TempValueFMax = ui32TempValueF;
- if (ui32TempValueF<ui32TempValueFMin)
- ui32TempValueFMin = ui32TempValueF;
- // Preparing to add a new data point to the strip chart ...
- // If the number count of items in the strip chart has reached the
- // maximum value, then the data points need to "slide down" in the
- // buffer so new data can be added at the end.
- //
- if(ui16ItemCount == SERIES_LENGTH)
- {
- memmove(&g_i8SeriesData0[0], &g_i8SeriesData0[1], SERIES_LENGTH - 1);
- memmove(&g_i8SeriesData1[0], &g_i8SeriesData1[1], SERIES_LENGTH - 1);
- }
- //
- // Otherwise, the series data buffer is less than full so just
- // increment the count of data points.
- //
- else
- {
- //
- // Increment the number of items that have been added to the strip
- // chart series data buffer.
- //
- ui16ItemCount++;
- //
- // Since the count of data items has changed, it must be updated in
- // the data series.
- //
- g_sSeries0.ui16NumItems = ui16ItemCount;
- g_sSeries1.ui16NumItems = ui16ItemCount;
- }
- //
- // Compute the elapsed time in decimal seconds, in floating point
- // format.
- //
- fElapsedTime = (float)g_ui32TickCount * FSECONDS_PER_TICK;
- //
- // Convert the time to radians.
- //
- fRadians = fElapsedTime * 2.0 * M_PI;
- //
- // Adjust the period of the wave. This will give us a wave period
- // of 4 seconds, or 0.25 Hz. This number was chosen arbitrarily to
- // provide a nice looking wave on the display.
- //
- fRadians /= 4.0;
- //
- // Compute the sine. Multiply by 0.5 to reduce the amplitude.
- //
- fSine = sinf(fRadians) * 0.5;
- //
- // Finally, save the sine value into the last location in the series
- // data point buffer. Convert the sine amplitude to display pixels.
- // (Amplitude 1 = 32 pixels)
- //
- //g_i8SeriesData[ui16ItemCount - 1] = (int8_t)(fSine * SCOPE_SCREEN_HIGHT/2.0);
- g_i8SeriesData0[ui16ItemCount - 1] = (int8_t)( ui32TempValueC * SCOPE_SCREEN_HIGHT / 100 );
- g_i8SeriesData1[ui16ItemCount - 1] = (int8_t)( ui32TempValueF * SCOPE_SCREEN_HIGHT / 100 );
- //
- // Now that a new data point has been added to the series, advance
- // the strip chart.
- //
- StripChartAdvance(&g_sStripChart, 1);
- //
- // Request a repaint and run the widget processing queue.
- //
- //WidgetPaint(WIDGET_ROOT);
- StripChartPaint(&g_sStripChart.sBase);
- WidgetMessageQueueProcess();
- }
- }
复制代码 |