diff options
Diffstat (limited to 'demos')
-rw-r--r-- | demos/benchmarks/gfxconf.h | 41 | ||||
-rw-r--r-- | demos/benchmarks/main.c | 146 | ||||
-rw-r--r-- | demos/modules/gdisp_basics/main.c | 7 | ||||
-rw-r--r-- | demos/modules/gdisp_circles/main.c | 1 | ||||
-rw-r--r-- | demos/modules/gdisp_text/main.c | 3 |
5 files changed, 193 insertions, 5 deletions
diff --git a/demos/benchmarks/gfxconf.h b/demos/benchmarks/gfxconf.h new file mode 100644 index 00000000..e96bf5fd --- /dev/null +++ b/demos/benchmarks/gfxconf.h @@ -0,0 +1,41 @@ +/** + * This file has a different license to the rest of the GFX system. + * You can copy, modify and distribute this file as you see fit. + * You do not need to publish your source modifications to this file. + * The only thing you are not permitted to do is to relicense it + * under a different license. + */ + +#ifndef _GFXCONF_H +#define _GFXCONF_H + +/* GFX sub-systems to turn on */ +#define GFX_USE_GDISP TRUE +#define GFX_USE_GWIN FALSE +#define GFX_USE_GEVENT FALSE +#define GFX_USE_GTIMER FALSE +#define GFX_USE_GINPUT FALSE + +/* Features for the GDISP sub-system. */ +#define GDISP_NEED_VALIDATION FALSE +#define GDISP_NEED_CLIP FALSE +#define GDISP_NEED_TEXT TRUE +#define GDISP_NEED_CIRCLE FALSE +#define GDISP_NEED_ELLIPSE FALSE +#define GDISP_NEED_ARC FALSE +#define GDISP_NEED_SCROLL FALSE +#define GDISP_NEED_PIXELREAD FALSE +#define GDISP_NEED_CONTROL TRUE +#define GDISP_NEED_MULTITHREAD FALSE +#define GDISP_NEED_ASYNC FALSE +#define GDISP_NEED_MSGAPI FALSE + +/* Builtin Fonts */ +#define GDISP_INCLUDE_FONT_SMALL FALSE +#define GDISP_INCLUDE_FONT_LARGER FALSE +#define GDISP_INCLUDE_FONT_UI1 FALSE +#define GDISP_INCLUDE_FONT_UI2 TRUE +#define GDISP_INCLUDE_FONT_LARGENUMBERS FALSE + +#endif /* _GFXCONF_H */ + diff --git a/demos/benchmarks/main.c b/demos/benchmarks/main.c new file mode 100644 index 00000000..9bd3cef3 --- /dev/null +++ b/demos/benchmarks/main.c @@ -0,0 +1,146 @@ +/*
+ ChibiOS/GFX - Copyright (C) 2012
+ Joel Bodenmann aka Tectu <joel@unormal.org>
+
+ This file is part of ChibiOS/GFX.
+
+ ChibiOS/GFX is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/GFX is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "ch.h"
+#include "hal.h"
+#include "chprintf.h"
+#include "stdlib.h"
+#include "string.h"
+#include "gfx.h"
+
+#define SCB_DEMCR (*(volatile unsigned *)0xE000EDFC)
+#define CPU_RESET_CYCLECOUNTER do { SCB_DEMCR = SCB_DEMCR | 0x01000000; \
+DWT_CYCCNT = 0; \
+DWT_CTRL = DWT_CTRL | 1 ; } while(0)
+
+static int uitoa(unsigned int value, char * buf, int max) {
+ int n = 0;
+ int i = 0;
+ unsigned int tmp = 0;
+
+ if (NULL == buf)
+ return -3;
+
+ if (2 > max)
+ return -4;
+
+ i=1;
+ tmp = value;
+ if (0 > tmp) {
+ tmp *= -1;
+ i++;
+ }
+ for (;;) {
+ tmp /= 10;
+ if (0 >= tmp)
+ break;
+ i++;
+ }
+ if (i >= max) {
+ buf[0] = '?';
+ buf[1] = 0x0;
+ return 2;
+ }
+
+ n = i;
+ tmp = value;
+ if (0 > tmp) {
+ tmp *= -1;
+ }
+ buf[i--] = 0x0;
+ for (;;) {
+ buf[i--] = (tmp % 10) + '0';
+ tmp /= 10;
+ if (0 >= tmp) {
+ break;
+ }
+ }
+ if (-1 != i) {
+ buf[i--] = '-';
+ }
+
+ return n;
+}
+
+void benchmark(void) {
+ uint32_t i, pixels, ms, pps;
+ char pps_str[25];
+ coord_t height, width, rx, ry, rcx, rcy;
+ color_t random_color;
+ font_t font;
+
+ gdispSetOrientation(GDISP_ROTATE_90);
+ gdispClear(Black);
+
+ width = gdispGetWidth();
+ height = gdispGetHeight();
+ font = gdispOpenFont("UI2 Double");
+
+ gdispDrawStringBox(0, 0, width, 30, "ChibiOS/GFX - Benchmark", font, White, justifyCenter);
+
+ font = gdispOpenFont("UI2");
+ gdispDrawStringBox(0, height/2, width, 30, "5000 random rectangles", font, White, justifyCenter);
+
+ chThdSleepMilliseconds(3000);
+
+ /* seed for the rand() */
+ srand(DWT_CYCCNT);
+ pixels = 0;
+
+ CPU_RESET_CYCLECOUNTER;
+
+ for (i = 0; i < 5000; i++) {
+ random_color = (rand() % 65535);
+ rx = (rand() % (width-10));
+ ry = (rand() % (height-10));
+ rcx = (rand() % ((width-rx)-10))+10;
+ rcy = (rand() % ((height-ry)-10))+10;
+
+ gdispFillArea(rx, ry, rcx, rcy, random_color);
+ pixels += (rcx+1)*(rcy+1);
+ }
+
+ ms = DWT_CYCCNT / 168000;
+ pps = (float)pixels/((float)ms/1000.0f);
+
+ memset (pps_str, 0, sizeof(pps_str));
+ uitoa(pps, pps_str, sizeof(pps_str));
+ strcat(pps_str, " Pixels/s");
+
+ font = gdispOpenFont("UI2 Double");
+ gdispClear(Black);
+ gdispDrawStringBox(0, 0, width, 30, "ChibiOS/GFX - Benchmark", font, White, justifyCenter);
+ gdispDrawStringBox(0, height/2, width, 30, pps_str, font, White, justifyCenter);
+ //gdispDrawString(20, height/2, pps_str, font, White);
+}
+
+int main(void) {
+ halInit();
+ chSysInit();
+ gdispInit();
+
+ benchmark();
+
+ while(TRUE) {
+ chThdSleepMilliseconds(500);
+ }
+
+ return 0;
+}
diff --git a/demos/modules/gdisp_basics/main.c b/demos/modules/gdisp_basics/main.c index e18b0e9e..fa0bef45 100644 --- a/demos/modules/gdisp_basics/main.c +++ b/demos/modules/gdisp_basics/main.c @@ -39,9 +39,10 @@ int main(void) { // Code Here
gdispDrawBox(10, 10, width/2, height/2, Yellow);
- gdispFillArea (width/2, height/2, width/2-10, height/2-10, Blue);
- gdispDrawLine (5, 30, width-50, height-40, Red);
- for(i=5, j=0; i < width && j < height; i+=7, j+=i/20)
+ gdispFillArea(width/2, height/2, width/2-10, height/2-10, Blue);
+ gdispDrawLine(5, 30, width-50, height-40, Red);
+
+ for(i = 5, j = 0; i < width && j < height; i += 7, j += i/20)
gdispDrawPixel (i, j, White);
while(TRUE) {
diff --git a/demos/modules/gdisp_circles/main.c b/demos/modules/gdisp_circles/main.c index d682a6ff..45764d4f 100644 --- a/demos/modules/gdisp_circles/main.c +++ b/demos/modules/gdisp_circles/main.c @@ -44,7 +44,6 @@ int main(void) { gdispDrawArc(width-width/8, height/8, 30, 10, 70, Gray);
gdispFillArc(width/8, height/8, 30, 10, 70, Gray);
-
while(TRUE) {
chThdSleepMilliseconds(500);
}
diff --git a/demos/modules/gdisp_text/main.c b/demos/modules/gdisp_text/main.c index 907e84be..4dc45f71 100644 --- a/demos/modules/gdisp_text/main.c +++ b/demos/modules/gdisp_text/main.c @@ -25,7 +25,7 @@ int main(void) {
coord_t width, height;
font_t font1, font2, font3, font4;
- const char *msg;
+ const char *msg;
halInit();
chSysInit();
@@ -47,6 +47,7 @@ int main(void) { // Display large numbers on the right (measuring the string)
msg = "123456";
gdispDrawString(width-gdispGetStringWidth(msg, font4)-3, 3, msg, font4, Green);
+
// Display the font name under it.
msg = gdispGetFontName(font4);
gdispDrawString(width-gdispGetStringWidth(msg, font1)-3, 20, msg, font1, Green);
|