1 /**************************************************************************/
4 @author K. Townsend (microBuilder.eu)
8 Software License Agreement (BSD License)
10 Copyright (c) 2011, microBuilder SARL
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 1. Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 2. Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 3. Neither the name of the copyright holders nor the
21 names of its contributors may be used to endorse or promote products
22 derived from this software without specific prior written permission.
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 /**************************************************************************/
40 #include "projectconfig.h"
43 #include "core/gpio/gpio.h"
44 #include "core/systick/systick.h"
46 #include "drivers/displays/tft/lcd.h"
47 #include "drivers/displays/tft/drawing.h"
48 #include "drivers/displays/tft/touchscreen.h"
49 #include "drivers/displays/tft/dialogues/alphanumeric.h"
51 #include "drivers/displays/tft/fonts/dejavusans9.h"
52 #include "drivers/displays/tft/fonts/dejavusansbold9.h"
53 #include "drivers/displays/tft/fonts/dejavusansmono8.h"
55 /**************************************************************************/
57 Main program entry point. After reset, normal code execution will
60 /**************************************************************************/
63 // Configure cpu and mandatory peripherals
66 #if !defined CFG_TFTLCD
67 #error "CFG_TFTLCD must be enabled in projectconfig.h for this test"
69 #if defined CFG_INTERFACE
70 #error "CFG_INTERFACE must be disabled in projectconfig.h for this test (to save space)"
74 // ---------------------------------------------------------------------
75 drawFill(COLOR_WHITE
);
77 // Render some text using DejaVu Sans 9 and Sans Mono 8
78 // ---------------------------------------------------------------------
79 drawString(5, 10, COLOR_BLACK
, &dejaVuSansBold9ptFontInfo
, "DejaVu Sans 9 Bold");
80 drawString(5, 30, COLOR_BLACK
, &dejaVuSans9ptFontInfo
, "DejaVu Sans 9");
81 drawString(5, 50, COLOR_BLACK
, &dejaVuSansMono8ptFontInfo
, "DejaVu Sans Mono 8");
83 // Change the LCD orientation to render text horizontally
84 // ---------------------------------------------------------------------
85 lcdProperties_t lcdProperties
= lcdGetProperties();
86 // Check if the screen orientation can be changed
87 if (lcdProperties
.orientation
)
89 // Change the orientation
90 lcdSetOrientation(lcdGetOrientation() == LCD_ORIENTATION_PORTRAIT
?
91 LCD_ORIENTATION_LANDSCAPE
: LCD_ORIENTATION_PORTRAIT
);
92 // Render some text in the new orientation
93 drawString(5, 10, COLOR_BLACK
, &dejaVuSans9ptFontInfo
, "DejaVu Sans 9 (Rotated)");
94 // Change the orientation back
95 lcdSetOrientation(lcdGetOrientation() == LCD_ORIENTATION_PORTRAIT
?
96 LCD_ORIENTATION_LANDSCAPE
: LCD_ORIENTATION_PORTRAIT
);
99 // Draw some primitive shapes
100 // ---------------------------------------------------------------------
101 drawLine(5, 65, 200, 65, COLOR_RED
);
102 drawLine(5, 67, 200, 67, COLOR_GREEN
);
103 drawLine(5, 69, 200, 69, COLOR_BLUE
);
104 drawCircleFilled(30, 105, 25, COLOR_BLACK
);
105 drawCircleFilled(30, 105, 23, drawRGB24toRGB565(0x33, 0x00, 0x00));
106 drawCircleFilled(30, 105, 19, drawRGB24toRGB565(0x66, 0x00, 0x00));
107 drawCircleFilled(30, 105, 15, drawRGB24toRGB565(0x99, 0x00, 0x00));
108 drawCircleFilled(30, 105, 11, drawRGB24toRGB565(0xCC, 0x00, 0x00));
109 drawCircleFilled(30, 105, 7, drawRGB24toRGB565(0xFF, 0x00, 0x00));
110 drawRectangleFilled( 80, 80, 180, 125, COLOR_DARKERGRAY
);
111 drawRectangleFilled( 85, 85, 175, 120, COLOR_DARKGRAY
);
112 drawRectangleFilled( 90, 90, 170, 115, COLOR_MEDIUMGRAY
);
113 drawRectangleFilled( 95, 95, 165, 110, COLOR_LIGHTGRAY
);
114 drawRectangleFilled(100, 100, 160, 105, COLOR_PALEGRAY
);
116 // Draw some compound shapes
117 // ---------------------------------------------------------------------
118 drawProgressBar(70, 140, 75, 12, COLOR_BLACK
, COLOR_MEDIUMGRAY
, 78);
119 drawString(5, 144, COLOR_BLACK
, &dejaVuSansBold9ptFontInfo
, "Progress");
120 drawString(155, 144, COLOR_BLACK
, &dejaVuSans9ptFontInfo
, "78%");
121 drawRectangleFilled(0, 175, 239, 210, COLOR_DARKERGRAY
);
122 drawButton(20, 180, 200, 25, &dejaVuSans9ptFontInfo
, 7, "Click For Text Entry", false);
124 // Wait for a valid touch event
125 // ---------------------------------------------------------------------
127 tsTouchError_t error
= -1;
128 bool success
= false;
131 // Wait forever for a valid touch event to occur (ignoring faulty readings)
134 // Only exit this loop when '0' is returned
135 error
= tsWaitForEvent(&data
, 0);
136 // printf("Error: %d X: %u Y: %u \r\n", error, data.x, data.y);
139 // Reset error to an error state in case we got a valid reading, but it's not
140 // within the expected range
143 // Check if the captured touch event is within the specified X/Y range
144 if (data
.x
> 20 && data
.x
< 220 && data
.y
> 180 && data
.y
< 205)
146 // Wait a few milliseconds then display the text input dialogue
148 char* results
= alphaShowDialogue();
149 // At this point, results contains the text from the dialogue ...
150 // clear the screen and show the results
151 drawFill(COLOR_WHITE
);
152 drawString(10, 10, COLOR_BLACK
, &dejaVuSans9ptFontInfo
, "You Entered:");
153 drawString(10, 30, COLOR_BLACK
, &dejaVuSansBold9ptFontInfo
, results
);
154 drawString(10, 155, COLOR_BLACK
, &dejaVuSans9ptFontInfo
, "Thanks ... starting blinky!");
155 // Setting success to true allow the code to move in to blinky
160 uint32_t currentSecond
, lastSecond
;
161 currentSecond
= lastSecond
= 0;
165 // Toggle LED once per second ... rollover = 136 years :)
166 currentSecond
= systickGetSecondsActive();
167 if (currentSecond
!= lastSecond
)
169 lastSecond
= currentSecond
;
170 if (gpioGetValue(CFG_LED_PORT
, CFG_LED_PIN
) == CFG_LED_OFF
)
172 gpioSetValue (CFG_LED_PORT
, CFG_LED_PIN
, CFG_LED_ON
);
176 gpioSetValue (CFG_LED_PORT
, CFG_LED_PIN
, CFG_LED_OFF
);