aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2013-05-25 01:26:52 +1000
committerinmarket <andrewh@inmarket.com.au>2013-05-25 01:26:52 +1000
commit7fbfde42aabbcd30cffba2fba35158236c0a6c6c (patch)
treee85c90a4f21974b706315d64209021e0b2bde764
parent42006a67b5ccfd86f30d8a91cc474681c437eaf6 (diff)
downloaduGFX-7fbfde42aabbcd30cffba2fba35158236c0a6c6c.tar.gz
uGFX-7fbfde42aabbcd30cffba2fba35158236c0a6c6c.tar.bz2
uGFX-7fbfde42aabbcd30cffba2fba35158236c0a6c6c.zip
GOS module, for operating system independance
GMISC fast floating point trig GMISC fast fixed point trig
-rw-r--r--demos/3rdparty/boing/gfxconf.h9
-rw-r--r--demos/3rdparty/boing/main.c8
-rw-r--r--demos/3rdparty/bubbles/gfxconf.h9
-rw-r--r--demos/3rdparty/bubbles/main.c8
-rw-r--r--demos/applications/mandelbrot/gfxconf.h9
-rw-r--r--demos/applications/mandelbrot/main.c7
-rw-r--r--demos/applications/notepad/gfxconf.h5
-rw-r--r--demos/applications/notepad/main.c7
-rw-r--r--demos/benchmarks/gfxconf.h9
-rw-r--r--demos/benchmarks/main.c13
-rw-r--r--demos/modules/gadc/gfxconf.h5
-rw-r--r--demos/modules/gadc/gwinosc.c11
-rw-r--r--demos/modules/gadc/gwinosc.h2
-rw-r--r--demos/modules/gadc/main.c10
-rw-r--r--demos/modules/gaudin/gfxconf.h5
-rw-r--r--demos/modules/gaudin/gwinosc.c11
-rw-r--r--demos/modules/gaudin/gwinosc.h2
-rw-r--r--demos/modules/gaudin/main.c7
-rw-r--r--demos/modules/gdisp/gdisp_basics/gfxconf.h9
-rw-r--r--demos/modules/gdisp/gdisp_basics/main.c10
-rw-r--r--demos/modules/gdisp/gdisp_circles/gfxconf.h9
-rw-r--r--demos/modules/gdisp/gdisp_circles/main.c10
-rw-r--r--demos/modules/gdisp/gdisp_images/gfxconf.h16
-rw-r--r--demos/modules/gdisp/gdisp_images/main.c10
-rw-r--r--demos/modules/gdisp/gdisp_images_animated/gfxconf.h16
-rw-r--r--demos/modules/gdisp/gdisp_images_animated/main.c14
-rw-r--r--demos/modules/gdisp/gdisp_text/gfxconf.h9
-rw-r--r--demos/modules/gdisp/gdisp_text/main.c10
-rw-r--r--demos/modules/ginput/touch_driver_test/gfxconf.h5
-rw-r--r--demos/modules/ginput/touch_driver_test/main.c8
-rw-r--r--demos/modules/graph/gfxconf.h8
-rw-r--r--demos/modules/graph/main.c10
-rw-r--r--demos/modules/gtimer/gfxconf.h9
-rw-r--r--demos/modules/gtimer/main.c7
-rw-r--r--demos/modules/gwin/basic/gfxconf.h8
-rw-r--r--demos/modules/gwin/basic/main.c8
-rw-r--r--demos/modules/gwin/console/gfxconf.h8
-rw-r--r--demos/modules/gwin/console/main.c12
-rw-r--r--demos/modules/gwin/slider/gfxconf.h5
-rw-r--r--demos/modules/gwin/slider/main.c8
-rw-r--r--demos/modules/tdisp/gfxconf.h44
-rw-r--r--demos/modules/tdisp/main.c13
-rw-r--r--drivers/gadc/AT91SAM7/gadc_lld.c2
-rw-r--r--drivers/gaudin/gadc/gaudin_lld.c2
-rw-r--r--drivers/gdisp/HX8347D/gdisp_lld.c6
-rw-r--r--drivers/gdisp/ILI9320/gdisp_lld.c4
-rw-r--r--drivers/gdisp/ILI9325/gdisp_lld.c4
-rw-r--r--drivers/gdisp/ILI9481/gdisp_lld.c6
-rw-r--r--drivers/gdisp/ILI9481/gdisp_lld_board_example_fsmc.h2
-rw-r--r--drivers/gdisp/Nokia6610GE12/gdisp_lld.c4
-rw-r--r--drivers/gdisp/Nokia6610GE8/gdisp_lld.c4
-rw-r--r--drivers/gdisp/S6D1121/gdisp_lld.c6
-rw-r--r--drivers/gdisp/SSD1289/gdisp_lld.c6
-rw-r--r--drivers/gdisp/SSD1289/gdisp_lld_board_example_fsmc.h14
-rw-r--r--drivers/gdisp/SSD1963/gdisp_lld.c18
-rw-r--r--drivers/gdisp/SSD1963/gdisp_lld_board_example_fsmc.h14
-rw-r--r--drivers/gdisp/SSD2119/gdisp_lld.c6
-rw-r--r--drivers/gdisp/TestStub/gdisp_lld.c2
-rw-r--r--drivers/ginput/dial/GADC/ginput_lld_dial.c2
-rw-r--r--drivers/ginput/toggle/Pal/ginput_lld_toggle.c14
-rw-r--r--drivers/ginput/touch/ADS7843/ginput_lld_mouse.c14
-rw-r--r--drivers/ginput/touch/MCU/ginput_lld_mouse.c14
-rw-r--r--drivers/ginput/touch/MCU/ginput_lld_mouse_board_olimex_stm32_lcd.h20
-rw-r--r--drivers/ginput/touch/STMPE811/ginput_lld_mouse.c6
-rw-r--r--drivers/multiple/Win32/gdisp_lld.c4
-rw-r--r--drivers/multiple/X/gdisp_lld.c10
-rw-r--r--drivers/tdisp/HD44780/tdisp_lld.c16
-rw-r--r--drivers/tdisp/HD44780/tdisp_lld_board_olimex_e407.h16
-rw-r--r--drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h16
-rw-r--r--gfx.mk3
-rw-r--r--gfxconf.example.h7
-rw-r--r--include/gadc/gadc.h4
-rw-r--r--include/gaudin/gaudin.h4
-rw-r--r--include/gdisp/fonts.h1
-rw-r--r--include/gdisp/gdisp.h31
-rw-r--r--include/gdisp/image.h42
-rw-r--r--include/gdisp/lld/gdisp_lld_msgs.h24
-rw-r--r--include/gevent/gevent.h11
-rw-r--r--include/gfx.h43
-rw-r--r--include/gfx_rules.h68
-rw-r--r--include/gmisc/gmisc.h96
-rw-r--r--include/gmisc/options.h26
-rw-r--r--include/gos/chibios.h124
-rw-r--r--include/gos/gos.h483
-rw-r--r--include/gos/options.h66
-rw-r--r--include/gos/posix.h31
-rw-r--r--include/gos/win32.h31
-rw-r--r--include/gtimer/gtimer.h6
-rw-r--r--include/gwin/console.h32
-rw-r--r--src/gadc/gadc.c83
-rw-r--r--src/gaudin/gaudin.c21
-rw-r--r--src/gaudout/gaudout.c2
-rw-r--r--src/gdisp/fonts.c3
-rw-r--r--src/gdisp/gdisp.c230
-rw-r--r--src/gdisp/image.c109
-rw-r--r--src/gdisp/image_bmp.c4
-rw-r--r--src/gdisp/image_gif.c8
-rw-r--r--src/gdisp/image_jpg.c2
-rw-r--r--src/gdisp/image_native.c7
-rw-r--r--src/gdisp/image_png.c7
-rw-r--r--src/gevent/gevent.c98
-rw-r--r--src/gfx.c107
-rw-r--r--src/ginput/dial.c2
-rw-r--r--src/ginput/ginput.c26
-rw-r--r--src/ginput/ginput.mk3
-rw-r--r--src/ginput/keyboard.c14
-rw-r--r--src/ginput/mouse.c20
-rw-r--r--src/ginput/toggle.c16
-rw-r--r--src/gmisc/arrayops.c16
-rw-r--r--src/gmisc/gmisc.mk3
-rw-r--r--src/gmisc/trig.c159
-rw-r--r--src/gos/chibios.c207
-rw-r--r--src/gos/gos.mk3
-rw-r--r--src/gos/posix.c32
-rw-r--r--src/gos/win32.c32
-rw-r--r--src/gtimer/gtimer.c83
-rw-r--r--src/gwin/button.c6
-rw-r--r--src/gwin/console.c70
-rw-r--r--src/gwin/graph.c2
-rw-r--r--src/gwin/gwin.c11
-rw-r--r--src/gwin/slider.c2
-rw-r--r--src/tdisp/tdisp.c14
122 files changed, 2213 insertions, 957 deletions
diff --git a/demos/3rdparty/boing/gfxconf.h b/demos/3rdparty/boing/gfxconf.h
index 45b6d7ab..0afcd45b 100644
--- a/demos/3rdparty/boing/gfxconf.h
+++ b/demos/3rdparty/boing/gfxconf.h
@@ -9,12 +9,13 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS TRUE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* 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
diff --git a/demos/3rdparty/boing/main.c b/demos/3rdparty/boing/main.c
index a34cd2a9..96ba5c9d 100644
--- a/demos/3rdparty/boing/main.c
+++ b/demos/3rdparty/boing/main.c
@@ -11,11 +11,11 @@
* width*height pixels out.
* --
* Chris Baird,, <cjb@brushtail.apana.org.au> April 2013
+ *
+ * Modified Andrew Hannam (inmarket) 2013-04-29 New GFX support
*/
#include <math.h>
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#include "ssd2119.h"
@@ -56,9 +56,7 @@ void main (void)
{
uint16_t xx, yy, colour;
- halInit();
- chSysInit();
- gdispInit();
+ gfxInit();
uint16_t width = (uint16_t)gdispGetWidth();
uint16_t height = (uint16_t)gdispGetHeight();
diff --git a/demos/3rdparty/bubbles/gfxconf.h b/demos/3rdparty/bubbles/gfxconf.h
index 9b1f76a6..344a986e 100644
--- a/demos/3rdparty/bubbles/gfxconf.h
+++ b/demos/3rdparty/bubbles/gfxconf.h
@@ -9,12 +9,13 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS TRUE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* 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
diff --git a/demos/3rdparty/bubbles/main.c b/demos/3rdparty/bubbles/main.c
index 81c5dbe3..62ef2830 100644
--- a/demos/3rdparty/bubbles/main.c
+++ b/demos/3rdparty/bubbles/main.c
@@ -8,11 +8,11 @@
* modifiable, provided his name is kept in the source.
* --
* Chris Baird,, <cjb@brushtail.apana.org.au> April 2013
+ *
+ * Modified Andrew Hannam (inmarket) 2013-04-29 New GFX calls
*/
#include <math.h>
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
@@ -149,9 +149,7 @@ int main (void)
{
int pass = 0;
- halInit();
- chSysInit();
- gdispInit();
+ gfxInit();
chThdSleepMilliseconds (10);
gdispClear (background); /* glitches.. */
diff --git a/demos/applications/mandelbrot/gfxconf.h b/demos/applications/mandelbrot/gfxconf.h
index 7093884f..a2b15927 100644
--- a/demos/applications/mandelbrot/gfxconf.h
+++ b/demos/applications/mandelbrot/gfxconf.h
@@ -28,12 +28,13 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS TRUE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* 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 TRUE
diff --git a/demos/applications/mandelbrot/main.c b/demos/applications/mandelbrot/main.c
index 969a9c92..9d753a87 100644
--- a/demos/applications/mandelbrot/main.c
+++ b/demos/applications/mandelbrot/main.c
@@ -25,8 +25,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
void mandelbrot(float x1, float y1, float x2, float y2) {
@@ -66,10 +64,7 @@ int main(void) {
float cx, cy;
float zoom = 1.0f;
- halInit();
- chSysInit();
-
- gdispInit();
+ gfxInit();
/* where to zoom in */
cx = -0.086f;
diff --git a/demos/applications/notepad/gfxconf.h b/demos/applications/notepad/gfxconf.h
index 7ba6483b..b9aa53f9 100644
--- a/demos/applications/notepad/gfxconf.h
+++ b/demos/applications/notepad/gfxconf.h
@@ -28,6 +28,11 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS TRUE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* GFX sub-systems to turn on */
#define GFX_USE_GDISP TRUE
#define GFX_USE_GWIN FALSE
diff --git a/demos/applications/notepad/main.c b/demos/applications/notepad/main.c
index 1dcfd154..d9a6d954 100644
--- a/demos/applications/notepad/main.c
+++ b/demos/applications/notepad/main.c
@@ -25,8 +25,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#define COLOR_SIZE 20
@@ -77,10 +75,7 @@ int main(void) {
color_t color = Black;
uint16_t pen = 0;
- halInit();
- chSysInit();
-
- gdispInit();
+ gfxInit();
ginputGetMouse(0);
gdispSetOrientation(GDISP_ROTATE_90);
diff --git a/demos/benchmarks/gfxconf.h b/demos/benchmarks/gfxconf.h
index d12025e5..5185b50e 100644
--- a/demos/benchmarks/gfxconf.h
+++ b/demos/benchmarks/gfxconf.h
@@ -28,12 +28,13 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS TRUE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* 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
diff --git a/demos/benchmarks/main.c b/demos/benchmarks/main.c
index c3cef762..d39215f0 100644
--- a/demos/benchmarks/main.c
+++ b/demos/benchmarks/main.c
@@ -25,12 +25,10 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "ch.h"
-#include "hal.h"
-#include "chprintf.h"
#include "stdlib.h"
#include "string.h"
#include "gfx.h"
+#include "chprintf.h"
#define SCB_DEMCR (*(volatile unsigned *)0xE000EDFC)
#define CPU_RESET_CYCLECOUNTER do { SCB_DEMCR = SCB_DEMCR | 0x01000000; \
@@ -94,7 +92,6 @@ void benchmark(void) {
font_t font;
gdispSetOrientation(GDISP_ROTATE_90);
- gdispClear(Black);
width = gdispGetWidth();
height = gdispGetHeight();
@@ -105,7 +102,7 @@ void benchmark(void) {
font = gdispOpenFont("UI2");
gdispDrawStringBox(0, height/2, width, 30, "5000 random rectangles", font, White, justifyCenter);
- chThdSleepMilliseconds(3000);
+ gfxSleepMilliseconds(3000);
/* seed for the rand() */
srand(DWT_CYCCNT);
@@ -139,14 +136,12 @@ void benchmark(void) {
}
int main(void) {
- halInit();
- chSysInit();
- gdispInit();
+ gfxInit();
benchmark();
while(TRUE) {
- chThdSleepMilliseconds(500);
+ gfxSleepMilliseconds(500);
}
return 0;
diff --git a/demos/modules/gadc/gfxconf.h b/demos/modules/gadc/gfxconf.h
index 557184cc..17bc5a6b 100644
--- a/demos/modules/gadc/gfxconf.h
+++ b/demos/modules/gadc/gfxconf.h
@@ -33,6 +33,11 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS TRUE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* GFX sub-systems to turn on */
#define GFX_USE_GDISP TRUE
#define GFX_USE_TDISP FALSE
diff --git a/demos/modules/gadc/gwinosc.c b/demos/modules/gadc/gwinosc.c
index 49d9fe22..589fdb9e 100644
--- a/demos/modules/gadc/gwinosc.c
+++ b/demos/modules/gadc/gwinosc.c
@@ -30,10 +30,7 @@
*
* This GWIN superset implements a simple audio oscilloscope using the GADC high speed device.
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
-
#include "gwinosc.h"
/* Include internal GWIN routines so we can build our own superset class */
@@ -55,11 +52,11 @@ GHandle gwinCreateScope(GScopeObject *gs, coord_t x, coord_t y, coord_t cx, coor
/* Initialise the scope object members and allocate memory for buffers */
gs->gwin.type = GW_SCOPE;
- chBSemInit(&gs->bsem, TRUE);
+ gfxSemInit(&gs->bsem, 0, 1);
gs->nextx = 0;
- if (!(gs->lastscopetrace = (coord_t *)chHeapAlloc(NULL, gs->gwin.width * sizeof(coord_t))))
+ if (!(gs->lastscopetrace = (coord_t *)gfxAlloc(gs->gwin.width * sizeof(coord_t))))
return 0;
- if (!(gs->audiobuf = (adcsample_t *)chHeapAlloc(NULL, AUDIOBUFSZ * sizeof(adcsample_t))))
+ if (!(gs->audiobuf = (adcsample_t *)gfxAlloc(AUDIOBUFSZ * sizeof(adcsample_t))))
return 0;
#if TRIGGER_METHOD == TRIGGER_POSITIVERAMP
gs->lasty = gs->gwin.height/2;
@@ -93,7 +90,7 @@ void gwinWaitForScopeTrace(GHandle gh) {
#endif
/* Wait for a set of audio conversions */
- chBSemWait(&gs->bsem);
+ gfxSemWait(&gs->bsem, TIME_INFINITE);
/* Ensure we are drawing in the right area */
#if GDISP_NEED_CLIP
diff --git a/demos/modules/gadc/gwinosc.h b/demos/modules/gadc/gwinosc.h
index 11644be4..1a2e7f18 100644
--- a/demos/modules/gadc/gwinosc.h
+++ b/demos/modules/gadc/gwinosc.h
@@ -57,7 +57,7 @@ typedef struct GScopeObject_t {
GWindowObject gwin; // Base Class
coord_t *lastscopetrace; // To store last scope trace
- BinarySemaphore bsem; // We get signalled on this
+ gfxSem bsem; // We get signalled on this
adcsample_t *audiobuf; // To store audio samples
GEventADC myEvent; // Information on received samples
coord_t nextx; // Where we are up to
diff --git a/demos/modules/gadc/main.c b/demos/modules/gadc/main.c
index f506a473..4acf1da7 100644
--- a/demos/modules/gadc/main.c
+++ b/demos/modules/gadc/main.c
@@ -34,11 +34,8 @@
*
* It also demonstrates how to write your own custom GWIN window type.
*/
-#include "ch.h"
-#include "hal.h"
-#include "chprintf.h"
-
#include "gfx.h"
+#include "chprintf.h"
/* Include our custom gwin oscilloscope */
#include "gwinosc.h"
@@ -143,10 +140,7 @@ int main(void) {
font_t font;
#endif
- halInit();
- chSysInit();
- gdispInit();
- gdispClear(Black);
+ gfxInit();
/* Get the screen dimensions */
swidth = gdispGetWidth();
diff --git a/demos/modules/gaudin/gfxconf.h b/demos/modules/gaudin/gfxconf.h
index d9db73a5..01981087 100644
--- a/demos/modules/gaudin/gfxconf.h
+++ b/demos/modules/gaudin/gfxconf.h
@@ -33,6 +33,11 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS TRUE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* GFX sub-systems to turn on */
#define GFX_USE_GDISP TRUE
#define GFX_USE_TDISP FALSE
diff --git a/demos/modules/gaudin/gwinosc.c b/demos/modules/gaudin/gwinosc.c
index 5a2867c1..82ed4b44 100644
--- a/demos/modules/gaudin/gwinosc.c
+++ b/demos/modules/gaudin/gwinosc.c
@@ -37,10 +37,7 @@
* correctly if we were really building something generic.
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
-
#include "gwinosc.h"
/* Include internal GWIN routines so we can build our own superset class */
@@ -62,11 +59,11 @@ GHandle gwinCreateScope(GScopeObject *gs, coord_t x, coord_t y, coord_t cx, coor
/* Initialise the scope object members and allocate memory for buffers */
gs->gwin.type = GW_SCOPE;
- chBSemInit(&gs->bsem, TRUE);
+ gfxSemInit(&gs->bsem, 0, 1);
gs->nextx = 0;
- if (!(gs->lastscopetrace = (coord_t *)chHeapAlloc(NULL, gs->gwin.width * sizeof(coord_t))))
+ if (!(gs->lastscopetrace = (coord_t *)gfxAlloc(NULL, gs->gwin.width * sizeof(coord_t))))
return 0;
- if (!(gs->audiobuf = (adcsample_t *)chHeapAlloc(NULL, AUDIOBUFSZ * sizeof(adcsample_t))))
+ if (!(gs->audiobuf = (adcsample_t *)gfxAlloc(NULL, AUDIOBUFSZ * sizeof(adcsample_t))))
return 0;
#if TRIGGER_METHOD == TRIGGER_POSITIVERAMP
gs->lasty = gs->gwin.height/2;
@@ -100,7 +97,7 @@ void gwinWaitForScopeTrace(GHandle gh) {
#endif
/* Wait for a set of audio conversions */
- chBSemWait(&gs->bsem);
+ gfxSemWait(&gs->bsem, TIME_INFINITE);
/* Ensure we are drawing in the right area */
#if GDISP_NEED_CLIP
diff --git a/demos/modules/gaudin/gwinosc.h b/demos/modules/gaudin/gwinosc.h
index 9c51e548..d696e276 100644
--- a/demos/modules/gaudin/gwinosc.h
+++ b/demos/modules/gaudin/gwinosc.h
@@ -63,7 +63,7 @@ typedef struct GScopeObject_t {
GWindowObject gwin; // Base Class
coord_t *lastscopetrace; // To store last scope trace
- BinarySemaphore bsem; // We get signalled on this
+ gfxSem bsem; // We get signalled on this
audin_sample_t *audiobuf; // To store audio samples
GEventAudioIn myEvent; // Information on received samples
coord_t nextx; // Where we are up to
diff --git a/demos/modules/gaudin/main.c b/demos/modules/gaudin/main.c
index f532b324..a647d4af 100644
--- a/demos/modules/gaudin/main.c
+++ b/demos/modules/gaudin/main.c
@@ -31,8 +31,6 @@
*
* It also demonstrates how to write your own custom GWIN window type.
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
/* Include our custom gwin audio oscilloscope */
@@ -52,10 +50,7 @@ int main(void) {
GHandle ghScope;
coord_t swidth, sheight;
- halInit();
- chSysInit();
- gdispInit();
- gdispClear(Black);
+ gfxInit();
/* Get the screen dimensions */
swidth = gdispGetWidth();
diff --git a/demos/modules/gdisp/gdisp_basics/gfxconf.h b/demos/modules/gdisp/gdisp_basics/gfxconf.h
index f64884a0..b632f6e0 100644
--- a/demos/modules/gdisp/gdisp_basics/gfxconf.h
+++ b/demos/modules/gdisp/gdisp_basics/gfxconf.h
@@ -28,12 +28,13 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS TRUE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* 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 TRUE
diff --git a/demos/modules/gdisp/gdisp_basics/main.c b/demos/modules/gdisp/gdisp_basics/main.c
index 134f2473..d7a1b5e3 100644
--- a/demos/modules/gdisp/gdisp_basics/main.c
+++ b/demos/modules/gdisp/gdisp_basics/main.c
@@ -25,20 +25,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
int main(void) {
coord_t width, height;
coord_t i, j;
- halInit();
- chSysInit();
-
/* Initialize and clear the display */
- gdispInit();
- gdispClear(Black);
+ gfxInit();
// Get the screen size
width = gdispGetWidth();
@@ -53,7 +47,7 @@ int main(void) {
gdispDrawPixel (i, j, White);
while(TRUE) {
- chThdSleepMilliseconds(500);
+ gfxSleepMilliseconds(500);
}
}
diff --git a/demos/modules/gdisp/gdisp_circles/gfxconf.h b/demos/modules/gdisp/gdisp_circles/gfxconf.h
index cc60c46b..cd7515d9 100644
--- a/demos/modules/gdisp/gdisp_circles/gfxconf.h
+++ b/demos/modules/gdisp/gdisp_circles/gfxconf.h
@@ -28,12 +28,13 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS TRUE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* 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 TRUE
diff --git a/demos/modules/gdisp/gdisp_circles/main.c b/demos/modules/gdisp/gdisp_circles/main.c
index 395af009..3a9675bb 100644
--- a/demos/modules/gdisp/gdisp_circles/main.c
+++ b/demos/modules/gdisp/gdisp_circles/main.c
@@ -25,19 +25,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
int main(void) {
coord_t width, height;
- halInit();
- chSysInit();
-
/* Initialize and clear the display */
- gdispInit();
- gdispClear(Black);
+ gfxInit();
// Get the screen size
width = gdispGetWidth();
@@ -52,7 +46,7 @@ int main(void) {
gdispFillArc(width/8, height/8, 30, 10, 70, Gray);
while(TRUE) {
- chThdSleepMilliseconds(500);
+ gfxSleepMilliseconds(500);
}
}
diff --git a/demos/modules/gdisp/gdisp_images/gfxconf.h b/demos/modules/gdisp/gdisp_images/gfxconf.h
index e76ddd72..866f3ba7 100644
--- a/demos/modules/gdisp/gdisp_images/gfxconf.h
+++ b/demos/modules/gdisp/gdisp_images/gfxconf.h
@@ -28,12 +28,13 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS TRUE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* 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 TRUE
@@ -65,11 +66,4 @@
#define GDISP_NEED_IMAGE_JPG FALSE
#define GDISP_NEED_IMAGE_PNG FALSE
-/* Features for the GWIN sub-system. */
-#define GWIN_NEED_BUTTON FALSE
-#define GWIN_NEED_CONSOLE FALSE
-
-/* Features for the GINPUT sub-system. */
-#define GINPUT_NEED_MOUSE FALSE
-
#endif /* _GFXCONF_H */
diff --git a/demos/modules/gdisp/gdisp_images/main.c b/demos/modules/gdisp/gdisp_images/main.c
index a6fa58d8..3fc20490 100644
--- a/demos/modules/gdisp/gdisp_images/main.c
+++ b/demos/modules/gdisp/gdisp_images/main.c
@@ -25,8 +25,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#ifdef WIN32
@@ -44,11 +42,7 @@ static gdispImage myImage;
int main(void) {
coord_t swidth, sheight;
- halInit(); // Initialize the Hardware
- chSysInit(); // Initialize the OS
- gdispInit(); // Initialize the display
-
- gdispClear(Black);
+ gfxInit(); // Initialize the display
// Get the display dimensions
swidth = gdispGetWidth();
@@ -66,7 +60,7 @@ int main(void) {
gdispImageClose(&myImage);
while(1) {
- chThdSleepMilliseconds(1000);
+ gfxSleepMilliseconds(1000);
}
return 0;
diff --git a/demos/modules/gdisp/gdisp_images_animated/gfxconf.h b/demos/modules/gdisp/gdisp_images_animated/gfxconf.h
index cd368e95..9a734924 100644
--- a/demos/modules/gdisp/gdisp_images_animated/gfxconf.h
+++ b/demos/modules/gdisp/gdisp_images_animated/gfxconf.h
@@ -9,12 +9,13 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS TRUE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* 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 TRUE
@@ -47,11 +48,4 @@
#define GDISP_NEED_IMAGE_PNG FALSE
#define GDISP_NEED_IMAGE_ACCOUNTING FALSE
-/* Features for the GWIN sub-system. */
-#define GWIN_NEED_BUTTON FALSE
-#define GWIN_NEED_CONSOLE FALSE
-
-/* Features for the GINPUT sub-system. */
-#define GINPUT_NEED_MOUSE FALSE
-
#endif /* _GFXCONF_H */
diff --git a/demos/modules/gdisp/gdisp_images_animated/main.c b/demos/modules/gdisp/gdisp_images_animated/main.c
index d5c3d712..8502dcf9 100644
--- a/demos/modules/gdisp/gdisp_images_animated/main.c
+++ b/demos/modules/gdisp/gdisp_images_animated/main.c
@@ -18,8 +18,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#define USE_IMAGE_CACHE FALSE // Only if you want to get performance at the expense of RAM
@@ -51,11 +49,9 @@ static gdispImage myImage;
*/
int main(void) {
coord_t swidth, sheight;
- systime_t delay;
+ delaytime_t delay;
- halInit(); // Initialize the Hardware
- chSysInit(); // Initialize the OS
- gdispInit(); // Initialize the display
+ gfxInit(); // Initialize the display
gdispClear(MY_BG_COLOR);
@@ -67,7 +63,7 @@ int main(void) {
#if USE_MEMORY_FILE
gdispImageSetMemoryReader(&myImage, testanim);
#else
- gdispImageSetSimulFileReader(&myImage, "testanim.gif");
+ gdispImageSetFileReader(&myImage, "testanim.gif");
#endif
if (gdispImageOpen(&myImage) == GDISP_IMAGE_ERR_OK) {
@@ -87,14 +83,14 @@ int main(void) {
}
SHOW_ERROR(Yellow);
if (delay != TIME_IMMEDIATE)
- chThdSleepMilliseconds(delay);
+ gfxSleepMilliseconds(delay);
}
gdispImageClose(&myImage);
} else
SHOW_ERROR(Red);
while(1) {
- chThdSleepMilliseconds(1000);
+ gfxSleepMilliseconds(1000);
}
return 0;
diff --git a/demos/modules/gdisp/gdisp_text/gfxconf.h b/demos/modules/gdisp/gdisp_text/gfxconf.h
index 007de8e4..01fc2749 100644
--- a/demos/modules/gdisp/gdisp_text/gfxconf.h
+++ b/demos/modules/gdisp/gdisp_text/gfxconf.h
@@ -28,12 +28,13 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS TRUE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* 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 TRUE
diff --git a/demos/modules/gdisp/gdisp_text/main.c b/demos/modules/gdisp/gdisp_text/main.c
index 4062e07c..042ccc5b 100644
--- a/demos/modules/gdisp/gdisp_text/main.c
+++ b/demos/modules/gdisp/gdisp_text/main.c
@@ -25,8 +25,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
int main(void) {
@@ -34,12 +32,8 @@ int main(void) {
font_t font1, font2, font3, font4;
const char *msg;
- halInit();
- chSysInit();
-
/* Initialize and clear the display */
- gdispInit();
- gdispClear(Black);
+ gfxInit();
// Get the screen size
width = gdispGetWidth();
@@ -73,7 +67,7 @@ int main(void) {
// Wait forever
while(TRUE) {
- chThdSleepMilliseconds(500);
+ gfxSleepMilliseconds(500);
}
}
diff --git a/demos/modules/ginput/touch_driver_test/gfxconf.h b/demos/modules/ginput/touch_driver_test/gfxconf.h
index 87787527..ee96f23c 100644
--- a/demos/modules/ginput/touch_driver_test/gfxconf.h
+++ b/demos/modules/ginput/touch_driver_test/gfxconf.h
@@ -28,6 +28,11 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS TRUE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* GFX sub-systems to turn on */
#define GFX_USE_GDISP TRUE
#define GFX_USE_GWIN TRUE
diff --git a/demos/modules/ginput/touch_driver_test/main.c b/demos/modules/ginput/touch_driver_test/main.c
index 80c85273..424b2587 100644
--- a/demos/modules/ginput/touch_driver_test/main.c
+++ b/demos/modules/ginput/touch_driver_test/main.c
@@ -25,10 +25,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "ch.h"
-#include "hal.h"
-#include "chprintf.h"
#include "gfx.h"
+#include "chprintf.h"
static GConsoleObject gc;
static GButtonObject gNext;
@@ -49,9 +47,7 @@ int main(void) {
GEventType deviceType;
font_t font;
- halInit(); // Initialise the Hardware
- chSysInit(); // Initialize the OS
- gdispInit(); // Initialize the display
+ gfxInit(); // Initialize the display
// Get the display dimensions
swidth = gdispGetWidth();
diff --git a/demos/modules/graph/gfxconf.h b/demos/modules/graph/gfxconf.h
index ee36fb93..f54cfe1a 100644
--- a/demos/modules/graph/gfxconf.h
+++ b/demos/modules/graph/gfxconf.h
@@ -28,12 +28,14 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS TRUE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* GFX sub-systems to turn on */
#define GFX_USE_GDISP TRUE
#define GFX_USE_GWIN TRUE
-#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 TRUE
diff --git a/demos/modules/graph/main.c b/demos/modules/graph/main.c
index 79935083..f74ecb5d 100644
--- a/demos/modules/graph/main.c
+++ b/demos/modules/graph/main.c
@@ -25,8 +25,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#include "math.h"
@@ -64,11 +62,7 @@ int main(void) {
GHandle gh;
uint16_t i;
- halInit();
- chSysInit();
-
- gdispInit();
- gdispClear(Black);
+ gfxInit();
gh = gwinCreateGraph(&g, 0, 0, gdispGetWidth(), gdispGetHeight());
@@ -92,7 +86,7 @@ int main(void) {
gwinGraphDrawPoints(gh, data, sizeof(data)/sizeof(data[0]));
while(TRUE) {
- chThdSleepMilliseconds(100);
+ gfxSleepMilliseconds(100);
}
}
diff --git a/demos/modules/gtimer/gfxconf.h b/demos/modules/gtimer/gfxconf.h
index 931357a5..8e996d52 100644
--- a/demos/modules/gtimer/gfxconf.h
+++ b/demos/modules/gtimer/gfxconf.h
@@ -28,11 +28,12 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS TRUE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* GFX sub-systems to turn on */
-#define GFX_USE_GDISP FALSE
-#define GFX_USE_GWIN FALSE
-#define GFX_USE_GEVENT FALSE
#define GFX_USE_GTIMER TRUE
-#define GFX_USE_GINPUT FALSE
#endif /* _GFXCONF_H */
diff --git a/demos/modules/gtimer/main.c b/demos/modules/gtimer/main.c
index 403491ea..6d09d594 100644
--- a/demos/modules/gtimer/main.c
+++ b/demos/modules/gtimer/main.c
@@ -25,8 +25,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
GTimer GT1, GT2;
@@ -44,8 +42,7 @@ void callback2(void* arg) {
}
int main(void) {
- halInit();
- chSysInit();
+ gfxInit();
/* initialize the timers */
gtimerInit(&GT1);
@@ -58,7 +55,7 @@ int main(void) {
gtimerStart(&GT2, callback2, NULL, FALSE, 1000);
while(TRUE) {
- chThdSleepMilliseconds(500);
+ gfxSleepMilliseconds(500);
}
return 0;
diff --git a/demos/modules/gwin/basic/gfxconf.h b/demos/modules/gwin/basic/gfxconf.h
index e567e5a0..dd8376bf 100644
--- a/demos/modules/gwin/basic/gfxconf.h
+++ b/demos/modules/gwin/basic/gfxconf.h
@@ -9,12 +9,14 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS TRUE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* GFX sub-systems to turn on */
#define GFX_USE_GDISP TRUE
#define GFX_USE_GWIN TRUE
-#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 TRUE
diff --git a/demos/modules/gwin/basic/main.c b/demos/modules/gwin/basic/main.c
index a0326fac..624eed18 100644
--- a/demos/modules/gwin/basic/main.c
+++ b/demos/modules/gwin/basic/main.c
@@ -18,20 +18,16 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
/* The handles for our two Windows */
GHandle GW1, GW2;
int main(void) {
- halInit();
- chSysInit();
coord_t i, j;
/* Initialize and clear the display */
- gdispInit();
+ gfxInit();
gdispClear(Lime);
/* Create two windows */
@@ -61,7 +57,7 @@ int main(void) {
gwinFillCircle(GW2, 20, 20, 15);
while(TRUE) {
- chThdSleepMilliseconds(500);
+ gfxSleepMilliseconds(500);
}
}
diff --git a/demos/modules/gwin/console/gfxconf.h b/demos/modules/gwin/console/gfxconf.h
index 178beb86..46361c9b 100644
--- a/demos/modules/gwin/console/gfxconf.h
+++ b/demos/modules/gwin/console/gfxconf.h
@@ -9,12 +9,14 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS TRUE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* GFX sub-systems to turn on */
#define GFX_USE_GDISP TRUE
#define GFX_USE_GWIN TRUE
-#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 TRUE
diff --git a/demos/modules/gwin/console/main.c b/demos/modules/gwin/console/main.c
index 90ebf86f..d968b920 100644
--- a/demos/modules/gwin/console/main.c
+++ b/demos/modules/gwin/console/main.c
@@ -18,10 +18,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "ch.h"
-#include "hal.h"
-#include "chprintf.h"
#include "gfx.h"
+#include "chprintf.h"
/* The handles for our three consoles */
GHandle GW1, GW2, GW3;
@@ -33,12 +31,8 @@ int main(void) {
uint8_t i;
font_t font1, font2;
- halInit();
- chSysInit();
-
/* initialize and clear the display */
- gdispInit();
- gdispClear(Black);
+ gfxInit();
font1 = gdispOpenFont("UI2 Double");
font2 = gdispOpenFont("Small");
@@ -81,7 +75,7 @@ int main(void) {
}
while(TRUE) {
- chThdSleepMilliseconds(500);
+ gfxSleepMilliseconds(500);
}
}
diff --git a/demos/modules/gwin/slider/gfxconf.h b/demos/modules/gwin/slider/gfxconf.h
index 947fc4c8..84698905 100644
--- a/demos/modules/gwin/slider/gfxconf.h
+++ b/demos/modules/gwin/slider/gfxconf.h
@@ -9,6 +9,11 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS TRUE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* GFX sub-systems to turn on */
#define GFX_USE_GDISP TRUE
#define GFX_USE_GWIN TRUE
diff --git a/demos/modules/gwin/slider/main.c b/demos/modules/gwin/slider/main.c
index 19a56f6a..f1d4248d 100644
--- a/demos/modules/gwin/slider/main.c
+++ b/demos/modules/gwin/slider/main.c
@@ -18,8 +18,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#include "chprintf.h"
@@ -35,11 +33,7 @@ int main(void) {
GEventGWinSlider * pSliderEvent;
BaseSequentialStream *consout;
- halInit(); // Initialize the Hardware
- chSysInit(); // Initialize the OS
- gdispInit(); // Initialize the display
-
- gdispClear(Black);
+ gfxInit(); // Initialize the display
// Get the display dimensions
swidth = gdispGetWidth();
diff --git a/demos/modules/tdisp/gfxconf.h b/demos/modules/tdisp/gfxconf.h
index cdc0dfdd..eeaaa2a2 100644
--- a/demos/modules/tdisp/gfxconf.h
+++ b/demos/modules/tdisp/gfxconf.h
@@ -28,47 +28,13 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS TRUE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* GFX sub-systems to turn on */
#define GFX_USE_TDISP TRUE
-#define GFX_USE_GDISP FALSE
-#define GFX_USE_GWIN FALSE
-#define GFX_USE_GEVENT FALSE
-#define GFX_USE_GTIMER FALSE
-#define GFX_USE_GINPUT FALSE
-
-/* Features for the GDISP subsystem */
-#define GDISP_NEED_VALIDATION FALSE
-#define GDISP_NEED_CLIP FALSE
-#define GDISP_NEED_TEXT FALSE
-#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 FALSE
-#define GDISP_NEED_MULTITHREAD FALSE
-#define GDISP_NEED_ASYNC FALSE
-#define GDISP_NEED_MSGAPI FALSE
-
-/* Features for the TDISP subsystem */
-#define TDISP_NEED_4BIT_MODE TRUE
-#define TDISP_NEED_8BIT_MODE 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 FALSE
-#define GDISP_INCLUDE_FONT_LARGENUMBERS FALSE
-
-/* GWIN */
-#define GWIN_NEED_CONSOLE FALSE
-#define GWIN_NEED_GRAPH FALSE
-#define GWIN_NEED_BUTTON FALSE
-#define GWIN_NEED_DIAL FALSE
-
-/* GINPUT */
-#define GINPUT_NEED_MOUSE FALSE
#endif /* _GFXCONF_H */
diff --git a/demos/modules/tdisp/main.c b/demos/modules/tdisp/main.c
index bf6f6c46..face28c1 100644
--- a/demos/modules/tdisp/main.c
+++ b/demos/modules/tdisp/main.c
@@ -25,21 +25,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
int main(void) {
uint8_t charmap[8];
- halInit();
- chSysInit();
-
- tdispInit();
-
- /* reset cursor position and clear the screen */
- tdispHome();
- tdispClear();
+ gfxInit();
/* set cursor position and draw single characters */
tdispSetCursor(4, 0);
@@ -68,7 +59,7 @@ int main(void) {
tdispDrawChar(0);
while(TRUE) {
- chThdSleepMilliseconds(250);
+ gfxSleepMilliseconds(250);
}
}
diff --git a/drivers/gadc/AT91SAM7/gadc_lld.c b/drivers/gadc/AT91SAM7/gadc_lld.c
index 00af65a5..3425cbf0 100644
--- a/drivers/gadc/AT91SAM7/gadc_lld.c
+++ b/drivers/gadc/AT91SAM7/gadc_lld.c
@@ -14,8 +14,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GADC
diff --git a/drivers/gaudin/gadc/gaudin_lld.c b/drivers/gaudin/gadc/gaudin_lld.c
index 42b4aafc..db7a2bb2 100644
--- a/drivers/gaudin/gadc/gaudin_lld.c
+++ b/drivers/gaudin/gadc/gaudin_lld.c
@@ -13,8 +13,6 @@
*
* @{
*/
-#include "ch.h"
-#include "hal.h"
/**
* We are now implementing the driver - pull in our channel table
diff --git a/drivers/gdisp/HX8347D/gdisp_lld.c b/drivers/gdisp/HX8347D/gdisp_lld.c
index 8443ca3d..2d9720bc 100644
--- a/drivers/gdisp/HX8347D/gdisp_lld.c
+++ b/drivers/gdisp/HX8347D/gdisp_lld.c
@@ -13,8 +13,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#include "HX8347D.h"
@@ -57,8 +55,8 @@
#define write_ram(color1, color2) { write_index(0x22); write_ram8(color1,color2); }
#define stream_start() { write_index(0x22); spiStart(&SPID1, &spi1cfg2); }
#define stream_stop() {while(((SPI1->SR & SPI_SR_TXE) == 0) || ((SPI1->SR & SPI_SR_BSY) != 0));palSetPad(GPIOA, 4);spiStart(&SPID1, &spi1cfg1); }
-#define delay(us) chThdSleepMicroseconds(us)
-#define delayms(ms) chThdSleepMilliseconds(ms)
+#define delay(us) gfxSleepMicroseconds(us)
+#define delayms(ms) gfxSleepMilliseconds(ms)
static inline void set_cursor(coord_t x, coord_t y) {
write_reg(HX8347D_REG_SCL, (uint8_t) x);
diff --git a/drivers/gdisp/ILI9320/gdisp_lld.c b/drivers/gdisp/ILI9320/gdisp_lld.c
index b2e47c22..8c9dbed7 100644
--- a/drivers/gdisp/ILI9320/gdisp_lld.c
+++ b/drivers/gdisp/ILI9320/gdisp_lld.c
@@ -13,8 +13,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
@@ -66,7 +64,7 @@ uint32_t DISPLAY_CODE;
/* Driver local functions. */
/*===========================================================================*/
static inline void lld_lcdDelay(uint16_t us) {
- chThdSleepMicroseconds(us);
+ gfxSleepMicroseconds(us);
}
static inline void lld_lcdWriteIndex(uint16_t index) {
diff --git a/drivers/gdisp/ILI9325/gdisp_lld.c b/drivers/gdisp/ILI9325/gdisp_lld.c
index 1603b0b0..4ca5fe78 100644
--- a/drivers/gdisp/ILI9325/gdisp_lld.c
+++ b/drivers/gdisp/ILI9325/gdisp_lld.c
@@ -13,8 +13,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
@@ -64,7 +62,7 @@ uint32_t DISPLAY_CODE;
/* Driver local functions. */
/*===========================================================================*/
static inline void lld_lcdDelay(uint16_t us) {
- chThdSleepMicroseconds(us);
+ gfxSleepMicroseconds(us);
}
static inline void lld_lcdWriteIndex(uint16_t index) {
diff --git a/drivers/gdisp/ILI9481/gdisp_lld.c b/drivers/gdisp/ILI9481/gdisp_lld.c
index 2534dcbd..47e5f679 100644
--- a/drivers/gdisp/ILI9481/gdisp_lld.c
+++ b/drivers/gdisp/ILI9481/gdisp_lld.c
@@ -14,8 +14,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
@@ -60,8 +58,8 @@
#define write_reg(reg, data) { write_index(reg); write_data(data); }
#define stream_start() write_index(0x2C);
#define stream_stop()
-#define delay(us) chThdSleepMicroseconds(us)
-#define delayms(ms) chThdSleepMilliseconds(ms)
+#define delay(us) gfxSleepMicroseconds(us)
+#define delayms(ms) gfxSleepMilliseconds(ms)
static inline void set_cursor(coord_t x, coord_t y) {
write_index(0x2A);
diff --git a/drivers/gdisp/ILI9481/gdisp_lld_board_example_fsmc.h b/drivers/gdisp/ILI9481/gdisp_lld_board_example_fsmc.h
index 7e9ce2b4..51013d87 100644
--- a/drivers/gdisp/ILI9481/gdisp_lld_board_example_fsmc.h
+++ b/drivers/gdisp/ILI9481/gdisp_lld_board_example_fsmc.h
@@ -45,7 +45,7 @@ static inline void init_board(void) {
rccEnableAHB3(RCC_AHB3ENR_FSMCEN, 0);
#if defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
- if (dmaStreamAllocate(GDISP_DMA_STREAM, 0, NULL, NULL)) chSysHalt();
+ if (dmaStreamAllocate(GDISP_DMA_STREAM, 0, NULL, NULL)) gfxExit();
dmaStreamSetMemory0(GDISP_DMA_STREAM, &GDISP_RAM);
dmaStreamSetMode(GDISP_DMA_STREAM, STM32_DMA_CR_PL(0) | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_DIR_M2M);
#endif
diff --git a/drivers/gdisp/Nokia6610GE12/gdisp_lld.c b/drivers/gdisp/Nokia6610GE12/gdisp_lld.c
index dead6bab..860c3ca3 100644
--- a/drivers/gdisp/Nokia6610GE12/gdisp_lld.c
+++ b/drivers/gdisp/Nokia6610GE12/gdisp_lld.c
@@ -13,8 +13,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
@@ -67,7 +65,7 @@
#endif
// Some macros just to make reading the code easier
-#define delayms(ms) chThdSleepMilliseconds(ms)
+#define delayms(ms) gfxSleepMilliseconds(ms)
#define write_data2(d1, d2) { write_data(d1); write_data(d2); }
#define write_data3(d1, d2, d3) { write_data(d1); write_data(d2); write_data(d3); }
#define write_cmd1(cmd, d1) { write_cmd(cmd); write_data(d1); }
diff --git a/drivers/gdisp/Nokia6610GE8/gdisp_lld.c b/drivers/gdisp/Nokia6610GE8/gdisp_lld.c
index c4264bc2..64f65ae7 100644
--- a/drivers/gdisp/Nokia6610GE8/gdisp_lld.c
+++ b/drivers/gdisp/Nokia6610GE8/gdisp_lld.c
@@ -13,8 +13,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
@@ -72,7 +70,7 @@
#endif
// Some macros just to make reading the code easier
-#define delayms(ms) chThdSleepMilliseconds(ms)
+#define delayms(ms) gfxSleepMilliseconds(ms)
#define write_data2(d1, d2) { write_data(d1); write_data(d2); }
#define write_data3(d1, d2, d3) { write_data(d1); write_data(d2); write_data(d3); }
#define write_data4(d1, d2, d3, d4) { write_data(d1); write_data(d2); write_data(d3); write_data(d4); }
diff --git a/drivers/gdisp/S6D1121/gdisp_lld.c b/drivers/gdisp/S6D1121/gdisp_lld.c
index a76cdde0..e8099ff6 100644
--- a/drivers/gdisp/S6D1121/gdisp_lld.c
+++ b/drivers/gdisp/S6D1121/gdisp_lld.c
@@ -13,8 +13,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
@@ -58,8 +56,8 @@
#define write_reg(reg, data) { write_index(reg); write_data(data); }
#define stream_start() write_index(0x0022);
#define stream_stop()
-#define delay(us) chThdSleepMicroseconds(us)
-#define delayms(ms) chThdSleepMilliseconds(ms)
+#define delay(us) gfxSleepMicroseconds(us)
+#define delayms(ms) gfxSleepMilliseconds(ms)
static inline void set_cursor(coord_t x, coord_t y) {
/* R20h - 8 bit
diff --git a/drivers/gdisp/SSD1289/gdisp_lld.c b/drivers/gdisp/SSD1289/gdisp_lld.c
index a3daeb88..7b603520 100644
--- a/drivers/gdisp/SSD1289/gdisp_lld.c
+++ b/drivers/gdisp/SSD1289/gdisp_lld.c
@@ -13,8 +13,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
@@ -54,8 +52,8 @@
#define write_reg(reg, data) { write_index(reg); write_data(data); }
#define stream_start() write_index(0x0022);
#define stream_stop()
-#define delay(us) chThdSleepMicroseconds(us)
-#define delayms(ms) chThdSleepMilliseconds(ms)
+#define delay(us) gfxSleepMicroseconds(us)
+#define delayms(ms) gfxSleepMilliseconds(ms)
static inline void set_cursor(coord_t x, coord_t y) {
/* Reg 0x004E is an 8 bit value
diff --git a/drivers/gdisp/SSD1289/gdisp_lld_board_example_fsmc.h b/drivers/gdisp/SSD1289/gdisp_lld_board_example_fsmc.h
index 7223a507..48891078 100644
--- a/drivers/gdisp/SSD1289/gdisp_lld_board_example_fsmc.h
+++ b/drivers/gdisp/SSD1289/gdisp_lld_board_example_fsmc.h
@@ -1,9 +1,9 @@
-/*
- * This file is subject to the terms of the GFX License, v1.0. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://chibios-gfx.com/license.html
- */
+/*
+ * This file is subject to the terms of the GFX License, v1.0. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://chibios-gfx.com/license.html
+ */
/**
* @file drivers/gdisp/SSD1289/gdisp_lld_board_example_fsmc.h
@@ -44,7 +44,7 @@ static inline void init_board(void) {
rccEnableAHB3(RCC_AHB3ENR_FSMCEN, 0);
#if defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
- if (dmaStreamAllocate(GDISP_DMA_STREAM, 0, NULL, NULL)) chSysHalt();
+ if (dmaStreamAllocate(GDISP_DMA_STREAM, 0, NULL, NULL)) gfxExit();
dmaStreamSetMemory0(GDISP_DMA_STREAM, &GDISP_RAM);
dmaStreamSetMode(GDISP_DMA_STREAM, STM32_DMA_CR_PL(0) | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_DIR_M2M);
#endif
diff --git a/drivers/gdisp/SSD1963/gdisp_lld.c b/drivers/gdisp/SSD1963/gdisp_lld.c
index 8d12cf60..0a70406c 100644
--- a/drivers/gdisp/SSD1963/gdisp_lld.c
+++ b/drivers/gdisp/SSD1963/gdisp_lld.c
@@ -13,8 +13,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
@@ -61,7 +59,7 @@ bool_t gdisp_lld_init(void) {
init_board();
write_index(SSD1963_SOFT_RESET);
- chThdSleepMicroseconds(100);
+ gfxSleepMicroseconds(100);
/* Driver PLL config */
write_index(SSD1963_SET_PLL_MN);
@@ -71,14 +69,14 @@ bool_t gdisp_lld_init(void) {
write_index(SSD1963_SET_PLL); // Enable PLL
write_data(0x01);
- chThdSleepMicroseconds(200);
+ gfxSleepMicroseconds(200);
write_index(SSD1963_SET_PLL); // Use PLL
write_data(0x03);
- chThdSleepMicroseconds(200);
+ gfxSleepMicroseconds(200);
write_index(SSD1963_SOFT_RESET);
- chThdSleepMicroseconds(100);
+ gfxSleepMicroseconds(100);
/* Screen size */
write_index(SSD1963_SET_GDISP_MODE);
@@ -362,13 +360,13 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) {
switch((gdisp_powermode_t)value) {
case powerOff:
write_index(SSD1963_EXIT_SLEEP_MODE); // leave sleep mode
- chThdSleepMilliseconds(5);
+ gfxSleepMilliseconds(5);
write_index(SSD1963_SET_DISPLAY_OFF);
write_index(SSD1963_SET_DEEP_SLEEP); // enter deep sleep mode
break;
case powerOn:
- read_reg(0x0000); chThdSleepMilliseconds(5); // 2x Dummy reads to wake up from deep sleep
- read_reg(0x0000); chThdSleepMilliseconds(5);
+ read_reg(0x0000); gfxSleepMilliseconds(5); // 2x Dummy reads to wake up from deep sleep
+ read_reg(0x0000); gfxSleepMilliseconds(5);
if (GDISP.Powermode != powerSleep)
gdisp_lld_init();
write_index(SSD1963_SET_DISPLAY_ON);
@@ -377,7 +375,7 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) {
case powerSleep:
write_index(SSD1963_SET_DISPLAY_OFF);
write_index(SSD1963_ENTER_SLEEP_MODE); // enter sleep mode
- chThdSleepMilliseconds(5);
+ gfxSleepMilliseconds(5);
break;
default:
return;
diff --git a/drivers/gdisp/SSD1963/gdisp_lld_board_example_fsmc.h b/drivers/gdisp/SSD1963/gdisp_lld_board_example_fsmc.h
index 0e310482..cfb3eb60 100644
--- a/drivers/gdisp/SSD1963/gdisp_lld_board_example_fsmc.h
+++ b/drivers/gdisp/SSD1963/gdisp_lld_board_example_fsmc.h
@@ -1,9 +1,9 @@
-/*
- * This file is subject to the terms of the GFX License, v1.0. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://chibios-gfx.com/license.html
- */
+/*
+ * This file is subject to the terms of the GFX License, v1.0. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://chibios-gfx.com/license.html
+ */
/**
* @file drivers/gdisp/SSD1289/gdisp_lld_board_example_fsmc.h
@@ -76,7 +76,7 @@ static inline void init_board(void) {
rccEnableAHB3(RCC_AHB3ENR_FSMCEN, 0);
#if defined(GDISP_USE_DMA) && defined(GDISP_DMA_STREAM)
- if (dmaStreamAllocate(GDISP_DMA_STREAM, 0, NULL, NULL)) chSysHalt();
+ if (dmaStreamAllocate(GDISP_DMA_STREAM, 0, NULL, NULL)) gfxExit();
dmaStreamSetMemory0(GDISP_DMA_STREAM, &GDISP_RAM);
dmaStreamSetMode(GDISP_DMA_STREAM, STM32_DMA_CR_PL(0) | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_DIR_M2M);
#endif
diff --git a/drivers/gdisp/SSD2119/gdisp_lld.c b/drivers/gdisp/SSD2119/gdisp_lld.c
index 282331cf..565edc1a 100644
--- a/drivers/gdisp/SSD2119/gdisp_lld.c
+++ b/drivers/gdisp/SSD2119/gdisp_lld.c
@@ -13,8 +13,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#include "ssd2119.h"
@@ -56,8 +54,8 @@
#define write_reg(reg, data) { write_index(reg); write_data(data); }
#define stream_start() write_index(SSD2119_REG_RAM_DATA);
#define stream_stop()
-#define delay(us) chThdSleepMicroseconds(us)
-#define delayms(ms) chThdSleepMilliseconds(ms)
+#define delay(us) gfxSleepMicroseconds(us)
+#define delayms(ms) gfxSleepMilliseconds(ms)
static inline void set_cursor(coord_t x, coord_t y) {
/* Reg SSD2119_REG_X_RAM_ADDR is 9 bit value
diff --git a/drivers/gdisp/TestStub/gdisp_lld.c b/drivers/gdisp/TestStub/gdisp_lld.c
index ecb23862..ccc8074b 100644
--- a/drivers/gdisp/TestStub/gdisp_lld.c
+++ b/drivers/gdisp/TestStub/gdisp_lld.c
@@ -13,8 +13,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
diff --git a/drivers/ginput/dial/GADC/ginput_lld_dial.c b/drivers/ginput/dial/GADC/ginput_lld_dial.c
index e9dc8a3f..96ac8675 100644
--- a/drivers/ginput/dial/GADC/ginput_lld_dial.c
+++ b/drivers/ginput/dial/GADC/ginput_lld_dial.c
@@ -14,8 +14,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GINPUT && GINPUT_NEED_DIAL
diff --git a/drivers/ginput/toggle/Pal/ginput_lld_toggle.c b/drivers/ginput/toggle/Pal/ginput_lld_toggle.c
index 9797b3c5..038253a4 100644
--- a/drivers/ginput/toggle/Pal/ginput_lld_toggle.c
+++ b/drivers/ginput/toggle/Pal/ginput_lld_toggle.c
@@ -1,9 +1,9 @@
-/*
- * This file is subject to the terms of the GFX License, v1.0. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://chibios-gfx.com/license.html
- */
+/*
+ * This file is subject to the terms of the GFX License, v1.0. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://chibios-gfx.com/license.html
+ */
/**
* @file drivers/ginput/toggle/Pal/ginput_lld_toggle.c
@@ -14,8 +14,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if (GFX_USE_GINPUT && GINPUT_NEED_TOGGLE) /*|| defined(__DOXYGEN__)*/
diff --git a/drivers/ginput/touch/ADS7843/ginput_lld_mouse.c b/drivers/ginput/touch/ADS7843/ginput_lld_mouse.c
index ed4a3c32..7fedaa63 100644
--- a/drivers/ginput/touch/ADS7843/ginput_lld_mouse.c
+++ b/drivers/ginput/touch/ADS7843/ginput_lld_mouse.c
@@ -1,9 +1,9 @@
-/*
- * This file is subject to the terms of the GFX License, v1.0. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://chibios-gfx.com/license.html
- */
+/*
+ * This file is subject to the terms of the GFX License, v1.0. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://chibios-gfx.com/license.html
+ */
/**
* @file drivers/ginput/touch/ADS7843/ginput_lld_mouse.c
@@ -14,8 +14,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) /*|| defined(__DOXYGEN__)*/
diff --git a/drivers/ginput/touch/MCU/ginput_lld_mouse.c b/drivers/ginput/touch/MCU/ginput_lld_mouse.c
index 7289f077..a5588b57 100644
--- a/drivers/ginput/touch/MCU/ginput_lld_mouse.c
+++ b/drivers/ginput/touch/MCU/ginput_lld_mouse.c
@@ -1,9 +1,9 @@
-/*
- * This file is subject to the terms of the GFX License, v1.0. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://chibios-gfx.com/license.html
- */
+/*
+ * This file is subject to the terms of the GFX License, v1.0. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://chibios-gfx.com/license.html
+ */
/**
* @file drivers/ginput/touch/MCU/ginput_lld_mouse.c
@@ -15,8 +15,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) /*|| defined(__DOXYGEN__)*/
diff --git a/drivers/ginput/touch/MCU/ginput_lld_mouse_board_olimex_stm32_lcd.h b/drivers/ginput/touch/MCU/ginput_lld_mouse_board_olimex_stm32_lcd.h
index dddd4a7c..49a86380 100644
--- a/drivers/ginput/touch/MCU/ginput_lld_mouse_board_olimex_stm32_lcd.h
+++ b/drivers/ginput/touch/MCU/ginput_lld_mouse_board_olimex_stm32_lcd.h
@@ -1,9 +1,9 @@
-/*
- * This file is subject to the terms of the GFX License, v1.0. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://chibios-gfx.com/license.html
- */
+/*
+ * This file is subject to the terms of the GFX License, v1.0. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://chibios-gfx.com/license.html
+ */
/**
* @file drivers/ginput/touch/MCU/ginput_lld_mouse_board_olimex_stm32_lcd.h
@@ -105,13 +105,13 @@ static inline uint16_t read_x_value(void) {
palSetPad(GPIOC, 2);
palClearPad(GPIOC, 3);
- chThdSleepMilliseconds(1);
+ gfxSleepMilliseconds(1);
adcConvert(&ADCD1, &adc_x_config, samples, ADC_BUF_DEPTH);
val1 = ((samples[0] + samples[1])/2);
palClearPad(GPIOC, 2);
palSetPad(GPIOC, 3);
- chThdSleepMilliseconds(1);
+ gfxSleepMilliseconds(1);
adcConvert(&ADCD1, &adc_x_config, samples, ADC_BUF_DEPTH);
val2 = ((samples[0] + samples[1])/2);
@@ -135,13 +135,13 @@ static inline uint16_t read_y_value(void) {
palSetPad(GPIOC, 1);
palClearPad(GPIOC, 0);
- chThdSleepMilliseconds(1);
+ gfxSleepMilliseconds(1);
adcConvert(&ADCD1, &adc_y_config, samples, ADC_BUF_DEPTH);
val1 = ((samples[0] + samples[1])/2);
palClearPad(GPIOC, 1);
palSetPad(GPIOC, 0);
- chThdSleepMilliseconds(1);
+ gfxSleepMilliseconds(1);
adcConvert(&ADCD1, &adc_y_config, samples, ADC_BUF_DEPTH);
val2 = ((samples[0] + samples[1])/2);
diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c
index 88eceb39..be8ed207 100644
--- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c
+++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c
@@ -14,8 +14,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#include "stmpe811.h"
@@ -61,7 +59,7 @@ void ginput_lld_mouse_init(void)
init_board();
write_reg(STMPE811_REG_SYS_CTRL1, 1, 0x02); // Software chip reset
- chThdSleepMilliseconds(10);
+ gfxSleepMilliseconds(10);
write_reg(STMPE811_REG_SYS_CTRL2, 1, 0x0C); // Temperature sensor clock off, GPIO clock off, touch clock on, ADC clock on
#if STMP811_NO_GPIO_IRQPIN
@@ -70,7 +68,7 @@ void ginput_lld_mouse_init(void)
write_reg(STMPE811_REG_INT_EN, 1, 0x01); // Interrupt on INT pin when touch is detected
#endif
write_reg(STMPE811_REG_ADC_CTRL1, 1, 0x48); // ADC conversion time = 80 clock ticks, 12-bit ADC, internal voltage refernce
- chThdSleepMilliseconds(2);
+ gfxSleepMilliseconds(2);
write_reg(STMPE811_REG_ADC_CTRL2, 1, 0x01); // ADC speed 3.25MHz
write_reg(STMPE811_REG_GPIO_AF, 1, 0x00); // GPIO alternate function - OFF
diff --git a/drivers/multiple/Win32/gdisp_lld.c b/drivers/multiple/Win32/gdisp_lld.c
index e8b55e45..221442ef 100644
--- a/drivers/multiple/Win32/gdisp_lld.c
+++ b/drivers/multiple/Win32/gdisp_lld.c
@@ -13,8 +13,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
@@ -173,7 +171,7 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
mousex = (coord_t)LOWORD(lParam);
mousey = (coord_t)HIWORD(lParam);
#if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE
- ginputMouseWakeup();
+ ginputMouseWakeupI();
#endif
break;
#endif
diff --git a/drivers/multiple/X/gdisp_lld.c b/drivers/multiple/X/gdisp_lld.c
index 139cc420..c431c30c 100644
--- a/drivers/multiple/X/gdisp_lld.c
+++ b/drivers/multiple/X/gdisp_lld.c
@@ -10,8 +10,6 @@
* @brief GDISP Graphics Driver subsystem low level driver source for X.
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP
@@ -119,12 +117,12 @@ static void ProcessEvent(void) {
/* this is the X11 thread which keeps track of all events */
#if GDISP_THREAD_CHIBIOS
- static WORKING_AREA(waXThread, 1024);
- static msg_t ThreadX(void *arg) {
+ static DECLARESTACK(waXThread, 1024);
+ static threadreturn_t ThreadX(void *arg) {
(void)arg;
while(1) {
- chThdSleepMilliseconds(100);
+ gfxSleepMilliseconds(100);
while(XPending(dis)) {
XNextEvent(dis, &evt);
ProcessEvent();
@@ -230,7 +228,7 @@ bool_t gdisp_lld_init(void)
ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
#if GDISP_THREAD_CHIBIOS
- if (!chThdCreateStatic(waXThread, sizeof(waXThread), HIGHPRIO, ThreadX, 0)) {
+ if (!gfxCreateThread(waXThread, sizeof(waXThread), HIGH_PRIORITY, ThreadX, 0)) {
#else
if (pthread_attr_init(&thattr)
|| pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_DETACHED)
diff --git a/drivers/tdisp/HD44780/tdisp_lld.c b/drivers/tdisp/HD44780/tdisp_lld.c
index bfe202fc..6ffadc65 100644
--- a/drivers/tdisp/HD44780/tdisp_lld.c
+++ b/drivers/tdisp/HD44780/tdisp_lld.c
@@ -13,8 +13,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_TDISP /*|| defined(__DOXYGEN__)*/
@@ -70,7 +68,7 @@ bool_t tdisp_lld_init(void) {
*/
/* Give the LCD a little time to wake up */
- chThdSleepMilliseconds(15);
+ gfxSleepMilliseconds(15);
/* write three times 0x03 to display
* with RS = low.
@@ -107,20 +105,20 @@ bool_t tdisp_lld_init(void) {
/* END OF INITIALISATION */
// /* wait some time */
-// chThdSleepMilliseconds(50);
+// gfxSleepMilliseconds(50);
//
// write_cmd(0x38);
-// chThdSleepMilliseconds(64);
+// gfxSleepMilliseconds(64);
//
// displaycontrol = TDISP_DISPLAY_ON | TDISP_CURSOR_ON | TDISP_CURSOR_BLINK; // The default displaycontrol
// write_cmd(0x08 | displaycontrol);
-// chThdSleepMicroseconds(50);
+// gfxSleepMicroseconds(50);
//
// write_cmd(0x01); // Clear the screen
-// chThdSleepMilliseconds(5);
+// gfxSleepMilliseconds(5);
//
// write_cmd(0x06);
-// chThdSleepMicroseconds(50);
+// gfxSleepMicroseconds(50);
return TRUE;
}
@@ -131,7 +129,7 @@ bool_t tdisp_lld_init(void) {
*/
void tdisp_lld_clear(void) {
write_cmd(0x01);
-// chThdSleepMilliseconds(LONG_DELAY_MS);
+// gfxSleepMilliseconds(LONG_DELAY_MS);
}
void tdisp_lld_draw_char(char c) {
diff --git a/drivers/tdisp/HD44780/tdisp_lld_board_olimex_e407.h b/drivers/tdisp/HD44780/tdisp_lld_board_olimex_e407.h
index 5cc0f9f0..7b1789cf 100644
--- a/drivers/tdisp/HD44780/tdisp_lld_board_olimex_e407.h
+++ b/drivers/tdisp/HD44780/tdisp_lld_board_olimex_e407.h
@@ -1,9 +1,9 @@
-/*
- * This file is subject to the terms of the GFX License, v1.0. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://chibios-gfx.com/license.html
- */
+/*
+ * This file is subject to the terms of the GFX License, v1.0. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://chibios-gfx.com/license.html
+ */
/**
* @file drivers/tdisp/HD44780/tdisp_lld_board_olimex_e407.h
@@ -33,9 +33,9 @@ static void init_board(void) {
static void writeToLCD(uint8_t data) {
palWritePort(PORT_DATA, data);
palSetPad(PORT_CTRL, PIN_EN);
- chThdSleepMicroseconds(1);
+ gfxSleepMicroseconds(1);
palClearPad(PORT_CTRL, PIN_EN);
- chThdSleepMicroseconds(5);
+ gfxSleepMicroseconds(5);
}
static void write_cmd(uint8_t data) {
diff --git a/drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h b/drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h
index 84d92a0f..4b7dfacb 100644
--- a/drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h
+++ b/drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h
@@ -1,9 +1,9 @@
-/*
- * This file is subject to the terms of the GFX License, v1.0. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://chibios-gfx.com/license.html
- */
+/*
+ * This file is subject to the terms of the GFX License, v1.0. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://chibios-gfx.com/license.html
+ */
/**
* @file drivers/tdisp/HD44780/tdisp_lld_board_st_stm32f4_discovery.h
@@ -69,10 +69,10 @@ static void init_board(void) {
static void writeToLCD(uint8_t data) {
palWritePort(PORT_DATA, data<<hardware_offset);
palSetPad(PORT_CTRL, PIN_EN);
- chThdSleepMicroseconds(1);
+ gfxSleepMicroseconds(1);
palClearPad(PORT_CTRL, PIN_EN);
/* wait a little while so that de display can process the data */
- chThdSleepMicroseconds(5);
+ gfxSleepMicroseconds(5);
}
/* Writes a command to the display. The
diff --git a/gfx.mk b/gfx.mk
index c98211fa..c476e096 100644
--- a/gfx.mk
+++ b/gfx.mk
@@ -4,8 +4,9 @@ ifeq ($(GFXLIB),)
endif
GFXINC += $(GFXLIB)/include
-GFXSRC +=
+GFXSRC += $(GFXLIB)/src/gfx.c
+include $(GFXLIB)/src/gos/gos.mk
include $(GFXLIB)/src/gdisp/gdisp.mk
include $(GFXLIB)/src/tdisp/tdisp.mk
include $(GFXLIB)/src/gevent/gevent.mk
diff --git a/gfxconf.example.h b/gfxconf.example.h
index 5d6681ce..5ba739a9 100644
--- a/gfxconf.example.h
+++ b/gfxconf.example.h
@@ -14,6 +14,11 @@
#ifndef _GFXCONF_H
#define _GFXCONF_H
+/* The operating system to use - one of these must be defined */
+#define GFX_USE_OS_CHIBIOS FALSE
+#define GFX_USE_OS_WIN32 FALSE
+#define GFX_USE_OS_POSIX FALSE
+
/* GFX subsystems to turn on */
#define GFX_USE_GDISP FALSE
#define GFX_USE_TDISP FALSE
@@ -102,6 +107,8 @@
/* Features for the GMISC subsystem. */
#define GMISC_NEED_ARRAYOPS FALSE
+#define GMISC_NEED_FASTTRIG FALSE
+#define GMISC_NEED_FIXEDTRIG FALSE
/* Optional Parameters for various subsystems */
/*
diff --git a/include/gadc/gadc.h b/include/gadc/gadc.h
index af43ce06..6da63a15 100644
--- a/include/gadc/gadc.h
+++ b/include/gadc/gadc.h
@@ -179,7 +179,7 @@ void gadcHighSpeedSetISRCallback(GADCISRCallbackFunction isrfn);
/**
* @brief Allow retrieving of results from the high speed ADC using a Binary Semaphore and a static event buffer.
*
- * @param[in] pbsem The binary semaphore is signaled when data is available.
+ * @param[in] pbsem The semaphore is signaled when data is available.
* @param[in] pEvent The static event buffer to place the result information.
*
* @note Passing a NULL for pbsem or pEvent will turn off signalling via this method as will calling
@@ -189,7 +189,7 @@ void gadcHighSpeedSetISRCallback(GADCISRCallbackFunction isrfn);
*
* @api
*/
-void gadcHighSpeedSetBSem(BinarySemaphore *pbsem, GEventADC *pEvent);
+void gadcHighSpeedSetBSem(gfxSem *pbsem, GEventADC *pEvent);
/**
* @brief Start the high speed ADC conversions.
diff --git a/include/gaudin/gaudin.h b/include/gaudin/gaudin.h
index 0a530cf9..7175f631 100644
--- a/include/gaudin/gaudin.h
+++ b/include/gaudin/gaudin.h
@@ -136,7 +136,7 @@ bool_t gaudinInit(uint16_t channel, uint32_t frequency, audin_sample_t *buffer,
/**
* @brief Allow retrieving of results from the audio input using a Binary Semaphore and a static event buffer.
*
- * @param[in] pbsem The binary semaphore is signaled when data is available.
+ * @param[in] pbsem The semaphore is signaled when data is available.
* @param[in] pEvent The static event buffer to place the result information.
*
* @note Passing a NULL for pbsem or pEvent will turn off signalling via this method.
@@ -145,7 +145,7 @@ bool_t gaudinInit(uint16_t channel, uint32_t frequency, audin_sample_t *buffer,
*
* @api
*/
-void gaudinSetBSem(BinarySemaphore *pbsem, GEventAudioIn *pEvent);
+void gaudinSetBSem(gfxSem *pbsem, GEventAudioIn *pEvent);
/**
* @brief Start the audio input conversions.
diff --git a/include/gdisp/fonts.h b/include/gdisp/fonts.h
index ca175b77..881b90ad 100644
--- a/include/gdisp/fonts.h
+++ b/include/gdisp/fonts.h
@@ -12,7 +12,6 @@
* by the low level drivers that need to understand a font.
*
* @addtogroup GDISP
- *
* @{
*/
diff --git a/include/gdisp/gdisp.h b/include/gdisp/gdisp.h
index 8c14ca9f..c005f1e3 100644
--- a/include/gdisp/gdisp.h
+++ b/include/gdisp/gdisp.h
@@ -45,20 +45,6 @@ typedef int16_t coord_t;
/*===========================================================================*/
/**
- * @brief The type for a fixed point coordinate.
- * @details The top 16 bits are the integer component, the bottom 16 bits are the real component.
- */
-typedef int32_t fpcoord_t;
-
-/**
- * @brief Macros to convert to and from a fixed point coord.
- * @{
- */
-#define COORD2FP(x) ((fpcoord_t)(x)<<16)
-#define FP2COORD(x) ((coord_t)((x)>>16))
-/* @} */
-
-/**
* @brief Type for a 2D point on the screen.
*/
typedef struct point_t {
@@ -318,19 +304,6 @@ extern "C" {
/* Base Functions */
/**
- * @brief GDISP Driver initialization.
- * @details Must be called before any other gdisp function.
- *
- * @note This function is NOT currently implicitly invoked by @p halInit().
- * It must be called manually.
- *
- * @return True if succeeded, False otherwise
- *
- * @api
- */
- bool_t gdispInit(void);
-
- /**
* @brief Test if the GDISP engine is currently drawing.
* @note This function will always return FALSE if
* GDISP_NEED_ASYNC is not defined.
@@ -568,7 +541,6 @@ extern "C" {
#if GDISP_NEED_CONTROL || defined(__DOXYGEN__)
/**
* @brief Control hardware specific parts of the display. eg powermodes, backlight etc
- * @pre The GDISP unit must have been initialised using @p gdispInit().
* @note Depending on the hardware implementation this function may not
* support some codes. They will be ignored.
*
@@ -585,7 +557,6 @@ extern "C" {
#if GDISP_NEED_QUERY || defined(__DOXYGEN__)
/**
* @brief Query a property of the display.
- * @pre The GDISP unit must have been initialised using @p gdispInit().
* @note The result must be typecast to the correct type.
* @note An unsupported query will return (void *)-1.
*
@@ -601,7 +572,7 @@ extern "C" {
#include "gdisp/lld/gdisp_lld.h"
/* The same as above but use the low level driver directly if no multi-thread support is needed */
- #define gdispInit(gdisp) gdisp_lld_init()
+ #define _gdispInit(gdisp) gdisp_lld_init()
#define gdispIsBusy() FALSE
#define gdispClear(color) gdisp_lld_clear(color)
#define gdispDrawPixel(x, y, color) gdisp_lld_draw_pixel(x, y, color)
diff --git a/include/gdisp/image.h b/include/gdisp/image.h
index f169a0f1..5dcd9c56 100644
--- a/include/gdisp/image.h
+++ b/include/gdisp/image.h
@@ -129,19 +129,21 @@ extern "C" {
*/
bool_t gdispImageSetMemoryReader(gdispImage *img, const void *memimage);
- /**
- * @brief Sets the io fields in the image structure to routines
- * that support reading from an image stored on a BaseFileStream (eg SDCard).
- *
- * @return TRUE if the IO open function succeeds
- *
- * @param[in] img The image structure
- * @param[in] BaseFileStreamPtr A pointer to the (open) BaseFileStream object.
- *
- */
- bool_t gdispImageSetBaseFileStreamReader(gdispImage *img, void *BaseFileStreamPtr);
+ #if GFX_USE_OS_CHIBIOS || defined(__DOXYGEN__)
+ /**
+ * @brief Sets the io fields in the image structure to routines
+ * that support reading from an image stored on a BaseFileStream (eg SDCard).
+ *
+ * @return TRUE if the IO open function succeeds
+ *
+ * @param[in] img The image structure
+ * @param[in] BaseFileStreamPtr A pointer to the (open) BaseFileStream object.
+ *
+ */
+ bool_t gdispImageSetBaseFileStreamReader(gdispImage *img, void *BaseFileStreamPtr);
+ #endif
- #if defined(WIN32) || defined(__DOXYGEN__)
+ #if defined(WIN32) || GFX_USE_OS_WIN32 || GFX_USE_OS_POSIX || defined(__DOXYGEN__)
/**
* @brief Sets the io fields in the image structure to routines
* that support reading from an image stored in Win32 simulators native
@@ -154,7 +156,9 @@ extern "C" {
* @param[in] filename The filename to open
*
*/
- bool_t gdispImageSetSimulFileReader(gdispImage *img, const char *filename);
+ bool_t gdispImageSetFileReader(gdispImage *img, const char *filename);
+ /* Old definition */
+ #define gdispImageSetSimulFileReader(img, fname) gdispImageSetFileReader(img, fname)
#endif
/**
@@ -261,7 +265,7 @@ extern "C" {
* @note Calling gdispImageDraw() after getting a TIME_INFINITE will go back to drawing the first
* frame/page.
*/
- systime_t gdispImageNext(gdispImage *img);
+ delaytime_t gdispImageNext(gdispImage *img);
#if GDISP_NEED_IMAGE_NATIVE
/**
@@ -283,7 +287,7 @@ extern "C" {
void gdispImageClose_NATIVE(gdispImage *img);
gdispImageError gdispImageCache_NATIVE(gdispImage *img);
gdispImageError gdispImageDraw_NATIVE(gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy);
- systime_t gdispImageNext_NATIVE(gdispImage *img);
+ delaytime_t gdispImageNext_NATIVE(gdispImage *img);
/* @} */
#endif
@@ -299,7 +303,7 @@ extern "C" {
void gdispImageClose_GIF(gdispImage *img);
gdispImageError gdispImageCache_GIF(gdispImage *img);
gdispImageError gdispImageDraw_GIF(gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy);
- systime_t gdispImageNext_GIF(gdispImage *img);
+ delaytime_t gdispImageNext_GIF(gdispImage *img);
/* @} */
#endif
@@ -315,7 +319,7 @@ extern "C" {
void gdispImageClose_BMP(gdispImage *img);
gdispImageError gdispImageCache_BMP(gdispImage *img);
gdispImageError gdispImageDraw_BMP(gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy);
- systime_t gdispImageNext_BMP(gdispImage *img);
+ delaytime_t gdispImageNext_BMP(gdispImage *img);
/* @} */
#endif
@@ -331,7 +335,7 @@ extern "C" {
void gdispImageClose_JPG(gdispImage *img);
gdispImageError gdispImageCache_JPG(gdispImage *img);
gdispImageError gdispImageDraw_JPG(gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy);
- systime_t gdispImageNext_JPG(gdispImage *img);
+ delaytime_t gdispImageNext_JPG(gdispImage *img);
/* @} */
#endif
@@ -347,7 +351,7 @@ extern "C" {
void gdispImageClose_PNG(gdispImage *img);
gdispImageError gdispImageCache_PNG(gdispImage *img);
gdispImageError gdispImageDraw_PNG(gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy);
- systime_t gdispImageNext_PNG(gdispImage *img);
+ delaytime_t gdispImageNext_PNG(gdispImage *img);
/* @} */
#endif
diff --git a/include/gdisp/lld/gdisp_lld_msgs.h b/include/gdisp/lld/gdisp_lld_msgs.h
index de3d3035..91d8ed97 100644
--- a/include/gdisp/lld/gdisp_lld_msgs.h
+++ b/include/gdisp/lld/gdisp_lld_msgs.h
@@ -59,26 +59,34 @@ typedef enum gdisp_msgaction {
} gdisp_msgaction_t;
typedef union gdisp_lld_msg {
- gdisp_msgaction_t action;
+ struct {
+ gfxQueueItem qi;
+ gdisp_msgaction_t action;
+ };
struct gdisp_lld_msg_init {
+ gfxQueueItem qi;
gdisp_msgaction_t action; // GDISP_LLD_MSG_INIT
} init;
struct gdisp_lld_msg_clear {
+ gfxQueueItem qi;
gdisp_msgaction_t action; // GDISP_LLD_MSG_CLEAR
color_t color;
} clear;
struct gdisp_lld_msg_drawpixel {
+ gfxQueueItem qi;
gdisp_msgaction_t action; // GDISP_LLD_MSG_DRAWPIXEL
coord_t x, y;
color_t color;
} drawpixel;
struct gdisp_lld_msg_fillarea {
+ gfxQueueItem qi;
gdisp_msgaction_t action; // GDISP_LLD_MSG_FILLAREA
coord_t x, y;
coord_t cx, cy;
color_t color;
} fillarea;
struct gdisp_lld_msg_blitarea {
+ gfxQueueItem qi;
gdisp_msgaction_t action; // GDISP_LLD_MSG_BLITAREA
coord_t x, y;
coord_t cx, cy;
@@ -87,41 +95,48 @@ typedef union gdisp_lld_msg {
const pixel_t *buffer;
} blitarea;
struct gdisp_lld_msg_setclip {
+ gfxQueueItem qi;
gdisp_msgaction_t action; // GDISP_LLD_MSG_SETCLIP
coord_t x, y;
coord_t cx, cy;
} setclip;
struct gdisp_lld_msg_drawline {
+ gfxQueueItem qi;
gdisp_msgaction_t action; // GDISP_LLD_MSG_DRAWLINE
coord_t x0, y0;
coord_t x1, y1;
color_t color;
} drawline;
struct gdisp_lld_msg_drawcircle {
+ gfxQueueItem qi;
gdisp_msgaction_t action; // GDISP_LLD_MSG_DRAWCIRCLE
coord_t x, y;
coord_t radius;
color_t color;
} drawcircle;
struct gdisp_lld_msg_fillcircle {
+ gfxQueueItem qi;
gdisp_msgaction_t action; // GDISP_LLD_MSG_FILLCIRCLE
coord_t x, y;
coord_t radius;
color_t color;
} fillcircle;
struct gdisp_lld_msg_drawellipse {
+ gfxQueueItem qi;
gdisp_msgaction_t action; // GDISP_LLD_MSG_DRAWELLIPSE
coord_t x, y;
coord_t a, b;
color_t color;
} drawellipse;
struct gdisp_lld_msg_fillellipse {
+ gfxQueueItem qi;
gdisp_msgaction_t action; // GDISP_LLD_MSG_FILLELLIPSE
coord_t x, y;
coord_t a, b;
color_t color;
} fillellipse;
struct gdisp_lld_msg_drawarc {
+ gfxQueueItem qi;
gdisp_msgaction_t action; // GDISP_LLD_MSG_DRAWARC
coord_t x, y;
coord_t radius;
@@ -129,6 +144,7 @@ typedef union gdisp_lld_msg {
color_t color;
} drawarc;
struct gdisp_lld_msg_fillarc {
+ gfxQueueItem qi;
gdisp_msgaction_t action; // GDISP_LLD_MSG_FILLARC
coord_t x, y;
coord_t radius;
@@ -136,6 +152,7 @@ typedef union gdisp_lld_msg {
color_t color;
} fillarc;
struct gdisp_lld_msg_drawchar {
+ gfxQueueItem qi;
gdisp_msgaction_t action; // GDISP_LLD_MSG_DRAWCHAR
coord_t x, y;
char c;
@@ -143,6 +160,7 @@ typedef union gdisp_lld_msg {
color_t color;
} drawchar;
struct gdisp_lld_msg_fillchar {
+ gfxQueueItem qi;
gdisp_msgaction_t action; // GDISP_LLD_MSG_FILLCHAR
coord_t x, y;
char c;
@@ -151,11 +169,13 @@ typedef union gdisp_lld_msg {
color_t bgcolor;
} fillchar;
struct gdisp_lld_msg_getpixelcolor {
+ gfxQueueItem qi;
gdisp_msgaction_t action; // GDISP_LLD_MSG_GETPIXELCOLOR
coord_t x, y;
color_t result;
} getpixelcolor;
struct gdisp_lld_msg_verticalscroll {
+ gfxQueueItem qi;
gdisp_msgaction_t action; // GDISP_LLD_MSG_VERTICALSCROLL
coord_t x, y;
coord_t cx, cy;
@@ -163,11 +183,13 @@ typedef union gdisp_lld_msg {
color_t bgcolor;
} verticalscroll;
struct gdisp_lld_msg_control {
+ gfxQueueItem qi;
gdisp_msgaction_t action; // GDISP_LLD_MSG_CONTROL
int what;
void * value;
} control;
struct gdisp_lld_msg_query {
+ gfxQueueItem qi;
gdisp_msgaction_t action; // GDISP_LLD_MSG_QUERY
int what;
void * result;
diff --git a/include/gevent/gevent.h b/include/gevent/gevent.h
index 27d05db6..59557991 100644
--- a/include/gevent/gevent.h
+++ b/include/gevent/gevent.h
@@ -25,11 +25,6 @@
#if GFX_USE_GEVENT || defined(__DOXYGEN__)
-/* Data part of a static GListener initializer */
-#define _GLISTENER_DATA(name) { _SEMAPHORE_DATA(name.waitqueue, 0), _BSEMAPHORE_DATA(name.eventlock, FALSE), 0, 0, {0} }
-/* Static GListener initializer */
-#define GLISTENER_DECL(name) GListener name = _GLISTENER_DATA(name)
-
/*===========================================================================*/
/* Type definitions */
/*===========================================================================*/
@@ -60,8 +55,8 @@ typedef void (*GEventCallbackFn)(void *param, GEvent *pe);
// The Listener Object
typedef struct GListener {
- Semaphore waitqueue; // Private: Semaphore for the listener to wait on.
- BinarySemaphore eventlock; // Private: Protect against more than one sources trying to use this event lock at the same time
+ gfxSem waitqueue; // Private: Semaphore for the listener to wait on.
+ gfxSem eventlock; // Private: Protect against more than one sources trying to use this event lock at the same time
GEventCallbackFn callback; // Private: Call back Function
void *param; // Private: Parameter for the callback function.
GEvent event; // Public: The event object into which the event information is stored.
@@ -163,7 +158,7 @@ void geventDetachSource(GListener *pl, GSourceHandle gsh);
*
* @return NULL on timeout
*/
-GEvent *geventEventWait(GListener *pl, systime_t timeout);
+GEvent *geventEventWait(GListener *pl, delaytime_t timeout);
/* @brief Register a callback for an event on a listener from an assigned source.
* @details The type of the event should be checked (pevent->type) and then pevent should be typecast to the
diff --git a/include/gfx.h b/include/gfx.h
index ba4a9167..84aec39f 100644
--- a/include/gfx.h
+++ b/include/gfx.h
@@ -16,6 +16,25 @@
#ifndef _GFX_H
#define _GFX_H
+/**
+ * These two definitions below are required before anything else so that we can
+ * turn module definitions off and on.
+ */
+
+/**
+ * @brief Generic 'false' boolean constant.
+ */
+#if !defined(FALSE) || defined(__DOXYGEN__)
+ #define FALSE 0
+#endif
+
+/**
+ * @brief Generic 'true' boolean constant.
+ */
+#if !defined(TRUE) || defined(__DOXYGEN__)
+ #define TRUE -1
+#endif
+
/* gfxconf.h is the user's project configuration for the GFX system. */
#include "gfxconf.h"
@@ -122,6 +141,7 @@
* Get all the options for each sub-system.
*
*/
+#include "gos/options.h"
#include "gmisc/options.h"
#include "gevent/options.h"
#include "gtimer/options.h"
@@ -142,6 +162,7 @@
/**
* Include the sub-system header files
*/
+#include "gos/gos.h"
#include "gmisc/gmisc.h"
#include "gevent/gevent.h"
#include "gtimer/gtimer.h"
@@ -153,5 +174,27 @@
#include "gaudin/gaudin.h"
#include "gaudout/gaudout.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ /**
+ * @brief The one call to start it all
+ *
+ * @note This will initialise each sub-system that has been turned on.
+ * For example, if GFX_USE_GDISP is defined then display will be initialised
+ * and cleared to black.
+ *
+ * @api
+ */
+ void gfxInit(void);
+
+ /* Compatibility for old programs */
+ #define gdispInit() gfxInit()
+
+#ifdef __cplusplus
+}
+#endif
+
#endif /* _GFX_H */
/** @} */
diff --git a/include/gfx_rules.h b/include/gfx_rules.h
index b93ea8ae..4fff2d21 100644
--- a/include/gfx_rules.h
+++ b/include/gfx_rules.h
@@ -22,28 +22,51 @@
* These are defined in the order of their inter-dependancies.
*/
+#ifndef GFX_DISPLAY_RULE_WARNINGS
+ #define GFX_DISPLAY_RULE_WARNINGS FALSE
+#endif
+
+#if !GFX_USE_OS_CHIBIOS && !GFX_USE_OS_WIN32 && !GFX_USE_OS_POSIX
+ #if GFX_DISPLAY_RULE_WARNINGS
+ #warning "GOS: No Operating System has been defined. ChibiOS (GFX_USE_OS_CHIBIOS) has been turned on for you."
+ #endif
+ #undef GFX_USE_OS_CHIBIOS
+ #define GFX_USE_OS_CHIBIOS TRUE
+#endif
+#if GFX_USE_OS_CHIBIOS + GFX_USE_OS_WIN32 + GFX_USE_OS_POSIX != 1 * TRUE
+ #error "GOS: More than one operation system has been defined as TRUE."
+#endif
+
#if GFX_USE_GWIN
#if !GFX_USE_GDISP
#error "GWIN: GFX_USE_GDISP must be TRUE when using GWIN"
#endif
#if !GDISP_NEED_CLIP
- #warning "GWIN: Drawing can occur outside the defined windows as GDISP_NEED_CLIP is FALSE"
+ #if GFX_DISPLAY_RULE_WARNINGS
+ #warning "GWIN: Drawing can occur outside the defined windows as GDISP_NEED_CLIP is FALSE"
+ #endif
#endif
#if GWIN_NEED_BUTTON
#if !GDISP_NEED_TEXT
#error "GWIN: GDISP_NEED_TEXT is required if GWIN_NEED_BUTTON is TRUE."
#endif
#if !GFX_USE_GEVENT
- #warning "GWIN: GFX_USE_GEVENT is required if GWIN_NEED_BUTTON is TRUE. It has been turned on for you."
+ #if GFX_DISPLAY_RULE_WARNINGS
+ #warning "GWIN: GFX_USE_GEVENT is required if GWIN_NEED_BUTTON is TRUE. It has been turned on for you."
+ #endif
#undef GFX_USE_GEVENT
#define GFX_USE_GEVENT TRUE
#endif
#if !GFX_USE_GINPUT || !(GINPUT_NEED_MOUSE || GINPUT_NEED_TOGGLE)
- #warning "GWIN: You have set GWIN_NEED_BUTTON to TRUE but no supported GINPUT (mouse/toggle) devices have been included"
+ #if GFX_DISPLAY_RULE_WARNINGS
+ #warning "GWIN: You have set GWIN_NEED_BUTTON to TRUE but no supported GINPUT (mouse/toggle) devices have been included"
+ #endif
#endif
#if !GDISP_NEED_MULTITHREAD && !GDISP_NEED_ASYNC
- #warning "GWIN: Either GDISP_NEED_MULTITHREAD or GDISP_NEED_ASYNC is required if GWIN_NEED_BUTTON is TRUE."
- #warning "GWIN: GDISP_NEED_MULTITHREAD has been turned on for you."
+ #if GFX_DISPLAY_RULE_WARNINGS
+ #warning "GWIN: Either GDISP_NEED_MULTITHREAD or GDISP_NEED_ASYNC is required if GWIN_NEED_BUTTON is TRUE."
+ #warning "GWIN: GDISP_NEED_MULTITHREAD has been turned on for you."
+ #endif
#undef GDISP_NEED_MULTITHREAD
#define GDISP_NEED_MULTITHREAD TRUE
#endif
@@ -59,12 +82,16 @@
#if GFX_USE_GINPUT
#if !GFX_USE_GEVENT
- #warning "GINPUT: GFX_USE_GEVENT is required if GFX_USE_GINPUT is TRUE. It has been turned on for you."
+ #if GFX_DISPLAY_RULE_WARNINGS
+ #warning "GINPUT: GFX_USE_GEVENT is required if GFX_USE_GINPUT is TRUE. It has been turned on for you."
+ #endif
#undef GFX_USE_GEVENT
#define GFX_USE_GEVENT TRUE
#endif
#if !GFX_USE_GTIMER
- #warning "GINPUT: GFX_USE_GTIMER is required if GFX_USE_GINPUT is TRUE. It has been turned on for you."
+ #if GFX_DISPLAY_RULE_WARNINGS
+ #warning "GINPUT: GFX_USE_GTIMER is required if GFX_USE_GINPUT is TRUE. It has been turned on for you."
+ #endif
#undef GFX_USE_GTIMER
#define GFX_USE_GTIMER TRUE
#endif
@@ -74,13 +101,6 @@
#if GDISP_NEED_MULTITHREAD && GDISP_NEED_ASYNC
#error "GDISP: Only one of GDISP_NEED_MULTITHREAD and GDISP_NEED_ASYNC should be defined."
#endif
- #if GDISP_NEED_ASYNC
- #if !GDISP_NEED_MSGAPI
- #warning "GDISP: Messaging API is required for Async Multi-Thread. It has been turned on for you."
- #undef GDISP_NEED_MSGAPI
- #define GDISP_NEED_MSGAPI TRUE
- #endif
- #endif
#endif
#if GFX_USE_TDISP
@@ -88,33 +108,33 @@
#if GFX_USE_GAUDIN
#if GFX_USE_GEVENT && !GFX_USE_GTIMER
- #warning "GAUDIN: GFX_USE_GTIMER is required if GFX_USE_GAUDIN and GFX_USE_GEVENT are TRUE. It has been turned on for you."
+ #if GFX_DISPLAY_RULE_WARNINGS
+ #warning "GAUDIN: GFX_USE_GTIMER is required if GFX_USE_GAUDIN and GFX_USE_GEVENT are TRUE. It has been turned on for you."
+ #endif
#undef GFX_USE_GTIMER
#define GFX_USE_GTIMER TRUE
#endif
#endif
#if GFX_USE_GADC
- #if !CH_USE_MUTEXES || !CH_USE_SEMAPHORES
- #error "GADC: CH_USE_MUTEXES and CH_USE_SEMAPHORES must be defined in chconf.h"
- #endif
#if !GFX_USE_GTIMER
- #warning "GADC: GFX_USE_GTIMER is required if GFX_USE_GADC is TRUE. It has been turned on for you."
+ #if GFX_DISPLAY_RULE_WARNINGS
+ #warning "GADC: GFX_USE_GTIMER is required if GFX_USE_GADC is TRUE. It has been turned on for you."
+ #endif
#undef GFX_USE_GTIMER
#define GFX_USE_GTIMER TRUE
#endif
#endif
#if GFX_USE_GEVENT
- #if !CH_USE_MUTEXES || !CH_USE_SEMAPHORES
- #error "GEVENT: CH_USE_MUTEXES and CH_USE_SEMAPHORES must be defined in chconf.h"
- #endif
#endif
#if GFX_USE_GTIMER
#if GFX_USE_GDISP && !GDISP_NEED_MULTITHREAD && !GDISP_NEED_ASYNC
- #warning "GTIMER: Neither GDISP_NEED_MULTITHREAD nor GDISP_NEED_ASYNC has been specified."
- #warning "GTIMER: Make sure you are not performing any GDISP/GWIN drawing operations in the timer callback!"
+ #if GFX_DISPLAY_RULE_WARNINGS
+ #warning "GTIMER: Neither GDISP_NEED_MULTITHREAD nor GDISP_NEED_ASYNC has been specified."
+ #warning "GTIMER: Make sure you are not performing any GDISP/GWIN drawing operations in the timer callback!"
+ #endif
#endif
#endif
diff --git a/include/gmisc/gmisc.h b/include/gmisc/gmisc.h
index bf1aa498..21eb2bbe 100644
--- a/include/gmisc/gmisc.h
+++ b/include/gmisc/gmisc.h
@@ -37,6 +37,32 @@ typedef enum ArrayDataFormat_e {
ARRAY_DATA_16BITUNSIGNED = 16, ARRAY_DATA_16BITSIGNED = 17,
} ArrayDataFormat;
+/**
+ * @brief The type for a fixed point type.
+ * @details The top 16 bits are the integer component, the bottom 16 bits are the real component.
+ */
+typedef int32_t fixed;
+
+/**
+ * @brief Macros to convert to and from a fixed point.
+ * @{
+ */
+#define FIXED(x) ((fixed)(x)<<16) /* @< integer to fixed */
+#define NONFIXED(x) ((x)>>16) /* @< fixed to integer */
+#define FP2FIXED(x) ((fixed)((x)*65536.0)) /* @< floating point to fixed */
+#define FIXED2FP(x) ((double)(x)/65536.0) /* @< fixed to floating point */
+/* @} */
+
+/**
+ * @brief The famous number pi
+ */
+#define PI 3.1415926535897932384626433832795028841971693993751
+
+/**
+ * @brief pi as a fixed point
+ */
+#define FIXED_PI FP2FIXED(PI)
+
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
@@ -85,6 +111,76 @@ extern "C" {
#endif
#endif
+#if GMISC_NEED_FASTTRIG || defined(__DOXYGEN__)
+ extern const double sintabledouble[];
+
+ /**
+ * @brief Fast Table Based Trig functions
+ * @return A double in the range -1.0 .. 0.0 .. 1.0
+ *
+ * @param[in] degrees The angle in degrees (not radians)
+ *
+ * @note These functions use degrees rather than radians to describe the angle.
+ *
+ * @api
+ * @{
+ */
+ double fsin(int degrees);
+ double fcos(int degrees);
+ /** @}
+ *
+ * @brief Fast Table Based Trig functions
+ * @return A double in the range -1.0 .. 0.0 .. 1.0
+ *
+ * @param[in] degrees The angle in degrees 0 .. 359
+ *
+ * @note These functions use degrees rather than radians to describe the angle.
+ * @note These functions are super fast but require the parameter to be in range.
+ * Use the lowercase functions if the parameter may not be in range or if a
+ * required trig function is not supported in this form.
+ *
+ * @api
+ * @{
+ */
+ #define FSIN(degrees) sintabledouble[degrees];
+ /** @} */
+#endif
+
+#if GMISC_NEED_FIXEDTRIG || defined(__DOXYGEN__)
+ extern const fixed sintablefixed[];
+
+ /**
+ * @brief Fast Table Based Trig functions
+ * @return A fixed point in the range -1.0 .. 0.0 .. 1.0
+ *
+ * @param[in] degrees The angle in degrees (not radians)
+ *
+ * @note These functions use degrees rather than radians to describe the angle.
+ *
+ * @api
+ * @{
+ */
+ fixed ffsin(int degrees);
+ fixed ffcos(int degrees);
+ /** @}
+ *
+ * @brief Fast Table Based Trig functions
+ * @return A fixed point in the range -1.0 .. 0.0 .. 1.0
+ *
+ * @param[in] degrees The angle in degrees 0 .. 359
+ *
+ * @note These functions use degrees rather than radians to describe the angle.
+ * @note These functions are super fast but require the parameter to be in range.
+ * Use the lowercase functions if the parameter may not be in range or if a
+ * required trig function is not supported in this form.
+ *
+ * @api
+ * @{
+ */
+ #define FFSIN(degrees) sintablefixed[degrees];
+ /** @} */
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/include/gmisc/options.h b/include/gmisc/options.h
index ee58609e..5a2f68ea 100644
--- a/include/gmisc/options.h
+++ b/include/gmisc/options.h
@@ -1,9 +1,9 @@
-/*
- * This file is subject to the terms of the GFX License, v1.0. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://chibios-gfx.com/license.html
- */
+/*
+ * This file is subject to the terms of the GFX License, v1.0. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://chibios-gfx.com/license.html
+ */
/**
* @file include/gmisc/options.h
@@ -27,6 +27,20 @@
#ifndef GMISC_NEED_ARRAYOPS
#define GMISC_NEED_ARRAYOPS FALSE
#endif
+ /**
+ * @brief Include fast array based trig functions (sin, cos)
+ * @details Defaults to FALSE
+ */
+ #ifndef GMISC_NEED_FASTTRIG
+ #define GMISC_NEED_FASTTRIG FALSE
+ #endif
+ /**
+ * @brief Include fast fixed point trig functions (sin, cos)
+ * @details Defaults to FALSE
+ */
+ #ifndef GMISC_NEED_FIXEDTRIG
+ #define GMISC_NEED_FIXEDTRIG FALSE
+ #endif
/**
* @}
*
diff --git a/include/gos/chibios.h b/include/gos/chibios.h
new file mode 100644
index 00000000..37bf93ee
--- /dev/null
+++ b/include/gos/chibios.h
@@ -0,0 +1,124 @@
+/*
+ ChibiOS/GFX - Copyright (C) 2012, 2013
+ 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/>.
+*/
+/**
+ * @file include/gos/chibios.h
+ * @brief GOS - Operating System Support header file for ChibiOS.
+ */
+
+#ifndef _GOS_CHIBIOS_H
+#define _GOS_CHIBIOS_H
+
+#if GFX_USE_OS_CHIBIOS
+
+#include "ch.h"
+#include "hal.h"
+
+/*===========================================================================*/
+/* Type definitions */
+/*===========================================================================*/
+
+/**
+ * bool_t,
+ * int8_t, uint8_t,
+ * int16_t, uint16_t,
+ * int32_t, uint32_t,
+ * size_t
+ * TRUE, FALSE
+ * TIME_IMMEDIATE, TIME_INFINITE
+ * are already defined by ChibiOS
+ */
+
+typedef systime_t delaytime_t;
+typedef systime_t systemticks_t;
+typedef cnt_t semcount_t;
+typedef msg_t threadreturn_t;
+typedef tprio_t threadpriority_t;
+
+typedef threadreturn_t (*gfxThreadFunction)(void *param);
+
+#define MAX_SEMAPHORE_COUNT ((semcount_t)(((unsigned long)((semcount_t)(-1))) >> 1))
+#define LOW_PRIORITY LOWPRIO
+#define NORMAL_PRIORITY NORMALPRIO
+#define HIGH_PRIORITY HIGHPRIO
+#define DECLARESTACK(name, sz) WORKING_AREA(name, sz);
+
+
+typedef struct {
+ Semaphore sem;
+ semcount_t limit;
+ } gfxSem;
+
+#define gfxMutex Mutex
+
+typedef struct gfxQueue {
+ struct gfxQueueItem *head;
+ struct gfxQueueItem *tail;
+ Semaphore sem;
+ } gfxQueue;
+
+typedef struct gfxQueueItem {
+ struct gfxQueueItem *next;
+ Semaphore sem;
+ } gfxQueueItem;
+
+/*===========================================================================*/
+/* Function declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define gfxHalt(msg) chDbgPanic(msg)
+#define gfxExit() chSysHalt()
+#define gfxAlloc(sz) chHeapAlloc(NULL, sz)
+#define gfxFree(ptr) chHeapFree(ptr)
+void gfxSleepMilliseconds(delaytime_t ms);
+void gfxSleepMicroseconds(delaytime_t ms);
+void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit);
+bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
+void gfxSemSignal(gfxSem *psem);
+void gfxSemSignalI(gfxSem *psem);
+#define gfxSemCounterI(psem) ((psem)->sem.s_cnt)
+#define gfxSemCounter(psem) ((psem)->sem.s_cnt)
+#define gfxSystemTicks() chTimeNow()
+#define gfxMillisecondsToTicks(ms) MS2ST(ms)
+#define gfxYield() chThdYield()
+#define gfxSystemLock() chSysLock()
+#define gfxSystemUnlock() chSysUnlock()
+#define gfxMutexInit(pmutex) chMtxInit(pmutex)
+#define gfxMutexEnter(pmutex) chMtxLock(pmutex)
+#define gfxMutexExit(pmutex) chMtxUnlock()
+void gfxQueueInit(gfxQueue *pqueue);
+gfxQueueItem * gfxQueueGet(gfxQueue *pqueue, delaytime_t ms);
+bool_t gfxQueuePut(gfxQueue *pqueue, gfxQueueItem *pitem, delaytime_t ms);
+#define gfxQueuePop(q) gfxQueueGet(q)
+bool_t gfxQueuePush(gfxQueue *pqueue, gfxQueueItem *pitem, delaytime_t ms);
+void gfxQueueRemove(gfxQueue *pqueue, gfxQueueItem *pitem);
+bool_t gfxQueueIsEmpty(gfxQueue *pqueue);
+bool_t gfxQueueIsIn(gfxQueue *pqueue, gfxQueueItem *pitem);
+bool_t gfxCreateThread(void *stackarea, size_t stacksz, threadpriority_t prio, gfxThreadFunction fn, void *param);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GFX_USE_OS_CHIBIOS */
+#endif /* _GOS_CHIBIOS_H */
diff --git a/include/gos/gos.h b/include/gos/gos.h
new file mode 100644
index 00000000..04799540
--- /dev/null
+++ b/include/gos/gos.h
@@ -0,0 +1,483 @@
+/*
+ ChibiOS/GFX - Copyright (C) 2012, 2013
+ 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/>.
+*/
+/**
+ * @file include/gos/gos.h
+ * @brief GOS - Operating System Support header file.
+ *
+ * @addtogroup GOS
+ * @brief GOS provides the operating system interface with the GFX library.
+ * @note Some of the routines specified below may be implemented simply as
+ * a macro to the real operating system call.
+ * @{
+ */
+
+#ifndef _GOS_H
+#define _GOS_H
+
+#if defined(__DOXYGEN__)
+ /*===========================================================================*/
+ /* Type definitions */
+ /*===========================================================================*/
+
+ /**
+ * @brief A function for a new thread to execute.
+ */
+ typedef threadreturn_t (*gfxThreadFunction)(void *param);
+
+ /**
+ * @brief Various integer sizes
+ * @note Your platform may use slightly different definitions to these
+ * @{
+ */
+ typedef unsigned char bool_t;
+ typedef char int8_t;
+ typedef unsigned char uint8_t;
+ typedef short int16_t;
+ typedef unsigned short uint16_t;
+ typedef long int32_t;
+ typedef unsigned long uint32_t;
+ /**
+ * @}
+ *
+ * @brief Various platform (and operating system) dependent types
+ * @note Your platform may use slightly different definitions to these
+ * @{
+ */
+ typedef unsigned long size_t;
+ typedef unsigned long delaytime_t;
+ typedef unsigned long systemticks_t;
+ typedef short semcount_t;
+ typedef int threadreturn_t;
+ typedef int threadpriority_t;
+ /**
+ * @}
+ *
+ * @brief Various platform (and operating system) constants
+ * @note Your platform may use slightly different definitions to these
+ * @{
+ */
+ #define FALSE 0
+ #define TRUE 1
+ #define TIME_IMMEDIATE 0
+ #define TIME_INFINITE ((delaytime_t)-1)
+ #define MAX_SEMAPHORE_COUNT ((semcount_t)-1)
+ #define LOW_PRIORITY 0
+ #define NORMAL_PRIORITY 1
+ #define HIGH_PRIORITY 2
+ #define DECLARESTACK(name, sz) uint8_t name[sz];
+ /* @} */
+
+ /**
+ * @brief A semaphore
+ * @note Your operating system will have a proper definition for this structure
+ */
+ typedef struct {} gfxSem;
+
+ /**
+ * @brief A mutex
+ * @note Your operating system will have a proper definition for this structure
+ */
+ typedef struct {} gfxMutex;
+
+ /**
+ * @brief A queue
+ * @note Your operating system will have a proper definition for this structure
+ */
+ typedef struct {} gfxQueue;
+
+ /**
+ * @brief A queue item
+ * @note Your operating system will have a proper definition for this structure
+ */
+ typedef struct {} gfxQueueItem;
+
+ /*===========================================================================*/
+ /* Function declarations. */
+ /*===========================================================================*/
+
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+
+ /**
+ * @brief Halt the GFX application due to an error.
+ *
+ * @param[in] msg An optional debug message to show (Can be NULL)
+ *
+ * @api
+ */
+ void gfxHalt(const char *msg);
+
+ /**
+ * @brief Exit the GFX application.
+ *
+ * @api
+ */
+ void gfxExit(void);
+
+ /**
+ * @brief Allocate memory
+ * @return A pointer to the memory allocated or NULL if there is no more memory available
+ *
+ * @param[in] sz The size in bytes of the area to allocate
+ *
+ * @api
+ */
+ void *gfxAlloc(size_t sz);
+
+ /**
+ * @brief Free memory
+ *
+ * @param[in] ptr The memory to free
+ *
+ * @api
+ */
+ void gfxFree(void *ptr);
+
+ /**
+ * @brief Put the current thread to sleep for the specified period in milliseconds
+ *
+ * @param[in] ms The number milliseconds to sleep
+ *
+ * @note Specifying TIME_IMMEDIATE will yield the current thread but return
+ * on the next time slice.
+ * @note Specifying TIME_INFINITE will sleep forever.
+ *
+ * @api
+ */
+ void gfxSleepMilliseconds(delaytime_t ms);
+
+ /**
+ * @brief Put the current thread to sleep for the specified period in microseconds
+ *
+ * @param[in] ms The number microseconds to sleep
+ *
+ * @note Specifying TIME_IMMEDIATE will return immediately (no sleeping)
+ * @note Specifying TIME_INFINITE will sleep forever.
+ *
+ * @api
+ */
+ void gfxSleepMicroseconds(delaytime_t ms);
+
+ /**
+ * @brief Initialise a Counted Semaphore
+ *
+ * @param[in] psem A pointer to the semaphore
+ * @param[in] val The initial value of the semaphore
+ * @param[in] limit The maxmimum value of the semaphore
+ *
+ * @note Operations defined for counted semaphores:
+ * Signal: The semaphore counter is increased and if the result is non-positive then a waiting thread
+ * is queued for execution. Note that once the thread reaches "limit", further signals are
+ * ignored.
+ * Wait: The semaphore counter is decreased and if the result becomes negative the thread is queued
+ * in the semaphore and suspended.
+ *
+ * @api
+ */
+ void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit);
+
+ /**
+ * @brief Wait on a semaphore
+ * @details The semaphore counter is decreased and if the result becomes negative the thread waits for it to become
+ * non-negative again
+ * @return FALSE if the wait timeout occurred otherwise TRUE
+ *
+ * @param[in] psem A pointer to the semaphore
+ * @param[in] ms The maxmimum time to wait for the semaphore
+ *
+ * @api
+ */
+ bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
+
+ /**
+ * @brief Signal a semaphore
+ * @details The semaphore counter is increased and if the result is non-positive then a waiting thread
+ * is queued for execution. Note that once the thread reaches "limit", further signals are
+ * ignored.
+ *
+ * @param[in] psem A pointer to the semaphore
+ *
+ * @api
+ */
+ void gfxSemSignal(gfxSem *psem);
+
+ /**
+ * @brief Signal a semaphore
+ * @details The semaphore counter is increased and if the result is non-positive then a waiting thread
+ * is queued for execution. Note that once the thread reaches "limit", further signals are
+ * ignored.
+ *
+ * @param[in] psem A pointer to the semaphore
+ *
+ * @iclass
+ * @api
+ */
+ void gfxSemSignalI(gfxSem *psem);
+
+ /**
+ * @brief Get the current semaphore count
+ * @return The current semaphore count
+ *
+ * @param[in] psem A pointer to the semaphore
+ *
+ * @api
+ */
+ semcount_t gfxSemCounter(gfxSem *pSem);
+
+ /**
+ * @brief Get the current semaphore count
+ * @return The current semaphore count
+ *
+ * @param[in] psem A pointer to the semaphore
+ *
+ * @iclass
+ * @api
+ */
+ semcount_t gfxSemCounterI(gfxSem *pSem);
+
+ /**
+ * @brief Get the current operating system tick time
+ * @return The current tick time
+ *
+ * @note A "tick" is an arbitrary period of time that the operating
+ * system uses to mark time.
+ * @note The absolute value of this call is relatively meaningless. Its usefulness
+ * is in calculating periods between two calls to this function.
+ * @note As the value from this function can wrap it is important that any periods are calculated
+ * as t2 - t1 and then compared to the desired period rather than comparing
+ * t1 + period to t2
+ *
+ * @api
+ */
+ systemticks_t gfxSystemTicks(void);
+
+ /**
+ * @brief Convert a given number of millseconds to a number of operating system ticks
+ * @return The period in system ticks.
+ *
+ * @note A "tick" is an arbitrary period of time that the operating
+ * system uses to mark time.
+ *
+ * @param[in] ms The number of millseconds
+ *
+ * @api
+ */
+ systemticks_t gfxMillisecondsToTicks(delaytime_t ms);
+
+ /**
+ * @brief Yield the current thread
+ * @details Give up the rest of the current time slice for this thread in order to give other threads
+ * a chance to run.
+ *
+ * @api
+ */
+ void gfxYield(void);
+
+ /**
+ * @brief Lock the operating system to protect a sequence of code
+ *
+ * @note Calling this will lock out all other threads from executing even at interrupt level
+ * within the GFX system. On hardware this may be implemented as a disabling of interrupts,
+ * however in an operating system which hides real interrupt level code it may simply use a
+ * mutex lock.
+ * @note The thread MUST NOT block whilst the system is locked. It must execute in this state for
+ * as short a period as possible as this can seriously affect interrupt latency on some
+ * platforms.
+ * @note While locked only interrupt level (iclass) GFX routines may be called.
+ *
+ * @api
+ */
+ void gfxSystemLock(void);
+
+ /**
+ * @brief Unlock the operating system previous locked by gfxSystemLock()
+ *
+ * @api
+ */
+ void gfxSystemUnlock(void);
+
+ /**
+ * @brief Initialise a mutex to protect a region of code from other threads.
+ *
+ * @param[in] pmutex A pointer to the mutex
+ *
+ * @note Whilst a counting semaphore with a limit of 1 can be used for similiar purposes
+ * on many operating systems using a seperate mutex structure is more efficient.
+ *
+ * @api
+ */
+ void gfxMutexInit(gfxMutex *pmutex);
+
+ /**
+ * @brief Enter the critical code region protected by the mutex.
+ * @details Blocks until there is no other thread in the critical region.
+ *
+ * @param[in] pmutex A pointer to the mutex
+ *
+ * @api
+ */
+ void gfxMutexEnter(gfxMutex *pmutex);
+
+ /**
+ * @brief Exit the critical code region protected by the mutex.
+ * @details May cause another thread waiting on the mutex to now be placed into the run queue.
+ *
+ * @param[in] pmutex A pointer to the mutex
+ *
+ * @api
+ */
+ void gfxMutexExit(gfxMutex *pmutex);
+
+ /**
+ * @brief Initialise a queue.
+ *
+ * @param[in] pqueue A pointer to the queue
+ *
+ * @note Whilst queues are normally FIFO, a GFX queue also supports push and pop operations.
+ * A pop operation is the same as normal get from the queue but a push places the item
+ * at the head of the queue instead of the tail (as a put would).
+ *
+ * @api
+ */
+ void gfxQueueInit(gfxQueue *pqueue);
+
+ /**
+ * @brief Get an item from the head of the queue.
+ * @return NULL if the timeout expires before an item is available
+ *
+ * @param[in] pqueue A pointer to the queue
+ * @param[in] ms The maxmimum time to wait for an item
+ *
+ * @api
+ */
+ gfxQueueItem * gfxQueueGet(gfxQueue *pqueue, delaytime_t ms);
+
+ /**
+ * @brief Put an item on the end of the queue.
+ * @return FALSE on timeout, otherwise TRUE
+ *
+ * @param[in] pqueue A pointer to the queue
+ * @param[in] pitem A pointer to the queue item
+ * @param[in] ms The maxmimum time to wait for an item to be removed from the queue
+ *
+ * @note Use a delay time of TIME_IMMEDIATE if you don't want to wait until the
+ * item is removed from the queue
+ *
+ * @api
+ */
+ bool_t gfxQueuePut(gfxQueue *pqueue, gfxQueueItem *pitem, delaytime_t ms);
+
+ /**
+ * @brief Pop an item from the head of the queue.
+ * @return NULL if there are no more items on the queue
+ *
+ * @param[in] pqueue A pointer to the queue
+ *
+ * @api
+ */
+ #define gfxQueuePop(pqueue, ms) gfxQueueGet(pqueue, ms)
+
+ /**
+ * @brief Push an item into the start of the queue.
+ * @return FALSE on timeout, otherwise TRUE
+ *
+ * @param[in] pqueue A pointer to the queue
+ * @param[in] pitem A pointer to the queue item
+ * @param[in] ms The maxmimum time to wait for an item to be popped
+ *
+ * @note Use a delay time of TIME_IMMEDIATE if you don't want to wait until the
+ * item is removed from the queue
+ *
+ * @api
+ */
+ bool_t gfxQueuePush(gfxQueue *pqueue, gfxQueueItem *pitem, delaytime_t ms);
+
+ /**
+ * @brief Remove an item from the queue.
+ * @note Removes the specified item from the queue whereever it is in the queue
+ *
+ * @param[in] pqueue A pointer to the queue
+ * @param[in] pitem A pointer to the queue item
+ *
+ * @note If the item isn't in the queue the routine just returns.
+ *
+ * @api
+ */
+ void gfxQueueRemove(gfxQueue *pqueue, gfxQueueItem *pitem);
+
+ /**
+ * @brief Is the queue empty?
+ * @return TRUE if the queue is empty
+ *
+ * @param[in] pqueue A pointer to the queue
+ *
+ * @api
+ */
+ bool_t gfxQueueIsEmpty(gfxQueue *pqueue);
+
+ /**
+ * @brief Is an item in the queue?
+ * @return TRUE if the item is in the queue?
+ *
+ * @param[in] pqueue A pointer to the queue
+ * @param[in] pitem A pointer to the queue item
+ *
+ * @note This operation may be expensive.
+ *
+ * @api
+ */
+ bool_t gfxQueueIsIn(gfxQueue *pqueue, gfxQueueItem *pitem);
+
+ /**
+ * @brief Start a new thread.
+ * @return Return TRUE if the thread was started, FALSE on an error
+ *
+ * @param[in] stackarea A pointer to the area for the new threads stack or NULL to dynamically allocate it
+ * @param[in] stacksz The size of the thread stack. 0 means the default operating system size although this
+ * is only valid when stackarea is dynamically allocated.
+ * @param[in] prio The priority of the new thread
+ * @param[in] fn The function the new thread will run
+ * @param[in] param A parameter to pass the thread function.
+ *
+ * @api
+ */
+ bool_t gfxCreateThread(void *stackarea, size_t stacksz, threadpriority_t prio, gfxThreadFunction fn, void *param);
+
+ #ifdef __cplusplus
+ }
+ #endif
+
+/**
+ * All the above was just for the doxygen documentation. All the implementation of the above
+ * (without any of the documentation overheads) is in the files below.
+ */
+#elif GFX_USE_OS_CHIBIOS
+ #include "gos/chibios.h"
+#elif GFX_USE_OS_WIN32
+ #include "gos/win32.h"
+#elif GFX_USE_OS_POSIX
+ #include "gos/posix.h"
+#else
+ #error "Your operating system is not supported yet"
+#endif
+
+#endif /* _GOS_H */
+/** @} */
diff --git a/include/gos/options.h b/include/gos/options.h
new file mode 100644
index 00000000..f9d41bb5
--- /dev/null
+++ b/include/gos/options.h
@@ -0,0 +1,66 @@
+/*
+ ChibiOS/GFX - Copyright (C) 2012, 2013
+ 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/>.
+*/
+
+/**
+ * @file include/gos/options.h
+ * @brief GOS - Operating System options header file.
+ *
+ * @addtogroup GOS
+ * @{
+ */
+
+#ifndef _GOS_OPTIONS_H
+#define _GOS_OPTIONS_H
+
+/**
+ * @name GOS The operating system to use. One (and only one) of these must be defined.
+ * @{
+ */
+ /**
+ * @brief Use ChibiOS
+ * @details Defaults to FALSE
+ */
+ #ifndef GFX_USE_OS_CHIBIOS
+ #define GFX_USE_OS_CHIBIOS FALSE
+ #endif
+ /**
+ * @brief Use Win32
+ * @details Defaults to FALSE
+ */
+ #ifndef GFX_USE_OS_WIN32
+ #define GFX_USE_OS_WIN32 FALSE
+ #endif
+ /**
+ * @brief Use a unix variant with posix threads
+ * @details Defaults to FALSE
+ */
+ #ifndef GFX_USE_OS_POSIX
+ #define GFX_USE_OS_POSIX FALSE
+ #endif
+/**
+ * @}
+ *
+ * @name GOS Optional Sizing Parameters
+ * @{
+ */
+/** @} */
+
+#endif /* _GOS_OPTIONS_H */
+/** @} */
diff --git a/include/gos/posix.h b/include/gos/posix.h
new file mode 100644
index 00000000..f61b13db
--- /dev/null
+++ b/include/gos/posix.h
@@ -0,0 +1,31 @@
+/*
+ ChibiOS/GFX - Copyright (C) 2012, 2013
+ 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/>.
+*/
+/**
+ * @file include/gos/posix.h
+ * @brief GOS - Operating System Support header file for POSIX.
+ */
+
+#ifndef _GOS_POSIX_H
+#define _GOS_POSIX_H
+
+#if GFX_USE_OS_POSIX
+#endif /* GFX_USE_OS_POSIX */
+
+#endif /* _GOS_POSIX_H */
diff --git a/include/gos/win32.h b/include/gos/win32.h
new file mode 100644
index 00000000..a6f28865
--- /dev/null
+++ b/include/gos/win32.h
@@ -0,0 +1,31 @@
+/*
+ ChibiOS/GFX - Copyright (C) 2012, 2013
+ 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/>.
+*/
+/**
+ * @file include/gos/win32.h
+ * @brief GOS - Operating System Support header file for WIN32.
+ */
+
+#ifndef _GOS_WIN32_H
+#define _GOS_WIN32_H
+
+#if GFX_USE_OS_WIN32
+#endif /* GFX_USE_OS_WIN32 */
+
+#endif /* _GOS_WIN32_H */
diff --git a/include/gtimer/gtimer.h b/include/gtimer/gtimer.h
index 7d7747d4..5ad8c7c0 100644
--- a/include/gtimer/gtimer.h
+++ b/include/gtimer/gtimer.h
@@ -51,8 +51,8 @@ typedef void (*GTimerFunction)(void *param);
typedef struct GTimer_t {
GTimerFunction fn;
void *param;
- systime_t when;
- systime_t period;
+ systemticks_t when;
+ systemticks_t period;
uint16_t flags;
struct GTimer_t *next;
struct GTimer_t *prev;
@@ -104,7 +104,7 @@ void gtimerInit(GTimer *pt);
*
* @api
*/
-void gtimerStart(GTimer *pt, GTimerFunction fn, void *param, bool_t periodic, systime_t millisec);
+void gtimerStart(GTimer *pt, GTimerFunction fn, void *param, bool_t periodic, delaytime_t millisec);
/**
* @brief Stop a timer (periodic or otherwise)
diff --git a/include/gwin/console.h b/include/gwin/console.h
index 55bad841..1fc19e42 100644
--- a/include/gwin/console.h
+++ b/include/gwin/console.h
@@ -40,10 +40,12 @@
typedef struct GConsoleObject_t {
GWindowObject gwin;
- struct GConsoleWindowStream_t {
- const struct GConsoleWindowVMT_t *vmt;
- _base_asynchronous_channel_data
- } stream;
+ #if GFX_USE_OS_CHIBIOS
+ struct GConsoleWindowStream_t {
+ const struct GConsoleWindowVMT_t *vmt;
+ _base_asynchronous_channel_data
+ } stream;
+ #endif
coord_t cx,cy; // Cursor position
uint8_t fy; // Current font height
@@ -78,15 +80,19 @@ extern "C" {
*/
GHandle gwinCreateConsole(GConsoleObject *gc, coord_t x, coord_t y, coord_t width, coord_t height, font_t font);
-/**
- * @brief Get a stream from a console window suitable for use with chprintf().
- * @return The stream handle or NULL if this is not a console window.
- *
- * @param[in] gh The window handle (must be a console window)
- *
- * @api
- */
-BaseSequentialStream *gwinGetConsoleStream(GHandle gh);
+#if GFX_USE_OS_CHIBIOS
+ /**
+ * @brief Get a stream from a console window suitable for use with chprintf().
+ * @return The stream handle or NULL if this is not a console window.
+ *
+ * @param[in] gh The window handle (must be a console window)
+ *
+ * @note Only useful in ChibiOS
+ *
+ * @api
+ */
+ BaseSequentialStream *gwinGetConsoleStream(GHandle gh);
+#endif
/**
* @brief Put a character at the cursor position in the window.
diff --git a/src/gadc/gadc.c b/src/gadc/gadc.c
index ff1903c8..36f4db6d 100644
--- a/src/gadc/gadc.c
+++ b/src/gadc/gadc.c
@@ -12,8 +12,6 @@
* @addtogroup GADC
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GADC
@@ -33,16 +31,15 @@
volatile bool_t GADC_Timer_Missed;
-static SEMAPHORE_DECL(gadcsem, GADC_MAX_LOWSPEED_DEVICES);
-static MUTEX_DECL(gadcmutex);
-static GTIMER_DECL(LowSpeedGTimer);
+static gfxSem gadcsem;
+static gfxMutex gadcmutex;
+static GTimer LowSpeedGTimer;
#if GFX_USE_GEVENT
- static GTIMER_DECL(HighSpeedGTimer);
+ static GTimer HighSpeedGTimer;
#endif
static volatile uint16_t gflags = 0;
- #define GADC_GFLG_INITDONE 0x0001
- #define GADC_GFLG_ISACTIVE 0x0002
+ #define GADC_GFLG_ISACTIVE 0x0001
#define GADC_FLG_ISACTIVE 0x0001
#define GADC_FLG_ISDONE 0x0002
@@ -64,11 +61,11 @@ static struct hsdev {
adcsample_t *lastbuffer;
uint16_t lastflags;
- // Other stuff we need to track progress and for signalling
+ // Other stuff we need to track progress and for signaling
GadcLldTimerData lld;
size_t samplesPerConversion;
size_t remaining;
- BinarySemaphore *bsem;
+ gfxSem *bsem;
GEventADC *pEvent;
GADCISRCallbackFunction isrfn;
} hs;
@@ -175,7 +172,7 @@ void GADC_ISR_CompleteI(ADCDriver *adcp, adcsample_t *buffer, size_t n) {
hs.isrfn(buffer, n);
if (hs.bsem)
- chBSemSignalI(hs.bsem);
+ gfxSemSignalI(hs.bsem);
#if GFX_USE_GEVENT
if (hs.flags & GADC_FLG_GTIMER)
@@ -238,25 +235,29 @@ void GADC_ISR_ErrorI(ADCDriver *adcp, adcerror_t err) {
FindNextConversionI();
}
-static inline void DoInit(void) {
- if (!(gflags & GADC_GFLG_INITDONE)) {
- gflags |= GADC_GFLG_INITDONE;
- gadc_lld_init();
- }
+/* Our module initialiser */
+void _gadcInit(void) {
+ gadc_lld_init();
+ gfxSemInit(&gadcsem, GADC_MAX_LOWSPEED_DEVICES, GADC_MAX_LOWSPEED_DEVICES);
+ gfxMutexInit(&gadcmutex);
+ gtimerInit(&LowSpeedGTimer);
+ #if GFX_USE_GEVENT
+ gtimerInit(&HighSpeedGTimer);
+ #endif
}
static inline void StartADC(bool_t onNoHS) {
- chSysLock();
+ gfxSystemLock();
if (!(gflags & GADC_GFLG_ISACTIVE) || (onNoHS && !curlsdev))
FindNextConversionI();
- chSysUnlock();
+ gfxSystemUnlock();
}
static void BSemSignalCallback(adcsample_t *buffer, void *param) {
(void) buffer;
/* Signal the BinarySemaphore parameter */
- chBSemSignal((BinarySemaphore *)param);
+ gfxSemSignal((gfxSem *)param);
}
#if GFX_USE_GEVENT
@@ -310,7 +311,7 @@ static void LowSpeedGTimerCallback(void *param) {
p->param = 0; // Needed to prevent the compiler removing the local variables
p->lld.buffer = 0; // Needed to prevent the compiler removing the local variables
p->flags = 0; // The slot is available (indivisible operation)
- chSemSignal(&gadcsem); // Tell everyone
+ gfxSemSignal(&gadcsem); // Tell everyone
fn(buffer, prm); // Perform the callback
}
}
@@ -342,7 +343,6 @@ void gadcHighSpeedInit(uint32_t physdev, uint32_t frequency, adcsample_t *buffer
#if GFX_USE_GEVENT
GSourceHandle gadcHighSpeedGetSource(void) {
- DoInit();
if (!gtimerIsActive(&HighSpeedGTimer))
gtimerStart(&HighSpeedGTimer, HighSpeedGTimerCallback, NULL, TRUE, TIME_INFINITE);
hs.flags |= GADC_FLG_GTIMER;
@@ -354,19 +354,15 @@ void gadcHighSpeedSetISRCallback(GADCISRCallbackFunction isrfn) {
hs.isrfn = isrfn;
}
-void gadcHighSpeedSetBSem(BinarySemaphore *pbsem, GEventADC *pEvent) {
- DoInit();
-
+void gadcHighSpeedSetBSem(gfxSem *pbsem, GEventADC *pEvent) {
/* Use the system lock to ensure they occur atomically */
- chSysLock();
+ gfxSystemLock();
hs.pEvent = pEvent;
hs.bsem = pbsem;
- chSysUnlock();
+ gfxSystemUnlock();
}
void gadcHighSpeedStart(void) {
- DoInit();
-
/* If its already going we don't need to do anything */
if (hs.flags & GADC_FLG_ISACTIVE)
return;
@@ -377,8 +373,6 @@ void gadcHighSpeedStart(void) {
}
void gadcHighSpeedStop(void) {
- DoInit();
-
if (hs.flags & GADC_FLG_ISACTIVE) {
/* No more from us */
hs.flags = 0;
@@ -392,21 +386,22 @@ void gadcHighSpeedStop(void) {
}
void gadcLowSpeedGet(uint32_t physdev, adcsample_t *buffer) {
- struct lsdev *p;
- BSEMAPHORE_DECL(mysem, TRUE);
+ struct lsdev *p;
+ gfxSem mysem;
/* Start the Low Speed Timer */
- chMtxLock(&gadcmutex);
+ gfxSemInit(&mysem, 1, 1);
+ gfxMutexEnter(&gadcmutex);
if (!gtimerIsActive(&LowSpeedGTimer))
gtimerStart(&LowSpeedGTimer, LowSpeedGTimerCallback, NULL, TRUE, TIME_INFINITE);
- chMtxUnlock();
+ gfxMutexExit(&gadcmutex);
while(1) {
/* Wait for an available slot */
- chSemWait(&gadcsem);
+ gfxSemWait(&gadcsem, TIME_INFINITE);
/* Find a slot */
- chMtxLock(&gadcmutex);
+ gfxMutexEnter(&gadcmutex);
for(p = ls; p < &ls[GADC_MAX_LOWSPEED_DEVICES]; p++) {
if (!(p->flags & GADC_FLG_ISACTIVE)) {
p->lld.physdev = physdev;
@@ -414,13 +409,13 @@ void gadcLowSpeedGet(uint32_t physdev, adcsample_t *buffer) {
p->fn = BSemSignalCallback;
p->param = &mysem;
p->flags = GADC_FLG_ISACTIVE;
- chMtxUnlock();
+ gfxMutexExit(&gadcmutex);
StartADC(FALSE);
- chBSemWait(&mysem);
+ gfxSemWait(&mysem, TIME_INFINITE);
return;
}
}
- chMtxUnlock();
+ gfxMutexExit(&gadcmutex);
/**
* We should never get here - the count semaphore must be wrong.
@@ -432,10 +427,8 @@ void gadcLowSpeedGet(uint32_t physdev, adcsample_t *buffer) {
bool_t gadcLowSpeedStart(uint32_t physdev, adcsample_t *buffer, GADCCallbackFunction fn, void *param) {
struct lsdev *p;
- DoInit();
-
/* Start the Low Speed Timer */
- chMtxLock(&gadcmutex);
+ gfxMutexEnter(&gadcmutex);
if (!gtimerIsActive(&LowSpeedGTimer))
gtimerStart(&LowSpeedGTimer, LowSpeedGTimerCallback, NULL, TRUE, TIME_INFINITE);
@@ -443,18 +436,18 @@ bool_t gadcLowSpeedStart(uint32_t physdev, adcsample_t *buffer, GADCCallbackFunc
for(p = ls; p < &ls[GADC_MAX_LOWSPEED_DEVICES]; p++) {
if (!(p->flags & GADC_FLG_ISACTIVE)) {
/* We know we have a slot - this should never wait anyway */
- chSemWaitTimeout(&gadcsem, TIME_IMMEDIATE);
+ gfxSemWait(&gadcsem, TIME_IMMEDIATE);
p->lld.physdev = physdev;
p->lld.buffer = buffer;
p->fn = fn;
p->param = param;
p->flags = GADC_FLG_ISACTIVE;
- chMtxUnlock();
+ gfxMutexExit(&gadcmutex);
StartADC(FALSE);
return TRUE;
}
}
- chMtxUnlock();
+ gfxMutexExit(&gadcmutex);
return FALSE;
}
diff --git a/src/gaudin/gaudin.c b/src/gaudin/gaudin.c
index 3a9d23b8..2e87c628 100644
--- a/src/gaudin/gaudin.c
+++ b/src/gaudin/gaudin.c
@@ -12,8 +12,6 @@
* @addtogroup GAUDIN
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GAUDIN
@@ -22,7 +20,7 @@
#include "gaudin/lld/gaudin_lld.h"
static gaudin_params aud;
-static BinarySemaphore *paudSem;
+static gfxSem *paudSem;
static GEventAudioIn *paudEvent;
static audin_sample_t *lastbuffer;
static size_t lastcount;
@@ -31,7 +29,7 @@ static uint16_t audFlags;
#define AUDFLG_USE_EVENTS 0x0002
#if GFX_USE_GEVENT
- static GTIMER_DECL(AudGTimer);
+ static GTimer AudGTimer;
static void AudGTimerCallback(void *param) {
(void) param;
@@ -75,7 +73,7 @@ void GAUDIN_ISR_CompleteI(audin_sample_t *buffer, size_t n) {
/* Our two signalling mechanisms */
if (paudSem)
- chBSemSignalI(paudSem);
+ gfxSemSignalI(paudSem);
#if GFX_USE_GEVENT
if (audFlags & AUDFLG_USE_EVENTS)
@@ -87,6 +85,13 @@ void GAUDIN_ISR_ErrorI(void) {
/* Ignore any errors for now */
}
+/* The module initialiser */
+void _gaudinInit(void) {
+ #if GFX_USE_GEVENT
+ gtimerInit(&AudGTimer);
+ #endif
+}
+
bool_t gaudinInit(uint16_t channel, uint32_t frequency, audin_sample_t *buffer, size_t bufcount, size_t samplesPerEvent) {
/* Check the channel is valid */
if (channel >= GAUDIN_NUM_CHANNELS || frequency > GAUDIN_MAX_SAMPLE_FREQUENCY)
@@ -120,11 +125,11 @@ bool_t gaudinInit(uint16_t channel, uint32_t frequency, audin_sample_t *buffer,
}
#endif
-void gaudinSetBSem(BinarySemaphore *pbsem, GEventAudioIn *pEvent) {
- chSysLock();
+void gaudinSetBSem(gfxSem *pbsem, GEventAudioIn *pEvent) {
+ gfxSystemLock();
paudSem = pbsem;
paudEvent = pEvent;
- chSysUnlock();
+ gfxSystemUnlock();
}
void gaudinStart(void) {
diff --git a/src/gaudout/gaudout.c b/src/gaudout/gaudout.c
index 3b4051ff..b418b158 100644
--- a/src/gaudout/gaudout.c
+++ b/src/gaudout/gaudout.c
@@ -12,8 +12,6 @@
* @addtogroup GAUDOUT
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GAUDOUT || defined(__DOXYGEN__)
diff --git a/src/gdisp/fonts.c b/src/gdisp/fonts.c
index 3d29e50c..175828c6 100644
--- a/src/gdisp/fonts.c
+++ b/src/gdisp/fonts.c
@@ -10,12 +10,9 @@
* @brief GDISP Font Handling.
*
* @addtogroup GDISP
- *
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP && GDISP_NEED_TEXT
diff --git a/src/gdisp/gdisp.c b/src/gdisp/gdisp.c
index 069bc577..b316be49 100644
--- a/src/gdisp/gdisp.c
+++ b/src/gdisp/gdisp.c
@@ -12,8 +12,6 @@
* @addtogroup GDISP
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP
@@ -26,44 +24,22 @@
#include "gdisp/lld/gdisp_lld.h"
/*===========================================================================*/
-/* Driver local definitions. */
-/*===========================================================================*/
-
-#if GDISP_NEED_MULTITHREAD
- #if !CH_USE_MUTEXES
- #error "GDISP: CH_USE_MUTEXES must be defined in chconf.h because GDISP_NEED_MULTITHREAD is defined"
- #endif
-#endif
-
-#if GDISP_NEED_ASYNC
- #if !CH_USE_MAILBOXES || !CH_USE_MUTEXES || !CH_USE_SEMAPHORES
- #error "GDISP: CH_USE_MAILBOXES, CH_USE_SEMAPHORES and CH_USE_MUTEXES must be defined in chconf.h because GDISP_NEED_ASYNC is defined"
- #endif
-#endif
-
-/*===========================================================================*/
-/* Driver exported variables. */
-/*===========================================================================*/
-
-/*===========================================================================*/
/* Driver local variables. */
/*===========================================================================*/
#if GDISP_NEED_MULTITHREAD || GDISP_NEED_ASYNC
- static Mutex gdispMutex;
+ static gfxMutex gdispMutex;
#endif
#if GDISP_NEED_ASYNC
- #define GDISP_THREAD_STACK_SIZE 512 /* Just a number - not yet a reflection of actual use */
+ #define GDISP_THREAD_STACK_SIZE 256 /* Just a number - not yet a reflection of actual use */
#define GDISP_QUEUE_SIZE 8 /* We only allow a short queue */
- static Thread * lldThread;
- static Mailbox gdispMailbox;
- static msg_t gdispMailboxQueue[GDISP_QUEUE_SIZE];
- static Semaphore gdispMsgsSem;
- static Mutex gdispMsgsMutex;
+ static gfxQueue gdispQueue;
+ static gfxMutex gdispMsgsMutex;
+ static gfxSem gdispMsgsSem;
static gdisp_lld_msg_t gdispMsgs[GDISP_QUEUE_SIZE];
- static WORKING_AREA(waGDISPThread, GDISP_THREAD_STACK_SIZE);
+ static DECLARESTACK(waGDISPThread, GDISP_THREAD_STACK_SIZE);
#endif
/*===========================================================================*/
@@ -71,26 +47,23 @@
/*===========================================================================*/
#if GDISP_NEED_ASYNC
- static msg_t GDISPThreadHandler(void *arg) {
+ static threadreturn_t GDISPThreadHandler(void *arg) {
(void)arg;
gdisp_lld_msg_t *pmsg;
- #if CH_USE_REGISTRY
- chRegSetThreadName("GDISPAsyncAPI");
- #endif
-
while(1) {
/* Wait for msg with work to do. */
- chMBFetch(&gdispMailbox, (msg_t *)&pmsg, TIME_INFINITE);
+ pmsg = (gdisp_lld_msg_t *)gfxQueueGet(&gdispQueue, TIME_INFINITE);
/* OK - we need to obtain the mutex in case a synchronous operation is occurring */
- chMtxLock(&gdispMutex);
+ gfxMutexEnter(&gdispMutex);
+
gdisp_lld_msg_dispatch(pmsg);
- chMtxUnlock();
/* Mark the message as free */
pmsg->action = GDISP_LLD_MSG_NOP;
- chSemSignal(&gdispMsgsSem);
+
+ gfxMutexExit(&gdispMutex);
}
return 0;
}
@@ -101,22 +74,22 @@
while(1) { /* To be sure, to be sure */
/* Wait for a slot */
- chSemWait(&gdispMsgsSem);
+ gfxSemWait(&gdispMsgsSem, TIME_INFINITE);
/* Find the slot */
- chMtxLock(&gdispMsgsMutex);
+ gfxMutexEnter(&gdispMsgsMutex);
for(p=gdispMsgs; p < &gdispMsgs[GDISP_QUEUE_SIZE]; p++) {
if (p->action == GDISP_LLD_MSG_NOP) {
/* Allocate it */
p->action = action;
- chMtxUnlock();
+ gfxMutexExit(&gdispMsgsMutex);
return p;
}
}
- chMtxUnlock();
+ gfxMutexExit(&gdispMsgsMutex);
/* Oops - none found, try again */
- chSemSignal(&gdispMsgsSem);
+ gfxSemSignal(&gdispMsgsSem);
}
}
#endif
@@ -125,46 +98,40 @@
/* Driver exported functions. */
/*===========================================================================*/
+/* Our module initialiser */
#if GDISP_NEED_MULTITHREAD
- bool_t gdispInit(void) {
- bool_t res;
-
+ void _gdispInit(void) {
/* Initialise Mutex */
- chMtxInit(&gdispMutex);
+ gfxMutexInit(&gdispMutex);
/* Initialise driver */
- chMtxLock(&gdispMutex);
- res = gdisp_lld_init();
- chMtxUnlock();
-
- return res;
+ gfxMutexEnter(&gdispMutex);
+ gdisp_lld_init();
+ gfxMutexExit(&gdispMutex);
}
#elif GDISP_NEED_ASYNC
- bool_t gdispInit(void) {
- bool_t res;
+ void _gdispInit(void) {
unsigned i;
/* Mark all the Messages as free */
for(i=0; i < GDISP_QUEUE_SIZE; i++)
gdispMsgs[i].action = GDISP_LLD_MSG_NOP;
- /* Initialise our Mailbox, Mutex's and Counting Semaphore.
- * A Mutex is required as well as the Mailbox and Thread because some calls have to be synchronous.
+ /* Initialise our Queue, Mutex's and Counting Semaphore.
+ * A Mutex is required as well as the Queue and Thread because some calls have to be synchronous.
* Synchronous calls get handled by the calling thread, asynchronous by our worker thread.
*/
- chMBInit(&gdispMailbox, gdispMailboxQueue, sizeof(gdispMailboxQueue)/sizeof(gdispMailboxQueue[0]));
- chMtxInit(&gdispMutex);
- chMtxInit(&gdispMsgsMutex);
- chSemInit(&gdispMsgsSem, GDISP_QUEUE_SIZE);
+ gfxQueueInit(&gdispQueue);
+ gfxMutexInit(&gdispMutex);
+ gfxMutexInit(&gdispMsgsMutex);
+ gfxSemInit(&gdispMsgsSem, GDISP_QUEUE_SIZE, GDISP_QUEUE_SIZE);
- lldThread = chThdCreateStatic(waGDISPThread, sizeof(waGDISPThread), NORMALPRIO, GDISPThreadHandler, NULL);
+ gfxCreateThread(waGDISPThread, sizeof(waGDISPThread), NORMAL_PRIORITY, GDISPThreadHandler, NULL);
/* Initialise driver - synchronous */
- chMtxLock(&gdispMutex);
- res = gdisp_lld_init();
- chMtxUnlock();
-
- return res;
+ gfxMutexEnter(&gdispMutex);
+ gdisp_lld_init();
+ gfxMutexExit(&gdispMutex);
}
#endif
@@ -174,29 +141,29 @@
}
#elif GDISP_NEED_ASYNC
bool_t gdispIsBusy(void) {
- return chMBGetUsedCountI(&gdispMailbox) != FALSE;
+ return !gfxQueueIsEmpty(&gdispQueue);
}
#endif
#if GDISP_NEED_MULTITHREAD
void gdispClear(color_t color) {
- chMtxLock(&gdispMutex);
+ gfxMutexEnter(&gdispMutex);
gdisp_lld_clear(color);
- chMtxUnlock();
+ gfxMutexExit(&gdispMutex);
}
#elif GDISP_NEED_ASYNC
void gdispClear(color_t color) {
gdisp_lld_msg_t *p = gdispAllocMsg(GDISP_LLD_MSG_CLEAR);
p->clear.color = color;
- chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
+ gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE);
}
#endif
#if GDISP_NEED_MULTITHREAD
void gdispDrawPixel(coord_t x, coord_t y, color_t color) {
- chMtxLock(&gdispMutex);
+ gfxMutexEnter(&gdispMutex);
gdisp_lld_draw_pixel(x, y, color);
- chMtxUnlock();
+ gfxMutexExit(&gdispMutex);
}
#elif GDISP_NEED_ASYNC
void gdispDrawPixel(coord_t x, coord_t y, color_t color) {
@@ -204,15 +171,15 @@
p->drawpixel.x = x;
p->drawpixel.y = y;
p->drawpixel.color = color;
- chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
+ gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE);
}
#endif
#if GDISP_NEED_MULTITHREAD
void gdispDrawLine(coord_t x0, coord_t y0, coord_t x1, coord_t y1, color_t color) {
- chMtxLock(&gdispMutex);
+ gfxMutexEnter(&gdispMutex);
gdisp_lld_draw_line(x0, y0, x1, y1, color);
- chMtxUnlock();
+ gfxMutexExit(&gdispMutex);
}
#elif GDISP_NEED_ASYNC
void gdispDrawLine(coord_t x0, coord_t y0, coord_t x1, coord_t y1, color_t color) {
@@ -222,15 +189,15 @@
p->drawline.x1 = x1;
p->drawline.y1 = y1;
p->drawline.color = color;
- chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
+ gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE);
}
#endif
#if GDISP_NEED_MULTITHREAD
void gdispFillArea(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
- chMtxLock(&gdispMutex);
+ gfxMutexEnter(&gdispMutex);
gdisp_lld_fill_area(x, y, cx, cy, color);
- chMtxUnlock();
+ gfxMutexExit(&gdispMutex);
}
#elif GDISP_NEED_ASYNC
void gdispFillArea(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
@@ -240,15 +207,15 @@
p->fillarea.cx = cx;
p->fillarea.cy = cy;
p->fillarea.color = color;
- chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
+ gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE);
}
#endif
#if GDISP_NEED_MULTITHREAD
void gdispBlitAreaEx(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) {
- chMtxLock(&gdispMutex);
+ gfxMutexEnter(&gdispMutex);
gdisp_lld_blit_area_ex(x, y, cx, cy, srcx, srcy, srccx, buffer);
- chMtxUnlock();
+ gfxMutexExit(&gdispMutex);
}
#elif GDISP_NEED_ASYNC
void gdispBlitAreaEx(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) {
@@ -261,15 +228,15 @@
p->blitarea.srcy = srcy;
p->blitarea.srccx = srccx;
p->blitarea.buffer = buffer;
- chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
+ gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE);
}
#endif
#if (GDISP_NEED_CLIP && GDISP_NEED_MULTITHREAD)
void gdispSetClip(coord_t x, coord_t y, coord_t cx, coord_t cy) {
- chMtxLock(&gdispMutex);
+ gfxMutexEnter(&gdispMutex);
gdisp_lld_set_clip(x, y, cx, cy);
- chMtxUnlock();
+ gfxMutexExit(&gdispMutex);
}
#elif GDISP_NEED_CLIP && GDISP_NEED_ASYNC
void gdispSetClip(coord_t x, coord_t y, coord_t cx, coord_t cy) {
@@ -278,15 +245,15 @@
p->setclip.y = y;
p->setclip.cx = cx;
p->setclip.cy = cy;
- chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
+ gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE);
}
#endif
#if (GDISP_NEED_CIRCLE && GDISP_NEED_MULTITHREAD)
void gdispDrawCircle(coord_t x, coord_t y, coord_t radius, color_t color) {
- chMtxLock(&gdispMutex);
+ gfxMutexEnter(&gdispMutex);
gdisp_lld_draw_circle(x, y, radius, color);
- chMtxUnlock();
+ gfxMutexExit(&gdispMutex);
}
#elif GDISP_NEED_CIRCLE && GDISP_NEED_ASYNC
void gdispDrawCircle(coord_t x, coord_t y, coord_t radius, color_t color) {
@@ -295,15 +262,15 @@
p->drawcircle.y = y;
p->drawcircle.radius = radius;
p->drawcircle.color = color;
- chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
+ gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE);
}
#endif
#if (GDISP_NEED_CIRCLE && GDISP_NEED_MULTITHREAD)
void gdispFillCircle(coord_t x, coord_t y, coord_t radius, color_t color) {
- chMtxLock(&gdispMutex);
+ gfxMutexEnter(&gdispMutex);
gdisp_lld_fill_circle(x, y, radius, color);
- chMtxUnlock();
+ gfxMutexExit(&gdispMutex);
}
#elif GDISP_NEED_CIRCLE && GDISP_NEED_ASYNC
void gdispFillCircle(coord_t x, coord_t y, coord_t radius, color_t color) {
@@ -312,15 +279,15 @@
p->fillcircle.y = y;
p->fillcircle.radius = radius;
p->fillcircle.color = color;
- chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
+ gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE);
}
#endif
#if (GDISP_NEED_ELLIPSE && GDISP_NEED_MULTITHREAD)
void gdispDrawEllipse(coord_t x, coord_t y, coord_t a, coord_t b, color_t color) {
- chMtxLock(&gdispMutex);
+ gfxMutexEnter(&gdispMutex);
gdisp_lld_draw_ellipse(x, y, a, b, color);
- chMtxUnlock();
+ gfxMutexExit(&gdispMutex);
}
#elif GDISP_NEED_ELLIPSE && GDISP_NEED_ASYNC
void gdispDrawEllipse(coord_t x, coord_t y, coord_t a, coord_t b, color_t color) {
@@ -330,15 +297,15 @@
p->drawellipse.a = a;
p->drawellipse.b = b;
p->drawellipse.color = color;
- chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
+ gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE);
}
#endif
#if (GDISP_NEED_ELLIPSE && GDISP_NEED_MULTITHREAD)
void gdispFillEllipse(coord_t x, coord_t y, coord_t a, coord_t b, color_t color) {
- chMtxLock(&gdispMutex);
+ gfxMutexEnter(&gdispMutex);
gdisp_lld_fill_ellipse(x, y, a, b, color);
- chMtxUnlock();
+ gfxMutexExit(&gdispMutex);
}
#elif GDISP_NEED_ELLIPSE && GDISP_NEED_ASYNC
void gdispFillEllipse(coord_t x, coord_t y, coord_t a, coord_t b, color_t color) {
@@ -348,15 +315,15 @@
p->fillellipse.a = a;
p->fillellipse.b = b;
p->fillellipse.color = color;
- chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
+ gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE);
}
#endif
#if (GDISP_NEED_ARC && GDISP_NEED_MULTITHREAD)
void gdispDrawArc(coord_t x, coord_t y, coord_t radius, coord_t start, coord_t end, color_t color) {
- chMtxLock(&gdispMutex);
+ gfxMutexEnter(&gdispMutex);
gdisp_lld_draw_arc(x, y, radius, start, end, color);
- chMtxUnlock();
+ gfxMutexExit(&gdispMutex);
}
#elif GDISP_NEED_ARC && GDISP_NEED_ASYNC
void gdispDrawArc(coord_t x, coord_t y, coord_t radius, coord_t start, coord_t end, color_t color) {
@@ -367,15 +334,15 @@
p->drawarc.start = start;
p->drawarc.end = end;
p->drawarc.color = color;
- chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
+ gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE);
}
#endif
#if (GDISP_NEED_ARC && GDISP_NEED_MULTITHREAD)
void gdispFillArc(coord_t x, coord_t y, coord_t radius, coord_t start, coord_t end, color_t color) {
- chMtxLock(&gdispMutex);
+ gfxMutexEnter(&gdispMutex);
gdisp_lld_fill_arc(x, y, radius, start, end, color);
- chMtxUnlock();
+ gfxMutexExit(&gdispMutex);
}
#elif GDISP_NEED_ARC && GDISP_NEED_ASYNC
void gdispFillArc(coord_t x, coord_t y, coord_t radius, coord_t start, coord_t end, color_t color) {
@@ -386,7 +353,7 @@
p->fillarc.start = start;
p->fillarc.end = end;
p->fillarc.color = color;
- chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
+ gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE);
}
#endif
@@ -428,9 +395,9 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r
#if (GDISP_NEED_TEXT && GDISP_NEED_MULTITHREAD)
void gdispDrawChar(coord_t x, coord_t y, char c, font_t font, color_t color) {
- chMtxLock(&gdispMutex);
+ gfxMutexEnter(&gdispMutex);
gdisp_lld_draw_char(x, y, c, font, color);
- chMtxUnlock();
+ gfxMutexExit(&gdispMutex);
}
#elif GDISP_NEED_TEXT && GDISP_NEED_ASYNC
void gdispDrawChar(coord_t x, coord_t y, char c, font_t font, color_t color) {
@@ -440,15 +407,15 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r
p->drawchar.c = c;
p->drawchar.font = font;
p->drawchar.color = color;
- chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
+ gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE);
}
#endif
#if (GDISP_NEED_TEXT && GDISP_NEED_MULTITHREAD)
void gdispFillChar(coord_t x, coord_t y, char c, font_t font, color_t color, color_t bgcolor) {
- chMtxLock(&gdispMutex);
+ gfxMutexEnter(&gdispMutex);
gdisp_lld_fill_char(x, y, c, font, color, bgcolor);
- chMtxUnlock();
+ gfxMutexExit(&gdispMutex);
}
#elif GDISP_NEED_TEXT && GDISP_NEED_ASYNC
void gdispFillChar(coord_t x, coord_t y, char c, font_t font, color_t color, color_t bgcolor) {
@@ -459,7 +426,7 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r
p->fillchar.font = font;
p->fillchar.color = color;
p->fillchar.bgcolor = bgcolor;
- chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
+ gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE);
}
#endif
@@ -468,9 +435,9 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r
color_t c;
/* Always synchronous as it must return a value */
- chMtxLock(&gdispMutex);
+ gfxMutexEnter(&gdispMutex);
c = gdisp_lld_get_pixel_color(x, y);
- chMtxUnlock();
+ gfxMutexExit(&gdispMutex);
return c;
}
@@ -478,9 +445,9 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r
#if (GDISP_NEED_SCROLL && GDISP_NEED_MULTITHREAD)
void gdispVerticalScroll(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) {
- chMtxLock(&gdispMutex);
+ gfxMutexEnter(&gdispMutex);
gdisp_lld_vertical_scroll(x, y, cx, cy, lines, bgcolor);
- chMtxUnlock();
+ gfxMutexExit(&gdispMutex);
}
#elif GDISP_NEED_SCROLL && GDISP_NEED_ASYNC
void gdispVerticalScroll(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) {
@@ -491,23 +458,22 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r
p->verticalscroll.cy = cy;
p->verticalscroll.lines = lines;
p->verticalscroll.bgcolor = bgcolor;
- chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
+ gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE);
}
#endif
#if (GDISP_NEED_CONTROL && GDISP_NEED_MULTITHREAD)
void gdispControl(unsigned what, void *value) {
- chMtxLock(&gdispMutex);
+ gfxMutexEnter(&gdispMutex);
gdisp_lld_control(what, value);
- chMtxUnlock();
+ gfxMutexExit(&gdispMutex);
}
#elif GDISP_NEED_CONTROL && GDISP_NEED_ASYNC
void gdispControl(unsigned what, void *value) {
gdisp_lld_msg_t *p = gdispAllocMsg(GDISP_LLD_MSG_CONTROL);
p->control.what = what;
p->control.value = value;
- chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
- chThdSleepMilliseconds(100);
+ gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE);
}
#endif
@@ -515,9 +481,9 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r
void *gdispQuery(unsigned what) {
void *res;
- chMtxLock(&gdispMutex);
+ gfxMutexEnter(&gdispMutex);
res = gdisp_lld_query(what);
- chMtxUnlock();
+ gfxMutexExit(&gdispMutex);
return res;
}
#endif
@@ -564,7 +530,7 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
void gdispFillConvexPoly(coord_t tx, coord_t ty, const point *pntarray, unsigned cnt, color_t color) {
const point *lpnt, *rpnt, *epnts;
- fpcoord_t lx, rx, lk, rk;
+ fixed lx, rx, lk, rk;
coord_t y, ymax, lxc, rxc;
epnts = &pntarray[cnt-1];
@@ -575,13 +541,13 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
if (lpnt->y < rpnt->y)
rpnt = lpnt;
}
- lx = rx = rpnt->x<<16;
+ lx = rx = FIXED(rpnt->x);
y = rpnt->y;
/* Work out the slopes of the two attached line segs */
lpnt = rpnt <= pntarray ? epnts : rpnt-1;
while (lpnt->y == y) {
- lx = lpnt->x<<16;
+ lx = FIXED(lpnt->x);
lpnt = lpnt <= pntarray ? epnts : lpnt-1;
if (!cnt--) return;
}
@@ -591,8 +557,8 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
rpnt = rpnt >= epnts ? pntarray : rpnt+1;
if (!cnt--) return;
}
- lk = (((fpcoord_t)(lpnt->x)<<16) - lx) / (lpnt->y - y);
- rk = (((fpcoord_t)(rpnt->x)<<16) - rx) / (rpnt->y - y);
+ lk = (FIXED(lpnt->x) - lx) / (lpnt->y - y);
+ rk = (FIXED(rpnt->x) - rx) / (rpnt->y - y);
while(1) {
/* Determine our boundary */
@@ -600,8 +566,8 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
/* Scan down the line segments until we hit a boundary */
for(; y < ymax; y++) {
- lxc = lx>>16;
- rxc = rx>>16;
+ lxc = NONFIXED(lx);
+ rxc = NONFIXED(rx);
/*
* Doesn't print the right hand point in order to allow polygon joining.
* Also ensures that we draw from left to right with the minimum number
@@ -629,19 +595,19 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
if (ymax == lpnt->y) {
lpnt = lpnt <= pntarray ? epnts : lpnt-1;
while (lpnt->y == y) {
- lx = lpnt->x<<16;
+ lx = FIXED(lpnt->x);
lpnt = lpnt <= pntarray ? epnts : lpnt-1;
if (!cnt--) return;
}
- lk = (((fpcoord_t)(lpnt->x)<<16) - lx) / (lpnt->y - y);
+ lk = (FIXED(lpnt->x) - lx) / (lpnt->y - y);
} else {
rpnt = rpnt >= epnts ? pntarray : rpnt+1;
while (rpnt->y == y) {
- rx = rpnt->x<<16;
+ rx = FIXED(rpnt->x);
rpnt = rpnt >= epnts ? pntarray : rpnt+1;
if (!cnt--) return;
}
- rk = (((fpcoord_t)(rpnt->x)<<16) - rx) / (rpnt->y - y);
+ rk = (FIXED(rpnt->x) - rx) / (rpnt->y - y);
}
}
}
diff --git a/src/gdisp/image.c b/src/gdisp/image.c
index 2a648e59..50b641b6 100644
--- a/src/gdisp/image.c
+++ b/src/gdisp/image.c
@@ -12,8 +12,6 @@
* @defgroup Image Image
* @ingroup GDISP
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP && GDISP_NEED_IMAGE
@@ -27,7 +25,7 @@ typedef struct gdispImageHandlers {
coord_t x, coord_t y,
coord_t cx, coord_t cy,
coord_t sx, coord_t sy); /* The draw function */
- systime_t (*next)(gdispImage *img); /* The next frame function */
+ delaytime_t (*next)(gdispImage *img); /* The next frame function */
} gdispImageHandlers;
static gdispImageHandlers ImageHandlers[] = {
@@ -85,72 +83,79 @@ bool_t gdispImageSetMemoryReader(gdispImage *img, const void *memimage) {
return TRUE;
}
-static size_t ImageBaseFileStreamRead(struct gdispImageIO *pio, void *buf, size_t len) {
- if (pio->fd == (void *)-1) return 0;
- len = chSequentialStreamRead(((BaseFileStream *)pio->fd), (uint8_t *)buf, len);
- pio->pos += len;
- return len;
-}
+#if GFX_USE_OS_CHIBIOS
+ static size_t ImageBaseFileStreamRead(struct gdispImageIO *pio, void *buf, size_t len) {
+ if (pio->fd == (void *)-1) return 0;
+ len = chSequentialStreamRead(((BaseFileStream *)pio->fd), (uint8_t *)buf, len);
+ pio->pos += len;
+ return len;
+ }
-static void ImageBaseFileStreamSeek(struct gdispImageIO *pio, size_t pos) {
- if (pio->fd == (void *)-1) return;
- if (pio->pos != pos) {
- chFileStreamSeek(((BaseFileStream *)pio->fd), pos);
- pio->pos = pos;
+ static void ImageBaseFileStreamSeek(struct gdispImageIO *pio, size_t pos) {
+ if (pio->fd == (void *)-1) return;
+ if (pio->pos != pos) {
+ chFileStreamSeek(((BaseFileStream *)pio->fd), pos);
+ pio->pos = pos;
+ }
}
-}
-static void ImageBaseFileStreamClose(struct gdispImageIO *pio) {
- if (pio->fd == (void *)-1) return;
- chFileStreamClose(((BaseFileStream *)pio->fd));
- pio->fd = (void *)-1;
- pio->pos = 0;
-}
+ static void ImageBaseFileStreamClose(struct gdispImageIO *pio) {
+ if (pio->fd == (void *)-1) return;
+ chFileStreamClose(((BaseFileStream *)pio->fd));
+ pio->fd = (void *)-1;
+ pio->pos = 0;
+ }
-static const gdispImageIOFunctions ImageBaseFileStreamFunctions =
- { ImageBaseFileStreamRead, ImageBaseFileStreamSeek, ImageBaseFileStreamClose };
+ static const gdispImageIOFunctions ImageBaseFileStreamFunctions =
+ { ImageBaseFileStreamRead, ImageBaseFileStreamSeek, ImageBaseFileStreamClose };
-bool_t gdispImageSetBaseFileStreamReader(gdispImage *img, void *BaseFileStreamPtr) {
- img->io.fns = &ImageBaseFileStreamFunctions;
- img->io.pos = 0;
- img->io.fd = BaseFileStreamPtr;
- return TRUE;
-}
+ bool_t gdispImageSetBaseFileStreamReader(gdispImage *img, void *BaseFileStreamPtr) {
+ img->io.fns = &ImageBaseFileStreamFunctions;
+ img->io.pos = 0;
+ img->io.fd = BaseFileStreamPtr;
+ return TRUE;
+ }
+#endif
-#if defined(WIN32)
- #include <fcntl.h>
+#if defined(WIN32) || GFX_USE_OS_WIN32 || GFX_USE_OS_POSIX
+ #include <stdio.h>
- static size_t ImageSimulFileRead(struct gdispImageIO *pio, void *buf, size_t len) {
- if (pio->fd == (void *)-1) return 0;
- len = read((int)pio->fd, buf, len);
+ static size_t ImageFileRead(struct gdispImageIO *pio, void *buf, size_t len) {
+ if (!pio->fd) return 0;
+ len = fread(buf, 1, len, (FILE *)pio->fd);
if ((int)len < 0) len = 0;
pio->pos += len;
return len;
}
- static void ImageSimulFileSeek(struct gdispImageIO *pio, size_t pos) {
- if (pio->fd == (void *)-1) return;
+ static void ImageFileSeek(struct gdispImageIO *pio, size_t pos) {
+ if (!pio->fd) return;
if (pio->pos != pos) {
- lseek((int)pio->fd, pos, SEEK_SET);
+ fseek((FILE *)pio->fd, pos, SEEK_SET);
pio->pos = pos;
}
}
- static void ImageSimulFileClose(struct gdispImageIO *pio) {
- if (pio->fd == (void *)-1) return;
- close((int)pio->fd);
- pio->fd = (void *)-1;
+ static void ImageFileClose(struct gdispImageIO *pio) {
+ if (!pio->fd) return;
+ fclose((FILE *)pio->fd);
+ pio->fd = 0;
pio->pos = 0;
}
- static const gdispImageIOFunctions ImageSimulFileFunctions =
- { ImageSimulFileRead, ImageSimulFileSeek, ImageSimulFileClose };
+ static const gdispImageIOFunctions ImageFileFunctions =
+ { ImageFileRead, ImageFileSeek, ImageFileClose };
- bool_t gdispImageSetSimulFileReader(gdispImage *img, const char *filename) {
- img->io.fns = &ImageSimulFileFunctions;
+ bool_t gdispImageSetFileReader(gdispImage *img, const char *filename) {
+ img->io.fns = &ImageFileFunctions;
img->io.pos = 0;
- img->io.fd = (void *)open(filename, O_RDONLY|O_BINARY);
- return img->io.fd != (void *)-1;
+ #if defined(WIN32) || GFX_USE_OS_WIN32
+ img->io.fd = (void *)fopen(filename, "rb");
+ #else
+ img->io.fd = (void *)fopen(filename, "r");
+ #endif
+
+ return img->io.fd != 0;
}
#endif
@@ -195,7 +200,7 @@ gdispImageError gdispImageDraw(gdispImage *img, coord_t x, coord_t y, coord_t cx
return img->fns->draw(img, x, y, cx, cy, sx, sy);
}
-systime_t gdispImageNext(gdispImage *img) {
+delaytime_t gdispImageNext(gdispImage *img) {
if (!img->fns) return GDISP_IMAGE_ERR_BADFORMAT;
return img->fns->next(img);
}
@@ -205,7 +210,7 @@ void *gdispImageAlloc(gdispImage *img, size_t sz) {
#if GDISP_NEED_IMAGE_ACCOUNTING
void *ptr;
- ptr = chHeapAlloc(NULL, sz);
+ ptr = gfxAlloc(sz);
if (ptr) {
img->memused += sz;
if (img->memused > img->maxmemused)
@@ -214,18 +219,18 @@ void *gdispImageAlloc(gdispImage *img, size_t sz) {
return ptr;
#else
(void) img;
- return chHeapAlloc(NULL, sz);
+ return gfxAlloc(sz);
#endif
}
void gdispImageFree(gdispImage *img, void *ptr, size_t sz) {
#if GDISP_NEED_IMAGE_ACCOUNTING
- chHeapFree(ptr);
+ gfxFree(ptr);
img->memused -= sz;
#else
(void) img;
(void) sz;
- chHeapFree(ptr);
+ gfxFree(ptr);
#endif
}
diff --git a/src/gdisp/image_bmp.c b/src/gdisp/image_bmp.c
index 830ee327..51d1ce91 100644
--- a/src/gdisp/image_bmp.c
+++ b/src/gdisp/image_bmp.c
@@ -12,8 +12,6 @@
* @defgroup Image Image
* @ingroup GDISP
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP && GDISP_NEED_IMAGE && GDISP_NEED_IMAGE_BMP
@@ -895,7 +893,7 @@ gdispImageError gdispImageDraw_BMP(gdispImage *img, coord_t x, coord_t y, coord_
return GDISP_IMAGE_ERR_OK;
}
-systime_t gdispImageNext_BMP(gdispImage *img) {
+delaytime_t gdispImageNext_BMP(gdispImage *img) {
(void) img;
/* No more frames/pages */
diff --git a/src/gdisp/image_gif.c b/src/gdisp/image_gif.c
index 6c61219a..e8f4f422 100644
--- a/src/gdisp/image_gif.c
+++ b/src/gdisp/image_gif.c
@@ -12,8 +12,6 @@
* @defgroup Image Image
* @ingroup GDISP
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP && GDISP_NEED_IMAGE && GDISP_NEED_IMAGE_GIF
@@ -1161,15 +1159,15 @@ baddatacleanup:
return GDISP_IMAGE_ERR_BADDATA;
}
-systime_t gdispImageNext_GIF(gdispImage *img) {
+delaytime_t gdispImageNext_GIF(gdispImage *img) {
gdispImagePrivate * priv;
- systime_t delay;
+ delaytime_t delay;
uint8_t blocksz;
priv = img->priv;
// Save the delay and convert to millisecs
- delay = (systime_t)priv->frame.delay * 10;
+ delay = (delaytime_t)priv->frame.delay * 10;
// We need to get to the end of this frame
if (!priv->frame.posend) {
diff --git a/src/gdisp/image_jpg.c b/src/gdisp/image_jpg.c
index 05c9ef37..3a51ea5f 100644
--- a/src/gdisp/image_jpg.c
+++ b/src/gdisp/image_jpg.c
@@ -9,8 +9,6 @@
* @file src/gdisp/image_jpg.c
* @brief GDISP native image code.
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP && GDISP_NEED_IMAGE && GDISP_NEED_IMAGE_JPG
diff --git a/src/gdisp/image_native.c b/src/gdisp/image_native.c
index 6da4e862..8cc15817 100644
--- a/src/gdisp/image_native.c
+++ b/src/gdisp/image_native.c
@@ -8,12 +8,7 @@
/**
* @file src/gdisp/image_native.c
* @brief GDISP native image code.
- *
- * @defgroup Image Image
- * @ingroup GDISP
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP && GDISP_NEED_IMAGE && GDISP_NEED_IMAGE_NATIVE
@@ -139,7 +134,7 @@ gdispImageError gdispImageDraw_NATIVE(gdispImage *img, coord_t x, coord_t y, coo
return GDISP_IMAGE_ERR_OK;
}
-systime_t gdispImageNext_NATIVE(gdispImage *img) {
+delaytime_t gdispImageNext_NATIVE(gdispImage *img) {
(void) img;
/* No more frames/pages */
diff --git a/src/gdisp/image_png.c b/src/gdisp/image_png.c
index 1cfba97f..76e8f652 100644
--- a/src/gdisp/image_png.c
+++ b/src/gdisp/image_png.c
@@ -8,12 +8,7 @@
/**
* @file src/gdisp/image_png.c
* @brief GDISP native image code.
- *
- * @defgroup Image Image
- * @ingroup GDISP
-*/
-#include "ch.h"
-#include "hal.h"
+ */
#include "gfx.h"
#if GFX_USE_GDISP && GDISP_NEED_IMAGE && GDISP_NEED_IMAGE_PNG
diff --git a/src/gevent/gevent.c b/src/gevent/gevent.c
index a8c7a63a..676fc8cb 100644
--- a/src/gevent/gevent.c
+++ b/src/gevent/gevent.c
@@ -12,8 +12,6 @@
* @addtogroup GEVENT
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GEVENT || defined(__DOXYGEN__)
@@ -25,7 +23,7 @@
#endif
/* This mutex protects access to our tables */
-static MUTEX_DECL(geventMutex);
+static gfxMutex geventMutex;
/* Our table of listener/source pairs */
static GSourceListener Assignments[GEVENT_MAX_SOURCE_LISTENERS];
@@ -37,22 +35,26 @@ static void deleteAssignments(GListener *pl, GSourceHandle gsh) {
for(psl = Assignments; psl < Assignments+GEVENT_MAX_SOURCE_LISTENERS; psl++) {
if ((!pl || psl->pListener == pl) && (!gsh || psl->pSource == gsh)) {
- if (chSemGetCounterI(&psl->pListener->waitqueue) < 0) {
- chBSemWait(&psl->pListener->eventlock); // Obtain the buffer lock
- psl->pListener->event.type = GEVENT_EXIT; // Set up the EXIT event
- chSemSignal(&psl->pListener->waitqueue); // Wake up the listener
- chBSemSignal(&psl->pListener->eventlock); // Release the buffer lock
+ if (gfxSemCounter(&psl->pListener->waitqueue) < 0) {
+ gfxSemWait(&psl->pListener->eventlock, TIME_INFINITE); // Obtain the buffer lock
+ psl->pListener->event.type = GEVENT_EXIT; // Set up the EXIT event
+ gfxSemSignal(&psl->pListener->waitqueue); // Wake up the listener
+ gfxSemSignal(&psl->pListener->eventlock); // Release the buffer lock
}
psl->pListener = 0;
}
}
}
+void _geventInit(void) {
+ gfxMutexInit(&geventMutex);
+}
+
void geventListenerInit(GListener *pl) {
- chSemInit(&pl->waitqueue, 0); // Next wait'er will block
- chBSemInit(&pl->eventlock, FALSE); // Only one thread at a time looking at the event buffer
- pl->callback = 0; // No callback active
- pl->event.type = GEVENT_NULL; // Always safety
+ gfxSemInit(&pl->waitqueue, 0, MAX_SEMAPHORE_COUNT); // Next wait'er will block
+ gfxSemInit(&pl->eventlock, 1, 1); // Only one thread at a time looking at the event buffer
+ pl->callback = 0; // No callback active
+ pl->event.type = GEVENT_NULL; // Always safety
}
bool_t geventAttachSource(GListener *pl, GSourceHandle gsh, unsigned flags) {
@@ -64,7 +66,7 @@ bool_t geventAttachSource(GListener *pl, GSourceHandle gsh, unsigned flags) {
return FALSE;
}
- chMtxLock(&geventMutex);
+ gfxMutexEnter(&geventMutex);
// Check if this pair is already in the table (scan for a free slot at the same time)
pslfree = 0;
@@ -72,10 +74,10 @@ bool_t geventAttachSource(GListener *pl, GSourceHandle gsh, unsigned flags) {
if (pl == psl->pListener && gsh == psl->pSource) {
// Just update the flags
- chBSemWait(&pl->eventlock); // Safety first - just in case a source is using it
+ gfxSemWait(&pl->eventlock, TIME_INFINITE); // Safety first - just in case a source is using it
psl->listenflags = flags;
- chBSemSignal(&pl->eventlock); // Release this lock
- chMtxUnlock();
+ gfxSemSignal(&pl->eventlock); // Release this lock
+ gfxMutexExit(&geventMutex);
return TRUE;
}
if (!pslfree && !psl->pListener)
@@ -89,43 +91,43 @@ bool_t geventAttachSource(GListener *pl, GSourceHandle gsh, unsigned flags) {
pslfree->listenflags = flags;
pslfree->srcflags = 0;
}
- chMtxUnlock();
+ gfxMutexExit(&geventMutex);
GEVENT_ASSERT(pslfree != 0);
return pslfree != 0;
}
void geventDetachSource(GListener *pl, GSourceHandle gsh) {
if (pl) {
- chMtxLock(&geventMutex);
+ gfxMutexEnter(&geventMutex);
deleteAssignments(pl, gsh);
- if (!gsh && chSemGetCounterI(&pl->waitqueue) < 0) {
- chBSemWait(&pl->eventlock); // Obtain the buffer lock
- pl->event.type = GEVENT_EXIT; // Set up the EXIT event
- chSemSignal(&pl->waitqueue); // Wake up the listener
- chBSemSignal(&pl->eventlock); // Release the buffer lock
+ if (!gsh && gfxSemCounter(&pl->waitqueue) < 0) {
+ gfxSemWait(&pl->eventlock, TIME_INFINITE); // Obtain the buffer lock
+ pl->event.type = GEVENT_EXIT; // Set up the EXIT event
+ gfxSemSignal(&pl->waitqueue); // Wake up the listener
+ gfxSemSignal(&pl->eventlock); // Release the buffer lock
}
- chMtxUnlock();
+ gfxMutexExit(&geventMutex);
}
}
-GEvent *geventEventWait(GListener *pl, systime_t timeout) {
- if (pl->callback || chSemGetCounterI(&pl->waitqueue) < 0)
+GEvent *geventEventWait(GListener *pl, delaytime_t timeout) {
+ if (pl->callback || gfxSemCounter(&pl->waitqueue) < 0)
return 0;
- return chSemWaitTimeout(&pl->waitqueue, timeout) == RDY_OK ? &pl->event : 0;
+ return gfxSemWait(&pl->waitqueue, timeout) ? &pl->event : 0;
}
void geventRegisterCallback(GListener *pl, GEventCallbackFn fn, void *param) {
if (pl) {
- chMtxLock(&geventMutex);
- chBSemWait(&pl->eventlock); // Obtain the buffer lock
- pl->param = param; // Set the param
- pl->callback = fn; // Set the callback function
- if (chSemGetCounterI(&pl->waitqueue) < 0) {
+ gfxMutexEnter(&geventMutex);
+ gfxSemWait(&pl->eventlock, TIME_INFINITE); // Obtain the buffer lock
+ pl->param = param; // Set the param
+ pl->callback = fn; // Set the callback function
+ if (gfxSemCounter(&pl->waitqueue) < 0) {
pl->event.type = GEVENT_EXIT; // Set up the EXIT event
- chSemSignal(&pl->waitqueue); // Wake up the listener
+ gfxSemSignal(&pl->waitqueue); // Wake up the listener
}
- chBSemSignal(&pl->eventlock); // Release the buffer lock
- chMtxUnlock();
+ gfxSemSignal(&pl->eventlock); // Release the buffer lock
+ gfxMutexExit(&geventMutex);
}
}
@@ -136,48 +138,48 @@ GSourceListener *geventGetSourceListener(GSourceHandle gsh, GSourceListener *las
if (!gsh)
return 0;
- chMtxLock(&geventMutex);
+ gfxMutexEnter(&geventMutex);
// Unlock the last listener event buffer
if (lastlr)
- chBSemSignal(&lastlr->pListener->eventlock);
+ gfxSemSignal(&lastlr->pListener->eventlock);
// Loop through the table looking for attachments to this source
for(psl = lastlr ? (lastlr+1) : Assignments; psl < Assignments+GEVENT_MAX_SOURCE_LISTENERS; psl++) {
if (gsh == psl->pSource) {
- chBSemWait(&psl->pListener->eventlock); // Obtain a lock on the listener event buffer
- chMtxUnlock();
+ gfxSemWait(&psl->pListener->eventlock, TIME_INFINITE); // Obtain a lock on the listener event buffer
+ gfxMutexExit(&geventMutex);
return psl;
}
}
- chMtxUnlock();
+ gfxMutexExit(&geventMutex);
return 0;
}
GEvent *geventGetEventBuffer(GSourceListener *psl) {
// We already know we have the event lock
- return &psl->pListener->callback || chSemGetCounterI(&psl->pListener->waitqueue) < 0 ? &psl->pListener->event : 0;
+ return &psl->pListener->callback || gfxSemCounter(&psl->pListener->waitqueue) < 0 ? &psl->pListener->event : 0;
}
void geventSendEvent(GSourceListener *psl) {
- chMtxLock(&geventMutex);
+ gfxMutexEnter(&geventMutex);
if (psl->pListener->callback) { // This test needs to be taken inside the mutex
- chMtxUnlock();
+ gfxMutexExit(&geventMutex);
// We already know we have the event lock
psl->pListener->callback(psl->pListener->param, &psl->pListener->event);
} else {
// Wake up the listener
- if (chSemGetCounterI(&psl->pListener->waitqueue) < 0)
- chSemSignal(&psl->pListener->waitqueue);
- chMtxUnlock();
+ if (gfxSemCounter(&psl->pListener->waitqueue) < 0)
+ gfxSemSignal(&psl->pListener->waitqueue);
+ gfxMutexExit(&geventMutex);
}
}
void geventDetachSourceListeners(GSourceHandle gsh) {
- chMtxLock(&geventMutex);
+ gfxMutexEnter(&geventMutex);
deleteAssignments(0, gsh);
- chMtxUnlock();
+ gfxMutexExit(&geventMutex);
}
#endif /* GFX_USE_GEVENT */
diff --git a/src/gfx.c b/src/gfx.c
new file mode 100644
index 00000000..c14dffb0
--- /dev/null
+++ b/src/gfx.c
@@ -0,0 +1,107 @@
+/*
+ ChibiOS/GFX - Copyright (C) 2012, 2013
+ 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/>.
+*/
+
+/**
+ * @file src/gfx.c
+ * @brief GFX common routines.
+ */
+
+/* Display various warnings from gfx_rules.h */
+#define GFX_DISPLAY_RULE_WARNINGS TRUE
+
+#include "gfx.h"
+
+/* These init functions are defined by each module but not published */
+extern void _gosInit(void);
+#if GFX_USE_GDISP && (GDISP_NEED_MULTITHREAD || GDISP_NEED_ASYNC)
+ extern void _gdispInit(void);
+#endif
+#if GFX_USE_TDISP
+ extern void _tdispInit(void);
+#endif
+#if GFX_USE_GWIN
+ extern void _gwinInit(void);
+#endif
+#if GFX_USE_GEVENT
+ extern void _geventInit(void);
+#endif
+#if GFX_USE_GTIMER
+ extern void _gtimerInit(void);
+#endif
+#if GFX_USE_GINPUT
+ extern void _ginputInit(void);
+#endif
+#if GFX_USE_GADC
+ extern void _gadcInit(void);
+#endif
+#if GFX_USE_GAUDIN
+ extern void _gaudinInit(void);
+#endif
+#if GFX_USE_GAUDOUT
+ extern void _gaudoutInit(void);
+#endif
+#if GFX_USE_GMISC
+ extern void _gmiscInit(void);
+#endif
+
+void gfxInit(void) {
+ static bool_t initDone = FALSE;
+
+ /* Ensure we only initialise once */
+ if (initDone)
+ return;
+ initDone = TRUE;
+
+ /* These must be initialised in the order of their dependancies */
+ _gosInit();
+ #if GFX_USE_GMISC
+ _gmiscInit();
+ #endif
+ #if GFX_USE_GEVENT
+ _geventInit();
+ #endif
+ #if GFX_USE_GTIMER
+ _gtimerInit();
+ #endif
+ #if GFX_USE_GDISP
+ _gdispInit();
+ gdispClear(Black);
+ #endif
+ #if GFX_USE_GWIN
+ _gwinInit();
+ #endif
+ #if GFX_USE_GINPUT
+ _ginputInit();
+ #endif
+ #if GFX_USE_TDISP
+ _tdispInit();
+ tdispHome();
+ tdispClear();
+ #endif
+ #if GFX_USE_GADC
+ _gadcInit();
+ #endif
+ #if GFX_USE_GAUDIN
+ _gaudinInit();
+ #endif
+ #if GFX_USE_GAUDOUT
+ _gaudoutInit();
+ #endif
+}
diff --git a/src/ginput/dial.c b/src/ginput/dial.c
index c8bc7d0f..24836910 100644
--- a/src/ginput/dial.c
+++ b/src/ginput/dial.c
@@ -13,8 +13,6 @@
* @ingroup GINPUT
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GINPUT && GINPUT_NEED_DIAL
diff --git a/src/ginput/ginput.c b/src/ginput/ginput.c
new file mode 100644
index 00000000..96fa1449
--- /dev/null
+++ b/src/ginput/ginput.c
@@ -0,0 +1,26 @@
+/*
+ * This file is subject to the terms of the GFX License, v1.0. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://chibios-gfx.com/license.html
+ */
+
+/**
+ * @file src/ginput/ginput.c
+ * @brief GINPUT subsystem common code.
+ *
+ * @addtogroup GINPUT
+ * @{
+ */
+#include "gfx.h"
+
+#if GFX_USE_GINPUT
+
+/**
+ * This should really call an init routine for each ginput sub-system.
+ * Maybe we'll do this later.
+ */
+void _ginputInit(void) {}
+
+#endif /* GFX_USE_GINPUT */
+/** @} */
diff --git a/src/ginput/ginput.mk b/src/ginput/ginput.mk
index 06bcfc07..ed34d46d 100644
--- a/src/ginput/ginput.mk
+++ b/src/ginput/ginput.mk
@@ -1,4 +1,5 @@
-GFXSRC += $(GFXLIB)/src/ginput/mouse.c \
+GFXSRC += $(GFXLIB)/src/ginput/ginput.c \
+ $(GFXLIB)/src/ginput/mouse.c \
$(GFXLIB)/src/ginput/keyboard.c \
$(GFXLIB)/src/ginput/toggle.c \
$(GFXLIB)/src/ginput/dial.c
diff --git a/src/ginput/keyboard.c b/src/ginput/keyboard.c
index 26d90ba9..99aa90e8 100644
--- a/src/ginput/keyboard.c
+++ b/src/ginput/keyboard.c
@@ -1,9 +1,9 @@
-/*
- * This file is subject to the terms of the GFX License, v1.0. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://chibios-gfx.com/license.html
- */
+/*
+ * This file is subject to the terms of the GFX License, v1.0. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://chibios-gfx.com/license.html
+ */
/**
* @file src/ginput/keyboard.c
@@ -15,8 +15,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if (GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD) || defined(__DOXYGEN__)
diff --git a/src/ginput/mouse.c b/src/ginput/mouse.c
index 7320cf2d..334fdb6c 100644
--- a/src/ginput/mouse.c
+++ b/src/ginput/mouse.c
@@ -13,8 +13,6 @@
* @ingroup GINPUT
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) || defined(__DOXYGEN__)
@@ -58,7 +56,7 @@ static struct MouseConfig_t {
MouseReading t;
MousePoint movepos;
MousePoint clickpos;
- systime_t clicktime;
+ systemticks_t clicktime;
uint16_t last_buttons;
uint16_t flags;
#define FLG_INIT_DONE 0x8000
@@ -253,7 +251,7 @@ static void MousePoll(void *param) {
if ((tbtns & (GINPUT_MOUSE_BTN_LEFT|GINPUT_MOUSE_BTN_RIGHT))) {
MouseConfig.clickpos.x = MouseConfig.t.x;
MouseConfig.clickpos.y = MouseConfig.t.y;
- MouseConfig.clicktime = chTimeNow();
+ MouseConfig.clicktime = gfxSystemTicks();
MouseConfig.flags |= FLG_CLICK_TIMER;
}
@@ -265,7 +263,7 @@ static void MousePoll(void *param) {
if ((MouseConfig.flags & FLG_CLICK_TIMER)) {
if ((tbtns & GINPUT_MOUSE_BTN_LEFT)
#if GINPUT_MOUSE_CLICK_TIME != TIME_INFINITE
- && chTimeNow() - MouseConfig.clicktime < MS2ST(GINPUT_MOUSE_CLICK_TIME)
+ && gfxSystemTicks() - MouseConfig.clicktime < gfxMillisecondsToTicks(GINPUT_MOUSE_CLICK_TIME)
#endif
)
meta |= GMETA_MOUSE_CLICK;
@@ -338,7 +336,7 @@ GSourceHandle ginputGetMouse(uint16_t instance) {
MouseConfig.caldata = pc[0];
MouseConfig.flags |= (FLG_CAL_OK|FLG_CAL_SAVED);
if ((MouseConfig.flags & FLG_CAL_FREE))
- chHeapFree((void *)pc);
+ gfxFree((void *)pc);
} else if (instance == 9999) {
MouseConfig.caldata.ax = 1;
MouseConfig.caldata.bx = 0;
@@ -367,7 +365,7 @@ GSourceHandle ginputGetMouse(uint16_t instance) {
bool_t ginputGetMouseStatus(uint16_t instance, GEventMouse *pe) {
// Win32 threads don't seem to recognise priority and/or pre-emption
// so we add a sleep here to prevent 100% polled applications from locking up.
- chThdSleepMilliseconds(1);
+ gfxSleepMilliseconds(1);
if (instance || (MouseConfig.flags & (FLG_INIT_DONE|FLG_IN_CAL)) != FLG_INIT_DONE)
return FALSE;
@@ -443,11 +441,11 @@ bool_t ginputCalibrateMouse(uint16_t instance) {
/* Wait for the mouse to be pressed */
while(get_raw_reading(&MouseConfig.t), !(MouseConfig.t.buttons & GINPUT_MOUSE_BTN_LEFT))
- chThdSleepMilliseconds(20);
+ gfxSleepMilliseconds(20);
/* Average all the samples while the mouse is down */
for(px = py = 0, j = 0;
- chThdSleepMilliseconds(20), /* Settling time between readings */
+ gfxSleepMilliseconds(20), /* Settling time between readings */
get_raw_reading(&MouseConfig.t),
(MouseConfig.t.buttons & GINPUT_MOUSE_BTN_LEFT);
j++) {
@@ -464,7 +462,7 @@ bool_t ginputCalibrateMouse(uint16_t instance) {
if (i >= 1 && pt->x == (pt-1)->x && pt->y == (pt-1)->y) {
gdispFillStringBox(0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_SAME_TEXT, font2, Red, Yellow, justifyCenter);
- chThdSleepMilliseconds(5000);
+ gfxSleepMilliseconds(5000);
gdispFillArea(0, 35, width, 40, Blue);
}
@@ -492,7 +490,7 @@ bool_t ginputCalibrateMouse(uint16_t instance) {
break;
gdispFillStringBox(0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_ERROR_TEXT, font2, Red, Yellow, justifyCenter);
- chThdSleepMilliseconds(5000);
+ gfxSleepMilliseconds(5000);
}
#endif
diff --git a/src/ginput/toggle.c b/src/ginput/toggle.c
index a2474c3e..2784a6ef 100644
--- a/src/ginput/toggle.c
+++ b/src/ginput/toggle.c
@@ -1,9 +1,9 @@
-/*
- * This file is subject to the terms of the GFX License, v1.0. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://chibios-gfx.com/license.html
- */
+/*
+ * This file is subject to the terms of the GFX License, v1.0. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://chibios-gfx.com/license.html
+ */
/**
* @file src/ginput/toggle.c
@@ -13,8 +13,6 @@
* @ingroup GINPUT
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if (GFX_USE_GINPUT && GINPUT_NEED_TOGGLE) || defined(__DOXYGEN__)
@@ -134,7 +132,7 @@ void ginputInvertToggle(uint16_t instance, bool_t invert) {
bool_t ginputGetToggleStatus(uint16_t instance, GEventToggle *ptoggle) {
// Win32 threads don't seem to recognise priority and/or pre-emption
// so we add a sleep here to prevent 100% polled applications from locking up.
- chThdSleepMilliseconds(1);
+ gfxSleepMilliseconds(1);
if (instance >= GINPUT_TOGGLE_NUM_PORTS)
return FALSE;
diff --git a/src/gmisc/arrayops.c b/src/gmisc/arrayops.c
index e5f06072..460387f6 100644
--- a/src/gmisc/arrayops.c
+++ b/src/gmisc/arrayops.c
@@ -1,9 +1,9 @@
-/*
- * This file is subject to the terms of the GFX License, v1.0. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://chibios-gfx.com/license.html
- */
+/*
+ * This file is subject to the terms of the GFX License, v1.0. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://chibios-gfx.com/license.html
+ */
/**
* @file src/gmisc/arrayops.c
@@ -12,11 +12,9 @@
* @addtogroup GMISC
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
-#if (GFX_USE_GMISC && GMISC_NEED_ARRAYOPS) || defined(__DOXYGEN__)
+#if GFX_USE_GMISC && GMISC_NEED_ARRAYOPS
void gmiscArrayConvert(ArrayDataFormat srcfmt, void *src, ArrayDataFormat dstfmt, void *dst, size_t cnt) {
uint8_t *src8, *dst8;
diff --git a/src/gmisc/gmisc.mk b/src/gmisc/gmisc.mk
index 7e4caea8..a4ec787e 100644
--- a/src/gmisc/gmisc.mk
+++ b/src/gmisc/gmisc.mk
@@ -1 +1,2 @@
-GFXSRC += $(GFXLIB)/src/gmisc/arrayops.c
+GFXSRC += $(GFXLIB)/src/gmisc/arrayops.c \
+ $(GFXLIB)/src/gmisc/trig.c
diff --git a/src/gmisc/trig.c b/src/gmisc/trig.c
new file mode 100644
index 00000000..2cd90a53
--- /dev/null
+++ b/src/gmisc/trig.c
@@ -0,0 +1,159 @@
+/*
+ ChibiOS/GFX - Copyright (C) 2012, 2013
+ 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/>.
+*/
+
+/**
+ * @file src/gmisc/trig.c
+ * @brief GMISC Trig Functions.
+ *
+ * @addtogroup GMISC
+ * @{
+ */
+#include "gfx.h"
+
+#if GFX_USE_GMISC
+
+#if GMISC_NEED_FASTTRIG
+ const double sintabledouble[] = {
+ 0.000000, 0.017452, 0.034899, 0.052336, 0.069756, 0.087156, 0.104528, 0.121869,
+ 0.139173, 0.156434, 0.173648, 0.190809, 0.207912, 0.224951, 0.241922, 0.258819,
+ 0.275637, 0.292372, 0.309017, 0.325568, 0.342020, 0.358368, 0.374607, 0.390731,
+ 0.406737, 0.422618, 0.438371, 0.453990, 0.469472, 0.484810, 0.500000, 0.515038,
+ 0.529919, 0.544639, 0.559193, 0.573576, 0.587785, 0.601815, 0.615661, 0.629320,
+ 0.642788, 0.656059, 0.669131, 0.681998, 0.694658, 0.707107, 0.719340, 0.731354,
+ 0.743145, 0.754710, 0.766044, 0.777146, 0.788011, 0.798636, 0.809017, 0.819152,
+ 0.829038, 0.838671, 0.848048, 0.857167, 0.866025, 0.874620, 0.882948, 0.891007,
+ 0.898794, 0.906308, 0.913545, 0.920505, 0.927184, 0.933580, 0.939693, 0.945519,
+ 0.951057, 0.956305, 0.961262, 0.965926, 0.970296, 0.974370, 0.978148, 0.981627,
+ 0.984808, 0.987688, 0.990268, 0.992546, 0.994522, 0.996195, 0.997564, 0.998630,
+ 0.999391, 0.999848, 1.000000, 0.999848, 0.999391, 0.998630, 0.997564, 0.996195,
+ 0.994522, 0.992546, 0.990268, 0.987688, 0.984808, 0.981627, 0.978148, 0.974370,
+ 0.970296, 0.965926, 0.961262, 0.956305, 0.951057, 0.945519, 0.939693, 0.933580,
+ 0.927184, 0.920505, 0.913545, 0.906308, 0.898794, 0.891007, 0.882948, 0.874620,
+ 0.866025, 0.857167, 0.848048, 0.838671, 0.829038, 0.819152, 0.809017, 0.798636,
+ 0.788011, 0.777146, 0.766044, 0.754710, 0.743145, 0.731354, 0.719340, 0.707107,
+ 0.694658, 0.681998, 0.669131, 0.656059, 0.642788, 0.629320, 0.615661, 0.601815,
+ 0.587785, 0.573576, 0.559193, 0.544639, 0.529919, 0.515038, 0.500000, 0.484810,
+ 0.469472, 0.453990, 0.438371, 0.422618, 0.406737, 0.390731, 0.374607, 0.358368,
+ 0.342020, 0.325568, 0.309017, 0.292372, 0.275637, 0.258819, 0.241922, 0.224951,
+ 0.207912, 0.190809, 0.173648, 0.156434, 0.139173, 0.121869, 0.104528, 0.087156,
+ 0.069756, 0.052336, 0.034899, 0.017452, 0.000000, -0.017452, -0.034899, -0.052336,
+ -0.069756, -0.087156, -0.104528, -0.121869, -0.139173, -0.156434, -0.173648, -0.190809,
+ -0.207912, -0.224951, -0.241922, -0.258819, -0.275637, -0.292372, -0.309017, -0.325568,
+ -0.342020, -0.358368, -0.374607, -0.390731, -0.406737, -0.422618, -0.438371, -0.453990,
+ -0.469472, -0.484810, -0.500000, -0.515038, -0.529919, -0.544639, -0.559193, -0.573576,
+ -0.587785, -0.601815, -0.615661, -0.629320, -0.642788, -0.656059, -0.669131, -0.681998,
+ -0.694658, -0.707107, -0.719340, -0.731354, -0.743145, -0.754710, -0.766044, -0.777146,
+ -0.788011, -0.798636, -0.809017, -0.819152, -0.829038, -0.838671, -0.848048, -0.857167,
+ -0.866025, -0.874620, -0.882948, -0.891007, -0.898794, -0.906308, -0.913545, -0.920505,
+ -0.927184, -0.933580, -0.939693, -0.945519, -0.951057, -0.956305, -0.961262, -0.965926,
+ -0.970296, -0.974370, -0.978148, -0.981627, -0.984808, -0.987688, -0.990268, -0.992546,
+ -0.994522, -0.996195, -0.997564, -0.998630, -0.999391, -0.999848, -1.000000, -0.999848,
+ -0.999391, -0.998630, -0.997564, -0.996195, -0.994522, -0.992546, -0.990268, -0.987688,
+ -0.984808, -0.981627, -0.978148, -0.974370, -0.970296, -0.965926, -0.961262, -0.956305,
+ -0.951057, -0.945519, -0.939693, -0.933580, -0.927184, -0.920505, -0.913545, -0.906308,
+ -0.898794, -0.891007, -0.882948, -0.874620, -0.866025, -0.857167, -0.848048, -0.838671,
+ -0.829038, -0.819152, -0.809017, -0.798636, -0.788011, -0.777146, -0.766044, -0.754710,
+ -0.743145, -0.731354, -0.719340, -0.707107, -0.694658, -0.681998, -0.669131, -0.656059,
+ -0.642788, -0.629320, -0.615661, -0.601815, -0.587785, -0.573576, -0.559193, -0.544639,
+ -0.529919, -0.515038, -0.500000, -0.484810, -0.469472, -0.453990, -0.438371, -0.422618,
+ -0.406737, -0.390731, -0.374607, -0.358368, -0.342020, -0.325568, -0.309017, -0.292372,
+ -0.275637, -0.258819, -0.241922, -0.224951, -0.207912, -0.190809, -0.173648, -0.156434,
+ -0.139173, -0.121869, -0.104528, -0.087156, -0.069756, -0.052336, -0.034899, -0.017452
+ };
+
+ double fsin(int degrees) {
+ if (degrees < 0)
+ degrees -= (degrees/360-1)*360;
+ else if (degrees >= 360)
+ degrees %= 360;
+ return sintabledouble[degrees];
+ }
+
+ double fcos(int degrees) {
+ return fsin(degrees+90);
+ }
+
+#endif
+
+#if GMISC_NEED_FIXEDTRIG
+ const fixed sintablefixed[] = {
+ 0, 1143, 2287, 3429, 4571, 5711, 6850, 7986,
+ 9120, 10252, 11380, 12504, 13625, 14742, 15854, 16961,
+ 18064, 19160, 20251, 21336, 22414, 23486, 24550, 25606,
+ 26655, 27696, 28729, 29752, 30767, 31772, 32767, 33753,
+ 34728, 35693, 36647, 37589, 38521, 39440, 40347, 41243,
+ 42125, 42995, 43852, 44695, 45525, 46340, 47142, 47929,
+ 48702, 49460, 50203, 50931, 51643, 52339, 53019, 53683,
+ 54331, 54963, 55577, 56175, 56755, 57319, 57864, 58393,
+ 58903, 59395, 59870, 60326, 60763, 61183, 61583, 61965,
+ 62328, 62672, 62997, 63302, 63589, 63856, 64103, 64331,
+ 64540, 64729, 64898, 65047, 65176, 65286, 65376, 65446,
+ 65496, 65526, 65536, 65526, 65496, 65446, 65376, 65286,
+ 65176, 65047, 64898, 64729, 64540, 64331, 64103, 63856,
+ 63589, 63302, 62997, 62672, 62328, 61965, 61583, 61183,
+ 60763, 60326, 59870, 59395, 58903, 58393, 57864, 57319,
+ 56755, 56175, 55577, 54963, 54331, 53683, 53019, 52339,
+ 51643, 50931, 50203, 49460, 48702, 47929, 47142, 46340,
+ 45525, 44695, 43852, 42995, 42125, 41243, 40347, 39440,
+ 38521, 37589, 36647, 35693, 34728, 33753, 32767, 31772,
+ 30767, 29752, 28729, 27696, 26655, 25606, 24550, 23486,
+ 22414, 21336, 20251, 19160, 18064, 16961, 15854, 14742,
+ 13625, 12504, 11380, 10252, 9120, 7986, 6850, 5711,
+ 4571, 3429, 2287, 1143, 0, -1143, -2287, -3429,
+ -4571, -5711, -6850, -7986, -9120, -10252, -11380, -12504,
+ -13625, -14742, -15854, -16961, -18064, -19160, -20251, -21336,
+ -22414, -23486, -24550, -25606, -26655, -27696, -28729, -29752,
+ -30767, -31772, -32768, -33753, -34728, -35693, -36647, -37589,
+ -38521, -39440, -40347, -41243, -42125, -42995, -43852, -44695,
+ -45525, -46340, -47142, -47929, -48702, -49460, -50203, -50931,
+ -51643, -52339, -53019, -53683, -54331, -54963, -55577, -56175,
+ -56755, -57319, -57864, -58393, -58903, -59395, -59870, -60326,
+ -60763, -61183, -61583, -61965, -62328, -62672, -62997, -63302,
+ -63589, -63856, -64103, -64331, -64540, -64729, -64898, -65047,
+ -65176, -65286, -65376, -65446, -65496, -65526, -65536, -65526,
+ -65496, -65446, -65376, -65286, -65176, -65047, -64898, -64729,
+ -64540, -64331, -64103, -63856, -63589, -63302, -62997, -62672,
+ -62328, -61965, -61583, -61183, -60763, -60326, -59870, -59395,
+ -58903, -58393, -57864, -57319, -56755, -56175, -55577, -54963,
+ -54331, -53683, -53019, -52339, -51643, -50931, -50203, -49460,
+ -48702, -47929, -47142, -46340, -45525, -44695, -43852, -42995,
+ -42125, -41243, -40347, -39440, -38521, -37589, -36647, -35693,
+ -34728, -33753, -32768, -31772, -30767, -29752, -28729, -27696,
+ -26655, -25606, -24550, -23486, -22414, -21336, -20251, -19160,
+ -18064, -16961, -15854, -14742, -13625, -12504, -11380, -10252,
+ -9120, -7986, -6850, -5711, -4571, -3429, -2287, -1143
+ };
+
+ fixed ffsin(int degrees) {
+ if (degrees < 0)
+ degrees -= (degrees/360-1)*360;
+ else if (degrees >= 360)
+ degrees %= 360;
+ return sintablefixed[degrees];
+ }
+
+ fixed ffcos(int degrees) {
+ return ffsin(degrees+90);
+ }
+
+#endif
+
+#endif /* GFX_USE_GMISC */
+/** @} */
diff --git a/src/gos/chibios.c b/src/gos/chibios.c
new file mode 100644
index 00000000..6e63a2a4
--- /dev/null
+++ b/src/gos/chibios.c
@@ -0,0 +1,207 @@
+/*
+ ChibiOS/GFX - Copyright (C) 2012, 2013
+ 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/>.
+*/
+
+/**
+ * @file src/gos/chibios.c
+ * @brief GOS ChibiOS Operating System support.
+ */
+#include "gfx.h"
+
+#if GFX_USE_OS_CHIBIOS
+
+#if !CH_USE_MUTEXES
+ #error "GOS: CH_USE_MUTEXES must be defined in chconf.h"
+#endif
+#if !CH_USE_SEMAPHORES
+ #error "GOS: CH_USE_SEMAPHORES must be defined in chconf.h"
+#endif
+
+/* Our module initialiser */
+void _gosInit(void) {
+ /* Don't initialise if the user already has */
+ if (!chThdSelf()) {
+ halInit();
+ chSysInit();
+ }
+}
+
+void gfxSleepMilliseconds(delaytime_t ms) {
+ switch(ms) {
+ case TIME_IMMEDIATE: chThdYield(); return;
+ case TIME_INFINITE: chThdSleep(TIME_INFINITE); return;
+ default: chThdSleepMilliseconds(ms); return;
+ }
+}
+
+void gfxSleepMicroseconds(delaytime_t ms) {
+ switch(ms) {
+ case TIME_IMMEDIATE: return;
+ case TIME_INFINITE: chThdSleep(TIME_INFINITE); return;
+ default: chThdSleepMicroseconds(ms); return;
+ }
+}
+
+void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit) {
+ if (val > limit) val = limit;
+ psem->limit = limit;
+ chSemInit(&psem->sem, val);
+}
+
+bool_t gfxSemWait(gfxSem *psem, delaytime_t ms) {
+ if (ms == TIME_INFINITE) {
+ chSemWait(&psem->sem);
+ return TRUE;
+ }
+ return chSemWaitTimeout(&psem->sem, MS2ST(ms)) != RDY_TIMEOUT;
+}
+
+void gfxSemSignal(gfxSem *psem) {
+ chSysLock();
+ if (gfxSemCounterI(psem) < psem->limit)
+ chSemSignalI(&psem->sem);
+ chSchRescheduleS();
+ chSysUnlock();
+}
+
+void gfxSemSignalI(gfxSem *psem) {
+ if (gfxSemCounterI(psem) < psem->limit)
+ chSemSignalI(&psem->sem);
+}
+
+void gfxQueueInit(gfxQueue *pqueue) {
+ pqueue->head = pqueue->tail = 0;
+ chSemInit(&pqueue->sem, 0);
+}
+
+gfxQueueItem * gfxQueueGet(gfxQueue *pqueue, delaytime_t ms) {
+ gfxQueueItem *pi;
+
+ chSysLock();
+ /* If someone else is waiting or if the queue is empty - wait ourselves */
+ if (pqueue->sem.s_cnt < 0 || !pqueue->head) {
+ if (chSemWaitTimeoutS(&pqueue->sem, ms == TIME_INFINITE ? TIME_INFINITE : MS2ST(ms)) == RDY_TIMEOUT) {
+ chSysUnlock();
+ return NULL;
+ }
+ }
+ /* We can now get the head element */
+ pi = pqueue->head;
+ pqueue->head = pi;
+ chSemSignalI(&pi->sem);
+ chSysUnlock();
+ return pi;
+}
+
+bool_t gfxQueuePut(gfxQueue *pqueue, gfxQueueItem *pitem, delaytime_t ms) {
+ chSemInit(&pitem->sem, 0);
+ chSysLock();
+ pitem->next = 0;
+ if (!pqueue->head) {
+ pqueue->head = pqueue->tail = pitem;
+ } else {
+ pqueue->tail->next = pitem;
+ pqueue->tail = pitem;
+ }
+ /* Wake up someone who is waiting */
+ if (chSemGetCounterI(&pqueue->sem) < 0)
+ chSemSignalI(&pqueue->sem);
+ chSysUnlock();
+ return chSemWaitTimeout(&pitem->sem, ms == TIME_INFINITE ? TIME_INFINITE : MS2ST(ms)) != RDY_TIMEOUT;
+}
+
+bool_t gfxQueuePush(gfxQueue *pqueue, gfxQueueItem *pitem, delaytime_t ms) {
+ chSemInit(&pitem->sem, 0);
+ chSysLock();
+ pitem->next = pqueue->head;
+ pqueue->head = pitem;
+ if (!pitem->next)
+ pqueue->tail = pitem;
+ /* Wake up someone who is waiting */
+ if (chSemGetCounterI(&pqueue->sem) < 0)
+ chSemSignalI(&pqueue->sem);
+ chSysUnlock();
+ return chSemWaitTimeout(&pitem->sem, ms == TIME_INFINITE ? TIME_INFINITE : MS2ST(ms)) != RDY_TIMEOUT;
+}
+
+void gfxQueueRemove(gfxQueue *pqueue, gfxQueueItem *pitem) {
+ gfxQueueItem *pi;
+
+ chSysLock();
+ if (pqueue->head) {
+ if (pqueue->head == pitem) {
+ pqueue->head = pitem->next;
+ chSemSignalI(&pitem->sem);
+ } else {
+ for(pi = pqueue->head; pi->next; pi = pi->next) {
+ if (pi->next == pitem) {
+ pi->next = pitem->next;
+ if (pqueue->tail == pitem)
+ pqueue->tail = pi;
+ chSemSignalI(&pitem->sem);
+ break;
+ }
+ }
+ }
+ }
+ chSysUnlock();
+}
+
+bool_t gfxQueueIsEmpty(gfxQueue *pqueue) {
+ return pqueue->head == NULL;
+}
+
+bool_t gfxQueueIsIn(gfxQueue *pqueue, gfxQueueItem *pitem) {
+ gfxQueueItem *pi;
+
+ chSysLock();
+ for(pi = pqueue->head; pi; pi = pi->next) {
+ if (pi == pitem) {
+ chSysUnlock();
+ return TRUE;
+ }
+ }
+ chSysUnlock();
+ return FALSE;
+}
+
+/**
+ * @brief Start a new thread.
+ * @return Return TRUE if the thread was started, FALSE on an error
+ *
+ * @param[in] stackarea A pointer to the area for the new threads stack or NULL to dynamically allocate it
+ * @param[in] stacksz The size of the thread stack. 0 means the default operating system size although this
+ * is only valid when stackarea is dynamically allocated.
+ * @param[in] prio The priority of the new thread
+ * @param[in] fn The function the new thread will run
+ * @param[in] param A parameter to pass the thread function.
+ *
+ * @api
+ */
+bool_t gfxCreateThread(void *stackarea, size_t stacksz, threadpriority_t prio, gfxThreadFunction fn, void *param) {
+ if (!stackarea) {
+ if (!stacksz) stacksz = 256;
+ return chThdCreateFromHeap(0, stacksz, prio, fn, param) != 0;
+ }
+
+ return stacksz && chThdCreateStatic(stackarea, stacksz, prio, fn, param) != NULL;
+}
+
+#endif /* GFX_USE_OS_CHIBIOS */
+/** @} */
diff --git a/src/gos/gos.mk b/src/gos/gos.mk
new file mode 100644
index 00000000..d963eea8
--- /dev/null
+++ b/src/gos/gos.mk
@@ -0,0 +1,3 @@
+GFXSRC += $(GFXLIB)/src/gos/chibios.c \
+ $(GFXLIB)/src/gos/win32.c \
+ $(GFXLIB)/src/gos/posix.c
diff --git a/src/gos/posix.c b/src/gos/posix.c
new file mode 100644
index 00000000..9f6fe430
--- /dev/null
+++ b/src/gos/posix.c
@@ -0,0 +1,32 @@
+/*
+ ChibiOS/GFX - Copyright (C) 2012, 2013
+ 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/>.
+*/
+
+/**
+ * @file src/gos/chibios.c
+ * @brief GOS ChibiOS Operating System support.
+ */
+#include "gfx.h"
+
+#if GFX_USE_OS_POSIX
+
+#error "GOS: POSIX not supported yet"
+
+#endif /* GFX_USE_OS_POSIX */
+/** @} */
diff --git a/src/gos/win32.c b/src/gos/win32.c
new file mode 100644
index 00000000..6cf803a2
--- /dev/null
+++ b/src/gos/win32.c
@@ -0,0 +1,32 @@
+/*
+ ChibiOS/GFX - Copyright (C) 2012, 2013
+ 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/>.
+*/
+
+/**
+ * @file src/gos/chibios.c
+ * @brief GOS ChibiOS Operating System support.
+ */
+#include "gfx.h"
+
+#if GFX_USE_OS_WIN32
+
+#error "GOS: WIN32 not supported yet"
+
+#endif /* GFX_USE_OS_WIN32 */
+/** @} */
diff --git a/src/gtimer/gtimer.c b/src/gtimer/gtimer.c
index 8d9fc073..366ca4a9 100644
--- a/src/gtimer/gtimer.c
+++ b/src/gtimer/gtimer.c
@@ -1,9 +1,9 @@
-/*
- * This file is subject to the terms of the GFX License, v1.0. If a copy of
- * the license was not distributed with this file, you can obtain one at:
- *
- * http://chibios-gfx.com/license.html
- */
+/*
+ * This file is subject to the terms of the GFX License, v1.0. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://chibios-gfx.com/license.html
+ */
/**
* @file src/gtimer/gtimer.c
@@ -12,16 +12,10 @@
* @addtogroup GTIMER
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GTIMER || defined(__DOXYGEN__)
-#if !CH_USE_MUTEXES || !CH_USE_SEMAPHORES
- #error "GTIMER: CH_USE_MUTEXES and CH_USE_SEMAPHORES must be defined in chconf.h"
-#endif
-
#define GTIMER_FLG_PERIODIC 0x0001
#define GTIMER_FLG_INFINITE 0x0002
#define GTIMER_FLG_JABBED 0x0004
@@ -31,44 +25,40 @@
#define TimeIsWithin(x, start, end) ((end >= start && x >= start && x <= end) || (end < start && (x >= start || x <= end)))
/* This mutex protects access to our tables */
-static MUTEX_DECL(mutex);
-static Thread *pThread = 0;
+static gfxMutex mutex;
+static bool_t haveThread = 0;
static GTimer *pTimerHead = 0;
-static BSEMAPHORE_DECL(waitsem, TRUE);
-static WORKING_AREA(waTimerThread, GTIMER_THREAD_WORKAREA_SIZE);
+static gfxSem waitsem;
+static DECLARESTACK(waTimerThread, GTIMER_THREAD_WORKAREA_SIZE);
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
-static msg_t GTimerThreadHandler(void *arg) {
+static threadreturn_t GTimerThreadHandler(void *arg) {
(void)arg;
GTimer *pt;
- systime_t tm;
- systime_t nxtTimeout;
- systime_t lastTime;
+ systemticks_t tm;
+ systemticks_t nxtTimeout;
+ systemticks_t lastTime;
GTimerFunction fn;
void *param;
- #if CH_USE_REGISTRY
- chRegSetThreadName("GTimer");
- #endif
-
nxtTimeout = TIME_INFINITE;
lastTime = 0;
while(1) {
/* Wait for work to do. */
- chThdYield(); // Give someone else a go no matter how busy we are
- chBSemWaitTimeout(&waitsem, nxtTimeout);
+ gfxYield(); // Give someone else a go no matter how busy we are
+ gfxSemWait(&waitsem, nxtTimeout);
restartTimerChecks:
// Our reference time
- tm = chTimeNow();
+ tm = gfxSystemTicks();
nxtTimeout = TIME_INFINITE;
/* We need to obtain the mutex */
- chMtxLock(&mutex);
+ gfxMutexEnter(&mutex);
if (pTimerHead) {
pt = pTimerHead;
@@ -106,7 +96,7 @@ static msg_t GTimerThreadHandler(void *arg) {
// Call the callback function
fn = pt->fn;
param = pt->param;
- chMtxUnlock();
+ gfxMutexExit(&mutex);
fn(param);
// We no longer hold the mutex, the callback function may have taken a while
@@ -123,21 +113,26 @@ static msg_t GTimerThreadHandler(void *arg) {
// Ready for the next loop
lastTime = tm;
- chMtxUnlock();
+ gfxMutexExit(&mutex);
}
return 0;
}
+void _gtimerInit(void) {
+ gfxSemInit(&waitsem, 0, 1);
+ gfxMutexInit(&mutex);
+}
+
void gtimerInit(GTimer *pt) {
pt->flags = 0;
}
-void gtimerStart(GTimer *pt, GTimerFunction fn, void *param, bool_t periodic, systime_t millisec) {
- chMtxLock(&mutex);
+void gtimerStart(GTimer *pt, GTimerFunction fn, void *param, bool_t periodic, delaytime_t millisec) {
+ gfxMutexEnter(&mutex);
// Start our thread if not already going
- if (!pThread)
- pThread = chThdCreateStatic(waTimerThread, sizeof(waTimerThread), HIGHPRIO, GTimerThreadHandler, NULL);
+ if (!haveThread)
+ haveThread = gfxCreateThread(waTimerThread, sizeof(waTimerThread), HIGH_PRIORITY, GTimerThreadHandler, NULL);
// Is this already scheduled?
if (pt->flags & GTIMER_FLG_SCHEDULED) {
@@ -162,8 +157,8 @@ void gtimerStart(GTimer *pt, GTimerFunction fn, void *param, bool_t periodic, sy
pt->flags |= GTIMER_FLG_INFINITE;
pt->period = TIME_INFINITE;
} else {
- pt->period = MS2ST(millisec);
- pt->when = chTimeNow() + pt->period;
+ pt->period = gfxMillisecondsToTicks(millisec);
+ pt->when = gfxSystemTicks() + pt->period;
}
// Just pop it on the end of the queue
@@ -177,12 +172,12 @@ void gtimerStart(GTimer *pt, GTimerFunction fn, void *param, bool_t periodic, sy
// Bump the thread
if (!(pt->flags & GTIMER_FLG_INFINITE))
- chBSemSignal(&waitsem);
- chMtxUnlock();
+ gfxSemSignal(&waitsem);
+ gfxMutexExit(&mutex);
}
void gtimerStop(GTimer *pt) {
- chMtxLock(&mutex);
+ gfxMutexEnter(&mutex);
if (pt->flags & GTIMER_FLG_SCHEDULED) {
// Cancel it!
if (pt->next == pt->prev)
@@ -196,7 +191,7 @@ void gtimerStop(GTimer *pt) {
// Make sure we know the structure is dead!
pt->flags = 0;
}
- chMtxUnlock();
+ gfxMutexExit(&mutex);
}
bool_t gtimerIsActive(GTimer *pt) {
@@ -204,14 +199,14 @@ bool_t gtimerIsActive(GTimer *pt) {
}
void gtimerJab(GTimer *pt) {
- chMtxLock(&mutex);
+ gfxMutexEnter(&mutex);
// Jab it!
pt->flags |= GTIMER_FLG_JABBED;
// Bump the thread
- chBSemSignal(&waitsem);
- chMtxUnlock();
+ gfxSemSignal(&waitsem);
+ gfxMutexExit(&mutex);
}
void gtimerJabI(GTimer *pt) {
@@ -219,7 +214,7 @@ void gtimerJabI(GTimer *pt) {
pt->flags |= GTIMER_FLG_JABBED;
// Bump the thread
- chBSemSignalI(&waitsem);
+ gfxSemSignalI(&waitsem);
}
#endif /* GFX_USE_GTIMER */
diff --git a/src/gwin/button.c b/src/gwin/button.c
index 8d77b8ba..19301698 100644
--- a/src/gwin/button.c
+++ b/src/gwin/button.c
@@ -15,8 +15,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if (GFX_USE_GWIN && GWIN_NEED_BUTTON) || defined(__DOXYGEN__)
@@ -204,7 +202,7 @@ void gwinSetButtonText(GHandle gh, const char *txt, bool_t useAlloc) {
if ((gh->flags & GBTN_FLG_ALLOCTXT)) {
gh->flags &= ~GBTN_FLG_ALLOCTXT;
if (gbw->txt) {
- chHeapFree((void *)gbw->txt);
+ gfxFree((void *)gbw->txt);
gbw->txt = "";
}
}
@@ -212,7 +210,7 @@ void gwinSetButtonText(GHandle gh, const char *txt, bool_t useAlloc) {
if (txt && useAlloc) {
char *str;
- if ((str = (char *)chHeapAlloc(NULL, strlen(txt)+1))) {
+ if ((str = (char *)gfxAlloc(strlen(txt)+1))) {
gh->flags |= GBTN_FLG_ALLOCTXT;
strcpy(str, txt);
}
diff --git a/src/gwin/console.c b/src/gwin/console.c
index 6abb18dc..a01ed79d 100644
--- a/src/gwin/console.c
+++ b/src/gwin/console.c
@@ -15,8 +15,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if (GFX_USE_GWIN && GWIN_NEED_CONSOLE) || defined(__DOXYGEN__)
@@ -32,48 +30,54 @@
* Stream interface implementation. The interface is write only
*/
-#define Stream2GWindow(ip) ((GHandle)(((char *)(ip)) - (size_t)(&(((GConsoleObject *)0)->stream))))
-
-static size_t GWinStreamWrite(void *ip, const uint8_t *bp, size_t n) { gwinPutCharArray(Stream2GWindow(ip), (const char *)bp, n); return RDY_OK; }
-static size_t GWinStreamRead(void *ip, uint8_t *bp, size_t n) { (void)ip; (void)bp; (void)n; return 0; }
-static msg_t GWinStreamPut(void *ip, uint8_t b) { gwinPutChar(Stream2GWindow(ip), (char)b); return RDY_OK; }
-static msg_t GWinStreamGet(void *ip) {(void)ip; return RDY_OK; }
-static msg_t GWinStreamPutTimed(void *ip, uint8_t b, systime_t time) { (void)time; gwinPutChar(Stream2GWindow(ip), (char)b); return RDY_OK; }
-static msg_t GWinStreamGetTimed(void *ip, systime_t timeout) { (void)ip; (void)timeout; return RDY_OK; }
-static size_t GWinStreamWriteTimed(void *ip, const uint8_t *bp, size_t n, systime_t time) { (void)time; gwinPutCharArray(Stream2GWindow(ip), (const char *)bp, n); return RDY_OK; }
-static size_t GWinStreamReadTimed(void *ip, uint8_t *bp, size_t n, systime_t time) { (void)ip; (void)bp; (void)n; (void)time; return 0; }
-
-struct GConsoleWindowVMT_t {
- _base_asynchronous_channel_methods
-};
-
-static const struct GConsoleWindowVMT_t GWindowConsoleVMT = {
- GWinStreamWrite,
- GWinStreamRead,
- GWinStreamPut,
- GWinStreamGet,
- GWinStreamPutTimed,
- GWinStreamGetTimed,
- GWinStreamWriteTimed,
- GWinStreamReadTimed
-};
+#if GFX_USE_OS_CHIBIOS
+ #define Stream2GWindow(ip) ((GHandle)(((char *)(ip)) - (size_t)(&(((GConsoleObject *)0)->stream))))
+
+ static size_t GWinStreamWrite(void *ip, const uint8_t *bp, size_t n) { gwinPutCharArray(Stream2GWindow(ip), (const char *)bp, n); return RDY_OK; }
+ static size_t GWinStreamRead(void *ip, uint8_t *bp, size_t n) { (void)ip; (void)bp; (void)n; return 0; }
+ static msg_t GWinStreamPut(void *ip, uint8_t b) { gwinPutChar(Stream2GWindow(ip), (char)b); return RDY_OK; }
+ static msg_t GWinStreamGet(void *ip) {(void)ip; return RDY_OK; }
+ static msg_t GWinStreamPutTimed(void *ip, uint8_t b, systime_t time) { (void)time; gwinPutChar(Stream2GWindow(ip), (char)b); return RDY_OK; }
+ static msg_t GWinStreamGetTimed(void *ip, systime_t timeout) { (void)ip; (void)timeout; return RDY_OK; }
+ static size_t GWinStreamWriteTimed(void *ip, const uint8_t *bp, size_t n, systime_t time) { (void)time; gwinPutCharArray(Stream2GWindow(ip), (const char *)bp, n); return RDY_OK; }
+ static size_t GWinStreamReadTimed(void *ip, uint8_t *bp, size_t n, systime_t time) { (void)ip; (void)bp; (void)n; (void)time; return 0; }
+
+ struct GConsoleWindowVMT_t {
+ _base_asynchronous_channel_methods
+ };
+
+ static const struct GConsoleWindowVMT_t GWindowConsoleVMT = {
+ GWinStreamWrite,
+ GWinStreamRead,
+ GWinStreamPut,
+ GWinStreamGet,
+ GWinStreamPutTimed,
+ GWinStreamGetTimed,
+ GWinStreamWriteTimed,
+ GWinStreamReadTimed
+ };
+#endif
GHandle gwinCreateConsole(GConsoleObject *gc, coord_t x, coord_t y, coord_t width, coord_t height, font_t font) {
if (!(gc = (GConsoleObject *)_gwinInit((GWindowObject *)gc, x, y, width, height, sizeof(GConsoleObject))))
return 0;
gc->gwin.type = GW_CONSOLE;
gwinSetFont(&gc->gwin, font);
- gc->stream.vmt = &GWindowConsoleVMT;
+ #if GFX_USE_OS_CHIBIOS
+ gc->stream.vmt = &GWindowConsoleVMT;
+ #endif
gc->cx = 0;
gc->cy = 0;
return (GHandle)gc;
}
-BaseSequentialStream *gwinGetConsoleStream(GHandle gh) {
- if (gh->type != GW_CONSOLE)
- return 0;
- return (BaseSequentialStream *)&(((GConsoleObject *)(gh))->stream);
-}
+#if GFX_USE_OS_CHIBIOS
+ BaseSequentialStream *gwinGetConsoleStream(GHandle gh) {
+ if (gh->type != GW_CONSOLE)
+ return 0;
+ return (BaseSequentialStream *)&(((GConsoleObject *)(gh))->stream);
+ }
+#endif
void gwinPutChar(GHandle gh, char c) {
uint8_t width;
diff --git a/src/gwin/graph.c b/src/gwin/graph.c
index dd4506a3..287deba9 100644
--- a/src/gwin/graph.c
+++ b/src/gwin/graph.c
@@ -15,8 +15,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if (GFX_USE_GWIN && GWIN_NEED_GRAPH) || defined(__DOXYGEN__)
diff --git a/src/gwin/gwin.c b/src/gwin/gwin.c
index b6340c2d..c01c8a90 100644
--- a/src/gwin/gwin.c
+++ b/src/gwin/gwin.c
@@ -5,8 +5,6 @@
* http://chibios-gfx.com/license.html
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GWIN
@@ -29,7 +27,7 @@ GHandle _gwinInit(GWindowObject *gw, coord_t x, coord_t y, coord_t width, coord_
// Allocate the structure if necessary
if (!gw) {
- if (!(gw = (GWindowObject *)chHeapAlloc(NULL, size)))
+ if (!(gw = (GWindowObject *)gfxAlloc(size)))
return 0;
gw->flags = GWIN_FLG_DYNAMIC;
} else
@@ -56,7 +54,8 @@ GHandle gwinCreateWindow(GWindowObject *gw, coord_t x, coord_t y, coord_t width,
}
void gwinSetEnabled(GHandle gh, bool_t enabled) {
-
+ (void)gh;
+ (void)enabled;
}
void gwinDestroyWindow(GHandle gh) {
@@ -66,7 +65,7 @@ void gwinDestroyWindow(GHandle gh) {
case GW_BUTTON:
if ((gh->flags & GBTN_FLG_ALLOCTXT)) {
gh->flags &= ~GBTN_FLG_ALLOCTXT; // To be sure, to be sure
- chHeapFree((void *)((GButtonObject *)gh)->txt);
+ gfxFree((void *)((GButtonObject *)gh)->txt);
}
geventDetachSource(&((GButtonObject *)gh)->listener, 0);
geventDetachSourceListeners((GSourceHandle)gh);
@@ -85,7 +84,7 @@ void gwinDestroyWindow(GHandle gh) {
// Clean up the structure
if (gh->flags & GWIN_FLG_DYNAMIC) {
gh->flags = 0; // To be sure, to be sure
- chHeapFree((void *)gh);
+ gfxFree((void *)gh);
}
}
diff --git a/src/gwin/slider.c b/src/gwin/slider.c
index 26555f33..7f1e36bc 100644
--- a/src/gwin/slider.c
+++ b/src/gwin/slider.c
@@ -15,8 +15,6 @@
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if (GFX_USE_GWIN && GWIN_NEED_SLIDER) || defined(__DOXYGEN__)
diff --git a/src/tdisp/tdisp.c b/src/tdisp/tdisp.c
index 42b22cd5..c7931995 100644
--- a/src/tdisp/tdisp.c
+++ b/src/tdisp/tdisp.c
@@ -12,8 +12,6 @@
* @addtogroup TDISP
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_TDISP || defined(__DOXYGEN__)
@@ -21,15 +19,11 @@
#include "tdisp/lld/tdisp_lld.h"
#if TDISP_NEED_MULTITHREAD
- #if !CH_USE_MUTEXES
- #error "TDISP: CH_USE_MUTEXES must be defined in chconf.h because TDISP_NEED_MULTITHREAD is defined"
- #endif
+ static gfxMutex tdispMutex;
- static Mutex tdispMutex;
-
- #define MUTEX_INIT() chMtxInit(&tdispMutex)
- #define MUTEX_ENTER() chMtxLock(&tdispMutex)
- #define MUTEX_LEAVE() chMtxUnlock()
+ #define MUTEX_INIT() gfxMutexInit(&tdispMutex)
+ #define MUTEX_ENTER() gfxMutexEnter(&tdispMutex)
+ #define MUTEX_LEAVE() gfxMutexExit(&tdispMutex)
#else