Merge pull request #73 from inmarket/master

GOS module for OS independance, GMISC additions
ugfx_release_2.6
Andrew Hannam 2013-05-24 08:41:48 -07:00
commit f0569e2555
122 changed files with 2216 additions and 960 deletions

View File

@ -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

View File

@ -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();

View File

@ -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

View File

@ -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.. */

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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();

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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();

View File

@ -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

View File

@ -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);
}
}

View File

@ -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

View File

@ -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);
}
}

View File

@ -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 */

View File

@ -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;

View File

@ -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 */

View File

@ -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;

View File

@ -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

View File

@ -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);
}
}

View File

@ -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

View File

@ -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();

View File

@ -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

View File

@ -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);
}
}

View File

@ -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 */

View File

@ -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;

View File

@ -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

View File

@ -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);
}
}

View File

@ -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

View File

@ -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);
}
}

View File

@ -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

View File

@ -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();

View File

@ -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 */

View File

@ -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);
}
}

View File

@ -14,8 +14,6 @@
* @{
*/
#include "ch.h"
#include "hal.h"
#include "gfx.h"
#if GFX_USE_GADC

View File

@ -13,8 +13,6 @@
*
* @{
*/
#include "ch.h"
#include "hal.h"
/**
* We are now implementing the driver - pull in our channel table

View File

@ -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);

View File

@ -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) {

View File

@ -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) {

View File

@ -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);

View File

@ -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

View File

@ -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); }

View File

@ -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); }

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -13,8 +13,6 @@
* @{
*/
#include "ch.h"
#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/

View File

@ -14,8 +14,6 @@
* @{
*/
#include "ch.h"
#include "hal.h"
#include "gfx.h"
#if GFX_USE_GINPUT && GINPUT_NEED_DIAL

View File

@ -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__)*/

View File

@ -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__)*/

View File

@ -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__)*/

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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) {

View File

@ -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) {

View File

@ -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

3
gfx.mk
View File

@ -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

View File

@ -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 */
/*

View File

@ -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.

View File

@ -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.

View File

@ -12,7 +12,6 @@
* by the low level drivers that need to understand a font.
*
* @addtogroup GDISP
*
* @{
*/

View File

@ -44,20 +44,6 @@ typedef int16_t coord_t;
/* Type definitions */
/*===========================================================================*/
/**
* @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.
*/
@ -317,19 +303,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
@ -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)

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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 */
/** @} */

View File

@ -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

View File

@ -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

View File

@ -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
/**
* @}
*

View File

@ -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 */

483
include/gos/gos.h 100644
View File

@ -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 */
/** @} */

View File

@ -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 */
/** @} */

View File

@ -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 */

View File

@ -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 */

View File

@ -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)

View File

@ -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.

View File

@ -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;
}

View File

@ -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) {

View File

@ -12,8 +12,6 @@
* @addtogroup GAUDOUT
* @{
*/
#include "ch.h"
#include "hal.h"
#include "gfx.h"
#if GFX_USE_GAUDOUT || defined(__DOXYGEN__)

View File

@ -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

View File

@ -12,8 +12,6 @@
* @addtogroup GDISP
* @{
*/
#include "ch.h"
#include "hal.h"
#include "gfx.h"
#if GFX_USE_GDISP
@ -25,45 +23,23 @@
/* Include the low level driver information */
#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);
}
}
}

View File

@ -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;
}
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 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;
}
#if defined(WIN32)
#include <fcntl.h>
static size_t ImageSimulFileRead(struct gdispImageIO *pio, void *buf, size_t 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 = read((int)pio->fd, buf, len);
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 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 };
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) || GFX_USE_OS_WIN32 || GFX_USE_OS_POSIX
#include <stdio.h>
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
}

View File

@ -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 */

View File

@ -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) {

View File

@ -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

View File

@ -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 */

View File

@ -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

Some files were not shown because too many files have changed in this diff Show More