From 92d972cfd83b67961dc63d60c5317ec2651eb256 Mon Sep 17 00:00:00 2001 From: inmarket Date: Wed, 2 Jul 2014 09:40:01 +1000 Subject: [PATCH 01/87] First part new mouse infrastructure --- src/ginput/driver_mouse.h | 195 ++++++++---------- src/ginput/mouse.c | 403 +++++++++++++++++++------------------- src/ginput/sys_options.h | 45 ++--- 3 files changed, 305 insertions(+), 338 deletions(-) diff --git a/src/ginput/driver_mouse.h b/src/ginput/driver_mouse.h index 21d87dac..c60b9a0e 100644 --- a/src/ginput/driver_mouse.h +++ b/src/ginput/driver_mouse.h @@ -19,68 +19,81 @@ #if GINPUT_NEED_MOUSE || defined(__DOXYGEN__) -#include "ginput_lld_mouse_config.h" - -// GEVENT_MOUSE or GEVENT_TOUCH - What type of device is this. -#ifndef GINPUT_MOUSE_EVENT_TYPE - #define GINPUT_MOUSE_EVENT_TYPE GEVENT_MOUSE -#endif - -// TRUE/FALSE - Does the mouse/touch driver require calibration? -#ifndef GINPUT_MOUSE_NEED_CALIBRATION - #define GINPUT_MOUSE_NEED_CALIBRATION FALSE -#endif - -// TRUE/FALSE - Should the calibration happen at the extremes of the panel? -#ifndef GINPUT_MOUSE_CALIBRATE_EXTREMES - #define GINPUT_MOUSE_CALIBRATE_EXTREMES FALSE -#endif - -// TRUE/FALSE - Can the mouse/touch driver itself save calibration data? -#ifndef GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE - #define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE -#endif - -// n or -1 - n means to test calibration result (+/- pixels), -1 means not to. -#ifndef GINPUT_MOUSE_MAX_CALIBRATION_ERROR - #define GINPUT_MOUSE_MAX_CALIBRATION_ERROR -1 -#endif - -// n - How many times to read (and average) per poll -#ifndef GINPUT_MOUSE_READ_CYCLES - #define GINPUT_MOUSE_READ_CYCLES 1 -#endif - -// n - Millisecs between poll's -#ifndef GINPUT_MOUSE_POLL_PERIOD - #define GINPUT_MOUSE_POLL_PERIOD 25 -#endif - -// n - Movement allowed without discarding the CLICK or CLICKCXT event (+/- pixels) -#ifndef GINPUT_MOUSE_MAX_CLICK_JITTER - #define GINPUT_MOUSE_MAX_CLICK_JITTER 1 -#endif - -// n - Movement allowed without discarding the MOVE event (+/- pixels) -#ifndef GINPUT_MOUSE_MAX_MOVE_JITTER - #define GINPUT_MOUSE_MAX_MOVE_JITTER 0 -#endif - -// ms - Millisecs seperating a CLICK from a CXTCLICK -#ifndef GINPUT_MOUSE_CLICK_TIME - #define GINPUT_MOUSE_CLICK_TIME 700 -#endif - -// true/false - Whether the mouse driver internally handles screen rotation -#ifndef GINPUT_MOUSE_NO_ROTATION - #define GINPUT_MOUSE_NO_ROTATION FALSE -#endif - -typedef struct MouseReading_t { +typedef struct MouseReading { coord_t x, y, z; uint16_t buttons; } MouseReading; +#if !GINPUT_TOUCH_NOCALIBRATE + typedef struct MouseCalibration { + float ax; + float bx; + float cx; + float ay; + float by; + float cy; + } MouseCalibration; +#endif + +typedef struct MouseInstance { + struct MouseInstance * next; // The next mouse instance + const struct MOUSEVMT * vmt; // The mouse VMT + MouseReading r; // The current position and state + uint16_t flags; // Flags + #define GMOUSE_FLG_ACTIVE 0x0001 // Mouse is currently active + #define GMOUSE_FLG_DYNAMIC 0x0002 // Mouse is dynamically allocated + #define GMOUSE_FLG_CLICK_TIMER 0x0004 // Currently timing a click event + #define GMOUSE_FLG_INDELTA 0x0008 // Currently in a up/down transition test + #define GMOUSE_FLG_CLIP 0x0010 // Clip reading to the display + #define GMOUSE_FLG_CALIBRATE 0x0020 // Calibrate readings + #define GMOUSE_FLG_CAL_INPROGRESS 0x0040 // Calibrate is currently in progress + #define GMOUSE_FLG_CAL_SAVED 0x0080 // Calibration has been saved + #define GMOUSE_FLG_FINGERMODE 0x0100 // Mouse is currently in finger mode + point clickpos; // The position of the last click event + systemticks_t clicktime; // The time of the last click event + GDisplay * display; // The display the mouse is associated with + void * param; // A variable for private driver use + #if !GINPUT_TOUCH_NOCALIBRATE + GMouseCalibrationSaveRoutine fnsavecal; // The calibration load routine + GMouseCalibrationLoadRoutine fnloadcal; // The calibration save routine + MouseCalibration caldata; // The calibration data + #endif +} MouseInstance; + +typedef struct MouseJitter { + coord_t calibrate; // Maximum error for a calibration to succeed + coord_t click; // Movement allowed without discarding the CLICK or CLICKCXT event + coord_t move; // Movement allowed without discarding the MOVE event +} MouseJitter; + +typedef struct MOUSEVMT { + uint16_t flags; // Device flags + #define GMOUSE_VFLG_TOUCH 0x0001 // This is a touch device (rather than a mouse). Button 1 is calculated from z value. + #define GMOUSE_VFLG_NOPOLL 0x0002 // Do not poll this device - it is purely interrupt driven + #define GMOUSE_VFLG_SELFROTATION 0x0004 // This device returns readings that are aligned with the display orientation + #define GMOUSE_VFLG_DEFAULTFINGER 0x0008 // Default to finger mode + #define GMOUSE_VFLG_CALIBRATE 0x0010 // This device requires calibration + #define GMOUSE_VFLG_CAL_EXTREMES 0x0020 // Use edge to edge calibration + #define GMOUSE_VFLG_CAL_TEST 0x0040 // Test the results of the calibration + #define GMOUSE_VFLG_ONLY_DOWN 0x0100 // This device returns a valid position only when the mouse is down + #define GMOUSE_VFLG_POORUPDOWN 0x0200 // Position readings during up/down are unreliable + coord_t z_max; // TOUCH: Maximum possible z value (fully touched) + coord_t z_min; // TOUCH: Minimum possible z value (touch off screen). Note may also be > z_max + coord_t z_touchon; // TOUCH: z values between z_max and this are a solid touch on + coord_t z_touchoff; // TOUCH: z values between z_min and this are a solid touch off + + MouseJitter pen_jitter; // PEN MODE: Jitter settings + MouseJitter finger_jitter; // FINGER MODE: Jitter settings + + void (*init)((MouseInstance *pmouse); // Required + void (*get)(MouseInstance *pmouse, MouseReading *prd); // Required + void (*cal_save)(MouseInstance *pmouse, void *buf, size_t sz); // Optional + const char *(*cal_load)(MouseInstance *pmouse); // Optional: Can return NULL if no data is saved. + // Buffer is gfxFree()'d afterwards. +} MOUSEVMT; + +#include "ginput_lld_mouse_config.h" + /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ @@ -88,70 +101,33 @@ typedef struct MouseReading_t { #ifdef __cplusplus extern "C" { #endif - /** - * @brief Initialise the mouse/touch. + * @brief Get a new empty mouse instance and assign it this VMT and display + * @note This routine is provided to low level drivers by the high level code. + * @note This routine is designed for displays that have their own dedicated mouse + * eg. Win32, X, uGFXnet. + * The display driver will during initialisation call this routine to associate + * itself with a mouse. * * @notapi */ - void ginput_lld_mouse_init(void); + MouseInstance *ginputMouseGetNewMouseForDisplay(const MOUSEVMT *vmt, GDisplay *g); /** - * @brief Read the mouse/touch position. - * - * @param[in] pt A pointer to the structure to fill - * - * @note For drivers that don't support returning a position - * when the touch is up (most touch devices), it should - * return the previous position with the new Z value. - * The z value is the pressure for those touch devices - * that support it (-100 to 100 where > 0 is touched) - * or, 0 or 100 for those drivers that don't. + * @brief Release a mouse + * @note This routine is provided to low level drivers by the high level code. + * @note This routine is designed for displays that have their own dedicated mouse + * eg. Win32, X, uGFXnet. + * When the display has finished with the mouse it can release it. * * @notapi */ - void ginput_lld_mouse_get_reading(MouseReading *pt); - - #if GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE - /** - * @brief Load calibration data from a storage area on the touch controller. - * - * @param[in] instance The mouse instance number - * - * @note The instance parameter is currently always 0 as we only support - * one mouse/touch device at a time. - * @note This routine should only be provided if the driver has its own - * storage area where calibration data can be stored. The drivers - * option.h file should define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE = TRUE - * if it supports this. - * - * @notapi - */ - const char *ginput_lld_mouse_calibration_load(uint16_t instance); - /** - * @brief Save calibration data to a storage area on the touch controller. - * - * @param[in] instance The mouse instance number - * @param[in] calbuf The calibration data to be saved - * @param[in] sz The size of the calibration data - * - * @note The instance parameter is currently always 0 as we only support - * one mouse/touch device at a time. - * @note This routine should only be provided if the driver has its own - * storage area where calibration data can be stored. The drivers - * option.h file should define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE = TRUE - * if it supports this. - * - * @notapi - */ - void ginput_lld_mouse_calibration_save(uint16_t instance, const uint8_t *calbuf, size_t sz); - #endif + void ginputMouseGetNewMouseForDisplay(MouseIntance *pmouse); /** * @brief Wakeup the high level code so that it attempts another read * * @note This routine is provided to low level drivers by the high level code - * @note Particularly useful if GINPUT_MOUSE_POLL_PERIOD = TIME_INFINITE * * @notapi */ @@ -161,7 +137,6 @@ extern "C" { * @brief Wakeup the high level code so that it attempts another read * * @note This routine is provided to low level drivers by the high level code - * @note Particularly useful if GINPUT_MOUSE_POLL_PERIOD = TIME_INFINITE * * @iclass * @notapi @@ -172,7 +147,7 @@ extern "C" { } #endif -#endif /* GINPUT_NEED_MOUSE || GINPUT_NEED_TOUCH */ +#endif /* GINPUT_NEED_MOUSE */ #endif /* _LLD_GINPUT_MOUSE_H */ /** @} */ diff --git a/src/ginput/mouse.c b/src/ginput/mouse.c index f7842e33..1f1a18fe 100644 --- a/src/ginput/mouse.c +++ b/src/ginput/mouse.c @@ -19,7 +19,7 @@ #include "src/ginput/driver_mouse.h" -#if GINPUT_MOUSE_NEED_CALIBRATION +#if !GINPUT_TOUCH_NOCALIBRATE #if !defined(GFX_USE_GDISP) || !GFX_USE_GDISP #error "GINPUT: GFX_USE_GDISP must be defined when mouse or touch calibration is required" #endif @@ -38,87 +38,12 @@ #define GINPUT_MOUSE_CALIBRATION_POINTS 4 #endif - typedef struct Calibration_t { - float ax; - float bx; - float cx; - float ay; - float by; - float cy; - } Calibration; -#endif - -typedef struct MousePoint_t { - coord_t x, y; -} MousePoint; +endif static GTIMER_DECL(MouseTimer); -static struct MouseConfig_t { - MouseReading t; - MousePoint movepos; - MousePoint clickpos; - systemticks_t clicktime; - uint16_t last_buttons; - uint16_t flags; - #define FLG_INIT_DONE 0x8000 - #define FLG_CLICK_TIMER 0x0001 - #define FLG_IN_CAL 0x0010 - #define FLG_CAL_OK 0x0020 - #define FLG_CAL_SAVED 0x0040 - #define FLG_CAL_FREE 0x0080 - #define FLG_CAL_RAW 0x0100 - #if GINPUT_MOUSE_NEED_CALIBRATION - GMouseCalibrationSaveRoutine fnsavecal; - GMouseCalibrationLoadRoutine fnloadcal; - Calibration caldata; - #endif - GDisplay * display; -} MouseConfig; - -void _tsOrientClip(MouseReading *pt, GDisplay *g, bool_t doClip) { - coord_t w, h; - - w = gdispGGetWidth(g); - h = gdispGGetHeight(g); - - #if GDISP_NEED_CONTROL && !GINPUT_MOUSE_NO_ROTATION - switch(gdispGGetOrientation(g)) { - case GDISP_ROTATE_0: - break; - case GDISP_ROTATE_90: - { - coord_t t = pt->x; - pt->x = w - 1 - pt->y; - pt->y = t; - } - break; - case GDISP_ROTATE_180: - pt->x = w - 1 - pt->x; - pt->y = h - 1 - pt->y; - break; - case GDISP_ROTATE_270: - { - coord_t t = pt->y; - pt->y = h - 1 - pt->x; - pt->x = t; - } - break; - default: - break; - } - #endif - - if (doClip) { - if (pt->x < 0) pt->x = 0; - else if (pt->x >= w) pt->x = w-1; - if (pt->y < 0) pt->y = 0; - else if (pt->y >= h) pt->y = h-1; - } -} - -#if GINPUT_MOUSE_NEED_CALIBRATION - static inline void _tsSetIdentity(Calibration *c) { +#if !GINPUT_TOUCH_NOCALIBRATE + static inline void _tsSetIdentity(MouseCalibration *c) { c->ax = 1; c->bx = 0; c->cx = 0; @@ -127,7 +52,7 @@ void _tsOrientClip(MouseReading *pt, GDisplay *g, bool_t doClip) { c->cy = 0; } - static inline void _tsDrawCross(const MousePoint *pp) { + static inline void _tsDrawCross(const point *pp) { gdispGDrawLine(MouseConfig.display, pp->x-15, pp->y, pp->x-2, pp->y, White); gdispGDrawLine(MouseConfig.display, pp->x+2, pp->y, pp->x+15, pp->y, White); gdispGDrawLine(MouseConfig.display, pp->x, pp->y-15, pp->x, pp->y-2, White); @@ -250,143 +175,208 @@ void _tsOrientClip(MouseReading *pt, GDisplay *g, bool_t doClip) { } #endif -#if GINPUT_MOUSE_READ_CYCLES > 1 - static void get_raw_reading(MouseReading *pt) { - int32_t x, y, z; - unsigned i; +static void DoMouseReading(MouseInstance *pm) { + MouseReading r; - x = y = z = 0; - for(i = 0; i < GINPUT_MOUSE_READ_CYCLES; i++) { - ginput_lld_mouse_get_reading(pt); - x += pt->x; - y += pt->y; - z += pt->z; + pm->vmt->get(pm, &r); + + // If touch then calculate button 1 from z + if ((pm->vmt->flags & GMOUSE_VFLG_TOUCH)) { + if (pm->vmt->z_min <= pm->vmt->z_max) { + if (r.z >= pm->vmt->z_touchon) r.buttons |= GINPUT_MOUSE_BTN_LEFT; + else if (r.z <= pm->vmt->z_touchoff) r.buttons &= ~GINPUT_MOUSE_BTN_LEFT; + else return; // bad reading + } else { + if (r.z <= pm->vmt->z_touchon) r.buttons |= GINPUT_MOUSE_BTN_LEFT; + else if (r.z >= pm->vmt->z_touchoff) r.buttons &= ~GINPUT_MOUSE_BTN_LEFT; + else return; // bad reading + } + } + + // Double check up & down events if needed + if ((pm->vmt->flags & GMOUSE_VFLG_POORUPDOWN)) { + // Are we in a transition test + if ((pm->flags & GMOUSE_FLG_INDELTA)) { + if (!((r.buttons ^ pm->r.buttons) & GINPUT_MOUSE_BTN_LEFT)) { + // Transition failed + pm->flags &= ~GMOUSE_FLG_INDELTA; + return; + } + // Transition succeeded + pm->flags &= ~GMOUSE_FLG_INDELTA; + + // Should we start a transition test + } else if (((r.buttons ^ pm->r.buttons) & GINPUT_MOUSE_BTN_LEFT)) { + pm->flags |= GMOUSE_FLG_INDELTA; + return; + } + } + + // If the mouse is up we may need to keep our previous position + if ((pm->vmt->flags & GMOUSE_VFLG_ONLY_DOWN) && !(r.buttons & GINPUT_MOUSE_BTN_LEFT)) { + r.x = pm->r.x; + r.y = pm->r.y; + + } else { + coord_t w, h; + + #if !GINPUT_TOUCH_NOCALIBRATE + // Do we need to calibrate the reading? + if ((pm->flags & GMOUSE_FLG_CALIBRATE)) + _tsTransform(&r, &MouseConfig.caldata); + #endif + + // We now need display information + w = gdispGGetWidth(g); + h = gdispGGetHeight(g); + + #if GDISP_NEED_CONTROL + // Do we need to rotate the reading to match the display + if (!(pm->vmt->flags & GMOUSE_VFLG_SELFROTATION)) { + coord_t t; + + switch(gdispGGetOrientation(g)) { + case GDISP_ROTATE_0: + break; + case GDISP_ROTATE_90: + t = r.x; + r.x = w - 1 - r.y; + r.y = t; + break; + case GDISP_ROTATE_180: + r.x = w - 1 - r.x; + r.y = h - 1 - r.y; + break; + case GDISP_ROTATE_270: + t = r.y; + r.y = h - 1 - r.x; + r.x = t; + break; + default: + break; + } + } + #endif + + // Do we need to clip the reading to the display + if ((pm->flags & GMOUSE_FLG_CLIP)) { + if (r.x < 0) r.x = 0; + else if (r.x >= w) r.x = w-1; + if (r.y < 0) r.y = 0; + else if (r.y >= h) r.y = h-1; + } + } + + { + MouseJitter *pj; + uint32_t diff; + + // Are we in pen or finger mode + pj = (pm->flags & GMOUSE_FLG_FINGERMODE) ? &pm->vmt->finger_jitter : &pm->vmt->pen_jitter; + + // Is this just movement jitter + if (pj->move > 0) { + diff = (uint32_t)(r.x - pm->r.x) * (uint32_t)(r.x - pm->r.x) + (uint32_t)(r.y - pm->r.y) * (uint32_t)(r.y - pm->r.y); + if (diff > (uint32_t)pj->move * (uint32_t)pj->move) { + r.x = pm->r.x; + r.y = pm->r.y; + } } - /* Take the average of the readings */ - pt->x = x / GINPUT_MOUSE_READ_CYCLES; - pt->y = y / GINPUT_MOUSE_READ_CYCLES; - pt->z = z / GINPUT_MOUSE_READ_CYCLES; + // Check if the click has moved outside the click area and if so cancel the click + if (pj->click > 0 && (pm->flags & GMOUSE_FLG_CLICK_TIMER)) { + diff = (uint32_t)(r.x - pm->clickpos.x) * (uint32_t)(r.x - pm->clickpos.x) + (uint32_t)(r.y - pm->clickpos.y) * (uint32_t)(r.y - pm->clickpos.y); + if (diff > (uint32_t)pj->click * (uint32_t)pj->click) + pm->flags &= ~GMOUSE_FLG_CLICK_TIMER; + } } -#else - #define get_raw_reading(pt) ginput_lld_mouse_get_reading(pt) -#endif -static void get_calibrated_reading(MouseReading *pt) { - get_raw_reading(pt); + { + GSourceListener *psl; + GEventMouse *pe; + unsigned meta; + uint16_t upbtns, dnbtns; - #if GINPUT_MOUSE_NEED_CALIBRATION - _tsTransform(pt, &MouseConfig.caldata); - #endif + // Calculate out new event meta value and handle CLICK and CXTCLICK + dnbtns = r.buttons & ~pm->r.buttons; + upbtns = ~r.buttons & pm->r.buttons; + meta = GMETA_NONE; - _tsOrientClip(pt, MouseConfig.display, !(MouseConfig.flags & FLG_CAL_RAW)); + // Mouse down + if ((dnbtns & (GINPUT_MOUSE_BTN_LEFT|GINPUT_MOUSE_BTN_RIGHT))) { + pm->clickpos.x = r.x; + pm->clickpos.y = r.y; + pm->clicktime = gfxSystemTicks(); + pm->flags |= GMOUSE_FLG_CLICK_TIMER; + if ((dnbtns & GINPUT_MOUSE_BTN_LEFT)) + meta |= GMETA_MOUSE_DOWN; + } + + // Mouse up + if ((upbtns & (GINPUT_MOUSE_BTN_LEFT|GINPUT_MOUSE_BTN_RIGHT))) { + if ((upbtns & GINPUT_MOUSE_BTN_LEFT)) + meta |= GMETA_MOUSE_UP; + if ((pm->flags & GMOUSE_FLG_CLICK_TIMER)) { + if ((upbtns & GINPUT_MOUSE_BTN_LEFT) + #if GINPUT_TOUCH_CLICK_TIME != TIME_INFINITE + && gfxSystemTicks() - pm->clicktime < gfxMillisecondsToTicks(GINPUT_TOUCH_CLICK_TIME) + #endif + ) + meta |= GMETA_MOUSE_CLICK; + else + meta |= GMETA_MOUSE_CXTCLICK; + pm->flags &= ~GMOUSE_FLG_CLICK_TIMER; + } + } + + // Send the event to the listeners that are interested. + psl = 0; + while ((psl = geventGetSourceListener((GSourceHandle)(&MouseConfig), psl))) { + if (!(pe = (GEventMouse *)geventGetEventBuffer(psl))) { + // This listener is missing - save the meta events that have happened + psl->srcflags |= meta; + continue; + } + + // If we haven't really moved (and there are no meta events) don't bother sending the event + if (!meta && !psl->srcflags && !(psl->listenflags & GLISTEN_MOUSENOFILTER) + && r.x == pm->r.x && r.y == pm->r.y && r.buttons == pm->r.buttons) + continue; + + // Send the event if we are listening for it + if (((r.buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEDOWNMOVES)) + || (!(r.buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEUPMOVES)) + || (meta && (psl->listenflags & GLISTEN_MOUSEMETA))) { + pe->type = GINPUT_MOUSE_EVENT_TYPE; + pe->instance = 0; + pe->x = r.x; + pe->y = r.y; + pe->z = r.z; + pe->current_buttons = r.buttons; + pe->last_buttons = pm->r.buttons; + pe->meta = meta; + if (psl->srcflags) { + pe->current_buttons |= GINPUT_MISSED_MOUSE_EVENT; + pe->meta |= psl->srcflags; + psl->srcflags = 0; + } + pe->display = pm->display; + geventSendEvent(psl); + } + } + } + + // Finally save the results + pm->r.x = r.x; + pm->r.y = r.y; + pm->r.z = r.z; + pm->r.buttons = r.buttons; } static void MousePoll(void *param) { (void) param; - GSourceListener *psl; - GEventMouse *pe; - unsigned meta; - uint16_t upbtns, dnbtns; - uint32_t cdiff; - uint32_t mdiff; - - // Save the last mouse state - MouseConfig.last_buttons = MouseConfig.t.buttons; - - // Get the new mouse reading - get_calibrated_reading(&MouseConfig.t); - - // Calculate out new event meta value and handle CLICK and CXTCLICK - dnbtns = MouseConfig.t.buttons & ~MouseConfig.last_buttons; - upbtns = ~MouseConfig.t.buttons & MouseConfig.last_buttons; - meta = GMETA_NONE; - - // As the touch moves up we need to return a point at the old position because some - // controllers return garbage with the mouse up - if ((upbtns & GINPUT_MOUSE_BTN_LEFT)) { - MouseConfig.t.x = MouseConfig.movepos.x; - MouseConfig.t.y = MouseConfig.movepos.y; - } - - // Calculate the position difference from our movement reference (update the reference if out of range) - mdiff = (MouseConfig.t.x - MouseConfig.movepos.x) * (MouseConfig.t.x - MouseConfig.movepos.x) + - (MouseConfig.t.y - MouseConfig.movepos.y) * (MouseConfig.t.y - MouseConfig.movepos.y); - if (mdiff > GINPUT_MOUSE_MAX_MOVE_JITTER * GINPUT_MOUSE_MAX_MOVE_JITTER) { - MouseConfig.movepos.x = MouseConfig.t.x; - MouseConfig.movepos.y = MouseConfig.t.y; - } - // Check if the click has moved outside the click area and if so cancel the click - if ((MouseConfig.flags & FLG_CLICK_TIMER)) { - cdiff = (MouseConfig.t.x - MouseConfig.clickpos.x) * (MouseConfig.t.x - MouseConfig.clickpos.x) + - (MouseConfig.t.y - MouseConfig.clickpos.y) * (MouseConfig.t.y - MouseConfig.clickpos.y); - if (cdiff > GINPUT_MOUSE_MAX_CLICK_JITTER * GINPUT_MOUSE_MAX_CLICK_JITTER) - MouseConfig.flags &= ~FLG_CLICK_TIMER; - } - - // Mouse down - if ((dnbtns & (GINPUT_MOUSE_BTN_LEFT|GINPUT_MOUSE_BTN_RIGHT))) { - MouseConfig.clickpos.x = MouseConfig.t.x; - MouseConfig.clickpos.y = MouseConfig.t.y; - MouseConfig.clicktime = gfxSystemTicks(); - MouseConfig.flags |= FLG_CLICK_TIMER; - if ((dnbtns & GINPUT_MOUSE_BTN_LEFT)) - meta |= GMETA_MOUSE_DOWN; - } - - // Mouse up - if ((upbtns & (GINPUT_MOUSE_BTN_LEFT|GINPUT_MOUSE_BTN_RIGHT))) { - if ((upbtns & GINPUT_MOUSE_BTN_LEFT)) - meta |= GMETA_MOUSE_UP; - if ((MouseConfig.flags & FLG_CLICK_TIMER)) { - if ((upbtns & GINPUT_MOUSE_BTN_LEFT) - #if GINPUT_MOUSE_CLICK_TIME != TIME_INFINITE - && gfxSystemTicks() - MouseConfig.clicktime < gfxMillisecondsToTicks(GINPUT_MOUSE_CLICK_TIME) - #endif - ) - meta |= GMETA_MOUSE_CLICK; - else - meta |= GMETA_MOUSE_CXTCLICK; - MouseConfig.flags &= ~FLG_CLICK_TIMER; - } - } - - // Send the event to the listeners that are interested. - psl = 0; - while ((psl = geventGetSourceListener((GSourceHandle)(&MouseConfig), psl))) { - if (!(pe = (GEventMouse *)geventGetEventBuffer(psl))) { - // This listener is missing - save the meta events that have happened - psl->srcflags |= meta; - continue; - } - - // If we haven't really moved (and there are no meta events) don't bother sending the event - if (mdiff <= GINPUT_MOUSE_MAX_MOVE_JITTER * GINPUT_MOUSE_MAX_MOVE_JITTER && !psl->srcflags - && !meta && MouseConfig.last_buttons == MouseConfig.t.buttons && !(psl->listenflags & GLISTEN_MOUSENOFILTER)) - continue; - - // Send the event if we are listening for it - if (((MouseConfig.t.buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEDOWNMOVES)) - || (!(MouseConfig.t.buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEUPMOVES)) - || (meta && (psl->listenflags & GLISTEN_MOUSEMETA))) { - pe->type = GINPUT_MOUSE_EVENT_TYPE; - pe->instance = 0; - pe->x = MouseConfig.t.x; - pe->y = MouseConfig.t.y; - pe->z = MouseConfig.t.z; - pe->current_buttons = MouseConfig.t.buttons; - pe->last_buttons = MouseConfig.last_buttons; - pe->meta = meta; - if (psl->srcflags) { - pe->current_buttons |= GINPUT_MISSED_MOUSE_EVENT; - pe->meta |= psl->srcflags; - psl->srcflags = 0; - } - pe->display = MouseConfig.display; - geventSendEvent(psl); - } - } + DoMouseReading(stuff in here); } GSourceHandle ginputGetMouse(uint16_t instance) { @@ -481,7 +471,8 @@ bool_t ginputGetMouseStatus(uint16_t instance, GEventMouse *pe) { } bool_t ginputCalibrateMouse(uint16_t instance) { - #if !GINPUT_MOUSE_NEED_CALIBRATION + #if GINPUT_TOUCH_NOCALIBRATE + (void) instance; return FALSE; diff --git a/src/ginput/sys_options.h b/src/ginput/sys_options.h index c606262b..7ccc7b78 100644 --- a/src/ginput/sys_options.h +++ b/src/ginput/sys_options.h @@ -73,40 +73,41 @@ * @{ */ /** - * @brief Use a custom board definition for the mouse/touch driver even if a board definition exists. + * @brief Turn off touch mouse support. * @details Defaults to FALSE - * @details If TRUE, add ginput_lld_mouse_board.h to your project directory and customise it. - * @note Not all GINPUT mouse/touch low level drivers use board definition files. + * @note Touch device handling requires a lot of code. If your mouse doesn't require it + * this can be turned off to save a lot of space. */ - #ifndef GINPUT_MOUSE_USE_CUSTOM_BOARD - #define GINPUT_MOUSE_USE_CUSTOM_BOARD FALSE + #ifndef GINPUT_TOUCH_NOTOUCH + #define GINPUT_TOUCH_NOTOUCH FALSE #endif /** - * @brief Use a custom board definition for the keyboard driver even if a board definition exists. + * @brief Turn off calibration support. * @details Defaults to FALSE - * @details If TRUE, add ginput_lld_keyboard_board.h to your project directory and customise it. - * @note Not all GINPUT keyboard low level drivers use board definition files. + * @note Calibration requires a lot of code. If your mouse doesn't require it + * this can be turned off to save a lot of space. */ - #ifndef GINPUT_KEYBOARD_USE_CUSTOM_BOARD - #define GINPUT_KEYBOARD_USE_CUSTOM_BOARD FALSE + #ifndef GINPUT_TOUCH_NOCALIBRATE + #define GINPUT_TOUCH_NOCALIBRATE FALSE #endif /** - * @brief Use a custom board definition for the toggle driver even if a board definition exists. - * @details Defaults to FALSE - * @details If TRUE, add ginput_lld_toggle_board.h to your project directory and customise it. - * @note Not all GINPUT toggle low level drivers use board definition files. + * @brief Milliseconds between mouse polls. + * @details Defaults to 25 millseconds + * @note How often mice should be polled. More often leads to smoother mouse movement + * but increases CPU usage. If no mouse drivers need polling the poll is not + * started. */ - #ifndef GINPUT_TOGGLE_USE_CUSTOM_BOARD - #define GINPUT_TOGGLE_USE_CUSTOM_BOARD FALSE + #ifndef GINPUT_MOUSE_POLL_PERIOD + #define GINPUT_MOUSE_POLL_PERIOD 25 #endif + /** - * @brief Use a custom board definition for the dial driver even if a board definition exists. - * @details Defaults to FALSE - * @details If TRUE, add ginput_lld_dial_board.h to your project directory and customise it. - * @note Not all GINPUT dial low level drivers use board definition files. + * @brief Milliseconds separating a CLICK from a CXTCLICK. + * @details Defaults to 700 millseconds + * @note How long it takes for a click to turn into a CXTCLICK on a touch device. */ - #ifndef GINPUT_DIAL_USE_CUSTOM_BOARD - #define GINPUT_DIAL_USE_CUSTOM_BOARD FALSE + #ifndef GINPUT_TOUCH_CLICK_TIME + #define GINPUT_TOUCH_CLICK_TIME 700 #endif /** @} */ From eaf1909c5601fe510f5a51a6b4aef6c1d82121b4 Mon Sep 17 00:00:00 2001 From: inmarket Date: Tue, 16 Sep 2014 10:06:16 +1000 Subject: [PATCH 02/87] Readme for integration with yaffs2 (coming soon) --- 3rdparty/yaffs2/readme.txt | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 3rdparty/yaffs2/readme.txt diff --git a/3rdparty/yaffs2/readme.txt b/3rdparty/yaffs2/readme.txt new file mode 100644 index 00000000..f34bb5b3 --- /dev/null +++ b/3rdparty/yaffs2/readme.txt @@ -0,0 +1,28 @@ +Yaffs2 source code has not been included in this repository so that you are fully +aware of the license restrictions before using it with uGFX. + +Yaffs2 may be downloaded from http://www.yaffs.net + +This notice has been provided in collaboration with Aleph One - the owners of Yaffs2. +As such it represents an agreement of understanding between Aleph One and uGFX. + +Yaffs2 is distributed under the GPLv2 license. Specifically that means the following… +- You may publish the source code for your project including the yaffs2 and uGFX code + provided that you retain the respective licenses and copyrights in the header + of each source file. +- You may create a binary for your own personal use. +- You MUST NOT distribute a binary that you produce in any form (even in the ROM of + a device) that contains both yaffs2 and uGFX code as that will put you in + breach of either the GPL license or the uGFX license no matter what you do. + See http://ugfx.org/licensing for more details. +- Regardless of whether the project is commercial or non-commercial, you MUST NOT + even compile binaries for other people since that is considered "distribution". + You cannot even compile binaries for a friend, they must build it for themselves. + +If you want to distribute a binary that contains both yaffs2 and uGFX (even in the +ROM of a device) then you must obtain a commercial license of yaffs2 just as you must +obtain a commercial license for uGFX if you want to use it for commercial purposes. + +Just as uGFX provides special licenses for certain open hardware projects, Aleph One +may consider providing special licenses for various special purposes. Please contact +Aleph One at info@aleph1.co.uk for more information. From 6f8845e86c31fa8f5076950d46d80aae53bef21a Mon Sep 17 00:00:00 2001 From: inmarket Date: Tue, 16 Sep 2014 10:06:59 +1000 Subject: [PATCH 03/87] More mouse updates - not working yet. --- src/gdisp/driver.h | 2 +- src/ginput/driver_mouse.h | 90 ++++----- src/ginput/ginput_mouse.c | 387 +++++++++++++++++++------------------- src/ginput/ginput_mouse.h | 1 - 4 files changed, 228 insertions(+), 252 deletions(-) diff --git a/src/gdisp/driver.h b/src/gdisp/driver.h index 5213e5ae..3b77c568 100644 --- a/src/gdisp/driver.h +++ b/src/gdisp/driver.h @@ -287,7 +287,7 @@ struct GDisplay { }; typedef struct GDISPVMT { - GDriverVMT vmtdriver; + GDriverVMT d; bool_t (*init)(GDisplay *g); void (*deinit)(GDisplay *g); void (*writestart)(GDisplay *g); // Uses p.x,p.y p.cx,p.cy diff --git a/src/ginput/driver_mouse.h b/src/ginput/driver_mouse.h index c60b9a0e..dbd327d9 100644 --- a/src/ginput/driver_mouse.h +++ b/src/ginput/driver_mouse.h @@ -19,55 +19,57 @@ #if GINPUT_NEED_MOUSE || defined(__DOXYGEN__) -typedef struct MouseReading { +// Include the GDRIVER infrastructure +#include "src/gdriver/sys_defs.h" + +typedef struct GMouseReading { coord_t x, y, z; uint16_t buttons; - } MouseReading; + } GMouseReading; #if !GINPUT_TOUCH_NOCALIBRATE - typedef struct MouseCalibration { + typedef struct GMouseCalibration { float ax; float bx; float cx; float ay; float by; float cy; - } MouseCalibration; + } GMouseCalibration; #endif -typedef struct MouseInstance { - struct MouseInstance * next; // The next mouse instance - const struct MOUSEVMT * vmt; // The mouse VMT - MouseReading r; // The current position and state +typedef struct GMouse { + GDriver d; // The driver overheads and vmt + GMouseReading r; // The current position and state uint16_t flags; // Flags #define GMOUSE_FLG_ACTIVE 0x0001 // Mouse is currently active - #define GMOUSE_FLG_DYNAMIC 0x0002 // Mouse is dynamically allocated - #define GMOUSE_FLG_CLICK_TIMER 0x0004 // Currently timing a click event - #define GMOUSE_FLG_INDELTA 0x0008 // Currently in a up/down transition test - #define GMOUSE_FLG_CLIP 0x0010 // Clip reading to the display - #define GMOUSE_FLG_CALIBRATE 0x0020 // Calibrate readings - #define GMOUSE_FLG_CAL_INPROGRESS 0x0040 // Calibrate is currently in progress - #define GMOUSE_FLG_CAL_SAVED 0x0080 // Calibration has been saved - #define GMOUSE_FLG_FINGERMODE 0x0100 // Mouse is currently in finger mode + #define GMOUSE_FLG_CLICK_TIMER 0x0002 // Currently timing a click event + #define GMOUSE_FLG_INDELTA 0x0004 // Currently in a up/down transition test + #define GMOUSE_FLG_CLIP 0x0008 // Clip reading to the display + #define GMOUSE_FLG_CALIBRATE 0x0010 // Calibrate readings + #define GMOUSE_FLG_CAL_INPROGRESS 0x0020 // Calibrate is currently in progress + #define GMOUSE_FLG_CAL_SAVED 0x0040 // Calibration has been saved + #define GMOUSE_FLG_FINGERMODE 0x0080 // Mouse is currently in finger mode + #define GMOUSE_FLG_NEEDREAD 0x0100 // The mouse needs reading point clickpos; // The position of the last click event systemticks_t clicktime; // The time of the last click event GDisplay * display; // The display the mouse is associated with - void * param; // A variable for private driver use #if !GINPUT_TOUCH_NOCALIBRATE GMouseCalibrationSaveRoutine fnsavecal; // The calibration load routine GMouseCalibrationLoadRoutine fnloadcal; // The calibration save routine MouseCalibration caldata; // The calibration data #endif -} MouseInstance; + // Other driver specific fields may follow. +} GMouse; -typedef struct MouseJitter { +typedef struct GMouseJitter { coord_t calibrate; // Maximum error for a calibration to succeed coord_t click; // Movement allowed without discarding the CLICK or CLICKCXT event coord_t move; // Movement allowed without discarding the MOVE event -} MouseJitter; +} GMouseJitter; -typedef struct MOUSEVMT { - uint16_t flags; // Device flags +typedef struct GMouseVMT { + GDriverVMT d; // Device flags are part of the general vmt #define GMOUSE_VFLG_TOUCH 0x0001 // This is a touch device (rather than a mouse). Button 1 is calculated from z value. #define GMOUSE_VFLG_NOPOLL 0x0002 // Do not poll this device - it is purely interrupt driven #define GMOUSE_VFLG_SELFROTATION 0x0004 // This device returns readings that are aligned with the display orientation @@ -82,17 +84,16 @@ typedef struct MOUSEVMT { coord_t z_touchon; // TOUCH: z values between z_max and this are a solid touch on coord_t z_touchoff; // TOUCH: z values between z_min and this are a solid touch off - MouseJitter pen_jitter; // PEN MODE: Jitter settings - MouseJitter finger_jitter; // FINGER MODE: Jitter settings + GMouseJitter pen_jitter; // PEN MODE: Jitter settings + GMouseJitter finger_jitter; // FINGER MODE: Jitter settings - void (*init)((MouseInstance *pmouse); // Required - void (*get)(MouseInstance *pmouse, MouseReading *prd); // Required - void (*cal_save)(MouseInstance *pmouse, void *buf, size_t sz); // Optional - const char *(*cal_load)(MouseInstance *pmouse); // Optional: Can return NULL if no data is saved. - // Buffer is gfxFree()'d afterwards. -} MOUSEVMT; + bool_t (*init)(GMouse *m); // Required + void (*get)(GMouse *m, GMouseReading *prd); // Required + void (*calsave)(GMouse *m, void *buf, size_t sz); // Optional + const char *(*calload)(GMouse *m); // Optional: Can return NULL if no data is saved. Buffer is automatically gfxFree()'d afterwards. +} GMouseVMT; -#include "ginput_lld_mouse_config.h" +#define gmvmt(m) ((const GMouseVMT const *)((m)->d.vmt)) /*===========================================================================*/ /* External declarations. */ @@ -101,29 +102,6 @@ typedef struct MOUSEVMT { #ifdef __cplusplus extern "C" { #endif - /** - * @brief Get a new empty mouse instance and assign it this VMT and display - * @note This routine is provided to low level drivers by the high level code. - * @note This routine is designed for displays that have their own dedicated mouse - * eg. Win32, X, uGFXnet. - * The display driver will during initialisation call this routine to associate - * itself with a mouse. - * - * @notapi - */ - MouseInstance *ginputMouseGetNewMouseForDisplay(const MOUSEVMT *vmt, GDisplay *g); - - /** - * @brief Release a mouse - * @note This routine is provided to low level drivers by the high level code. - * @note This routine is designed for displays that have their own dedicated mouse - * eg. Win32, X, uGFXnet. - * When the display has finished with the mouse it can release it. - * - * @notapi - */ - void ginputMouseGetNewMouseForDisplay(MouseIntance *pmouse); - /** * @brief Wakeup the high level code so that it attempts another read * @@ -131,7 +109,7 @@ extern "C" { * * @notapi */ - void ginputMouseWakeup(void); + void ginputMouseWakeup(GMouse *m); /** * @brief Wakeup the high level code so that it attempts another read @@ -141,7 +119,7 @@ extern "C" { * @iclass * @notapi */ - void ginputMouseWakeupI(void); + void ginputMouseWakeupI(GMouse *m); #ifdef __cplusplus } diff --git a/src/ginput/ginput_mouse.c b/src/ginput/ginput_mouse.c index 772e300b..e2b1f15e 100644 --- a/src/ginput/ginput_mouse.c +++ b/src/ginput/ginput_mouse.c @@ -26,24 +26,22 @@ #include // Required for memcpy - #define GINPUT_MOUSE_CALIBRATION_FONT "* Double" - #define GINPUT_MOUSE_CALIBRATION_FONT2 "* Narrow" - #define GINPUT_MOUSE_CALIBRATION_TEXT "Calibration" - #define GINPUT_MOUSE_CALIBRATION_ERROR_TEXT "Failed - Please try again!" - #define GINPUT_MOUSE_CALIBRATION_SAME_TEXT "Error: Same Reading - Check Driver!" + #define CALIBRATION_FONT "* Double" + #define CALIBRATION_FONT2 "* Narrow" + #define CALIBRATION_TEXT "Calibration" + #define CALIBRATION_ERROR_TEXT "Failed - Please try again!" + #define CALIBRATION_SAME_TEXT "Error: Same Reading - Check Driver!" + #define CALIBRATION_BACKGROUND Blue + #define CALIBRATION_COLOR1 White + #define CALIBRATION_COLOR2 RGB2COLOR(184,158,131) - #if GINPUT_MOUSE_MAX_CALIBRATION_ERROR < 0 - #define GINPUT_MOUSE_CALIBRATION_POINTS 3 - #else - #define GINPUT_MOUSE_CALIBRATION_POINTS 4 - #endif - -endif +#endif static GTIMER_DECL(MouseTimer); #if !GINPUT_TOUCH_NOCALIBRATE - static inline void _tsSetIdentity(MouseCalibration *c) { + /* + static inline void CalibrationSetIdentity(MouseCalibration *c) { c->ax = 1; c->bx = 0; c->cx = 0; @@ -51,150 +49,142 @@ static GTIMER_DECL(MouseTimer); c->by = 1; c->cy = 0; } + */ - static inline void _tsDrawCross(const point *pp) { - gdispGDrawLine(MouseConfig.display, pp->x-15, pp->y, pp->x-2, pp->y, White); - gdispGDrawLine(MouseConfig.display, pp->x+2, pp->y, pp->x+15, pp->y, White); - gdispGDrawLine(MouseConfig.display, pp->x, pp->y-15, pp->x, pp->y-2, White); - gdispGDrawLine(MouseConfig.display, pp->x, pp->y+2, pp->x, pp->y+15, White); - - gdispGDrawLine(MouseConfig.display, pp->x-15, pp->y+15, pp->x-7, pp->y+15, RGB2COLOR(184,158,131)); - gdispGDrawLine(MouseConfig.display, pp->x-15, pp->y+7, pp->x-15, pp->y+15, RGB2COLOR(184,158,131)); - - gdispGDrawLine(MouseConfig.display, pp->x-15, pp->y-15, pp->x-7, pp->y-15, RGB2COLOR(184,158,131)); - gdispGDrawLine(MouseConfig.display, pp->x-15, pp->y-7, pp->x-15, pp->y-15, RGB2COLOR(184,158,131)); - - gdispGDrawLine(MouseConfig.display, pp->x+7, pp->y+15, pp->x+15, pp->y+15, RGB2COLOR(184,158,131)); - gdispGDrawLine(MouseConfig.display, pp->x+15, pp->y+7, pp->x+15, pp->y+15, RGB2COLOR(184,158,131)); - - gdispGDrawLine(MouseConfig.display, pp->x+7, pp->y-15, pp->x+15, pp->y-15, RGB2COLOR(184,158,131)); - gdispGDrawLine(MouseConfig.display, pp->x+15, pp->y-15, pp->x+15, pp->y-7, RGB2COLOR(184,158,131)); + static inline void CalibrationCrossDraw(GMouse *m, const point *pp) { + gdispGDrawLine(m->display, pp->x-15, pp->y, pp->x-2, pp->y, CALIBRATION_COLOR1); + gdispGDrawLine(m->display, pp->x+2, pp->y, pp->x+15, pp->y, CALIBRATION_COLOR1); + gdispGDrawLine(m->display, pp->x, pp->y-15, pp->x, pp->y-2, CALIBRATION_COLOR1); + gdispGDrawLine(m->display, pp->x, pp->y+2, pp->x, pp->y+15, CALIBRATION_COLOR1); + gdispGDrawLine(m->display, pp->x-15, pp->y+15, pp->x-7, pp->y+15, CALIBRATION_COLOR2); + gdispGDrawLine(m->display, pp->x-15, pp->y+7, pp->x-15, pp->y+15, CALIBRATION_COLOR2); + gdispGDrawLine(m->display, pp->x-15, pp->y-15, pp->x-7, pp->y-15, CALIBRATION_COLOR2); + gdispGDrawLine(m->display, pp->x-15, pp->y-7, pp->x-15, pp->y-15, CALIBRATION_COLOR2); + gdispGDrawLine(m->display, pp->x+7, pp->y+15, pp->x+15, pp->y+15, CALIBRATION_COLOR2); + gdispGDrawLine(m->display, pp->x+15, pp->y+7, pp->x+15, pp->y+15, CALIBRATION_COLOR2); + gdispGDrawLine(m->display, pp->x+7, pp->y-15, pp->x+15, pp->y-15, CALIBRATION_COLOR2); + gdispGDrawLine(m->display, pp->x+15, pp->y-15, pp->x+15, pp->y-7, CALIBRATION_COLOR2); } - static inline void _tsClearCross(const MousePoint *pp) { - gdispGFillArea(MouseConfig.display, pp->x - 15, pp->y - 15, 42, 42, Blue); + static inline void CalibrationCrossClear(GMouse *m, const point *pp) { + gdispGFillArea(m->display, pp->x - 15, pp->y - 15, 32, 32, CALIBRATION_BACKGROUND); } - static inline void _tsTransform(MouseReading *pt, const Calibration *c) { + static inline void CalibrationTransform(GMouseReading *pt, const GMouseCalibration *c) { pt->x = (coord_t) (c->ax * pt->x + c->bx * pt->y + c->cx); pt->y = (coord_t) (c->ay * pt->x + c->by * pt->y + c->cy); } - static inline void _tsDo3PointCalibration(const MousePoint *cross, const MousePoint *points, GDisplay *g, Calibration *c) { + static inline void CalibrationCalculate(GMouse *m, const MousePoint *cross, const MousePoint *points) { float dx; coord_t c0, c1, c2; + (void) m; + + // Work on x values + c0 = cross[0].x; + c1 = cross[1].x; + c2 = cross[2].x; #if GDISP_NEED_CONTROL - /* Convert all cross points back to GDISP_ROTATE_0 convention - * before calculating the calibration matrix. - */ - switch(gdispGGetOrientation(g)) { - case GDISP_ROTATE_90: - c0 = cross[0].y; - c1 = cross[1].y; - c2 = cross[2].y; - break; - case GDISP_ROTATE_180: - c0 = c1 = c2 = gdispGGetWidth(g) - 1; - c0 -= cross[0].x; - c1 -= cross[1].x; - c2 -= cross[2].x; - break; - case GDISP_ROTATE_270: - c0 = c1 = c2 = gdispGGetHeight(g) - 1; - c0 -= cross[0].y; - c1 -= cross[1].y; - c2 -= cross[2].y; - break; - case GDISP_ROTATE_0: - default: - c0 = cross[0].x; - c1 = cross[1].x; - c2 = cross[2].x; - break; + if (!(gmvmt(m)->d.flags & GMOUSE_VFLG_SELFROTATION)) { + /* Convert all cross points back to GDISP_ROTATE_0 convention + * before calculating the calibration matrix. + */ + switch(gdispGGetOrientation(m->display)) { + case GDISP_ROTATE_90: + c0 = cross[0].y; + c1 = cross[1].y; + c2 = cross[2].y; + break; + case GDISP_ROTATE_180: + c0 = c1 = c2 = gdispGGetWidth(m->display) - 1; + c0 -= cross[0].x; + c1 -= cross[1].x; + c2 -= cross[2].x; + break; + case GDISP_ROTATE_270: + c0 = c1 = c2 = gdispGGetHeight(m->display) - 1; + c0 -= cross[0].y; + c1 -= cross[1].y; + c2 -= cross[2].y; + break; + } } - #else - (void) g; - - c0 = cross[0].x; - c1 = cross[1].x; - c2 = cross[2].x; #endif /* Compute all the required determinants */ dx = (float)(points[0].x - points[2].x) * (float)(points[1].y - points[2].y) - (float)(points[1].x - points[2].x) * (float)(points[0].y - points[2].y); - c->ax = ((float)(c0 - c2) * (float)(points[1].y - points[2].y) - - (float)(c1 - c2) * (float)(points[0].y - points[2].y)) / dx; - c->bx = ((float)(c1 - c2) * (float)(points[0].x - points[2].x) - - (float)(c0 - c2) * (float)(points[1].x - points[2].x)) / dx; - c->cx = (c0 * ((float)points[1].x * (float)points[2].y - (float)points[2].x * (float)points[1].y) - - c1 * ((float)points[0].x * (float)points[2].y - (float)points[2].x * (float)points[0].y) - + c2 * ((float)points[0].x * (float)points[1].y - (float)points[1].x * (float)points[0].y)) / dx; + m->caldata.ax = ((float)(c0 - c2) * (float)(points[1].y - points[2].y) + - (float)(c1 - c2) * (float)(points[0].y - points[2].y)) / dx; + m->caldata.bx = ((float)(c1 - c2) * (float)(points[0].x - points[2].x) + - (float)(c0 - c2) * (float)(points[1].x - points[2].x)) / dx; + m->caldata.cx = (c0 * ((float)points[1].x * (float)points[2].y - (float)points[2].x * (float)points[1].y) + - c1 * ((float)points[0].x * (float)points[2].y - (float)points[2].x * (float)points[0].y) + + c2 * ((float)points[0].x * (float)points[1].y - (float)points[1].x * (float)points[0].y)) / dx; + + // Work on y values + c0 = cross[0].y; + c1 = cross[1].y; + c2 = cross[2].y; #if GDISP_NEED_CONTROL - switch(gdispGGetOrientation(g)) { - case GDISP_ROTATE_90: - c0 = c1 = c2 = gdispGGetWidth(g) - 1; - c0 -= cross[0].x; - c1 -= cross[1].x; - c2 -= cross[2].x; - break; - case GDISP_ROTATE_180: - c0 = c1 = c2 = gdispGGetHeight(g) - 1; - c0 -= cross[0].y; - c1 -= cross[1].y; - c2 -= cross[2].y; - break; - case GDISP_ROTATE_270: - c0 = cross[0].x; - c1 = cross[1].x; - c2 = cross[2].x; - break; - case GDISP_ROTATE_0: - default: - c0 = cross[0].y; - c1 = cross[1].y; - c2 = cross[2].y; - break; + if (!(gmvmt(m)->d.flags & GMOUSE_VFLG_SELFROTATION)) { + switch(gdispGGetOrientation(m->display)) { + case GDISP_ROTATE_90: + c0 = c1 = c2 = gdispGGetWidth(m->display) - 1; + c0 -= cross[0].x; + c1 -= cross[1].x; + c2 -= cross[2].x; + break; + case GDISP_ROTATE_180: + c0 = c1 = c2 = gdispGGetHeight(m->display) - 1; + c0 -= cross[0].y; + c1 -= cross[1].y; + c2 -= cross[2].y; + break; + case GDISP_ROTATE_270: + c0 = cross[0].x; + c1 = cross[1].x; + c2 = cross[2].x; + break; + } } - #else - c0 = cross[0].y; - c1 = cross[1].y; - c2 = cross[2].y; #endif - c->ay = ((float)(c0 - c2) * (float)(points[1].y - points[2].y) - - (float)(c1 - c2) * (float)(points[0].y - points[2].y)) / dx; - c->by = ((float)(c1 - c2) * (float)(points[0].x - points[2].x) - - (float)(c0 - c2) * (float)(points[1].x - points[2].x)) / dx; - c->cy = (c0 * ((float)points[1].x * (float)points[2].y - (float)points[2].x * (float)points[1].y) - - c1 * ((float)points[0].x * (float)points[2].y - (float)points[2].x * (float)points[0].y) - + c2 * ((float)points[0].x * (float)points[1].y - (float)points[1].x * (float)points[0].y)) / dx; + m->caldata.ay = ((float)(c0 - c2) * (float)(points[1].y - points[2].y) + - (float)(c1 - c2) * (float)(points[0].y - points[2].y)) / dx; + m->caldata.by = ((float)(c1 - c2) * (float)(points[0].x - points[2].x) + - (float)(c0 - c2) * (float)(points[1].x - points[2].x)) / dx; + m->caldata.cy = (c0 * ((float)points[1].x * (float)points[2].y - (float)points[2].x * (float)points[1].y) + - c1 * ((float)points[0].x * (float)points[2].y - (float)points[2].x * (float)points[0].y) + + c2 * ((float)points[0].x * (float)points[1].y - (float)points[1].x * (float)points[0].y)) / dx; } #endif -static void DoMouseReading(MouseInstance *pm) { - MouseReading r; +static void GetMouseReading(GMouse *m) { + GMouseReading r; - pm->vmt->get(pm, &r); + // Get the raw reading. + gmvmt(m)->get(m, &r); + m->flags &= ~GMOUSE_FLG_NEEDREAD; - // If touch then calculate button 1 from z - if ((pm->vmt->flags & GMOUSE_VFLG_TOUCH)) { - if (pm->vmt->z_min <= pm->vmt->z_max) { - if (r.z >= pm->vmt->z_touchon) r.buttons |= GINPUT_MOUSE_BTN_LEFT; - else if (r.z <= pm->vmt->z_touchoff) r.buttons &= ~GINPUT_MOUSE_BTN_LEFT; - else return; // bad reading + // If touch then calculate button 0 from z + if ((gmvmt(m)->d.flags & GMOUSE_VFLG_TOUCH)) { + if (gmvmt(m)->z_min <= gmvmt(m)->z_max) { + if (r.z >= gmvmt(m)->z_touchon) r.buttons |= GINPUT_MOUSE_BTN_LEFT; + else if (r.z <= gmvmt(m)->z_touchoff) r.buttons &= ~GINPUT_MOUSE_BTN_LEFT; + else return; // bad transitional reading } else { - if (r.z <= pm->vmt->z_touchon) r.buttons |= GINPUT_MOUSE_BTN_LEFT; - else if (r.z >= pm->vmt->z_touchoff) r.buttons &= ~GINPUT_MOUSE_BTN_LEFT; - else return; // bad reading + if (r.z <= gmvmt(m)->z_touchon) r.buttons |= GINPUT_MOUSE_BTN_LEFT; + else if (r.z >= gmvmt(m)->z_touchoff) r.buttons &= ~GINPUT_MOUSE_BTN_LEFT; + else return; // bad transitional reading } } // Double check up & down events if needed - if ((pm->vmt->flags & GMOUSE_VFLG_POORUPDOWN)) { + if ((gmvmt(m)->d.flags & GMOUSE_VFLG_POORUPDOWN)) { // Are we in a transition test if ((pm->flags & GMOUSE_FLG_INDELTA)) { if (!((r.buttons ^ pm->r.buttons) & GINPUT_MOUSE_BTN_LEFT)) { @@ -213,7 +203,7 @@ static void DoMouseReading(MouseInstance *pm) { } // If the mouse is up we may need to keep our previous position - if ((pm->vmt->flags & GMOUSE_VFLG_ONLY_DOWN) && !(r.buttons & GINPUT_MOUSE_BTN_LEFT)) { + if ((gmvmt(m)->d.flags & GMOUSE_VFLG_ONLY_DOWN) && !(r.buttons & GINPUT_MOUSE_BTN_LEFT)) { r.x = pm->r.x; r.y = pm->r.y; @@ -223,71 +213,75 @@ static void DoMouseReading(MouseInstance *pm) { #if !GINPUT_TOUCH_NOCALIBRATE // Do we need to calibrate the reading? if ((pm->flags & GMOUSE_FLG_CALIBRATE)) - _tsTransform(&r, &MouseConfig.caldata); + CalibrationTransform(&r, &m->caldata); #endif - // We now need display information - w = gdispGGetWidth(g); - h = gdispGGetHeight(g); + // We can't clip or rotate if we don't have a display + if (m->display) { - #if GDISP_NEED_CONTROL - // Do we need to rotate the reading to match the display - if (!(pm->vmt->flags & GMOUSE_VFLG_SELFROTATION)) { - coord_t t; + // We now need display information + w = gdispGGetWidth(m->display); + h = gdispGGetHeight(m->display); - switch(gdispGGetOrientation(g)) { - case GDISP_ROTATE_0: - break; - case GDISP_ROTATE_90: - t = r.x; - r.x = w - 1 - r.y; - r.y = t; - break; - case GDISP_ROTATE_180: - r.x = w - 1 - r.x; - r.y = h - 1 - r.y; - break; - case GDISP_ROTATE_270: - t = r.y; - r.y = h - 1 - r.x; - r.x = t; - break; - default: - break; + #if GDISP_NEED_CONTROL + // Do we need to rotate the reading to match the display + if (!(gmvmt(m)->d.flags & GMOUSE_VFLG_SELFROTATION)) { + coord_t t; + + switch(gdispGGetOrientation(m->display)) { + case GDISP_ROTATE_0: + break; + case GDISP_ROTATE_90: + t = r.x; + r.x = w - 1 - r.y; + r.y = t; + break; + case GDISP_ROTATE_180: + r.x = w - 1 - r.x; + r.y = h - 1 - r.y; + break; + case GDISP_ROTATE_270: + t = r.y; + r.y = h - 1 - r.x; + r.x = t; + break; + default: + break; + } } - } - #endif + #endif - // Do we need to clip the reading to the display - if ((pm->flags & GMOUSE_FLG_CLIP)) { - if (r.x < 0) r.x = 0; - else if (r.x >= w) r.x = w-1; - if (r.y < 0) r.y = 0; - else if (r.y >= h) r.y = h-1; + // Do we need to clip the reading to the display + if ((pm->flags & GMOUSE_FLG_CLIP)) { + if (r.x < 0) r.x = 0; + else if (r.x >= w) r.x = w-1; + if (r.y < 0) r.y = 0; + else if (r.y >= h) r.y = h-1; + } } } { - MouseJitter *pj; - uint32_t diff; + const GMouseJitter *pj; + uint32_t diff; // Are we in pen or finger mode - pj = (pm->flags & GMOUSE_FLG_FINGERMODE) ? &pm->vmt->finger_jitter : &pm->vmt->pen_jitter; + pj = (m->flags & GMOUSE_FLG_FINGERMODE) ? &gmvmt(m)->finger_jitter : &gmvmt(m)->pen_jitter; // Is this just movement jitter if (pj->move > 0) { - diff = (uint32_t)(r.x - pm->r.x) * (uint32_t)(r.x - pm->r.x) + (uint32_t)(r.y - pm->r.y) * (uint32_t)(r.y - pm->r.y); + diff = (uint32_t)(r.x - m->r.x) * (uint32_t)(r.x - m->r.x) + (uint32_t)(r.y - m->r.y) * (uint32_t)(r.y - m->r.y); if (diff > (uint32_t)pj->move * (uint32_t)pj->move) { - r.x = pm->r.x; - r.y = pm->r.y; + r.x = m->r.x; + r.y = m->r.y; } } // Check if the click has moved outside the click area and if so cancel the click - if (pj->click > 0 && (pm->flags & GMOUSE_FLG_CLICK_TIMER)) { - diff = (uint32_t)(r.x - pm->clickpos.x) * (uint32_t)(r.x - pm->clickpos.x) + (uint32_t)(r.y - pm->clickpos.y) * (uint32_t)(r.y - pm->clickpos.y); + if (pj->click > 0 && (m->flags & GMOUSE_FLG_CLICK_TIMER)) { + diff = (uint32_t)(r.x - m->clickpos.x) * (uint32_t)(r.x - m->clickpos.x) + (uint32_t)(r.y - m->clickpos.y) * (uint32_t)(r.y - m->clickpos.y); if (diff > (uint32_t)pj->click * (uint32_t)pj->click) - pm->flags &= ~GMOUSE_FLG_CLICK_TIMER; + m->flags &= ~GMOUSE_FLG_CLICK_TIMER; } } @@ -298,16 +292,16 @@ static void DoMouseReading(MouseInstance *pm) { uint16_t upbtns, dnbtns; // Calculate out new event meta value and handle CLICK and CXTCLICK - dnbtns = r.buttons & ~pm->r.buttons; - upbtns = ~r.buttons & pm->r.buttons; + dnbtns = r.buttons & ~m->r.buttons; + upbtns = ~r.buttons & m->r.buttons; meta = GMETA_NONE; // Mouse down if ((dnbtns & (GINPUT_MOUSE_BTN_LEFT|GINPUT_MOUSE_BTN_RIGHT))) { - pm->clickpos.x = r.x; - pm->clickpos.y = r.y; - pm->clicktime = gfxSystemTicks(); - pm->flags |= GMOUSE_FLG_CLICK_TIMER; + m->clickpos.x = r.x; + m->clickpos.y = r.y; + m->clicktime = gfxSystemTicks(); + m->flags |= GMOUSE_FLG_CLICK_TIMER; if ((dnbtns & GINPUT_MOUSE_BTN_LEFT)) meta |= GMETA_MOUSE_DOWN; } @@ -316,16 +310,16 @@ static void DoMouseReading(MouseInstance *pm) { if ((upbtns & (GINPUT_MOUSE_BTN_LEFT|GINPUT_MOUSE_BTN_RIGHT))) { if ((upbtns & GINPUT_MOUSE_BTN_LEFT)) meta |= GMETA_MOUSE_UP; - if ((pm->flags & GMOUSE_FLG_CLICK_TIMER)) { + if ((m->flags & GMOUSE_FLG_CLICK_TIMER)) { if ((upbtns & GINPUT_MOUSE_BTN_LEFT) #if GINPUT_TOUCH_CLICK_TIME != TIME_INFINITE - && gfxSystemTicks() - pm->clicktime < gfxMillisecondsToTicks(GINPUT_TOUCH_CLICK_TIME) + && gfxSystemTicks() - m->clicktime < gfxMillisecondsToTicks(GINPUT_TOUCH_CLICK_TIME) #endif ) meta |= GMETA_MOUSE_CLICK; else meta |= GMETA_MOUSE_CXTCLICK; - pm->flags &= ~GMOUSE_FLG_CLICK_TIMER; + m->flags &= ~GMOUSE_FLG_CLICK_TIMER; } } @@ -340,7 +334,7 @@ static void DoMouseReading(MouseInstance *pm) { // If we haven't really moved (and there are no meta events) don't bother sending the event if (!meta && !psl->srcflags && !(psl->listenflags & GLISTEN_MOUSENOFILTER) - && r.x == pm->r.x && r.y == pm->r.y && r.buttons == pm->r.buttons) + && r.x == m->r.x && r.y == m->r.y && r.buttons == m->r.buttons) continue; // Send the event if we are listening for it @@ -348,35 +342,38 @@ static void DoMouseReading(MouseInstance *pm) { || (!(r.buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEUPMOVES)) || (meta && (psl->listenflags & GLISTEN_MOUSEMETA))) { pe->type = GINPUT_MOUSE_EVENT_TYPE; - pe->instance = 0; pe->x = r.x; pe->y = r.y; pe->z = r.z; pe->current_buttons = r.buttons; - pe->last_buttons = pm->r.buttons; + pe->last_buttons = m->r.buttons; pe->meta = meta; if (psl->srcflags) { pe->current_buttons |= GINPUT_MISSED_MOUSE_EVENT; pe->meta |= psl->srcflags; psl->srcflags = 0; } - pe->display = pm->display; + pe->display = m->display; geventSendEvent(psl); } } } // Finally save the results - pm->r.x = r.x; - pm->r.y = r.y; - pm->r.z = r.z; - pm->r.buttons = r.buttons; + m->r.x = r.x; + m->r.y = r.y; + m->r.z = r.z; + m->r.buttons = r.buttons; } static void MousePoll(void *param) { - (void) param; + GMouse * m; + (void) param; - DoMouseReading(stuff in here); + for(m = (GMouse *)gdriverGetNext(GDRIVER_TYPE_MOUSE, 0); m; m = (GMouse *)gdriverGetNext(GDRIVER_TYPE_MOUSE, m)) { + if (!(gmvmt(m)->d.flags & GMOUSE_VFLG_NOPOLL) || (m->flags & GMOUSE_FLG_NEEDREAD)) + GetMouseReading(m); + } } GSourceHandle ginputGetMouse(uint16_t instance) { @@ -413,7 +410,7 @@ GSourceHandle ginputGetMouse(uint16_t instance) { if ((MouseConfig.flags & FLG_CAL_FREE)) gfxFree((void *)pc); } else if (instance == 9999) { - _tsSetIdentity(&MouseConfig.caldata); + CalibrationSetIdentity(&MouseConfig.caldata); MouseConfig.flags |= (FLG_CAL_OK|FLG_CAL_SAVED|FLG_CAL_RAW); } else ginputCalibrateMouse(instance); @@ -491,7 +488,7 @@ bool_t ginputCalibrateMouse(uint16_t instance) { {(width - (width / 4)) , (height - (height / 4))}, {(width / 2), (height / 2)}}; /* Check point */ #endif - MousePoint points[GINPUT_MOUSE_CALIBRATION_POINTS]; + MousePoint points[4]; const MousePoint *pc; MousePoint *pt; int32_t px, py; @@ -523,7 +520,7 @@ bool_t ginputCalibrateMouse(uint16_t instance) { gdispGFillStringBox(MouseConfig.display, 0, 5, width, 30, GINPUT_MOUSE_CALIBRATION_TEXT, font1, White, Blue, justifyCenter); for(i = 0, pt = points, pc = cross; i < GINPUT_MOUSE_CALIBRATION_POINTS; i++, pt++, pc++) { - _tsDrawCross(pc); + CalibrationCrossDraw(pc); do { @@ -546,7 +543,7 @@ bool_t ginputCalibrateMouse(uint16_t instance) { pt->x = px / j; pt->y = py / j; - _tsClearCross(pc); + CalibrationCrossClear(pc); if (i >= 1 && pt->x == (pt-1)->x && pt->y == (pt-1)->y) { gdispGFillStringBox(MouseConfig.display, 0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_SAME_TEXT, font2, Red, Yellow, justifyCenter); @@ -557,7 +554,7 @@ bool_t ginputCalibrateMouse(uint16_t instance) { } /* Apply 3 point calibration algorithm */ - _tsDo3PointCalibration(cross, points, MouseConfig.display, &MouseConfig.caldata); + CalibrationCalculate(&MouseConfig, cross, points); /* Verification of correctness of calibration (optional) : * See if the 4th point (Middle of the screen) coincides with the calibrated @@ -568,7 +565,7 @@ bool_t ginputCalibrateMouse(uint16_t instance) { /* Transform the co-ordinates */ MouseConfig.t.x = points[3].x; MouseConfig.t.y = points[3].y; - _tsTransform(&MouseConfig.t, &MouseConfig.caldata); + CalibrationTransform(&MouseConfig.t, &MouseConfig.caldata); _tsOrientClip(&MouseConfig.t, MouseConfig.display, FALSE); /* Calculate the delta */ @@ -657,12 +654,14 @@ bool_t ginputRequireMouseCalibrationStorage(uint16_t instance) { } /* Wake up the mouse driver from an interrupt service routine (there may be new readings available) */ -void ginputMouseWakeup(void) { +void ginputMouseWakeup(GMouse *m) { + m->flags |= GMOUSE_FLG_NEEDREAD; gtimerJab(&MouseTimer); } /* Wake up the mouse driver from an interrupt service routine (there may be new readings available) */ -void ginputMouseWakeupI(void) { +void ginputMouseWakeupI(GMouse *m) { + m->flags |= GMOUSE_FLG_NEEDREAD; gtimerJabI(&MouseTimer); } diff --git a/src/ginput/ginput_mouse.h b/src/ginput/ginput_mouse.h index 61ad35e0..6cae66d1 100644 --- a/src/ginput/ginput_mouse.h +++ b/src/ginput/ginput_mouse.h @@ -33,7 +33,6 @@ /* This type definition is also used by touch */ typedef struct GEventMouse_t { GEventType type; // The type of this event (GEVENT_MOUSE or GEVENT_TOUCH) - uint16_t instance; // The mouse/touch instance coord_t x, y, z; // The position of the mouse. // - For touch devices, Z is the current pressure if supported (otherwise 0) // - For mice, Z is the 3rd dimension if supported (otherwise 0) From e586459a24c3c5bd383ef0045911dd155c47ef7f Mon Sep 17 00:00:00 2001 From: inmarket Date: Wed, 17 Sep 2014 08:41:34 +1000 Subject: [PATCH 04/87] Clean up demo gfxconf.h files that incorrectly specify every option. --- demos/modules/gwin/imagebox/gfxconf.h | 155 +---------------------- demos/modules/gwin/label/gfxconf.h | 170 +------------------------- 2 files changed, 4 insertions(+), 321 deletions(-) diff --git a/demos/modules/gwin/imagebox/gfxconf.h b/demos/modules/gwin/imagebox/gfxconf.h index 4db8be39..d068141a 100644 --- a/demos/modules/gwin/imagebox/gfxconf.h +++ b/demos/modules/gwin/imagebox/gfxconf.h @@ -30,93 +30,20 @@ /////////////////////////////////////////////////////////////////////////// #define GFX_USE_GDISP TRUE -#define GDISP_NEED_AUTOFLUSH FALSE -#define GDISP_NEED_TIMERFLUSH FALSE +//#define GDISP_NEED_AUTOFLUSH FALSE +//#define GDISP_NEED_TIMERFLUSH FALSE #define GDISP_NEED_VALIDATION TRUE #define GDISP_NEED_CLIP TRUE -#define GDISP_NEED_CIRCLE FALSE -#define GDISP_NEED_ELLIPSE FALSE -#define GDISP_NEED_ARC FALSE -#define GDISP_NEED_CONVEX_POLYGON FALSE -#define GDISP_NEED_SCROLL FALSE -#define GDISP_NEED_PIXELREAD FALSE -#define GDISP_NEED_CONTROL FALSE -#define GDISP_NEED_QUERY FALSE #define GDISP_NEED_MULTITHREAD TRUE -#define GDISP_NEED_STREAMING FALSE #define GDISP_NEED_TEXT TRUE - #define GDISP_NEED_ANTIALIAS FALSE - #define GDISP_NEED_UTF8 FALSE - #define GDISP_NEED_TEXT_KERNING FALSE - #define GDISP_INCLUDE_FONT_UI1 FALSE #define GDISP_INCLUDE_FONT_UI2 TRUE - #define GDISP_INCLUDE_FONT_LARGENUMBERS FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANS10 FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANS12 FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANS16 FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANS24 FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANS32 FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANSBOLD12 FALSE - #define GDISP_INCLUDE_FONT_FIXED_10X20 FALSE - #define GDISP_INCLUDE_FONT_FIXED_7X14 FALSE - #define GDISP_INCLUDE_FONT_FIXED_5X8 FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANS12_AA FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANS16_AA FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANS24_AA FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANS32_AA FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANSBOLD12_AA FALSE - #define GDISP_INCLUDE_USER_FONTS FALSE #define GDISP_NEED_IMAGE TRUE - #define GDISP_NEED_IMAGE_NATIVE FALSE #define GDISP_NEED_IMAGE_GIF TRUE #define GDISP_NEED_IMAGE_BMP TRUE - #define GDISP_NEED_IMAGE_BMP_1 FALSE - #define GDISP_NEED_IMAGE_BMP_4 FALSE - #define GDISP_NEED_IMAGE_BMP_4_RLE FALSE - #define GDISP_NEED_IMAGE_BMP_8 FALSE - #define GDISP_NEED_IMAGE_BMP_8_RLE FALSE - #define GDISP_NEED_IMAGE_BMP_16 FALSE #define GDISP_NEED_IMAGE_BMP_24 TRUE - #define GDISP_NEED_IMAGE_BMP_32 FALSE - #define GDISP_NEED_IMAGE_JPG FALSE - #define GDISP_NEED_IMAGE_PNG FALSE - #define GDISP_NEED_IMAGE_ACCOUNTING FALSE - -#define GDISP_NEED_STARTUP_LOGO TRUE #define GDISP_DEFAULT_ORIENTATION GDISP_ROTATE_LANDSCAPE -#define GDISP_LINEBUF_SIZE 128 - -#define GDISP_TOTAL_DISPLAYS 1 - #if GDISP_TOTAL_DISPLAYS > 1 - #define GDISP_HARDWARE_STREAM_WRITE FALSE - #define GDISP_HARDWARE_STREAM_READ FALSE - #define GDISP_HARDWARE_STREAM_POS FALSE - #define GDISP_HARDWARE_DRAWPIXEL FALSE - #define GDISP_HARDWARE_CLEARS FALSE - #define GDISP_HARDWARE_FILLS FALSE - #define GDISP_HARDWARE_BITFILLS FALSE - #define GDISP_HARDWARE_SCROLL FALSE - #define GDISP_HARDWARE_PIXELREAD FALSE - #define GDISP_HARDWARE_CONTROL FALSE - #define GDISP_HARDWARE_QUERY FALSE - #define GDISP_HARDWARE_CLIP FALSE - #endif - -#define GDISP_TOTAL_CONTROLLERS 1 - #if GDISP_TOTAL_CONTROLLERS > 1 - #define GDISP_CONTROLLER_LIST GDISPVMT_Win32, GDISPVMT_Win32 - #define GDISP_CONTROLLER_DISPLAYS 1, 1 - #define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB888 - #endif - -#define GDISP_USE_GFXNET FALSE - #define GDISP_GFXNET_PORT 13001 - #define GDISP_GFXNET_CUSTOM_LWIP_STARTUP FALSE - #define GDISP_DONT_WAIT_FOR_NET_DISPLAY FALSE - #define GDISP_GFXNET_UNSAFE_SOCKETS FALSE - /////////////////////////////////////////////////////////////////////////// // GWIN // @@ -125,27 +52,9 @@ #define GWIN_NEED_WINDOWMANAGER TRUE -#define GWIN_NEED_CONSOLE FALSE - #define GWIN_CONSOLE_USE_HISTORY FALSE - #define GWIN_CONSOLE_HISTORY_AVERAGING FALSE - #define GWIN_CONSOLE_HISTORY_ATCREATE FALSE - #define GWIN_CONSOLE_ESCSEQ FALSE - #define GWIN_CONSOLE_USE_BASESTREAM FALSE - #define GWIN_CONSOLE_USE_FLOAT FALSE -#define GWIN_NEED_GRAPH FALSE - #define GWIN_NEED_WIDGET TRUE - #define GWIN_NEED_LABEL FALSE - #define GWIN_NEED_BUTTON FALSE - #define GWIN_BUTTON_LAZY_RELEASE FALSE - #define GWIN_NEED_SLIDER FALSE - #define GWIN_NEED_CHECKBOX FALSE #define GWIN_NEED_IMAGE TRUE #define GWIN_NEED_IMAGE_ANIMATION TRUE - #define GWIN_NEED_RADIO FALSE - #define GWIN_NEED_LIST FALSE - #define GWIN_NEED_LIST_IMAGES FALSE - #define GWIN_NEED_PROGRESSBAR FALSE /////////////////////////////////////////////////////////////////////////// @@ -153,29 +62,16 @@ /////////////////////////////////////////////////////////////////////////// #define GFX_USE_GEVENT TRUE -#define GEVENT_ASSERT_NO_RESOURCE FALSE -#define GEVENT_MAXIMUM_SIZE 32 -#define GEVENT_MAX_SOURCE_LISTENERS 32 - - /////////////////////////////////////////////////////////////////////////// // GTIMER // /////////////////////////////////////////////////////////////////////////// #define GFX_USE_GTIMER TRUE -#define GTIMER_THREAD_PRIORITY HIGH_PRIORITY -#define GTIMER_THREAD_WORKAREA_SIZE 2048 - - /////////////////////////////////////////////////////////////////////////// // GQUEUE // /////////////////////////////////////////////////////////////////////////// #define GFX_USE_GQUEUE TRUE - #define GQUEUE_NEED_ASYNC TRUE -#define GQUEUE_NEED_GSYNC FALSE -#define GQUEUE_NEED_FSYNC FALSE -#define GQUEUE_NEED_BUFFERS FALSE /////////////////////////////////////////////////////////////////////////// // GINPUT // @@ -183,59 +79,12 @@ #define GFX_USE_GINPUT TRUE #define GINPUT_NEED_MOUSE TRUE -#define GINPUT_NEED_KEYBOARD FALSE -#define GINPUT_NEED_TOGGLE FALSE -#define GINPUT_NEED_DIAL FALSE - /////////////////////////////////////////////////////////////////////////// // GFILE // /////////////////////////////////////////////////////////////////////////// #define GFX_USE_GFILE TRUE -#define GFILE_NEED_PRINTG FALSE -#define GFILE_NEED_SCANG FALSE -#define GFILE_NEED_STRINGS FALSE -#define GFILE_NEED_STDIO FALSE - #define GFILE_ALLOW_FLOATS FALSE - #define GFILE_ALLOW_DEVICESPECIFIC FALSE - #define GFILE_MAX_GFILES 3 - -#define GFILE_NEED_MEMFS FALSE #define GFILE_NEED_ROMFS TRUE -#define GFILE_NEED_RAMFS FALSE -#define GFILE_NEED_FATFS FALSE -#define GFILE_NEED_NATIVEFS FALSE -#define GFILE_NEED_CHBIOSFS FALSE - - -/////////////////////////////////////////////////////////////////////////// -// GADC // -/////////////////////////////////////////////////////////////////////////// -#define GFX_USE_GADC FALSE - -#define GADC_MAX_LOWSPEED_DEVICES 4 - - -/////////////////////////////////////////////////////////////////////////// -// GAUDIO // -/////////////////////////////////////////////////////////////////////////// -#define GFX_USE_GAUDIO FALSE - #define GAUDIO_NEED_PLAY FALSE - #define GAUDIO_NEED_RECORD FALSE - - -/////////////////////////////////////////////////////////////////////////// -// GMISC // -/////////////////////////////////////////////////////////////////////////// -#define GFX_USE_GMISC FALSE - -#define GMISC_NEED_ARRAYOPS FALSE -#define GMISC_NEED_FASTTRIG FALSE -#define GMISC_NEED_FIXEDTRIG FALSE -#define GMISC_NEED_INVSQRT FALSE - #define GMISC_INVSQRT_MIXED_ENDIAN FALSE - #define GMISC_INVSQRT_REAL_SLOW FALSE - #endif /* _GFXCONF_H */ diff --git a/demos/modules/gwin/label/gfxconf.h b/demos/modules/gwin/label/gfxconf.h index 59ba809e..568ea4fe 100644 --- a/demos/modules/gwin/label/gfxconf.h +++ b/demos/modules/gwin/label/gfxconf.h @@ -24,98 +24,20 @@ //#define GFX_USE_OS_LINUX TRUE //#define GFX_USE_OS_OSX TRUE - /////////////////////////////////////////////////////////////////////////// // GDISP // /////////////////////////////////////////////////////////////////////////// #define GFX_USE_GDISP TRUE -#define GDISP_NEED_AUTOFLUSH FALSE -#define GDISP_NEED_TIMERFLUSH FALSE +//#define GDISP_NEED_AUTOFLUSH FALSE +//#define GDISP_NEED_TIMERFLUSH FALSE #define GDISP_NEED_VALIDATION TRUE #define GDISP_NEED_CLIP TRUE -#define GDISP_NEED_CIRCLE FALSE -#define GDISP_NEED_ELLIPSE FALSE -#define GDISP_NEED_ARC FALSE -#define GDISP_NEED_CONVEX_POLYGON FALSE -#define GDISP_NEED_SCROLL FALSE -#define GDISP_NEED_PIXELREAD FALSE -#define GDISP_NEED_CONTROL FALSE -#define GDISP_NEED_QUERY FALSE -#define GDISP_NEED_MULTITHREAD FALSE -#define GDISP_NEED_STREAMING FALSE #define GDISP_NEED_TEXT TRUE #define GDISP_NEED_ANTIALIAS TRUE #define GDISP_NEED_UTF8 TRUE #define GDISP_NEED_TEXT_KERNING TRUE - #define GDISP_INCLUDE_FONT_UI1 FALSE - #define GDISP_INCLUDE_FONT_UI2 FALSE - #define GDISP_INCLUDE_FONT_LARGENUMBERS FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANS10 FALSE #define GDISP_INCLUDE_FONT_DEJAVUSANS12 TRUE - #define GDISP_INCLUDE_FONT_DEJAVUSANS16 FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANS24 FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANS32 FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANSBOLD12 FALSE - #define GDISP_INCLUDE_FONT_FIXED_10X20 FALSE - #define GDISP_INCLUDE_FONT_FIXED_7X14 FALSE - #define GDISP_INCLUDE_FONT_FIXED_5X8 FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANS12_AA FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANS16_AA FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANS24_AA FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANS32_AA FALSE - #define GDISP_INCLUDE_FONT_DEJAVUSANSBOLD12_AA FALSE - #define GDISP_INCLUDE_USER_FONTS FALSE - -#define GDISP_NEED_IMAGE FALSE - #define GDISP_NEED_IMAGE_NATIVE FALSE - #define GDISP_NEED_IMAGE_GIF FALSE - #define GDISP_NEED_IMAGE_BMP FALSE - #define GDISP_NEED_IMAGE_BMP_1 FALSE - #define GDISP_NEED_IMAGE_BMP_4 FALSE - #define GDISP_NEED_IMAGE_BMP_4_RLE FALSE - #define GDISP_NEED_IMAGE_BMP_8 FALSE - #define GDISP_NEED_IMAGE_BMP_8_RLE FALSE - #define GDISP_NEED_IMAGE_BMP_16 FALSE - #define GDISP_NEED_IMAGE_BMP_24 FALSE - #define GDISP_NEED_IMAGE_BMP_32 FALSE - #define GDISP_NEED_IMAGE_JPG FALSE - #define GDISP_NEED_IMAGE_PNG FALSE - #define GDISP_NEED_IMAGE_ACCOUNTING FALSE - -#define GDISP_NEED_STARTUP_LOGO FALSE - -#define GDISP_DEFAULT_ORIENTATION GDISP_ROTATE_LANDSCAPE -#define GDISP_LINEBUF_SIZE 128 - -#define GDISP_TOTAL_DISPLAYS 1 - #if GDISP_TOTAL_DISPLAYS > 1 - #define GDISP_HARDWARE_STREAM_WRITE FALSE - #define GDISP_HARDWARE_STREAM_READ FALSE - #define GDISP_HARDWARE_STREAM_POS FALSE - #define GDISP_HARDWARE_DRAWPIXEL FALSE - #define GDISP_HARDWARE_CLEARS FALSE - #define GDISP_HARDWARE_FILLS FALSE - #define GDISP_HARDWARE_BITFILLS FALSE - #define GDISP_HARDWARE_SCROLL FALSE - #define GDISP_HARDWARE_PIXELREAD FALSE - #define GDISP_HARDWARE_CONTROL FALSE - #define GDISP_HARDWARE_QUERY FALSE - #define GDISP_HARDWARE_CLIP FALSE - #endif - -#define GDISP_TOTAL_CONTROLLERS 1 - #if GDISP_TOTAL_CONTROLLERS > 1 - #define GDISP_CONTROLLER_LIST GDISPVMT_Win32, GDISPVMT_Win32 - #define GDISP_CONTROLLER_DISPLAYS 1, 1 - #define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB888 - #endif - -#define GDISP_USE_GFXNET FALSE - #define GDISP_GFXNET_PORT 13001 - #define GDISP_GFXNET_CUSTOM_LWIP_STARTUP FALSE - #define GDISP_DONT_WAIT_FOR_NET_DISPLAY FALSE - #define GDISP_GFXNET_UNSAFE_SOCKETS FALSE /////////////////////////////////////////////////////////////////////////// @@ -125,59 +47,25 @@ #define GWIN_NEED_WINDOWMANAGER TRUE -#define GWIN_NEED_CONSOLE FALSE - #define GWIN_CONSOLE_USE_HISTORY FALSE - #define GWIN_CONSOLE_HISTORY_AVERAGING FALSE - #define GWIN_CONSOLE_HISTORY_ATCREATE FALSE - #define GWIN_CONSOLE_ESCSEQ FALSE - #define GWIN_CONSOLE_USE_BASESTREAM FALSE - #define GWIN_CONSOLE_USE_FLOAT FALSE -#define GWIN_NEED_GRAPH FALSE -#define GWIN_NEED_WIDGET FALSE - #define GWIN_NEED_HIERARCHY FALSE #define GWIN_NEED_LABEL TRUE #define GWIN_LABEL_ATTRIBUTE TRUE - #define GWIN_NEED_BUTTON FALSE - #define GWIN_BUTTON_LAZY_RELEASE FALSE - #define GWIN_NEED_SLIDER FALSE - #define GWIN_NEED_CHECKBOX FALSE - #define GWIN_NEED_IMAGE FALSE - #define GWIN_NEED_IMAGE_ANIMATION FALSE - #define GWIN_NEED_RADIO FALSE - #define GWIN_NEED_LIST FALSE - #define GWIN_NEED_LIST_IMAGES FALSE - #define GWIN_NEED_PROGRESSBAR FALSE - #define GWIN_NEED_FRAME FALSE - /////////////////////////////////////////////////////////////////////////// // GEVENT // /////////////////////////////////////////////////////////////////////////// #define GFX_USE_GEVENT TRUE -#define GEVENT_ASSERT_NO_RESOURCE FALSE -#define GEVENT_MAXIMUM_SIZE 32 -#define GEVENT_MAX_SOURCE_LISTENERS 32 - - /////////////////////////////////////////////////////////////////////////// // GTIMER // /////////////////////////////////////////////////////////////////////////// #define GFX_USE_GTIMER TRUE -#define GTIMER_THREAD_PRIORITY HIGH_PRIORITY -#define GTIMER_THREAD_WORKAREA_SIZE 2048 - - /////////////////////////////////////////////////////////////////////////// // GQUEUE // /////////////////////////////////////////////////////////////////////////// #define GFX_USE_GQUEUE TRUE #define GQUEUE_NEED_ASYNC TRUE -#define GQUEUE_NEED_GSYNC FALSE -#define GQUEUE_NEED_FSYNC FALSE -#define GQUEUE_NEED_BUFFERS FALSE /////////////////////////////////////////////////////////////////////////// // GINPUT // @@ -185,59 +73,5 @@ #define GFX_USE_GINPUT TRUE #define GINPUT_NEED_MOUSE TRUE -#define GINPUT_NEED_KEYBOARD FALSE -#define GINPUT_NEED_TOGGLE FALSE -#define GINPUT_NEED_DIAL FALSE - - -/////////////////////////////////////////////////////////////////////////// -// GFILE // -/////////////////////////////////////////////////////////////////////////// -#define GFX_USE_GFILE FALSE - -#define GFILE_NEED_PRINTG FALSE -#define GFILE_NEED_SCANG FALSE -#define GFILE_NEED_STRINGS FALSE -#define GFILE_NEED_STDIO FALSE - #define GFILE_ALLOW_FLOATS FALSE - #define GFILE_ALLOW_DEVICESPECIFIC FALSE - #define GFILE_MAX_GFILES 3 - -#define GFILE_NEED_MEMFS FALSE -#define GFILE_NEED_ROMFS FALSE -#define GFILE_NEED_RAMFS FALSE -#define GFILE_NEED_FATFS FALSE -#define GFILE_NEED_NATIVEFS FALSE -#define GFILE_NEED_CHBIOSFS FALSE - - -/////////////////////////////////////////////////////////////////////////// -// GADC // -/////////////////////////////////////////////////////////////////////////// -#define GFX_USE_GADC FALSE - -#define GADC_MAX_LOWSPEED_DEVICES 4 - - -/////////////////////////////////////////////////////////////////////////// -// GAUDIO // -/////////////////////////////////////////////////////////////////////////// -#define GFX_USE_GAUDIO FALSE - #define GAUDIO_NEED_PLAY FALSE - #define GAUDIO_NEED_RECORD FALSE - - -/////////////////////////////////////////////////////////////////////////// -// GMISC // -/////////////////////////////////////////////////////////////////////////// -#define GFX_USE_GMISC FALSE - -#define GMISC_NEED_ARRAYOPS FALSE -#define GMISC_NEED_FASTTRIG FALSE -#define GMISC_NEED_FIXEDTRIG FALSE -#define GMISC_NEED_INVSQRT FALSE - #define GMISC_INVSQRT_MIXED_ENDIAN FALSE - #define GMISC_INVSQRT_REAL_SLOW FALSE - #endif /* _GFXCONF_H */ From ffa03cb57042e9460f6193e5a284a3760b1b348f Mon Sep 17 00:00:00 2001 From: inmarket Date: Wed, 17 Sep 2014 08:43:11 +1000 Subject: [PATCH 05/87] SImplify the options for multiple displays. This will also be more compatible with newmouse infrastructure --- .../modules/gdisp/multiple_displays/gfxconf.h | 28 +++-- demos/modules/gdisp/multiple_displays/main.c | 10 +- drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c | 62 +++++----- gfxconf.example.h | 6 +- src/gdisp/driver.h | 40 +++---- src/gdisp/gdisp_gdisp.c | 111 +++++++----------- src/gdisp/sys_defs.h | 28 +++-- src/gdisp/sys_options.h | 50 +++----- src/gdisp/sys_rules.h | 13 +- 9 files changed, 155 insertions(+), 193 deletions(-) diff --git a/demos/modules/gdisp/multiple_displays/gfxconf.h b/demos/modules/gdisp/multiple_displays/gfxconf.h index 60467f93..959f1d0b 100644 --- a/demos/modules/gdisp/multiple_displays/gfxconf.h +++ b/demos/modules/gdisp/multiple_displays/gfxconf.h @@ -46,16 +46,20 @@ #define GDISP_INCLUDE_FONT_UI2 TRUE -#define GDISP_TOTAL_DISPLAYS 2 - -/* Uncomment the following lines if you want to use multiple displays on - * different controllers. +/* You must either define GDISP_TOTAL_DISPLAYS or GDISP_DRIVER_LIST for multiple displays. + * You cannot define both! * - * Change the definitions to suit your hardware. - * Currently all controllers must use the same pixel format. + * Defining GDISP_TOTAL_DISPLAYS will create multiple instances of the one default driver. + * Defining GDISP_DRIVER_LIST allows you to specify multiple different drivers. * - * Remember that GDISP_TOTAL_DISPLAYS above must match the **Total** - * number of displays in your system across all controllers. + * Extra Notes for GDISP_DRIVER_LIST: + *----------------------------------- + * + * The same controller can appear more than once in the list. + * + * You must specify a GDISP_PIXELFORMAT that the application will work in. This + * is translated into each drivers internal pixel format by the driver. You the + * pixel format that is most common accross your drivers (for efficiency). * * Optionally, you can also specify hardware characteristics that are common to * all your controllers. This significantly improves code and speed efficiency @@ -72,9 +76,9 @@ * #define GDISP_HARDWARE_DRAWPIXEL TRUE * #define GDISP_HARDWARE_FILLS TRUE */ -//#define GDISP_TOTAL_CONTROLLERS 2 -//#define GDISP_CONTROLLER_LIST GDISPVMT_Win32, GDISPVMT_Win32 -//#define GDISP_CONTROLLER_DISPLAYS 1, 1 -//#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB888 +#define GDISP_TOTAL_DISPLAYS 2 + +//#define GDISP_DRIVER_LIST GDISPVMT_Win32, GDISPVMT_Win32 +//#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB888 #endif /* _GFXCONF_H */ diff --git a/demos/modules/gdisp/multiple_displays/main.c b/demos/modules/gdisp/multiple_displays/main.c index 4e8a5a08..c4c37bed 100644 --- a/demos/modules/gdisp/multiple_displays/main.c +++ b/demos/modules/gdisp/multiple_displays/main.c @@ -46,7 +46,7 @@ #if USE_METHOD_1 int main(void) { coord_t width, height; - coord_t display, i, j; + coord_t display, i, j, cnt; font_t f; GDisplay *g; char buf[16]; @@ -58,7 +58,8 @@ f = gdispOpenFont("*"); /* Cycle through each display */ - for(display = 0; display < GDISP_TOTAL_DISPLAYS; display++) { + cnt = gdispGetDisplayCount(); + for(display = 0; display < cnt; display++) { // Get the specified display g = gdispGetDisplay(display); @@ -84,7 +85,7 @@ #else int main(void) { coord_t width, height; - coord_t display, i, j; + coord_t display, i, j, cnt; font_t f; char buf[16]; @@ -95,7 +96,8 @@ f = gdispOpenFont("*"); /* Cycle through each display */ - for(display = 0; display < GDISP_TOTAL_DISPLAYS; display++) { + cnt = gdispGetDisplayCount(); + for(display = 0; display < cnt; display++) { // Set the default display to the specified display gdispSetDisplay(gdispGetDisplay(display)); diff --git a/drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c b/drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c index 802f2822..e96ad3b2 100644 --- a/drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c +++ b/drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c @@ -205,20 +205,18 @@ static DECLARE_THREAD_FUNCTION(NetThread, param) { gfxHalt("GDISP: uGFXnet - Accept failed"); // Look for a display that isn't connected - for(disp = 0; disp < GDISP_TOTAL_DISPLAYS; disp++) { - if (!(g = gdispGetDisplay(disp))) - continue; - #if GDISP_TOTAL_CONTROLLERS > 1 - // Ignore displays for other controllers - if (g->vmt != &GDISPVMT_uGFXnet) - continue; - #endif + for(g = 0; (g = (GDisplay *)gdriverGetNext(GDRIVER_TYPE_DISPLAY, (GDriver *)g));) { + // Ignore displays for other controllers + #ifdef GDISP_DRIVER_LIST + if (gvmt(g) != &GDISPVMT_uGFXnet) + continue; + #endif if (!(g->flags & GDISP_FLG_CONNECTED)) break; } // Was anything found? - if (disp >= GDISP_TOTAL_DISPLAYS) { + if (!g) { // No Just close the connection closesocket(clientfd); gfxHalt("GDISP: uGFXnet - Can't find display for connection"); @@ -275,21 +273,19 @@ static DECLARE_THREAD_FUNCTION(NetThread, param) { if((clientfd = accept(listenfd, (struct sockaddr *)&addr, &len)) == (SOCKET_TYPE)-1) gfxHalt("GDISP: uGFXnet - Accept failed"); - // Look for a display that isn't connected - for(disp = 0; disp < GDISP_TOTAL_DISPLAYS; disp++) { - if (!(g = gdispGetDisplay(disp))) - continue; - #if GDISP_TOTAL_CONTROLLERS > 1 - // Ignore displays for other controllers - if (g->vmt != &GDISPVMT_uGFXnet) - continue; - #endif - if (!(g->flags & GDISP_FLG_CONNECTED)) - break; - } + // Look for a display that isn't connected + for(g = 0; (g = (GDisplay *)gdriverGetNext(GDRIVER_TYPE_DISPLAY, (GDriver *)g));) { + // Ignore displays for other controllers + #ifdef GDISP_DRIVER_LIST + if (gvmt(g) != &GDISPVMT_uGFXnet) + continue; + #endif + if (!(g->flags & GDISP_FLG_CONNECTED)) + break; + } // Was anything found? - if (disp >= GDISP_TOTAL_DISPLAYS) { + if (!g) { // No Just close the connection closesocket(clientfd); //printf(New connection from %s on socket %d rejected as all displays are already connected\n", inet_ntoa(addr.sin_addr), clientfd); @@ -332,19 +328,17 @@ static DECLARE_THREAD_FUNCTION(NetThread, param) { // Handle data from a client // Look for a display that is connected and the socket descriptor matches - for(disp = 0; disp < GDISP_TOTAL_DISPLAYS; disp++) { - if (!(g = gdispGetDisplay(disp))) - continue; - #if GDISP_TOTAL_CONTROLLERS > 1 - // Ignore displays for other controllers - if (g->vmt != &GDISPVMT_uGFXnet) - continue; - #endif + for(g = 0; (g = (GDisplay *)gdriverGetNext(GDRIVER_TYPE_DISPLAY, (GDriver *)g));) { + // Ignore displays for other controllers + #ifdef GDISP_DRIVER_LIST + if (gvmt(g) != &GDISPVMT_uGFXnet) + continue; + #endif priv = g->priv; if ((g->flags & GDISP_FLG_CONNECTED) && priv->netfd == i) break; - } - if (disp >= GDISP_TOTAL_DISPLAYS) + } + if (!g) gfxHalt("GDISP: uGFXnet - Got data from unrecognized connection"); if ((g->flags & GDISP_FLG_HAVEDATA)) { @@ -538,7 +532,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { // Make everything relative to the start of the line buffer = g->p.ptr; buffer += g->p.x2*g->p.y1; - + priv = g->priv; buf[0] = GNETCODE_BLIT; buf[1] = g->p.x; @@ -583,7 +577,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { // Now wait for a reply while(!(g->flags & GDISP_FLG_HAVEDATA) || priv->data[0] != GNETCODE_READ) gfxSleepMilliseconds(1); - + data = gdispNative2Color(priv->data[1]); g->flags &= ~GDISP_FLG_HAVEDATA; diff --git a/gfxconf.example.h b/gfxconf.example.h index 9b5ba477..205c79d3 100644 --- a/gfxconf.example.h +++ b/gfxconf.example.h @@ -108,8 +108,8 @@ //#define GDISP_TOTAL_DISPLAYS 1 -//#define GDISP_TOTAL_CONTROLLERS 1 -// #if GDISP_TOTAL_CONTROLLERS > 1 +//#define GDISP_DRIVER_LIST GDISPVMT_Win32, GDISPVMT_Win32 +// #ifdef GDISP_DRIVER_LIST // // For code and speed optimization define as TRUE or FALSE if all controllers have the same capability // #define GDISP_HARDWARE_STREAM_WRITE FALSE // #define GDISP_HARDWARE_STREAM_READ FALSE @@ -124,8 +124,6 @@ // #define GDISP_HARDWARE_QUERY FALSE // #define GDISP_HARDWARE_CLIP FALSE -// #define GDISP_CONTROLLER_LIST GDISPVMT_Win32, GDISPVMT_Win32 -// #define GDISP_CONTROLLER_DISPLAYS 1, 1 // #define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB888 // #endif diff --git a/src/gdisp/driver.h b/src/gdisp/driver.h index 3b77c568..10f9fd87 100644 --- a/src/gdisp/driver.h +++ b/src/gdisp/driver.h @@ -24,7 +24,7 @@ // Our special auto-detect hardware code which uses the VMT. #define HARDWARE_AUTODETECT 2 -#if GDISP_TOTAL_CONTROLLERS > 1 && !defined(GDISP_DRIVER_VMT) +#if defined(GDISP_DRIVER_LIST) && !defined(GDISP_DRIVER_VMT) // Multiple controllers the default is to hardware detect #define HARDWARE_DEFAULT HARDWARE_AUTODETECT #else @@ -40,7 +40,7 @@ * @brief The display hardware can benefit from being de-initialized when usage is complete. * @details Can be set to TRUE, FALSE or HARDWARE_AUTODETECT * - * @note HARDWARE_AUTODETECT is only meaningful when GDISP_TOTAL_CONTROLLERS > 1 + * @note HARDWARE_AUTODETECT is only meaningful when GDISP_DRIVER_LIST is defined * @note This is most useful for displays such as remote network displays. */ #ifndef GDISP_HARDWARE_DEINIT @@ -51,7 +51,7 @@ * @brief The display hardware can benefit from being flushed. * @details Can be set to TRUE, FALSE or HARDWARE_AUTODETECT * - * @note HARDWARE_AUTODETECT is only meaningful when GDISP_TOTAL_CONTROLLERS > 1 + * @note HARDWARE_AUTODETECT is only meaningful when GDISP_DRIVER_LIST is defined * @note Some controllers ** require ** the application to flush */ #ifndef GDISP_HARDWARE_FLUSH @@ -62,7 +62,7 @@ * @brief Hardware streaming writing is supported. * @details Can be set to TRUE, FALSE or HARDWARE_AUTODETECT * - * @note HARDWARE_AUTODETECT is only meaningful when GDISP_TOTAL_CONTROLLERS > 1 + * @note HARDWARE_AUTODETECT is only meaningful when GDISP_DRIVER_LIST is defined * @note Either GDISP_HARDWARE_STREAM_WRITE or GDISP_HARDWARE_DRAWPIXEL must be provided by each driver */ #ifndef GDISP_HARDWARE_STREAM_WRITE @@ -73,7 +73,7 @@ * @brief Hardware streaming reading of the display surface is supported. * @details Can be set to TRUE, FALSE or HARDWARE_AUTODETECT * - * @note HARDWARE_AUTODETECT is only meaningful when GDISP_TOTAL_CONTROLLERS > 1 + * @note HARDWARE_AUTODETECT is only meaningful when GDISP_DRIVER_LIST is defined * */ #ifndef GDISP_HARDWARE_STREAM_READ @@ -84,7 +84,7 @@ * @brief Hardware supports setting the cursor position within the stream window. * @details Can be set to TRUE, FALSE or HARDWARE_AUTODETECT * - * @note HARDWARE_AUTODETECT is only meaningful when GDISP_TOTAL_CONTROLLERS > 1 + * @note HARDWARE_AUTODETECT is only meaningful when GDISP_DRIVER_LIST is defined * @note This is used to optimise setting of individual pixels within a stream window. * It should therefore not be implemented unless it is cheaper than just setting * a new window. @@ -97,7 +97,7 @@ * @brief Hardware accelerated draw pixel. * @details Can be set to TRUE, FALSE or HARDWARE_AUTODETECT * - * @note HARDWARE_AUTODETECT is only meaningful when GDISP_TOTAL_CONTROLLERS > 1 + * @note HARDWARE_AUTODETECT is only meaningful when GDISP_DRIVER_LIST is defined * @note Either GDISP_HARDWARE_STREAM_WRITE or GDISP_HARDWARE_DRAWPIXEL must be provided by the driver */ #ifndef GDISP_HARDWARE_DRAWPIXEL @@ -108,7 +108,7 @@ * @brief Hardware accelerated screen clears. * @details Can be set to TRUE, FALSE or HARDWARE_AUTODETECT * - * @note HARDWARE_AUTODETECT is only meaningful when GDISP_TOTAL_CONTROLLERS > 1 + * @note HARDWARE_AUTODETECT is only meaningful when GDISP_DRIVER_LIST is defined * @note This clears the entire display surface regardless of the clipping area currently set */ #ifndef GDISP_HARDWARE_CLEARS @@ -119,7 +119,7 @@ * @brief Hardware accelerated rectangular fills. * @details Can be set to TRUE, FALSE or HARDWARE_AUTODETECT * - * @note HARDWARE_AUTODETECT is only meaningful when GDISP_TOTAL_CONTROLLERS > 1 + * @note HARDWARE_AUTODETECT is only meaningful when GDISP_DRIVER_LIST is defined */ #ifndef GDISP_HARDWARE_FILLS #define GDISP_HARDWARE_FILLS HARDWARE_DEFAULT @@ -129,7 +129,7 @@ * @brief Hardware accelerated fills from an image. * @details Can be set to TRUE, FALSE or HARDWARE_AUTODETECT * - * @note HARDWARE_AUTODETECT is only meaningful when GDISP_TOTAL_CONTROLLERS > 1 + * @note HARDWARE_AUTODETECT is only meaningful when GDISP_DRIVER_LIST is defined */ #ifndef GDISP_HARDWARE_BITFILLS #define GDISP_HARDWARE_BITFILLS HARDWARE_DEFAULT @@ -139,7 +139,7 @@ * @brief Hardware accelerated scrolling. * @details Can be set to TRUE, FALSE or HARDWARE_AUTODETECT * - * @note HARDWARE_AUTODETECT is only meaningful when GDISP_TOTAL_CONTROLLERS > 1 + * @note HARDWARE_AUTODETECT is only meaningful when GDISP_DRIVER_LIST is defined */ #ifndef GDISP_HARDWARE_SCROLL #define GDISP_HARDWARE_SCROLL HARDWARE_DEFAULT @@ -149,7 +149,7 @@ * @brief Reading back of pixel values. * @details Can be set to TRUE, FALSE or HARDWARE_AUTODETECT * - * @note HARDWARE_AUTODETECT is only meaningful when GDISP_TOTAL_CONTROLLERS > 1 + * @note HARDWARE_AUTODETECT is only meaningful when GDISP_DRIVER_LIST is defined */ #ifndef GDISP_HARDWARE_PIXELREAD #define GDISP_HARDWARE_PIXELREAD HARDWARE_DEFAULT @@ -159,7 +159,7 @@ * @brief The driver supports one or more control commands. * @details Can be set to TRUE, FALSE or HARDWARE_AUTODETECT * - * @note HARDWARE_AUTODETECT is only meaningful when GDISP_TOTAL_CONTROLLERS > 1 + * @note HARDWARE_AUTODETECT is only meaningful when GDISP_DRIVER_LIST is defined */ #ifndef GDISP_HARDWARE_CONTROL #define GDISP_HARDWARE_CONTROL HARDWARE_DEFAULT @@ -169,7 +169,7 @@ * @brief The driver supports a non-standard query. * @details Can be set to TRUE, FALSE or HARDWARE_AUTODETECT * - * @note HARDWARE_AUTODETECT is only meaningful when GDISP_TOTAL_CONTROLLERS > 1 + * @note HARDWARE_AUTODETECT is only meaningful when GDISP_DRIVER_LIST is defined */ #ifndef GDISP_HARDWARE_QUERY #define GDISP_HARDWARE_QUERY HARDWARE_DEFAULT @@ -179,7 +179,7 @@ * @brief The driver supports a clipping in hardware. * @details Can be set to TRUE, FALSE or HARDWARE_AUTODETECT * - * @note HARDWARE_AUTODETECT is only meaningful when GDISP_TOTAL_CONTROLLERS > 1 + * @note HARDWARE_AUTODETECT is only meaningful when GDISP_DRIVER_LIST is defined * @note If this is defined the driver must perform its own clipping on all calls to * the driver and respond appropriately if a parameter is outside the display area. * @note If this is not defined then the software ensures that all calls to the @@ -310,16 +310,16 @@ typedef struct GDISPVMT { } GDISPVMT; // Do we need function definitions or macro's (via the VMT) -#if GDISP_TOTAL_CONTROLLERS <= 1 || defined(GDISP_DRIVER_VMT) || defined(__DOXYGEN__) +#if !defined(GDISP_DRIVER_LIST) || defined(GDISP_DRIVER_VMT) || defined(__DOXYGEN__) #ifdef __cplusplus extern "C" { #endif // Should the driver routines should be static or not - #if GDISP_TOTAL_CONTROLLERS <= 1 - #define LLDSPEC + #if defined(GDISP_DRIVER_LIST) + #define LLDSPEC static #else - #define LLDSPEC static + #define LLDSPEC #endif /** @@ -611,7 +611,7 @@ typedef struct GDISPVMT { #endif // If we are not using multiple displays then hard-code the VMT name - #ifndef GDISP_CONTROLLER_LIST + #if !defined(GDISP_DRIVER_LIST) #undef GDISP_DRIVER_VMT #define GDISP_DRIVER_VMT GDISPVMT_OnlyOne #endif diff --git a/src/gdisp/gdisp_gdisp.c b/src/gdisp/gdisp_gdisp.c index a34788b2..0e5cacb5 100644 --- a/src/gdisp/gdisp_gdisp.c +++ b/src/gdisp/gdisp_gdisp.c @@ -566,45 +566,24 @@ static void line_clip(GDisplay *g) { void _gdispInit(void) { - // Both GDISP_CONTROLLER_LIST and GDISP_CONTROLLER_DISPLAYS are defined - create the required numbers of each controller - #if defined(GDISP_CONTROLLER_LIST) && defined(GDISP_CONTROLLER_DISPLAYS) - { - int i, cnt; - - extern GDriverVMTList GDISP_CONTROLLER_LIST; - static const struct GDriverVMT const * dclist[GDISP_TOTAL_CONTROLLERS] = {GDISP_CONTROLLER_LIST}; - static const unsigned dnlist[GDISP_TOTAL_CONTROLLERS] = {GDISP_CONTROLLER_DISPLAYS}; - - for(i = 0; i < GDISP_TOTAL_CONTROLLERS; i++) { - for(cnt = dnlist[i]; cnt; cnt--) - gdriverRegister(dclist[i]); - } - } - - // Only GDISP_CONTROLLER_LIST is defined - create one of each controller - #elif defined(GDISP_CONTROLLER_LIST) + // GDISP_DRIVER_LIST is defined - create each driver instance + #if defined(GDISP_DRIVER_LIST) { int i; - extern GDriverVMTList GDISP_CONTROLLER_LIST; - static const struct GDriverVMT const * dclist[GDISP_TOTAL_CONTROLLERS] = {GDISP_CONTROLLER_LIST}; + extern GDriverVMTList GDISP_DRIVER_LIST; + static const struct GDriverVMT const * dclist[] = {GDISP_DRIVER_LIST}; - for(i = 0; i < GDISP_TOTAL_CONTROLLERS; i++) + for(i = 0; i < sizeof(dclist)/sizeof(dclist[0]); i++) gdriverRegister(dclist[i]); } - - // Only GDISP_TOTAL_DISPLAYS is defined - create the required number of the one controller #elif GDISP_TOTAL_DISPLAYS > 1 { - int cnt; + int i; - extern GDriverVMTList GDISPVMT_OnlyOne; - - for(cnt = 0; cnt < GDISP_TOTAL_DISPLAYS; cnt++) + for(i = 0; i < GDISP_TOTAL_DISPLAYS; i++) gdriverRegister(GDISPVMT_OnlyOne); } - - // One and only one display #else { extern GDriverVMTList GDISPVMT_OnlyOne; @@ -715,10 +694,6 @@ void _gdispDeInitDriver(GDriver *g) { #undef gd } -GDisplay *gdispGetDisplay(unsigned display) { - return (GDisplay *)gdriverGetInstance(GDRIVER_TYPE_DISPLAY, display); -} - void gdispSetDisplay(GDisplay *g) { if (g) GDISP = g; } @@ -1001,7 +976,7 @@ void gdispGDrawPixel(GDisplay *g, coord_t x, coord_t y, color_t color) { autoflush(g); MUTEX_EXIT(g); } - + void gdispGDrawLine(GDisplay *g, coord_t x0, coord_t y0, coord_t x1, coord_t y1, color_t color) { MUTEX_ENTER(g); g->p.x = x0; @@ -1110,7 +1085,7 @@ void gdispGFillArea(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, c autoflush_stopdone(g); MUTEX_EXIT(g); } - + void gdispGBlitArea(GDisplay *g, 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) { MUTEX_ENTER(g); @@ -1246,7 +1221,7 @@ void gdispGBlitArea(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, c } #endif } - + #if GDISP_NEED_CLIP || GDISP_NEED_VALIDATION void gdispGSetClip(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy) { MUTEX_ENTER(g); @@ -1400,7 +1375,7 @@ void gdispGBlitArea(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, c MUTEX_EXIT(g); } #endif - + #if GDISP_NEED_ELLIPSE void gdispGFillEllipse(GDisplay *g, coord_t x, coord_t y, coord_t a, coord_t b, color_t color) { coord_t dx, dy; @@ -2662,7 +2637,7 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co } } } - + static int32_t rounding_div(const int32_t n, const int32_t d) { if ((n < 0) != (d < 0)) @@ -2670,23 +2645,23 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co else return (n + d/2) / d; } - + /* Find a vector (nx, ny) that is perpendicular to (dx, dy) and has length * equal to 'norm'. */ static void get_normal_vector(coord_t dx, coord_t dy, coord_t norm, coord_t *nx, coord_t *ny) { int32_t dx2, dy2, len_sq, norm_sq, norm_sq2; int div, step, best, delta, abs_delta; - + dx2 = dx; dy2 = dy; norm_sq = (int32_t)norm * norm; norm_sq2 = norm_sq * 512; - + /* Scale dx2 and dy2 so that * len_sq / 2 <= norm_sq * 512 <= len_sq * 2. * The scaling by 512 is to yield higher accuracy in division later. */ len_sq = dx2 * dx2 + dy2 * dy2; - + if (len_sq < norm_sq2) { while (len_sq && len_sq < norm_sq2) @@ -2701,69 +2676,69 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co len_sq >>= 2; dx2 >>= 1; dy2 >>= 1; } } - + /* Now find the divider div so that * len_sq / div^2 == norm_sq i.e. div = sqrt(len_sq / norm_sq) * * This is done using bisection search to avoid the need for floating * point sqrt. - * + * * Based on previous scaling, we know that * len_sq / 2 <= norm_sq * 512 <=> div <= sqrt(1024) = 32 * len_sq * 2 >= norm_sq * 512 <=> div >= sqrt(256) = 16 */ div = 24; step = 8; best = 256; - + for (;;) { dx = dx2 / div; dy = dy2 / div; len_sq = dx*dx + dy*dy; - + delta = len_sq - norm_sq; - + abs_delta = (delta >= 0) ? delta : -delta; - + if (abs_delta < best) { *nx = dy; *ny = -dx; best = abs_delta; } - + if (delta > 0) div += step; else if (delta < 0) div -= step; else if (delta == 0) break; - + if (step == 0) break; else step >>= 1; /* Do one round with step = 0 to calculate final result. */ } } - + void gdispGDrawThickLine(GDisplay *g, coord_t x0, coord_t y0, coord_t x1, coord_t y1, color_t color, coord_t width, bool_t round) { coord_t dx, dy, nx = 0, ny = 0; - + /* Compute the direction vector for the line */ dx = x1 - x0; dy = y1 - y0; - + /* Draw a small dot if the line length is zero. */ if (dx == 0 && dy == 0) dx += 1; - + /* Compute a normal vector with length 'width'. */ get_normal_vector(dx, dy, width, &nx, &ny); - + /* Handle 1px wide lines gracefully */ if (nx == 0 && ny == 0) nx = 1; - + /* Offset the x0,y0 by half the width of the line. This way we * can keep the width of the line accurate even if it is not evenly * divisible by 2. @@ -2772,11 +2747,11 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co x0 -= rounding_div(nx, 2); y0 -= rounding_div(ny, 2); } - + /* Fill in the point array */ if (!round) { /* We use 4 points for the basic line shape: - * + * * pt1 pt2 * (+n) ------------------------------------ (d+n) * | | @@ -2784,7 +2759,7 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co * pt0 pt3 */ point pntarray[4]; - + pntarray[0].x = 0; pntarray[0].y = 0; pntarray[1].x = nx; @@ -2793,7 +2768,7 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co pntarray[2].y = dy + ny; pntarray[3].x = dx; pntarray[3].y = dy; - + gdispGFillConvexPoly(g, x0, y0, pntarray, 4, color); } else { /* We use 4 points for basic shape, plus 4 extra points for ends: @@ -2808,26 +2783,26 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co */ point pntarray[8]; coord_t nx2, ny2; - + /* Magic numbers: * 75/256 = sin(45) / (1 + sqrt(2)) diagonal octagon segments * 106/256 = 1 / (1 + sqrt(2)) octagon side * 53/256 = 0.5 / (1 + sqrt(2)) half of octagon side * 150/256 = 1 - 1 / (1 + sqrt(2)) octagon height minus one side */ - + /* Rotate the normal vector 45 deg counter-clockwise and reduce * to 1 / (1 + sqrt(2)) length, for forming octagonal ends. */ nx2 = rounding_div((nx * 75 + ny * 75), 256); ny2 = rounding_div((-nx * 75 + ny * 75), 256); - + /* Offset and extend the line so that the center of the octagon * is at the specified points. */ x0 += ny * 53 / 256; y0 -= nx * 53 / 256; dx -= ny * 106 / 256; dy += nx * 106 / 256; - + /* Now fill in the points by summing the calculated vectors. */ pntarray[0].x = 0; pntarray[0].y = 0; @@ -2845,7 +2820,7 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co pntarray[6].y = dy + ny * 150/256 - ny2; pntarray[7].x = dx; pntarray[7].y = dy; - + gdispGFillConvexPoly(g, x0, y0, pntarray, 8, color); } } @@ -3099,19 +3074,19 @@ color_t gdispBlendColor(color_t fg, color_t bg, uint8_t alpha) uint16_t fg_ratio = alpha + 1; uint16_t bg_ratio = 256 - alpha; uint16_t r, g, b; - + r = RED_OF(fg) * fg_ratio; g = GREEN_OF(fg) * fg_ratio; b = BLUE_OF(fg) * fg_ratio; - + r += RED_OF(bg) * bg_ratio; g += GREEN_OF(bg) * bg_ratio; b += BLUE_OF(bg) * bg_ratio; - + r >>= 8; g >>= 8; b >>= 8; - + return RGB2COLOR(r, g, b); } diff --git a/src/gdisp/sys_defs.h b/src/gdisp/sys_defs.h index d67fdcee..0d51d639 100644 --- a/src/gdisp/sys_defs.h +++ b/src/gdisp/sys_defs.h @@ -111,7 +111,7 @@ extern GDisplay *GDISP; /* Defines relating to the display hardware */ /*===========================================================================*/ -#if GDISP_TOTAL_CONTROLLERS <= 1 +#if !defined(GDISP_DRIVER_LIST) // Pull in the default hardware configuration for a single controller. // If we have multiple controllers the settings must be set in the // users gfxconf.h file. @@ -133,7 +133,7 @@ extern GDisplay *GDISP; * @details It generally defaults to the hardware pixel format. * @note This doesn't need to match the hardware pixel format. * It is definitely more efficient when it does. - * @note When GDISP_TOTAL_CONTROLLERS > 1, this must + * @note When GDISP_DRIVER_LIST is defined, this must * be explicitly defined and you should ensure the best match * with your hardware across all devices. */ @@ -213,13 +213,13 @@ color_t gdispContrastColor(color_t color); * @note The GDISP variable contains the display used by the gdispXxxx routines * as opposed to the gdispGXxxx routines which take an explicit display * parameter. - * @note Displays are numbered from 0 to GDISP_TOTAL_DISPLAYS - 1 + * @note Displays are numbered from 0 to @p gdispGetDisplayCount() - 1 * * @param[in] display The display number (0..n) * * @api */ -GDisplay *gdispGetDisplay(unsigned display); +#define gdispGetDisplay(display) ((GDisplay *)gdriverGetInstance(GDRIVER_TYPE_DISPLAY, display)) /** * @brief Set the current default display to the specified display @@ -235,6 +235,14 @@ GDisplay *gdispGetDisplay(unsigned display); */ void gdispSetDisplay(GDisplay *g); +/** + * @brief Get the count of currently active displays + * @return The count of displays currently in the system + * + * @note Displays are numbered from 0 to @p gdispGetDisplayCount() - 1 + */ +#define gdispGetDisplayCount() gdriverInstanceCount(GDRIVER_TYPE_DISPLAY) + /* Property Functions */ /** @@ -683,20 +691,20 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co */ void gdispGFillConvexPoly(GDisplay *g, coord_t tx, coord_t ty, const point *pntarray, unsigned cnt, color_t color); #define gdispFillConvexPoly(x,y,p,i,c) gdispGFillConvexPoly(GDISP,x,y,p,i,c) - + /** * @brief Draw a line with a specified thickness * @details The line thickness is specified in pixels. The line ends can * be selected to be either flat or round. * @note Uses gdispGFillConvexPoly() internally to perform the drawing. - * + * * @param[in] g The display to use * @param[in] x0,y0 The start position * @param[in] x1,y1 The end position * @param[in] color The color to use * @param[in] width The width of the line * @param[in] round Use round ends for the line - * + * * @api */ void gdispGDrawThickLine(GDisplay *g, coord_t x0, coord_t y0, coord_t x1, coord_t y1, color_t color, coord_t width, bool_t round); @@ -857,13 +865,13 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co * @brief Make a scaled copy of an existing font. * @details Allocates memory for new font metadata using gfxAlloc, remember to close font after use! * @return A new font or NULL if out of memory. - * + * * @param[in] font The base font to use. * @param[in] scale_x The scale factor in horizontal direction. * @param[in] scale_y The scale factor in vertical direction. */ font_t gdispScaleFont(font_t font, uint8_t scale_x, uint8_t scale_y); - + /** * @brief Get the name of the specified font. * @returns The name of the font. @@ -907,7 +915,7 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co #define gdispFillRoundedBox(x,y,cx,cy,r,c) gdispGFillRoundedBox(GDISP,x,y,cx,cy,r,c) #endif -/* +/* * Macro definitions */ diff --git a/src/gdisp/sys_options.h b/src/gdisp/sys_options.h index 466bbb98..855f22ff 100644 --- a/src/gdisp/sys_options.h +++ b/src/gdisp/sys_options.h @@ -184,42 +184,26 @@ * @{ */ /** - * @brief The total number of displays. - * @note This can be on just one type of controller or spread across several different controllers + * @brief The total number of displays using the default driver. + * @note If you want to use multiple displays either set GDISP_TOTAL_DISPLAYS or GDISP_DRIVER_LIST + * but not both. */ #ifndef GDISP_TOTAL_DISPLAYS #define GDISP_TOTAL_DISPLAYS 1 #endif - /** - * @brief The total number of controllers. - * @note If this is greater than one, all the hardware acceleration options below - * and the pixel format must be manually specified in your gfxconf.h along with - * @p GDISP_CONTROLLER_LIST. See the gdisp_lld_config.h in each driver to get a list - * of hardware capabilities for each driver in order to work out the common set across - * all the controllers you want to use. - */ - #ifndef GDISP_TOTAL_CONTROLLERS - #define GDISP_TOTAL_CONTROLLERS 1 - #endif - #if defined(__DOXYGEN__) /** - * @brief The list of controllers. - * @note This is required if @p GDISP_TOTAL_CONTROLLERS is greater than one. - * @note The number of entries must match @p GDISP_TOTAL_CONTROLLERS. - * @note See the gdisp_lld.c in each driver (near the top) to get the name of the VMT for a driver. - * @note Replace this example with your own definition in your gfxconf.h file. + * @brief The list of display drivers. + * @note Replace this example with your own definition in your gfxconf.h file. See the gdisp_lld.c + * in each driver (near the top) to get the name of the VMT for a driver. + * @note The same driver can occur more than once in the list to create an extra instance of that driver. + * @note If defining this you must also define GDISP_PIXELFORMAT for your application to use. + * Choose a value that is most common accross all your drivers for efficiency. + * @note If using this you may optionally define the GDISP_HARDWARE_xxx values as either TRUE or FALSE. + * Doing this causes GDISP to assume that all (TRUE) or none (FALSE) of the listed drivers have that + * capability. This can help improve drawing speed and efficiency. */ - #define GDISP_CONTROLLER_LIST GDISPVMT_Win32, GDISPVMT_SSD1963 - /** - * @brief The number of displays for each controller. - * @note This is required if @p GDISP_TOTAL_CONTROLLERS is greater than one. - * @note The number of entries must match @p GDISP_TOTAL_CONTROLLERS. - * @note The sum of all the display counts must equal @p GDISP_TOTAL_DISPLAYS (3 for this example) - * or bad things will happen. - * @note Replace this example with your own definition in your gfxconf.h file. - */ - #define GDISP_CONTROLLER_DISPLAYS 2, 1 + #define GDISP_DRIVER_LIST GDISPVMT_Win32, GDISPVMT_SSD1963 #endif /** * @} @@ -272,7 +256,7 @@ #endif /** * @} - * + * * @name GDISP Text Rendering Options * @{ */ @@ -283,7 +267,7 @@ #ifndef GDISP_NEED_UTF8 #define GDISP_NEED_UTF8 FALSE #endif - + /** * @brief Enable kerning for font rendering (improves character placement). * @details Defaults to FALSE @@ -291,7 +275,7 @@ #ifndef GDISP_NEED_TEXT_KERNING #define GDISP_NEED_TEXT_KERNING FALSE #endif - + /** * @brief Enable antialiased font support * @details Defaults to FALSE @@ -299,7 +283,7 @@ #ifndef GDISP_NEED_ANTIALIAS #define GDISP_NEED_ANTIALIAS FALSE #endif - + /** * @} * diff --git a/src/gdisp/sys_rules.h b/src/gdisp/sys_rules.h index eca55ce3..90b07138 100644 --- a/src/gdisp/sys_rules.h +++ b/src/gdisp/sys_rules.h @@ -24,15 +24,12 @@ #undef GFX_USE_GDRIVER #define GFX_USE_GDRIVER TRUE #endif - #if GDISP_TOTAL_CONTROLLERS > 1 - #ifndef GDISP_CONTROLLER_LIST - #error "GDISP Multiple Controllers: You must specify a value for GDISP_CONTROLLER_LIST" - #endif - #ifndef GDISP_CONTROLLER_DISPLAYS - #error "GDISP Multiple Controllers: You must specify a value for GDISP_CONTROLLER_DISPLAYS" - #endif + #if defined(GDISP_DRIVER_LIST) + #if GDISP_TOTAL_DISPLAYS != 1 + #error "GDISP Multiple Drivers: You can't specify both GDISP_TOTAL_DISPLAYS and GDISP_DRIVER_LIST + #endif #ifndef GDISP_PIXELFORMAT - #error "GDISP Multiple Controllers: You must specify a value for GDISP_PIXELFORMAT" + #error "GDISP Multiple Drivers: You must specify a value for GDISP_PIXELFORMAT when using GDISP_DRIVER_LIST" #endif #endif #if GDISP_NEED_AUTOFLUSH && GDISP_NEED_TIMERFLUSH From b5c3f3f4f8fe841a192a5b4590adca0c20f41f88 Mon Sep 17 00:00:00 2001 From: inmarket Date: Wed, 17 Sep 2014 08:44:14 +1000 Subject: [PATCH 06/87] Create a readme for the gdisp drivers directory listing what hardware each driver can drive. --- drivers/gdisp/readme.txt | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 drivers/gdisp/readme.txt diff --git a/drivers/gdisp/readme.txt b/drivers/gdisp/readme.txt new file mode 100644 index 00000000..5cb576a0 --- /dev/null +++ b/drivers/gdisp/readme.txt @@ -0,0 +1,28 @@ +A list of current display drivers: + +ED060SC4 - E-Ink display +framebuffer - Supports any non-palletized, non-bitpacked color display with a framebuffer +HX8347D - Mid-sized color LCD displays eg RGB565 320x240 +ILI9320 - Mid-sized color LCD displays eg RGB565 320x240 +ILI9325 - Mid-sized color LCD displays eg RGB565 320x240 +ILI9341 - Mid-sized color LCD displays eg RGB565 320x240 +ILI93xx - Mid-sized color LCD displays eg RGB565 320x240 (attempt at a common driver) +ILI9481 - Mid-sized color LCD displays eg RGB565 320x240 +LGD4532 - Mid-sized color LCD displays eg RGB565 320x240 +Nokia6610GE8 - Small (130x130) 12bit color LCD +Nokia6610GE12 - Small (130x130) 12bit color LCD (untested) +PCD8544 - Small monochrome LCD +PCF8812 - Small monochrome LCD +R61505U - Mid-sized color LCD displays eg RGB565 320x240 +RA8875 - Mid-sized color LCD displays eg RGB565 320x240 +S6D1121 - Mid-sized color LCD displays eg RGB565 320x240 +SPFD54124B - Mid-sized color LCD displays eg RGB565 320x240 +SSD1289 - Mid-sized color LCD displays eg RGB565 320x240 +SSD1306 - Small monochrome LCD +SSD1963 - Mid-sized color LCD displays eg RGB565 320x240 +SSD2119 - Mid-sized color LCD displays eg RGB565 320x240 +ST7565 - Small monochrome LCD +TestStub - NULL driver just to test compile +uGFXnet - Remote Network display (in drivers/multiple/uGFXnet directory) +Win32 - Microsoft Windows (in drivers/multiple/Win32 directory) +X - X Windows (Xlib) (in drivers/multiple/X directory) From 676c416a9bb85a092d9290244a9564f314fcf799 Mon Sep 17 00:00:00 2001 From: inmarket Date: Wed, 17 Sep 2014 08:44:31 +1000 Subject: [PATCH 07/87] More newmouse updates --- src/ginput/driver_mouse.h | 2 +- src/ginput/ginput_ginput.c | 14 +++- src/ginput/ginput_mouse.c | 130 ++++++++++++++++++++++--------------- 3 files changed, 91 insertions(+), 55 deletions(-) diff --git a/src/ginput/driver_mouse.h b/src/ginput/driver_mouse.h index dbd327d9..a0f0f807 100644 --- a/src/ginput/driver_mouse.h +++ b/src/ginput/driver_mouse.h @@ -57,7 +57,7 @@ typedef struct GMouse { #if !GINPUT_TOUCH_NOCALIBRATE GMouseCalibrationSaveRoutine fnsavecal; // The calibration load routine GMouseCalibrationLoadRoutine fnloadcal; // The calibration save routine - MouseCalibration caldata; // The calibration data + GMouseCalibration caldata; // The calibration data #endif // Other driver specific fields may follow. } GMouse; diff --git a/src/ginput/ginput_ginput.c b/src/ginput/ginput_ginput.c index 4197fa25..191ae025 100644 --- a/src/ginput/ginput_ginput.c +++ b/src/ginput/ginput_ginput.c @@ -16,10 +16,16 @@ #if GFX_USE_GINPUT +#if GINPUT_NEED_MOUSE + extern void _gmouseInit(void); + extern void _gmouseDeinit(void); +#endif + void _ginputInit(void) { - /* ToDo */ - + #if GINPUT_NEED_MOUSE + _gmouseInit(); + #endif /** * This should really call an init routine for each ginput sub-system. * Maybe we'll do this later. @@ -28,7 +34,9 @@ void _ginputInit(void) void _ginputDeinit(void) { - + #if GINPUT_NEED_MOUSE + _gmouseDeinit(); + #endif } #endif /* GFX_USE_GINPUT */ diff --git a/src/ginput/ginput_mouse.c b/src/ginput/ginput_mouse.c index e2b1f15e..ee6f51b6 100644 --- a/src/ginput/ginput_mouse.c +++ b/src/ginput/ginput_mouse.c @@ -75,7 +75,7 @@ static GTIMER_DECL(MouseTimer); pt->y = (coord_t) (c->ay * pt->x + c->by * pt->y + c->cy); } - static inline void CalibrationCalculate(GMouse *m, const MousePoint *cross, const MousePoint *points) { + static inline void CalibrationCalculate(GMouse *m, const point *cross, const point *points) { float dx; coord_t c0, c1, c2; (void) m; @@ -108,6 +108,8 @@ static GTIMER_DECL(MouseTimer); c1 -= cross[1].y; c2 -= cross[2].y; break; + default: + break; } } #endif @@ -149,6 +151,8 @@ static GTIMER_DECL(MouseTimer); c1 = cross[1].x; c2 = cross[2].x; break; + default: + break; } } #endif @@ -186,33 +190,33 @@ static void GetMouseReading(GMouse *m) { // Double check up & down events if needed if ((gmvmt(m)->d.flags & GMOUSE_VFLG_POORUPDOWN)) { // Are we in a transition test - if ((pm->flags & GMOUSE_FLG_INDELTA)) { - if (!((r.buttons ^ pm->r.buttons) & GINPUT_MOUSE_BTN_LEFT)) { + if ((m->flags & GMOUSE_FLG_INDELTA)) { + if (!((r.buttons ^ m->r.buttons) & GINPUT_MOUSE_BTN_LEFT)) { // Transition failed - pm->flags &= ~GMOUSE_FLG_INDELTA; + m->flags &= ~GMOUSE_FLG_INDELTA; return; } // Transition succeeded - pm->flags &= ~GMOUSE_FLG_INDELTA; + m->flags &= ~GMOUSE_FLG_INDELTA; // Should we start a transition test - } else if (((r.buttons ^ pm->r.buttons) & GINPUT_MOUSE_BTN_LEFT)) { - pm->flags |= GMOUSE_FLG_INDELTA; + } else if (((r.buttons ^ m->r.buttons) & GINPUT_MOUSE_BTN_LEFT)) { + m->flags |= GMOUSE_FLG_INDELTA; return; } } // If the mouse is up we may need to keep our previous position if ((gmvmt(m)->d.flags & GMOUSE_VFLG_ONLY_DOWN) && !(r.buttons & GINPUT_MOUSE_BTN_LEFT)) { - r.x = pm->r.x; - r.y = pm->r.y; + r.x = m->r.x; + r.y = m->r.y; } else { coord_t w, h; #if !GINPUT_TOUCH_NOCALIBRATE // Do we need to calibrate the reading? - if ((pm->flags & GMOUSE_FLG_CALIBRATE)) + if ((m->flags & GMOUSE_FLG_CALIBRATE)) CalibrationTransform(&r, &m->caldata); #endif @@ -252,7 +256,7 @@ static void GetMouseReading(GMouse *m) { #endif // Do we need to clip the reading to the display - if ((pm->flags & GMOUSE_FLG_CLIP)) { + if ((m->flags & GMOUSE_FLG_CLIP)) { if (r.x < 0) r.x = 0; else if (r.x >= w) r.x = w-1; if (r.y < 0) r.y = 0; @@ -325,7 +329,7 @@ static void GetMouseReading(GMouse *m) { // Send the event to the listeners that are interested. psl = 0; - while ((psl = geventGetSourceListener((GSourceHandle)(&MouseConfig), psl))) { + while ((psl = geventGetSourceListener((GSourceHandle)m, psl))) { if (!(pe = (GEventMouse *)geventGetEventBuffer(psl))) { // This listener is missing - save the meta events that have happened psl->srcflags |= meta; @@ -341,7 +345,7 @@ static void GetMouseReading(GMouse *m) { if (((r.buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEDOWNMOVES)) || (!(r.buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEUPMOVES)) || (meta && (psl->listenflags & GLISTEN_MOUSEMETA))) { - pe->type = GINPUT_MOUSE_EVENT_TYPE; + pe->type = (gmvmt(m)->d.flags & GMOUSE_VFLG_TOUCH) ? GEVENT_TOUCH : GEVENT_MOUSE; pe->x = r.x; pe->y = r.y; pe->z = r.z; @@ -369,78 +373,103 @@ static void GetMouseReading(GMouse *m) { static void MousePoll(void *param) { GMouse * m; (void) param; - - for(m = (GMouse *)gdriverGetNext(GDRIVER_TYPE_MOUSE, 0); m; m = (GMouse *)gdriverGetNext(GDRIVER_TYPE_MOUSE, m)) { + + for(m = (GMouse *)gdriverGetNext(GDRIVER_TYPE_MOUSE, 0); m; m = (GMouse *)gdriverGetNext(GDRIVER_TYPE_MOUSE, (GDriver *)m)) { if (!(gmvmt(m)->d.flags & GMOUSE_VFLG_NOPOLL) || (m->flags & GMOUSE_FLG_NEEDREAD)) GetMouseReading(m); } } +void _gmouseInit(void) { + // GINPUT_MOUSE_DRIVER_LIST is defined - create each driver instance + #if defined(GINPUT_MOUSE_DRIVER_LIST) + { + int i; + + extern GDriverVMTList GINPUT_MOUSE_DRIVER_LIST; + static const struct GDriverVMT const * dclist[] = {GINPUT_MOUSE_DRIVER_LIST}; + static const unsigned dnlist[] = {GDISP_CONTROLLER_DISPLAYS}; + + for(i = 0; i < sizeof(dclist)/sizeof(dclist[0]); i++) + gdriverRegister(dclist[i]); + } + + // One and only one display + #else + { + extern GDriverVMTList GINPUTMOUSEVMT_OnlyOne; + + gdriverRegister(GINPUTMOUSEVMT_OnlyOne); + } + #endif +} + +void _gmouseDeinit(void) { +} + GSourceHandle ginputGetMouse(uint16_t instance) { + GMouse *m; #if GINPUT_MOUSE_NEED_CALIBRATION - Calibration *pc; + GCalibration *pc; #endif - // We only support a single mouse instance currently - // Instance 9999 is the same as instance 0 except that it installs - // a special "raw" calibration if there isn't one we can load. - if (instance && instance != 9999) - return 0; + if (!(m = (GMouse *)gdriverGetInstance(GDRIVER_TYPE_MOUSE, instance))) + return 0; // Make sure we have a valid mouse display - if (!MouseConfig.display) - MouseConfig.display = GDISP; + if (!m->display) + m->display = GDISP; // Do we need to initialise the mouse subsystem? - if (!(MouseConfig.flags & FLG_INIT_DONE)) { + if (!(m->flags & FLG_INIT_DONE)) { ginput_lld_mouse_init(); #if GINPUT_MOUSE_NEED_CALIBRATION #if GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE - if (!MouseConfig.fnloadcal) { - MouseConfig.fnloadcal = ginput_lld_mouse_calibration_load; - MouseConfig.flags &= ~FLG_CAL_FREE; + if (!m->fnloadcal) { + m->fnloadcal = ginput_lld_mouse_calibration_load; + m->flags &= ~FLG_CAL_FREE; } - if (!MouseConfig.fnsavecal) - MouseConfig.fnsavecal = ginput_lld_mouse_calibration_save; + if (!m->fnsavecal) + m->fnsavecal = ginput_lld_mouse_calibration_save; #endif - if (MouseConfig.fnloadcal && (pc = (Calibration *)MouseConfig.fnloadcal(instance))) { - memcpy(&MouseConfig.caldata, pc, sizeof(MouseConfig.caldata)); - MouseConfig.flags |= (FLG_CAL_OK|FLG_CAL_SAVED); - if ((MouseConfig.flags & FLG_CAL_FREE)) + if (m->fnloadcal && (pc = (Calibration *)m->fnloadcal(instance))) { + memcpy(&m->caldata, pc, sizeof(m->caldata)); + m->flags |= (FLG_CAL_OK|FLG_CAL_SAVED); + if ((m->flags & FLG_CAL_FREE)) gfxFree((void *)pc); } else if (instance == 9999) { - CalibrationSetIdentity(&MouseConfig.caldata); - MouseConfig.flags |= (FLG_CAL_OK|FLG_CAL_SAVED|FLG_CAL_RAW); + CalibrationSetIdentity(&m->caldata); + m->flags |= (FLG_CAL_OK|FLG_CAL_SAVED|FLG_CAL_RAW); } else ginputCalibrateMouse(instance); #endif // Get the first reading - MouseConfig.last_buttons = 0; - get_calibrated_reading(&MouseConfig.t); + m->last_buttons = 0; + get_calibrated_reading(&m->t); // Mark init as done and start the Poll timer - MouseConfig.flags |= FLG_INIT_DONE; + m->flags |= FLG_INIT_DONE; gtimerStart(&MouseTimer, MousePoll, 0, TRUE, GINPUT_MOUSE_POLL_PERIOD); } // Return our structure as the handle - return (GSourceHandle)&MouseConfig; + return (GSourceHandle)m; } void ginputSetMouseDisplay(uint16_t instance, GDisplay *g) { if (instance) return; - MouseConfig.display = g ? g : GDISP; + m->display = g ? g : GDISP; } GDisplay *ginputGetMouseDisplay(uint16_t instance) { if (instance) return 0; - return MouseConfig.display; + return m->display; } bool_t ginputGetMouseStatus(uint16_t instance, GEventMouse *pe) { @@ -448,16 +477,15 @@ bool_t ginputGetMouseStatus(uint16_t instance, GEventMouse *pe) { // so we add a sleep here to prevent 100% polled applications from locking up. gfxSleepMilliseconds(1); - if (instance || (MouseConfig.flags & (FLG_INIT_DONE|FLG_IN_CAL)) != FLG_INIT_DONE) + if (instance || (m->flags & (FLG_INIT_DONE|FLG_IN_CAL)) != FLG_INIT_DONE) return FALSE; pe->type = GINPUT_MOUSE_EVENT_TYPE; - pe->instance = instance; - pe->x = MouseConfig.t.x; - pe->y = MouseConfig.t.y; - pe->z = MouseConfig.t.z; - pe->current_buttons = MouseConfig.t.buttons; - pe->last_buttons = MouseConfig.last_buttons; + pe->x = m->t.x; + pe->y = m->t.y; + pe->z = m->t.z; + pe->current_buttons = m->t.buttons; + pe->last_buttons = m->last_buttons; if (pe->current_buttons & ~pe->last_buttons & GINPUT_MOUSE_BTN_LEFT) pe->meta = GMETA_MOUSE_DOWN; else if (~pe->current_buttons & pe->last_buttons & GINPUT_MOUSE_BTN_LEFT) @@ -471,7 +499,7 @@ bool_t ginputCalibrateMouse(uint16_t instance) { #if GINPUT_TOUCH_NOCALIBRATE (void) instance; - + return FALSE; #else @@ -589,7 +617,7 @@ bool_t ginputCalibrateMouse(uint16_t instance) { MouseConfig.flags &= ~FLG_IN_CAL; if ((MouseConfig.flags & FLG_INIT_DONE)) gtimerStart(&MouseTimer, MousePoll, 0, TRUE, GINPUT_MOUSE_POLL_PERIOD); - + // Save the calibration data (if possible) if (MouseConfig.fnsavecal) { MouseConfig.fnsavecal(instance, (const uint8_t *)&MouseConfig.caldata, sizeof(MouseConfig.caldata)); @@ -602,7 +630,7 @@ bool_t ginputCalibrateMouse(uint16_t instance) { #else gdispGClear(MouseConfig.display, Black); #endif - + return TRUE; #endif } From 5ee4290941f5445649403a84f3f0e9d5bf48b9e2 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 25 Sep 2014 17:42:11 +1000 Subject: [PATCH 08/87] Expose the GDISP_STARTUP_COLOR setting for the initial color of displays --- gfxconf.example.h | 4 +- src/gdisp/gdisp_gdisp.c | 3 - src/gdisp/sys_options.h | 119 +++++++++++++++++++--------------------- 3 files changed, 58 insertions(+), 68 deletions(-) diff --git a/gfxconf.example.h b/gfxconf.example.h index 205c79d3..7ac48591 100644 --- a/gfxconf.example.h +++ b/gfxconf.example.h @@ -101,10 +101,10 @@ // #define GDISP_NEED_IMAGE_PNG FALSE // #define GDISP_NEED_IMAGE_ACCOUNTING FALSE -//#define GDISP_NEED_STARTUP_LOGO TRUE - //#define GDISP_DEFAULT_ORIENTATION GDISP_ROTATE_LANDSCAPE // If not defined the native hardware orientation is used. //#define GDISP_LINEBUF_SIZE 128 +//#define GDISP_STARTUP_COLOR Black +//#define GDISP_NEED_STARTUP_LOGO TRUE //#define GDISP_TOTAL_DISPLAYS 1 diff --git a/src/gdisp/gdisp_gdisp.c b/src/gdisp/gdisp_gdisp.c index 4a149faa..74cfb67e 100644 --- a/src/gdisp/gdisp_gdisp.c +++ b/src/gdisp/gdisp_gdisp.c @@ -38,9 +38,6 @@ #define GDISP_STARTUP_LOGO_TIMEOUT 0 #endif -// The color to clear the display on startup -#define GDISP_STARTUP_COLOR Black - /*===========================================================================*/ /* Driver local variables. */ /*===========================================================================*/ diff --git a/src/gdisp/sys_options.h b/src/gdisp/sys_options.h index 855f22ff..f3d8875d 100644 --- a/src/gdisp/sys_options.h +++ b/src/gdisp/sys_options.h @@ -20,14 +20,6 @@ * @name GDISP Functionality to be included * @{ */ - /** - * @brief Should the startup logo be displayed - * - * @details Defaults to TRUE - */ - #ifndef GDISP_NEED_STARTUP_LOGO - #define GDISP_NEED_STARTUP_LOGO TRUE - #endif /** * @brief Should drawing operations be automatically flushed. * @details Defaults to FALSE @@ -177,6 +169,62 @@ #ifndef GDISP_NEED_IMAGE #define GDISP_NEED_IMAGE FALSE #endif +/** + * @} + * + * @name GDISP Multi-Threading Options + * @{ + */ + /** + * @brief Do the drawing functions need to be thread-safe. + * @details Defaults to FALSE + */ + #ifndef GDISP_NEED_MULTITHREAD + #define GDISP_NEED_MULTITHREAD FALSE + #endif +/** + * @} + * + * @name GDISP Optional Parameters + * @{ + */ + /** + * @brief Should the startup logo be displayed + * + * @details Defaults to TRUE + */ + #ifndef GDISP_NEED_STARTUP_LOGO + #define GDISP_NEED_STARTUP_LOGO TRUE + #endif + /** + * @brief Define the initial background color for all displays in the system. + */ + #ifndef GDISP_STARTUP_COLOR + #define GDISP_STARTUP_COLOR Black + #endif + /** + * @brief Define the default orientation for all displays in the system. + * @note GDISP_NEED_CONTROL must also be set (and the hardware must support it) + * @note If not specified then displays default to the native hardware orientation + */ + // #define GDISP_DEFAULT_ORIENTATION GDISP_ROTATE_LANDSCAPE + /** + * @brief The size of pixel buffer (in pixels) used for optimization. + * @details Set to zero to guarantee disabling of the buffer. + * @note Depending on the driver and what operations the application + * needs, this buffer may never be allocated. + * @note Setting the size to zero may cause some operations to not + * compile eg. Scrolling if there is no hardware scroll support. + * @note Increasing the size will speedup certain operations + * at the expense of RAM. + * @note Currently only used to support scrolling on hardware without + * scrolling support, and to increase the speed of streaming + * operations on non-streaming hardware where there is a + * hardware supported bit-blit. + */ + #ifndef GDISP_LINEBUF_SIZE + #define GDISP_LINEBUF_SIZE 128 + #endif /** * @} * @@ -267,7 +315,6 @@ #ifndef GDISP_NEED_UTF8 #define GDISP_NEED_UTF8 FALSE #endif - /** * @brief Enable kerning for font rendering (improves character placement). * @details Defaults to FALSE @@ -275,7 +322,6 @@ #ifndef GDISP_NEED_TEXT_KERNING #define GDISP_NEED_TEXT_KERNING FALSE #endif - /** * @brief Enable antialiased font support * @details Defaults to FALSE @@ -283,65 +329,12 @@ #ifndef GDISP_NEED_ANTIALIAS #define GDISP_NEED_ANTIALIAS FALSE #endif - -/** - * @} - * - * @name GDISP Multi-Threading Options - * @{ - */ - /** - * @brief Do the drawing functions need to be thread-safe. - * @details Defaults to FALSE - */ - #ifndef GDISP_NEED_MULTITHREAD - #define GDISP_NEED_MULTITHREAD FALSE - #endif -/** - * @} - * - * @name GDISP Fonts - * @{ - */ - /** - * @brief Predefined built in fonts - * @note Turning off the ones you are not using can save program size. - */ - -/** - * @} - * - * @name GDISP Optional Sizing Parameters - * @{ - */ - /** - * @brief The size of pixel buffer (in pixels) used for optimization. - * @details Set to zero to guarantee disabling of the buffer. - * @note Depending on the driver and what operations the application - * needs, this buffer may never be allocated. - * @note Setting the size to zero may cause some operations to not - * compile eg. Scrolling if there is no hardware scroll support. - * @note Increasing the size will speedup certain operations - * at the expense of RAM. - * @note Currently only used to support scrolling on hardware without - * scrolling support, and to increase the speed of streaming - * operations on non-streaming hardware where there is a - * hardware supported bit-blit. - */ - #ifndef GDISP_LINEBUF_SIZE - #define GDISP_LINEBUF_SIZE 128 - #endif /** * @} * * @name GDISP Optional Low Level Driver Defines * @{ */ - /** - * @brief Define the default orientation for all displays in the system. - * @note GDISP_NEED_CONTROL must also be set (and the hardware must support it) - */ - // #define GDISP_DEFAULT_ORIENTATION GDISP_ROTATE_LANDSCAPE /** * @brief Set the screen height and width. * @note Ignored by some low level GDISP drivers, optional for others. From 6b9ff5de2a2ddf1056e00b7590f936779c56b517 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 25 Sep 2014 17:43:05 +1000 Subject: [PATCH 09/87] C decls on GDISP functions --- src/gdisp/driver.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/gdisp/driver.h b/src/gdisp/driver.h index f8d66f4b..98bf64fc 100644 --- a/src/gdisp/driver.h +++ b/src/gdisp/driver.h @@ -617,9 +617,15 @@ typedef struct GDISPVMT { #endif // Routines needed by the general driver VMT - bool_t _gdispInitDriver(GDriver *g, unsigned driverinstance, unsigned systeminstance); - void _gdispPostInitDriver(GDriver *g); - void _gdispDeInitDriver(GDriver *g); + #ifdef __cplusplus + extern "C" { + #endif + bool_t _gdispInitDriver(GDriver *g, unsigned driverinstance, unsigned systeminstance); + void _gdispPostInitDriver(GDriver *g); + void _gdispDeInitDriver(GDriver *g); + #ifdef __cplusplus + } + #endif // Build the VMT const GDISPVMT const GDISP_DRIVER_VMT[1] = {{ From 33200c1a9787254532394e6877ec403ed4b89db8 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 25 Sep 2014 17:43:43 +1000 Subject: [PATCH 10/87] Additional GDriver call --- src/gdriver/gdriver_gdriver.c | 27 ++++++++++++++++++--------- src/gdriver/sys_defs.h | 9 +++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/gdriver/gdriver_gdriver.c b/src/gdriver/gdriver_gdriver.c index 0a53aaf7..3c17fca0 100644 --- a/src/gdriver/gdriver_gdriver.c +++ b/src/gdriver/gdriver_gdriver.c @@ -11,19 +11,13 @@ #include "sys_defs.h" +#include // For memset + // Define the tables to hold the driver instances. static GDriver *dhead; // The system initialization. void _gdriverInit(void) { - - // Drivers not loaded yet - // GINPUT_NEED_MOUSE - // GINPUT_NEED_DIAL - // GINPUT_NEED_TOGGLE - // GINPUT_NEED_KEYBOARD - // GINPUT_NEED_STRING - // GFX_USE_GBLOCK } // The system de-initialization. @@ -51,7 +45,7 @@ GDriver *gdriverRegister(const GDriverVMT *vmt) { pd = gfxAlloc(vmt->objsize); if (!pd) return 0; - pd->driverchain = 0; + memset(pd, 0, vmt->objsize); pd->vmt = vmt; if (vmt->init && !vmt->init(pd, dinstance, sinstance)) { gfxFree(pd); @@ -136,4 +130,19 @@ GDriver *gdriverGetNext(uint16_t type, GDriver *driver) { return driver; } +unsigned gdriverGetDriverInstanceNumber(GDriver *driver) { + GDriver *pd; + unsigned instance; + + // Loop to find the system instance + instance = 0; + for(pd = dhead; pd; pd = pd->driverchain) { + if (pd == driver) + return instance; + if (pd->vmt->type == driver->vmt->type) + instance++; + } + return (unsigned)-1; +} + #endif /* GFX_USE_GDRIVER */ diff --git a/src/gdriver/sys_defs.h b/src/gdriver/sys_defs.h index 546246de..d8de25fc 100644 --- a/src/gdriver/sys_defs.h +++ b/src/gdriver/sys_defs.h @@ -70,6 +70,7 @@ typedef struct GDriverVMT { bool_t (*init)(GDriver *driver, unsigned driverinstance, unsigned systeminstance); // @< Initialise the driver. Returns TRUE if OK. // driverinstance is the instance 0..n of this driver. // systeminstance is the instance 0..n of this type of device. + // The memory allocated is cleared before this call. void (*postinit)(GDriver *driver); // @< Called once the driver is registered. void (*deinit)(GDriver *driver); // @< De-initialise the driver } GDriverVMT; @@ -130,6 +131,14 @@ extern "C" { */ unsigned gdriverInstanceCount(uint16_t type); + /** + * @brief Get the instance number for a device + * @return The instance number or (unsigned)-1 if it fails. + * + * @param[in] driver The driver to find the instance number for + */ + unsigned gdriverGetDriverInstanceNumber(GDriver *driver); + /** * @brief Get the next driver for a type of device * @return The runtime driver structure or NULL if there are no more. From 10dc968427ed1ec846342dd1932b273acea414bd Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 25 Sep 2014 17:44:16 +1000 Subject: [PATCH 11/87] New mouse updates. Just need a driver now. --- gfxconf.example.h | 10 + src/ginput/driver_mouse.h | 48 +- src/ginput/ginput_mouse.c | 1088 ++++++++++++++++++++----------------- src/ginput/ginput_mouse.h | 148 ++--- src/ginput/sys_options.h | 86 ++- src/ginput/sys_rules.h | 15 + src/gwin/gwin_widget.c | 16 +- src/gwin/gwin_widget.h | 4 +- 8 files changed, 812 insertions(+), 603 deletions(-) diff --git a/gfxconf.example.h b/gfxconf.example.h index 7ac48591..0ff436ca 100644 --- a/gfxconf.example.h +++ b/gfxconf.example.h @@ -210,6 +210,16 @@ //#define GFX_USE_GINPUT FALSE //#define GINPUT_NEED_MOUSE FALSE +// #define GINPUT_TOUCH_STARTRAW FALSE +// #define GINPUT_TOUCH_NOTOUCH FALSE +// #define GINPUT_TOUCH_NOCALIBRATE FALSE +// #define GINPUT_TOUCH_NOCALIBRATE_GUI FALSE +// #define GINPUT_MOUSE_POLL_PERIOD 25 +// #define GINPUT_MOUSE_CLICK_TIME 300 +// #define GINPUT_TOUCH_CXTCLICK_TIME 700 +// #define GINPUT_TOUCH_USER_CALIBRATION_LOAD FALSE +// #define GINPUT_TOUCH_USER_CALIBRATION_FREE FALSE +// #define GINPUT_TOUCH_USER_CALIBRATION_SAVE FALSE //#define GINPUT_NEED_KEYBOARD FALSE //#define GINPUT_NEED_TOGGLE FALSE //#define GINPUT_NEED_DIAL FALSE diff --git a/src/ginput/driver_mouse.h b/src/ginput/driver_mouse.h index a0f0f807..ababfef8 100644 --- a/src/ginput/driver_mouse.h +++ b/src/ginput/driver_mouse.h @@ -42,21 +42,17 @@ typedef struct GMouse { GDriver d; // The driver overheads and vmt GMouseReading r; // The current position and state uint16_t flags; // Flags - #define GMOUSE_FLG_ACTIVE 0x0001 // Mouse is currently active - #define GMOUSE_FLG_CLICK_TIMER 0x0002 // Currently timing a click event - #define GMOUSE_FLG_INDELTA 0x0004 // Currently in a up/down transition test - #define GMOUSE_FLG_CLIP 0x0008 // Clip reading to the display - #define GMOUSE_FLG_CALIBRATE 0x0010 // Calibrate readings - #define GMOUSE_FLG_CAL_INPROGRESS 0x0020 // Calibrate is currently in progress - #define GMOUSE_FLG_CAL_SAVED 0x0040 // Calibration has been saved - #define GMOUSE_FLG_FINGERMODE 0x0080 // Mouse is currently in finger mode - #define GMOUSE_FLG_NEEDREAD 0x0100 // The mouse needs reading + #define GMOUSE_FLG_CLICK_TIMER 0x0001 // Currently timing a click + #define GMOUSE_FLG_INDELTA 0x0002 // Currently in a up/down transition test + #define GMOUSE_FLG_CLIP 0x0004 // Clip reading to the display + #define GMOUSE_FLG_CALIBRATE 0x0008 // Calibrate readings + #define GMOUSE_FLG_IN_CAL 0x0010 // Currently in calibration routine + #define GMOUSE_FLG_FINGERMODE 0x0020 // Mouse is currently in finger mode + #define GMOUSE_FLG_NEEDREAD 0x0040 // The mouse needs reading point clickpos; // The position of the last click event systemticks_t clicktime; // The time of the last click event GDisplay * display; // The display the mouse is associated with #if !GINPUT_TOUCH_NOCALIBRATE - GMouseCalibrationSaveRoutine fnsavecal; // The calibration load routine - GMouseCalibrationLoadRoutine fnloadcal; // The calibration save routine GMouseCalibration caldata; // The calibration data #endif // Other driver specific fields may follow. @@ -77,8 +73,10 @@ typedef struct GMouseVMT { #define GMOUSE_VFLG_CALIBRATE 0x0010 // This device requires calibration #define GMOUSE_VFLG_CAL_EXTREMES 0x0020 // Use edge to edge calibration #define GMOUSE_VFLG_CAL_TEST 0x0040 // Test the results of the calibration + #define GMOUSE_VFLG_CAL_LOADFREE 0x0080 // Call gfxFree on the buffer returned by the VMT calload() routine. #define GMOUSE_VFLG_ONLY_DOWN 0x0100 // This device returns a valid position only when the mouse is down #define GMOUSE_VFLG_POORUPDOWN 0x0200 // Position readings during up/down are unreliable + #define GMOUSE_VFLG_DYNAMICONLY 0x8000 // This mouse driver should not be statically initialized eg Win32 coord_t z_max; // TOUCH: Maximum possible z value (fully touched) coord_t z_min; // TOUCH: Minimum possible z value (touch off screen). Note may also be > z_max coord_t z_touchon; // TOUCH: z values between z_max and this are a solid touch on @@ -87,10 +85,11 @@ typedef struct GMouseVMT { GMouseJitter pen_jitter; // PEN MODE: Jitter settings GMouseJitter finger_jitter; // FINGER MODE: Jitter settings - bool_t (*init)(GMouse *m); // Required + bool_t (*init)(GMouse *m, unsigned driverinstance); // Required + void (*deinit)(GMouse *m); // Optional void (*get)(GMouse *m, GMouseReading *prd); // Required void (*calsave)(GMouse *m, void *buf, size_t sz); // Optional - const char *(*calload)(GMouse *m); // Optional: Can return NULL if no data is saved. Buffer is automatically gfxFree()'d afterwards. + const char *(*calload)(GMouse *m, size_t sz); // Optional: Can return NULL if no data is saved. } GMouseVMT; #define gmvmt(m) ((const GMouseVMT const *)((m)->d.vmt)) @@ -99,9 +98,28 @@ typedef struct GMouseVMT { /* External declarations. */ /*===========================================================================*/ +// If we are not using multiple mice then hard-code the VMT name +#if !defined(GINPUT_MOUSE_DRIVER_LIST) + #undef GMOUSE_DRIVER_VMT + #define GMOUSE_DRIVER_VMT GMOUSEVMT_OnlyOne +#endif + #ifdef __cplusplus extern "C" { #endif + /** + * @brief Routines needed by the general driver VMT + * @note These routines are provided by the high level code for + * use in the GMouseVMT.d structure. + * + * @notapi + * @{ + */ + bool_t _gmouseInitDriver(GDriver *g, unsigned driverinstance, unsigned systeminstance); + void _gmousePostInitDriver(GDriver *g); + void _gmouseDeInitDriver(GDriver *g); + /** @} */ + /** * @brief Wakeup the high level code so that it attempts another read * @@ -109,7 +127,7 @@ extern "C" { * * @notapi */ - void ginputMouseWakeup(GMouse *m); + void _gmouseWakeup(GMouse *m); /** * @brief Wakeup the high level code so that it attempts another read @@ -119,7 +137,7 @@ extern "C" { * @iclass * @notapi */ - void ginputMouseWakeupI(GMouse *m); + void _gmouseWakeupI(GMouse *m); #ifdef __cplusplus } diff --git a/src/ginput/ginput_mouse.c b/src/ginput/ginput_mouse.c index ee6f51b6..f33a74e0 100644 --- a/src/ginput/ginput_mouse.c +++ b/src/ginput/ginput_mouse.c @@ -8,72 +8,341 @@ /** * @file src/ginput/ginput_mouse.c * @brief GINPUT mouse/touch code. - * - * @defgroup Mouse Mouse - * @ingroup GINPUT - * @{ */ #include "gfx.h" -#if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) || defined(__DOXYGEN__) +#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE +// Local Settings +#define CALIBRATION_POLL_PERIOD 20 // milliseconds +#define CALIBRATION_MINPRESS_PERIOD 300 // milliseconds +#define CALIBRATION_MAXPRESS_PERIOD 5000 // milliseconds + +#define CALIBRATION_FONT "* Double" +#define CALIBRATION_FONT2 "* Narrow" +#define CALIBRATION_BACKGROUND Blue + +#define CALIBRATION_CROSS_COLOR1 White +#define CALIBRATION_CROSS_COLOR2 RGB2COLOR(184,158,131) +#define CALIBRATION_CROSS_INNERGAP 2 +#define CALIBRATION_CROSS_RADIUS 15 + +#define CALIBRATION_TITLE "Calibration" +#define CALIBRATION_TITLE_Y 5 +#define CALIBRATION_TITLE_HEIGHT 30 +#define CALIBRATION_TITLE_COLOR White +#define CALIBRATION_TITLE_BACKGROUND Blue + +#define CALIBRATION_ERROR_TEXT "Failed - Please try again!" +#define CALIBRATION_ERROR_COLOR Red +#define CALIBRATION_ERROR_BACKGROUND Yellow +#define CALIBRATION_ERROR_Y 35 +#define CALIBRATION_ERROR_HEIGHT 40 + +// Get the mouse driver interface #include "driver_mouse.h" -#if !GINPUT_TOUCH_NOCALIBRATE - #if !defined(GFX_USE_GDISP) || !GFX_USE_GDISP - #error "GINPUT: GFX_USE_GDISP must be defined when mouse or touch calibration is required" - #endif - - #include // Required for memcpy - - #define CALIBRATION_FONT "* Double" - #define CALIBRATION_FONT2 "* Narrow" - #define CALIBRATION_TEXT "Calibration" - #define CALIBRATION_ERROR_TEXT "Failed - Please try again!" - #define CALIBRATION_SAME_TEXT "Error: Same Reading - Check Driver!" - #define CALIBRATION_BACKGROUND Blue - #define CALIBRATION_COLOR1 White - #define CALIBRATION_COLOR2 RGB2COLOR(184,158,131) - -#endif - +// The mouse poll timer static GTIMER_DECL(MouseTimer); +// Calibration application #if !GINPUT_TOUCH_NOCALIBRATE - /* - static inline void CalibrationSetIdentity(MouseCalibration *c) { - c->ax = 1; - c->bx = 0; - c->cx = 0; - c->ay = 0; - c->by = 1; - c->cy = 0; - } - */ - - static inline void CalibrationCrossDraw(GMouse *m, const point *pp) { - gdispGDrawLine(m->display, pp->x-15, pp->y, pp->x-2, pp->y, CALIBRATION_COLOR1); - gdispGDrawLine(m->display, pp->x+2, pp->y, pp->x+15, pp->y, CALIBRATION_COLOR1); - gdispGDrawLine(m->display, pp->x, pp->y-15, pp->x, pp->y-2, CALIBRATION_COLOR1); - gdispGDrawLine(m->display, pp->x, pp->y+2, pp->x, pp->y+15, CALIBRATION_COLOR1); - gdispGDrawLine(m->display, pp->x-15, pp->y+15, pp->x-7, pp->y+15, CALIBRATION_COLOR2); - gdispGDrawLine(m->display, pp->x-15, pp->y+7, pp->x-15, pp->y+15, CALIBRATION_COLOR2); - gdispGDrawLine(m->display, pp->x-15, pp->y-15, pp->x-7, pp->y-15, CALIBRATION_COLOR2); - gdispGDrawLine(m->display, pp->x-15, pp->y-7, pp->x-15, pp->y-15, CALIBRATION_COLOR2); - gdispGDrawLine(m->display, pp->x+7, pp->y+15, pp->x+15, pp->y+15, CALIBRATION_COLOR2); - gdispGDrawLine(m->display, pp->x+15, pp->y+7, pp->x+15, pp->y+15, CALIBRATION_COLOR2); - gdispGDrawLine(m->display, pp->x+7, pp->y-15, pp->x+15, pp->y-15, CALIBRATION_COLOR2); - gdispGDrawLine(m->display, pp->x+15, pp->y-15, pp->x+15, pp->y-7, CALIBRATION_COLOR2); - } - - static inline void CalibrationCrossClear(GMouse *m, const point *pp) { - gdispGFillArea(m->display, pp->x - 15, pp->y - 15, 32, 32, CALIBRATION_BACKGROUND); - } + #if GINPUT_TOUCH_USER_CALIBRATION_LOAD + #include // Required for memcpy + #endif static inline void CalibrationTransform(GMouseReading *pt, const GMouseCalibration *c) { pt->x = (coord_t) (c->ax * pt->x + c->bx * pt->y + c->cx); pt->y = (coord_t) (c->ay * pt->x + c->by * pt->y + c->cy); } +#endif + +static void SendMouseEvent(GSourceListener *psl, GMouse *m, GMouseReading *r) { + GEventMouse *pe; + + // If there is no event buffer just mark a missed event + if (!(pe = (GEventMouse *)geventGetEventBuffer(psl))) { + // This listener is missing - save the meta events that have happened + psl->srcflags |= ((r->buttons & GMETA_MASK)|GINPUT_MISSED_MOUSE_EVENT); + return; + } + + // If we haven't really moved (and there are no meta events) don't bother sending the event + if (!(r->buttons & GMETA_MASK) && !psl->srcflags && !(psl->listenflags & GLISTEN_MOUSENOFILTER) + && r->x == m->r.x && r->y == m->r.y && (r->buttons & GINPUT_MOUSE_BTN_MASK) == (m->r.buttons & GINPUT_MOUSE_BTN_MASK)) + return; + + // Send the event only if we are listening for it + if (!((r->buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEDOWNMOVES)) + && !((r->buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEUPMOVES)) + && !((r->buttons & GMETA_MASK) && (psl->listenflags & GLISTEN_MOUSEMETA))) + return; + + #if !GINPUT_TOUCH_NOTOUCH + pe->type = (gmvmt(m)->d.flags & GMOUSE_VFLG_TOUCH) ? GEVENT_TOUCH : GEVENT_MOUSE; + #else + pe->type = GEVENT_MOUSE; + #endif + pe->x = r->x; + pe->y = r->y; + pe->z = r->z; + pe->buttons = r->buttons | psl->srcflags; + psl->srcflags = 0; + pe->display = m->display; + geventSendEvent(psl); +} + +static void GetMouseReading(GMouse *m) { + GMouseReading r; + + // Step 1 - Get the Raw Reading + { + m->flags &= ~GMOUSE_FLG_NEEDREAD; + gmvmt(m)->get(m, &r); + } + + // Step 2 - Handle touch and button 0 debouncing + { + // Clean off button garbage + r.buttons &= GINPUT_MOUSE_BTN_MASK; + + #if !GINPUT_TOUCH_NOTOUCH + // If touch then calculate button 0 from z + if ((gmvmt(m)->d.flags & GMOUSE_VFLG_TOUCH)) { + if (gmvmt(m)->z_min <= gmvmt(m)->z_max) { + if (r.z >= gmvmt(m)->z_touchon) r.buttons |= GINPUT_MOUSE_BTN_LEFT; + else if (r.z <= gmvmt(m)->z_touchoff) r.buttons &= ~GINPUT_MOUSE_BTN_LEFT; + else return; // bad transitional reading + } else { + if (r.z <= gmvmt(m)->z_touchon) r.buttons |= GINPUT_MOUSE_BTN_LEFT; + else if (r.z >= gmvmt(m)->z_touchoff) r.buttons &= ~GINPUT_MOUSE_BTN_LEFT; + else return; // bad transitional reading + } + } + + // Devices with poor button 0 transitioning need debouncing + if ((gmvmt(m)->d.flags & GMOUSE_VFLG_POORUPDOWN)) { + // Are we in a transition test + if ((m->flags & GMOUSE_FLG_INDELTA)) { + if (!((r.buttons ^ m->r.buttons) & GINPUT_MOUSE_BTN_LEFT)) { + // Transition failed + m->flags &= ~GMOUSE_FLG_INDELTA; + return; + } + // Transition succeeded + m->flags &= ~GMOUSE_FLG_INDELTA; + + // Should we start a transition test + } else if (((r.buttons ^ m->r.buttons) & GINPUT_MOUSE_BTN_LEFT)) { + m->flags |= GMOUSE_FLG_INDELTA; + return; + } + } + #endif + + #if !GINPUT_TOUCH_NOCALIBRATE_GUI + // Stop here with just the raw x,y reading during calibration + if ((m->flags & GMOUSE_FLG_IN_CAL)) { + if ((r.buttons & GINPUT_MOUSE_BTN_LEFT)) { + m->r.x = r.x; + m->r.y = r.y; + } + m->r.buttons = r.buttons; + return; + } + #endif + } + + // Step 3 - Apply calibration, rotation and display clipping + { + // If the mouse is up we may need to keep our previous position + if ((gmvmt(m)->d.flags & GMOUSE_VFLG_ONLY_DOWN) && !(r.buttons & GINPUT_MOUSE_BTN_LEFT)) { + r.x = m->r.x; + r.y = m->r.y; + + } else { + + #if !GINPUT_TOUCH_NOCALIBRATE + // Do we need to calibrate the reading? + if ((m->flags & GMOUSE_FLG_CALIBRATE)) + CalibrationTransform(&r, &m->caldata); + #endif + + // We can't clip or rotate if we don't have a display + if (m->display) { + coord_t w, h; + + // We now need display information + w = gdispGGetWidth(m->display); + h = gdispGGetHeight(m->display); + + #if GDISP_NEED_CONTROL + // Do we need to rotate the reading to match the display + if (!(gmvmt(m)->d.flags & GMOUSE_VFLG_SELFROTATION)) { + coord_t t; + + switch(gdispGGetOrientation(m->display)) { + case GDISP_ROTATE_0: + break; + case GDISP_ROTATE_90: + t = r.x; + r.x = w - 1 - r.y; + r.y = t; + break; + case GDISP_ROTATE_180: + r.x = w - 1 - r.x; + r.y = h - 1 - r.y; + break; + case GDISP_ROTATE_270: + t = r.y; + r.y = h - 1 - r.x; + r.x = t; + break; + default: + break; + } + } + #endif + + // Do we need to clip the reading to the display + if ((m->flags & GMOUSE_FLG_CLIP)) { + if (r.x < 0) r.x = 0; + else if (r.x >= w) r.x = w-1; + if (r.y < 0) r.y = 0; + else if (r.y >= h) r.y = h-1; + } + } + } + } + + // Step 4 - Apply jitter detection + #if !GINPUT_TOUCH_NOTOUCH + { + const GMouseJitter *pj; + uint32_t diff; + + // Are we in pen or finger mode + pj = (m->flags & GMOUSE_FLG_FINGERMODE) ? &gmvmt(m)->finger_jitter : &gmvmt(m)->pen_jitter; + + // Is this just movement jitter + if (pj->move > 0) { + diff = (uint32_t)(r.x - m->r.x) * (uint32_t)(r.x - m->r.x) + (uint32_t)(r.y - m->r.y) * (uint32_t)(r.y - m->r.y); + if (diff > (uint32_t)pj->move * (uint32_t)pj->move) { + r.x = m->r.x; + r.y = m->r.y; + } + } + + // Check if the click has moved outside the click area and if so cancel the click + if (pj->click > 0 && (m->flags & GMOUSE_FLG_CLICK_TIMER)) { + diff = (uint32_t)(r.x - m->clickpos.x) * (uint32_t)(r.x - m->clickpos.x) + (uint32_t)(r.y - m->clickpos.y) * (uint32_t)(r.y - m->clickpos.y); + if (diff > (uint32_t)pj->click * (uint32_t)pj->click) + m->flags &= ~GMOUSE_FLG_CLICK_TIMER; + } + } + #endif + + // Step 5 - Click, context-click and other meta event detection + { + uint16_t upbtns, dnbtns; + + // Calculate button transitions + dnbtns = r.buttons & ~m->r.buttons; + upbtns = ~r.buttons & m->r.buttons; + + // Left mouse down generates the Mouse-down meta event + if ((dnbtns & GINPUT_MOUSE_BTN_LEFT)) + r.buttons |= GMETA_MOUSE_DOWN; + + // Left mouse up generates the Mouse-up meta event + if ((upbtns & GINPUT_MOUSE_BTN_LEFT)) + r.buttons |= GMETA_MOUSE_UP; + + // Left/Right mouse down starts the click timer + if ((dnbtns & (GINPUT_MOUSE_BTN_LEFT|GINPUT_MOUSE_BTN_RIGHT))) { + m->clickpos.x = r.x; + m->clickpos.y = r.y; + m->clicktime = gfxSystemTicks(); + m->flags |= GMOUSE_FLG_CLICK_TIMER; + } + + // Left/Right mouse up with the click timer still running may generate a click or context click + if ((upbtns & (GINPUT_MOUSE_BTN_LEFT|GINPUT_MOUSE_BTN_RIGHT)) && (m->flags & GMOUSE_FLG_CLICK_TIMER)) { + m->flags &= ~GMOUSE_FLG_CLICK_TIMER; + m->clicktime = gfxSystemTicks() - m->clicktime; + + // Was this a short click? + if (m->clicktime <= gfxMillisecondsToTicks(GINPUT_MOUSE_CLICK_TIME)) { + if ((upbtns & GINPUT_MOUSE_BTN_RIGHT)) + r.buttons |= GMETA_MOUSE_CXTCLICK; + if ((upbtns & GINPUT_MOUSE_BTN_LEFT)) + r.buttons |= GMETA_MOUSE_CLICK; + } + + #if !GINPUT_TOUCH_NOTOUCH + // Was this a long click on a touch device? + if ((gmvmt(m)->d.flags & GMOUSE_VFLG_TOUCH) && m->clicktime >= gfxMillisecondsToTicks(GINPUT_TOUCH_CXTCLICK_TIME)) + r.buttons |= GMETA_MOUSE_CXTCLICK; + #endif + } + } + + // Step 6 - Send the event to the listeners that are interested. + { + GSourceListener *psl; + + // Send to the "All Mice" source listeners + psl = 0; + while ((psl = geventGetSourceListener((GSourceHandle)&MouseTimer, psl))) + SendMouseEvent(psl, m, &r); + + // Send to the mouse specific source listeners + psl = 0; + while ((psl = geventGetSourceListener((GSourceHandle)m, psl))) + SendMouseEvent(psl, m, &r); + } + + // Step 7 - Finally save the results + m->r.x = r.x; + m->r.y = r.y; + m->r.z = r.z; + m->r.buttons = r.buttons; +} + +static void MousePoll(void *param) { + GMouse * m; + (void) param; + + for(m = (GMouse *)gdriverGetNext(GDRIVER_TYPE_MOUSE, 0); m; m = (GMouse *)gdriverGetNext(GDRIVER_TYPE_MOUSE, (GDriver *)m)) { + if (!(gmvmt(m)->d.flags & GMOUSE_VFLG_NOPOLL) || (m->flags & GMOUSE_FLG_NEEDREAD)) + GetMouseReading(m); + } +} + +// Calibration user interface +#if !GINPUT_TOUCH_NOCALIBRATE_GUI + #if !defined(GFX_USE_GDISP) || !GFX_USE_GDISP + #error "GINPUT: GFX_USE_GDISP must be defined when calibration is required" + #endif + + static inline void CalibrationCrossDraw(GMouse *m, const point *pp) { + gdispGDrawLine(m->display, pp->x-CALIBRATION_CROSS_RADIUS, pp->y, pp->x-CALIBRATION_CROSS_INNERGAP, pp->y, CALIBRATION_CROSS_COLOR1); + gdispGDrawLine(m->display, pp->x+CALIBRATION_CROSS_INNERGAP, pp->y, pp->x+CALIBRATION_CROSS_RADIUS, pp->y, CALIBRATION_CROSS_COLOR1); + gdispGDrawLine(m->display, pp->x, pp->y-CALIBRATION_CROSS_RADIUS, pp->x, pp->y-CALIBRATION_CROSS_INNERGAP, CALIBRATION_CROSS_COLOR1); + gdispGDrawLine(m->display, pp->x, pp->y+CALIBRATION_CROSS_INNERGAP, pp->x, pp->y+CALIBRATION_CROSS_RADIUS, CALIBRATION_CROSS_COLOR1); + gdispGDrawLine(m->display, pp->x-CALIBRATION_CROSS_RADIUS, pp->y+CALIBRATION_CROSS_RADIUS, pp->x-CALIBRATION_CROSS_RADIUS/2, pp->y+CALIBRATION_CROSS_RADIUS, CALIBRATION_CROSS_COLOR2); + gdispGDrawLine(m->display, pp->x-CALIBRATION_CROSS_RADIUS, pp->y+CALIBRATION_CROSS_RADIUS/2, pp->x-CALIBRATION_CROSS_RADIUS, pp->y+CALIBRATION_CROSS_RADIUS, CALIBRATION_CROSS_COLOR2); + gdispGDrawLine(m->display, pp->x-CALIBRATION_CROSS_RADIUS, pp->y-CALIBRATION_CROSS_RADIUS, pp->x-CALIBRATION_CROSS_RADIUS/2, pp->y-CALIBRATION_CROSS_RADIUS, CALIBRATION_CROSS_COLOR2); + gdispGDrawLine(m->display, pp->x-CALIBRATION_CROSS_RADIUS, pp->y-CALIBRATION_CROSS_RADIUS/2, pp->x-CALIBRATION_CROSS_RADIUS, pp->y-CALIBRATION_CROSS_RADIUS, CALIBRATION_CROSS_COLOR2); + gdispGDrawLine(m->display, pp->x+CALIBRATION_CROSS_RADIUS/2, pp->y+CALIBRATION_CROSS_RADIUS, pp->x+CALIBRATION_CROSS_RADIUS, pp->y+CALIBRATION_CROSS_RADIUS, CALIBRATION_CROSS_COLOR2); + gdispGDrawLine(m->display, pp->x+CALIBRATION_CROSS_RADIUS, pp->y+CALIBRATION_CROSS_RADIUS/2, pp->x+CALIBRATION_CROSS_RADIUS, pp->y+CALIBRATION_CROSS_RADIUS, CALIBRATION_CROSS_COLOR2); + gdispGDrawLine(m->display, pp->x+CALIBRATION_CROSS_RADIUS/2, pp->y-CALIBRATION_CROSS_RADIUS, pp->x+CALIBRATION_CROSS_RADIUS, pp->y-CALIBRATION_CROSS_RADIUS, CALIBRATION_CROSS_COLOR2); + gdispGDrawLine(m->display, pp->x+CALIBRATION_CROSS_RADIUS, pp->y-CALIBRATION_CROSS_RADIUS, pp->x+CALIBRATION_CROSS_RADIUS, pp->y-CALIBRATION_CROSS_RADIUS/2, CALIBRATION_CROSS_COLOR2); + } + + static inline void CalibrationCrossClear(GMouse *m, const point *pp) { + gdispGFillArea(m->display, pp->x - CALIBRATION_CROSS_RADIUS, pp->y - CALIBRATION_CROSS_RADIUS, CALIBRATION_CROSS_RADIUS*2, CALIBRATION_CROSS_RADIUS*2, CALIBRATION_BACKGROUND); + } static inline void CalibrationCalculate(GMouse *m, const point *cross, const point *points) { float dx; @@ -165,220 +434,178 @@ static GTIMER_DECL(MouseTimer); - c1 * ((float)points[0].x * (float)points[2].y - (float)points[2].x * (float)points[0].y) + c2 * ((float)points[0].x * (float)points[1].y - (float)points[1].x * (float)points[0].y)) / dx; } -#endif -static void GetMouseReading(GMouse *m) { - GMouseReading r; + static void CalibrateMouse(GMouse *m) { + coord_t w, h; + point cross[4]; // The locations of the test points on the display + point points[4]; // The x, y readings obtained from the mouse for each test point + font_t font1, font2; - // Get the raw reading. - gmvmt(m)->get(m, &r); - m->flags &= ~GMOUSE_FLG_NEEDREAD; - - // If touch then calculate button 0 from z - if ((gmvmt(m)->d.flags & GMOUSE_VFLG_TOUCH)) { - if (gmvmt(m)->z_min <= gmvmt(m)->z_max) { - if (r.z >= gmvmt(m)->z_touchon) r.buttons |= GINPUT_MOUSE_BTN_LEFT; - else if (r.z <= gmvmt(m)->z_touchoff) r.buttons &= ~GINPUT_MOUSE_BTN_LEFT; - else return; // bad transitional reading - } else { - if (r.z <= gmvmt(m)->z_touchon) r.buttons |= GINPUT_MOUSE_BTN_LEFT; - else if (r.z >= gmvmt(m)->z_touchoff) r.buttons &= ~GINPUT_MOUSE_BTN_LEFT; - else return; // bad transitional reading - } - } - - // Double check up & down events if needed - if ((gmvmt(m)->d.flags & GMOUSE_VFLG_POORUPDOWN)) { - // Are we in a transition test - if ((m->flags & GMOUSE_FLG_INDELTA)) { - if (!((r.buttons ^ m->r.buttons) & GINPUT_MOUSE_BTN_LEFT)) { - // Transition failed - m->flags &= ~GMOUSE_FLG_INDELTA; - return; - } - // Transition succeeded - m->flags &= ~GMOUSE_FLG_INDELTA; - - // Should we start a transition test - } else if (((r.buttons ^ m->r.buttons) & GINPUT_MOUSE_BTN_LEFT)) { - m->flags |= GMOUSE_FLG_INDELTA; - return; - } - } - - // If the mouse is up we may need to keep our previous position - if ((gmvmt(m)->d.flags & GMOUSE_VFLG_ONLY_DOWN) && !(r.buttons & GINPUT_MOUSE_BTN_LEFT)) { - r.x = m->r.x; - r.y = m->r.y; - - } else { - coord_t w, h; - - #if !GINPUT_TOUCH_NOCALIBRATE - // Do we need to calibrate the reading? - if ((m->flags & GMOUSE_FLG_CALIBRATE)) - CalibrationTransform(&r, &m->caldata); + font1 = gdispOpenFont(CALIBRATION_FONT); + font2 = gdispOpenFont(CALIBRATION_FONT2); + w = gdispGGetWidth(m->display); + h = gdispGGetHeight(m->display); + #if GDISP_NEED_CLIP + gdispGSetClip(m->display, 0, 0, w, h); #endif - // We can't clip or rotate if we don't have a display - if (m->display) { + // Ensure we get minimaly processed readings for the calibration + m->flags |= GMOUSE_FLG_IN_CAL; - // We now need display information - w = gdispGGetWidth(m->display); - h = gdispGGetHeight(m->display); + // Set up our calibration locations + if ((gmvmt(m)->d.flags & GMOUSE_VFLG_CAL_EXTREMES)) { + cross[0].x = 0; cross[0].y = 0; + cross[1].x = w-1; cross[1].y = 0; + cross[2].x = w-1; cross[2].y = h-1; + cross[3].x = w/2; cross[3].y = h/2; + } else { + cross[0].x = w/4; cross[0].y = h/4; + cross[1].x = w-w/4; cross[1].y = h/4; + cross[2].x = w-w/4; cross[2].y = h-h/4; + cross[3].x = w/2; cross[3].y = h/2; + } + + // Perform calibration until we get a valid result + while(1) { + + // Set up the calibration display + gdispGClear(m->display, Blue); + gdispGFillStringBox(m->display, + 0, CALIBRATION_TITLE_Y, w, CALIBRATION_TITLE_HEIGHT, + CALIBRATION_TITLE, font1, CALIBRATION_TITLE_COLOR, CALIBRATION_TITLE_BACKGROUND, + justifyCenter); + + // Calculate the calibration + { + unsigned i, maxpoints; + + maxpoints = (gmvmt(m)->d.flags & GMOUSE_VFLG_CAL_TEST) ? 4 : 3; + + // Loop through the calibration points + for(i = 0; i < maxpoints; i++) { + int32_t px, py; + unsigned j; + + // Draw the current calibration point + CalibrationCrossDraw(m, &cross[i]); + + // Get a valid "point pressed" average reading + do { + // Wait for the mouse to be pressed + while(!(m->r.buttons & GINPUT_MOUSE_BTN_LEFT)) + gfxSleepMilliseconds(CALIBRATION_POLL_PERIOD); + + // Sum samples taken every CALIBRATION_POLL_PERIOD milliseconds while the mouse is down + px = py = j = 0; + while((m->r.buttons & GINPUT_MOUSE_BTN_LEFT)) { + // Limit sampling period to prevent overflow + if (j < CALIBRATION_MAXPRESS_PERIOD/CALIBRATION_POLL_PERIOD) { + px += m->r.x; + py += m->r.y; + j++; + } + gfxSleepMilliseconds(CALIBRATION_POLL_PERIOD); + } + + // Ignore presses less than CALIBRATION_MAXPRESS_PERIOD milliseconds + } while(j < CALIBRATION_MINPRESS_PERIOD/CALIBRATION_POLL_PERIOD); + points[i].x = px / j; + points[i].y = py / j; + + // Clear the current calibration point + CalibrationCrossClear(m, &cross[i]); + } + + // Apply 3 point calibration algorithm + CalibrationCalculate(m, cross, points); + + // Skip the 4th point tests if we don't want them + if (maxpoints < 4) + break; + } + + /* Verification of correctness of calibration (optional) : + * See if the 4th point (Middle of the screen) coincides with the calibrated + * result. If point is within +/- Squareroot(ERROR) pixel margin, then successful calibration + * Else, start from the beginning. + */ + { + const GMouseJitter *pj; + uint32_t err; + + // Are we in pen or finger mode + pj = (m->flags & GMOUSE_FLG_FINGERMODE) ? &gmvmt(m)->finger_jitter : &gmvmt(m)->pen_jitter; + + // Transform the co-ordinates + CalibrationTransform((GMouseReading *)&points[3], &m->caldata); - #if GDISP_NEED_CONTROL // Do we need to rotate the reading to match the display - if (!(gmvmt(m)->d.flags & GMOUSE_VFLG_SELFROTATION)) { - coord_t t; + #if GDISP_NEED_CONTROL + if (!(gmvmt(m)->d.flags & GMOUSE_VFLG_SELFROTATION)) { + coord_t t; - switch(gdispGGetOrientation(m->display)) { - case GDISP_ROTATE_0: - break; - case GDISP_ROTATE_90: - t = r.x; - r.x = w - 1 - r.y; - r.y = t; - break; - case GDISP_ROTATE_180: - r.x = w - 1 - r.x; - r.y = h - 1 - r.y; - break; - case GDISP_ROTATE_270: - t = r.y; - r.y = h - 1 - r.x; - r.x = t; - break; - default: - break; + switch(gdispGGetOrientation(m->display)) { + case GDISP_ROTATE_0: + break; + case GDISP_ROTATE_90: + t = points[3].x; + points[3].x = w - 1 - points[3].y; + points[3].y = t; + break; + case GDISP_ROTATE_180: + points[3].x = w - 1 - points[3].x; + points[3].y = h - 1 - points[3].y; + break; + case GDISP_ROTATE_270: + t = points[3].y; + points[3].y = h - 1 - points[3].x; + points[3].x = t; + break; + default: + break; + } } - } - #endif + #endif - // Do we need to clip the reading to the display - if ((m->flags & GMOUSE_FLG_CLIP)) { - if (r.x < 0) r.x = 0; - else if (r.x >= w) r.x = w-1; - if (r.y < 0) r.y = 0; - else if (r.y >= h) r.y = h-1; + // Is this accurate enough? + err = (points[3].x - cross[3].x) * (points[3].x - cross[3].x) + (points[3].y - cross[3].y) * (points[3].y - cross[3].y); + if (err <= (uint32_t)pj->calibrate * (uint32_t)pj->calibrate) + break; + + // No - Display error and try again + gdispGFillStringBox(m->display, + 0, CALIBRATION_ERROR_Y, w, CALIBRATION_ERROR_HEIGHT, + CALIBRATION_ERROR_TEXT, font2, CALIBRATION_ERROR_COLOR, CALIBRATION_ERROR_BACKGROUND, + justifyCenter); + gfxSleepMilliseconds(5000); } } + + // We are done calibrating + gdispCloseFont(font1); + gdispCloseFont(font2); + m->flags |= GMOUSE_FLG_CALIBRATE|GMOUSE_FLG_CLIP; + m->flags &= ~GMOUSE_FLG_IN_CAL; + + // Force an initial reading + m->r.buttons = 0; + GetMouseReading(m); + + // Save the calibration data (if possible) + #if GINPUT_TOUCH_USER_CALIBRATION_SAVE + SaveMouseCalibration(gdriverGetDriverInstanceNumber((GDriver *)m), &m->caldata, sizeof(GMouseCalibration)); + #endif + if (gmvmt(m)->calsave) + gmvmt(m)->calsave(m, &m->caldata, sizeof(GMouseCalibration)); + + // Clear the screen using the GWIN default background color + #if GFX_USE_GWIN + gdispGClear(m->display, gwinGetDefaultBgColor()); + #else + gdispGClear(m->display, GDISP_STARTUP_COLOR); + #endif } - - { - const GMouseJitter *pj; - uint32_t diff; - - // Are we in pen or finger mode - pj = (m->flags & GMOUSE_FLG_FINGERMODE) ? &gmvmt(m)->finger_jitter : &gmvmt(m)->pen_jitter; - - // Is this just movement jitter - if (pj->move > 0) { - diff = (uint32_t)(r.x - m->r.x) * (uint32_t)(r.x - m->r.x) + (uint32_t)(r.y - m->r.y) * (uint32_t)(r.y - m->r.y); - if (diff > (uint32_t)pj->move * (uint32_t)pj->move) { - r.x = m->r.x; - r.y = m->r.y; - } - } - - // Check if the click has moved outside the click area and if so cancel the click - if (pj->click > 0 && (m->flags & GMOUSE_FLG_CLICK_TIMER)) { - diff = (uint32_t)(r.x - m->clickpos.x) * (uint32_t)(r.x - m->clickpos.x) + (uint32_t)(r.y - m->clickpos.y) * (uint32_t)(r.y - m->clickpos.y); - if (diff > (uint32_t)pj->click * (uint32_t)pj->click) - m->flags &= ~GMOUSE_FLG_CLICK_TIMER; - } - } - - { - GSourceListener *psl; - GEventMouse *pe; - unsigned meta; - uint16_t upbtns, dnbtns; - - // Calculate out new event meta value and handle CLICK and CXTCLICK - dnbtns = r.buttons & ~m->r.buttons; - upbtns = ~r.buttons & m->r.buttons; - meta = GMETA_NONE; - - // Mouse down - if ((dnbtns & (GINPUT_MOUSE_BTN_LEFT|GINPUT_MOUSE_BTN_RIGHT))) { - m->clickpos.x = r.x; - m->clickpos.y = r.y; - m->clicktime = gfxSystemTicks(); - m->flags |= GMOUSE_FLG_CLICK_TIMER; - if ((dnbtns & GINPUT_MOUSE_BTN_LEFT)) - meta |= GMETA_MOUSE_DOWN; - } - - // Mouse up - if ((upbtns & (GINPUT_MOUSE_BTN_LEFT|GINPUT_MOUSE_BTN_RIGHT))) { - if ((upbtns & GINPUT_MOUSE_BTN_LEFT)) - meta |= GMETA_MOUSE_UP; - if ((m->flags & GMOUSE_FLG_CLICK_TIMER)) { - if ((upbtns & GINPUT_MOUSE_BTN_LEFT) - #if GINPUT_TOUCH_CLICK_TIME != TIME_INFINITE - && gfxSystemTicks() - m->clicktime < gfxMillisecondsToTicks(GINPUT_TOUCH_CLICK_TIME) - #endif - ) - meta |= GMETA_MOUSE_CLICK; - else - meta |= GMETA_MOUSE_CXTCLICK; - m->flags &= ~GMOUSE_FLG_CLICK_TIMER; - } - } - - // Send the event to the listeners that are interested. - psl = 0; - while ((psl = geventGetSourceListener((GSourceHandle)m, psl))) { - if (!(pe = (GEventMouse *)geventGetEventBuffer(psl))) { - // This listener is missing - save the meta events that have happened - psl->srcflags |= meta; - continue; - } - - // If we haven't really moved (and there are no meta events) don't bother sending the event - if (!meta && !psl->srcflags && !(psl->listenflags & GLISTEN_MOUSENOFILTER) - && r.x == m->r.x && r.y == m->r.y && r.buttons == m->r.buttons) - continue; - - // Send the event if we are listening for it - if (((r.buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEDOWNMOVES)) - || (!(r.buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEUPMOVES)) - || (meta && (psl->listenflags & GLISTEN_MOUSEMETA))) { - pe->type = (gmvmt(m)->d.flags & GMOUSE_VFLG_TOUCH) ? GEVENT_TOUCH : GEVENT_MOUSE; - pe->x = r.x; - pe->y = r.y; - pe->z = r.z; - pe->current_buttons = r.buttons; - pe->last_buttons = m->r.buttons; - pe->meta = meta; - if (psl->srcflags) { - pe->current_buttons |= GINPUT_MISSED_MOUSE_EVENT; - pe->meta |= psl->srcflags; - psl->srcflags = 0; - } - pe->display = m->display; - geventSendEvent(psl); - } - } - } - - // Finally save the results - m->r.x = r.x; - m->r.y = r.y; - m->r.z = r.z; - m->r.buttons = r.buttons; -} - -static void MousePoll(void *param) { - GMouse * m; - (void) param; - - for(m = (GMouse *)gdriverGetNext(GDRIVER_TYPE_MOUSE, 0); m; m = (GMouse *)gdriverGetNext(GDRIVER_TYPE_MOUSE, (GDriver *)m)) { - if (!(gmvmt(m)->d.flags & GMOUSE_VFLG_NOPOLL) || (m->flags & GMOUSE_FLG_NEEDREAD)) - GetMouseReading(m); - } -} +#endif void _gmouseInit(void) { // GINPUT_MOUSE_DRIVER_LIST is defined - create each driver instance @@ -388,298 +615,173 @@ void _gmouseInit(void) { extern GDriverVMTList GINPUT_MOUSE_DRIVER_LIST; static const struct GDriverVMT const * dclist[] = {GINPUT_MOUSE_DRIVER_LIST}; - static const unsigned dnlist[] = {GDISP_CONTROLLER_DISPLAYS}; - for(i = 0; i < sizeof(dclist)/sizeof(dclist[0]); i++) - gdriverRegister(dclist[i]); + for(i = 0; i < sizeof(dclist)/sizeof(dclist[0]); i++) { + if (!(dclist[i]->flags & GMOUSE_VFLG_DYNAMICONLY)) + gdriverRegister(dclist[i]); + } } - // One and only one display + // One and only one mouse #else { - extern GDriverVMTList GINPUTMOUSEVMT_OnlyOne; + extern GDriverVMTList GMOUSEVMT_OnlyOne; - gdriverRegister(GINPUTMOUSEVMT_OnlyOne); + if (!(GMOUSEVMT_OnlyOne->flags & GMOUSE_VFLG_DYNAMICONLY)) + gdriverRegister(GMOUSEVMT_OnlyOne); } #endif + } void _gmouseDeinit(void) { + gtimerDeinit(&MouseTimer); } -GSourceHandle ginputGetMouse(uint16_t instance) { - GMouse *m; - #if GINPUT_MOUSE_NEED_CALIBRATION - GCalibration *pc; +bool_t _gmouseInitDriver(GDriver *g, unsigned driverinstance, unsigned systeminstance) { + #define m ((GMouse *)g) + (void) systeminstance; + + // Init the mouse + if (!gmvmt(m)->init((GMouse *)g, driverinstance)) + return FALSE; + + #if !GINPUT_TOUCH_NOTOUCH + // Should this mouse start in finger mode? + if ((gmvmt(m)->d.flags & GMOUSE_VFLG_DEFAULTFINGER)) + m->flags |= GMOUSE_FLG_FINGERMODE; #endif - if (!(m = (GMouse *)gdriverGetInstance(GDRIVER_TYPE_MOUSE, instance))) - return 0; + // Ensure the Poll timer is started + if (!gtimerIsActive(&MouseTimer)) + gtimerStart(&MouseTimer, MousePoll, 0, TRUE, GINPUT_MOUSE_POLL_PERIOD); + + return TRUE; + + #undef m +} + +void _gmousePostInitDriver(GDriver *g) { + #define m ((GMouse *)g) // Make sure we have a valid mouse display if (!m->display) m->display = GDISP; - // Do we need to initialise the mouse subsystem? - if (!(m->flags & FLG_INIT_DONE)) { - ginput_lld_mouse_init(); + #if !GINPUT_TOUCH_NOCALIBRATE && !GINPUT_TOUCH_STARTRAW + if ((gmvmt(m)->d.flags & GMOUSE_VFLG_CALIBRATE)) { + GMouseCalibration *pc; - #if GINPUT_MOUSE_NEED_CALIBRATION - #if GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE - if (!m->fnloadcal) { - m->fnloadcal = ginput_lld_mouse_calibration_load; - m->flags &= ~FLG_CAL_FREE; - } - if (!m->fnsavecal) - m->fnsavecal = ginput_lld_mouse_calibration_save; + #if GINPUT_TOUCH_USER_CALIBRATION_LOAD + if ((pc = (GMouseCalibration *)LoadMouseCalibration(gdriverGetDriverInstanceNumber((GDriver *)m), sizeof(GMouseCalibration)))) { + memcpy(&m->caldata, pc, sizeof(GMouseCalibration)); + #if GINPUT_TOUCH_USER_CALIBRATION_FREE + gfxFree(pc); + #endif + m->flags |= GMOUSE_FLG_CALIBRATE|GMOUSE_FLG_CLIP; + } else + #endif + if (gmvmt(m)->calload && (pc = (GMouseCalibration *)gmvmt(m)->calload(m, sizeof(GMouseCalibration)))) { + memcpy(&m->caldata, pc, sizeof(GMouseCalibration)); + if ((gmvmt(m)->d.flags & GMOUSE_VFLG_CAL_LOADFREE)) + gfxFree(pc); + m->flags |= GMOUSE_FLG_CALIBRATE|GMOUSE_FLG_CLIP; + } + #if !GINPUT_TOUCH_NOCALIBRATE_GUI + else + CalibrateMouse(m); #endif - if (m->fnloadcal && (pc = (Calibration *)m->fnloadcal(instance))) { - memcpy(&m->caldata, pc, sizeof(m->caldata)); - m->flags |= (FLG_CAL_OK|FLG_CAL_SAVED); - if ((m->flags & FLG_CAL_FREE)) - gfxFree((void *)pc); - } else if (instance == 9999) { - CalibrationSetIdentity(&m->caldata); - m->flags |= (FLG_CAL_OK|FLG_CAL_SAVED|FLG_CAL_RAW); - } else - ginputCalibrateMouse(instance); - #endif + } + #endif - // Get the first reading - m->last_buttons = 0; - get_calibrated_reading(&m->t); + // Get the first reading + GetMouseReading(m); - // Mark init as done and start the Poll timer - m->flags |= FLG_INIT_DONE; - gtimerStart(&MouseTimer, MousePoll, 0, TRUE, GINPUT_MOUSE_POLL_PERIOD); - } - - // Return our structure as the handle - return (GSourceHandle)m; + #undef m } -void ginputSetMouseDisplay(uint16_t instance, GDisplay *g) { - if (instance) +void _gmouseDeInitDriver(GDriver *g) { + (void) g; +} + +GSourceHandle ginputGetMouse(unsigned instance) { + if (instance == GMOUSE_ALL_INSTANCES) + return (GSourceHandle)&MouseTimer; + return (GSourceHandle)gdriverGetInstance(GDRIVER_TYPE_MOUSE, instance); +} + +void ginputSetMouseDisplay(unsigned instance, GDisplay *g) { + GMouse *m; + + if (!(m = (GMouse *)gdriverGetInstance(GDRIVER_TYPE_MOUSE, instance))) return; m->display = g ? g : GDISP; } -GDisplay *ginputGetMouseDisplay(uint16_t instance) { - if (instance) +GDisplay *ginputGetMouseDisplay(unsigned instance) { + GMouse *m; + + if (!(m = (GMouse *)gdriverGetInstance(GDRIVER_TYPE_MOUSE, instance))) return 0; return m->display; } -bool_t ginputGetMouseStatus(uint16_t instance, GEventMouse *pe) { +bool_t ginputGetMouseStatus(unsigned instance, GEventMouse *pe) { + GMouse *m; + // Win32 threads don't seem to recognise priority and/or pre-emption // so we add a sleep here to prevent 100% polled applications from locking up. gfxSleepMilliseconds(1); - if (instance || (m->flags & (FLG_INIT_DONE|FLG_IN_CAL)) != FLG_INIT_DONE) + if (!(m = (GMouse *)gdriverGetInstance(GDRIVER_TYPE_MOUSE, instance))) return FALSE; - pe->type = GINPUT_MOUSE_EVENT_TYPE; - pe->x = m->t.x; - pe->y = m->t.y; - pe->z = m->t.z; - pe->current_buttons = m->t.buttons; - pe->last_buttons = m->last_buttons; - if (pe->current_buttons & ~pe->last_buttons & GINPUT_MOUSE_BTN_LEFT) - pe->meta = GMETA_MOUSE_DOWN; - else if (~pe->current_buttons & pe->last_buttons & GINPUT_MOUSE_BTN_LEFT) - pe->meta = GMETA_MOUSE_UP; - else - pe->meta = GMETA_NONE; + #if !GINPUT_TOUCH_NOCALIBRATE_GUI + if ((m->flags & GMOUSE_FLG_IN_CAL)) + return FALSE; + #endif + + #if !GINPUT_TOUCH_NOTOUCH + pe->type = (gmvmt(m)->d.flags & GMOUSE_VFLG_TOUCH) ? GEVENT_TOUCH : GEVENT_MOUSE; + #else + pe->type = GEVENT_MOUSE; + #endif + pe->x = m->r.x; + pe->y = m->r.y; + pe->z = m->r.z; + pe->buttons = m->r.buttons; + pe->display = m->display; return TRUE; } -bool_t ginputCalibrateMouse(uint16_t instance) { - #if GINPUT_TOUCH_NOCALIBRATE +#if !GINPUT_TOUCH_NOTOUCH + void ginputSetFingerMode(unsigned instance, bool_t on) { + GMouse *m; - (void) instance; - - return FALSE; - #else - - const coord_t height = gdispGGetHeight(MouseConfig.display); - const coord_t width = gdispGGetWidth(MouseConfig.display); - #if GINPUT_MOUSE_CALIBRATE_EXTREMES - const MousePoint cross[] = {{0, 0}, - {(width - 1) , 0}, - {(width - 1) , (height - 1)}, - {(width / 2), (height / 2)}}; /* Check point */ - #else - const MousePoint cross[] = {{(width / 4), (height / 4)}, - {(width - (width / 4)) , (height / 4)}, - {(width - (width / 4)) , (height - (height / 4))}, - {(width / 2), (height / 2)}}; /* Check point */ - #endif - MousePoint points[4]; - const MousePoint *pc; - MousePoint *pt; - int32_t px, py; - unsigned i, j; - font_t font1, font2; - #if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0 - unsigned err; - #endif - - if (instance || (MouseConfig.flags & FLG_IN_CAL)) - return FALSE; - - font1 = gdispOpenFont(GINPUT_MOUSE_CALIBRATION_FONT); - font2 = gdispOpenFont(GINPUT_MOUSE_CALIBRATION_FONT2); - - MouseConfig.flags |= FLG_IN_CAL; - gtimerStop(&MouseTimer); - MouseConfig.flags &= ~(FLG_CAL_OK|FLG_CAL_SAVED|FLG_CAL_RAW); - - #if GDISP_NEED_CLIP - gdispGSetClip(MouseConfig.display, 0, 0, width, height); - #endif - - #if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0 - while(1) { - #endif - gdispGClear(MouseConfig.display, Blue); - - gdispGFillStringBox(MouseConfig.display, 0, 5, width, 30, GINPUT_MOUSE_CALIBRATION_TEXT, font1, White, Blue, justifyCenter); - - for(i = 0, pt = points, pc = cross; i < GINPUT_MOUSE_CALIBRATION_POINTS; i++, pt++, pc++) { - CalibrationCrossDraw(pc); - - do { - - /* Wait for the mouse to be pressed */ - while(get_raw_reading(&MouseConfig.t), !(MouseConfig.t.buttons & GINPUT_MOUSE_BTN_LEFT)) - gfxSleepMilliseconds(20); - - /* Average all the samples while the mouse is down */ - for(px = py = 0, j = 0; - gfxSleepMilliseconds(20), /* Settling time between readings */ - get_raw_reading(&MouseConfig.t), - (MouseConfig.t.buttons & GINPUT_MOUSE_BTN_LEFT); - j++) { - px += MouseConfig.t.x; - py += MouseConfig.t.y; - } - - } while(!j); - - pt->x = px / j; - pt->y = py / j; - - CalibrationCrossClear(pc); - - if (i >= 1 && pt->x == (pt-1)->x && pt->y == (pt-1)->y) { - gdispGFillStringBox(MouseConfig.display, 0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_SAME_TEXT, font2, Red, Yellow, justifyCenter); - gfxSleepMilliseconds(5000); - gdispGFillArea(MouseConfig.display, 0, 35, width, 40, Blue); - } - - } - - /* Apply 3 point calibration algorithm */ - CalibrationCalculate(&MouseConfig, cross, points); - - /* Verification of correctness of calibration (optional) : - * See if the 4th point (Middle of the screen) coincides with the calibrated - * result. If point is within +/- Squareroot(ERROR) pixel margin, then successful calibration - * Else, start from the beginning. - */ - #if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0 - /* Transform the co-ordinates */ - MouseConfig.t.x = points[3].x; - MouseConfig.t.y = points[3].y; - CalibrationTransform(&MouseConfig.t, &MouseConfig.caldata); - _tsOrientClip(&MouseConfig.t, MouseConfig.display, FALSE); - - /* Calculate the delta */ - err = (MouseConfig.t.x - cross[3].x) * (MouseConfig.t.x - cross[3].x) + - (MouseConfig.t.y - cross[3].y) * (MouseConfig.t.y - cross[3].y); - - if (err <= GINPUT_MOUSE_MAX_CALIBRATION_ERROR * GINPUT_MOUSE_MAX_CALIBRATION_ERROR) - break; - - gdispGFillStringBox(MouseConfig.display, 0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_ERROR_TEXT, font2, Red, Yellow, justifyCenter); - gfxSleepMilliseconds(5000); - } - #endif - - // Restart everything - gdispCloseFont(font1); - gdispCloseFont(font2); - MouseConfig.flags |= FLG_CAL_OK; - MouseConfig.last_buttons = 0; - get_calibrated_reading(&MouseConfig.t); - MouseConfig.flags &= ~FLG_IN_CAL; - if ((MouseConfig.flags & FLG_INIT_DONE)) - gtimerStart(&MouseTimer, MousePoll, 0, TRUE, GINPUT_MOUSE_POLL_PERIOD); - - // Save the calibration data (if possible) - if (MouseConfig.fnsavecal) { - MouseConfig.fnsavecal(instance, (const uint8_t *)&MouseConfig.caldata, sizeof(MouseConfig.caldata)); - MouseConfig.flags |= FLG_CAL_SAVED; - } - - // Clear the screen using the GWIN default background color - #if GFX_USE_GWIN - gdispGClear(MouseConfig.display, gwinGetDefaultBgColor()); - #else - gdispGClear(MouseConfig.display, Black); - #endif - - return TRUE; - #endif -} - -/* Set the routines to save and fetch calibration data. - * This function should be called before first calling ginputGetMouse() for a particular instance - * as the ginputGetMouse() routine may attempt to fetch calibration data and perform a startup calibration if there is no way to get it. - * If this is called after ginputGetMouse() has been called and the driver requires calibration storage, it will immediately save the data is has already obtained. - * The 'requireFree' parameter indicates if the fetch buffer must be free()'d to deallocate the buffer provided by the Fetch routine. - */ -void ginputSetMouseCalibrationRoutines(uint16_t instance, GMouseCalibrationSaveRoutine fnsave, GMouseCalibrationLoadRoutine fnload, bool_t requireFree) { - #if GINPUT_MOUSE_NEED_CALIBRATION - if (instance) + if (!(m = (GMouse *)gdriverGetInstance(GDRIVER_TYPE_MOUSE, instance))) return; - MouseConfig.fnloadcal = fnload; - MouseConfig.fnsavecal = fnsave; - if (requireFree) - MouseConfig.flags |= FLG_CAL_FREE; + if (on) + m->flags |= GMOUSE_FLG_FINGERMODE; else - MouseConfig.flags &= ~FLG_CAL_FREE; - #if GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE - if (!MouseConfig.fnloadcal) { - MouseConfig.fnloadcal = ginput_lld_mouse_calibration_load; - MouseConfig.flags &= ~FLG_CAL_FREE; - } - if (!MouseConfig.fnsavecal) - MouseConfig.fnsavecal = ginput_lld_mouse_calibration_save; - #endif - if (MouseConfig.fnsavecal && (MouseConfig.flags & (FLG_CAL_OK|FLG_CAL_SAVED)) == FLG_CAL_OK) { - MouseConfig.fnsavecal(instance, (const uint8_t *)&MouseConfig.caldata, sizeof(MouseConfig.caldata)); - MouseConfig.flags |= FLG_CAL_SAVED; - } - #else - (void)instance, (void)fnsave, (void)fnload, (void)requireFree; - #endif -} + m->flags &= ~GMOUSE_FLG_FINGERMODE; -/* Test if a particular mouse instance requires routines to save its calibration data. */ -bool_t ginputRequireMouseCalibrationStorage(uint16_t instance) { - if (instance) - return FALSE; + } +#endif - #if GINPUT_MOUSE_NEED_CALIBRATION && !GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE +#if !GINPUT_TOUCH_NOCALIBRATE_GUI + bool_t ginputCalibrateMouse(unsigned instance) { + GMouse *m; + + if (!(m = (GMouse *)gdriverGetInstance(GDRIVER_TYPE_MOUSE, instance))) + return FALSE; + + CalibrateMouse(m); return TRUE; - #else - return FALSE; - #endif -} + } +#endif /* Wake up the mouse driver from an interrupt service routine (there may be new readings available) */ void ginputMouseWakeup(GMouse *m) { diff --git a/src/ginput/ginput_mouse.h b/src/ginput/ginput_mouse.h index 6cae66d1..1eff64f4 100644 --- a/src/ginput/ginput_mouse.h +++ b/src/ginput/ginput_mouse.h @@ -17,7 +17,7 @@ * * @pre GFX_USE_GINPUT must be set to TRUE in your gfxconf.h * @pre GINPUT_NEED_MOUSE must be set to TRUE in your gfxconf.h - * + * * @{ */ @@ -32,31 +32,29 @@ /* This type definition is also used by touch */ typedef struct GEventMouse_t { - GEventType type; // The type of this event (GEVENT_MOUSE or GEVENT_TOUCH) - coord_t x, y, z; // The position of the mouse. - // - For touch devices, Z is the current pressure if supported (otherwise 0) - // - For mice, Z is the 3rd dimension if supported (otherwise 0) - uint16_t current_buttons; // A bit is set if the button is down. - // - For touch only bit 0 is relevant - // - For mice the order of the buttons is (from 0 to n) left, right, middle, any other buttons - // - Bit 15 being set indicates that an important mouse event has been missed. - #define GINPUT_MOUSE_BTN_LEFT 0x0001 - #define GINPUT_MOUSE_BTN_RIGHT 0x0002 - #define GINPUT_MOUSE_BTN_MIDDLE 0x0004 - #define GINPUT_MOUSE_BTN_4 0x0008 - #define GINPUT_MISSED_MOUSE_EVENT 0x8000 - #define GINPUT_TOUCH_PRESSED GINPUT_MOUSE_BTN_LEFT - uint16_t last_buttons; // The value of current_buttons on the last event - enum GMouseMeta_e { - GMETA_NONE = 0, // There is no meta event currently happening - GMETA_MOUSE_DOWN = 1, // Button 0 has just gone down - GMETA_MOUSE_UP = 2, // Button 0 has just gone up - GMETA_MOUSE_CLICK = 4, // Button 0 has just gone through a short down - up cycle - GMETA_MOUSE_CXTCLICK = 8 // For mice - The right button has just been depressed - // For touch - a long press has just occurred - } meta; + GEventType type; // The type of this event (GEVENT_MOUSE or GEVENT_TOUCH) + coord_t x, y, z; // The position of the mouse. + // - For touch devices, Z is the current pressure if supported (values are device specific) + // - For mice, Z is the 3rd dimension if supported (values are device specific) + uint16_t buttons; // A bit is set if the button is down or a meta event has occurred. + #define GINPUT_MOUSE_BTN_MASK 0x000F // The "button is down" mask + #define GINPUT_MOUSE_BTN_LEFT 0x0001 // The left mouse button is currently down + #define GINPUT_MOUSE_BTN_RIGHT 0x0002 // The right mouse button is currently down + #define GINPUT_MOUSE_BTN_MIDDLE 0x0004 // The middle mouse button is currently down + #define GINPUT_MOUSE_BTN_4 0x0008 // The 4th mouse button is currently down + #define GINPUT_TOUCH_PRESSED 0x0001 // The touch surface is currently touched + + #define GMETA_MASK 0x00F0 // The "button transition" mask + #define GMETA_NONE 0x0000 // No "button transition" events + #define GMETA_MOUSE_DOWN 0x0001 // Left mouse/touch has just gone down + #define GMETA_MOUSE_UP 0x0002 // Left mouse/touch has just gone up + #define GMETA_MOUSE_CLICK 0x0004 // Left mouse/touch has just gone through a click (short down - up cycle) + #define GMETA_MOUSE_CXTCLICK 0x0008 // Right mouse has just been depressed or touch has gone through a long click + + #define GINPUT_MISSED_MOUSE_EVENT 0x8000 // Oops - a mouse event has previously been missed + GDisplay * display; // The display this mouse is currently associated with. - } GEventMouse; +} GEventMouse; // Mouse/Touch Listen Flags - passed to geventAddSourceToListener() #define GLISTEN_MOUSEMETA 0x0001 // Create events for meta events such as CLICK and CXTCLICK @@ -68,12 +66,13 @@ typedef struct GEventMouse_t { #define GLISTEN_TOUCHUPMOVES GLISTEN_MOUSEUPMOVES #define GLISTEN_TOUCHNOFILTER GLISTEN_MOUSENOFILTER -#define GINPUT_MOUSE_NUM_PORTS 1 // The total number of mouse/touch inputs supported - // Event types for the mouse ginput source #define GEVENT_MOUSE (GEVENT_GINPUT_FIRST+0) #define GEVENT_TOUCH (GEVENT_GINPUT_FIRST+1) +// All mice +#define GMOUSE_ALL_INSTANCES ((unsigned)-1) + /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ @@ -83,16 +82,32 @@ extern "C" { #endif /** - * @brief Creates an instance of a mouse and returns the Source handler - * @note HACK: if the instance is 9999, it is treated as instance 0 except - * that no calibration will be performed! + * @brief Get the Source handler for a mouse using the instance number * - * @param[in] instance The ID of the mouse input instance (from 0 to 9999) + * @param[in] instance The mouse instance number * - * @return The source handle of the created instance + * @return The source handle of the mouse or NULL + * @note You can use the special value of GMOUSE_ALL_INSTANCES to + * get a source handle that returns events for all mice rather + * than a specific mouse. Using GMOUSE_ALL_INSTANCES will always + * return a valid spurce handle even if there are currently no mice + * in the system. */ - GSourceHandle ginputGetMouse(uint16_t instance); - + GSourceHandle ginputGetMouse(unsigned instance); + + /** + * @brief Should this device be in Pen mode or Finger mode + * @note A touch device (and even theoritically a mouse) can operate + * in either pen or finger mode. In finger mode typically a + * touch device will be far more tolerant of movement and other + * inaccuracies. Each driver specifies its own tolerances for + * pen versus finger mode. + * + * @param[in] instance The ID of the mouse input instance + * @param[in] on If true then finger mode is turned on. + */ + void ginputSetFingerMode(unsigned instance, bool_t on); + /** * @brief Assign the display associated with the mouse * @note This only needs to be called if the mouse is associated with a display @@ -104,7 +119,7 @@ extern "C" { * @param[in] instance The ID of the mouse input instance * @param[in] g The GDisplay to which this mouse belongs */ - void ginputSetMouseDisplay(uint16_t instance, GDisplay *g); + void ginputSetMouseDisplay(unsigned instance, GDisplay *g); /** * @brief Get the display currently associated with the mouse @@ -112,7 +127,7 @@ extern "C" { * * @param[in] instance The ID of the mouse input instance */ - GDisplay *ginputGetMouseDisplay(uint16_t instance); + GDisplay *ginputGetMouseDisplay(unsigned instance); /** * @brief Get the current mouse position and button status @@ -124,7 +139,7 @@ extern "C" { * * @return FALSE on an error (eg. invalid instance) */ - bool_t ginputGetMouseStatus(uint16_t instance, GEventMouse *pmouse); + bool_t ginputGetMouseStatus(unsigned instance, GEventMouse *pmouse); /** * @brief Performs a calibration @@ -133,42 +148,37 @@ extern "C" { * * @return FALSE if the driver dosen't support a calibration of if the handle is invalid */ - bool_t ginputCalibrateMouse(uint16_t instance); + bool_t ginputCalibrateMouse(unsigned instance); - /* Set the routines to save and fetch calibration data. - * This function should be called before first calling ginputGetMouse() for a particular instance - * as the gdispGetMouse() routine may attempt to fetch calibration data and perform a startup calibration if there is no way to get it. - * If this is called after gdispGetMouse() has been called and the driver requires calibration storage, it will immediately save the data is has already obtained. - * The 'requireFree' parameter indicates if the fetch buffer must be free()'d to deallocate the buffer provided by the Fetch routine. - */ - typedef void (*GMouseCalibrationSaveRoutine)(uint16_t instance, const uint8_t *calbuf, size_t sz); // Save calibration data - typedef const char * (*GMouseCalibrationLoadRoutine)(uint16_t instance); // Load calibration data (returns NULL if not data saved) + /** + * @brief Load a set of mouse calibration data + * @return A pointer to the data or NULL on failure + * + * @param[in] instance The mouse input instance number + * @param[in] sz The size in bytes of the data to retrieve. + * + * @note This routine is provided by the user application. It is only + * called if GINPUT_TOUCH_USER_CALIBRATION_LOAD has been set to TRUE in the + * users gfxconf.h file. + * @note If GINPUT_TOUCH_USER_CALIBRATION_FREE has been set to TRUE in the users + * gfxconf.h file then the buffer returned will be free'd using gfxFree(). + */ + void *LoadMouseCalibration(unsigned instance, size_t sz); - /** - * @brief Set the routines to store and restore calibration data + /** + * @brief Save a set of mouse calibration data + * @return TRUE if the save operation was successful. + * + * @param[in] instance The mouse input instance number + * @param[in] data The data to save + * @param[in] sz The size in bytes of the data to retrieve. * - * @details This function should be called before first calling ginputGetMouse() for a particular instance - * as the gdispGetMouse() routine may attempt to fetch calibration data and perform a startup calibration if there is no way to get it. - * If this is called after gdispGetMouse() has been called and the driver requires calibration storage, it will immediately save the - * data is has already obtained. - * - * @param[in] instance The ID of the mouse input instance - * @param[in] fnsave The routine to save the data - * @param[in] fnload The routine to restore the data - * @param[in] requireFree TRUE if the buffer returned by the load function must be freed by the mouse code. - */ - void ginputSetMouseCalibrationRoutines(uint16_t instance, GMouseCalibrationSaveRoutine fnsave, GMouseCalibrationLoadRoutine fnload, bool_t requireFree); + * @note This routine is provided by the user application. It is only + * called if GINPUT_TOUCH_USER_CALIBRATION_SAVE has been set to TRUE in the + * users gfxconf.h file. + */ + bool_t SaveMouseCalibration(unsigned instance, const void *data, size_t sz); - /** - * @brief Test if a particular mouse/touch instance requires routines to save it's alibration data - * @note Not implemented yet - * - * @param[in] instance The ID of the mouse input instance - * - * @return TRUE if needed - */ - bool_t ginputRequireMouseCalibrationStorage(uint16_t instance); - #ifdef __cplusplus } #endif diff --git a/src/ginput/sys_options.h b/src/ginput/sys_options.h index 7ccc7b78..e67a03ce 100644 --- a/src/ginput/sys_options.h +++ b/src/ginput/sys_options.h @@ -73,41 +73,97 @@ * @{ */ /** - * @brief Turn off touch mouse support. + * @brief Start touch devices without loading or running calibration. * @details Defaults to FALSE - * @note Touch device handling requires a lot of code. If your mouse doesn't require it - * this can be turned off to save a lot of space. + * @note This is used if you want to manually control the initial calibration + * process. In practice this is only useful for a touch driver test program. */ - #ifndef GINPUT_TOUCH_NOTOUCH - #define GINPUT_TOUCH_NOTOUCH FALSE + #ifndef GINPUT_TOUCH_STARTRAW + #define GINPUT_TOUCH_STARTRAW FALSE + #endif + /** + * @brief Turn off the touch calibration GUI. + * @details Defaults to FALSE + * @note Turning off the calibration GUI just turns off the manual calibration + * process. Readings may still be calibrated if calibration data + * can be loaded. + * @note Calibration requires a lot of code. If your device doesn't require it + * using this option can save a lot of space. + */ + #ifndef GINPUT_TOUCH_NOCALIBRATE_GUI + #define GINPUT_TOUCH_NOCALIBRATE_GUI FALSE #endif /** - * @brief Turn off calibration support. + * @brief Turn off all touch calibration support. * @details Defaults to FALSE - * @note Calibration requires a lot of code. If your mouse doesn't require it - * this can be turned off to save a lot of space. + * @note With this set to TRUE touch readings will not be calibrated. + * @note This automatically turns off the calibration GUI too! + * @note Calibration requires a lot of code. If your device doesn't require it + * using this option can save a lot of space. */ #ifndef GINPUT_TOUCH_NOCALIBRATE #define GINPUT_TOUCH_NOCALIBRATE FALSE #endif + /** + * @brief Turn off all touch support. + * @details Defaults to FALSE + * @note This automatically turns off all calibration and the calibration GUI too! + * @note Touch device handling requires a lot of code. If your device doesn't require it + * using this option can save a lot of space. + */ + #ifndef GINPUT_TOUCH_NOTOUCH + #define GINPUT_TOUCH_NOTOUCH FALSE + #endif /** * @brief Milliseconds between mouse polls. * @details Defaults to 25 millseconds * @note How often mice should be polled. More often leads to smoother mouse movement - * but increases CPU usage. If no mouse drivers need polling the poll is not - * started. + * but increases CPU usage. */ #ifndef GINPUT_MOUSE_POLL_PERIOD #define GINPUT_MOUSE_POLL_PERIOD 25 #endif /** - * @brief Milliseconds separating a CLICK from a CXTCLICK. - * @details Defaults to 700 millseconds - * @note How long it takes for a click to turn into a CXTCLICK on a touch device. + * @brief Maximum length of CLICK in milliseconds + * @details Defaults to 300 millseconds + * @note Mouse down to Mouse up times greater than this are not clicks. */ - #ifndef GINPUT_TOUCH_CLICK_TIME - #define GINPUT_TOUCH_CLICK_TIME 700 + #ifndef GINPUT_MOUSE_CLICK_TIME + #define GINPUT_MOUSE_CLICK_TIME 300 + #endif + /** + * @brief Milliseconds to generate a CXTCLICK on a touch device. + * @details Defaults to 700 millseconds + * @note If you hold the touch down for longer than this a CXTCLICK is generated + * but only on a touch device. + */ + #ifndef GINPUT_TOUCH_CXTCLICK_TIME + #define GINPUT_TOUCH_CXTCLICK_TIME 700 + #endif + /** + * @brief There is a user supplied routine to load mouse calibration data + * @details Defaults to FALSE + * @note If TRUE the user must supply the @p LoadMouseCalibration() routine. + */ + #ifndef GINPUT_TOUCH_USER_CALIBRATION_LOAD + #define GINPUT_TOUCH_USER_CALIBRATION_LOAD FALSE + #endif + /** + * @brief The buffer returned by the users @p LoadMouseCalibration() routine must be gfxFree()'d + * by the mouse code. + * @details Defaults to FALSE + */ + #ifndef GINPUT_TOUCH_USER_CALIBRATION_FREE + #define GINPUT_TOUCH_USER_CALIBRATION_FREE FALSE + #endif + /** + * @brief There is a user supplied routine to save mouse calibration data + * @details Defaults to FALSE + * @note If TRUE the user must supply the @p SaveMouseCalibration() routine. + */ + #ifndef GINPUT_TOUCH_USER_CALIBRATION_SAVE + #define GINPUT_TOUCH_USER_CALIBRATION_SAVE FALSE #endif /** @} */ diff --git a/src/ginput/sys_rules.h b/src/ginput/sys_rules.h index f98cc469..d9a367ce 100644 --- a/src/ginput/sys_rules.h +++ b/src/ginput/sys_rules.h @@ -31,6 +31,21 @@ #undef GFX_USE_GTIMER #define GFX_USE_GTIMER TRUE #endif + #if GINPUT_NEED_MOUSE + #if GINPUT_TOUCH_NOTOUCH + // No warning needed for this + #undef GINPUT_TOUCH_NOCALIBRATE + #define GINPUT_TOUCH_NOCALIBRATE TRUE + #endif + #if GINPUT_TOUCH_NOCALIBRATE + // No warning needed for this + #undef GINPUT_TOUCH_NOCALIBRATE_GUI + #define GINPUT_TOUCH_NOCALIBRATE_GUI TRUE + #endif + #if !GINPUT_TOUCH_NOTOUCH && GINPUT_MOUSE_CLICK_TIME > GINPUT_TOUCH_CXTCLICK_TIME + #error "GINPUT MOUSE: The GINPUT_MOUSE_CLICK_TIME must be <= GINPUT_TOUCH_CXTCLICK_TIME" + #endif + #endif #endif #endif /* _GINPUT_RULES_H */ diff --git a/src/gwin/gwin_widget.c b/src/gwin/gwin_widget.c index f85e6f20..cf1f59c7 100644 --- a/src/gwin/gwin_widget.c +++ b/src/gwin/gwin_widget.c @@ -114,7 +114,7 @@ static void gwidgetEvent(void *param, GEvent *pe) { // Is the mouse currently captured by this widget? if ((h->flags & (GWIN_FLG_WIDGET|GWIN_FLG_MOUSECAPTURE)) == (GWIN_FLG_WIDGET|GWIN_FLG_MOUSECAPTURE)) { gh = h; - if ((pme->last_buttons & ~pme->current_buttons & GINPUT_MOUSE_BTN_LEFT)) { + if ((pme->buttons & GMETA_MOUSE_UP)) { gh->flags &= ~GWIN_FLG_MOUSECAPTURE; if (wvmt->MouseUp) wvmt->MouseUp(gw, pme->x - gh->x, pme->y - gh->y); @@ -133,7 +133,7 @@ static void gwidgetEvent(void *param, GEvent *pe) { // Process any mouse down over the highest order window if it is an enabled widget if (gh && (gh->flags & (GWIN_FLG_WIDGET|GWIN_FLG_SYSENABLED)) == (GWIN_FLG_WIDGET|GWIN_FLG_SYSENABLED)) { - if ((~pme->last_buttons & pme->current_buttons & GINPUT_MOUSE_BTN_LEFT)) { + if ((pme->buttons & GMETA_MOUSE_DOWN)) { gh->flags |= GWIN_FLG_MOUSECAPTURE; if (wvmt->MouseDown) wvmt->MouseDown(gw, pme->x - gh->x, pme->y - gh->y); @@ -234,6 +234,7 @@ void _gwidgetInit(void) { geventListenerInit(&gl); geventRegisterCallback(&gl, gwidgetEvent, 0); + geventAttachSource(&gl, ginputGetMouse(GMOUSE_ALL_INSTANCES), GLISTEN_MOUSEMETA|GLISTEN_MOUSEDOWNMOVES); } void _gwidgetDeinit(void) @@ -427,13 +428,10 @@ bool_t gwinAttachListener(GListener *pl) { } #if GFX_USE_GINPUT && GINPUT_NEED_MOUSE - bool_t gwinAttachMouse(uint16_t instance) { - GSourceHandle gsh; - - if (!(gsh = ginputGetMouse(instance))) - return FALSE; - - return geventAttachSource(&gl, gsh, GLISTEN_MOUSEMETA|GLISTEN_MOUSEDOWNMOVES); + bool_t DEPRECATED("This call can now be removed. Attaching the mouse to GWIN is now automatic.") gwinAttachMouse(uint16_t instance) { + // This is now a NULL event because we automatically attach to all mice in the system. + (void) instance; + return TRUE; } #endif diff --git a/src/gwin/gwin_widget.h b/src/gwin/gwin_widget.h index 81c76263..2c503116 100644 --- a/src/gwin/gwin_widget.h +++ b/src/gwin/gwin_widget.h @@ -199,7 +199,7 @@ void gwinSetDefaultStyle(const GWidgetStyle *pstyle, bool_t updateAll); * @brief Get the current default style. * * @return The current default style. - * + * * @api */ const GWidgetStyle *gwinGetDefaultStyle(void); @@ -315,7 +315,7 @@ bool_t gwinAttachListener(GListener *pl); * * @api */ - bool_t gwinAttachMouse(uint16_t instance); + bool_t DEPRECATED("This call can now be removed. Attaching the mouse to GWIN is now automatic.") gwinAttachMouse(uint16_t instance); #endif #if (GFX_USE_GINPUT && GINPUT_NEED_TOGGLE) || defined(__DOXYGEN__) From 8410c8c8b509cfbf7add50b711cf2c425328815f Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 26 Sep 2014 16:27:34 +1000 Subject: [PATCH 12/87] Makefile: Add support for - - ..'s in the source path - USER_LISTINGS to control whether listings are generated - dependancy directory now a MACRO - support for Code::Blocks make targets --- boards/base/Win32/example/Makefile | 80 ++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 21 deletions(-) diff --git a/boards/base/Win32/example/Makefile b/boards/base/Win32/example/Makefile index 94a99caf..030cfc20 100644 --- a/boards/base/Win32/example/Makefile +++ b/boards/base/Win32/example/Makefile @@ -12,15 +12,32 @@ # To rebuild project do "make clean" and "make all". # +############################################################################################## +# Start of make control +# + +# Turn ChibiOS simimulator on or off? +USE_CHIBIOS=no + +# Verbose compiling? +USE_VERBOSE_COMPILE=no + +# Generate listing files? +USE_LISTING=no + +# Your project name and executable file name - Optional, defaults to the project directory name +#PROJECT=uGFX + +# +# End of make control +############################################################################################## + ############################################################################################## # Start of default section # CC = i686-pc-mingw32-gcc -g -# Turn ChibiOS simimulator on or off - uGFX doesn't need it but you might for other purposes. -USE_CHIBIOS=no - # List all default C defines here, like -D_DEBUG=1 DDEFS = @@ -34,7 +51,7 @@ DLIBDIR = DLIBS = -lws2_32 -lgdi32 -lwinmm # Make sure this empty for now -SRC = +SRC = # # End of default section @@ -44,9 +61,6 @@ SRC = # Start of user section # -# Define project name here -PROJECT = uGFX - # Imported source files and paths for uGFX GFXLIB = ../uGFX include $(GFXLIB)/gfx.mk @@ -108,51 +122,75 @@ OPT = -ggdb -O0 -fomit-frame-pointer ############################################################################################## -# Output directory and files -ifeq ($(BUILDDIR),) - BUILDDIR = .build +# Default project name is the project directory name +ifeq ($(PROJECT),) + PROJECT := $(notdir $(patsubst %/,%,$(dir $(abspath $(firstword $(MAKEFILE_LIST)))))) endif -ifeq ($(BUILDDIR),.) + +# Output directory and files +ifeq ($(MAKECMDGOALS),Debug) + BUILDDIR = bin/Debug +else ifeq ($(MAKECMDGOALS),Release) + BUILDDIR = bin/Release +else ifeq ($(BUILDDIR),) + BUILDDIR = .build +else ifeq ($(BUILDDIR),.) BUILDDIR = .build endif OBJDIR = $(BUILDDIR)/obj LSTDIR = $(BUILDDIR)/lst MAPDIR = $(BUILDDIR)/map +DEPDIR = .dep INCDIR = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR)) LIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR)) DEFS = $(DDEFS) $(UDEFS) ADEFS = $(DADEFS) $(UADEFS) -COBJ = $(addprefix $(OBJDIR)/, $(SRC:.c=.o)) -AOBJ = $(addprefix $(OBJDIR)/, $(ASRC:.s=.o)) +COBJ = $(addprefix $(OBJDIR)/, $(subst ../,_dot_dot/,$(SRC:.c=.o))) +AOBJ = $(addprefix $(OBJDIR)/, $(subst ../,_dot_dot/,$(ASRC:.s=.o))) OBJS = $(AOBJ) $(COBJ) LIBS = $(DLIBS) $(ULIBS) LDFLAGS = -Wl,-Map=$(MAPDIR)/$(PROJECT).map,--cref,--no-warn-mismatch $(LIBDIR) -CPFLAGS = $(OPT) -Wall -Wextra -Wstrict-prototypes -fverbose-asm -Wa,-alms=$(LSTDIR)/$(<:.c=.lst) $(DEFS) +CPFLAGS = $(OPT) -Wall -Wextra -Wstrict-prototypes -fverbose-asm $(DEFS) +ifeq ($(USE_LISTING),yes) + CPFLAGS += -Wa,-alms=$(LSTDIR)/$(<:.c=.lst) +endif # Generate dependency information -CPFLAGS += -MD -MP -MF .dep/$(@F).d +CPFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d # # makefile rules # +Debug Release: all + +cleanDebug cleanRelease: clean + -rm -fR bin + all: $(BUILDDIR) $(OBJS) $(BUILDDIR)/$(PROJECT).exe MAKE_ALL_RULE_HOOK +#all: main.cp + +main.cp: $(MYCSRC) + $(CC) -c $(CPFLAGS) -E -P -I. $(INCDIR) $< -o $@ MAKE_ALL_RULE_HOOK: $(BUILDDIR) $(OBJDIR) $(LSTDIR): mkdir -p $(OBJDIR) - mkdir -p $(LSTDIR) mkdir -p $(MAPDIR) +ifeq ($(USE_LISTING),yes) + mkdir -p $(LSTDIR) +endif ifneq ($(USE_VERBOSE_COMPILE),yes) @echo Compiler Options - $(CC) -c $(CPFLAGS) -I. $(INCDIR) main.c -o $(OBJDIR)/main.o @echo endif -$(OBJDIR)/%.o : %.c +.SECONDEXPANSION: +$(OBJDIR)/%.o : $$(subst _dot_dot/,../,%.c) @mkdir -p $(dir $@) ifeq ($(USE_VERBOSE_COMPILE),yes) @echo @@ -162,7 +200,7 @@ else @$(CC) -c $(CPFLAGS) -I. $(INCDIR) $< -o $@ endif -$(OBJDIR)/%.o : %.s +$(OBJDIR)/%.o : $$(subst _dot_dot/,../,%.s) @mkdir -p $(dir $@) ifeq ($(USE_VERBOSE_COMPILE),yes) @echo @@ -187,12 +225,12 @@ gcov: -mv *.gcov ./gcov clean: - -rm -fR .build - -rm -fR .dep + -rm -fR $(BUILDDIR) + -rm -fR $(DEPDIR) # # Include the dependency files, should be the last of the makefile # --include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) +-include $(shell mkdir $(DEPDIR) 2>/dev/null) $(wildcard $(DEPDIR)/*) # *** EOF *** From 8b1666e72f327c49b75f1f4f59ba55fa24863b3c Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 26 Sep 2014 16:28:26 +1000 Subject: [PATCH 13/87] Reorder initialisation to ensure gwin is initialised last --- src/gfx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 0803f59a..dfb438e2 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -89,9 +89,6 @@ void gfxInit(void) #if GFX_USE_GDISP _gdispInit(); #endif - #if GFX_USE_GWIN - _gwinInit(); - #endif #if GFX_USE_GINPUT _ginputInit(); #endif @@ -101,6 +98,9 @@ void gfxInit(void) #if GFX_USE_GAUDIO _gaudioInit(); #endif + #if GFX_USE_GWIN + _gwinInit(); + #endif } void gfxDeinit(void) @@ -110,6 +110,9 @@ void gfxDeinit(void) initDone = FALSE; // We deinitialise the opposite way as we initialised + #if GFX_USE_GWIN + _gwinDeinit(); + #endif #if GFX_USE_GAUDIN _gaudioDeinit(); #endif @@ -119,9 +122,6 @@ void gfxDeinit(void) #if GFX_USE_GINPUT _ginputDeinit(); #endif - #if GFX_USE_GWIN - _gwinDeinit(); - #endif #if GFX_USE_GDISP _gdispDeinit(); #endif From 72d04f891b5dd09ec4abdc8073a285b5d513946d Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 26 Sep 2014 16:29:52 +1000 Subject: [PATCH 14/87] Change to GDriver to support an initialisation parameter --- src/gdisp/driver.h | 2 +- src/gdisp/gdisp_gdisp.c | 9 +++++---- src/gdriver/gdriver_gdriver.c | 4 ++-- src/gdriver/sys_defs.h | 5 +++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/gdisp/driver.h b/src/gdisp/driver.h index 98bf64fc..8d22135d 100644 --- a/src/gdisp/driver.h +++ b/src/gdisp/driver.h @@ -620,7 +620,7 @@ typedef struct GDISPVMT { #ifdef __cplusplus extern "C" { #endif - bool_t _gdispInitDriver(GDriver *g, unsigned driverinstance, unsigned systeminstance); + bool_t _gdispInitDriver(GDriver *g, void *param, unsigned driverinstance, unsigned systeminstance); void _gdispPostInitDriver(GDriver *g); void _gdispDeInitDriver(GDriver *g); #ifdef __cplusplus diff --git a/src/gdisp/gdisp_gdisp.c b/src/gdisp/gdisp_gdisp.c index 74cfb67e..1552cea6 100644 --- a/src/gdisp/gdisp_gdisp.c +++ b/src/gdisp/gdisp_gdisp.c @@ -572,7 +572,7 @@ void _gdispInit(void) static const struct GDriverVMT const * dclist[] = {GDISP_DRIVER_LIST}; for(i = 0; i < sizeof(dclist)/sizeof(dclist[0]); i++) - gdriverRegister(dclist[i]); + gdriverRegister(dclist[i], 0); } #elif GDISP_TOTAL_DISPLAYS > 1 { @@ -580,13 +580,13 @@ void _gdispInit(void) extern GDriverVMTList GDISPVMT_OnlyOne; for(i = 0; i < GDISP_TOTAL_DISPLAYS; i++) - gdriverRegister(GDISPVMT_OnlyOne); + gdriverRegister(GDISPVMT_OnlyOne, 0); } #else { extern GDriverVMTList GDISPVMT_OnlyOne; - gdriverRegister(GDISPVMT_OnlyOne); + gdriverRegister(GDISPVMT_OnlyOne, 0); } #endif @@ -620,9 +620,10 @@ void _gdispDeinit(void) /* ToDo */ } -bool_t _gdispInitDriver(GDriver *g, unsigned driverinstance, unsigned systeminstance) { +bool_t _gdispInitDriver(GDriver *g, void *param, unsigned driverinstance, unsigned systeminstance) { #define gd ((GDisplay *)g) bool_t ret; + (void) param; // Intialise fields gd->systemdisplay = systeminstance; diff --git a/src/gdriver/gdriver_gdriver.c b/src/gdriver/gdriver_gdriver.c index 3c17fca0..d44d6f3c 100644 --- a/src/gdriver/gdriver_gdriver.c +++ b/src/gdriver/gdriver_gdriver.c @@ -27,7 +27,7 @@ void _gdriverDeinit(void) { } -GDriver *gdriverRegister(const GDriverVMT *vmt) { +GDriver *gdriverRegister(const GDriverVMT *vmt, void *param) { GDriver * pd; GDriver * dtail; unsigned dinstance, sinstance; @@ -47,7 +47,7 @@ GDriver *gdriverRegister(const GDriverVMT *vmt) { return 0; memset(pd, 0, vmt->objsize); pd->vmt = vmt; - if (vmt->init && !vmt->init(pd, dinstance, sinstance)) { + if (vmt->init && !vmt->init(pd, param, dinstance, sinstance)) { gfxFree(pd); return 0; } diff --git a/src/gdriver/sys_defs.h b/src/gdriver/sys_defs.h index d8de25fc..f7bf622e 100644 --- a/src/gdriver/sys_defs.h +++ b/src/gdriver/sys_defs.h @@ -67,7 +67,7 @@ typedef struct GDriverVMT { uint16_t type; // @< What type of driver this is uint16_t flags; // @< Flags for the driver. Meaning is specific to each driver type. uint32_t objsize; // @< How big the runtime driver structure is - bool_t (*init)(GDriver *driver, unsigned driverinstance, unsigned systeminstance); // @< Initialise the driver. Returns TRUE if OK. + bool_t (*init)(GDriver *driver, void *param, unsigned driverinstance, unsigned systeminstance); // @< Initialise the driver. Returns TRUE if OK. // driverinstance is the instance 0..n of this driver. // systeminstance is the instance 0..n of this type of device. // The memory allocated is cleared before this call. @@ -102,8 +102,9 @@ extern "C" { * @return The runtime driver structure or NULL if it fails. * * @param[in] vmt The driver's vmt + * @param[in] param An arbitrary paramater passed to the driver init routine. */ - GDriver *gdriverRegister(const GDriverVMT *vmt); + GDriver *gdriverRegister(const GDriverVMT *vmt, void *param); /** * @brief UnRegister a driver instance. From e7bc175ca0fb1b1d2bd6a80d36696efa6dc0d171 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 26 Sep 2014 16:30:53 +1000 Subject: [PATCH 15/87] Demos updated to remove now deprecated function gwinAttachMouse --- demos/modules/gwin/button/main.c | 5 +---- demos/modules/gwin/checkbox/main.c | 7 ++----- demos/modules/gwin/container/main.c | 5 +---- demos/modules/gwin/container_nested/main.c | 11 ++++------- demos/modules/gwin/frame/main.c | 7 ++----- demos/modules/gwin/label/main.c | 3 --- demos/modules/gwin/list/main.c | 3 --- demos/modules/gwin/radio/main.c | 3 --- demos/modules/gwin/slider/main.c | 3 --- demos/modules/gwin/widgets/main.c | 5 ----- 10 files changed, 10 insertions(+), 42 deletions(-) diff --git a/demos/modules/gwin/button/main.c b/demos/modules/gwin/button/main.c index 15e8e5a7..1d8aa2e6 100644 --- a/demos/modules/gwin/button/main.c +++ b/demos/modules/gwin/button/main.c @@ -39,7 +39,7 @@ static void createWidgets(void) { gwinWidgetClearInit(&wi); wi.g.show = TRUE; - // Apply the button parameters + // Apply the button parameters wi.g.width = 100; wi.g.height = 30; wi.g.y = 10; @@ -67,9 +67,6 @@ int main(void) { gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); - // Attach the mouse input - gwinAttachMouse(0); - // create the widget createWidgets(); diff --git a/demos/modules/gwin/checkbox/main.c b/demos/modules/gwin/checkbox/main.c index 28122bee..22963e40 100644 --- a/demos/modules/gwin/checkbox/main.c +++ b/demos/modules/gwin/checkbox/main.c @@ -39,14 +39,14 @@ static void createWidgets(void) { gwinWidgetClearInit(&wi); wi.g.show = TRUE; - // Apply the checkbox parameters + // Apply the checkbox parameters wi.g.width = 100; // includes text wi.g.height = 20; wi.g.y = 10; wi.g.x = 10; wi.text = "Checkbox"; - // Create the actual checkbox + // Create the actual checkbox ghCheckbox1 = gwinCheckboxCreate(0, &wi); } @@ -61,9 +61,6 @@ int main(void) { gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); - // Attach the mouse input - gwinAttachMouse(0); - // create the widget createWidgets(); diff --git a/demos/modules/gwin/container/main.c b/demos/modules/gwin/container/main.c index 4e73b0c4..75e3f78b 100644 --- a/demos/modules/gwin/container/main.c +++ b/demos/modules/gwin/container/main.c @@ -19,7 +19,7 @@ static void createWidgets(void) { ghContainer = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER); wi.g.show = TRUE; - // Apply the button parameters + // Apply the button parameters wi.g.width = 120; wi.g.height = 30; wi.g.y = 10; @@ -37,9 +37,6 @@ int main(void) { // Initialize the display gfxInit(); - // Attach the mouse input - gwinAttachMouse(0); - // Set the widget defaults gwinSetDefaultFont(gdispOpenFont("*")); gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); diff --git a/demos/modules/gwin/container_nested/main.c b/demos/modules/gwin/container_nested/main.c index 2d90f76b..5cd5e793 100644 --- a/demos/modules/gwin/container_nested/main.c +++ b/demos/modules/gwin/container_nested/main.c @@ -40,7 +40,7 @@ static void createWidgets(void) { wi.text = "Container 3"; ghContainer3 = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER); - // Button 1 + // Button 1 wi.g.width = 80; wi.g.height = 20; wi.g.y = 10; @@ -49,7 +49,7 @@ static void createWidgets(void) { wi.g.parent = ghContainer2; ghButton1 = gwinButtonCreate(0, &wi); - // Button 2 + // Button 2 wi.g.width = 80; wi.g.height = 20; wi.g.y = 40; @@ -58,7 +58,7 @@ static void createWidgets(void) { wi.g.parent = ghContainer2; ghButton2 = gwinButtonCreate(0, &wi); - // Button 3 + // Button 3 wi.g.width = 80; wi.g.height = 20; wi.g.y = 10; @@ -67,7 +67,7 @@ static void createWidgets(void) { wi.g.parent = ghContainer3; ghButton3 = gwinButtonCreate(0, &wi); - // Button 4 + // Button 4 wi.g.width = 80; wi.g.height = 20; wi.g.y = 40; @@ -115,9 +115,6 @@ int main(void) { // Initialize the display gfxInit(); - // Attach the mouse input - gwinAttachMouse(0); - // Set the widget defaults gwinSetDefaultFont(gdispOpenFont("*")); gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); diff --git a/demos/modules/gwin/frame/main.c b/demos/modules/gwin/frame/main.c index fe956925..a97525ab 100644 --- a/demos/modules/gwin/frame/main.c +++ b/demos/modules/gwin/frame/main.c @@ -33,7 +33,7 @@ static void _createWidgets(void) { wi.text = "Surprise!"; gwinLabelCreate(0, &wi); - // Apply the frame parameters + // Apply the frame parameters wi.g.width = 300; wi.g.height = 200; wi.g.y = 10; @@ -107,7 +107,7 @@ static void _createWidgets(void) { wi.g.x = 10; wi.g.y = 90; ghWindow1 = gwinWindowCreate(0, &wi.g); - + _updateColor(); } @@ -117,9 +117,6 @@ int main(void) { // Initialize the display gfxInit(); - // Attach the mouse input - gwinAttachMouse(0); - // Set the widget defaults gwinSetDefaultFont(gdispOpenFont("*")); gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); diff --git a/demos/modules/gwin/label/main.c b/demos/modules/gwin/label/main.c index aab9cd76..425436ea 100644 --- a/demos/modules/gwin/label/main.c +++ b/demos/modules/gwin/label/main.c @@ -63,9 +63,6 @@ int main(void) { gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); - // Attach the mouse input - gwinAttachMouse(0); - // create the widget createWidgets(); diff --git a/demos/modules/gwin/list/main.c b/demos/modules/gwin/list/main.c index ed5b6905..0102f276 100644 --- a/demos/modules/gwin/list/main.c +++ b/demos/modules/gwin/list/main.c @@ -79,9 +79,6 @@ int main(void) { gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); - // Attach the mouse input - gwinAttachMouse(0); - // create the widget createWidgets(); diff --git a/demos/modules/gwin/radio/main.c b/demos/modules/gwin/radio/main.c index 7455c770..59b86983 100644 --- a/demos/modules/gwin/radio/main.c +++ b/demos/modules/gwin/radio/main.c @@ -83,9 +83,6 @@ int main(void) { gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); - // Attach the mouse input - gwinAttachMouse(0); - // create the widget createWidgets(); diff --git a/demos/modules/gwin/slider/main.c b/demos/modules/gwin/slider/main.c index ddcd90df..bf0aacfc 100644 --- a/demos/modules/gwin/slider/main.c +++ b/demos/modules/gwin/slider/main.c @@ -59,9 +59,6 @@ int main(void) { gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); - // Attach the mouse input - gwinAttachMouse(0); - // create the widget createWidgets(); diff --git a/demos/modules/gwin/widgets/main.c b/demos/modules/gwin/widgets/main.c index 3239ab4c..d2f6882b 100644 --- a/demos/modules/gwin/widgets/main.c +++ b/demos/modules/gwin/widgets/main.c @@ -418,11 +418,6 @@ int main(void) { // Initialize the display gfxInit(); - // Connect the mouse - #if GINPUT_NEED_MOUSE - gwinAttachMouse(0); - #endif - // Set the widget defaults font = gdispOpenFont("*"); // Get the first defined font. gwinSetDefaultFont(font); From 174e60c76d2429de1b07d4afc00fa35999b7ccde Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 26 Sep 2014 16:32:00 +1000 Subject: [PATCH 16/87] GINPUT mouse updated - first working version of newmouse. Note: drivers to be ported. Note: not tested well yet. --- src/ginput/driver_mouse.h | 2 +- src/ginput/ginput_mouse.c | 40 ++++++++++++++++++++++----------------- src/ginput/ginput_mouse.h | 8 ++++---- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/ginput/driver_mouse.h b/src/ginput/driver_mouse.h index ababfef8..76367ba2 100644 --- a/src/ginput/driver_mouse.h +++ b/src/ginput/driver_mouse.h @@ -115,7 +115,7 @@ extern "C" { * @notapi * @{ */ - bool_t _gmouseInitDriver(GDriver *g, unsigned driverinstance, unsigned systeminstance); + bool_t _gmouseInitDriver(GDriver *g, void *display, unsigned driverinstance, unsigned systeminstance); void _gmousePostInitDriver(GDriver *g); void _gmouseDeInitDriver(GDriver *g); /** @} */ diff --git a/src/ginput/ginput_mouse.c b/src/ginput/ginput_mouse.c index f33a74e0..ee6555b2 100644 --- a/src/ginput/ginput_mouse.c +++ b/src/ginput/ginput_mouse.c @@ -13,6 +13,11 @@ #if GFX_USE_GINPUT && GINPUT_NEED_MOUSE +// Just to make code easier +#if !GFX_USE_GDISP + #define GDISP 0 +#endif + // Local Settings #define CALIBRATION_POLL_PERIOD 20 // milliseconds #define CALIBRATION_MINPRESS_PERIOD 300 // milliseconds @@ -618,7 +623,7 @@ void _gmouseInit(void) { for(i = 0; i < sizeof(dclist)/sizeof(dclist[0]); i++) { if (!(dclist[i]->flags & GMOUSE_VFLG_DYNAMICONLY)) - gdriverRegister(dclist[i]); + gdriverRegister(dclist[i], GDISP); } } @@ -628,7 +633,7 @@ void _gmouseInit(void) { extern GDriverVMTList GMOUSEVMT_OnlyOne; if (!(GMOUSEVMT_OnlyOne->flags & GMOUSE_VFLG_DYNAMICONLY)) - gdriverRegister(GMOUSEVMT_OnlyOne); + gdriverRegister(GMOUSEVMT_OnlyOne, GDISP); } #endif @@ -638,20 +643,23 @@ void _gmouseDeinit(void) { gtimerDeinit(&MouseTimer); } -bool_t _gmouseInitDriver(GDriver *g, unsigned driverinstance, unsigned systeminstance) { +bool_t _gmouseInitDriver(GDriver *g, void *display, unsigned driverinstance, unsigned systeminstance) { #define m ((GMouse *)g) (void) systeminstance; + // The initial display is passed in the parameter for mice + m->display = display; + + #if !GINPUT_TOUCH_NOTOUCH + // Should this mouse start in finger mode? (according to the VMT) + if ((gmvmt(m)->d.flags & GMOUSE_VFLG_DEFAULTFINGER)) + m->flags |= GMOUSE_FLG_FINGERMODE; + #endif + // Init the mouse if (!gmvmt(m)->init((GMouse *)g, driverinstance)) return FALSE; - #if !GINPUT_TOUCH_NOTOUCH - // Should this mouse start in finger mode? - if ((gmvmt(m)->d.flags & GMOUSE_VFLG_DEFAULTFINGER)) - m->flags |= GMOUSE_FLG_FINGERMODE; - #endif - // Ensure the Poll timer is started if (!gtimerIsActive(&MouseTimer)) gtimerStart(&MouseTimer, MousePoll, 0, TRUE, GINPUT_MOUSE_POLL_PERIOD); @@ -664,10 +672,6 @@ bool_t _gmouseInitDriver(GDriver *g, unsigned driverinstance, unsigned systemins void _gmousePostInitDriver(GDriver *g) { #define m ((GMouse *)g) - // Make sure we have a valid mouse display - if (!m->display) - m->display = GDISP; - #if !GINPUT_TOUCH_NOCALIBRATE && !GINPUT_TOUCH_STARTRAW if ((gmvmt(m)->d.flags & GMOUSE_VFLG_CALIBRATE)) { GMouseCalibration *pc; @@ -784,14 +788,16 @@ bool_t ginputGetMouseStatus(unsigned instance, GEventMouse *pe) { #endif /* Wake up the mouse driver from an interrupt service routine (there may be new readings available) */ -void ginputMouseWakeup(GMouse *m) { - m->flags |= GMOUSE_FLG_NEEDREAD; +void _gmouseWakeup(GMouse *m) { + if (m) + m->flags |= GMOUSE_FLG_NEEDREAD; gtimerJab(&MouseTimer); } /* Wake up the mouse driver from an interrupt service routine (there may be new readings available) */ -void ginputMouseWakeupI(GMouse *m) { - m->flags |= GMOUSE_FLG_NEEDREAD; +void _gmouseWakeupI(GMouse *m) { + if (m) + m->flags |= GMOUSE_FLG_NEEDREAD; gtimerJabI(&MouseTimer); } diff --git a/src/ginput/ginput_mouse.h b/src/ginput/ginput_mouse.h index 1eff64f4..3e9c017b 100644 --- a/src/ginput/ginput_mouse.h +++ b/src/ginput/ginput_mouse.h @@ -46,10 +46,10 @@ typedef struct GEventMouse_t { #define GMETA_MASK 0x00F0 // The "button transition" mask #define GMETA_NONE 0x0000 // No "button transition" events - #define GMETA_MOUSE_DOWN 0x0001 // Left mouse/touch has just gone down - #define GMETA_MOUSE_UP 0x0002 // Left mouse/touch has just gone up - #define GMETA_MOUSE_CLICK 0x0004 // Left mouse/touch has just gone through a click (short down - up cycle) - #define GMETA_MOUSE_CXTCLICK 0x0008 // Right mouse has just been depressed or touch has gone through a long click + #define GMETA_MOUSE_DOWN 0x0010 // Left mouse/touch has just gone down + #define GMETA_MOUSE_UP 0x0020 // Left mouse/touch has just gone up + #define GMETA_MOUSE_CLICK 0x0040 // Left mouse/touch has just gone through a click (short down - up cycle) + #define GMETA_MOUSE_CXTCLICK 0x0080 // Right mouse has just been depressed or touch has gone through a long click #define GINPUT_MISSED_MOUSE_EVENT 0x8000 // Oops - a mouse event has previously been missed From 19e2e7a60c7d81ec758ec5ff2b718149804ed8c6 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 26 Sep 2014 16:32:34 +1000 Subject: [PATCH 17/87] Win32 mouse ported to new mouse driver format --- drivers/multiple/Win32/gdisp_lld_Win32.c | 133 +++++++++++++++++------ 1 file changed, 97 insertions(+), 36 deletions(-) diff --git a/drivers/multiple/Win32/gdisp_lld_Win32.c b/drivers/multiple/Win32/gdisp_lld_Win32.c index 3643d727..d4cc130e 100644 --- a/drivers/multiple/Win32/gdisp_lld_Win32.c +++ b/drivers/multiple/Win32/gdisp_lld_Win32.c @@ -10,7 +10,7 @@ #if GFX_USE_GDISP #define GDISP_DRIVER_VMT GDISPVMT_Win32 -#include "drivers/multiple/Win32/gdisp_lld_config.h" +#include "gdisp_lld_config.h" #include "src/gdisp/driver.h" #ifndef GDISP_SCREEN_WIDTH @@ -52,7 +52,6 @@ #define GDISP_FLG_READY (GDISP_FLG_DRIVER<<0) #define GDISP_FLG_HASTOGGLE (GDISP_FLG_DRIVER<<1) -#define GDISP_FLG_HASMOUSE (GDISP_FLG_DRIVER<<2) #if GDISP_HARDWARE_STREAM_WRITE || GDISP_HARDWARE_STREAM_READ #define GDISP_FLG_WSTREAM (GDISP_FLG_DRIVER<<3) #define GDISP_FLG_WRAPPED (GDISP_FLG_DRIVER<<4) @@ -64,16 +63,50 @@ #endif #if GINPUT_NEED_MOUSE - /* Include mouse support code */ + // Include mouse support code + #define GMOUSE_DRIVER_VMT GMOUSEVMT_Win32 #include "src/ginput/driver_mouse.h" + + // Forward definitions + static bool_t Win32MouseInit(GMouse *m, unsigned driverinstance); + static void Win32MouseRead(GMouse *m, GMouseReading *prd); + + const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ + { + GDRIVER_TYPE_MOUSE, + GMOUSE_VFLG_NOPOLL|GMOUSE_VFLG_DYNAMICONLY, + // Extra flags for testing only + //GMOUSE_VFLG_TOUCH|GMOUSE_VFLG_SELFROTATION|GMOUSE_VFLG_DEFAULTFINGER + //GMOUSE_VFLG_CALIBRATE|GMOUSE_VFLG_CAL_EXTREMES|GMOUSE_VFLG_CAL_TEST|GMOUSE_VFLG_CAL_LOADFREE + //GMOUSE_VFLG_ONLY_DOWN|GMOUSE_VFLG_POORUPDOWN + sizeof(GMouse), + _gmouseInitDriver, _gmousePostInitDriver, _gmouseDeInitDriver + }, + 1, // z_max + 0, // z_min + 1, // z_touchon + 0, // z_touchoff + { // pen_jitter + 0, // calibrate + 0, // click + 0 // move + }, + { // finger_jitter + 0, // calibrate + 2, // click + 2 // move + }, + Win32MouseInit, // init + 0, // deinit + Win32MouseRead, // get + 0, //calsave + 0 //calload + }}; #endif static DWORD winThreadId; static volatile bool_t QReady; static HANDLE drawMutex; -#if GINPUT_NEED_MOUSE - static GDisplay * mouseDisplay; -#endif /*===========================================================================*/ /* Driver local routines . */ @@ -95,6 +128,7 @@ typedef struct winPriv { #if GINPUT_NEED_MOUSE coord_t mousex, mousey; uint16_t mousebuttons; + GMouse *mouse; #endif #if GINPUT_NEED_TOGGLE uint8_t toggles; @@ -149,7 +183,7 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) // Handle mouse down on the window #if GINPUT_NEED_MOUSE - if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASMOUSE)) { + if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT) { priv->mousebuttons |= GINPUT_MOUSE_BTN_LEFT; goto mousemove; } @@ -198,7 +232,7 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) // Handle mouse up on the window #if GINPUT_NEED_MOUSE - if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASMOUSE)) { + if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT) { priv->mousebuttons &= ~GINPUT_MOUSE_BTN_LEFT; goto mousemove; } @@ -210,7 +244,7 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) case WM_MBUTTONDOWN: g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA); priv = (winPriv *)g->priv; - if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASMOUSE)) { + if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT) { priv->mousebuttons |= GINPUT_MOUSE_BTN_MIDDLE; goto mousemove; } @@ -218,7 +252,7 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) case WM_MBUTTONUP: g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA); priv = (winPriv *)g->priv; - if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASMOUSE)) { + if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT) { priv->mousebuttons &= ~GINPUT_MOUSE_BTN_MIDDLE; goto mousemove; } @@ -226,7 +260,7 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) case WM_RBUTTONDOWN: g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA); priv = (winPriv *)g->priv; - if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASMOUSE)) { + if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT) { priv->mousebuttons |= GINPUT_MOUSE_BTN_RIGHT; goto mousemove; } @@ -234,7 +268,7 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) case WM_RBUTTONUP: g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA); priv = (winPriv *)g->priv; - if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT && (g->flags & GDISP_FLG_HASMOUSE)) { + if ((coord_t)HIWORD(lParam) < GDISP_SCREEN_HEIGHT) { priv->mousebuttons &= ~GINPUT_MOUSE_BTN_RIGHT; goto mousemove; } @@ -242,14 +276,13 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) case WM_MOUSEMOVE: g = (GDisplay *)GetWindowLongPtr(hWnd, GWLP_USERDATA); priv = (winPriv *)g->priv; - if ((coord_t)HIWORD(lParam) >= GDISP_SCREEN_HEIGHT || !(g->flags & GDISP_FLG_HASMOUSE)) + if ((coord_t)HIWORD(lParam) >= GDISP_SCREEN_HEIGHT) break; mousemove: priv->mousex = (coord_t)LOWORD(lParam); priv->mousey = (coord_t)HIWORD(lParam); - #if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE - ginputMouseWakeup(); - #endif + if ((gmvmt(priv->mouse)->d.flags & GMOUSE_VFLG_NOPOLL)) // For normal setup this is always TRUE + _gmouseWakeup(priv->mouse); break; #endif @@ -445,14 +478,6 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { g->flags |= GDISP_FLG_HASTOGGLE; #endif - // Only turn on mouse on the first window for now - #if GINPUT_NEED_MOUSE - if (!g->controllerdisplay) { - mouseDisplay = g; - g->flags |= GDISP_FLG_HASMOUSE; - } - #endif - // Create a private area for this window priv = gfxAlloc(sizeof(winPriv)); assert(priv != 0); @@ -476,6 +501,11 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { ShowWindow(priv->hwnd, SW_SHOW); UpdateWindow(priv->hwnd); + // Create the associated mouse + #if GINPUT_NEED_MOUSE + priv->mouse = (GMouse *)gdriverRegister((const GDriverVMT const *)GMOUSE_DRIVER_VMT, g); + #endif + return TRUE; } @@ -686,10 +716,10 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { winPriv * priv; int x, y; COLORREF color; - + priv = g->priv; color = gdispColor2Native(g->p.color); - + #if GDISP_NEED_CONTROL switch(g->g.Orientation) { case GDISP_ROTATE_0: @@ -818,7 +848,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { sz = (size_t)g->p.cx * (size_t)g->p.cy; if (!(dstbuf = (pixel_t *)malloc(sz * sizeof(pixel_t)))) return 0; - + // Copy the bits we need switch(g->g.Orientation) { case GDISP_ROTATE_0: @@ -847,7 +877,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { return dstbuf; } #endif - + #if GDISP_HARDWARE_BITFILLS #if COLOR_SYSTEM != GDISP_COLORSYSTEM_TRUECOLOR || COLOR_TYPE_BITS <= 8 #error "GDISP Win32: This driver's bitblit currently only supports true-color with bit depths > 8 bits." @@ -863,7 +893,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { priv = g->priv; buffer = g->p.ptr; buffer += g->p.x2*g->p.y1; - + memset(&bmpInfo, 0, sizeof(bmpInfo)); bmpInfo.bV4Size = sizeof(bmpInfo); bmpInfo.bV4Planes = 1; @@ -982,7 +1012,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { color = GetPixel(priv->dcBuffer, g->p.x, g->p.y); #endif ReleaseMutex(drawMutex); - + return gdispNative2Color(color); } #endif @@ -992,7 +1022,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { winPriv * priv; RECT rect; coord_t lines; - + priv = g->priv; #if GDISP_NEED_CONTROL @@ -1134,18 +1164,49 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { #endif #if GINPUT_NEED_MOUSE - void ginput_lld_mouse_init(void) {} - void ginput_lld_mouse_get_reading(MouseReading *pt) { + static bool_t Win32MouseInit(GMouse *m, unsigned driverinstance) { + (void) m; + (void) driverinstance; + return TRUE; + } + static void Win32MouseRead(GMouse *m, GMouseReading *pt) { GDisplay * g; winPriv * priv; - g = mouseDisplay; + g = m->display; priv = g->priv; pt->x = priv->mousex; - pt->y = priv->mousey > g->g.Height ? g->g.Height : priv->mousey; - pt->z = (priv->mousebuttons & GINPUT_MOUSE_BTN_LEFT) ? 100 : 0; + pt->y = priv->mousey; + pt->z = (priv->mousebuttons & GINPUT_MOUSE_BTN_LEFT) ? 1 : 0; pt->buttons = priv->mousebuttons; + + #if GDISP_NEED_CONTROL + // If the self-rotation has been set in the VMT then do that here (TESTING ONLY) + if ((gmvmt(m)->d.flags & GMOUSE_VFLG_SELFROTATION)) { // For normal setup this is always False + coord_t t; + + switch(gdispGGetOrientation(m->display)) { + case GDISP_ROTATE_0: + default: + break; + case GDISP_ROTATE_90: + t = pt->x; + pt->x = g->g.Width - 1 - pt->y; + pt->y = t; + break; + case GDISP_ROTATE_180: + pt->x = g->g.Width - 1 - pt->x; + pt->y = g->g.Height - 1 - pt->y; + break; + case GDISP_ROTATE_270: + t = pt->y; + pt->y = g->g.Height - 1 - pt->x; + pt->x = t; + break; + } + } + #endif } #endif /* GINPUT_NEED_MOUSE */ From a18511cdc10c5b45222d870bf4fb203b5c7e4aeb Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 26 Sep 2014 16:34:29 +1000 Subject: [PATCH 18/87] doco --- docs/releases.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/releases.txt b/docs/releases.txt index adf7ca12..aa01972b 100644 --- a/docs/releases.txt +++ b/docs/releases.txt @@ -31,11 +31,14 @@ FIX: Improve memory usage for the GWIN Frame widget. FEATURE: Added transparent custom draws for GWIN containers and frame widgets FEATURE: Added image custom draws for GWIN containers and frame widgets FEATURE: Added GDRIVER infrastructure. Ported GDISP to use it. +FEATURE: Ported GINPUT MOUSE to GDRIVER infrastructure. +FEATURE: Mouse/Touch now support both pen and finger mode. +DEPRECATE: gwinAttachMouse() is now handled automaticly. *** Release 2.1 *** FIX: Significant improvements to the way the MCU touch driver works. -FEATURE: Add support for edge to edge touch calibration. +FEATURE: Add support for edge to edge touch calibration. FEATURE: Added progressbar widget FEATURE: Added gdispGDrawThickLine() by user jpa- DEPRECATE: TDISP module removed @@ -78,7 +81,7 @@ FEATURE: GDISP Streaming API and demos. DEPRECATE: GDISP_NEED_ASYNC is now deprecated. DEPRECATE: 3rd party boing demo is now deprecated (replaced by GDISP Streaming demo) FIX: Remove GOS definitions from demo conf files so that it can be supplied by a makefile. -FEATURE: Repair GDISP low level driver interfaces so they can now be included in the doxygen documentation. +FEATURE: Repair GDISP low level driver interfaces so they can now be included in the doxygen documentation. FEATURE: New driver interface for GDISP FEATURE: Multiple display support FEATURE: Multiple controller support From 27d7c68dd74953f9347ff880f87e750b59f70c79 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 26 Sep 2014 17:28:43 +1000 Subject: [PATCH 19/87] Update more Makefiles --- .../base/Linux-Framebuffer/example/Makefile | 113 +++++++++++++----- boards/base/Linux/example/Makefile | 111 ++++++++++++----- 2 files changed, 169 insertions(+), 55 deletions(-) diff --git a/boards/base/Linux-Framebuffer/example/Makefile b/boards/base/Linux-Framebuffer/example/Makefile index 66af4bdc..8be8c839 100644 --- a/boards/base/Linux-Framebuffer/example/Makefile +++ b/boards/base/Linux-Framebuffer/example/Makefile @@ -12,16 +12,29 @@ # To rebuild project do "make clean" and "make all". # +############################################################################################## +# Start of make control +# + +# Verbose compiling? +USE_VERBOSE_COMPILE=no + +# Generate listing files? +USE_LISTING=no + +# Your project name and executable file name - Optional, defaults to the project directory name +#PROJECT=uGFX + ############################################################################################## # Start of default section # -TRGT = +TRGT = CC = $(TRGT)gcc AS = $(TRGT)gcc -x assembler-with-cpp # List all default C defines here, like -D_DEBUG=1 -DDEFS = +DDEFS = # List all default ASM defines here, like -D_DEBUG=1 DADEFS = @@ -33,7 +46,7 @@ DINCDIR = DLIBDIR = # List all default libraries here -DLIBS = -lX11 -pthread -lrt +DLIBS = -lrt # # End of default section @@ -43,8 +56,10 @@ DLIBS = -lX11 -pthread -lrt # Start of user section # -# Define project name here -PROJECT = ugfx +# Default project name is the project directory name +ifeq ($(PROJECT),) + PROJECT := $(notdir $(patsubst %/,%,$(dir $(abspath $(firstword $(MAKEFILE_LIST)))))) +endif # Imported source files and paths for uGFX GFXLIB = ../ugfx @@ -87,15 +102,38 @@ OPT = -ggdb -O0 -fomit-frame-pointer # End of user defines ############################################################################################## +I# Output directory and files +ifeq ($(MAKECMDGOALS),Debug) + BUILDDIR = bin/Debug +else ifeq ($(MAKECMDGOALS),Release) + BUILDDIR = bin/Release +else ifeq ($(BUILDDIR),) + BUILDDIR = .build +else ifeq ($(BUILDDIR),.) + BUILDDIR = .build +endif + +OBJDIR = $(BUILDDIR)/obj +LSTDIR = $(BUILDDIR)/lst +MAPDIR = $(BUILDDIR)/map +DEPDIR = .dep + INCDIR = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR)) LIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR)) DEFS = $(DDEFS) $(UDEFS) ADEFS = $(DADEFS) $(UADEFS) -OBJS = $(ASRC:.s=.o) $(SRC:.c=.o) +COBJ = $(addprefix $(OBJDIR)/, $(subst ../,_dot_dot/,$(SRC:.c=.o))) +AOBJ = $(addprefix $(OBJDIR)/, $(subst ../,_dot_dot/,$(ASRC:.s=.o))) +OBJS = $(AOBJ) $(COBJ) LIBS = $(DLIBS) $(ULIBS) -ASFLAGS = -Wa,-amhls=$(<:.s=.lst) $(ADEFS) -CPFLAGS = $(OPT) -Wall -Wextra -Wstrict-prototypes -fverbose-asm $(DEFS) +ASFLAGS = $(ADEFS) +CPFLAGS = $(OPT) -Wall -Wextra -Wstrict-prototypes -fverbose-asm $(DEFS) +LDFLAGS = -Wl,-Map=$(MAPDIR)/$(PROJECT).map,--cref,--no-warn-mismatch $(LIBDIR) +ifeq ($(USE_LISTING),yes) + ASFLAGS += -Wa,-amhls=$(LSTDIR)/$(subst ../,_dot_dot/,$(<:.s=.lst)) + CPFLAGS += -Wa,-alms=$(LSTDIR)/$(subst ../,_dot_dot/,$(<:.c=.lst)) +endif ifeq ($(HOST_OSX),yes) ifeq ($(OSX_SDK),) @@ -105,29 +143,54 @@ ifeq ($(HOST_OSX),yes) OSX_ARCH = -mmacosx-version-min=10.3 -arch i386 endif - CPFLAGS += -isysroot $(OSX_SDK) $(OSX_ARCH) - LDFLAGS = -Wl -Map=$(PROJECT).map,-syslibroot,$(OSX_SDK),$(LIBDIR) LIBS += $(OSX_ARCH) + CPFLAGS += -isysroot $(OSX_SDK) $(OSX_ARCH) + LDFLAGS = -Wl -Map=$(MAPDIR)/$(PROJECT).map,-syslibroot,$(OSX_SDK),$(LIBDIR) else # Linux, or other - CPFLAGS += -m32 -Wa,-alms=$(<:.c=.lst) - LDFLAGS = -m32 -Wl,-Map=$(PROJECT).map,--cref,--no-warn-mismatch $(LIBDIR) + CPFLAGS += -m32 endif # Generate dependency information -CPFLAGS += -MD -MP -MF .dep/$(@F).d +CPFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d # # makefile rules # -all: $(OBJS) $(PROJECT) +all: $(BUILDDIR) $(OBJS) $(PROJECT) -%.o : %.c - $(CC) -c $(CPFLAGS) -I . $(INCDIR) $< -o $@ +$(BUILDDIR) $(OBJDIR) $(LSTDIR) $(MAPDIR): + mkdir -p $(OBJDIR) + mkdir -p $(MAPDIR) +ifeq ($(USE_LISTING),yes) + mkdir -p $(LSTDIR) +endif +ifneq ($(USE_VERBOSE_COMPILE),yes) + @echo Compiler Options - $(CC) -c $(CPFLAGS) -I. $(INCDIR) main.c -o $(OBJDIR)/main.o + @echo +endif -%.o : %.s - $(AS) -c $(ASFLAGS) $< -o $@ +.SECONDEXPANSION: +$(OBJDIR)/%.o : $$(subst _dot_dot/,../,%.c) + @mkdir -p $(dir $@) +ifeq ($(USE_VERBOSE_COMPILE),yes) + @echo + $(CC) -c $(CPFLAGS) -I. $(INCDIR) $< -o $@ +else + @echo Compiling $< + @$(CC) -c $(CPFLAGS) -I. $(INCDIR) $< -o $@ +endif + +$(OBJDIR)/%.o : $$(subst _dot_dot/,../,%.s) + @mkdir -p $(dir $@) +ifeq ($(USE_VERBOSE_COMPILE),yes) + @echo + $(AS) -c $(ASFLAGS) -I. $(INCDIR) $< -o $@ +else + @echo Compiling $< + @$(AS) -c $(ASFLAGS) -I. $(INCDIR) $< -o $@ +endif $(PROJECT): $(OBJS) $(CC) $(OBJS) $(LDFLAGS) $(LIBS) -o $@ @@ -137,19 +200,13 @@ gcov: $(COV) -u $(subst /,\,$(SRC)) -mv *.gcov ./gcov -clean: - -rm -f $(OBJS) - -rm -f $(PROJECT) - -rm -f $(PROJECT).map - -rm -f $(SRC:.c=.c.bak) - -rm -f $(SRC:.c=.lst) - -rm -f $(ASRC:.s=.s.bak) - -rm -f $(ASRC:.s=.lst) - -rm -fR .dep +clean: + -rm -f $(BUILDDIR) + -rm -fR $(DEPDIR) # # Include the dependency files, should be the last of the makefile # --include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) +-include $(shell mkdir $(DEPDIR) 2>/dev/null) $(wildcard $(DEPDIR)/*) # *** EOF *** diff --git a/boards/base/Linux/example/Makefile b/boards/base/Linux/example/Makefile index e454a811..938494cb 100644 --- a/boards/base/Linux/example/Makefile +++ b/boards/base/Linux/example/Makefile @@ -12,16 +12,29 @@ # To rebuild project do "make clean" and "make all". # +############################################################################################## +# Start of make control +# + +# Verbose compiling? +USE_VERBOSE_COMPILE=no + +# Generate listing files? +USE_LISTING=no + +# Your project name and executable file name - Optional, defaults to the project directory name +#PROJECT=uGFX + ############################################################################################## # Start of default section # -TRGT = +TRGT = CC = $(TRGT)gcc AS = $(TRGT)gcc -x assembler-with-cpp # List all default C defines here, like -D_DEBUG=1 -DDEFS = +DDEFS = # List all default ASM defines here, like -D_DEBUG=1 DADEFS = @@ -43,8 +56,10 @@ DLIBS = -lX11 -pthread -lrt # Start of user section # -# Define project name here -PROJECT = ugfx +# Default project name is the project directory name +ifeq ($(PROJECT),) + PROJECT := $(notdir $(patsubst %/,%,$(dir $(abspath $(firstword $(MAKEFILE_LIST)))))) +endif # Imported source files and paths for uGFX GFXLIB = ../ugfx @@ -87,15 +102,38 @@ OPT = -ggdb -O0 -fomit-frame-pointer # End of user defines ############################################################################################## +# Output directory and files +ifeq ($(MAKECMDGOALS),Debug) + BUILDDIR = bin/Debug +else ifeq ($(MAKECMDGOALS),Release) + BUILDDIR = bin/Release +else ifeq ($(BUILDDIR),) + BUILDDIR = .build +else ifeq ($(BUILDDIR),.) + BUILDDIR = .build +endif + +OBJDIR = $(BUILDDIR)/obj +LSTDIR = $(BUILDDIR)/lst +MAPDIR = $(BUILDDIR)/map +DEPDIR = .dep + INCDIR = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR)) LIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR)) DEFS = $(DDEFS) $(UDEFS) ADEFS = $(DADEFS) $(UADEFS) -OBJS = $(ASRC:.s=.o) $(SRC:.c=.o) +COBJ = $(addprefix $(OBJDIR)/, $(subst ../,_dot_dot/,$(SRC:.c=.o))) +AOBJ = $(addprefix $(OBJDIR)/, $(subst ../,_dot_dot/,$(ASRC:.s=.o))) +OBJS = $(AOBJ) $(COBJ) LIBS = $(DLIBS) $(ULIBS) -ASFLAGS = -Wa,-amhls=$(<:.s=.lst) $(ADEFS) -CPFLAGS = $(OPT) -Wall -Wextra -Wstrict-prototypes -fverbose-asm $(DEFS) +ASFLAGS = $(ADEFS) +CPFLAGS = $(OPT) -Wall -Wextra -Wstrict-prototypes -fverbose-asm $(DEFS) +LDFLAGS = -Wl,-Map=$(MAPDIR)/$(PROJECT).map,--cref,--no-warn-mismatch $(LIBDIR) +ifeq ($(USE_LISTING),yes) + ASFLAGS += -Wa,-amhls=$(LSTDIR)/$(subst ../,_dot_dot/,$(<:.s=.lst)) + CPFLAGS += -Wa,-alms=$(LSTDIR)/$(subst ../,_dot_dot/,$(<:.c=.lst)) +endif ifeq ($(HOST_OSX),yes) ifeq ($(OSX_SDK),) @@ -105,29 +143,54 @@ ifeq ($(HOST_OSX),yes) OSX_ARCH = -mmacosx-version-min=10.3 -arch i386 endif - CPFLAGS += -isysroot $(OSX_SDK) $(OSX_ARCH) - LDFLAGS = -Wl -Map=$(PROJECT).map,-syslibroot,$(OSX_SDK),$(LIBDIR) LIBS += $(OSX_ARCH) + CPFLAGS += -isysroot $(OSX_SDK) $(OSX_ARCH) + LDFLAGS = -Wl -Map=$(MAPDIR)/$(PROJECT).map,-syslibroot,$(OSX_SDK),$(LIBDIR) else # Linux, or other - CPFLAGS += -m32 -Wa,-alms=$(<:.c=.lst) - LDFLAGS = -m32 -Wl,-Map=$(PROJECT).map,--cref,--no-warn-mismatch $(LIBDIR) + CPFLAGS += -m32 endif # Generate dependency information -CPFLAGS += -MD -MP -MF .dep/$(@F).d +CPFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d # # makefile rules # -all: $(OBJS) $(PROJECT) +all: $(BUILDDIR) $(OBJS) $(PROJECT) -%.o : %.c - $(CC) -c $(CPFLAGS) -I . $(INCDIR) $< -o $@ +$(BUILDDIR) $(OBJDIR) $(LSTDIR) $(MAPDIR): + mkdir -p $(OBJDIR) + mkdir -p $(MAPDIR) +ifeq ($(USE_LISTING),yes) + mkdir -p $(LSTDIR) +endif +ifneq ($(USE_VERBOSE_COMPILE),yes) + @echo Compiler Options - $(CC) -c $(CPFLAGS) -I. $(INCDIR) main.c -o $(OBJDIR)/main.o + @echo +endif -%.o : %.s - $(AS) -c $(ASFLAGS) $< -o $@ +.SECONDEXPANSION: +$(OBJDIR)/%.o : $$(subst _dot_dot/,../,%.c) + @mkdir -p $(dir $@) +ifeq ($(USE_VERBOSE_COMPILE),yes) + @echo + $(CC) -c $(CPFLAGS) -I. $(INCDIR) $< -o $@ +else + @echo Compiling $< + @$(CC) -c $(CPFLAGS) -I. $(INCDIR) $< -o $@ +endif + +$(OBJDIR)/%.o : $$(subst _dot_dot/,../,%.s) + @mkdir -p $(dir $@) +ifeq ($(USE_VERBOSE_COMPILE),yes) + @echo + $(AS) -c $(ASFLAGS) -I. $(INCDIR) $< -o $@ +else + @echo Compiling $< + @$(AS) -c $(ASFLAGS) -I. $(INCDIR) $< -o $@ +endif $(PROJECT): $(OBJS) $(CC) $(OBJS) $(LDFLAGS) $(LIBS) -o $@ @@ -137,19 +200,13 @@ gcov: $(COV) -u $(subst /,\,$(SRC)) -mv *.gcov ./gcov -clean: - -rm -f $(OBJS) - -rm -f $(PROJECT) - -rm -f $(PROJECT).map - -rm -f $(SRC:.c=.c.bak) - -rm -f $(SRC:.c=.lst) - -rm -f $(ASRC:.s=.s.bak) - -rm -f $(ASRC:.s=.lst) - -rm -fR .dep +clean: + -rm -f $(BUILDDIR) + -rm -fR $(DEPDIR) # # Include the dependency files, should be the last of the makefile # --include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) +-include $(shell mkdir $(DEPDIR) 2>/dev/null) $(wildcard $(DEPDIR)/*) # *** EOF *** From 67fdb1e0b8faa6e97bd4ed9343805530ca9b0c6f Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 26 Sep 2014 17:29:06 +1000 Subject: [PATCH 20/87] comments --- drivers/multiple/Win32/gdisp_lld_Win32.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/multiple/Win32/gdisp_lld_Win32.c b/drivers/multiple/Win32/gdisp_lld_Win32.c index d4cc130e..875c7ad1 100644 --- a/drivers/multiple/Win32/gdisp_lld_Win32.c +++ b/drivers/multiple/Win32/gdisp_lld_Win32.c @@ -99,8 +99,8 @@ Win32MouseInit, // init 0, // deinit Win32MouseRead, // get - 0, //calsave - 0 //calload + 0, // calsave + 0 // calload }}; #endif From 1298e3d6358f65c677fca8125ee7947501592b39 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 26 Sep 2014 17:29:31 +1000 Subject: [PATCH 21/87] First version X newmouse driver --- drivers/multiple/X/gdisp_lld_X.c | 130 ++++++++++++++++++++----------- 1 file changed, 86 insertions(+), 44 deletions(-) diff --git a/drivers/multiple/X/gdisp_lld_X.c b/drivers/multiple/X/gdisp_lld_X.c index 00b2748b..0462d0d6 100644 --- a/drivers/multiple/X/gdisp_lld_X.c +++ b/drivers/multiple/X/gdisp_lld_X.c @@ -10,10 +10,10 @@ #if GFX_USE_GDISP #define GDISP_DRIVER_VMT GDISPVMT_X11 -#include "drivers/multiple/X/gdisp_lld_config.h" +#include "gdisp_lld_config.h" #include "src/gdisp/driver.h" -#ifndef GDISP_FORCE_24BIT +#ifndef GDISP_FORCE_24BIT #define GDISP_FORCE_24BIT FALSE #endif @@ -27,8 +27,45 @@ #define GDISP_FLG_READY (GDISP_FLG_DRIVER<<0) #if GINPUT_NEED_MOUSE - /* Include mouse support code */ + // Include mouse support code + #define GMOUSE_DRIVER_VMT GMOUSEVMT_X11 #include "src/ginput/driver_mouse.h" + + // Forward definitions + static bool_t XMouseInit(GMouse *m, unsigned driverinstance); + static void XMouseRead(GMouse *m, GMouseReading *prd); + + const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ + { + GDRIVER_TYPE_MOUSE, + GMOUSE_VFLG_NOPOLL|GMOUSE_VFLG_DYNAMICONLY, + // Extra flags for testing only + //GMOUSE_VFLG_TOUCH|GMOUSE_VFLG_SELFROTATION|GMOUSE_VFLG_DEFAULTFINGER + //GMOUSE_VFLG_CALIBRATE|GMOUSE_VFLG_CAL_EXTREMES|GMOUSE_VFLG_CAL_TEST|GMOUSE_VFLG_CAL_LOADFREE + //GMOUSE_VFLG_ONLY_DOWN|GMOUSE_VFLG_POORUPDOWN + sizeof(GMouse), + _gmouseInitDriver, _gmousePostInitDriver, _gmouseDeInitDriver + }, + 1, // z_max + 0, // z_min + 1, // z_touchon + 0, // z_touchoff + { // pen_jitter + 0, // calibrate + 0, // click + 0 // move + }, + { // finger_jitter + 0, // calibrate + 2, // click + 2 // move + }, + XMouseInit, // init + 0, // deinit + XMouseRead, // get + 0, // calsave + 0 // calload + }}; #endif #include @@ -44,15 +81,16 @@ static XEvent evt; static Colormap cmap; static XVisualInfo vis; static XContext cxt; -#if GINPUT_NEED_MOUSE - static coord_t mousex, mousey; - static uint16_t mousebuttons; -#endif typedef struct xPriv { Pixmap pix; GC gc; Window win; + #if GINPUT_NEED_MOUSE + coord_t mousex, mousey; + uint16_t buttons; + GMouse * mouse; + #endif } xPriv; static void ProcessEvent(GDisplay *g, xPriv *priv) { @@ -68,42 +106,36 @@ static void ProcessEvent(GDisplay *g, xPriv *priv) { case Expose: XCopyArea(dis, priv->pix, evt.xexpose.window, priv->gc, evt.xexpose.x, evt.xexpose.y, - evt.xexpose.width, evt.xexpose.height, + evt.xexpose.width, evt.xexpose.height, evt.xexpose.x, evt.xexpose.y); break; #if GINPUT_NEED_MOUSE case ButtonPress: - mousex = evt.xbutton.x; - mousey = evt.xbutton.y; + priv->mousex = evt.xbutton.x; + priv->mousey = evt.xbutton.y; switch(evt.xbutton.button){ - case 1: mousebuttons |= GINPUT_MOUSE_BTN_LEFT; break; - case 2: mousebuttons |= GINPUT_MOUSE_BTN_MIDDLE; break; - case 3: mousebuttons |= GINPUT_MOUSE_BTN_RIGHT; break; - case 4: mousebuttons |= GINPUT_MOUSE_BTN_4; break; + case 1: priv->buttons |= GINPUT_MOUSE_BTN_LEFT; break; + case 2: priv->buttons |= GINPUT_MOUSE_BTN_MIDDLE; break; + case 3: priv->buttons |= GINPUT_MOUSE_BTN_RIGHT; break; + case 4: priv->buttons |= GINPUT_MOUSE_BTN_4; break; } - #if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE - ginputMouseWakeup(); - #endif + _gmouseWakeup(priv->mouse); break; case ButtonRelease: - mousex = evt.xbutton.x; - mousey = evt.xbutton.y; + priv->mousex = evt.xbutton.x; + priv->mousey = evt.xbutton.y; switch(evt.xbutton.button){ - case 1: mousebuttons &= ~GINPUT_MOUSE_BTN_LEFT; break; - case 2: mousebuttons &= ~GINPUT_MOUSE_BTN_MIDDLE; break; - case 3: mousebuttons &= ~GINPUT_MOUSE_BTN_RIGHT; break; - case 4: mousebuttons &= ~GINPUT_MOUSE_BTN_4; break; + case 1: priv->buttons &= ~GINPUT_MOUSE_BTN_LEFT; break; + case 2: priv->buttons &= ~GINPUT_MOUSE_BTN_MIDDLE; break; + case 3: priv->buttons &= ~GINPUT_MOUSE_BTN_RIGHT; break; + case 4: priv->buttons &= ~GINPUT_MOUSE_BTN_4; break; } - #if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE - ginputMouseWakeup(); - #endif + _gmouseWakeup(priv->mouse); break; case MotionNotify: - mousex = evt.xmotion.x; - mousey = evt.xmotion.y; - #if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE - ginputMouseWakeup(); - #endif + priv->mousex = evt.xmotion.x; + priv->mousey = evt.xmotion.y; + _gmouseWakeup(priv->mouse); break; #endif } @@ -125,7 +157,7 @@ static DECLARE_THREAD_FUNCTION(ThreadX, arg) { } return 0; } - + static int FatalXIOError(Display *d) { (void) d; @@ -187,13 +219,13 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { xa.colormap = cmap; xa.border_pixel = 0xFFFFFF; xa.background_pixel = 0x000000; - + priv->win = XCreateWindow(dis, RootWindow(dis, scr), 16, 16, GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT, 0, vis.depth, InputOutput, vis.visual, CWBackPixel|CWColormap|CWBorderPixel, &xa); XSync(dis, TRUE); - + XSaveContext(dis, priv->win, cxt, (XPointer)g); { @@ -205,7 +237,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { XSetWMIconName(dis, priv->win, &WindowTitle); XSync(dis, TRUE); } - + pSH = XAllocSizeHints(); pSH->flags = PSize | PMinSize | PMaxSize; pSH->min_width = pSH->max_width = pSH->base_width = GDISP_SCREEN_WIDTH; @@ -213,7 +245,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { XSetWMNormalHints(dis, priv->win, pSH); XFree(pSH); XSync(dis, TRUE); - + priv->pix = XCreatePixmap(dis, priv->win, GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT, vis.depth); XSync(dis, TRUE); @@ -236,6 +268,12 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { g->g.Contrast = 50; g->g.Width = GDISP_SCREEN_WIDTH; g->g.Height = GDISP_SCREEN_HEIGHT; + + // Create the associated mouse + #if GINPUT_NEED_MOUSE + priv->mouse = (GMouse *)gdriverRegister((const GDriverVMT const *)GMOUSE_DRIVER_VMT, g); + #endif + return TRUE; } @@ -312,16 +350,20 @@ LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) #endif #if GINPUT_NEED_MOUSE - - void ginput_lld_mouse_init(void) {} - - void ginput_lld_mouse_get_reading(MouseReading *pt) { - pt->x = mousex; - pt->y = mousey; - pt->z = (mousebuttons & GINPUT_MOUSE_BTN_LEFT) ? 100 : 0; - pt->buttons = mousebuttons; + static bool_t XMouseInit(GMouse *m, unsigned driverinstance) { + (void) m; + (void) driverinstance; + return TRUE; } + static void XMouseRead(GMouse *m, GMouseReading *pt) { + xPriv * priv; + priv = m->display->priv; + pt->x = priv->mousex; + pt->y = priv->mousey; + pt->z = (priv->buttons & GINPUT_MOUSE_BTN_LEFT) ? 1 : 0; + pt->buttons = priv->buttons; + } #endif /* GINPUT_NEED_MOUSE */ #endif /* GFX_USE_GDISP */ From 8926f56babf93c13d18649ade196c1e42b56e77e Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 26 Sep 2014 18:08:49 +1000 Subject: [PATCH 22/87] More makefile updates --- boards/base/Linux-Framebuffer/example/Makefile | 10 +++++++++- boards/base/Linux/example/Makefile | 10 +++++++++- boards/base/Win32/example/Makefile | 5 ++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/boards/base/Linux-Framebuffer/example/Makefile b/boards/base/Linux-Framebuffer/example/Makefile index 8be8c839..d5032f57 100644 --- a/boards/base/Linux-Framebuffer/example/Makefile +++ b/boards/base/Linux-Framebuffer/example/Makefile @@ -107,6 +107,10 @@ ifeq ($(MAKECMDGOALS),Debug) BUILDDIR = bin/Debug else ifeq ($(MAKECMDGOALS),Release) BUILDDIR = bin/Release +else ifeq ($(MAKECMDGOALS),cleanDebug) + BUILDDIR = bin/Debug +else ifeq ($(MAKECMDGOALS),cleanRelease) + BUILDDIR = bin/Release else ifeq ($(BUILDDIR),) BUILDDIR = .build else ifeq ($(BUILDDIR),.) @@ -158,6 +162,10 @@ CPFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d # makefile rules # +Debug Release: all + +cleanDebug cleanRelease: clean + all: $(BUILDDIR) $(OBJS) $(PROJECT) $(BUILDDIR) $(OBJDIR) $(LSTDIR) $(MAPDIR): @@ -201,7 +209,7 @@ gcov: -mv *.gcov ./gcov clean: - -rm -f $(BUILDDIR) + -rm -fR $(BUILDDIR) -rm -fR $(DEPDIR) # diff --git a/boards/base/Linux/example/Makefile b/boards/base/Linux/example/Makefile index 938494cb..21343755 100644 --- a/boards/base/Linux/example/Makefile +++ b/boards/base/Linux/example/Makefile @@ -107,6 +107,10 @@ ifeq ($(MAKECMDGOALS),Debug) BUILDDIR = bin/Debug else ifeq ($(MAKECMDGOALS),Release) BUILDDIR = bin/Release +else ifeq ($(MAKECMDGOALS),cleanDebug) + BUILDDIR = bin/Debug +else ifeq ($(MAKECMDGOALS),cleanRelease) + BUILDDIR = bin/Release else ifeq ($(BUILDDIR),) BUILDDIR = .build else ifeq ($(BUILDDIR),.) @@ -158,6 +162,10 @@ CPFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d # makefile rules # +Debug Release: all + +cleanDebug cleanRelease: clean + all: $(BUILDDIR) $(OBJS) $(PROJECT) $(BUILDDIR) $(OBJDIR) $(LSTDIR) $(MAPDIR): @@ -201,7 +209,7 @@ gcov: -mv *.gcov ./gcov clean: - -rm -f $(BUILDDIR) + -rm -fR $(BUILDDIR) -rm -fR $(DEPDIR) # diff --git a/boards/base/Win32/example/Makefile b/boards/base/Win32/example/Makefile index 030cfc20..7d54ac02 100644 --- a/boards/base/Win32/example/Makefile +++ b/boards/base/Win32/example/Makefile @@ -132,6 +132,10 @@ ifeq ($(MAKECMDGOALS),Debug) BUILDDIR = bin/Debug else ifeq ($(MAKECMDGOALS),Release) BUILDDIR = bin/Release +else ifeq ($(MAKECMDGOALS),cleanDebug) + BUILDDIR = bin/Debug +else ifeq ($(MAKECMDGOALS),cleanRelease) + BUILDDIR = bin/Release else ifeq ($(BUILDDIR),) BUILDDIR = .build else ifeq ($(BUILDDIR),.) @@ -168,7 +172,6 @@ CPFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d Debug Release: all cleanDebug cleanRelease: clean - -rm -fR bin all: $(BUILDDIR) $(OBJS) $(BUILDDIR)/$(PROJECT).exe MAKE_ALL_RULE_HOOK #all: main.cp From ca71163aa02512915a7c022680ff0c9186ca0b03 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 26 Sep 2014 18:23:41 +1000 Subject: [PATCH 23/87] gdriver bugfix --- src/gdriver/gdriver_gdriver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gdriver/gdriver_gdriver.c b/src/gdriver/gdriver_gdriver.c index d44d6f3c..916b44fb 100644 --- a/src/gdriver/gdriver_gdriver.c +++ b/src/gdriver/gdriver_gdriver.c @@ -56,7 +56,7 @@ GDriver *gdriverRegister(const GDriverVMT *vmt, void *param) { if (dhead) dtail->driverchain = pd; else - dhead = pd; + dhead = dtail = pd; // Do the post init if (vmt->postinit) From d4eaafce109dfe2088ef2a8346b74694ca246af0 Mon Sep 17 00:00:00 2001 From: inmarket Date: Sun, 28 Sep 2014 01:44:24 +1000 Subject: [PATCH 24/87] Fix occassional startup crash under Win32 with newmouse --- drivers/multiple/Win32/gdisp_lld_Win32.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/multiple/Win32/gdisp_lld_Win32.c b/drivers/multiple/Win32/gdisp_lld_Win32.c index 875c7ad1..ecb100f6 100644 --- a/drivers/multiple/Win32/gdisp_lld_Win32.c +++ b/drivers/multiple/Win32/gdisp_lld_Win32.c @@ -496,16 +496,16 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { while(!(((volatile GDisplay *)g)->flags & GDISP_FLG_READY)) Sleep(1); - sprintf(buf, APP_NAME " - %u", g->systemdisplay+1); - SetWindowText(priv->hwnd, buf); - ShowWindow(priv->hwnd, SW_SHOW); - UpdateWindow(priv->hwnd); - // Create the associated mouse #if GINPUT_NEED_MOUSE priv->mouse = (GMouse *)gdriverRegister((const GDriverVMT const *)GMOUSE_DRIVER_VMT, g); #endif + sprintf(buf, APP_NAME " - %u", g->systemdisplay+1); + SetWindowText(priv->hwnd, buf); + ShowWindow(priv->hwnd, SW_SHOW); + UpdateWindow(priv->hwnd); + return TRUE; } From 7cceda585defd3fd1ea1802095660c16d3a4ece2 Mon Sep 17 00:00:00 2001 From: inmarket Date: Sun, 28 Sep 2014 01:44:41 +1000 Subject: [PATCH 25/87] Fix newmouse compiler warning --- src/ginput/ginput_mouse.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ginput/ginput_mouse.c b/src/ginput/ginput_mouse.c index ee6555b2..4e2bc2dd 100644 --- a/src/ginput/ginput_mouse.c +++ b/src/ginput/ginput_mouse.c @@ -52,9 +52,7 @@ static GTIMER_DECL(MouseTimer); // Calibration application #if !GINPUT_TOUCH_NOCALIBRATE - #if GINPUT_TOUCH_USER_CALIBRATION_LOAD - #include // Required for memcpy - #endif + #include // Required for memcpy static inline void CalibrationTransform(GMouseReading *pt, const GMouseCalibration *c) { pt->x = (coord_t) (c->ax * pt->x + c->bx * pt->y + c->cx); From 8d7bbe7e45e47e24074676ca996c0b744b14c959 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sun, 28 Sep 2014 23:02:44 +0200 Subject: [PATCH 26/87] some doxygen fixes (more coming) --- src/gdisp/gdisp_image_bmp.c | 2 +- src/gdisp/gdisp_image_gif.c | 2 +- src/gdisp/gdisp_image_jpg.c | 2 +- src/gdisp/gdisp_image_native.c | 2 +- src/gdisp/gdisp_image_png.c | 2 +- src/ginput/driver_mouse.h | 2 ++ src/gos/gfx_freertos.h | 2 +- src/gos/gfx_win32.c | 2 +- src/gos/gfx_win32.h | 2 +- 9 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/gdisp/gdisp_image_bmp.c b/src/gdisp/gdisp_image_bmp.c index 8ff40ca0..d4507ee2 100644 --- a/src/gdisp/gdisp_image_bmp.c +++ b/src/gdisp/gdisp_image_bmp.c @@ -6,7 +6,7 @@ */ /** - * @file src/gdisp/image_bmp.c + * @file src/gdisp/gdisp_image_bmp.c * @brief GDISP native image code. * * @defgroup Image Image diff --git a/src/gdisp/gdisp_image_gif.c b/src/gdisp/gdisp_image_gif.c index 06f4ef6a..8ea9beb2 100644 --- a/src/gdisp/gdisp_image_gif.c +++ b/src/gdisp/gdisp_image_gif.c @@ -6,7 +6,7 @@ */ /** - * @file src/gdisp/image_gif.c + * @file src/gdisp/gdisp_image_gif.c * @brief GDISP native image code. * * @defgroup Image Image diff --git a/src/gdisp/gdisp_image_jpg.c b/src/gdisp/gdisp_image_jpg.c index 2f6a9392..f20884bc 100644 --- a/src/gdisp/gdisp_image_jpg.c +++ b/src/gdisp/gdisp_image_jpg.c @@ -6,7 +6,7 @@ */ /** - * @file src/gdisp/image_jpg.c + * @file src/gdisp/gdisp_image_jpg.c * @brief GDISP native image code. */ #include "gfx.h" diff --git a/src/gdisp/gdisp_image_native.c b/src/gdisp/gdisp_image_native.c index 81344642..21dcb0fc 100644 --- a/src/gdisp/gdisp_image_native.c +++ b/src/gdisp/gdisp_image_native.c @@ -6,7 +6,7 @@ */ /** - * @file src/gdisp/image_native.c + * @file src/gdisp/gdisp_image_native.c * @brief GDISP native image code. */ #include "gfx.h" diff --git a/src/gdisp/gdisp_image_png.c b/src/gdisp/gdisp_image_png.c index f35174d9..5d2c1450 100644 --- a/src/gdisp/gdisp_image_png.c +++ b/src/gdisp/gdisp_image_png.c @@ -6,7 +6,7 @@ */ /** - * @file src/gdisp/image_png.c + * @file src/gdisp/gdisp_image_png.c * @brief GDISP native image code. */ #include "gfx.h" diff --git a/src/ginput/driver_mouse.h b/src/ginput/driver_mouse.h index 76367ba2..a252bca1 100644 --- a/src/ginput/driver_mouse.h +++ b/src/ginput/driver_mouse.h @@ -112,6 +112,8 @@ extern "C" { * @note These routines are provided by the high level code for * use in the GMouseVMT.d structure. * + * @return TRUE on success, FALSE otherwise + * * @notapi * @{ */ diff --git a/src/gos/gfx_freertos.h b/src/gos/gfx_freertos.h index 34ef548e..57f9b8bd 100644 --- a/src/gos/gfx_freertos.h +++ b/src/gos/gfx_freertos.h @@ -6,7 +6,7 @@ */ /** - * @file src/gos/freertos.h + * @file src/gos/gfx_freertos.h * @brief GOS - Operating System Support header file for FreeRTOS. */ diff --git a/src/gos/gfx_win32.c b/src/gos/gfx_win32.c index ffa7fac5..5d33314f 100644 --- a/src/gos/gfx_win32.c +++ b/src/gos/gfx_win32.c @@ -6,7 +6,7 @@ */ /** - * @file src/gos/win32.c + * @file src/gos/gfx_win32.c * @brief GOS Win32 Operating System support. */ #include "gfx.h" diff --git a/src/gos/gfx_win32.h b/src/gos/gfx_win32.h index 4a198200..5e924a44 100644 --- a/src/gos/gfx_win32.h +++ b/src/gos/gfx_win32.h @@ -6,7 +6,7 @@ */ /** - * @file src/gos/win32.h + * @file src/gos/gfx_win32.h * @brief GOS - Operating System Support header file for WIN32. */ From 0253b7df4967b3fee54d9d9a1e588e6da8cd687d Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sun, 28 Sep 2014 23:42:53 +0200 Subject: [PATCH 27/87] some more doxygen fixes --- src/gdisp/sys_defs.h | 12 ++++++++++++ src/gfile/sys_defs.h | 14 +++++++------- src/ginput/driver_mouse.h | 29 +++++++++++++++++++++++------ src/gwin/gwin_widget.h | 10 ---------- 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/gdisp/sys_defs.h b/src/gdisp/sys_defs.h index 35844e2d..6ebfe8b5 100644 --- a/src/gdisp/sys_defs.h +++ b/src/gdisp/sys_defs.h @@ -250,6 +250,8 @@ unsigned gdispGetDisplayCount(void); * * @param[in] g The display to use * + * @return The width of the display + * * @api */ coord_t gdispGGetWidth(GDisplay *g); @@ -260,6 +262,8 @@ coord_t gdispGGetWidth(GDisplay *g); * * @param[in] g The display to use * + * @return The height of the display + * * @api */ coord_t gdispGGetHeight(GDisplay *g); @@ -270,6 +274,8 @@ coord_t gdispGGetHeight(GDisplay *g); * * @param[in] g The display to use * + * @return The current power mode + * * @api */ powermode_t gdispGGetPowerMode(GDisplay *g); @@ -280,6 +286,8 @@ powermode_t gdispGGetPowerMode(GDisplay *g); * * @param[in] g The display to use * + * @return The current orientation + * * @api */ orientation_t gdispGGetOrientation(GDisplay *g); @@ -290,6 +298,8 @@ orientation_t gdispGGetOrientation(GDisplay *g); * * @param[in] g The display to use * + * @return The current backlight value + * * @api */ uint8_t gdispGGetBacklight(GDisplay *g); @@ -300,6 +310,8 @@ uint8_t gdispGGetBacklight(GDisplay *g); * * @param[in] g The display to use * + * @return The current contrast value + * * @api */ uint8_t gdispGGetContrast(GDisplay *g); diff --git a/src/gfile/sys_defs.h b/src/gfile/sys_defs.h index 5a2d9845..2c475b40 100644 --- a/src/gfile/sys_defs.h +++ b/src/gfile/sys_defs.h @@ -103,21 +103,21 @@ extern "C" { * @return Valid GFILE on success, 0 otherwise * * @note The modes follow the c library fopen() standard. - * The valid modes are:
+ * The valid modes are: *
  • r - Open for read, the file must exist
  • *
  • w - Open for write, the file is truncated if it exists
  • *
  • wx - Open for write, the file must not exist
  • *
  • a - Open for append, the file is truncated if it exists
  • *
  • ax - Open for append, the file must not exists
  • - *

- * THe following flags can also be added to the above modes:
+ * + * The following flags can also be added to the above modes:
*
  • + - Open for both read and write
  • *
  • b - Open as a binary file rather than a text file
  • - *
      + *
    * @note Not all file-systems support all modes. For example, write * is not available with the ROM file-system. Similarly few platforms * distinguish between binary and text files. - * @note Even though binary vs text is relevant only for a small number of platforms + * @note Even though binary vs. text is relevant only for a small number of platforms * the "b" flag should always be specified for binary files such as images. * This ensures portability to other platforms. The extra flag will be ignored * on platforms where it is not relevant. @@ -346,8 +346,8 @@ extern "C" { /** * @brief Open file from a null terminated C string * - * @param[in] memptr The pointer to the string or string buffer - * @param[in] mode The mode. + * @param[in] str The pointer to the string or string buffer + * @param[in] mode The mode * * @return Valid GFILE on success, 0 otherwise * diff --git a/src/ginput/driver_mouse.h b/src/ginput/driver_mouse.h index a252bca1..0f4c475a 100644 --- a/src/ginput/driver_mouse.h +++ b/src/ginput/driver_mouse.h @@ -17,7 +17,7 @@ #ifndef _LLD_GINPUT_MOUSE_H #define _LLD_GINPUT_MOUSE_H -#if GINPUT_NEED_MOUSE || defined(__DOXYGEN__) +#if GINPUT_NEED_MOUSE //|| defined(__DOXYGEN__) // Include the GDRIVER infrastructure #include "src/gdriver/sys_defs.h" @@ -108,19 +108,36 @@ typedef struct GMouseVMT { extern "C" { #endif /** - * @brief Routines needed by the general driver VMT - * @note These routines are provided by the high level code for - * use in the GMouseVMT.d structure. + * @brief Initialize a mouse driver + * + * @param[in] g The mouse driver + * @param[in] display The display to which the mouse shall be assigned + * @param[in] driverinstance The driver instance ToDo: Add some more details + * @param[in] systeminstance The mouse instance ToDo: Add some more details * * @return TRUE on success, FALSE otherwise * * @notapi - * @{ */ bool_t _gmouseInitDriver(GDriver *g, void *display, unsigned driverinstance, unsigned systeminstance); + + /** + * @brief Routine that is called after initialization + * + * @param[in] g The mouse driver + * + * @notapi + */ void _gmousePostInitDriver(GDriver *g); + + /** + * @brief Deinitialize a mouse driver + * + * @param[in] g The mouse driver + * + * @notapi + */ void _gmouseDeInitDriver(GDriver *g); - /** @} */ /** * @brief Wakeup the high level code so that it attempts another read diff --git a/src/gwin/gwin_widget.h b/src/gwin/gwin_widget.h index 2c503116..c6bc6d4c 100644 --- a/src/gwin/gwin_widget.h +++ b/src/gwin/gwin_widget.h @@ -305,16 +305,6 @@ void gwinSetCustomDraw(GHandle gh, CustomWidgetDrawFunction fn, void *param); bool_t gwinAttachListener(GListener *pl); #if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) || defined(__DOXYGEN__) - /** - * @brief Set the mouse to be used to control the widgets - * @return TRUE on success - * - * @param[in] instance The mouse instance - * - * @note Every widget uses the same mouse. - * - * @api - */ bool_t DEPRECATED("This call can now be removed. Attaching the mouse to GWIN is now automatic.") gwinAttachMouse(uint16_t instance); #endif From a873d55173fd0552e1108f4ccd9868fc4cb5163a Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 29 Sep 2014 15:58:44 +1000 Subject: [PATCH 28/87] doxygen updates --- src/ginput/driver_mouse.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ginput/driver_mouse.h b/src/ginput/driver_mouse.h index 0f4c475a..4a61d46b 100644 --- a/src/ginput/driver_mouse.h +++ b/src/ginput/driver_mouse.h @@ -116,6 +116,8 @@ extern "C" { * @param[in] systeminstance The mouse instance ToDo: Add some more details * * @return TRUE on success, FALSE otherwise + * @note This routine is provided by the high level code for + * use in the driver VMT's GMouseVMT.d structure. * * @notapi */ @@ -125,6 +127,8 @@ extern "C" { * @brief Routine that is called after initialization * * @param[in] g The mouse driver + * @note This routine is provided by the high level code for + * use in the driver VMT's GMouseVMT.d structure. * * @notapi */ @@ -134,6 +138,8 @@ extern "C" { * @brief Deinitialize a mouse driver * * @param[in] g The mouse driver + * @note This routine is provided by the high level code for + * use in the driver VMT's GMouseVMT.d structure. * * @notapi */ From 6b158b8a0bc28a5edebc4aa52c8456807dd8837e Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 29 Sep 2014 15:59:37 +1000 Subject: [PATCH 29/87] Move mouse initialisation to a better spot --- drivers/multiple/X/gdisp_lld_X.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/multiple/X/gdisp_lld_X.c b/drivers/multiple/X/gdisp_lld_X.c index 0462d0d6..e6136b49 100644 --- a/drivers/multiple/X/gdisp_lld_X.c +++ b/drivers/multiple/X/gdisp_lld_X.c @@ -254,6 +254,11 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { XSetBackground(dis, priv->gc, BlackPixel(dis, scr)); XSync(dis, TRUE); + // Create the associated mouse before the map + #if GINPUT_NEED_MOUSE + priv->mouse = (GMouse *)gdriverRegister((const GDriverVMT const *)GMOUSE_DRIVER_VMT, g); + #endif + XSelectInput(dis, priv->win, StructureNotifyMask); XMapWindow(dis, priv->win); @@ -269,11 +274,6 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { g->g.Width = GDISP_SCREEN_WIDTH; g->g.Height = GDISP_SCREEN_HEIGHT; - // Create the associated mouse - #if GINPUT_NEED_MOUSE - priv->mouse = (GMouse *)gdriverRegister((const GDriverVMT const *)GMOUSE_DRIVER_VMT, g); - #endif - return TRUE; } From a9e802395eff4517e79701ff210048b732c4b189 Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 29 Sep 2014 16:00:17 +1000 Subject: [PATCH 30/87] X bug fix so that window closes properly when using a window manager --- drivers/multiple/X/gdisp_lld_X.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/multiple/X/gdisp_lld_X.c b/drivers/multiple/X/gdisp_lld_X.c index e6136b49..6e0233ba 100644 --- a/drivers/multiple/X/gdisp_lld_X.c +++ b/drivers/multiple/X/gdisp_lld_X.c @@ -81,6 +81,7 @@ static XEvent evt; static Colormap cmap; static XVisualInfo vis; static XContext cxt; +static Atom wmDelete; typedef struct xPriv { Pixmap pix; @@ -103,6 +104,12 @@ static void ProcessEvent(GDisplay *g, xPriv *priv) { XCloseDisplay(dis); exit(0); break; + case ClientMessage: + if ((Atom)evt.xclient.data.l[0] == wmDelete) { + XCloseDisplay(dis); + exit(0); + } + break; case Expose: XCopyArea(dis, priv->pix, evt.xexpose.window, priv->gc, evt.xexpose.x, evt.xexpose.y, @@ -184,6 +191,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { dis = XOpenDisplay(0); scr = DefaultScreen(dis); cxt = XUniqueContext(); + wmDelete = XInternAtom(dis, "WM_DELETE_WINDOW", False); XSetIOErrorHandler(FatalXIOError); #if GDISP_FORCE_24BIT @@ -227,6 +235,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { XSync(dis, TRUE); XSaveContext(dis, priv->win, cxt, (XPointer)g); + XSetWMProtocols(dis, priv->win, &wmDelete, 1); { char buf[132]; From 1e8a7ff6ddb5bb9accaf2918c98667427aa1b6b3 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Mon, 29 Sep 2014 08:07:43 +0200 Subject: [PATCH 31/87] /src/gos/gfx_* -> /src/gos/gos_* --- src/gos/{gfx_chibios.c => gos_chibios.c} | 0 src/gos/{gfx_chibios.h => gos_chibios.h} | 0 src/gos/{gfx_ecos.c => gos_ecos.c} | 0 src/gos/{gfx_ecos.h => gos_ecos.h} | 0 src/gos/{gfx_freertos.c => gos_freertos.c} | 0 src/gos/{gfx_freertos.h => gos_freertos.h} | 0 src/gos/{gfx_linux.c => gos_linux.c} | 0 src/gos/{gfx_linux.h => gos_linux.h} | 0 src/gos/{gfx_osx.c => gos_osx.c} | 0 src/gos/{gfx_osx.h => gos_osx.h} | 0 src/gos/{gfx_raw32.c => gos_raw32.c} | 0 src/gos/{gfx_raw32.h => gos_raw32.h} | 0 src/gos/{gfx_rawrtos.c => gos_rawrtos.c} | 0 src/gos/{gfx_rawrtos.h => gos_rawrtos.h} | 0 src/gos/{gfx_win32.c => gos_win32.c} | 0 src/gos/{gfx_win32.h => gos_win32.h} | 0 src/gos/sys_defs.h | 16 ++++++++-------- src/gos/sys_make.mk | 16 ++++++++-------- 18 files changed, 16 insertions(+), 16 deletions(-) rename src/gos/{gfx_chibios.c => gos_chibios.c} (100%) rename src/gos/{gfx_chibios.h => gos_chibios.h} (100%) rename src/gos/{gfx_ecos.c => gos_ecos.c} (100%) rename src/gos/{gfx_ecos.h => gos_ecos.h} (100%) rename src/gos/{gfx_freertos.c => gos_freertos.c} (100%) rename src/gos/{gfx_freertos.h => gos_freertos.h} (100%) rename src/gos/{gfx_linux.c => gos_linux.c} (100%) rename src/gos/{gfx_linux.h => gos_linux.h} (100%) rename src/gos/{gfx_osx.c => gos_osx.c} (100%) rename src/gos/{gfx_osx.h => gos_osx.h} (100%) rename src/gos/{gfx_raw32.c => gos_raw32.c} (100%) rename src/gos/{gfx_raw32.h => gos_raw32.h} (100%) rename src/gos/{gfx_rawrtos.c => gos_rawrtos.c} (100%) rename src/gos/{gfx_rawrtos.h => gos_rawrtos.h} (100%) rename src/gos/{gfx_win32.c => gos_win32.c} (100%) rename src/gos/{gfx_win32.h => gos_win32.h} (100%) diff --git a/src/gos/gfx_chibios.c b/src/gos/gos_chibios.c similarity index 100% rename from src/gos/gfx_chibios.c rename to src/gos/gos_chibios.c diff --git a/src/gos/gfx_chibios.h b/src/gos/gos_chibios.h similarity index 100% rename from src/gos/gfx_chibios.h rename to src/gos/gos_chibios.h diff --git a/src/gos/gfx_ecos.c b/src/gos/gos_ecos.c similarity index 100% rename from src/gos/gfx_ecos.c rename to src/gos/gos_ecos.c diff --git a/src/gos/gfx_ecos.h b/src/gos/gos_ecos.h similarity index 100% rename from src/gos/gfx_ecos.h rename to src/gos/gos_ecos.h diff --git a/src/gos/gfx_freertos.c b/src/gos/gos_freertos.c similarity index 100% rename from src/gos/gfx_freertos.c rename to src/gos/gos_freertos.c diff --git a/src/gos/gfx_freertos.h b/src/gos/gos_freertos.h similarity index 100% rename from src/gos/gfx_freertos.h rename to src/gos/gos_freertos.h diff --git a/src/gos/gfx_linux.c b/src/gos/gos_linux.c similarity index 100% rename from src/gos/gfx_linux.c rename to src/gos/gos_linux.c diff --git a/src/gos/gfx_linux.h b/src/gos/gos_linux.h similarity index 100% rename from src/gos/gfx_linux.h rename to src/gos/gos_linux.h diff --git a/src/gos/gfx_osx.c b/src/gos/gos_osx.c similarity index 100% rename from src/gos/gfx_osx.c rename to src/gos/gos_osx.c diff --git a/src/gos/gfx_osx.h b/src/gos/gos_osx.h similarity index 100% rename from src/gos/gfx_osx.h rename to src/gos/gos_osx.h diff --git a/src/gos/gfx_raw32.c b/src/gos/gos_raw32.c similarity index 100% rename from src/gos/gfx_raw32.c rename to src/gos/gos_raw32.c diff --git a/src/gos/gfx_raw32.h b/src/gos/gos_raw32.h similarity index 100% rename from src/gos/gfx_raw32.h rename to src/gos/gos_raw32.h diff --git a/src/gos/gfx_rawrtos.c b/src/gos/gos_rawrtos.c similarity index 100% rename from src/gos/gfx_rawrtos.c rename to src/gos/gos_rawrtos.c diff --git a/src/gos/gfx_rawrtos.h b/src/gos/gos_rawrtos.h similarity index 100% rename from src/gos/gfx_rawrtos.h rename to src/gos/gos_rawrtos.h diff --git a/src/gos/gfx_win32.c b/src/gos/gos_win32.c similarity index 100% rename from src/gos/gfx_win32.c rename to src/gos/gos_win32.c diff --git a/src/gos/gfx_win32.h b/src/gos/gos_win32.h similarity index 100% rename from src/gos/gfx_win32.h rename to src/gos/gos_win32.h diff --git a/src/gos/sys_defs.h b/src/gos/sys_defs.h index d116826f..e4b3ddd2 100644 --- a/src/gos/sys_defs.h +++ b/src/gos/sys_defs.h @@ -440,21 +440,21 @@ * (without any of the documentation overheads) is in the files below. */ #elif GFX_USE_OS_RAWRTOS - #include "src/gos/gfx_rawrtos.h" + #include "src/gos/gos_rawrtos.h" #elif GFX_USE_OS_CHIBIOS - #include "src/gos/gfx_chibios.h" + #include "src/gos/gos_chibios.h" #elif GFX_USE_OS_FREERTOS - #include "src/gos/gfx_freertos.h" + #include "src/gos/gos_freertos.h" #elif GFX_USE_OS_WIN32 - #include "src/gos/gfx_win32.h" + #include "src/gos/gos_win32.h" #elif GFX_USE_OS_LINUX - #include "src/gos/gfx_linux.h" + #include "src/gos/gos_linux.h" #elif GFX_USE_OS_OSX - #include "src/gos/gfx_osx.h" + #include "src/gos/gos_osx.h" #elif GFX_USE_OS_RAW32 - #include "src/gos/gfx_raw32.h" + #include "src/gos/gos_raw32.h" #elif GFX_USE_OS_ECOS - #include "src/gos/gfx_ecos.h" + #include "src/gos/gos_ecos.h" #else #error "Your operating system is not supported yet" #endif diff --git a/src/gos/sys_make.mk b/src/gos/sys_make.mk index 5efa7f80..a7b3dec6 100644 --- a/src/gos/sys_make.mk +++ b/src/gos/sys_make.mk @@ -1,9 +1,9 @@ -GFXSRC += $(GFXLIB)/src/gos/gfx_chibios.c \ - $(GFXLIB)/src/gos/gfx_freertos.c \ - $(GFXLIB)/src/gos/gfx_win32.c \ - $(GFXLIB)/src/gos/gfx_linux.c \ - $(GFXLIB)/src/gos/gfx_osx.c \ - $(GFXLIB)/src/gos/gfx_raw32.c \ - $(GFXLIB)/src/gos/gfx_ecos.c \ - $(GFXLIB)/src/gos/gfx_rawrtos.c +GFXSRC += $(GFXLIB)/src/gos/gos_chibios.c \ + $(GFXLIB)/src/gos/gos_freertos.c \ + $(GFXLIB)/src/gos/gos_win32.c \ + $(GFXLIB)/src/gos/gos_linux.c \ + $(GFXLIB)/src/gos/gos_osx.c \ + $(GFXLIB)/src/gos/gos_raw32.c \ + $(GFXLIB)/src/gos/gos_ecos.c \ + $(GFXLIB)/src/gos/gos_rawrtos.c From d4a40cb507de1b164e28c369f045ea8e1ce5b491 Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 29 Sep 2014 17:50:43 +1000 Subject: [PATCH 32/87] Makefile fix --- drivers/multiple/uGFXnet/driver.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/multiple/uGFXnet/driver.mk b/drivers/multiple/uGFXnet/driver.mk index c9d2749c..a579a659 100644 --- a/drivers/multiple/uGFXnet/driver.mk +++ b/drivers/multiple/uGFXnet/driver.mk @@ -1,6 +1,6 @@ GFXINC += $(GFXLIB)/drivers/multiple/uGFXnet GFXSRC += $(GFXLIB)/drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c -ifeq($(OPT_NATIVEOS),win32) +ifeq ($(OPT_NATIVEOS),win32) GFXLIBS += ws2_32 endif From ac6e26f1a0a299152dadb61171127322033bdd8b Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 29 Sep 2014 17:51:23 +1000 Subject: [PATCH 33/87] uGFXnet ported to newmouse driver (and tidied up) --- drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c | 371 ++++++++++--------- 1 file changed, 193 insertions(+), 178 deletions(-) diff --git a/drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c b/drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c index 82c0e2ff..559b0c69 100644 --- a/drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c +++ b/drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c @@ -10,7 +10,7 @@ #if GFX_USE_GDISP #define GDISP_DRIVER_VMT GDISPVMT_uGFXnet -#include "drivers/multiple/uGFXnet/gdisp_lld_config.h" +#include "gdisp_lld_config.h" #include "src/gdisp/driver.h" #include "uGFXnetProtocol.h" @@ -33,6 +33,48 @@ #define GDISP_GFXNET_BROKEN_LWIP_ACCEPT FALSE #endif +#if GINPUT_NEED_MOUSE + // Include mouse support code + #define GMOUSE_DRIVER_VMT GMOUSEVMT_uGFXnet + #include "src/ginput/driver_mouse.h" + + // Forward definitions + static bool_t NMouseInit(GMouse *m, unsigned driverinstance); + static void NMouseRead(GMouse *m, GMouseReading *prd); + + const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ + { + GDRIVER_TYPE_MOUSE, + GMOUSE_VFLG_NOPOLL|GMOUSE_VFLG_DYNAMICONLY, + // Extra flags for testing only + //GMOUSE_VFLG_TOUCH|GMOUSE_VFLG_SELFROTATION|GMOUSE_VFLG_DEFAULTFINGER + //GMOUSE_VFLG_CALIBRATE|GMOUSE_VFLG_CAL_EXTREMES|GMOUSE_VFLG_CAL_TEST|GMOUSE_VFLG_CAL_LOADFREE + //GMOUSE_VFLG_ONLY_DOWN|GMOUSE_VFLG_POORUPDOWN + sizeof(GMouse), + _gmouseInitDriver, _gmousePostInitDriver, _gmouseDeInitDriver + }, + 1, // z_max + 0, // z_min + 1, // z_touchon + 0, // z_touchoff + { // pen_jitter + 0, // calibrate + 0, // click + 0 // move + }, + { // finger_jitter + 0, // calibrate + 2, // click + 2 // move + }, + NMouseInit, // init + 0, // deinit + NMouseRead, // get + 0, // calsave + 0 // calload + }}; +#endif + #if GNETCODE_VERSION != GNETCODE_VERSION_1_0 #error "GDISP: uGFXnet - This driver only support protocol V1.0" #endif @@ -98,14 +140,8 @@ #endif #endif -#define GDISP_FLG_HASMOUSE (GDISP_FLG_DRIVER<<0) -#define GDISP_FLG_CONNECTED (GDISP_FLG_DRIVER<<1) -#define GDISP_FLG_HAVEDATA (GDISP_FLG_DRIVER<<2) - -#if GINPUT_NEED_MOUSE - /* Include mouse support code */ - #include "src/ginput/driver_mouse.h" -#endif +#define GDISP_FLG_CONNECTED (GDISP_FLG_DRIVER<<0) +#define GDISP_FLG_HAVEDATA (GDISP_FLG_DRIVER<<1) /*===========================================================================*/ /* Driver local routines . */ @@ -118,15 +154,12 @@ typedef struct netPriv { #if GINPUT_NEED_MOUSE coord_t mousex, mousey; uint16_t mousebuttons; + GMouse * mouse; #endif } netPriv; static gfxThreadHandle hThread; -#if GINPUT_NEED_MOUSE - static GDisplay * mouseDisplay; -#endif - #if GDISP_GFXNET_UNSAFE_SOCKETS static gfxMutex uGFXnetMutex; #define MUTEX_INIT gfxMutexInit(&uGFXnetMutex) @@ -156,15 +189,134 @@ static bool_t sendpkt(SOCKET_TYPE netfd, uint16_t *pkt, int len) { return send(netfd, (const char *)pkt, len, 0) == len; } +static bool_t newconnection(SOCKET_TYPE clientfd) { + GDisplay * g; + netPriv * priv; + + // Look for a display that isn't connected + for(g = 0; (g = (GDisplay *)gdriverGetNext(GDRIVER_TYPE_DISPLAY, (GDriver *)g));) { + // Ignore displays for other controllers + #ifdef GDISP_DRIVER_LIST + if (gvmt(g) != &GDISPVMT_uGFXnet) + continue; + #endif + if (!(g->flags & GDISP_FLG_CONNECTED)) + break; + } + + // Was anything found? + if (!g) + return FALSE; + + // Reset the priv area + priv = g->priv; + priv->netfd = clientfd; + priv->databytes = 0; + priv->mousebuttons = 0; + + // Send the initialisation data (2 words at a time) + priv->data[0] = GNETCODE_INIT; + priv->data[1] = GNETCODE_VERSION; + sendpkt(priv->netfd, priv->data, 2); + priv->data[0] = GDISP_SCREEN_WIDTH; + priv->data[1] = GDISP_SCREEN_HEIGHT; + sendpkt(priv->netfd, priv->data, 2); + priv->data[0] = GDISP_LLD_PIXELFORMAT; + priv->data[1] = 1; // We have a mouse + MUTEX_ENTER; + sendpkt(priv->netfd, priv->data, 2); + MUTEX_EXIT; + + // The display is now working + g->flags |= GDISP_FLG_CONNECTED; + + // Send a redraw all + #if GFX_USE_GWIN && GWIN_NEED_WINDOWMANAGER + gdispGClear(g, gwinGetDefaultBgColor()); + gwinRedrawDisplay(g, FALSE); + #endif + + return TRUE; +} + +static bool_t rxdata(SOCKET_TYPE fd) { + GDisplay * g; + netPriv * priv; + int len; + + // Look for a display that is connected and the socket descriptor matches + for(g = 0; (g = (GDisplay *)gdriverGetNext(GDRIVER_TYPE_DISPLAY, (GDriver *)g));) { + // Ignore displays for other controllers + #ifdef GDISP_DRIVER_LIST + if (gvmt(g) != &GDISPVMT_uGFXnet) + continue; + #endif + priv = g->priv; + if ((g->flags & GDISP_FLG_CONNECTED) && priv->netfd == fd) + break; + } + if (!g) + gfxHalt("GDISP: uGFXnet - Got data from unrecognized connection"); + + if ((g->flags & GDISP_FLG_HAVEDATA)) { + // The higher level is still processing the previous data. + // Give it a chance to run by coming back to this data. + gfxSleepMilliseconds(1); + return TRUE; + } + + /* handle data from a client */ + MUTEX_ENTER; + if ((len = recv(fd, ((char *)priv->data)+priv->databytes, sizeof(priv->data)-priv->databytes, 0)) <= 0) { + // Socket closed or in error state + MUTEX_EXIT; + g->flags &= ~GDISP_FLG_CONNECTED; + return FALSE; + } + MUTEX_EXIT; + + // Do we have a full reply yet + priv->databytes += len; + if (priv->databytes < sizeof(priv->data)) + return TRUE; + priv->databytes = 0; + + // Convert network byte or to host byte order + priv->data[0] = ntohs(priv->data[0]); + priv->data[1] = ntohs(priv->data[1]); + + // Process the data received + switch(priv->data[0]) { + #if GINPUT_NEED_MOUSE + case GNETCODE_MOUSE_X: priv->mousex = priv->data[1]; break; + case GNETCODE_MOUSE_Y: priv->mousey = priv->data[1]; break; + case GNETCODE_MOUSE_B: + priv->mousebuttons = priv->data[1]; + // Treat the button event as the sync signal + _gmouseWakeup(priv->mouse); + break; + #endif + case GNETCODE_CONTROL: + case GNETCODE_READ: + g->flags |= GDISP_FLG_HAVEDATA; + break; + case GNETCODE_KILL: + gfxHalt("GDISP: uGFXnet - Display sent KILL command"); + break; + + default: + // Just ignore unrecognised data + break; + } + return TRUE; +} + static DECLARE_THREAD_STACK(waNetThread, 512); static DECLARE_THREAD_FUNCTION(NetThread, param) { SOCKET_TYPE listenfd, fdmax, i, clientfd; socklen_t len; - int leni; fd_set master, read_fds; struct sockaddr_in addr; - GDisplay * g; - netPriv * priv; (void)param; // Start the sockets layer @@ -197,25 +349,13 @@ static DECLARE_THREAD_FUNCTION(NetThread, param) { fdmax = listenfd; /* so far, it's this one*/ #if GDISP_GFXNET_BROKEN_LWIP_ACCEPT - { #warning "Using GDISP_GFXNET_BROKEN_LWIP_ACCEPT limits the number of displays and the use of GFXNET. Avoid if possible!" len = sizeof(addr); if((clientfd = accept(listenfd, (struct sockaddr *)&addr, &len)) == (SOCKET_TYPE)-1) gfxHalt("GDISP: uGFXnet - Accept failed"); + //printf("New connection from %s on socket %d\n", inet_ntoa(addr.sin_addr), clientfd); - // Look for a display that isn't connected - for(g = 0; (g = (GDisplay *)gdriverGetNext(GDRIVER_TYPE_DISPLAY, (GDriver *)g));) { - // Ignore displays for other controllers - #ifdef GDISP_DRIVER_LIST - if (gvmt(g) != &GDISPVMT_uGFXnet) - continue; - #endif - if (!(g->flags & GDISP_FLG_CONNECTED)) - break; - } - - // Was anything found? - if (!g) { + if (!newconnection(clientfd)) { // No Just close the connection closesocket(clientfd); gfxHalt("GDISP: uGFXnet - Can't find display for connection"); @@ -225,33 +365,6 @@ static DECLARE_THREAD_FUNCTION(NetThread, param) { // Save the descriptor FD_SET(clientfd, &master); if (clientfd > fdmax) fdmax = clientfd; - priv = g->priv; - memset(priv, 0, sizeof(netPriv)); - priv->netfd = clientfd; - //printf(New connection from %s on socket %d allocated to display %u\n", inet_ntoa(addr.sin_addr), clientfd, disp+1); - - // Send the initialisation data (2 words at a time) - priv->data[0] = GNETCODE_INIT; - priv->data[1] = GNETCODE_VERSION; - sendpkt(priv->netfd, priv->data, 2); - priv->data[0] = GDISP_SCREEN_WIDTH; - priv->data[1] = GDISP_SCREEN_HEIGHT; - sendpkt(priv->netfd, priv->data, 2); - priv->data[0] = GDISP_LLD_PIXELFORMAT; - priv->data[1] = (g->flags & GDISP_FLG_HASMOUSE) ? 1 : 0; - MUTEX_ENTER; - sendpkt(priv->netfd, priv->data, 2); - MUTEX_EXIT; - - // The display is now working - g->flags |= GDISP_FLG_CONNECTED; - - // Send a redraw all - #if GFX_USE_GWIN && GWIN_NEED_WINDOWMANAGER - gdispGClear(g, gwinGetDefaultBgColor()); - gwinRedrawDisplay(g, FALSE); - #endif - } #endif /* loop */ @@ -268,132 +381,33 @@ static DECLARE_THREAD_FUNCTION(NetThread, param) { // Handle new connections if(i == listenfd) { + + // Accept the connection len = sizeof(addr); if((clientfd = accept(listenfd, (struct sockaddr *)&addr, &len)) == (SOCKET_TYPE)-1) gfxHalt("GDISP: uGFXnet - Accept failed"); + //printf("New connection from %s on socket %d\n", inet_ntoa(addr.sin_addr), clientfd); - // Look for a display that isn't connected - for(g = 0; (g = (GDisplay *)gdriverGetNext(GDRIVER_TYPE_DISPLAY, (GDriver *)g));) { - // Ignore displays for other controllers - #ifdef GDISP_DRIVER_LIST - if (gvmt(g) != &GDISPVMT_uGFXnet) - continue; - #endif - if (!(g->flags & GDISP_FLG_CONNECTED)) - break; - } + // Can we handle it? + if (!newconnection(clientfd)) { - // Was anything found? - if (!g) { - // No Just close the connection + // No - Just close the connection closesocket(clientfd); - //printf(New connection from %s on socket %d rejected as all displays are already connected\n", inet_ntoa(addr.sin_addr), clientfd); + + //printf("Rejected connection as all displays are already connected\n"); continue; } // Save the descriptor FD_SET(clientfd, &master); if (clientfd > fdmax) fdmax = clientfd; - priv = g->priv; - memset(priv, 0, sizeof(netPriv)); - priv->netfd = clientfd; - //printf(New connection from %s on socket %d allocated to display %u\n", inet_ntoa(addr.sin_addr), clientfd, disp+1); - - // Send the initialisation data (2 words at a time) - priv->data[0] = GNETCODE_INIT; - priv->data[1] = GNETCODE_VERSION; - sendpkt(priv->netfd, priv->data, 2); - priv->data[0] = GDISP_SCREEN_WIDTH; - priv->data[1] = GDISP_SCREEN_HEIGHT; - sendpkt(priv->netfd, priv->data, 2); - priv->data[0] = GDISP_LLD_PIXELFORMAT; - priv->data[1] = (g->flags & GDISP_FLG_HASMOUSE) ? 1 : 0; - MUTEX_ENTER; - sendpkt(priv->netfd, priv->data, 2); - MUTEX_EXIT; - - // The display is now working - g->flags |= GDISP_FLG_CONNECTED; - - // Send a redraw all - #if GFX_USE_GWIN && GWIN_NEED_WINDOWMANAGER - gdispGClear(g, gwinGetDefaultBgColor()); - gwinRedrawDisplay(g, FALSE); - #endif - continue; } // Handle data from a client - - // Look for a display that is connected and the socket descriptor matches - for(g = 0; (g = (GDisplay *)gdriverGetNext(GDRIVER_TYPE_DISPLAY, (GDriver *)g));) { - // Ignore displays for other controllers - #ifdef GDISP_DRIVER_LIST - if (gvmt(g) != &GDISPVMT_uGFXnet) - continue; - #endif - priv = g->priv; - if ((g->flags & GDISP_FLG_CONNECTED) && priv->netfd == i) - break; - } - if (!g) - gfxHalt("GDISP: uGFXnet - Got data from unrecognized connection"); - - if ((g->flags & GDISP_FLG_HAVEDATA)) { - // The higher level is still processing the previous data. - // Give it a chance to run by coming back to this data. - gfxSleepMilliseconds(1); - continue; - } - - /* handle data from a client */ - MUTEX_ENTER; - if ((leni = recv(i, ((char *)priv->data)+priv->databytes, sizeof(priv->data)-priv->databytes, 0)) <= 0) { - // Socket closed or in error state - MUTEX_EXIT; - g->flags &= ~GDISP_FLG_CONNECTED; - memset(priv, 0, sizeof(netPriv)); + if (!rxdata(i)) { closesocket(i); - FD_CLR(i, &master); - continue; - } - MUTEX_EXIT; - - // Do we have a full reply yet - priv->databytes += leni; - if (priv->databytes < sizeof(priv->data)) - continue; - priv->databytes = 0; - - // Convert network byte or to host byte order - priv->data[0] = ntohs(priv->data[0]); - priv->data[1] = ntohs(priv->data[1]); - - // Process the data received - switch(priv->data[0]) { - #if GINPUT_NEED_MOUSE - case GNETCODE_MOUSE_X: priv->mousex = priv->data[1]; break; - case GNETCODE_MOUSE_Y: priv->mousey = priv->data[1]; break; - case GNETCODE_MOUSE_B: - priv->mousebuttons = priv->data[1]; - // Treat the button event as the sync signal - #if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE - ginputMouseWakeup(); - #endif - break; - #endif - case GNETCODE_CONTROL: - case GNETCODE_READ: - g->flags |= GDISP_FLG_HAVEDATA; - break; - case GNETCODE_KILL: - gfxHalt("GDISP: uGFXnet - Display sent KILL command"); - break; - - default: - // Just ignore unrecognised data - break; + FD_CLR(clientfd, &master); } } } @@ -414,14 +428,6 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { gfxThreadClose(hThread); } - // Only turn on mouse on the first window for now - #if GINPUT_NEED_MOUSE - if (!g->controllerdisplay) { - mouseDisplay = g; - g->flags |= GDISP_FLG_HASMOUSE; - } - #endif - // Create a private area for this window if (!(priv = gfxAlloc(sizeof(netPriv)))) gfxHalt("GDISP: uGFXnet - Memory allocation failed"); @@ -429,6 +435,11 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { g->priv = priv; g->board = 0; // no board interface for this controller + // Create the associated mouse + #if GINPUT_NEED_MOUSE + priv->mouse = (GMouse *)gdriverRegister((const GDriverVMT const *)GMOUSE_DRIVER_VMT, g); + #endif + // Initialise the GDISP structure g->g.Orientation = GDISP_ROTATE_0; g->g.Powermode = powerOn; @@ -694,17 +705,21 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { #endif #if GINPUT_NEED_MOUSE - void ginput_lld_mouse_init(void) {} - void ginput_lld_mouse_get_reading(MouseReading *pt) { + static bool_t NMouseInit(GMouse *m, unsigned driverinstance) { + (void) m; + (void) driverinstance; + return TRUE; + } + static void NMouseRead(GMouse *m, GMouseReading *pt) { GDisplay * g; netPriv * priv; - g = mouseDisplay; + g = m->display; priv = g->priv; pt->x = priv->mousex; pt->y = priv->mousey; - pt->z = (priv->mousebuttons & GINPUT_MOUSE_BTN_LEFT) ? 100 : 0; + pt->z = (priv->mousebuttons & GINPUT_MOUSE_BTN_LEFT) ? 1 : 0; pt->buttons = priv->mousebuttons; } #endif /* GINPUT_NEED_MOUSE */ From 8cc07f2d4c513ed7bd9d0d9a825102555038c715 Mon Sep 17 00:00:00 2001 From: inmarket Date: Tue, 30 Sep 2014 13:33:00 +1000 Subject: [PATCH 34/87] Updated make scripts to be more compatible with older versions of gmake 3.XX --- gfx.mk | 21 ++++++++++++++------- tools/gmake_scripts/compiler_gcc.mk | 12 ++++++++---- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/gfx.mk b/gfx.mk index a0f27c53..89c3282a 100644 --- a/gfx.mk +++ b/gfx.mk @@ -28,18 +28,25 @@ endif # Include the operating system define ifeq ($(OPT_OS),win32) GFXDEFS += GFX_USE_OS_WIN32=TRUE -else ifeq ($(OPT_OS),linux) +endif +ifeq ($(OPT_OS),linux) GFXDEFS += GFX_USE_OS_LINUX=TRUE -else ifeq ($(OPT_OS),osx) +endif +ifeq ($(OPT_OS),osx) GFXDEFS += GFX_USE_OS_OSX=TRUE -else ifeq ($(OPT_OS),chibios) +endif +ifeq ($(OPT_OS),chibios) GFXDEFS += GFX_USE_OS_CHIBIOS=TRUE -else ifeq ($(OPT_OS),freertos) +endif +ifeq ($(OPT_OS),freertos) GFXDEFS += GFX_USE_OS_FREERTOS=TRUE -else ifeq ($(OPT_OS),ecos) +endif +ifeq ($(OPT_OS),ecos) GFXDEFS += GFX_USE_OS_ECOS=TRUE -else ifeq ($(OPT_OS),rawrtos) +endif +ifeq ($(OPT_OS),rawrtos) GFXDEFS += GFX_USE_OS_RAWRTOS=TRUE -else ifeq ($(OPT_OS),raw32) +endif +ifeq ($(OPT_OS),raw32) GFXDEFS += GFX_USE_OS_RAW32=TRUE endif diff --git a/tools/gmake_scripts/compiler_gcc.mk b/tools/gmake_scripts/compiler_gcc.mk index eed78e82..0e5b8098 100644 --- a/tools/gmake_scripts/compiler_gcc.mk +++ b/tools/gmake_scripts/compiler_gcc.mk @@ -23,13 +23,17 @@ endif ifeq ($(BUILDDIR),) ifeq ($(MAKECMDGOALS),Debug) BUILDDIR = bin/Debug - else ifeq ($(MAKECMDGOALS),Release) + endif + ifeq ($(MAKECMDGOALS),Release) BUILDDIR = bin/Release - else ifeq ($(MAKECMDGOALS),cleanDebug) + endif + ifeq ($(MAKECMDGOALS),cleanDebug) BUILDDIR = bin/Debug - else ifeq ($(MAKECMDGOALS),cleanRelease) + endif + ifeq ($(MAKECMDGOALS),cleanRelease) BUILDDIR = bin/Release - else + endif + ifeq ($(BUILDDIR),) BUILDDIR = .build endif endif From 68a784d67e7ff1ce1c922819e5e8f1d6865c69da Mon Sep 17 00:00:00 2001 From: inmarket Date: Wed, 1 Oct 2014 00:44:40 +1000 Subject: [PATCH 35/87] First ARM build to use the new makefile plus makefile updates --- .../base/Linux-Framebuffer/example/Makefile | 36 ++- boards/base/Linux/example/Makefile | 36 ++- boards/base/OSX/example/Makefile | 41 +-- .../Olimex-SAM7EX256-GE8/example/Makefile | 249 ++++-------------- boards/base/Win32/example/Makefile | 63 ++--- drivers/multiple/uGFXnet/driver.mk | 2 +- tools/gmake_scripts/compiler_gcc.mk | 79 +++++- tools/gmake_scripts/os_chibios.mk | 30 +++ tools/gmake_scripts/os_linux.mk | 8 + tools/gmake_scripts/os_osx.mk | 10 + tools/gmake_scripts/os_win32.chibios.mk | 18 ++ tools/gmake_scripts/os_win32.mk | 6 + tools/gmake_scripts/readme.txt | 17 +- 13 files changed, 299 insertions(+), 296 deletions(-) create mode 100644 tools/gmake_scripts/os_chibios.mk create mode 100644 tools/gmake_scripts/os_linux.mk create mode 100644 tools/gmake_scripts/os_osx.mk create mode 100644 tools/gmake_scripts/os_win32.chibios.mk create mode 100644 tools/gmake_scripts/os_win32.mk diff --git a/boards/base/Linux-Framebuffer/example/Makefile b/boards/base/Linux-Framebuffer/example/Makefile index 29b0a266..76b2022a 100644 --- a/boards/base/Linux-Framebuffer/example/Makefile +++ b/boards/base/Linux-Framebuffer/example/Makefile @@ -4,30 +4,37 @@ # Settings # -# See $(GFXLIB)/tools/gmake_scripts/readme.txt for the meaning of these variables -OPT_VERBOSE_COMPILE = no -OPT_GENERATE_LISTINGS = yes -OPT_GENERATE_MAP = yes -OPT_COPY_EXE = no -OPT_NATIVEOS = linux -OPT_OS = linux +# General settings + # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables + OPT_VERBOSE_COMPILE = no + OPT_GENERATE_LISTINGS = yes + OPT_GENERATE_MAP = yes + OPT_COPY_EXE = no + OPT_LINK_OPTIMIZE = yes + OPT_NONSTANDARD_FLAGS = no + OPT_OS = linux -# See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the meaning of these variables -GFXLIB = ../uGFX -GFXBOARD = Linux-Framebuffer -#GFXDRIVERS = multiple/uGFXnet -GFXDEMO = modules/gdisp/basics +# uGFX settings + # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables + GFXLIB = ../uGFX + GFXBOARD = Linux-Framebuffer + #GFXDRIVERS = multiple/uGFXnet + GFXDEMO = modules/gdisp/basics + +# Linux settings + # See $(GFXLIB)/tools/gmake_scripts/os_linux.mk for the list of variables ############################################################################################## # Set these for your project # ARCH = -SRCFLAGS = -m32 -ggdb -O0 -fomit-frame-pointer -Wall -Wextra -Wstrict-prototypes -fverbose-asm +SRCFLAGS = -ggdb -O0 +SRCFLAGS+= -m32 CFLAGS = CXXFLAGS = ASFLAGS = -LDFLAGS = -pthread +LDFLAGS = SRC = DEFS = @@ -40,5 +47,6 @@ LIBPATH = # include $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk +include $(GFXLIB)/tools/gmake_scripts/os_$(OPT_OS).mk include $(GFXLIB)/tools/gmake_scripts/compiler_gcc.mk # *** EOF *** diff --git a/boards/base/Linux/example/Makefile b/boards/base/Linux/example/Makefile index 87b80434..d6402c8a 100644 --- a/boards/base/Linux/example/Makefile +++ b/boards/base/Linux/example/Makefile @@ -4,30 +4,37 @@ # Settings # -# See $(GFXLIB)/tools/gmake_scripts/readme.txt for the meaning of these variables -OPT_VERBOSE_COMPILE = no -OPT_GENERATE_LISTINGS = yes -OPT_GENERATE_MAP = yes -OPT_COPY_EXE = no -OPT_NATIVEOS = linux -OPT_OS = linux +# General settings + # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables + OPT_VERBOSE_COMPILE = no + OPT_GENERATE_LISTINGS = yes + OPT_GENERATE_MAP = yes + OPT_COPY_EXE = no + OPT_LINK_OPTIMIZE = yes + OPT_NONSTANDARD_FLAGS = no + OPT_OS = linux -# See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the meaning of these variables -GFXLIB = ../uGFX -GFXBOARD = Linux -#GFXDRIVERS = multiple/uGFXnet -GFXDEMO = modules/gdisp/basics +# uGFX settings + # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables + GFXLIB = ../uGFX + GFXBOARD = Linux + #GFXDRIVERS = multiple/uGFXnet + GFXDEMO = modules/gdisp/basics + +# Linux settings + # See $(GFXLIB)/tools/gmake_scripts/os_linux.mk for the list of variables ############################################################################################## # Set these for your project # ARCH = -SRCFLAGS = -m32 -ggdb -O0 -fomit-frame-pointer -Wall -Wextra -Wstrict-prototypes -fverbose-asm +SRCFLAGS = -ggdb -O0 +SRCFLAGS+= -m32 CFLAGS = CXXFLAGS = ASFLAGS = -LDFLAGS = -pthread +LDFLAGS = SRC = DEFS = @@ -40,5 +47,6 @@ LIBPATH = # include $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk +include $(GFXLIB)/tools/gmake_scripts/os_$(OPT_OS).mk include $(GFXLIB)/tools/gmake_scripts/compiler_gcc.mk # *** EOF *** diff --git a/boards/base/OSX/example/Makefile b/boards/base/OSX/example/Makefile index d3502528..956608ff 100644 --- a/boards/base/OSX/example/Makefile +++ b/boards/base/OSX/example/Makefile @@ -4,33 +4,39 @@ # Settings # -# See $(GFXLIB)/tools/gmake_scripts/readme.txt for the meaning of these variables -OPT_VERBOSE_COMPILE = no -OPT_GENERATE_LISTINGS = yes -OPT_GENERATE_MAP = yes -OPT_COPY_EXE = no -OPT_NATIVEOS = osx -OPT_OS = osx +# General settings + # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables + OPT_VERBOSE_COMPILE = no + OPT_GENERATE_LISTINGS = yes + OPT_GENERATE_MAP = yes + OPT_COPY_EXE = no + OPT_LINK_OPTIMIZE = yes + OPT_NONSTANDARD_FLAGS = no + OPT_OS = osx -# See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the meaning of these variables -GFXLIB = ../uGFX -GFXBOARD = OSX -#GFXDRIVERS = multiple/uGFXnet -GFXDEMO = modules/gdisp/basics +# uGFX settings + # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables + GFXLIB = ../uGFX + GFXBOARD = OSX + #GFXDRIVERS = multiple/uGFXnet + GFXDEMO = modules/gdisp/basics + +# OSX settings + # See $(GFXLIB)/tools/gmake_scripts/os_osx.mk for the list of variables + OSX_SDK = /Developer/SDKs/MacOSX10.7.sdk + OSX_ARCH = -mmacosx-version-min=10.3 -arch i386 ############################################################################################## # Set these for your project # -OSX_SDK = /Developer/SDKs/MacOSX10.7.sdk -OSX_ARCH = -mmacosx-version-min=10.3 -arch i386 - ARCH = -SRCFLAGS = -m32 -ggdb -O0 -fomit-frame-pointer -Wall -Wextra -Wstrict-prototypes -fverbose-asm -isysroot $(OSX_SDK) $(OSX_ARCH) +SRCFLAGS = -ggdb -O0 +SRCFLAGS+= -m32 CFLAGS = CXXFLAGS = ASFLAGS = -LDFLAGS = -pthread -Wl,-syslibroot,$(OSX_SDK) $(OSX_ARCH) +LDFLAGS = SRC = DEFS = @@ -43,5 +49,6 @@ LIBPATH = # include $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk +include $(GFXLIB)/tools/gmake_scripts/os_$(OPT_OS).mk include $(GFXLIB)/tools/gmake_scripts/compiler_gcc.mk # *** EOF *** diff --git a/boards/base/Olimex-SAM7EX256-GE8/example/Makefile b/boards/base/Olimex-SAM7EX256-GE8/example/Makefile index e9fdde2d..aa11abad 100644 --- a/boards/base/Olimex-SAM7EX256-GE8/example/Makefile +++ b/boards/base/Olimex-SAM7EX256-GE8/example/Makefile @@ -1,205 +1,64 @@ -############################################################################## -# Build global options -# NOTE: Can be overridden externally. +# Possible Targets: all clean Debug cleanDebug Release cleanRelease + +############################################################################################## +# Settings # -# Compiler options here. -ifeq ($(USE_OPT),) - # If you are using gcc V4.5.1 or older then replace -g with -ggdb -gstabs+ - # For debugging you probably want -O0 rather than -O2 - USE_OPT = -O0 -g -fomit-frame-pointer -mabi=apcs-gnu +# General settings + # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables + OPT_VERBOSE_COMPILE = no + OPT_GENERATE_LISTINGS = yes + OPT_GENERATE_MAP = yes + OPT_COPY_EXE = no + OPT_LINK_OPTIMIZE = yes + OPT_NONSTANDARD_FLAGS = no + OPT_NATIVEOS = chibios + OPT_OS = chibios + +# uGFX settings + # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables + GFXLIB = ../uGFX + GFXBOARD = Olimex-SAM7EX256-GE8 + #GFXDRIVERS = multiple/uGFXnet + GFXDEMO = modules/gdisp/basics + +# ChibiOS settings +ifeq ($(OPT_OS),chibios) + # See $(GFXLIB)/tools/gmake_scripts/os_chibios.mk for the list of variables + CHIBIOS = ../ChibiOS + CHIBIOS_BOARD = OLIMEX_SAM7_EX256 + CHIBIOS_PLATFORM = AT91SAM7 + CHIBIOS_PORT = GCC/ARM/AT91SAM7 + CHIBIOS_DEFS = + #CHIBIOS_LDSCRIPT = $(PORTLD)/AT91SAM7X256.ld + # We define a non standard linker script here just to give us some more stack space + CHIBIOS_LDSCRIPT = linker.ld endif -# C specific options here (added to USE_OPT). -ifeq ($(USE_COPT),) - USE_COPT = -endif - -# C++ specific options here (added to USE_OPT). -ifeq ($(USE_CPPOPT),) - USE_CPPOPT = -fno-rtti -endif - -# Enable this if you want the linker to remove unused code and data -ifeq ($(USE_LINK_GC),) - USE_LINK_GC = yes -endif - -# If enabled, this option allows to compile the application in THUMB mode. -ifeq ($(USE_THUMB),) - USE_THUMB = no -endif - -# Enable this if you want to see the full log while compiling. -ifeq ($(USE_VERBOSE_COMPILE),) - USE_VERBOSE_COMPILE = no -endif - -# -# Build global options -############################################################################## - -############################################################################## -# Project, sources and paths +############################################################################################## +# Set these for your project # -# Define project name here -PROJECT = ch +ARCH = arm-none-eabi- +SRCFLAGS = -ggdb -O0 +SRCFLAGS+= -mcpu=arm7tdmi -mabi=apcs-gnu -mno-thumb-interwork +CFLAGS = +CXXFLAGS = -fno-rtti +ASFLAGS = +LDFLAGS = -mcpu=arm7tdmi -# Imported source files and paths for ChibiOS -CHIBIOS = ../ChibiOS -include $(CHIBIOS)/boards/OLIMEX_SAM7_EX256/board.mk -include $(CHIBIOS)/os/hal/platforms/AT91SAM7/platform.mk -include $(CHIBIOS)/os/hal/hal.mk -include $(CHIBIOS)/os/ports/GCC/ARM/AT91SAM7/port.mk -include $(CHIBIOS)/os/kernel/kernel.mk +SRC = +DEFS = +LIBS = +INCPATH = +LIBPATH = +LDSCRIPT = -# We define a non standard linker script here just to give us some more stack space -# LDSCRIPT= $(PORTLD)/AT91SAM7X256.ld -LDSCRIPT= linker.ld - -# Imported source files and paths for uGFX -GFXLIB = ../uGFX -include $(GFXLIB)/gfx.mk -include $(GFXLIB)/boards/base/Olimex-SAM7EX256-GE8/board.mk - -# Where is our source code - alter these for your project. -# Either just include the demo makefile or add your own definitions -include $(GFXLIB)/demos/modules/gdisp/basics/demo.mk -#MYFILES = my-project-directory -#MYCSRC = $(MYFILES)/main.c -#MYDEFS = - -# C sources that can be compiled in ARM or THUMB mode depending on the global -# setting. -CSRC = $(PORTSRC) \ - $(KERNSRC) \ - $(TESTSRC) \ - $(HALSRC) \ - $(PLATFORMSRC) \ - $(BOARDSRC) \ - $(GFXSRC) \ - $(MYCSRC) - -# C++ sources that can be compiled in ARM or THUMB mode depending on the global -# setting. -CPPSRC = - -# C sources to be compiled in ARM mode regardless of the global setting. -# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler -# option that results in lower performance and larger code size. -ACSRC = - -# C++ sources to be compiled in ARM mode regardless of the global setting. -# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler -# option that results in lower performance and larger code size. -ACPPSRC = - -# C sources to be compiled in THUMB mode regardless of the global setting. -# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler -# option that results in lower performance and larger code size. -TCSRC = - -# C sources to be compiled in THUMB mode regardless of the global setting. -# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler -# option that results in lower performance and larger code size. -TCPPSRC = - -# List ASM source files here -ASMSRC = $(PORTASM) - -INCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \ - $(HALINC) $(PLATFORMINC) $(BOARDINC) \ - $(GFXINC) \ - $(MYFILES) - -# -# Project, sources and paths -############################################################################## - -############################################################################## -# Compiler settings +############################################################################################## +# These should be at the end # -MCU = arm7tdmi - -#TRGT = arm-elf- -TRGT = arm-none-eabi- -CC = $(TRGT)gcc -CPPC = $(TRGT)g++ -# Enable loading with g++ only if you need C++ runtime support. -# NOTE: You can use C++ even without C++ support if you are careful. C++ -# runtime support makes code size explode. -# If you are using gcc V4.5.1 or older then add -ggdb -gstabs+ to the LD line -LD = $(TRGT)gcc -#LD = $(TRGT)g++ -CP = $(TRGT)objcopy -AS = $(TRGT)gcc -x assembler-with-cpp -OD = $(TRGT)objdump -SZ = $(TRGT)size -HEX = $(CP) -O ihex -BIN = $(CP) -O binary - -# ARM-specific options here -AOPT = - -# THUMB-specific options here -TOPT = -mthumb -DTHUMB - -# Define C warning options here -CWARN = -Wall -Wextra -Wstrict-prototypes - -# Define C++ warning options here -CPPWARN = -Wall -Wextra - -# -# Compiler settings -############################################################################## - -############################################################################## -# Start of default section -# - -# List all default C defines here, like -D_DEBUG=1 -DDEFS = $(GFXDEFS) - -# List all default ASM defines here, like -D_DEBUG=1 -DADEFS = - -# List all default directories to look for include files here -DINCDIR = - -# List the default directory to look for the libraries here -DLIBDIR = - -# List all default libraries here -DLIBS = - -# -# End of default section -############################################################################## - -############################################################################## -# Start of user section -# - -# List all user C define here, like -D_DEBUG=1 -UDEFS = - -# Define ASM defines here -UADEFS = - -# List all user directories here -UINCDIR = - -# List the user directory to look for the libraries here -ULIBDIR = - -# List all user libraries here -ULIBS = - -# -# End of user defines -############################################################################## - -include $(CHIBIOS)/os/ports/GCC/ARM/rules.mk +include $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk +include $(GFXLIB)/tools/gmake_scripts/os_$(OPT_OS).mk +include $(GFXLIB)/tools/gmake_scripts/compiler_gcc.mk +# *** EOF *** diff --git a/boards/base/Win32/example/Makefile b/boards/base/Win32/example/Makefile index 502cf1ac..4bf6c603 100644 --- a/boards/base/Win32/example/Makefile +++ b/boards/base/Win32/example/Makefile @@ -4,33 +4,39 @@ # Settings # -# See $(GFXLIB)/tools/gmake_scripts/readme.txt for the meaning of these variables -OPT_VERBOSE_COMPILE = no -OPT_GENERATE_LISTINGS = yes -OPT_GENERATE_MAP = yes -OPT_COPY_EXE = no -OPT_NATIVEOS = win32 -OPT_OS = win32 +# General settings + # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables + OPT_VERBOSE_COMPILE = no + OPT_GENERATE_LISTINGS = yes + OPT_GENERATE_MAP = yes + OPT_COPY_EXE = no + OPT_LINK_OPTIMIZE = yes + OPT_NONSTANDARD_FLAGS = no + # For Win32 this variable can be set to "win32" (native win32 api) or "win32.chibios" (ChibiOS simulator). + OPT_OS = win32 -# See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the meaning of these variables -GFXLIB = ../uGFX -GFXBOARD = Win32 -#GFXDRIVERS = multiple/uGFXnet -GFXDEMO = modules/gdisp/basics +# uGFX settings + # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables + GFXLIB = ../uGFX + GFXBOARD = Win32 + #GFXDRIVERS = multiple/uGFXnet + GFXDEMO = modules/gdisp/basics -# Win32 - ChibiOS simulator -ifeq ($(OPT_OS),chibios) - # Required: Location of the ChibiOS code - CHIBIOS = ../ChibiOS +# ChibiOS settings +ifeq ($(OPT_OS),win32.chibios) + # See $(GFXLIB)/tools/gmake_scripts/os_win32.chibios.mk for the list of variables + CHIBIOS = ../ChibiOS endif +# Win32 settings + # See $(GFXLIB)/tools/gmake_scripts/os_win32.mk for the list of variables ############################################################################################## # Set these for your project # ARCH = i686-pc-mingw32- -SRCFLAGS = -ggdb -O0 -fomit-frame-pointer -Wall -Wextra -Wstrict-prototypes -fverbose-asm +SRCFLAGS = -ggdb -O0 CFLAGS = CXXFLAGS = ASFLAGS = @@ -42,32 +48,11 @@ LIBS = INCPATH = LIBPATH = -############################################################################################## -# Optional: Win32 - ChibiOS Simulator -# - -ifeq ($(OPT_OS),chibios) - include $(CHIBIOS)/boards/simulator/board.mk - include $(CHIBIOS)/os/hal/hal.mk - include $(CHIBIOS)/os/hal/platforms/Win32/platform.mk - include $(CHIBIOS)/os/ports/GCC/SIMIA32/port.mk - include $(CHIBIOS)/os/kernel/kernel.mk - DEFS += SIMULATOR SHELL_USE_IPRINTF=FALSE - INCPATH += $(PORTINC) $(KERNINC) $(TESTINC) \ - $(HALINC) $(PLATFORMINC) $(BOARDINC) - # $(CHIBIOS)/os/various - SRC += $(PORTSRC) \ - $(KERNSRC) \ - $(TESTSRC) \ - $(HALSRC) \ - $(PLATFORMSRC) \ - $(BOARDSRC) -endif - ############################################################################################## # These should be at the end # include $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk +include $(GFXLIB)/tools/gmake_scripts/os_$(OPT_OS).mk include $(GFXLIB)/tools/gmake_scripts/compiler_gcc.mk # *** EOF *** diff --git a/drivers/multiple/uGFXnet/driver.mk b/drivers/multiple/uGFXnet/driver.mk index a579a659..f0bd64d5 100644 --- a/drivers/multiple/uGFXnet/driver.mk +++ b/drivers/multiple/uGFXnet/driver.mk @@ -1,6 +1,6 @@ GFXINC += $(GFXLIB)/drivers/multiple/uGFXnet GFXSRC += $(GFXLIB)/drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c -ifeq ($(OPT_NATIVEOS),win32) +ifeq ($(basename $(OPT_OS)),win32) GFXLIBS += ws2_32 endif diff --git a/tools/gmake_scripts/compiler_gcc.mk b/tools/gmake_scripts/compiler_gcc.mk index 0e5b8098..cb3a3e2b 100644 --- a/tools/gmake_scripts/compiler_gcc.mk +++ b/tools/gmake_scripts/compiler_gcc.mk @@ -13,9 +13,18 @@ endif ifeq ($(XLD),) XLD = $(ARCH)gcc endif +ifeq ($(XOC),) + XOC = $(ARCH)objcopy +endif +ifeq ($(XOD),) + XOD = $(ARCH)objdump +endif # Default project name is the project directory name ifeq ($(PROJECT),) + ifneq ($(firstword $(abspath $(firstword $(MAKEFILE_LIST)))),$(lastword $(abspath $(firstword $(MAKEFILE_LIST))))) + $(error Your directory contains spaces. Gmake barfs at that. Please define PROJECT) + endif PROJECT := $(notdir $(patsubst %/,%,$(dir $(abspath $(firstword $(MAKEFILE_LIST)))))) endif @@ -45,24 +54,50 @@ SRCFILE = $< OBJFILE = $@ LSTFILE = $(@:.o=.lst) MAPFILE = $(BUILDDIR)/$(PROJECT).map -ifeq ($(OPT_NATIVEOS),win32) +EXEFILE = +ifeq ($(basename $(OPT_OS)),win32) EXEFILE = $(BUILDDIR)/$(PROJECT).exe -else + TARGETS = $(EXEFILE) +endif +ifeq ($(basename $(OPT_OS)),linux) EXEFILE = $(BUILDDIR)/$(PROJECT) + TARGETS = $(EXEFILE) +endif +ifeq ($(basename $(OPT_OS)),osx) + EXEFILE = $(BUILDDIR)/$(PROJECT) + TARGETS = $(EXEFILE) +endif +ifeq ($(EXEFILE),) + LDFLAGS += -nostartfiles + EXEFILE = $(BUILDDIR)/$(PROJECT).elf + TARGETS = $(EXEFILE) $(BUILDDIR)/$(PROJECT).hex $(BUILDDIR)/$(PROJECT).bin $(BUILDDIR)/$(PROJECT).dmp endif SRCFLAGS += -I. $(patsubst %,-I%,$(INCPATH)) $(patsubst %,-D%,$(patsubst -D%,%,$(DEFS))) LDFLAGS += $(patsubst %,-L%,$(LIBPATH)) $(patsubst %,-l%,$(patsubst -l%,%,$(LIBS))) OBJS = $(addprefix $(OBJDIR)/,$(subst ../,_dot_dot/,$(addsuffix .o,$(basename $(SRC))))) +ifneq ($(OPT_NONSTANDARD_FLAGS),yes) + SRCFLAGS += -fomit-frame-pointer -Wall -Wextra -Wstrict-prototypes -fverbose-asm +endif +ifeq ($(OPT_LINK_OPTIMIZE),yes) + SRCFLAGS += -ffunction-sections -fdata-sections +endif ifeq ($(OPT_GENERATE_MAP),yes) - LDFLAGS += -Wl,-Map=$(MAPFILE),--cref,--no-warn-mismatch + ifeq ($(OPT_LINK_OPTIMIZE),yes) + LDFLAGS += -Wl,-Map=$(MAPFILE),--cref,--no-warn-mismatch,--gc-sections + else + LDFLAGS += -Wl,-Map=$(MAPFILE),--cref,--no-warn-mismatch + endif endif ifeq ($(OPT_GENERATE_LISTINGS),yes) CFLAGS += -Wa,-alms=$(LSTFILE) CXXFLAGS += -Wa,-alms=$(LSTFILE) ASFLAGS += -Wa,-amhls=$(LSTFILE) endif +ifneq ($(LDSCRIPT),) + LDFLAGS += -T$(LDSCRIPT) +endif # Generate dependency information SRCFLAGS += -MMD -MP -MF $(DEPDIR)/$(@F).d @@ -76,7 +111,7 @@ SRCFLAGS += -MMD -MP -MF $(DEPDIR)/$(@F).d Debug Release: all cleanDebug cleanRelease: clean -all: builddirs fakefile.o $(EXEFILE) +all: builddirs fakefile.o $(TARGETS) builddirs: @mkdir -p $(BUILDDIR) @@ -140,7 +175,41 @@ else @$(XLD) $(OBJS) $(LDFLAGS) -o $@ endif ifeq ($(OPT_COPY_EXE),yes) - @cp $(EXEFILE) . + @cp $@ . +endif + +%.hex: %.elf $(LDSCRIPT) +ifeq ($(OPT_VERBOSE_COMPILE),yes) + $(XOC) -O ihex $< $@ +else + @echo Creating $@ + @$(XOC) -O ihex $< $@ +endif +ifeq ($(OPT_COPY_EXE),yes) + @cp $@ . +endif + +%.bin: %.elf $(LDSCRIPT) +ifeq ($(USE_VERBOSE_COMPILE),yes) + $(XOC) -O binary $< $@ +else + @echo Creating $@ + @$(XOC) -O binary $< $@ +endif +ifeq ($(OPT_COPY_EXE),yes) + @cp $@ . +endif + +%.dmp: %.elf $(LDSCRIPT) +ifeq ($(USE_VERBOSE_COMPILE),yes) + $(XOD) -x --syms $< > $@ +else + @echo Creating $@ + @$(XOD) -x --syms $< > $@ + @echo Done +endif +ifeq ($(OPT_COPY_EXE),yes) + @cp $@ . endif gcov: diff --git a/tools/gmake_scripts/os_chibios.mk b/tools/gmake_scripts/os_chibios.mk new file mode 100644 index 00000000..8165c269 --- /dev/null +++ b/tools/gmake_scripts/os_chibios.mk @@ -0,0 +1,30 @@ +# See readme.txt for the make API + +# Requirements: +# +# CHIBIOS: The location of the ChibiOS code eg CHIBIOS=../chibios +# CHIBIOS_BOARD The name of the ChibiOS board eg CHIBIOS_BOARD=OLIMEX_SAM7_EX256 +# CHIBIOS_PLATFORM The name of the ChibiOS platform eg CHIBIOS_PLATFORM=AT91SAM7 +# CHIBIOS_PORT The name of the ChibiOS port eg CHIBIOS_PORT=GCC/ARM/AT91SAM7 +# + +# Optional: +# +# CHIBIOS_LDSCRIPT The name of the loader script eg CHIBIOS_LDSCRIPT=$(PORTLD)/AT91SAM7X256.ld +# + +include $(CHIBIOS)/boards/$(CHIBIOS_BOARD)/board.mk +include $(CHIBIOS)/os/hal/platforms/$(CHIBIOS_PLATFORM)/platform.mk +include $(CHIBIOS)/os/hal/hal.mk +include $(CHIBIOS)/os/ports/$(CHIBIOS_PORT)/port.mk +include $(CHIBIOS)/os/kernel/kernel.mk +LDSCRIPT= $(CHIBIOS_LDSCRIPT) +INCPATH += $(PORTINC) $(KERNINC) $(TESTINC) \ + $(HALINC) $(PLATFORMINC) $(BOARDINC) +SRC += $(PORTSRC) \ + $(KERNSRC) \ + $(TESTSRC) \ + $(HALSRC) \ + $(PLATFORMSRC) \ + $(BOARDSRC) \ + $(PORTASM) diff --git a/tools/gmake_scripts/os_linux.mk b/tools/gmake_scripts/os_linux.mk new file mode 100644 index 00000000..39610ca4 --- /dev/null +++ b/tools/gmake_scripts/os_linux.mk @@ -0,0 +1,8 @@ +# See readme.txt for the make API + +# Requirements: +# +# NONE +# + +LDFLAGS += -pthread diff --git a/tools/gmake_scripts/os_osx.mk b/tools/gmake_scripts/os_osx.mk new file mode 100644 index 00000000..8b008f4b --- /dev/null +++ b/tools/gmake_scripts/os_osx.mk @@ -0,0 +1,10 @@ +# See readme.txt for the make API + +# Requirements: +# +# OSX_SDK The location of the SDK eg. OSX_SDK = /Developer/SDKs/MacOSX10.7.sdk +# OSX_ARCH The architecture flags eg. OSX_ARCH = -mmacosx-version-min=10.3 -arch i386 +# + +SRCFLAGS += -isysroot $(OSX_SDK) $(OSX_ARCH) +LDFLAGS += -pthread -Wl,-syslibroot,$(OSX_SDK) $(OSX_ARCH) diff --git a/tools/gmake_scripts/os_win32.chibios.mk b/tools/gmake_scripts/os_win32.chibios.mk new file mode 100644 index 00000000..5a804c64 --- /dev/null +++ b/tools/gmake_scripts/os_win32.chibios.mk @@ -0,0 +1,18 @@ +# See readme.txt for the make API + +# Requirements: +# +# CHIBIOS: The location of the ChibiOS code eg CHIBIOS=../chibios +# + +# Optional: +# + +CHIBIOS_BOARD = simulator +CHIBIOS_PLATFORM = Win32 +CHIBIOS_PORT = GCC/SIMIA32 + +DEFS += SIMULATOR SHELL_USE_IPRINTF=FALSE + +include $(GFXLIB)/tools/gmake_scripts/os_chibios.mk +include $(GFXLIB)/tools/gmake_scripts/os_win32.mk diff --git a/tools/gmake_scripts/os_win32.mk b/tools/gmake_scripts/os_win32.mk new file mode 100644 index 00000000..1b33ad85 --- /dev/null +++ b/tools/gmake_scripts/os_win32.mk @@ -0,0 +1,6 @@ +# See readme.txt for the make API + +# Requirements: +# +# NONE +# diff --git a/tools/gmake_scripts/readme.txt b/tools/gmake_scripts/readme.txt index d7389e1c..004c1495 100644 --- a/tools/gmake_scripts/readme.txt +++ b/tools/gmake_scripts/readme.txt @@ -12,8 +12,9 @@ OPT_VERBOSE_COMPILE=no|yes - Turn on full compile messages - default no OPT_GENERATE_LISTINGS=no|yes - Generate listing files - default no OPT_GENERATE_MAP=no|yes - Generate a map file - default no OPT_COPY_EXE=no|yes - Copy the final program to the local project directory - default no -OPT_NATIVEOS=win32|linux|osx|chibios|freertos|ecos|raw32|rawrtos - Mandatory: The real operating system of the machine -OPT_OS=win32|linux|osx|chibios|freertos|ecos|raw32|rawrtos - Mandatory: Should be the same as OPT_NATIVEOS except when running an OS simulator +OPT_NONSTANDARD_FLAGS=no - Turn off adding the standard compiler language flags - default no +OPT_LINK_OPTIMIZE=no - Remove unused code/data during link - default no +OPT_OS=win32|win32.chibios|linux|osx|chibios|freertos|ecos|raw32|rawrtos - Mandatory: The operating system BUILDDIR - Build Directory - default is ".build" or "bin/Debug" or "bin/Release" depending on the target PROJECT - Project Name - default is the name of the project directory @@ -23,6 +24,8 @@ XCC - C compiler - default is "$(ARCH)gcc" XCXX - C++ compiler - default is "$(ARCH)g++" XAS - Assembler - default is "$(ARCH)gcc -x assembler-with-cpp" XLD - Linker - default is "$(ARCH)gcc" +XOC - Object Copy - default is "$(ARCH)objcopy" +XOD - Object Dump - default is "$(ARCH)objdump" SRCFLAGS - Compiler defines for c, c++ and assembler files - default is "" CFLAGS - C specific compiler defines - default is "" @@ -39,15 +42,7 @@ LIBPATH - List of library include directories - default is "" DEFS - List of preprocessor defines (any -D prefix is ignored) - default is "" LIBS - List of libraries (any -l prefix is ignored) - default is "" SRC - List of c, c++ and assembler source files - default is "" - -Variables for use in variable defintions ----------------------------------------- - -SRCFILE - The original source file -OBJFILE - The output object file -LSTFILE - The listing file -MAPFILE - The map file -EXEFILE - The final project output file +LDSCRIPT - Custom loader script - default is "" Targets ---------------------------- From 5d3ab261c0f994b25013f73b4fd9794d81740da7 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 2 Oct 2014 19:52:28 +1000 Subject: [PATCH 36/87] Add makefile support for absolute paths Add makefile support for cygwin gmake versus mingw gmake Add makefile support for "master" directories eg GFXLIB, CHIBIOS etc --- tools/gmake_scripts/compiler_gcc.mk | 70 +++++++++++++++++++---------- tools/gmake_scripts/library_ugfx.mk | 1 + tools/gmake_scripts/os_chibios.mk | 2 + tools/gmake_scripts/readme.txt | 1 + 4 files changed, 50 insertions(+), 24 deletions(-) diff --git a/tools/gmake_scripts/compiler_gcc.mk b/tools/gmake_scripts/compiler_gcc.mk index cb3a3e2b..196e5d5a 100644 --- a/tools/gmake_scripts/compiler_gcc.mk +++ b/tools/gmake_scripts/compiler_gcc.mk @@ -1,5 +1,29 @@ # See readme.txt for the make API +ifeq ($(basename $(OPT_OS)),win32) + # Nasty - must convert all paths into a format make can handle + PATHEXPAND := ARCH XCC XCXX XAS XLD XOC XOD PROJECT BUILDDIR SRC DEFS LIBS INCPATH LIBPATH $(PATHLIST) + + # First convert \'s to /'s + $(foreach var,$(PATHEXPAND),$(eval $(var):=$$(subst \,/,$($(var))))) + + # For cygwin gmake - need to convert all absolute paths (mingw gmake doesn't need this) + ifneq ($(findstring cygdrive,$(PATH)),) + DRIVELETTERS := a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z + $(foreach drv,$(DRIVELETTERS),$(foreach var,$(PATHEXPAND),$(eval $(var):=$$(patsubst $(drv):%,/cygdrive/$(drv)%,$($(var)))))) + endif +endif + +# Path resolution - Functions to convert a source path to a object path and visa-versa +src_obj_fn := $$(1) +obj_src_fn := $$(1) +$(foreach var,$(PATHLIST),$(eval obj_src_fn := $$$$(patsubst $(var)/%,$$$$($(var))/%,$$(obj_src_fn)))) +$(foreach var,$(PATHLIST),$(eval src_obj_fn := $$$$(patsubst $$$$($(var))/%,$(var)/%,$$(src_obj_fn)))) +src_obj_fn := $$(subst :,_drv_drv_,$$(subst ../,_dot_dot/,$(src_obj_fn))) +obj_src_fn := $$(subst _drv_drv_,:,$$(subst _dot_dot/,../,$(obj_src_fn))) +$(eval src_obj=$(src_obj_fn)) +$(eval obj_src=$(obj_src_fn)) + # Add ARCH to each of the compiler programs ifeq ($(XCC),) XCC = $(ARCH)gcc @@ -23,12 +47,12 @@ endif # Default project name is the project directory name ifeq ($(PROJECT),) ifneq ($(firstword $(abspath $(firstword $(MAKEFILE_LIST)))),$(lastword $(abspath $(firstword $(MAKEFILE_LIST))))) - $(error Your directory contains spaces. Gmake barfs at that. Please define PROJECT) + $(error Your directory contains spaces. Gmake barfs at that. Please define PROJECT) endif PROJECT := $(notdir $(patsubst %/,%,$(dir $(abspath $(firstword $(MAKEFILE_LIST)))))) endif -# Output directory and files +# Output directories ifeq ($(BUILDDIR),) ifeq ($(MAKECMDGOALS),Debug) BUILDDIR = bin/Debug @@ -46,13 +70,10 @@ ifeq ($(BUILDDIR),) BUILDDIR = .build endif endif - OBJDIR = $(BUILDDIR)/obj DEPDIR = $(BUILDDIR)/dep -SRCFILE = $< -OBJFILE = $@ -LSTFILE = $(@:.o=.lst) +# Output files MAPFILE = $(BUILDDIR)/$(PROJECT).map EXEFILE = ifeq ($(basename $(OPT_OS)),win32) @@ -73,10 +94,12 @@ ifeq ($(EXEFILE),) TARGETS = $(EXEFILE) $(BUILDDIR)/$(PROJECT).hex $(BUILDDIR)/$(PROJECT).bin $(BUILDDIR)/$(PROJECT).dmp endif +# Combine all our compiler arguments SRCFLAGS += -I. $(patsubst %,-I%,$(INCPATH)) $(patsubst %,-D%,$(patsubst -D%,%,$(DEFS))) LDFLAGS += $(patsubst %,-L%,$(LIBPATH)) $(patsubst %,-l%,$(patsubst -l%,%,$(LIBS))) -OBJS = $(addprefix $(OBJDIR)/,$(subst ../,_dot_dot/,$(addsuffix .o,$(basename $(SRC))))) +OBJS = $(addprefix $(OBJDIR)/,$(call src_obj,$(addsuffix .o,$(basename $(SRC))))) +# Handle make API options that affect compiler arguments ifneq ($(OPT_NONSTANDARD_FLAGS),yes) SRCFLAGS += -fomit-frame-pointer -Wall -Wextra -Wstrict-prototypes -fverbose-asm endif @@ -91,9 +114,9 @@ ifeq ($(OPT_GENERATE_MAP),yes) endif endif ifeq ($(OPT_GENERATE_LISTINGS),yes) - CFLAGS += -Wa,-alms=$(LSTFILE) - CXXFLAGS += -Wa,-alms=$(LSTFILE) - ASFLAGS += -Wa,-amhls=$(LSTFILE) + CFLAGS += -Wa,-alms=$(@:.o=.lst) + CXXFLAGS += -Wa,-alms=$(@:.o=.lst) + ASFLAGS += -Wa,-amhls=$(@:.o=.lst) endif ifneq ($(LDSCRIPT),) LDFLAGS += -T$(LDSCRIPT) @@ -102,10 +125,7 @@ endif # Generate dependency information SRCFLAGS += -MMD -MP -MF $(DEPDIR)/$(@F).d -# -# makefile rules -# - +# Targets .PHONY: builddirs fakefile.o all clean Debug Release cleanDebug cleanRelease Debug Release: all @@ -124,8 +144,10 @@ ifneq ($(OPT_VERBOSE_COMPILE),yes) @echo endif +# Implicit Rules + .SECONDEXPANSION: -$(OBJDIR)/%.o : $$(subst _dot_dot/,../,%.c) +$(OBJDIR)/%.o : $$(call obj_src,%.c) @mkdir -p $(dir $@) ifeq ($(OPT_VERBOSE_COMPILE),yes) @echo @@ -135,7 +157,7 @@ else @$(XCC) -c $(CPPFLAGS) $(CFLAGS) $(SRCFLAGS) $< -o $@ endif -$(OBJDIR)/%.o : $$(subst _dot_dot/,../,%.cpp) +$(OBJDIR)/%.o : $$(call obj_src,%.cpp) @mkdir -p $(dir $@) ifeq ($(OPT_VERBOSE_COMPILE),yes) @echo @@ -145,7 +167,7 @@ else @$(XCXX) -c $(CPPFLAGS) $(CXXFLAGS) $(SRCFLAGS) $< -o $@ endif -$(OBJDIR)/%.o : $$(subst _dot_dot/,../,%.c++) +$(OBJDIR)/%.o : $$(call obj_src,%.c++) @mkdir -p $(dir $@) ifeq ($(OPT_VERBOSE_COMPILE),yes) @echo @@ -155,7 +177,7 @@ else @$(XCXX) -c $(CPPFLAGS) $(CXXFLAGS) $(SRCFLAGS) $< -o $@ endif -$(OBJDIR)/%.o : $$(subst _dot_dot/,../,%.s) +$(OBJDIR)/%.o : $$(call obj_src,%.s) @mkdir -p $(dir $@) ifeq ($(OPT_VERBOSE_COMPILE),yes) @echo @@ -165,7 +187,7 @@ else @$(XAS) -c $(CPPFLAGS) $(ASFLAGS) $(SRCFLAGS) $< -o $@ endif -$(EXEFILE): $(OBJS) +$(EXEFILE): $(OBJS) $(LDSCRIPT) @mkdir -p $(dir $@) ifeq ($(OPT_VERBOSE_COMPILE),yes) @echo @@ -178,7 +200,7 @@ ifeq ($(OPT_COPY_EXE),yes) @cp $@ . endif -%.hex: %.elf $(LDSCRIPT) +%.hex: %.elf ifeq ($(OPT_VERBOSE_COMPILE),yes) $(XOC) -O ihex $< $@ else @@ -189,7 +211,7 @@ ifeq ($(OPT_COPY_EXE),yes) @cp $@ . endif -%.bin: %.elf $(LDSCRIPT) +%.bin: %.elf ifeq ($(USE_VERBOSE_COMPILE),yes) $(XOC) -O binary $< $@ else @@ -200,7 +222,7 @@ ifeq ($(OPT_COPY_EXE),yes) @cp $@ . endif -%.dmp: %.elf $(LDSCRIPT) +%.dmp: %.elf ifeq ($(USE_VERBOSE_COMPILE),yes) $(XOD) -x --syms $< > $@ else @@ -212,16 +234,16 @@ ifeq ($(OPT_COPY_EXE),yes) @cp $@ . endif +# Goodness knows why we would want this. gcov: -mkdir gcov $(COV) -u $(subst /,\,$(SRC)) -mv *.gcov ./gcov -# # Include the dependency files, should be the last of the makefile except for clean -# -include $(shell mkdir -p $(DEPDIR) 2>/dev/null) $(wildcard $(DEPDIR)/*) +# Clean clean: -rm -fR $(BUILDDIR) diff --git a/tools/gmake_scripts/library_ugfx.mk b/tools/gmake_scripts/library_ugfx.mk index 7dbf9d99..24c501fe 100644 --- a/tools/gmake_scripts/library_ugfx.mk +++ b/tools/gmake_scripts/library_ugfx.mk @@ -12,6 +12,7 @@ # GFXDEMO: Compile a uGFX standard demo? If blank you need to include your own project files. eg GFXDEMO=modules/gwin/widgets # +PATHLIST += GFXLIB include $(GFXLIB)/gfx.mk SRC += $(GFXSRC) diff --git a/tools/gmake_scripts/os_chibios.mk b/tools/gmake_scripts/os_chibios.mk index 8165c269..a81c9803 100644 --- a/tools/gmake_scripts/os_chibios.mk +++ b/tools/gmake_scripts/os_chibios.mk @@ -13,6 +13,8 @@ # CHIBIOS_LDSCRIPT The name of the loader script eg CHIBIOS_LDSCRIPT=$(PORTLD)/AT91SAM7X256.ld # +PATHLIST += CHIBIOS + include $(CHIBIOS)/boards/$(CHIBIOS_BOARD)/board.mk include $(CHIBIOS)/os/hal/platforms/$(CHIBIOS_PLATFORM)/platform.mk include $(CHIBIOS)/os/hal/hal.mk diff --git a/tools/gmake_scripts/readme.txt b/tools/gmake_scripts/readme.txt index 004c1495..979ca364 100644 --- a/tools/gmake_scripts/readme.txt +++ b/tools/gmake_scripts/readme.txt @@ -18,6 +18,7 @@ OPT_OS=win32|win32.chibios|linux|osx|chibios|freertos|ecos|raw32|rawrtos - Manda BUILDDIR - Build Directory - default is ".build" or "bin/Debug" or "bin/Release" depending on the target PROJECT - Project Name - default is the name of the project directory +PATHLIST - A list of variable names of "master" paths that contain source and other objects of interest - default is "" ARCH - Architecture - default is "" XCC - C compiler - default is "$(ARCH)gcc" From 2151935b3a89fdf357181f6f1161c1c0c1dde1f0 Mon Sep 17 00:00:00 2001 From: inmarket Date: Sat, 4 Oct 2014 17:12:33 +1000 Subject: [PATCH 37/87] Update to makefiles to support ChibiOS v3, making ARM thumb targets, CPU specific flags etc Also put license in the gmake master scripts. --- .../base/Linux-Framebuffer/example/Makefile | 4 +- boards/base/Linux/example/Makefile | 4 +- .../example_chibios_2.x/Makefile | 282 ++++-------------- .../example_chibios_3.x/Makefile | 279 ++++------------- boards/base/OSX/example/Makefile | 4 +- .../Olimex-SAM7EX256-GE8/example/Makefile | 14 +- .../Olimex-SAM7EX256-GE8/example/readme.txt | 2 - boards/base/Win32/example/Makefile | 1 + boards/base/Win32/example/readme.txt | 5 +- tools/gmake_scripts/compiler_gcc.mk | 226 +++++++++----- tools/gmake_scripts/library_ugfx.mk | 7 + tools/gmake_scripts/os_chibios.mk | 50 +++- tools/gmake_scripts/os_linux.mk | 7 + tools/gmake_scripts/os_osx.mk | 10 +- tools/gmake_scripts/os_win32.chibios.mk | 7 + tools/gmake_scripts/os_win32.mk | 8 + tools/gmake_scripts/readme.txt | 12 + 17 files changed, 377 insertions(+), 545 deletions(-) diff --git a/boards/base/Linux-Framebuffer/example/Makefile b/boards/base/Linux-Framebuffer/example/Makefile index 76b2022a..fb0c1b7a 100644 --- a/boards/base/Linux-Framebuffer/example/Makefile +++ b/boards/base/Linux-Framebuffer/example/Makefile @@ -13,6 +13,8 @@ OPT_LINK_OPTIMIZE = yes OPT_NONSTANDARD_FLAGS = no OPT_OS = linux + # Change this next setting (or add the explicit compiler flags) if you are not compiling for x86 linux + OPT_CPU = x86 # uGFX settings # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables @@ -30,13 +32,13 @@ ARCH = SRCFLAGS = -ggdb -O0 -SRCFLAGS+= -m32 CFLAGS = CXXFLAGS = ASFLAGS = LDFLAGS = SRC = +OBJS = DEFS = LIBS = INCPATH = diff --git a/boards/base/Linux/example/Makefile b/boards/base/Linux/example/Makefile index d6402c8a..3d6d3d60 100644 --- a/boards/base/Linux/example/Makefile +++ b/boards/base/Linux/example/Makefile @@ -13,6 +13,8 @@ OPT_LINK_OPTIMIZE = yes OPT_NONSTANDARD_FLAGS = no OPT_OS = linux + # Change this next setting (or add the explicit compiler flags) if you are not compiling for x86 linux + OPT_CPU = x86 # uGFX settings # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables @@ -30,13 +32,13 @@ ARCH = SRCFLAGS = -ggdb -O0 -SRCFLAGS+= -m32 CFLAGS = CXXFLAGS = ASFLAGS = LDFLAGS = SRC = +OBJS = DEFS = LIBS = INCPATH = diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/Makefile b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/Makefile index 7b982d80..ac483689 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/Makefile +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/Makefile @@ -1,236 +1,66 @@ -############################################################################## -# Build global options -# NOTE: Can be overridden externally. +# Possible Targets: all clean Debug cleanDebug Release cleanRelease + +############################################################################################## +# Settings # -# Compiler options here. -ifeq ($(USE_OPT),) - # Replace -O0 with -O2 for a production build. -O2 just messes with the debugger. - USE_OPT = -O0 -g -fomit-frame-pointer -falign-functions=16 +# General settings + # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables + OPT_VERBOSE_COMPILE = no + OPT_GENERATE_LISTINGS = yes + OPT_GENERATE_MAP = yes + OPT_COPY_EXE = no + OPT_LINK_OPTIMIZE = yes + OPT_NONSTANDARD_FLAGS = no + OPT_NATIVEOS = chibios + OPT_OS = chibios + OPT_THUMB = yes + OPT_CPU = stm32m4 + +# uGFX settings + # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables + GFXLIB = ../uGFX + GFXBOARD = Mikromedia-STM32-M4-ILI9341 + #GFXDRIVERS = multiple/uGFXnet + GFXDEMO = modules/gdisp/basics + +# ChibiOS settings +ifeq ($(OPT_OS),chibios) + # See $(GFXLIB)/tools/gmake_scripts/os_chibios.mk for the list of variables + CHIBIOS = ../ChibiOS + CHIBIOS_BOARD = + CHIBIOS_PLATFORM = STM32F4xx + CHIBIOS_PORT = GCC/ARMCMx/STM32F4xx + CHIBIOS_DEFS = + CHIBIOS_LDSCRIPT = STM32F407xG.ld + # We define a non standard board script as this is not a standard ChibiOS supported board + include $(GFXLIB)/boards/base/Mikromedia-STM32-M4-ILI9341/ChibiOS_Board/board.mk endif -# C specific options here (added to USE_OPT). -ifeq ($(USE_COPT),) - USE_COPT = -endif - -# C++ specific options here (added to USE_OPT). -ifeq ($(USE_CPPOPT),) - USE_CPPOPT = -fno-rtti -endif - -# Enable this if you want the linker to remove unused code and data -ifeq ($(USE_LINK_GC),) - USE_LINK_GC = yes -endif - -# If enabled, this option allows to compile the application in THUMB mode. -ifeq ($(USE_THUMB),) - USE_THUMB = yes -endif - -# Enable this if you want to see the full log while compiling. -ifeq ($(USE_VERBOSE_COMPILE),) - USE_VERBOSE_COMPILE = no -endif - -# -# Build global options -############################################################################## - -############################################################################## -# Architecture or project specific options +############################################################################################## +# Set these for your project # -# Enables the use of FPU on Cortex-M4. -# Enable this if you really want to use the STM FWLib. -ifeq ($(USE_FPU),) - USE_FPU = no -endif +ARCH = arm-none-eabi- +SRCFLAGS = -ggdb -O0 +CFLAGS = +CXXFLAGS = -fno-rtti +ASFLAGS = +LDFLAGS = -# Enable this if you really want to use the STM FWLib. -ifeq ($(USE_FWLIB),) - USE_FWLIB = no -endif +SRC = +OBJS = +DEFS = +LIBS = +INCPATH = +LIBPATH = +LDSCRIPT = -# -# Architecture or project specific options -############################################################################## - -############################################################################## -# Project, sources and paths +############################################################################################## +# These should be at the end # -SW = .. - -# Define project name here -PROJECT = ch - -# Imported source files and paths -CHIBIOS = ../ChibiOS -#include $(CHIBIOS)/boards/MIKROMEDIA_STM32_M4/board.mk # Not a standard ChibiOS supported board -include $(CHIBIOS)/os/hal/platforms/STM32F4xx/platform.mk -include $(CHIBIOS)/os/hal/hal.mk -include $(CHIBIOS)/os/ports/GCC/ARMCMx/STM32F4xx/port.mk -include $(CHIBIOS)/os/kernel/kernel.mk -LDSCRIPT= $(PORTLD)/STM32F407xG.ld - -# Imported source files and paths for uGFX -GFXLIB = ../ugfx -include $(GFXLIB)/boards/base/Mikromedia-STM32-M4-ILI9341/board.mk -include $(GFXLIB)/boards/base/Mikromedia-STM32-M4-ILI9341/ChibiOS_Board/board.mk # The replacement ChibiOS board files -include $(GFXLIB)/gfx.mk - -# Where is our source code - alter these for your project. -# Either just include the demo makefile or add your own definitions -include $(GFXLIB)/demos/modules/gdisp/basics/demo.mk -#MYFILES = my-project-directory -#MYCSRC = $(MYFILES)/main.c -#MYDEFS = - -# C sources that can be compiled in ARM or THUMB mode depending on the global -# setting. -CSRC = $(PORTSRC) \ - $(KERNSRC) \ - $(TESTSRC) \ - $(HALSRC) \ - $(PLATFORMSRC) \ - $(BOARDSRC) \ - $(GFXSRC) \ - $(MYCSRC) - -# C++ sources that can be compiled in ARM or THUMB mode depending on the global -# setting. -CPPSRC = - -# C sources to be compiled in ARM mode regardless of the global setting. -# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler -# option that results in lower performance and larger code size. -ACSRC = - -# C++ sources to be compiled in ARM mode regardless of the global setting. -# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler -# option that results in lower performance and larger code size. -ACPPSRC = - -# C sources to be compiled in THUMB mode regardless of the global setting. -# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler -# option that results in lower performance and larger code size. -TCSRC = - -# C sources to be compiled in THUMB mode regardless of the global setting. -# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler -# option that results in lower performance and larger code size. -TCPPSRC = - -# List ASM source files here -ASMSRC = $(PORTASM) - -INCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \ - $(HALINC) $(PLATFORMINC) $(BOARDINC) \ - $(GFXINC) \ - $(MYFILES) - -# -# Project, sources and paths -############################################################################## - -############################################################################## -# Compiler settings -# - -MCU = cortex-m4 - -#TRGT = arm-elf- -TRGT = arm-none-eabi- -CC = $(TRGT)gcc -CPPC = $(TRGT)g++ -# Enable loading with g++ only if you need C++ runtime support. -# NOTE: You can use C++ even without C++ support if you are careful. C++ -# runtime support makes code size explode. -LD = $(TRGT)gcc -#LD = $(TRGT)g++ -CP = $(TRGT)objcopy -AS = $(TRGT)gcc -x assembler-with-cpp -OD = $(TRGT)objdump -SZ = $(TRGT)size -HEX = $(CP) -O ihex -BIN = $(CP) -O binary - -# ARM-specific options here -AOPT = - -# THUMB-specific options here -TOPT = -mthumb -DTHUMB - -# Define C warning options here -CWARN = -Wall -Wextra -Wstrict-prototypes - -# Define C++ warning options here -CPPWARN = -Wall -Wextra - -# -# Compiler settings -############################################################################## - -############################################################################## -# Start of default section -# - -# List all default C defines here, like -D_DEBUG=1 -DDEFS = $(GFXDEFS) - -# List all default ASM defines here, like -D_DEBUG=1 -DADEFS = - -# List all default directories to look for include files here -DINCDIR = - -# List the default directory to look for the libraries here -DLIBDIR = - -# List all default libraries here -DLIBS = - -# -# End of default section -############################################################################## - -############################################################################## -# Start of user section -# - -# List all user C define here, like -D_DEBUG=1 -UDEFS = - -# Define ASM defines here -UADEFS = - -# List all user directories here -UINCDIR = - -# List the user directory to look for the libraries here -ULIBDIR = - -# List all user libraries here -ULIBS = - -# -# End of user defines -############################################################################## - -ifeq ($(USE_FPU),yes) - USE_OPT += -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -fsingle-precision-constant - DDEFS += -DCORTEX_USE_FPU=TRUE -else - DDEFS += -DCORTEX_USE_FPU=FALSE -endif - -ifeq ($(USE_FWLIB),yes) - include $(CHIBIOS)/ext/stm32lib/stm32lib.mk - CSRC += $(STM32SRC) - INCDIR += $(STM32INC) - USE_OPT += -DUSE_STDPERIPH_DRIVER -endif - -include $(CHIBIOS)/os/ports/GCC/ARMCMx/rules.mk +include $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk +include $(GFXLIB)/tools/gmake_scripts/os_$(OPT_OS).mk +include $(GFXLIB)/tools/gmake_scripts/compiler_gcc.mk +# *** EOF *** diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/Makefile b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/Makefile index 4f55e0fd..d19c3d28 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/Makefile +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/Makefile @@ -1,53 +1,71 @@ -############################################################################## -# Build global options -# NOTE: Can be overridden externally. +# Possible Targets: all clean Debug cleanDebug Release cleanRelease + +############################################################################################## +# Settings # -# Compiler options here. -ifeq ($(USE_OPT),) - # Replace -O0 with -O2 for a production build. -O2 just messes with the debugger. - USE_OPT = -O0 -g -fomit-frame-pointer -falign-functions=16 +# General settings + # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables + OPT_VERBOSE_COMPILE = no + OPT_GENERATE_LISTINGS = yes + OPT_GENERATE_MAP = yes + OPT_COPY_EXE = no + OPT_LINK_OPTIMIZE = yes + OPT_NONSTANDARD_FLAGS = no + OPT_NATIVEOS = chibios + OPT_OS = chibios + OPT_THUMB = yes + OPT_CPU = stm32m4 + +# uGFX settings + # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables + GFXLIB = ../uGFX + GFXBOARD = Mikromedia-STM32-M4-ILI9341 + #GFXDRIVERS = multiple/uGFXnet + GFXDEMO = modules/gdisp/basics + +# ChibiOS settings +ifeq ($(OPT_OS),chibios) + # See $(GFXLIB)/tools/gmake_scripts/os_chibios.mk for the list of variables + CHIBIOS = ../ChibiOS + CHBIOS_VERSION = 3 + CHIBIOS_BOARD = + CHIBIOS_PLATFORM = STM32/STM32F4xx + CHIBIOS_PORT = ARMCMx/compilers/GCC/mk/port_stm32f4xx + CHIBIOS_DEFS = + CHIBIOS_LDSCRIPT = STM32F407xG.ld + # We define a non standard board script as this is not a standard ChibiOS supported board + include $(GFXLIB)/boards/base/Mikromedia-STM32-M4-ILI9341/ChibiOS_Board/board.mk endif -# C specific options here (added to USE_OPT). -ifeq ($(USE_COPT),) - USE_COPT = -endif - -# C++ specific options here (added to USE_OPT). -ifeq ($(USE_CPPOPT),) - USE_CPPOPT = -fno-rtti -endif - -# Enable this if you want the linker to remove unused code and data -ifeq ($(USE_LINK_GC),) - USE_LINK_GC = yes -endif - -# Linker extra options here. -ifeq ($(USE_LDOPT),) - USE_LDOPT = -endif - -# Enable this if you want link time optimizations (LTO) -ifeq ($(USE_LTO),) - ### disable as can cause segfault - USE_LTO = no -endif - -# If enabled, this option allows to compile the application in THUMB mode. -ifeq ($(USE_THUMB),) - USE_THUMB = yes -endif - -# Enable this if you want to see the full log while compiling. -ifeq ($(USE_VERBOSE_COMPILE),) - USE_VERBOSE_COMPILE = no -endif +############################################################################################## +# Set these for your project # -# Build global options -############################################################################## +ARCH = arm-none-eabi- +SRCFLAGS = -ggdb -O0 +CFLAGS = +CXXFLAGS = -fno-rtti +ASFLAGS = +LDFLAGS = + +SRC = +OBJS = +DEFS = +LIBS = +INCPATH = +LIBPATH = +LDSCRIPT = + +############################################################################################## +# These should be at the end +# + +include $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk +include $(GFXLIB)/tools/gmake_scripts/os_$(OPT_OS).mk +include $(GFXLIB)/tools/gmake_scripts/compiler_gcc.mk +# *** EOF *** +############################################################################## ############################################################################### # Architecture or project specific options # @@ -64,178 +82,5 @@ ifeq ($(USE_EXCEPTIONS_STACKSIZE),) USE_EXCEPTIONS_STACKSIZE = 0x400 endif -# Enables the use of FPU on Cortex-M4 (no, softfp, hard). -ifeq ($(USE_FPU),) - USE_FPU = no -endif - -# -# Architecture or project specific options -############################################################################## - -############################################################################## -# Project, sources and paths -# - -SW = .. - -# Define project name here -PROJECT = ch - -# Imported source files and paths -CHIBIOS = ../ChibiOS -#include $(CHIBIOS)/boards/MIKROMEDIA_STM32_M4/board.mk # Not a standard ChibiOS supported board -include $(CHIBIOS)/os/hal/hal.mk -include $(CHIBIOS)/os/hal/ports/STM32/STM32F4xx/platform.mk -include $(CHIBIOS)/os/hal/osal/rt/osal.mk -include $(CHIBIOS)/os/rt/rt.mk -include $(CHIBIOS)/os/rt/ports/ARMCMx/compilers/GCC/mk/port_stm32f4xx.mk -LDSCRIPT= $(PORTLD)/STM32F407xG.ld - -# Imported source files and paths for uGFX -GFXLIB = ../ugfx -include $(GFXLIB)/boards/base/Mikromedia-STM32-M4-ILI9341/board.mk -include $(GFXLIB)/boards/base/Mikromedia-STM32-M4-ILI9341/ChibiOS_Board/board.mk # The replacement ChibiOS board files -include $(GFXLIB)/gfx.mk - -# Where is our source code - alter these for your project. -# Either just include the demo makefile or add your own definitions -include $(GFXLIB)/demos/modules/gdisp/basics/demo.mk -#MYFILES = my-project-directory -#MYCSRC = $(MYFILES)/main.c -#MYDEFS = - -# C sources that can be compiled in ARM or THUMB mode depending on the global -# setting. -CSRC = $(PORTSRC) \ - $(KERNSRC) \ - $(TESTSRC) \ - $(HALSRC) \ - $(PLATFORMSRC) \ - $(BOARDSRC) \ - $(GFXSRC) \ - $(MYCSRC) - -# C++ sources that can be compiled in ARM or THUMB mode depending on the global -# setting. -CPPSRC = - -# C sources to be compiled in ARM mode regardless of the global setting. -# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler -# option that results in lower performance and larger code size. -ACSRC = - -# C++ sources to be compiled in ARM mode regardless of the global setting. -# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler -# option that results in lower performance and larger code size. -ACPPSRC = - -# C sources to be compiled in THUMB mode regardless of the global setting. -# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler -# option that results in lower performance and larger code size. -TCSRC = - -# C sources to be compiled in THUMB mode regardless of the global setting. -# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler -# option that results in lower performance and larger code size. -TCPPSRC = - -# List ASM source files here -ASMSRC = $(PORTASM) - -INCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \ - $(HALINC) $(OSALINC) $(PLATFORMINC) $(BOARDINC) \ - $(GFXINC) \ - $(MYFILES) - -# -# Project, sources and paths -############################################################################## - -############################################################################## -# Compiler settings -# - -MCU = cortex-m4 - -#TRGT = arm-elf- -TRGT = arm-none-eabi- -CC = $(TRGT)gcc -CPPC = $(TRGT)g++ -# Enable loading with g++ only if you need C++ runtime support. -# NOTE: You can use C++ even without C++ support if you are careful. C++ -# runtime support makes code size explode. -LD = $(TRGT)gcc -#LD = $(TRGT)g++ -CP = $(TRGT)objcopy -AS = $(TRGT)gcc -x assembler-with-cpp -OD = $(TRGT)objdump -SZ = $(TRGT)size -HEX = $(CP) -O ihex -BIN = $(CP) -O binary - -# ARM-specific options here -AOPT = - -# THUMB-specific options here -TOPT = -mthumb -DTHUMB - -# Define C warning options here -CWARN = -Wall -Wextra -Wstrict-prototypes - -# Define C++ warning options here -CPPWARN = -Wall -Wextra - -# -# Compiler settings -############################################################################## - -############################################################################## -# Start of default section -# - -# List all default C defines here, like -D_DEBUG=1 -DDEFS = $(GFXDEFS) - -# List all default ASM defines here, like -D_DEBUG=1 -DADEFS = - -# List all default directories to look for include files here -DINCDIR = - -# List the default directory to look for the libraries here -DLIBDIR = - -# List all default libraries here -DLIBS = - -# -# End of default section -############################################################################## - -############################################################################## -# Start of user section -# - -# List all user C define here, like -D_DEBUG=1 -UDEFS = - -# Define ASM defines here -UADEFS = - -# List all user directories here -UINCDIR = - -# List the user directory to look for the libraries here -ULIBDIR = - -# List all user libraries here -ULIBS = - -# -# End of user defines -############################################################################## - - RULESPATH = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC include $(RULESPATH)/rules.mk \ No newline at end of file diff --git a/boards/base/OSX/example/Makefile b/boards/base/OSX/example/Makefile index 956608ff..5bbcb5df 100644 --- a/boards/base/OSX/example/Makefile +++ b/boards/base/OSX/example/Makefile @@ -24,7 +24,7 @@ # OSX settings # See $(GFXLIB)/tools/gmake_scripts/os_osx.mk for the list of variables OSX_SDK = /Developer/SDKs/MacOSX10.7.sdk - OSX_ARCH = -mmacosx-version-min=10.3 -arch i386 + OSX_ARCH = -mmacosx-version-min=10.3 ############################################################################################## # Set these for your project @@ -32,13 +32,13 @@ ARCH = SRCFLAGS = -ggdb -O0 -SRCFLAGS+= -m32 CFLAGS = CXXFLAGS = ASFLAGS = LDFLAGS = SRC = +OBJS = DEFS = LIBS = INCPATH = diff --git a/boards/base/Olimex-SAM7EX256-GE8/example/Makefile b/boards/base/Olimex-SAM7EX256-GE8/example/Makefile index aa11abad..9130ed5a 100644 --- a/boards/base/Olimex-SAM7EX256-GE8/example/Makefile +++ b/boards/base/Olimex-SAM7EX256-GE8/example/Makefile @@ -14,6 +14,8 @@ OPT_NONSTANDARD_FLAGS = no OPT_NATIVEOS = chibios OPT_OS = chibios + OPT_THUMB = no + OPT_CPU = at91sam7 # uGFX settings # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables @@ -30,9 +32,7 @@ ifeq ($(OPT_OS),chibios) CHIBIOS_PLATFORM = AT91SAM7 CHIBIOS_PORT = GCC/ARM/AT91SAM7 CHIBIOS_DEFS = - #CHIBIOS_LDSCRIPT = $(PORTLD)/AT91SAM7X256.ld - # We define a non standard linker script here just to give us some more stack space - CHIBIOS_LDSCRIPT = linker.ld + CHIBIOS_LDSCRIPT = AT91SAM7X256.ld endif ############################################################################################## @@ -41,18 +41,20 @@ endif ARCH = arm-none-eabi- SRCFLAGS = -ggdb -O0 -SRCFLAGS+= -mcpu=arm7tdmi -mabi=apcs-gnu -mno-thumb-interwork CFLAGS = CXXFLAGS = -fno-rtti ASFLAGS = -LDFLAGS = -mcpu=arm7tdmi +LDFLAGS = SRC = +OBJS = DEFS = LIBS = INCPATH = LIBPATH = -LDSCRIPT = + +# We override the standard ChibiOS linker script here just to give us some more stack space +LDSCRIPT = linker.ld ############################################################################################## # These should be at the end diff --git a/boards/base/Olimex-SAM7EX256-GE8/example/readme.txt b/boards/base/Olimex-SAM7EX256-GE8/example/readme.txt index a357dc52..7d0909fd 100644 --- a/boards/base/Olimex-SAM7EX256-GE8/example/readme.txt +++ b/boards/base/Olimex-SAM7EX256-GE8/example/readme.txt @@ -1,3 +1 @@ Copy these files into your own project directory and alter them to suite. - -In particular look at the MYFILES definition and the MYCSRC definition. \ No newline at end of file diff --git a/boards/base/Win32/example/Makefile b/boards/base/Win32/example/Makefile index 4bf6c603..5670f0f1 100644 --- a/boards/base/Win32/example/Makefile +++ b/boards/base/Win32/example/Makefile @@ -43,6 +43,7 @@ ASFLAGS = LDFLAGS = SRC = +OBJS = DEFS = LIBS = INCPATH = diff --git a/boards/base/Win32/example/readme.txt b/boards/base/Win32/example/readme.txt index 78b8552b..23cc1aec 100644 --- a/boards/base/Win32/example/readme.txt +++ b/boards/base/Win32/example/readme.txt @@ -3,7 +3,4 @@ Copy these files into your own project directory and alter them to suite. Notes: 1/ This makefile uses the MINGW compiler tool chain and was run using the cygwin make. -2/ At the top of the Makefile is the define USE_CHIBIOS. Win32 can build uGFX for either - native Win32 (the default) or for the ChibiOS simulator. -3/ The files chconf.h and halconf.h are only needed if compiling for the ChibiOS simulator. -4/ Look at the MYFILES definition and the MYCSRC definition. +2/ The files chconf.h and halconf.h are only needed if compiling for the ChibiOS simulator. diff --git a/tools/gmake_scripts/compiler_gcc.mk b/tools/gmake_scripts/compiler_gcc.mk index 196e5d5a..bc3c216b 100644 --- a/tools/gmake_scripts/compiler_gcc.mk +++ b/tools/gmake_scripts/compiler_gcc.mk @@ -1,24 +1,33 @@ +# +# This file is subject to the terms of the GFX License. If a copy of +# the license was not distributed with this file, you can obtain one at: +# +# http://ugfx.org/license.html +# + +# # See readme.txt for the make API +# ifeq ($(basename $(OPT_OS)),win32) - # Nasty - must convert all paths into a format make can handle - PATHEXPAND := ARCH XCC XCXX XAS XLD XOC XOD PROJECT BUILDDIR SRC DEFS LIBS INCPATH LIBPATH $(PATHLIST) - - # First convert \'s to /'s - $(foreach var,$(PATHEXPAND),$(eval $(var):=$$(subst \,/,$($(var))))) - - # For cygwin gmake - need to convert all absolute paths (mingw gmake doesn't need this) - ifneq ($(findstring cygdrive,$(PATH)),) - DRIVELETTERS := a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z - $(foreach drv,$(DRIVELETTERS),$(foreach var,$(PATHEXPAND),$(eval $(var):=$$(patsubst $(drv):%,/cygdrive/$(drv)%,$($(var)))))) - endif + # Nasty - must convert all paths into a format make can handle + PATHEXPAND := ARCH XCC XCXX XAS XLD XOC XOD XSZ PROJECT BUILDDIR SRC DEFS LIBS INCPATH LIBPATH $(PATHLIST) + + # First convert \'s to /'s + $(foreach var,$(PATHEXPAND),$(eval $(var):=$$(subst \,/,$($(var))))) + + # For cygwin gmake - need to convert all absolute paths (mingw gmake doesn't need this) + ifneq ($(findstring cygdrive,$(PATH)),) + DRIVELETTERS := a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z + $(foreach drv,$(DRIVELETTERS),$(foreach var,$(PATHEXPAND),$(eval $(var):=$$(patsubst $(drv):%,/cygdrive/$(drv)%,$($(var)))))) + endif endif # Path resolution - Functions to convert a source path to a object path and visa-versa src_obj_fn := $$(1) obj_src_fn := $$(1) -$(foreach var,$(PATHLIST),$(eval obj_src_fn := $$$$(patsubst $(var)/%,$$$$($(var))/%,$$(obj_src_fn)))) -$(foreach var,$(PATHLIST),$(eval src_obj_fn := $$$$(patsubst $$$$($(var))/%,$(var)/%,$$(src_obj_fn)))) +$(foreach var,$(PATHLIST),$(eval obj_src_fn := $$$$(patsubst $(var)/%,$$$$($(var))/%,$$(obj_src_fn)))) +$(foreach var,$(PATHLIST),$(eval src_obj_fn := $$$$(patsubst $$$$($(var))/%,$(var)/%,$$(src_obj_fn)))) src_obj_fn := $$(subst :,_drv_drv_,$$(subst ../,_dot_dot/,$(src_obj_fn))) obj_src_fn := $$(subst _drv_drv_,:,$$(subst _dot_dot/,../,$(obj_src_fn))) $(eval src_obj=$(src_obj_fn)) @@ -26,122 +35,188 @@ $(eval obj_src=$(obj_src_fn)) # Add ARCH to each of the compiler programs ifeq ($(XCC),) - XCC = $(ARCH)gcc + XCC = $(ARCH)gcc endif ifeq ($(XCXX),) - XCXX = $(ARCH)g++ + XCXX = $(ARCH)g++ endif ifeq ($(XAS),) - XAS = $(ARCH)gcc -x assembler-with-cpp + XAS = $(ARCH)gcc -x assembler-with-cpp endif ifeq ($(XLD),) - XLD = $(ARCH)gcc + XLD = $(ARCH)gcc endif ifeq ($(XOC),) - XOC = $(ARCH)objcopy + XOC = $(ARCH)objcopy endif ifeq ($(XOD),) - XOD = $(ARCH)objdump + XOD = $(ARCH)objdump endif +ifeq ($(XSZ),) + XSZ = $(ARCH)size + endif # Default project name is the project directory name ifeq ($(PROJECT),) - ifneq ($(firstword $(abspath $(firstword $(MAKEFILE_LIST)))),$(lastword $(abspath $(firstword $(MAKEFILE_LIST))))) - $(error Your directory contains spaces. Gmake barfs at that. Please define PROJECT) - endif - PROJECT := $(notdir $(patsubst %/,%,$(dir $(abspath $(firstword $(MAKEFILE_LIST)))))) + ifneq ($(firstword $(abspath $(firstword $(MAKEFILE_LIST)))),$(lastword $(abspath $(firstword $(MAKEFILE_LIST))))) + $(error Your directory contains spaces. Gmake barfs at that. Please define PROJECT) + endif + PROJECT := $(notdir $(patsubst %/,%,$(dir $(abspath $(firstword $(MAKEFILE_LIST)))))) endif # Output directories ifeq ($(BUILDDIR),) - ifeq ($(MAKECMDGOALS),Debug) - BUILDDIR = bin/Debug - endif - ifeq ($(MAKECMDGOALS),Release) - BUILDDIR = bin/Release - endif - ifeq ($(MAKECMDGOALS),cleanDebug) - BUILDDIR = bin/Debug - endif - ifeq ($(MAKECMDGOALS),cleanRelease) - BUILDDIR = bin/Release - endif - ifeq ($(BUILDDIR),) - BUILDDIR = .build - endif + ifeq ($(MAKECMDGOALS),Debug) + BUILDDIR = bin/Debug + endif + ifeq ($(MAKECMDGOALS),Release) + BUILDDIR = bin/Release + endif + ifeq ($(MAKECMDGOALS),cleanDebug) + BUILDDIR = bin/Debug + endif + ifeq ($(MAKECMDGOALS),cleanRelease) + BUILDDIR = bin/Release + endif + ifeq ($(BUILDDIR),) + BUILDDIR = .build + endif endif OBJDIR = $(BUILDDIR)/obj DEPDIR = $(BUILDDIR)/dep # Output files MAPFILE = $(BUILDDIR)/$(PROJECT).map +FAKEFILE= fakefile.o EXEFILE = ifeq ($(basename $(OPT_OS)),win32) - EXEFILE = $(BUILDDIR)/$(PROJECT).exe - TARGETS = $(EXEFILE) + EXEFILE = $(BUILDDIR)/$(PROJECT).exe + TARGETS = $(EXEFILE) endif ifeq ($(basename $(OPT_OS)),linux) - EXEFILE = $(BUILDDIR)/$(PROJECT) - TARGETS = $(EXEFILE) + EXEFILE = $(BUILDDIR)/$(PROJECT) + TARGETS = $(EXEFILE) endif ifeq ($(basename $(OPT_OS)),osx) - EXEFILE = $(BUILDDIR)/$(PROJECT) - TARGETS = $(EXEFILE) + EXEFILE = $(BUILDDIR)/$(PROJECT) + TARGETS = $(EXEFILE) endif ifeq ($(EXEFILE),) - LDFLAGS += -nostartfiles - EXEFILE = $(BUILDDIR)/$(PROJECT).elf - TARGETS = $(EXEFILE) $(BUILDDIR)/$(PROJECT).hex $(BUILDDIR)/$(PROJECT).bin $(BUILDDIR)/$(PROJECT).dmp + LDFLAGS += -nostartfiles + EXEFILE = $(BUILDDIR)/$(PROJECT).elf + TARGETS = $(EXEFILE) $(BUILDDIR)/$(PROJECT).hex $(BUILDDIR)/$(PROJECT).bin $(BUILDDIR)/$(PROJECT).dmp elfstats endif -# Combine all our compiler arguments -SRCFLAGS += -I. $(patsubst %,-I%,$(INCPATH)) $(patsubst %,-D%,$(patsubst -D%,%,$(DEFS))) -LDFLAGS += $(patsubst %,-L%,$(LIBPATH)) $(patsubst %,-l%,$(patsubst -l%,%,$(LIBS))) -OBJS = $(addprefix $(OBJDIR)/,$(call src_obj,$(addsuffix .o,$(basename $(SRC))))) +# Generate our object file lists +OBJS_THUMB += $(addprefix $(OBJDIR)/,$(call src_obj,$(addsuffix .o,$(basename $(SRC_THUMB))))) +OBJS_NOTHUMB += $(addprefix $(OBJDIR)/,$(call src_obj,$(addsuffix .o,$(basename $(SRC_NOTHUMB))))) +ifeq ($(OPT_THUMB),yes) + OBJS_THUMB += $(OBJS) $(addprefix $(OBJDIR)/,$(call src_obj,$(addsuffix .o,$(basename $(SRC))))) +else + OBJS_NOTHUMB += $(OBJS) $(addprefix $(OBJDIR)/,$(call src_obj,$(addsuffix .o,$(basename $(SRC))))) +endif +ifneq ($(OBJS_THUMB),) + ifneq ($(OBJS_NOTHUMB),) + # Mixed ARM and THUMB mode - enabled only if needed because it kills performance. + SRCFLAGS += -mthumb-interwork + LDFLAGS += -mthumb-interwork + DEFS += THUMB_PRESENT + else + # Pure THUMB mode, THUMB C code cannot be called by ARM asm code directly. + LDFLAGS += -mthumb + DEFS += THUMB_PRESENT THUMB_NO_INTERWORKING + FAKEFILE= fakethumbfile.o + endif +endif # Handle make API options that affect compiler arguments ifneq ($(OPT_NONSTANDARD_FLAGS),yes) - SRCFLAGS += -fomit-frame-pointer -Wall -Wextra -Wstrict-prototypes -fverbose-asm + SRCFLAGS += -fomit-frame-pointer -Wall -Wextra -Wstrict-prototypes -fverbose-asm endif ifeq ($(OPT_LINK_OPTIMIZE),yes) - SRCFLAGS += -ffunction-sections -fdata-sections + SRCFLAGS += -ffunction-sections -fdata-sections -fno-common -flto endif ifeq ($(OPT_GENERATE_MAP),yes) - ifeq ($(OPT_LINK_OPTIMIZE),yes) - LDFLAGS += -Wl,-Map=$(MAPFILE),--cref,--no-warn-mismatch,--gc-sections - else - LDFLAGS += -Wl,-Map=$(MAPFILE),--cref,--no-warn-mismatch - endif + ifeq ($(OPT_LINK_OPTIMIZE),yes) + LDFLAGS += -Wl,-Map=$(MAPFILE),--cref,--no-warn-mismatch,--gc-sections + else + LDFLAGS += -Wl,-Map=$(MAPFILE),--cref,--no-warn-mismatch + endif endif ifeq ($(OPT_GENERATE_LISTINGS),yes) - CFLAGS += -Wa,-alms=$(@:.o=.lst) - CXXFLAGS += -Wa,-alms=$(@:.o=.lst) - ASFLAGS += -Wa,-amhls=$(@:.o=.lst) + CFLAGS += -Wa,-alms=$(@:.o=.lst) + CXXFLAGS += -Wa,-alms=$(@:.o=.lst) + ASFLAGS += -Wa,-amhls=$(@:.o=.lst) endif ifneq ($(LDSCRIPT),) - LDFLAGS += -T$(LDSCRIPT) + LDFLAGS += -T$(LDSCRIPT) +endif +ifeq ($(OPT_CPU),x86) + SRCFLAGS += -m32 + LDFLAGS += -m32 +endif +ifeq ($(OPT_CPU),x64) + SRCFLAGS += -m64 + LDFLAGS += -m64 +endif +ifeq ($(OPT_CPU),at91sam7) + SRCFLAGS += -mcpu=arm7tdmi -mabi=apcs-gnu + LDFLAGS += -mcpu=arm7tdmi +endif +ifeq ($(OPT_CPU),stm32m4) + SRCFLAGS += -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -falign-functions=16 + LDFLAGS += -mcpu=cortex-m4 + LIBS += m endif # Generate dependency information SRCFLAGS += -MMD -MP -MF $(DEPDIR)/$(@F).d +# Combine all our compiler arguments +SRCFLAGS += -I. $(patsubst %,-I%,$(INCPATH)) $(patsubst %,-D%,$(patsubst -D%,%,$(DEFS))) +LDFLAGS += $(patsubst %,-L%,$(LIBPATH)) $(patsubst %,-l%,$(patsubst -l%,%,$(LIBS))) + # Targets -.PHONY: builddirs fakefile.o all clean Debug Release cleanDebug cleanRelease +.PHONY: builddirs fakefile.o fakethumbfile.o elfstats all clean Debug Release cleanDebug cleanRelease Debug Release: all cleanDebug cleanRelease: clean -all: builddirs fakefile.o $(TARGETS) +all: builddirs $(FAKEFILE) $(TARGETS) builddirs: @mkdir -p $(BUILDDIR) @mkdir -p $(OBJDIR) @mkdir -p $(DEPDIR) -fakefile.o: +$(FAKEFILE): ifneq ($(OPT_VERBOSE_COMPILE),yes) - @echo Compiler Options - $(XCC) -c $(CPPFLAGS) $(CFLAGS) $(SRCFLAGS) fakefile.c -o $(OBJDIR)/$@ - @echo + @echo . + ifneq ($(filter %.cpp,$(SRC) $(SRC_NOTHUMB) $(SRC_THUMB)),) + @echo C++ Compiler Options.. $(XCXX) -c $(CPPFLAGS) $(CXXFLAGS) $(SRCFLAGS) $(@:.o=.cpp) -o $(OBJDIR)/$@ + else + ifneq ($(filter %.c++,$(SRC) $(SRC_NOTHUMB) $(SRC_THUMB)),) + @echo C++ Compiler Options.. $(XCXX) -c $(CPPFLAGS) $(CXXFLAGS) $(SRCFLAGS) $(@:.o=.c++) -o $(OBJDIR)/$@ + endif + endif + ifneq ($(filter %.c,$(SRC) $(SRC_NOTHUMB) $(SRC_THUMB)),) + @echo C Compiler Options.... $(XCC) -c $(CPPFLAGS) $(CFLAGS) $(SRCFLAGS) $(@:.o=.c) -o $(OBJDIR)/$@ + endif + ifneq ($(filter %.s,$(SRC) $(SRC_NOTHUMB) $(SRC_THUMB)),) + @echo Assembler Options..... $(XCC) -c $(CPPFLAGS) $(CFLAGS) $(SRCFLAGS) $(@:.o=.s) -o $(OBJDIR)/$@ + endif + @echo Linker Options........ $(XLD) $(LDFLAGS) $(OBJDIR)/$@ -o $(EXEFILE) + @echo . +endif + +fakethumbfile.o $(OBJS_THUMB): SRCFLAGS += -mthumb -DTHUMB + +elfstats: $(EXEFILE) + @echo . +ifeq ($(USE_VERBOSE_COMPILE),yes) + $(XSZ) $< +else + @$(XSZ) $< endif # Implicit Rules @@ -150,7 +225,7 @@ endif $(OBJDIR)/%.o : $$(call obj_src,%.c) @mkdir -p $(dir $@) ifeq ($(OPT_VERBOSE_COMPILE),yes) - @echo + @echo . $(XCC) -c $(CPPFLAGS) $(CFLAGS) $(SRCFLAGS) $< -o $@ else @echo Compiling $< @@ -160,7 +235,7 @@ endif $(OBJDIR)/%.o : $$(call obj_src,%.cpp) @mkdir -p $(dir $@) ifeq ($(OPT_VERBOSE_COMPILE),yes) - @echo + @echo . $(XCXX) -c $(CPPFLAGS) $(CXXFLAGS) $(SRCFLAGS) $< -o $@ else @echo Compiling $< @@ -170,7 +245,7 @@ endif $(OBJDIR)/%.o : $$(call obj_src,%.c++) @mkdir -p $(dir $@) ifeq ($(OPT_VERBOSE_COMPILE),yes) - @echo + @echo . $(XCXX) -c $(CPPFLAGS) $(CXXFLAGS) $(SRCFLAGS) $< -o $@ else @echo Compiling $< @@ -180,21 +255,21 @@ endif $(OBJDIR)/%.o : $$(call obj_src,%.s) @mkdir -p $(dir $@) ifeq ($(OPT_VERBOSE_COMPILE),yes) - @echo + @echo . $(XAS) -c $(CPPFLAGS) $(ASFLAGS) $(SRCFLAGS) $< -o $@ else @echo Compiling $< @$(XAS) -c $(CPPFLAGS) $(ASFLAGS) $(SRCFLAGS) $< -o $@ endif -$(EXEFILE): $(OBJS) $(LDSCRIPT) +$(EXEFILE): $(OBJS_THUMB) $(OBJS_NOTHUMB) $(LDSCRIPT) @mkdir -p $(dir $@) ifeq ($(OPT_VERBOSE_COMPILE),yes) - @echo - $(XLD) $(OBJS) $(LDFLAGS) -o $@ + @echo . + $(XLD) $(OBJS_THUMB) $(OBJS_NOTHUMB) $(LDFLAGS) -o $@ else @echo Linking $@ - @$(XLD) $(OBJS) $(LDFLAGS) -o $@ + @$(XLD) $(OBJS_THUMB) $(OBJS_NOTHUMB) $(LDFLAGS) -o $@ endif ifeq ($(OPT_COPY_EXE),yes) @cp $@ . @@ -228,7 +303,6 @@ ifeq ($(USE_VERBOSE_COMPILE),yes) else @echo Creating $@ @$(XOD) -x --syms $< > $@ - @echo Done endif ifeq ($(OPT_COPY_EXE),yes) @cp $@ . diff --git a/tools/gmake_scripts/library_ugfx.mk b/tools/gmake_scripts/library_ugfx.mk index 24c501fe..450f6ff6 100644 --- a/tools/gmake_scripts/library_ugfx.mk +++ b/tools/gmake_scripts/library_ugfx.mk @@ -1,3 +1,10 @@ +# +# This file is subject to the terms of the GFX License. If a copy of +# the license was not distributed with this file, you can obtain one at: +# +# http://ugfx.org/license.html +# + # See readme.txt for the make API # Requirements: diff --git a/tools/gmake_scripts/os_chibios.mk b/tools/gmake_scripts/os_chibios.mk index a81c9803..b8205dd3 100644 --- a/tools/gmake_scripts/os_chibios.mk +++ b/tools/gmake_scripts/os_chibios.mk @@ -1,28 +1,60 @@ +# +# This file is subject to the terms of the GFX License. If a copy of +# the license was not distributed with this file, you can obtain one at: +# +# http://ugfx.org/license.html +# + # See readme.txt for the make API # Requirements: # # CHIBIOS: The location of the ChibiOS code eg CHIBIOS=../chibios -# CHIBIOS_BOARD The name of the ChibiOS board eg CHIBIOS_BOARD=OLIMEX_SAM7_EX256 # CHIBIOS_PLATFORM The name of the ChibiOS platform eg CHIBIOS_PLATFORM=AT91SAM7 # CHIBIOS_PORT The name of the ChibiOS port eg CHIBIOS_PORT=GCC/ARM/AT91SAM7 # # Optional: # -# CHIBIOS_LDSCRIPT The name of the loader script eg CHIBIOS_LDSCRIPT=$(PORTLD)/AT91SAM7X256.ld +# CHIBIOS_LDSCRIPT The name of the loader script eg CHIBIOS_LDSCRIPT=AT91SAM7X256.ld +# CHIBIOS_BOARD The name of the ChibiOS board eg CHIBIOS_BOARD=OLIMEX_SAM7_EX256 - if not specified you must include equivalent code yourself +# CHIBIOS_STM32LIB Use the STM32 library source for drivers instead of native drivers (yes or no) - default no +# CHIBIOS_VERSION Which version of ChibiOS is this (2 or 3) - default is 2 # PATHLIST += CHIBIOS -include $(CHIBIOS)/boards/$(CHIBIOS_BOARD)/board.mk -include $(CHIBIOS)/os/hal/platforms/$(CHIBIOS_PLATFORM)/platform.mk -include $(CHIBIOS)/os/hal/hal.mk -include $(CHIBIOS)/os/ports/$(CHIBIOS_PORT)/port.mk -include $(CHIBIOS)/os/kernel/kernel.mk -LDSCRIPT= $(CHIBIOS_LDSCRIPT) +ifeq ($(CHIBIOS_VERSION),3) + include $(CHIBIOS)/os/hal/hal.mk + include $(CHIBIOS)/os/hal/osal/rt/osal.mk + include $(CHIBIOS)/os/hal/ports/$(CHIBIOS_PLATFORM)/platform.mk + include $(CHIBIOS)/os/rt/rt.mk + include $(CHIBIOS)/os/rt/ports/$(CHIBIOS_PORT).mk +else + include $(CHIBIOS)/os/hal/hal.mk + include $(CHIBIOS)/os/hal/platforms/$(CHIBIOS_PLATFORM)/platform.mk + include $(CHIBIOS)/os/kernel/kernel.mk + include $(CHIBIOS)/os/ports/$(CHIBIOS_PORT)/port.mk +endif + +ifneq ($(CHIBIOS_BOARD),) + include $(CHIBIOS)/boards/$(CHIBIOS_BOARD)/board.mk +endif +ifeq ($(LDSCRIPT),) + ifneq ($(CHIBIOS_LDSCRIPT),) + LDSCRIPT= $(PORTLD)/$(CHIBIOS_LDSCRIPT) + endif +endif + +ifeq ($(CHIBIOS_STM32LIB),yes) + include $(CHIBIOS)/ext/stm32lib/stm32lib.mk + SRC += $(STM32SRC) + DEFS += USE_STDPERIPH_DRIVER + INCPATH += $(STM32INC) +endif + INCPATH += $(PORTINC) $(KERNINC) $(TESTINC) \ - $(HALINC) $(PLATFORMINC) $(BOARDINC) + $(HALINC) $(PLATFORMINC) $(BOARDINC) SRC += $(PORTSRC) \ $(KERNSRC) \ $(TESTSRC) \ diff --git a/tools/gmake_scripts/os_linux.mk b/tools/gmake_scripts/os_linux.mk index 39610ca4..0893ca51 100644 --- a/tools/gmake_scripts/os_linux.mk +++ b/tools/gmake_scripts/os_linux.mk @@ -1,3 +1,10 @@ +# +# This file is subject to the terms of the GFX License. If a copy of +# the license was not distributed with this file, you can obtain one at: +# +# http://ugfx.org/license.html +# + # See readme.txt for the make API # Requirements: diff --git a/tools/gmake_scripts/os_osx.mk b/tools/gmake_scripts/os_osx.mk index 8b008f4b..9bfc7024 100644 --- a/tools/gmake_scripts/os_osx.mk +++ b/tools/gmake_scripts/os_osx.mk @@ -1,10 +1,18 @@ +# +# This file is subject to the terms of the GFX License. If a copy of +# the license was not distributed with this file, you can obtain one at: +# +# http://ugfx.org/license.html +# + # See readme.txt for the make API # Requirements: # # OSX_SDK The location of the SDK eg. OSX_SDK = /Developer/SDKs/MacOSX10.7.sdk -# OSX_ARCH The architecture flags eg. OSX_ARCH = -mmacosx-version-min=10.3 -arch i386 +# OSX_ARCH The architecture flags eg. OSX_ARCH = -mmacosx-version-min=10.3 # SRCFLAGS += -isysroot $(OSX_SDK) $(OSX_ARCH) LDFLAGS += -pthread -Wl,-syslibroot,$(OSX_SDK) $(OSX_ARCH) +OPT_CPU = x86 diff --git a/tools/gmake_scripts/os_win32.chibios.mk b/tools/gmake_scripts/os_win32.chibios.mk index 5a804c64..0eccf071 100644 --- a/tools/gmake_scripts/os_win32.chibios.mk +++ b/tools/gmake_scripts/os_win32.chibios.mk @@ -1,3 +1,10 @@ +# +# This file is subject to the terms of the GFX License. If a copy of +# the license was not distributed with this file, you can obtain one at: +# +# http://ugfx.org/license.html +# + # See readme.txt for the make API # Requirements: diff --git a/tools/gmake_scripts/os_win32.mk b/tools/gmake_scripts/os_win32.mk index 1b33ad85..07d15c20 100644 --- a/tools/gmake_scripts/os_win32.mk +++ b/tools/gmake_scripts/os_win32.mk @@ -1,6 +1,14 @@ +# +# This file is subject to the terms of the GFX License. If a copy of +# the license was not distributed with this file, you can obtain one at: +# +# http://ugfx.org/license.html +# + # See readme.txt for the make API # Requirements: # # NONE # +OPT_CPU = x86 diff --git a/tools/gmake_scripts/readme.txt b/tools/gmake_scripts/readme.txt index 979ca364..48ac2c9e 100644 --- a/tools/gmake_scripts/readme.txt +++ b/tools/gmake_scripts/readme.txt @@ -15,6 +15,7 @@ OPT_COPY_EXE=no|yes - Copy the final program to the local project directory - OPT_NONSTANDARD_FLAGS=no - Turn off adding the standard compiler language flags - default no OPT_LINK_OPTIMIZE=no - Remove unused code/data during link - default no OPT_OS=win32|win32.chibios|linux|osx|chibios|freertos|ecos|raw32|rawrtos - Mandatory: The operating system +OPT_CPU=x86|x64|stm32m4|at91sam7 - Add some cpu dependant flags BUILDDIR - Build Directory - default is ".build" or "bin/Debug" or "bin/Release" depending on the target PROJECT - Project Name - default is the name of the project directory @@ -27,6 +28,7 @@ XAS - Assembler - default is "$(ARCH)gcc -x assembler-with-cpp" XLD - Linker - default is "$(ARCH)gcc" XOC - Object Copy - default is "$(ARCH)objcopy" XOD - Object Dump - default is "$(ARCH)objdump" +XSZ - Report binary dump details - default is "$(ARCH)size" SRCFLAGS - Compiler defines for c, c++ and assembler files - default is "" CFLAGS - C specific compiler defines - default is "" @@ -43,8 +45,18 @@ LIBPATH - List of library include directories - default is "" DEFS - List of preprocessor defines (any -D prefix is ignored) - default is "" LIBS - List of libraries (any -l prefix is ignored) - default is "" SRC - List of c, c++ and assembler source files - default is "" +OBJS - List of additional object files - default is "" LDSCRIPT - Custom loader script - default is "" +ARM Specific options +---------------------------- +OPT_THUMB=no|yes - Compile normal sources in thumb mode - default is no + +SRC_THUMB - List of source files that MUST be compiled in thumb mode - default is "" +SRC_NOTHUMB - List of source files that MUST be compiled in non-thumb mode - default is "" +OBJS_THUMB - List of object files that MUST be linked in thumb mode - default is "" +OBJS_NOTHUMB - List of object files that MUST be linked in non-thumb mode - default is "" + Targets ---------------------------- From 18c4a9f8703b8a6ddcea050d74d31b194005dae1 Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 6 Oct 2014 15:50:19 +1000 Subject: [PATCH 38/87] Update support for ChibiOS v3 to the current repository. Update Make system to match. Add ability to make to a library rather than a program Stop ignoring objcode invalid format errors Multiple make tidy ups --- .../base/Linux-Framebuffer/example/Makefile | 8 +- boards/base/Linux/example/Makefile | 8 +- .../ChibiOS_Board/board.h | 1 + .../example_chibios_2.x/Makefile | 9 +-- .../example_chibios_3.x/Makefile | 35 ++------- .../example_chibios_3.x/chconf.h | 2 +- .../example_chibios_3.x/halconf.h | 18 ++--- .../example_chibios_3.x/mcuconf.h | 2 +- boards/base/OSX/example/Makefile | 8 +- .../Olimex-SAM7EX256-GE8/example/Makefile | 11 +-- boards/base/Win32/example/Makefile | 8 +- src/gos/gos_chibios.h | 4 + tools/gmake_scripts/compiler_gcc.mk | 78 +++++++++++-------- tools/gmake_scripts/cpu_at91sam7.mk | 20 +++++ tools/gmake_scripts/cpu_stm32m4.mk | 19 +++++ tools/gmake_scripts/cpu_x64.mk | 18 +++++ tools/gmake_scripts/cpu_x86.mk | 18 +++++ tools/gmake_scripts/os_chibios.mk | 31 ++++++-- tools/gmake_scripts/readme.txt | 4 + 19 files changed, 180 insertions(+), 122 deletions(-) create mode 100644 tools/gmake_scripts/cpu_at91sam7.mk create mode 100644 tools/gmake_scripts/cpu_stm32m4.mk create mode 100644 tools/gmake_scripts/cpu_x64.mk create mode 100644 tools/gmake_scripts/cpu_x86.mk diff --git a/boards/base/Linux-Framebuffer/example/Makefile b/boards/base/Linux-Framebuffer/example/Makefile index fb0c1b7a..802fddc3 100644 --- a/boards/base/Linux-Framebuffer/example/Makefile +++ b/boards/base/Linux-Framebuffer/example/Makefile @@ -6,13 +6,8 @@ # General settings # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables - OPT_VERBOSE_COMPILE = no - OPT_GENERATE_LISTINGS = yes - OPT_GENERATE_MAP = yes - OPT_COPY_EXE = no - OPT_LINK_OPTIMIZE = yes - OPT_NONSTANDARD_FLAGS = no OPT_OS = linux + OPT_LINK_OPTIMIZE = yes # Change this next setting (or add the explicit compiler flags) if you are not compiling for x86 linux OPT_CPU = x86 @@ -20,7 +15,6 @@ # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables GFXLIB = ../uGFX GFXBOARD = Linux-Framebuffer - #GFXDRIVERS = multiple/uGFXnet GFXDEMO = modules/gdisp/basics # Linux settings diff --git a/boards/base/Linux/example/Makefile b/boards/base/Linux/example/Makefile index 3d6d3d60..d75c1dd2 100644 --- a/boards/base/Linux/example/Makefile +++ b/boards/base/Linux/example/Makefile @@ -6,13 +6,8 @@ # General settings # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables - OPT_VERBOSE_COMPILE = no - OPT_GENERATE_LISTINGS = yes - OPT_GENERATE_MAP = yes - OPT_COPY_EXE = no - OPT_LINK_OPTIMIZE = yes - OPT_NONSTANDARD_FLAGS = no OPT_OS = linux + OPT_LINK_OPTIMIZE = yes # Change this next setting (or add the explicit compiler flags) if you are not compiling for x86 linux OPT_CPU = x86 @@ -20,7 +15,6 @@ # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables GFXLIB = ../uGFX GFXBOARD = Linux - #GFXDRIVERS = multiple/uGFXnet GFXDEMO = modules/gdisp/basics # Linux settings diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/ChibiOS_Board/board.h b/boards/base/Mikromedia-STM32-M4-ILI9341/ChibiOS_Board/board.h index 41f15201..b5ee34ad 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/ChibiOS_Board/board.h +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/ChibiOS_Board/board.h @@ -49,6 +49,7 @@ * MCU type as defined in the ST header. */ #define STM32F40_41xxx +#define STM32F407xx /* * IO pins assignments. diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/Makefile b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/Makefile index ac483689..8baa399f 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/Makefile +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/Makefile @@ -6,22 +6,16 @@ # General settings # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables - OPT_VERBOSE_COMPILE = no - OPT_GENERATE_LISTINGS = yes - OPT_GENERATE_MAP = yes - OPT_COPY_EXE = no - OPT_LINK_OPTIMIZE = yes - OPT_NONSTANDARD_FLAGS = no OPT_NATIVEOS = chibios OPT_OS = chibios OPT_THUMB = yes + OPT_LINK_OPTIMIZE = yes OPT_CPU = stm32m4 # uGFX settings # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables GFXLIB = ../uGFX GFXBOARD = Mikromedia-STM32-M4-ILI9341 - #GFXDRIVERS = multiple/uGFXnet GFXDEMO = modules/gdisp/basics # ChibiOS settings @@ -31,7 +25,6 @@ ifeq ($(OPT_OS),chibios) CHIBIOS_BOARD = CHIBIOS_PLATFORM = STM32F4xx CHIBIOS_PORT = GCC/ARMCMx/STM32F4xx - CHIBIOS_DEFS = CHIBIOS_LDSCRIPT = STM32F407xG.ld # We define a non standard board script as this is not a standard ChibiOS supported board include $(GFXLIB)/boards/base/Mikromedia-STM32-M4-ILI9341/ChibiOS_Board/board.mk diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/Makefile b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/Makefile index d19c3d28..55778283 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/Makefile +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/Makefile @@ -6,33 +6,27 @@ # General settings # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables - OPT_VERBOSE_COMPILE = no - OPT_GENERATE_LISTINGS = yes - OPT_GENERATE_MAP = yes - OPT_COPY_EXE = no - OPT_LINK_OPTIMIZE = yes - OPT_NONSTANDARD_FLAGS = no OPT_NATIVEOS = chibios OPT_OS = chibios OPT_THUMB = yes + OPT_LINK_OPTIMIZE = yes OPT_CPU = stm32m4 # uGFX settings # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables GFXLIB = ../uGFX GFXBOARD = Mikromedia-STM32-M4-ILI9341 - #GFXDRIVERS = multiple/uGFXnet GFXDEMO = modules/gdisp/basics # ChibiOS settings ifeq ($(OPT_OS),chibios) # See $(GFXLIB)/tools/gmake_scripts/os_chibios.mk for the list of variables - CHIBIOS = ../ChibiOS - CHBIOS_VERSION = 3 + CHIBIOS = ../ChibiOS3 + CHIBIOS_VERSION = 3 CHIBIOS_BOARD = + CHIBIOS_CPUCLASS = ARMCMx CHIBIOS_PLATFORM = STM32/STM32F4xx - CHIBIOS_PORT = ARMCMx/compilers/GCC/mk/port_stm32f4xx - CHIBIOS_DEFS = + CHIBIOS_PORT = stm32f4xx CHIBIOS_LDSCRIPT = STM32F407xG.ld # We define a non standard board script as this is not a standard ChibiOS supported board include $(GFXLIB)/boards/base/Mikromedia-STM32-M4-ILI9341/ChibiOS_Board/board.mk @@ -65,22 +59,3 @@ include $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk include $(GFXLIB)/tools/gmake_scripts/os_$(OPT_OS).mk include $(GFXLIB)/tools/gmake_scripts/compiler_gcc.mk # *** EOF *** -############################################################################## -############################################################################### -# Architecture or project specific options -# - -# Stack size to be allocated to the Cortex-M process stack. This stack is -# the stack used by the main() thread. -ifeq ($(USE_PROCESS_STACKSIZE),) - USE_PROCESS_STACKSIZE = 0x400 -endif - -# Stack size to the allocated to the Cortex-M main/exceptions stack. This -# stack is used for processing interrupts and exceptions. -ifeq ($(USE_EXCEPTIONS_STACKSIZE),) - USE_EXCEPTIONS_STACKSIZE = 0x400 -endif - -RULESPATH = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC -include $(RULESPATH)/rules.mk \ No newline at end of file diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/chconf.h b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/chconf.h index 150bd73c..53700421 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/chconf.h +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/chconf.h @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006-2014 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/halconf.h b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/halconf.h index 40c57eeb..06d3e2ff 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/halconf.h +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/halconf.h @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006-2014 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -30,13 +30,6 @@ #include "mcuconf.h" -/** - * @brief Enables the TM subsystem. - */ -#if !defined(HAL_USE_TM) || defined(__DOXYGEN__) -#define HAL_USE_TM FALSE -#endif - /** * @brief Enables the PAL subsystem. */ @@ -79,6 +72,13 @@ #define HAL_USE_I2C FALSE #endif +/** + * @brief Enables the I2S subsystem. + */ +#if !defined(HAL_USE_I2S) || defined(__DOXYGEN__) +#define HAL_USE_I2S FALSE +#endif + /** * @brief Enables the ICU subsystem. */ @@ -104,7 +104,7 @@ * @brief Enables the PWM subsystem. */ #if !defined(HAL_USE_PWM) || defined(__DOXYGEN__) -#define HAL_USE_PWM TRUE +#define HAL_USE_PWM FALSE #endif /** diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/mcuconf.h b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/mcuconf.h index 047224f1..1f8378d2 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/mcuconf.h +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/mcuconf.h @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006-2014 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/boards/base/OSX/example/Makefile b/boards/base/OSX/example/Makefile index 5bbcb5df..4226f613 100644 --- a/boards/base/OSX/example/Makefile +++ b/boards/base/OSX/example/Makefile @@ -6,19 +6,13 @@ # General settings # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables - OPT_VERBOSE_COMPILE = no - OPT_GENERATE_LISTINGS = yes - OPT_GENERATE_MAP = yes - OPT_COPY_EXE = no - OPT_LINK_OPTIMIZE = yes - OPT_NONSTANDARD_FLAGS = no OPT_OS = osx + OPT_LINK_OPTIMIZE = yes # uGFX settings # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables GFXLIB = ../uGFX GFXBOARD = OSX - #GFXDRIVERS = multiple/uGFXnet GFXDEMO = modules/gdisp/basics # OSX settings diff --git a/boards/base/Olimex-SAM7EX256-GE8/example/Makefile b/boards/base/Olimex-SAM7EX256-GE8/example/Makefile index 9130ed5a..fe0e5178 100644 --- a/boards/base/Olimex-SAM7EX256-GE8/example/Makefile +++ b/boards/base/Olimex-SAM7EX256-GE8/example/Makefile @@ -6,22 +6,16 @@ # General settings # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables - OPT_VERBOSE_COMPILE = no - OPT_GENERATE_LISTINGS = yes - OPT_GENERATE_MAP = yes - OPT_COPY_EXE = no - OPT_LINK_OPTIMIZE = yes - OPT_NONSTANDARD_FLAGS = no OPT_NATIVEOS = chibios OPT_OS = chibios - OPT_THUMB = no + OPT_THUMB = yes + OPT_LINK_OPTIMIZE = yes OPT_CPU = at91sam7 # uGFX settings # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables GFXLIB = ../uGFX GFXBOARD = Olimex-SAM7EX256-GE8 - #GFXDRIVERS = multiple/uGFXnet GFXDEMO = modules/gdisp/basics # ChibiOS settings @@ -31,7 +25,6 @@ ifeq ($(OPT_OS),chibios) CHIBIOS_BOARD = OLIMEX_SAM7_EX256 CHIBIOS_PLATFORM = AT91SAM7 CHIBIOS_PORT = GCC/ARM/AT91SAM7 - CHIBIOS_DEFS = CHIBIOS_LDSCRIPT = AT91SAM7X256.ld endif diff --git a/boards/base/Win32/example/Makefile b/boards/base/Win32/example/Makefile index 5670f0f1..0087ca90 100644 --- a/boards/base/Win32/example/Makefile +++ b/boards/base/Win32/example/Makefile @@ -6,20 +6,14 @@ # General settings # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables - OPT_VERBOSE_COMPILE = no - OPT_GENERATE_LISTINGS = yes - OPT_GENERATE_MAP = yes - OPT_COPY_EXE = no - OPT_LINK_OPTIMIZE = yes - OPT_NONSTANDARD_FLAGS = no # For Win32 this variable can be set to "win32" (native win32 api) or "win32.chibios" (ChibiOS simulator). OPT_OS = win32 + OPT_LINK_OPTIMIZE = yes # uGFX settings # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables GFXLIB = ../uGFX GFXBOARD = Win32 - #GFXDRIVERS = multiple/uGFXnet GFXDEMO = modules/gdisp/basics # ChibiOS settings diff --git a/src/gos/gos_chibios.h b/src/gos/gos_chibios.h index a07c72ab..a3aba712 100644 --- a/src/gos/gos_chibios.h +++ b/src/gos/gos_chibios.h @@ -28,6 +28,10 @@ * are already defined by ChibiOS */ +#if CH_KERNEL_MAJOR == 3 + typedef char bool_t; +#endif + typedef systime_t delaytime_t; typedef systime_t systemticks_t; typedef cnt_t semcount_t; diff --git a/tools/gmake_scripts/compiler_gcc.mk b/tools/gmake_scripts/compiler_gcc.mk index bc3c216b..04a68afc 100644 --- a/tools/gmake_scripts/compiler_gcc.mk +++ b/tools/gmake_scripts/compiler_gcc.mk @@ -9,9 +9,9 @@ # See readme.txt for the make API # +# Win32 Nasty - must convert all paths into a format make can handle ifeq ($(basename $(OPT_OS)),win32) - # Nasty - must convert all paths into a format make can handle - PATHEXPAND := ARCH XCC XCXX XAS XLD XOC XOD XSZ PROJECT BUILDDIR SRC DEFS LIBS INCPATH LIBPATH $(PATHLIST) + PATHEXPAND := ARCH XCC XCXX XAS XLD XOC XOD XSZ XAR PROJECT BUILDDIR SRC DEFS LIBS INCPATH LIBPATH $(PATHLIST) # First convert \'s to /'s $(foreach var,$(PATHEXPAND),$(eval $(var):=$$(subst \,/,$($(var))))) @@ -23,6 +23,14 @@ ifeq ($(basename $(OPT_OS)),win32) endif endif +# Where are we +CURRENTDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) + +# Handle cpu specific options +ifneq ($(OPT_CPU),) + include $(CURRENTDIR)cpu_$(OPT_CPU).mk +endif + # Path resolution - Functions to convert a source path to a object path and visa-versa src_obj_fn := $$(1) obj_src_fn := $$(1) @@ -54,7 +62,10 @@ ifeq ($(XOD),) endif ifeq ($(XSZ),) XSZ = $(ARCH)size - endif +endif +ifeq ($(XAR),) + XAR = $(ARCH)ar +endif # Default project name is the project directory name ifeq ($(PROJECT),) @@ -87,6 +98,7 @@ DEPDIR = $(BUILDDIR)/dep # Output files MAPFILE = $(BUILDDIR)/$(PROJECT).map +LIBFILE = $(BUILDDIR)/lib$(PROJECT).a FAKEFILE= fakefile.o EXEFILE = ifeq ($(basename $(OPT_OS)),win32) @@ -135,13 +147,10 @@ ifneq ($(OPT_NONSTANDARD_FLAGS),yes) endif ifeq ($(OPT_LINK_OPTIMIZE),yes) SRCFLAGS += -ffunction-sections -fdata-sections -fno-common -flto + LDFLAGS += -Wl,--gc-sections endif ifeq ($(OPT_GENERATE_MAP),yes) - ifeq ($(OPT_LINK_OPTIMIZE),yes) - LDFLAGS += -Wl,-Map=$(MAPFILE),--cref,--no-warn-mismatch,--gc-sections - else - LDFLAGS += -Wl,-Map=$(MAPFILE),--cref,--no-warn-mismatch - endif + LDFLAGS += -Wl,-Map=$(MAPFILE),--cref endif ifeq ($(OPT_GENERATE_LISTINGS),yes) CFLAGS += -Wa,-alms=$(@:.o=.lst) @@ -151,23 +160,6 @@ endif ifneq ($(LDSCRIPT),) LDFLAGS += -T$(LDSCRIPT) endif -ifeq ($(OPT_CPU),x86) - SRCFLAGS += -m32 - LDFLAGS += -m32 -endif -ifeq ($(OPT_CPU),x64) - SRCFLAGS += -m64 - LDFLAGS += -m64 -endif -ifeq ($(OPT_CPU),at91sam7) - SRCFLAGS += -mcpu=arm7tdmi -mabi=apcs-gnu - LDFLAGS += -mcpu=arm7tdmi -endif -ifeq ($(OPT_CPU),stm32m4) - SRCFLAGS += -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -falign-functions=16 - LDFLAGS += -mcpu=cortex-m4 - LIBS += m -endif # Generate dependency information SRCFLAGS += -MMD -MP -MF $(DEPDIR)/$(@F).d @@ -176,13 +168,23 @@ SRCFLAGS += -MMD -MP -MF $(DEPDIR)/$(@F).d SRCFLAGS += -I. $(patsubst %,-I%,$(INCPATH)) $(patsubst %,-D%,$(patsubst -D%,%,$(DEFS))) LDFLAGS += $(patsubst %,-L%,$(LIBPATH)) $(patsubst %,-l%,$(patsubst -l%,%,$(LIBS))) -# Targets -.PHONY: builddirs fakefile.o fakethumbfile.o elfstats all clean Debug Release cleanDebug cleanRelease +################# Targets ###################### +.PHONY: builddirs fakefile.o fakethumbfile.o elfstats all exe lib clean Debug Release cleanDebug cleanRelease + +# Many IDE's use these targets instead. Debug Release: all cleanDebug cleanRelease: clean -all: builddirs $(FAKEFILE) $(TARGETS) +# Make a program or a library? +ifeq ($(OPT_MAKE_LIB),yes) + all: lib +else + all: exe +endif + +exe: builddirs $(FAKEFILE) $(TARGETS) +lib: builddirs $(FAKEFILE) $(LIBFILE) builddirs: @mkdir -p $(BUILDDIR) @@ -205,7 +207,9 @@ ifneq ($(OPT_VERBOSE_COMPILE),yes) ifneq ($(filter %.s,$(SRC) $(SRC_NOTHUMB) $(SRC_THUMB)),) @echo Assembler Options..... $(XCC) -c $(CPPFLAGS) $(CFLAGS) $(SRCFLAGS) $(@:.o=.s) -o $(OBJDIR)/$@ endif + ifneq ($(OPT_MAKE_LIB),yes) @echo Linker Options........ $(XLD) $(LDFLAGS) $(OBJDIR)/$@ -o $(EXEFILE) + endif @echo . endif @@ -275,6 +279,18 @@ ifeq ($(OPT_COPY_EXE),yes) @cp $@ . endif +$(LIBFILE): $(OBJS_THUMB) $(OBJS_NOTHUMB) +ifeq ($(OPT_VERBOSE_COMPILE),yes) + @echo . + $(XAR) -r $@ $^ +else + @echo Creating Library $@ + @$(XAR) -r $@ $^ +endif +ifeq ($(OPT_COPY_EXE),yes) + @cp $@ . +endif + %.hex: %.elf ifeq ($(OPT_VERBOSE_COMPILE),yes) $(XOC) -O ihex $< $@ @@ -287,7 +303,7 @@ ifeq ($(OPT_COPY_EXE),yes) endif %.bin: %.elf -ifeq ($(USE_VERBOSE_COMPILE),yes) +ifeq ($(OPT_VERBOSE_COMPILE),yes) $(XOC) -O binary $< $@ else @echo Creating $@ @@ -298,7 +314,7 @@ ifeq ($(OPT_COPY_EXE),yes) endif %.dmp: %.elf -ifeq ($(USE_VERBOSE_COMPILE),yes) +ifeq ($(OPT_VERBOSE_COMPILE),yes) $(XOD) -x --syms $< > $@ else @echo Creating $@ @@ -311,7 +327,7 @@ endif # Goodness knows why we would want this. gcov: -mkdir gcov - $(COV) -u $(subst /,\,$(SRC)) + $(COV) -u $(subst /,\,$(SRC_NOTHUMB) $(SRC_THUMB)) -mv *.gcov ./gcov # Include the dependency files, should be the last of the makefile except for clean diff --git a/tools/gmake_scripts/cpu_at91sam7.mk b/tools/gmake_scripts/cpu_at91sam7.mk new file mode 100644 index 00000000..fe5d528d --- /dev/null +++ b/tools/gmake_scripts/cpu_at91sam7.mk @@ -0,0 +1,20 @@ +# +# This file is subject to the terms of the GFX License. If a copy of +# the license was not distributed with this file, you can obtain one at: +# +# http://ugfx.org/license.html +# + +# +# See readme.txt for the make API +# + +# Requirements: +# +# NONE +# + +SRCFLAGS += -mcpu=arm7tdmi +LDFLAGS += -mcpu=arm7tdmi +#SRCFLAGS += -mcpu=arm7tdmi -mabi=apcs-gnu +#LDFLAGS += -mcpu=arm7tdmi -Wl,--no-warn-mismatch diff --git a/tools/gmake_scripts/cpu_stm32m4.mk b/tools/gmake_scripts/cpu_stm32m4.mk new file mode 100644 index 00000000..9e105a36 --- /dev/null +++ b/tools/gmake_scripts/cpu_stm32m4.mk @@ -0,0 +1,19 @@ +# +# This file is subject to the terms of the GFX License. If a copy of +# the license was not distributed with this file, you can obtain one at: +# +# http://ugfx.org/license.html +# + +# +# See readme.txt for the make API +# + +# Requirements: +# +# NONE +# + +SRCFLAGS += -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -falign-functions=16 +LDFLAGS += -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 +LIBS += m diff --git a/tools/gmake_scripts/cpu_x64.mk b/tools/gmake_scripts/cpu_x64.mk new file mode 100644 index 00000000..5013e260 --- /dev/null +++ b/tools/gmake_scripts/cpu_x64.mk @@ -0,0 +1,18 @@ +# +# This file is subject to the terms of the GFX License. If a copy of +# the license was not distributed with this file, you can obtain one at: +# +# http://ugfx.org/license.html +# + +# +# See readme.txt for the make API +# + +# Requirements: +# +# NONE +# + +SRCFLAGS += -m64 +LDFLAGS += -m64 diff --git a/tools/gmake_scripts/cpu_x86.mk b/tools/gmake_scripts/cpu_x86.mk new file mode 100644 index 00000000..0e3e5af1 --- /dev/null +++ b/tools/gmake_scripts/cpu_x86.mk @@ -0,0 +1,18 @@ +# +# This file is subject to the terms of the GFX License. If a copy of +# the license was not distributed with this file, you can obtain one at: +# +# http://ugfx.org/license.html +# + +# +# See readme.txt for the make API +# + +# Requirements: +# +# NONE +# + +SRCFLAGS += -m32 +LDFLAGS += -m32 diff --git a/tools/gmake_scripts/os_chibios.mk b/tools/gmake_scripts/os_chibios.mk index b8205dd3..f583d186 100644 --- a/tools/gmake_scripts/os_chibios.mk +++ b/tools/gmake_scripts/os_chibios.mk @@ -12,6 +12,7 @@ # CHIBIOS: The location of the ChibiOS code eg CHIBIOS=../chibios # CHIBIOS_PLATFORM The name of the ChibiOS platform eg CHIBIOS_PLATFORM=AT91SAM7 # CHIBIOS_PORT The name of the ChibiOS port eg CHIBIOS_PORT=GCC/ARM/AT91SAM7 +# CHIBIOS_CPUCLASS The class of the CPU. Only required for ChibiOS v3 eg CHIBIOS_CPUCLASS=ARMCMx # # Optional: @@ -20,6 +21,8 @@ # CHIBIOS_BOARD The name of the ChibiOS board eg CHIBIOS_BOARD=OLIMEX_SAM7_EX256 - if not specified you must include equivalent code yourself # CHIBIOS_STM32LIB Use the STM32 library source for drivers instead of native drivers (yes or no) - default no # CHIBIOS_VERSION Which version of ChibiOS is this (2 or 3) - default is 2 +# CHIBIOS_PROCESS_STACKSIZE Size of the ChibiOS process stack. Only useful if the link script supports it - default is 0x400 +# CHIBIOS_EXCEPTIONS_STACKSIZE Size of the ChibiOS exceptopms stack. Only useful if the link script supports it - default is 0x400 # PATHLIST += CHIBIOS @@ -29,23 +32,40 @@ ifeq ($(CHIBIOS_VERSION),3) include $(CHIBIOS)/os/hal/osal/rt/osal.mk include $(CHIBIOS)/os/hal/ports/$(CHIBIOS_PLATFORM)/platform.mk include $(CHIBIOS)/os/rt/rt.mk - include $(CHIBIOS)/os/rt/ports/$(CHIBIOS_PORT).mk + include $(CHIBIOS)/os/rt/ports/$(CHIBIOS_CPUCLASS)/compilers/GCC/mk/port_$(CHIBIOS_PORT).mk + ifneq ($(CHIBIOS_BOARD),) + include $(CHIBIOS)/os/hal/boards/$(CHIBIOS_BOARD)/board.mk + endif + LIBPATH += $(CHIBIOS)/os/common/ports/$(CHIBIOS_CPUCLASS)/compilers/GCC else include $(CHIBIOS)/os/hal/hal.mk include $(CHIBIOS)/os/hal/platforms/$(CHIBIOS_PLATFORM)/platform.mk include $(CHIBIOS)/os/kernel/kernel.mk include $(CHIBIOS)/os/ports/$(CHIBIOS_PORT)/port.mk + ifneq ($(CHIBIOS_BOARD),) + include $(CHIBIOS)/boards/$(CHIBIOS_BOARD)/board.mk + endif endif -ifneq ($(CHIBIOS_BOARD),) - include $(CHIBIOS)/boards/$(CHIBIOS_BOARD)/board.mk -endif ifeq ($(LDSCRIPT),) ifneq ($(CHIBIOS_LDSCRIPT),) LDSCRIPT= $(PORTLD)/$(CHIBIOS_LDSCRIPT) endif endif +ifneq ($(LDSCRIPT),) + ifeq ($(CHIBIOS_PROCESS_STACKSIZE),) + LDFLAGS += -Wl,--defsym=__process_stack_size__=0x400 + else + LDFLAGS += -Wl,--defsym=__process_stack_size__=$(CHIBIOS_PROCESS_STACKSIZE) + endif + ifeq ($(CHIBIOS_EXCEPTIONS_STACKSIZE),) + LDFLAGS += -Wl,--defsym=__main_stack_size__=0x400 + else + LDFLAGS += -Wl,--defsym=__main_stack_size__=$(CHIBIOS_EXCEPTIONS_STACKSIZE) + endif +endif + ifeq ($(CHIBIOS_STM32LIB),yes) include $(CHIBIOS)/ext/stm32lib/stm32lib.mk SRC += $(STM32SRC) @@ -53,7 +73,7 @@ ifeq ($(CHIBIOS_STM32LIB),yes) INCPATH += $(STM32INC) endif -INCPATH += $(PORTINC) $(KERNINC) $(TESTINC) \ +INCPATH += $(PORTINC) $(KERNINC) $(TESTINC) $(OSALINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) SRC += $(PORTSRC) \ $(KERNSRC) \ @@ -61,4 +81,5 @@ SRC += $(PORTSRC) \ $(HALSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ + $(OSALSRC) \ $(PORTASM) diff --git a/tools/gmake_scripts/readme.txt b/tools/gmake_scripts/readme.txt index 48ac2c9e..eec7dd95 100644 --- a/tools/gmake_scripts/readme.txt +++ b/tools/gmake_scripts/readme.txt @@ -8,6 +8,7 @@ All make script files in this directory apply the following rules and assumption Input Variables (all optional unless otherwise specified) ---------------------------- +OPT_MAKE_LIB=no|yes - Make a library instead of an program = default no OPT_VERBOSE_COMPILE=no|yes - Turn on full compile messages - default no OPT_GENERATE_LISTINGS=no|yes - Generate listing files - default no OPT_GENERATE_MAP=no|yes - Generate a map file - default no @@ -29,6 +30,7 @@ XLD - Linker - default is "$(ARCH)gcc" XOC - Object Copy - default is "$(ARCH)objcopy" XOD - Object Dump - default is "$(ARCH)objdump" XSZ - Report binary dump details - default is "$(ARCH)size" +XAR - Library archiver - default is "$(ARCH)ar" SRCFLAGS - Compiler defines for c, c++ and assembler files - default is "" CFLAGS - C specific compiler defines - default is "" @@ -61,6 +63,8 @@ Targets ---------------------------- all +lib +exe clean Debug cleanDebug From df0a966fc2f221adfb133eca1a52e6f2c936368d Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 6 Oct 2014 15:57:13 +1000 Subject: [PATCH 39/87] Update buildfonts.sh to match change to fonts.h --- src/gdisp/fonts/build_fonts.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gdisp/fonts/build_fonts.sh b/src/gdisp/fonts/build_fonts.sh index b40f7fb6..615fed19 100644 --- a/src/gdisp/fonts/build_fonts.sh +++ b/src/gdisp/fonts/build_fonts.sh @@ -63,8 +63,7 @@ build fixed_10x20.bdf fixed_10x20 bwfont build fixed_7x14.bdf fixed_7x14 bwfont build fixed_5x8.bdf fixed_5x8 bwfont -echo > fonts.h -echo '#include ' >> fonts.h +echo '#include "gfx.h"' > fonts.h for file in *.c; do echo >> fonts.h noext="${file%.*}" From 50dfad6f038ed5d20a357f634a70b23c570b26ed Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 6 Oct 2014 17:04:47 +1000 Subject: [PATCH 40/87] Tidy ups --- .../Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/Makefile | 1 - .../Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/Makefile | 1 - boards/base/Olimex-SAM7EX256-GE8/example/Makefile | 1 - 3 files changed, 3 deletions(-) diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/Makefile b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/Makefile index 8baa399f..c4938d5f 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/Makefile +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_2.x/Makefile @@ -6,7 +6,6 @@ # General settings # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables - OPT_NATIVEOS = chibios OPT_OS = chibios OPT_THUMB = yes OPT_LINK_OPTIMIZE = yes diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/Makefile b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/Makefile index 55778283..875f79b1 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/Makefile +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/example_chibios_3.x/Makefile @@ -6,7 +6,6 @@ # General settings # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables - OPT_NATIVEOS = chibios OPT_OS = chibios OPT_THUMB = yes OPT_LINK_OPTIMIZE = yes diff --git a/boards/base/Olimex-SAM7EX256-GE8/example/Makefile b/boards/base/Olimex-SAM7EX256-GE8/example/Makefile index fe0e5178..652d43dd 100644 --- a/boards/base/Olimex-SAM7EX256-GE8/example/Makefile +++ b/boards/base/Olimex-SAM7EX256-GE8/example/Makefile @@ -6,7 +6,6 @@ # General settings # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables - OPT_NATIVEOS = chibios OPT_OS = chibios OPT_THUMB = yes OPT_LINK_OPTIMIZE = yes From 5a3f22617b02ec366461be21765e636e6bdd0222 Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 6 Oct 2014 17:05:16 +1000 Subject: [PATCH 41/87] Add support for FreeRTOS into make system --- .../Drivers => FreeRTOS}/bcm2835_intc.h | 0 .../main.c => FreeRTOS/freertos_main.c} | 34 ++---- .../Drivers => FreeRTOS}/gpio.c | 0 .../Drivers => FreeRTOS}/gpio.h | 0 .../Drivers => FreeRTOS}/interrupts.c | 0 .../Drivers => FreeRTOS}/interrupts.h | 0 .../Drivers => FreeRTOS}/mmio.h | 0 .../raspberrypi.ld | 0 .../{example-FreeRTOS => FreeRTOS}/startup.s | 4 +- .../Drivers => FreeRTOS}/uart.c | 0 .../Drivers => FreeRTOS}/uart.h | 0 .../RaspberryPi/example-FreeRTOS/Makefile | 110 ++++++++---------- tools/gmake_scripts/cpu_armv6.mk | 18 +++ tools/gmake_scripts/cpu_raspberrypi.mk | 18 +++ tools/gmake_scripts/os_freertos.mk | 36 ++++++ tools/gmake_scripts/readme.txt | 2 +- 16 files changed, 128 insertions(+), 94 deletions(-) rename boards/base/RaspberryPi/{example-FreeRTOS/Drivers => FreeRTOS}/bcm2835_intc.h (100%) rename boards/base/RaspberryPi/{example-FreeRTOS/main.c => FreeRTOS/freertos_main.c} (64%) rename boards/base/RaspberryPi/{example-FreeRTOS/Drivers => FreeRTOS}/gpio.c (100%) rename boards/base/RaspberryPi/{example-FreeRTOS/Drivers => FreeRTOS}/gpio.h (100%) rename boards/base/RaspberryPi/{example-FreeRTOS/Drivers => FreeRTOS}/interrupts.c (100%) rename boards/base/RaspberryPi/{example-FreeRTOS/Drivers => FreeRTOS}/interrupts.h (100%) rename boards/base/RaspberryPi/{example-FreeRTOS/Drivers => FreeRTOS}/mmio.h (100%) rename boards/base/RaspberryPi/{example-FreeRTOS => FreeRTOS}/raspberrypi.ld (100%) rename boards/base/RaspberryPi/{example-FreeRTOS => FreeRTOS}/startup.s (96%) rename boards/base/RaspberryPi/{example-FreeRTOS/Drivers => FreeRTOS}/uart.c (100%) rename boards/base/RaspberryPi/{example-FreeRTOS/Drivers => FreeRTOS}/uart.h (100%) create mode 100644 tools/gmake_scripts/cpu_armv6.mk create mode 100644 tools/gmake_scripts/cpu_raspberrypi.mk create mode 100644 tools/gmake_scripts/os_freertos.mk diff --git a/boards/base/RaspberryPi/example-FreeRTOS/Drivers/bcm2835_intc.h b/boards/base/RaspberryPi/FreeRTOS/bcm2835_intc.h similarity index 100% rename from boards/base/RaspberryPi/example-FreeRTOS/Drivers/bcm2835_intc.h rename to boards/base/RaspberryPi/FreeRTOS/bcm2835_intc.h diff --git a/boards/base/RaspberryPi/example-FreeRTOS/main.c b/boards/base/RaspberryPi/FreeRTOS/freertos_main.c similarity index 64% rename from boards/base/RaspberryPi/example-FreeRTOS/main.c rename to boards/base/RaspberryPi/FreeRTOS/freertos_main.c index 3a64a7bb..821a679b 100644 --- a/boards/base/RaspberryPi/example-FreeRTOS/main.c +++ b/boards/base/RaspberryPi/FreeRTOS/freertos_main.c @@ -3,43 +3,23 @@ #include "Drivers/interrupts.h" -#include "gfx.h" +extern int main(void); -static void displayTask(void *pvParameters) { - coord_t width, height; - // Get the screen size - width = gdispGetWidth(); - height = gdispGetHeight(); - - // Code Here - gdispDrawBox(10, 10, width/2, height/2, Yellow); - gdispFillArea(width/2, height/2, width/2-10, height/2-10, Blue); - gdispDrawLine(5, 30, width-50, height-40, Red); - - while(1) - { - vTaskDelay(1000); - } - - return; +static void mainTask(void *pvParameters) { + (void) pvParameters; + main(); } /** * This is the systems main entry, some call it a boot thread. - * - * -- Absolutely nothing wrong with this being called main(), just it doesn't have - * -- the same prototype as you'd see in a linux program. **/ -int main(void) { +int FreeRTOS_Main(void) { DisableInterrupts(); InitInterruptController(); - // Initialize and clear the display - gfxInit(); - - xTaskCreate(displayTask, - (portCHAR *)"Display Task", + xTaskCreate(mainTask, + (portCHAR *)"Main Task", 128, NULL, 0, diff --git a/boards/base/RaspberryPi/example-FreeRTOS/Drivers/gpio.c b/boards/base/RaspberryPi/FreeRTOS/gpio.c similarity index 100% rename from boards/base/RaspberryPi/example-FreeRTOS/Drivers/gpio.c rename to boards/base/RaspberryPi/FreeRTOS/gpio.c diff --git a/boards/base/RaspberryPi/example-FreeRTOS/Drivers/gpio.h b/boards/base/RaspberryPi/FreeRTOS/gpio.h similarity index 100% rename from boards/base/RaspberryPi/example-FreeRTOS/Drivers/gpio.h rename to boards/base/RaspberryPi/FreeRTOS/gpio.h diff --git a/boards/base/RaspberryPi/example-FreeRTOS/Drivers/interrupts.c b/boards/base/RaspberryPi/FreeRTOS/interrupts.c similarity index 100% rename from boards/base/RaspberryPi/example-FreeRTOS/Drivers/interrupts.c rename to boards/base/RaspberryPi/FreeRTOS/interrupts.c diff --git a/boards/base/RaspberryPi/example-FreeRTOS/Drivers/interrupts.h b/boards/base/RaspberryPi/FreeRTOS/interrupts.h similarity index 100% rename from boards/base/RaspberryPi/example-FreeRTOS/Drivers/interrupts.h rename to boards/base/RaspberryPi/FreeRTOS/interrupts.h diff --git a/boards/base/RaspberryPi/example-FreeRTOS/Drivers/mmio.h b/boards/base/RaspberryPi/FreeRTOS/mmio.h similarity index 100% rename from boards/base/RaspberryPi/example-FreeRTOS/Drivers/mmio.h rename to boards/base/RaspberryPi/FreeRTOS/mmio.h diff --git a/boards/base/RaspberryPi/example-FreeRTOS/raspberrypi.ld b/boards/base/RaspberryPi/FreeRTOS/raspberrypi.ld similarity index 100% rename from boards/base/RaspberryPi/example-FreeRTOS/raspberrypi.ld rename to boards/base/RaspberryPi/FreeRTOS/raspberrypi.ld diff --git a/boards/base/RaspberryPi/example-FreeRTOS/startup.s b/boards/base/RaspberryPi/FreeRTOS/startup.s similarity index 96% rename from boards/base/RaspberryPi/example-FreeRTOS/startup.s rename to boards/base/RaspberryPi/FreeRTOS/startup.s index 286f396c..d865439f 100644 --- a/boards/base/RaspberryPi/example-FreeRTOS/startup.s +++ b/boards/base/RaspberryPi/FreeRTOS/startup.s @@ -4,7 +4,7 @@ .extern vFreeRTOS_ISR .extern vPortYieldProcessor .extern DisableInterrupts -.extern main +.extern FreeRTOS_Main .section .init .globl _start ;; @@ -79,7 +79,7 @@ zero_loop: ;@ mov sp,#0x1000000 - b main ;@ We're ready?? Lets start main execution! + b FreeRTOS_Main ;@ We're ready?? Lets start main execution! .section .text undefined_instruction: diff --git a/boards/base/RaspberryPi/example-FreeRTOS/Drivers/uart.c b/boards/base/RaspberryPi/FreeRTOS/uart.c similarity index 100% rename from boards/base/RaspberryPi/example-FreeRTOS/Drivers/uart.c rename to boards/base/RaspberryPi/FreeRTOS/uart.c diff --git a/boards/base/RaspberryPi/example-FreeRTOS/Drivers/uart.h b/boards/base/RaspberryPi/FreeRTOS/uart.h similarity index 100% rename from boards/base/RaspberryPi/example-FreeRTOS/Drivers/uart.h rename to boards/base/RaspberryPi/FreeRTOS/uart.h diff --git a/boards/base/RaspberryPi/example-FreeRTOS/Makefile b/boards/base/RaspberryPi/example-FreeRTOS/Makefile index c1751204..a8d64ad0 100644 --- a/boards/base/RaspberryPi/example-FreeRTOS/Makefile +++ b/boards/base/RaspberryPi/example-FreeRTOS/Makefile @@ -1,73 +1,55 @@ -# build environment -PREFIX ?= /your compiler path/gcc-arm-none-eabi-4_8-2014q1 -ARCH ?= $(PREFIX)/bin/arm-none-eabi +# Possible Targets: all clean Debug cleanDebug Release cleanRelease -CC = ${ARCH}-gcc -CPP = ${ARCH}-g++ -AS = ${ARCH}-as -LD = ${ARCH}-ld -AR = ${ARCH}-ar -OBJCOPY = ${ARCH}-objcopy +############################################################################################## +# Settings +# -PLATFORM = raspi -LINKER_SCRIPT = raspberrypi.ld +# General settings + # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables + OPT_OS = freertos + OPT_THUMB = yes + OPT_LINK_OPTIMIZE = yes + # For the raspberry pi we can either use the generic armv6 cpu or the highly optimized raspberrypi settings + OPT_CPU = raspberrypi -CFLAGS = -march=armv6z -g -Wall -Wextra -ASFLAGS = -g +# uGFX settings + # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables + GFXLIB = ../uGFX + GFXBOARD = RaspberryPi + GFXDEMO = modules/gdisp/basics -CFLAGS_FOR_TARGET = #-mcpu=arm1176jzf-s -ASFLAGS_FOR_TARGET = #-mcpu=arm1176jzf-s -LDFLAGS = #--error-unresolved-symbols +# FreeRTOS settings +ifeq ($(OPT_OS),freertos) + # See $(GFXLIB)/tools/gmake_scripts/os_freertos.mk for the list of variables + FREERTOS = ../FreeRTOS + FREERTOS_BOARD = RaspberryPi + FREERTOS_MODULES = $(GFXLIB)/boards/base/RaspberryPi/FreeRTOS + FREERTOS_LDSCRIPT = $(GFXLIB)/boards/base/RaspberryPi/FreeRTOS/raspberrypi.ld +endif -GFXLIB := ../uGFX -include $(GFXLIB)/gfx.mk -include $(GFXLIB)/drivers/gdisp/framebuffer/driver.mk +############################################################################################## +# Set these for your project +# -OSLIB := ../FreeRTOS -MODULES := $(OSLIB)/Source/portable/GCC/RaspberryPi -MODULES += $(OSLIB)/Source/portable/MemMang -MODULES += $(OSLIB)/Source -MODULES += Drivers - -SRC_DIR := $(MODULES) -INC_DIR := $(addsuffix /include,$(SRC_DIR)) -BUILD_DIR := $(addsuffix /build,$(SRC_DIR)) - -INCLUDEDIRS := $(OSLIB)/Source/portable/GCC/RaspberryPi -INCLUDEDIRS += $(OSLIB)/Source/include -INCLUDEDIRS += Drivers -INCLUDEDIRS += $(GFXINC) - -INCLUDES := $(addprefix -I,$(INCLUDEDIRS)) - -ASRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.s)) -AOBJ := $(ASRC:.s=.o) -CSRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c)) -CSRC += $(GFXSRC) -COBJ := $(CSRC:.c=.o) - -vpath %.c $(SRC_DIR) -vpath %.cpp $(SRC_DIR) -vpath %.s $(SRC_DIR) - -%.o: %.c - $(CC) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) -c -o $*.o $< - -%.o: %.s - $(AS) $(ASFLAGS_FOR_TARGET) $(INCLUDES) $(ASFLAGS) -o $*.o $< - -OBJ = $(AOBJ) $(COBJ) - -bin/kernel.img: bin/kernel.elf - ${OBJCOPY} -O binary $< $@ - -bin/kernel.elf: LDFLAGS += -L "$(PREFIX)/lib/gcc/arm-none-eabi/4.8.3" -lgcc -bin/kernel.elf: LDFLAGS += -L "$(PREFIX)/arm-none-eabi/lib" -lc -bin/kernel.elf: $(OBJ) - ${LD} $(OBJ) -Map bin/kernel.map -o $@ -T $(LINKER_SCRIPT) ${LDFLAGS} - -clean: - rm -f bin/*.elf bin/*.img bin/*.map $(OBJ) +ARCH = arm-none-eabi- +SRCFLAGS = -ggdb -O0 +CFLAGS = +CXXFLAGS = -fno-rtti +ASFLAGS = +LDFLAGS = +SRC = +OBJS = +DEFS = +LIBS = +INCPATH = +LIBPATH = +############################################################################################## +# These should be at the end +# +include $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk +include $(GFXLIB)/tools/gmake_scripts/os_$(OPT_OS).mk +include $(GFXLIB)/tools/gmake_scripts/compiler_gcc.mk +# *** EOF *** diff --git a/tools/gmake_scripts/cpu_armv6.mk b/tools/gmake_scripts/cpu_armv6.mk new file mode 100644 index 00000000..0fa5867e --- /dev/null +++ b/tools/gmake_scripts/cpu_armv6.mk @@ -0,0 +1,18 @@ +# +# This file is subject to the terms of the GFX License. If a copy of +# the license was not distributed with this file, you can obtain one at: +# +# http://ugfx.org/license.html +# + +# +# See readme.txt for the make API +# + +# Requirements: +# +# NONE +# + +SRCFLAGS += -march=armv6 -mfpu=vfp -mfloat-abi=hard +LDFLAGS += -march=armv6 -mfpu=vfp -mfloat-abi=hard diff --git a/tools/gmake_scripts/cpu_raspberrypi.mk b/tools/gmake_scripts/cpu_raspberrypi.mk new file mode 100644 index 00000000..b31c35e9 --- /dev/null +++ b/tools/gmake_scripts/cpu_raspberrypi.mk @@ -0,0 +1,18 @@ +# +# This file is subject to the terms of the GFX License. If a copy of +# the license was not distributed with this file, you can obtain one at: +# +# http://ugfx.org/license.html +# + +# +# See readme.txt for the make API +# + +# Requirements: +# +# NONE +# + +SRCFLAGS += -march=armv6zk -mcpu=arm1176jzf-s -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard +LDFLAGS += -march=armv6zk -mcpu=arm1176jzf-s -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard diff --git a/tools/gmake_scripts/os_freertos.mk b/tools/gmake_scripts/os_freertos.mk new file mode 100644 index 00000000..5cbd5be0 --- /dev/null +++ b/tools/gmake_scripts/os_freertos.mk @@ -0,0 +1,36 @@ +# +# This file is subject to the terms of the GFX License. If a copy of +# the license was not distributed with this file, you can obtain one at: +# +# http://ugfx.org/license.html +# + +# See readme.txt for the make API + +# Requirements: +# +# FREERTOS: The location of the FreeRTOS code eg FREERTOS=../FreeRTOS +# FREERTOS_BOARD The board name eg FREERTOS_BOARD=RaspberryPi +# + +# Optional: +# +# FREERTOS_MODULES A list of directories containing FreeRTOS source (eg drivers, startup etc) - default is "" +# FREERTOS_LDSCRIPT The loader script - default is "" +# + +PATHLIST += FREERTOS + +FREERTOS_MODULES += $(FREERTOS)/Source/portable/GCC/$(FREERTOS_BOARD) +FREERTOS_MODULES += $(FREERTOS)/Source/portable/MemMang +FREERTOS_MODULES += $(FREERTOS)/Source + +INCPATH += $(FREERTOS)/Source/portable/GCC/$(FREERTOS_BOARD) \ + $(FREERTOS)/Source/include + +SRC += $(foreach sdir,$(FREERTOS_MODULES),$(wildcard $(sdir)/*.s)) +SRC += $(foreach sdir,$(FREERTOS_MODULES),$(wildcard $(sdir)/*.c)) + +ifeq ($(LDSCRIPT),) + LDSCRIPT= $(FREERTOS_LDSCRIPT) +endif diff --git a/tools/gmake_scripts/readme.txt b/tools/gmake_scripts/readme.txt index eec7dd95..67206ed9 100644 --- a/tools/gmake_scripts/readme.txt +++ b/tools/gmake_scripts/readme.txt @@ -16,7 +16,7 @@ OPT_COPY_EXE=no|yes - Copy the final program to the local project directory - OPT_NONSTANDARD_FLAGS=no - Turn off adding the standard compiler language flags - default no OPT_LINK_OPTIMIZE=no - Remove unused code/data during link - default no OPT_OS=win32|win32.chibios|linux|osx|chibios|freertos|ecos|raw32|rawrtos - Mandatory: The operating system -OPT_CPU=x86|x64|stm32m4|at91sam7 - Add some cpu dependant flags +OPT_CPU=x86|x64|stm32m4|at91sam7|armv6|raspberrypi - Add some cpu dependant flags BUILDDIR - Build Directory - default is ".build" or "bin/Debug" or "bin/Release" depending on the target PROJECT - Project Name - default is the name of the project directory From 6abd4d71d3fda52ed4d67077ac86130f7d666844 Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 6 Oct 2014 18:06:43 +1000 Subject: [PATCH 42/87] Add eCos to the new build system - untested! --- .../example/Makefile | 186 ++++-------------- .../example/readme.txt | 5 +- tools/gmake_scripts/os_ecos.mk | 33 ++++ 3 files changed, 71 insertions(+), 153 deletions(-) create mode 100644 tools/gmake_scripts/os_ecos.mk diff --git a/boards/base/eCos-Synthetic-Framebuffer/example/Makefile b/boards/base/eCos-Synthetic-Framebuffer/example/Makefile index e30e1c92..af590f16 100644 --- a/boards/base/eCos-Synthetic-Framebuffer/example/Makefile +++ b/boards/base/eCos-Synthetic-Framebuffer/example/Makefile @@ -1,165 +1,51 @@ -# -# !!!! Do NOT edit this makefile with an editor which replace tabs by spaces !!!! -# -############################################################################################## -# -# On command line: -# -# make INSTALL_DIR=/path/to/ecos/install all = Create project -# -# make clean = Clean project files. -# -# To rebuild project do "make clean" and "make all". -# +# Possible Targets: all clean Debug cleanDebug Release cleanRelease ############################################################################################## -# Start of default section +# Settings # -INSTALL_DIR=$$(INSTALL_DIR) # override on make command line +# General settings + # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables + OPT_OS = ecos + OPT_LINK_OPTIMIZE = yes + OPT_CPU = x86 -include $(INSTALL_DIR)/include/pkgconf/ecos.mak +# uGFX settings + # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables + GFXLIB = ../uGFX + GFXBOARD = eCos-Synthetic-Framebuffer + GFXDEMO = modules/gdisp/basics -CC = $(ECOS_COMMAND_PREFIX)gcc -AS = $(CC) -x assembler-with-cpp -CXX = $(CC) -LD = $(CC) -CFLAGS = -I$(INSTALL_DIR)/include -CXXFLAGS = $(CFLAGS) -g -LDFLAGS = -nostartfiles -L$(INSTALL_DIR)/lib -Ttarget.ld - -# List all default C defines here, like -D_DEBUG=1 -DDEFS = - -# List all default ASM defines here, like -D_DEBUG=1 -DADEFS = - -# List all default directories to look for include files here -DINCDIR = - -# List the default directory to look for the libraries here -DLIBDIR = - -# List all default libraries here -DLIBS = - -# -# End of default section -############################################################################################## - -############################################################################################## -# Start of user section -# - -# Define project name here -PROJECT = ugfx_over_ecos - -# Imported source files and paths for uGFX -GFXLIB = ../ugfx - -include ${GFXLIB}/gfx.mk -include ${GFXLIB}/boards/base/eCos-Synthetic-Framebuffer/board.mk - -# Where is our source code - alter these for your project. -# Either just include the demo makefile or add your own definitions -include $(GFXLIB)/demos/modules/gdisp/basics/demo.mk - -#MYFILES = -#MYCSRC = -#MYDEFS = - -# List all user C define here, like -D_DEBUG=1 -UDEFS = $(MYDEFS) $(GFXDEFS) - -# Define ASM defines here -UADEFS = - -# List C source files here -SRC = $(GFXSRC) \ - $(MYCSRC) - -# List ASM source files here -ASRC = - -# List all user directories here -UINCDIR = $(MYFILES) $(GFXINC) - -# List the user directory to look for the libraries here -ULIBDIR = - -# List all user libraries here -ULIBS = - -# Define optimisation level here -OPT = -ggdb -O0 -fomit-frame-pointer - -# -# End of user defines -############################################################################################## - -INCDIR = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR)) -LIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR)) -DEFS = $(DDEFS) $(UDEFS) -ADEFS = $(DADEFS) $(UADEFS) -OBJS = $(ASRC:.s=.o) $(SRC:.c=.o) -LIBS = $(DLIBS) $(ULIBS) - -ASFLAGS = -Wa,-amhls=$(<:.s=.lst) $(ADEFS) -CPFLAGS = $(OPT) -Wall -Wextra -Wstrict-prototypes -fverbose-asm $(DEFS) - -ifeq ($(HOST_OSX),yes) - ifeq ($(OSX_SDK),) - OSX_SDK = /Developer/SDKs/MacOSX10.7.sdk - endif - ifeq ($(OSX_ARCH),) - OSX_ARCH = -mmacosx-version-min=10.3 -arch i386 - endif - - CPFLAGS += -isysroot $(OSX_SDK) $(OSX_ARCH) - LDFLAGS = -Wl -Map=$(PROJECT).map,-syslibroot,$(OSX_SDK),$(LIBDIR) - LIBS += $(OSX_ARCH) -else - # Linux, or other - CPFLAGS += -m32 -Wa,-alms=$(<:.c=.lst) -I$(INSTALL_DIR)/include - LDFLAGS = -g -nostdlib -m32 -Wl,-Map=$(PROJECT).map,--cref,--no-warn-mismatch $(LIBDIR) -nostartfiles -L$(INSTALL_DIR)/lib -Ttarget.ld +# ECOS settings +ifeq ($(OPT_OS),ecos) + # See $(GFXLIB)/tools/gmake_scripts/os_ecos.mk for the list of variables + FREERTOS = ../eCos + ECOS_LDSCRIPT = target.ld endif -# Generate dependency information -CPFLAGS += -MD -MP -MF .dep/$(@F).d - -# -# makefile rules +############################################################################################## +# Set these for your project # -all: $(OBJS) $(PROJECT) +ARCH = $(ECOS_COMMAND_PREFIX) +SRCFLAGS = -ggdb -O0 +CFLAGS = +CXXFLAGS = -fno-rtti +ASFLAGS = +LDFLAGS = -%.o : %.c - $(CC) -c $(CPFLAGS) -I . $(INCDIR) $< -o $@ - -%.o : %.s - $(AS) -c $(ASFLAGS) $< -o $@ - -$(PROJECT): $(OBJS) - $(CC) $(OBJS) $(LDFLAGS) $(LIBS) -o $@ - -gcov: - -mkdir gcov - $(COV) -u $(subst /,\,$(SRC)) - -mv *.gcov ./gcov - -clean: - -rm -f $(OBJS) - -rm -f $(PROJECT) - -rm -f $(PROJECT).map - -rm -f $(SRC:.c=.c.bak) - -rm -f $(SRC:.c=.lst) - -rm -f $(ASRC:.s=.s.bak) - -rm -f $(ASRC:.s=.lst) - -rm -fR .dep +SRC = +OBJS = +DEFS = +LIBS = +INCPATH = +LIBPATH = +############################################################################################## +# These should be at the end # -# Include the dependency files, should be the last of the makefile -# --include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) +include $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk +include $(GFXLIB)/tools/gmake_scripts/os_$(OPT_OS).mk +include $(GFXLIB)/tools/gmake_scripts/compiler_gcc.mk # *** EOF *** diff --git a/boards/base/eCos-Synthetic-Framebuffer/example/readme.txt b/boards/base/eCos-Synthetic-Framebuffer/example/readme.txt index ca841f5b..6fd1f6ef 100644 --- a/boards/base/eCos-Synthetic-Framebuffer/example/readme.txt +++ b/boards/base/eCos-Synthetic-Framebuffer/example/readme.txt @@ -2,6 +2,5 @@ Copy these files into your own project directory and alter them to suite. Notes: -1/ Look at the MYFILES definition and the MYCSRC definition. -2/ To run please install eCos synthetic framebuffer according to the documentation. -3/ Call application ./ugfx_over_ecos -io \ No newline at end of file +1/ To run please install eCos synthetic framebuffer according to the documentation. +2/ Call application ./ugfx_over_ecos -io \ No newline at end of file diff --git a/tools/gmake_scripts/os_ecos.mk b/tools/gmake_scripts/os_ecos.mk new file mode 100644 index 00000000..b1b74554 --- /dev/null +++ b/tools/gmake_scripts/os_ecos.mk @@ -0,0 +1,33 @@ +# +# This file is subject to the terms of the GFX License. If a copy of +# the license was not distributed with this file, you can obtain one at: +# +# http://ugfx.org/license.html +# + +# See readme.txt for the make API + +# Requirements: +# +# ECOS: The location of the eCos code eg ECOS=../eCos +# + +# Optional: +# +# ECOS_LDSCRIPT The loader script - default is "" +# + +PATHLIST += ECOS + +# Not sure if this variable is needed by the ecos make. +INSTALL_DIR=$(ECOS) + +include $(ECOS)/include/pkgconf/ecos.mak + +INCPATH += $(ECOS)/include +LIBPATH += $(ECOS)/lib +LDFLAGS += -nostdlib + +ifeq ($(LDSCRIPT),) + LDSCRIPT= $(ECOS_LDSCRIPT) +endif From 71a77d64a1244390860010caa31733e40fdba442 Mon Sep 17 00:00:00 2001 From: inmarket Date: Tue, 7 Oct 2014 21:50:25 +1000 Subject: [PATCH 43/87] Bug in ChibiOS compiling with Hardware FPU causing Exceptions on epilogue on clock tick. For now just turn off hardware FPU --- tools/gmake_scripts/cpu_stm32m4.mk | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/gmake_scripts/cpu_stm32m4.mk b/tools/gmake_scripts/cpu_stm32m4.mk index 9e105a36..5acfe8ad 100644 --- a/tools/gmake_scripts/cpu_stm32m4.mk +++ b/tools/gmake_scripts/cpu_stm32m4.mk @@ -14,6 +14,11 @@ # NONE # -SRCFLAGS += -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -falign-functions=16 -LDFLAGS += -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -LIBS += m +#SRCFLAGS += -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -falign-functions=16 +#LDFLAGS += -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -falign-functions=16 +#DEFS += CORTEX_USE_FPU=TRUE +#LIBS += m +SRCFLAGS += -mcpu=cortex-m4 -falign-functions=16 +LDFLAGS += -mcpu=cortex-m4 +DEFS += CORTEX_USE_FPU=FALSE + From 3af0498a4cc4d347221be3e2229da6849a5b2463 Mon Sep 17 00:00:00 2001 From: inmarket Date: Tue, 7 Oct 2014 21:51:15 +1000 Subject: [PATCH 44/87] Replace ChibiOS specific delays with generic uGFX delays in ILI9341 driver --- drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c b/drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c index f27605a7..20b1e270 100644 --- a/drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c +++ b/drivers/gdisp/ILI9341/gdisp_lld_ILI9341.c @@ -89,7 +89,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { acquire_bus(g); write_index(g, 0x01); //software reset - chThdSleepMilliseconds(5); + gfxSleepMilliseconds(5); write_index(g, 0x28); // display off //--------------------------------------------------------- @@ -210,9 +210,9 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { write_data(g, 0x27); write_data(g, 0x00); write_index(g, 0x11); //sleep out - chThdSleepMilliseconds(100); + gfxSleepMilliseconds(100); write_index(g, 0x29); // display on - chThdSleepMilliseconds(100); + gfxSleepMilliseconds(100); // Finish Init post_init_board(g); From ccf05e8c0a789bdedeae14065f14b72ca3811b38 Mon Sep 17 00:00:00 2001 From: inmarket Date: Tue, 7 Oct 2014 21:52:00 +1000 Subject: [PATCH 45/87] Fix bugs in newmouse framework --- src/ginput/ginput_mouse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ginput/ginput_mouse.c b/src/ginput/ginput_mouse.c index 4e2bc2dd..94d5e5ef 100644 --- a/src/ginput/ginput_mouse.c +++ b/src/ginput/ginput_mouse.c @@ -230,7 +230,7 @@ static void GetMouseReading(GMouse *m) { // Is this just movement jitter if (pj->move > 0) { diff = (uint32_t)(r.x - m->r.x) * (uint32_t)(r.x - m->r.x) + (uint32_t)(r.y - m->r.y) * (uint32_t)(r.y - m->r.y); - if (diff > (uint32_t)pj->move * (uint32_t)pj->move) { + if (diff < (uint32_t)pj->move * (uint32_t)pj->move) { r.x = m->r.x; r.y = m->r.y; } @@ -344,7 +344,7 @@ static void MousePoll(void *param) { } static inline void CalibrationCrossClear(GMouse *m, const point *pp) { - gdispGFillArea(m->display, pp->x - CALIBRATION_CROSS_RADIUS, pp->y - CALIBRATION_CROSS_RADIUS, CALIBRATION_CROSS_RADIUS*2, CALIBRATION_CROSS_RADIUS*2, CALIBRATION_BACKGROUND); + gdispGFillArea(m->display, pp->x - CALIBRATION_CROSS_RADIUS, pp->y - CALIBRATION_CROSS_RADIUS, CALIBRATION_CROSS_RADIUS*2+1, CALIBRATION_CROSS_RADIUS*2+1, CALIBRATION_BACKGROUND); } static inline void CalibrationCalculate(GMouse *m, const point *cross, const point *points) { From 5497bf82b3cb886fbcc85e529de3f2bbf8af3433 Mon Sep 17 00:00:00 2001 From: inmarket Date: Tue, 7 Oct 2014 21:53:17 +1000 Subject: [PATCH 46/87] Remove stuff made superfluous by newmouse --- .../multiple/Win32/ginput_lld_mouse_config.h | 38 ------------------- drivers/multiple/X/ginput_lld_mouse_config.h | 38 ------------------- 2 files changed, 76 deletions(-) delete mode 100644 drivers/multiple/Win32/ginput_lld_mouse_config.h delete mode 100644 drivers/multiple/X/ginput_lld_mouse_config.h diff --git a/drivers/multiple/Win32/ginput_lld_mouse_config.h b/drivers/multiple/Win32/ginput_lld_mouse_config.h deleted file mode 100644 index 8263ebed..00000000 --- a/drivers/multiple/Win32/ginput_lld_mouse_config.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _LLD_GINPUT_MOUSE_CONFIG_H -#define _LLD_GINPUT_MOUSE_CONFIG_H - -// This driver supports being both a mouse or a touch device (we don't actually know which it really is) -// When operating in mouse mode a long left button click does not generate a context click. -// When operating in touch mode we allow sloppier clicks etc -#if 1 - #define GINPUT_MOUSE_EVENT_TYPE GEVENT_MOUSE - #define GINPUT_MOUSE_CLICK_TIME TIME_INFINITE // Long click != Context Click - #define GINPUT_MOUSE_NEED_CALIBRATION FALSE - #define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE - #define GINPUT_MOUSE_READ_CYCLES 1 - #define GINPUT_MOUSE_MAX_CALIBRATION_ERROR -1 - #define GINPUT_MOUSE_MAX_CLICK_JITTER 0 - #define GINPUT_MOUSE_MAX_MOVE_JITTER 0 -#else - #define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH - #define GINPUT_MOUSE_CLICK_TIME 700 // Long click = Context Click - #define GINPUT_MOUSE_NEED_CALIBRATION FALSE // Can be set to TRUE just for testing - #define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE - #define GINPUT_MOUSE_READ_CYCLES 1 - #define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 2 - #define GINPUT_MOUSE_MAX_CLICK_JITTER 2 - #define GINPUT_MOUSE_MAX_MOVE_JITTER 2 -#endif - -// This driver supports both an "interrupt" mode, and a polled mode -#define GINPUT_MOUSE_POLL_PERIOD TIME_INFINITE // Interrupt driven by the Window thread -//#define GINPUT_MOUSE_POLL_PERIOD 25 // Poll driven - -#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ diff --git a/drivers/multiple/X/ginput_lld_mouse_config.h b/drivers/multiple/X/ginput_lld_mouse_config.h deleted file mode 100644 index 8263ebed..00000000 --- a/drivers/multiple/X/ginput_lld_mouse_config.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _LLD_GINPUT_MOUSE_CONFIG_H -#define _LLD_GINPUT_MOUSE_CONFIG_H - -// This driver supports being both a mouse or a touch device (we don't actually know which it really is) -// When operating in mouse mode a long left button click does not generate a context click. -// When operating in touch mode we allow sloppier clicks etc -#if 1 - #define GINPUT_MOUSE_EVENT_TYPE GEVENT_MOUSE - #define GINPUT_MOUSE_CLICK_TIME TIME_INFINITE // Long click != Context Click - #define GINPUT_MOUSE_NEED_CALIBRATION FALSE - #define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE - #define GINPUT_MOUSE_READ_CYCLES 1 - #define GINPUT_MOUSE_MAX_CALIBRATION_ERROR -1 - #define GINPUT_MOUSE_MAX_CLICK_JITTER 0 - #define GINPUT_MOUSE_MAX_MOVE_JITTER 0 -#else - #define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH - #define GINPUT_MOUSE_CLICK_TIME 700 // Long click = Context Click - #define GINPUT_MOUSE_NEED_CALIBRATION FALSE // Can be set to TRUE just for testing - #define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE - #define GINPUT_MOUSE_READ_CYCLES 1 - #define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 2 - #define GINPUT_MOUSE_MAX_CLICK_JITTER 2 - #define GINPUT_MOUSE_MAX_MOVE_JITTER 2 -#endif - -// This driver supports both an "interrupt" mode, and a polled mode -#define GINPUT_MOUSE_POLL_PERIOD TIME_INFINITE // Interrupt driven by the Window thread -//#define GINPUT_MOUSE_POLL_PERIOD 25 // Poll driven - -#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ From 08e26fcb909de96b5f6476ae606149e618f75036 Mon Sep 17 00:00:00 2001 From: inmarket Date: Tue, 7 Oct 2014 21:54:19 +1000 Subject: [PATCH 47/87] New newmouse driver for MCU touch --- drivers/ginput/touch/MCU/driver.mk | 5 +- drivers/ginput/touch/MCU/ginput_lld_mouse.c | 80 ------------------- .../MCU/ginput_lld_mouse_board_template.h | 41 ---------- .../MCU/ginput_lld_mouse_config_template.h | 21 ----- drivers/ginput/touch/MCU/gmouse_lld_MCU.c | 50 ++++++++++++ .../touch/MCU/gmouse_lld_MCU_board_template.h | 38 +++++++++ .../MCU/gmouse_lld_MCU_config_template.h | 18 +++++ 7 files changed, 107 insertions(+), 146 deletions(-) delete mode 100644 drivers/ginput/touch/MCU/ginput_lld_mouse.c delete mode 100644 drivers/ginput/touch/MCU/ginput_lld_mouse_board_template.h delete mode 100644 drivers/ginput/touch/MCU/ginput_lld_mouse_config_template.h create mode 100644 drivers/ginput/touch/MCU/gmouse_lld_MCU.c create mode 100644 drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h create mode 100644 drivers/ginput/touch/MCU/gmouse_lld_MCU_config_template.h diff --git a/drivers/ginput/touch/MCU/driver.mk b/drivers/ginput/touch/MCU/driver.mk index e771236a..c8c792b2 100644 --- a/drivers/ginput/touch/MCU/driver.mk +++ b/drivers/ginput/touch/MCU/driver.mk @@ -1,5 +1,2 @@ # List the required driver. -GFXSRC += $(GFXLIB)/drivers/ginput/touch/MCU/ginput_lld_mouse.c - -# Required include directories -GFXINC += $(GFXLIB)/drivers/ginput/touch/MCU +GFXSRC += $(GFXLIB)/drivers/ginput/touch/MCU/gmouse_lld_MCU.c diff --git a/drivers/ginput/touch/MCU/ginput_lld_mouse.c b/drivers/ginput/touch/MCU/ginput_lld_mouse.c deleted file mode 100644 index ad2519e4..00000000 --- a/drivers/ginput/touch/MCU/ginput_lld_mouse.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#include "gfx.h" - -#if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) /*|| defined(__DOXYGEN__)*/ - -#include "src/ginput/driver_mouse.h" - -#include "ginput_lld_mouse_board.h" - -static uint16_t sampleBuf[7]; - -static void filter(void) { - uint16_t temp; - int i,j; - - for(i = 0; i < 4; i++) { - for(j = i; j < 7; j++) { - if(sampleBuf[i] > sampleBuf[j]) { - /* Swap the values */ - temp = sampleBuf[i]; - sampleBuf[i] = sampleBuf[j]; - sampleBuf[j] = temp; - } - } - } -} - -void ginput_lld_mouse_init(void) { - init_board(); -} - -void ginput_lld_mouse_get_reading(MouseReading *pt) { - uint16_t i; - - // Obtain access to the bus - aquire_bus(); - - // Read the ADC for z, x, y and then z again - while(1) { - setup_z(); - for(i = 0; i < 7; i++) - sampleBuf[i] = read_z(); - filter(); - pt->z = (coord_t)sampleBuf[3]; - - setup_x(); - for(i = 0; i < 7; i++) - sampleBuf[i] = read_x(); - filter(); - pt->x = (coord_t)sampleBuf[3]; - - setup_y(); - for(i = 0; i < 7; i++) - sampleBuf[i] = read_y(); - filter(); - pt->y = (coord_t)sampleBuf[3]; - - pt->buttons = pt->z >= 80 ? GINPUT_TOUCH_PRESSED : 0; - - setup_z(); - for(i = 0; i < 7; i++) - sampleBuf[i] = read_z(); - filter(); - i = (coord_t)sampleBuf[3] >= 80 ? GINPUT_TOUCH_PRESSED : 0; - - if (pt->buttons == i) - break; - } - - // Release the bus - release_bus(); -} - -#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */ diff --git a/drivers/ginput/touch/MCU/ginput_lld_mouse_board_template.h b/drivers/ginput/touch/MCU/ginput_lld_mouse_board_template.h deleted file mode 100644 index e213bcb9..00000000 --- a/drivers/ginput/touch/MCU/ginput_lld_mouse_board_template.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _GINPUT_LLD_MOUSE_BOARD_H -#define _GINPUT_LLD_MOUSE_BOARD_H - -static inline void init_board(void) { -} - -static inline void aquire_bus(void) { -} - -static inline void release_bus(void) { -} - -static inline void setup_x(void) { -} - -static inline void setup_y(void) { -} - -static inline void setup_z(void) { - palClearPad(GPIOB, GPIOB_DRIVEA); - palClearPad(GPIOB, GPIOB_DRIVEB); - chThdSleepMilliseconds(2); -} - -static inline uint16_t read_x(void) { -} - -static inline uint16_t read_y(void) { -} - -static inline uint16_t read_z(void) { -} - -#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ diff --git a/drivers/ginput/touch/MCU/ginput_lld_mouse_config_template.h b/drivers/ginput/touch/MCU/ginput_lld_mouse_config_template.h deleted file mode 100644 index 328e6337..00000000 --- a/drivers/ginput/touch/MCU/ginput_lld_mouse_config_template.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _LLD_GINPUT_MOUSE_CONFIG_H -#define _LLD_GINPUT_MOUSE_CONFIG_H - -#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH -#define GINPUT_MOUSE_NEED_CALIBRATION TRUE -#define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE -#define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 12 -#define GINPUT_MOUSE_READ_CYCLES 1 -#define GINPUT_MOUSE_POLL_PERIOD 25 -#define GINPUT_MOUSE_MAX_CLICK_JITTER 2 -#define GINPUT_MOUSE_MAX_MOVE_JITTER 2 -#define GINPUT_MOUSE_CLICK_TIME 500 - -#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ diff --git a/drivers/ginput/touch/MCU/gmouse_lld_MCU.c b/drivers/ginput/touch/MCU/gmouse_lld_MCU.c new file mode 100644 index 00000000..87b39ae4 --- /dev/null +++ b/drivers/ginput/touch/MCU/gmouse_lld_MCU.c @@ -0,0 +1,50 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#include "gfx.h" + +#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE + +#define GMOUSE_DRIVER_VMT GMOUSEVMT_MCU +#include "src/ginput/driver_mouse.h" + +// Get the hardware interface +#include "gmouse_lld_MCU_board.h" + +const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ + { + GDRIVER_TYPE_TOUCH, + GMOUSE_VFLG_TOUCH|GMOUSE_VFLG_CALIBRATE|GMOUSE_VFLG_CAL_TEST + |GMOUSE_VFLG_ONLY_DOWN|GMOUSE_VFLG_POORUPDOWN, + // Extra flags for testing only + //GMOUSE_VFLG_DEFAULTFINGER|GMOUSE_VFLG_CAL_EXTREMES - Possible + //GMOUSE_VFLG_NOPOLL|GMOUSE_VFLG_DYNAMICONLY|GMOUSE_VFLG_SELFROTATION|GMOUSE_VFLG_CAL_LOADFREE - unlikely + sizeof(GMouse), + _gmouseInitDriver, _gmousePostInitDriver, _gmouseDeInitDriver + }, + Z_MAX, // z_max + Z_MIN, // z_min + Z_TOUCHON, // z_touchon + Z_TOUCHOFF, // z_touchoff + { // pen_jitter + GMOUSE_MCU_PEN_CALIBRATE_ERROR, // calibrate + GMOUSE_MCU_PEN_CLICK_ERROR, // click + GMOUSE_MCU_PEN_MOVE_ERROR // move + }, + { // finger_jitter + GMOUSE_MCU_FINGER_CALIBRATE_ERROR, // calibrate + GMOUSE_MCU_FINGER_CLICK_ERROR, // click + GMOUSE_MCU_FINGER_MOVE_ERROR // move + }, + init_board, // init + 0, // deinit + read_xyz, // get + 0, // calsave + 0 // calload +}}; + +#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */ diff --git a/drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h b/drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h new file mode 100644 index 00000000..5366b16c --- /dev/null +++ b/drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h @@ -0,0 +1,38 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _LLD_GMOUSE_MCU_BOARD_H +#define _LLD_GMOUSE_MCU_BOARD_H + +// Either define your jitter settings here or define them in the config include file +#if 0 + #include "gmouse_lld_MCU_config.h" +#else + #define GMOUSE_MCU_PEN_CALIBRATE_ERROR 2 + #define GMOUSE_MCU_PEN_CLICK_ERROR 2 + #define GMOUSE_MCU_PEN_MOVE_ERROR 2 + #define GMOUSE_MCU_FINGER_CALIBRATE_ERROR 4 + #define GMOUSE_MCU_FINGER_CLICK_ERROR 4 + #define GMOUSE_MCU_FINGER_MOVE_ERROR 4 +#endif + +// Now board specific settings... + +#define BOARD_DATA_SIZE 0 // How many extra bytes to add on the end of the mouse structure for the board's use + +#define Z_MIN 0 // The minimum Z reading +#define Z_MAX 100 // The maximum Z reading +#define Z_TOUCHON 80 // Values between this and Z_MAX are definitely pressed +#define Z_TOUCHOFF 70 // Values between this and Z_MIN are definitely not pressed + +static bool_t init_board(GMouse *m, unsigned driverinstance) { +} + +static void read_xyz(GMouse *m, GMouseReading *prd) { +} + +#endif /* _LLD_GMOUSE_MCU_BOARD_H */ diff --git a/drivers/ginput/touch/MCU/gmouse_lld_MCU_config_template.h b/drivers/ginput/touch/MCU/gmouse_lld_MCU_config_template.h new file mode 100644 index 00000000..303557b4 --- /dev/null +++ b/drivers/ginput/touch/MCU/gmouse_lld_MCU_config_template.h @@ -0,0 +1,18 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _LLD_GMOUSE_MCU_CONFIG_H +#define _LLD_GMOUSE_MCU_CONFIG_H + +#define GMOUSE_MCU_PEN_CALIBRATE_ERROR 2 +#define GMOUSE_MCU_PEN_CLICK_ERROR 2 +#define GMOUSE_MCU_PEN_MOVE_ERROR 2 +#define GMOUSE_MCU_FINGER_CALIBRATE_ERROR 4 +#define GMOUSE_MCU_FINGER_CLICK_ERROR 4 +#define GMOUSE_MCU_FINGER_MOVE_ERROR 4 + +#endif /* _LLD_GMOUSE_MCU_CONFIG_H */ From 21ad2c0c585d32bdc0b9f4fe860067aef64f2f60 Mon Sep 17 00:00:00 2001 From: inmarket Date: Tue, 7 Oct 2014 21:55:12 +1000 Subject: [PATCH 48/87] New mouse board files for MikroMedia STM32 M4 board to use new MCU touch driver --- .../ginput_lld_mouse_board.h | 85 ---------------- .../ginput_lld_mouse_config.h | 21 ---- .../gmouse_lld_MCU_board.h | 96 +++++++++++++++++++ 3 files changed, 96 insertions(+), 106 deletions(-) delete mode 100644 boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_board.h delete mode 100644 boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_config.h create mode 100644 boards/base/Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_board.h b/boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_board.h deleted file mode 100644 index 75db2c62..00000000 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_board.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _GINPUT_LLD_MOUSE_BOARD_H -#define _GINPUT_LLD_MOUSE_BOARD_H - -#define ADC_NUM_CHANNELS 2 -#define ADC_BUF_DEPTH 1 - -static const ADCConversionGroup adcgrpcfg = { - FALSE, - ADC_NUM_CHANNELS, - 0, - 0, - /* HW dependent part.*/ - 0, - ADC_CR2_SWSTART, - 0, - 0, - ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS), - 0, - ADC_SQR3_SQ2_N(ADC_CHANNEL_IN8) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN9) -}; - -static inline void init_board(void) { - adcStart(&ADCD1, 0); -} - -static inline void aquire_bus(void) { - -} - -static inline void release_bus(void) { -} - -static inline void setup_x(void) { - palSetPad(GPIOB, GPIOB_DRIVEA); - palClearPad(GPIOB, GPIOB_DRIVEB); - chThdSleepMilliseconds(2); -} - -static inline void setup_y(void) { - palClearPad(GPIOB, GPIOB_DRIVEA); - palSetPad(GPIOB, GPIOB_DRIVEB); - chThdSleepMilliseconds(2); -} - -static inline void setup_z(void) { - palClearPad(GPIOB, GPIOB_DRIVEA); - palClearPad(GPIOB, GPIOB_DRIVEB); - chThdSleepMilliseconds(2); -} - -static inline uint16_t read_x(void) { - adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH]; - - adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH); - return samples[1]; -} - -static inline uint16_t read_y(void) { - adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH]; - - adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH); - return samples[0]; -} - -static inline uint16_t read_z(void) { - adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH]; - - adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH); - // z will go from ~200 to ~4000 when pressed - // auto range this back to 0 to 100 - if (samples[0] > 4000) - return 100; - if (samples[0] < 400) - return 0; - return (samples[0] - 400) / ((4000-400)/100); -} - -#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_config.h b/boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_config.h deleted file mode 100644 index 328e6337..00000000 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/ginput_lld_mouse_config.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _LLD_GINPUT_MOUSE_CONFIG_H -#define _LLD_GINPUT_MOUSE_CONFIG_H - -#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH -#define GINPUT_MOUSE_NEED_CALIBRATION TRUE -#define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE -#define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 12 -#define GINPUT_MOUSE_READ_CYCLES 1 -#define GINPUT_MOUSE_POLL_PERIOD 25 -#define GINPUT_MOUSE_MAX_CLICK_JITTER 2 -#define GINPUT_MOUSE_MAX_MOVE_JITTER 2 -#define GINPUT_MOUSE_CLICK_TIME 500 - -#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h b/boards/base/Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h new file mode 100644 index 00000000..94333067 --- /dev/null +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h @@ -0,0 +1,96 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _LLD_GMOUSE_MCU_BOARD_H +#define _LLD_GMOUSE_MCU_BOARD_H + +// We directly define the jitter settings +#define GMOUSE_MCU_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_MCU_PEN_CLICK_ERROR 4 +#define GMOUSE_MCU_PEN_MOVE_ERROR 4 +#define GMOUSE_MCU_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_MCU_FINGER_CLICK_ERROR 8 +#define GMOUSE_MCU_FINGER_MOVE_ERROR 8 + +// Now board specific settings... + +#define ADC_NUM_CHANNELS 2 +#define ADC_BUF_DEPTH 1 + +static const ADCConversionGroup adcgrpcfg = { + FALSE, + ADC_NUM_CHANNELS, + 0, + 0, + /* HW dependent part.*/ + 0, + ADC_CR2_SWSTART, + 0, + 0, + ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS), + 0, + ADC_SQR3_SQ2_N(ADC_CHANNEL_IN8) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN9) +}; + +#define BOARD_DATA_SIZE 0 // How many extra bytes to add on the end of the mouse structure for the board's use + +#define Z_MIN 0 // The minimum Z reading +#define Z_MAX 4095 // The maximum Z reading (12 bits) +#define Z_TOUCHON 4000 // Values between this and Z_MAX are definitely pressed +#define Z_TOUCHOFF 400 // Values between this and Z_MIN are definitely not pressed + +static bool_t init_board(GMouse *m, unsigned driverinstance) { + (void) m; + + // Only one touch interface on this board + if (driverinstance) + return FALSE; + + adcStart(&ADCD1, 0); + + // Set up for reading Z + palClearPad(GPIOB, GPIOB_DRIVEA); + palClearPad(GPIOB, GPIOB_DRIVEB); + chThdSleepMilliseconds(1); // Settling time + return TRUE; +} + +static void read_xyz(GMouse *m, GMouseReading *prd) { + adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH]; + (void) m; + + // No buttons + prd->buttons = 0; + + // Get the z reading (assumes we are ready to read z) + adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH); + prd->z = samples[0]; + + // Take a shortcut and don't read x, y if we know we are definitely not touched. + if (prd->z >= Z_TOUCHOFF) { + + // Get the x reading + palSetPad(GPIOB, GPIOB_DRIVEA); + palClearPad(GPIOB, GPIOB_DRIVEB); + chThdSleepMilliseconds(2); + adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH); + prd->x = samples[1]; + + // Get the y reading + palClearPad(GPIOB, GPIOB_DRIVEA); + palSetPad(GPIOB, GPIOB_DRIVEB); + chThdSleepMilliseconds(2); + adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_BUF_DEPTH); + prd->y = samples[0]; + + // Set up for reading z again. We know it will be 20ms before we get called again so don't worry about settling time + palClearPad(GPIOB, GPIOB_DRIVEA); + palClearPad(GPIOB, GPIOB_DRIVEB); + } +} + +#endif /* _LLD_GMOUSE_MCU_BOARD_H */ From 27906d68562d3e91435a2ab0e0b955232965f885 Mon Sep 17 00:00:00 2001 From: inmarket Date: Tue, 7 Oct 2014 21:55:45 +1000 Subject: [PATCH 49/87] Update touch driver test tool. More updates to come... --- tools/touch_driver_test/gfxconf.h | 1 + tools/touch_driver_test/main.c | 274 ++++++++++++++++-------------- 2 files changed, 150 insertions(+), 125 deletions(-) diff --git a/tools/touch_driver_test/gfxconf.h b/tools/touch_driver_test/gfxconf.h index 9cd0cf1f..3d93a138 100644 --- a/tools/touch_driver_test/gfxconf.h +++ b/tools/touch_driver_test/gfxconf.h @@ -57,5 +57,6 @@ /* Features for the GINPUT sub-system. */ #define GINPUT_NEED_MOUSE TRUE +#define GINPUT_TOUCH_STARTRAW TRUE #endif /* _GFXCONF_H */ diff --git a/tools/touch_driver_test/main.c b/tools/touch_driver_test/main.c index a8318edd..85a79bf2 100644 --- a/tools/touch_driver_test/main.c +++ b/tools/touch_driver_test/main.c @@ -29,6 +29,12 @@ #include "gfx.h" +// We get nasty and look at some internal structures - get the relevant information +#include "src/gdriver/sys_defs.h" +#include "src/ginput/driver_mouse.h" + +#include + static GConsoleObject gc; static GListener gl; static font_t font; @@ -41,16 +47,21 @@ int main(void) { GEventMouse *pem; coord_t swidth, sheight; GHandle ghc; - GEventType deviceType; - bool_t calibrated; + bool_t isFirstTime; + bool_t isCalibrated; + bool_t isTouch; + bool_t isFinger; + const char * isFingerText; + const char * deviceText; coord_t bWidth, bHeight; + GMouse * m; + GMouseVMT * vmt; gfxInit(); // Initialize the display // Get the display dimensions swidth = gdispGetWidth(); sheight = gdispGetHeight(); - calibrated = FALSE; // Create our title font = gdispOpenFont("UI2"); @@ -72,11 +83,29 @@ int main(void) { } gwinClear(ghc); - // Initialize the mouse in our special no calibration mode. + // Initialize the listener geventListenerInit(&gl); - gs = ginputGetMouse(9999); + + // Copy the current mouse's VMT so we can play with it. + m = (GMouse *)gdriverGetInstance(GDRIVER_TYPE_MOUSE, 0); + if (!m) gfxHalt("No mouse instance 0"); + vmt = gfxAlloc(sizeof(GMouseVMT)); + if (!vmt) gfxHalt("Could not allocate memory for mouse VMT"); + memcpy(vmt, m->d.vmt, sizeof(GMouseVMT)); + + // Swap VMT's on the current mouse to our RAM copy + m->d.vmt = (const GDriverVMT *)vmt; + + // Listen for events + gs = ginputGetMouse(0); geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA); + // Is the mouse good enough initially for buttons? + isFirstTime = TRUE; + isCalibrated = (vmt->d.flags & GMOUSE_VFLG_CALIBRATE) ? FALSE : TRUE; + if (isCalibrated) + gdispFillStringBox(swidth-1*bWidth, 0, bWidth , bHeight, "Next", font, Black, Gray, justifyCenter); + /* * Test: Device Type */ @@ -84,61 +113,60 @@ int main(void) { StepDeviceType: gwinClear(ghc); gwinSetColor(ghc, Yellow); - gwinPrintf(ghc, "\n1. DEVICE TYPE\n\n"); + gwinPrintf(ghc, "\n1. Device Type\n\n"); - pem = (GEventMouse *)&gl.event; - ginputGetMouseStatus(0, pem); - deviceType = pem->type; + // Get the type of device and the current mode + isTouch = (vmt->d.flags & GMOUSE_VFLG_TOUCH) ? TRUE : FALSE; + isFinger = (m->flags & GMOUSE_FLG_FINGERMODE) ? TRUE : FALSE; + isFingerText = isFinger ? "finger" : "pen"; + deviceText = isTouch ? isFingerText : "mouse"; gwinSetColor(ghc, White); - gwinPrintf(ghc, "This is detected as a %s device\n\n", - deviceType == GEVENT_MOUSE ? "MOUSE" : (pem->type == GEVENT_TOUCH ? "TOUCH" : "UNKNOWN")); + gwinPrintf(ghc, "This is detected as a %s device\n\n", isTouch ? "TOUCH" : "MOUSE"); + gwinPrintf(ghc, "It is currently in %s mode\n\n", isFinger ? "FINGER" : "PEN"); - if (calibrated) - gwinPrintf(ghc, "Press Next or Back to continue.\n"); - else if (deviceType == GEVENT_MOUSE) - gwinPrintf(ghc, "Click the mouse button to move on to the next test.\n"); + if (!isCalibrated) + gwinPrintf(ghc, "Press and release your %s to move on to the next test.\n", deviceText); + else if (isFirstTime) + gwinPrintf(ghc, "Press Next to continue.\n"); else - gwinPrintf(ghc, "Press and release your finger to move on to the next test.\n"); + gwinPrintf(ghc, "Press Next or Back to continue.\n"); while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); - if (calibrated) { + if (isCalibrated) { if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { - if ((pem->meta & GMETA_MOUSE_UP)) { + if ((pem->buttons & GMETA_MOUSE_UP)) { if (pem->x >= swidth-bWidth) break; - goto StepClickJitter; + if (!isFirstTime) + goto StepDrawing; } } - } else if ((pem->meta & GMETA_MOUSE_UP)) + } else if ((pem->buttons & GMETA_MOUSE_UP)) break; } /* - * Test: Mouse raw reading jitter + * Test: Mouse raw reading */ -StepRawJitter: +StepRawReading: gwinClear(ghc); gwinSetColor(ghc, Yellow); - gwinPrintf(ghc, "\n2. GINPUT_MOUSE_READ_CYCLES\n\n"); + gwinPrintf(ghc, "\n2. Raw Mouse Output\n\n"); + + // Make sure we are in uncalibrated mode + m->flags &= ~(GMOUSE_FLG_CALIBRATE|GMOUSE_FLG_CLIP); gwinSetColor(ghc, White); - if (deviceType == GEVENT_MOUSE) - gwinPrintf(ghc, "Press and hold the mouse button.\n\n"); - else + if (isTouch) gwinPrintf(ghc, "Press and hold on the surface.\n\n"); - gwinPrintf(ghc, "Numbers will display in this window.\n" - "Ensure that values don't jump around very much when your finger is stationary.\n\n" - "Increasing GINPUT_MOUSE_READ_CYCLES helps reduce jitter but increases CPU usage.\n\n"); - - if (calibrated) - gwinPrintf(ghc, "Press Next or Back to continue.\n"); - else if (deviceType == GEVENT_MOUSE) - gwinPrintf(ghc, "Release the mouse button to move on to the next test.\n"); else - gwinPrintf(ghc, "Release your finger to move on to the next test.\n"); + gwinPrintf(ghc, "Press and hold the mouse button.\n\n"); + gwinPrintf(ghc, "The raw values coming from your mouse driver will display.\n\n"); + + gwinPrintf(ghc, "Release your %s to move on to the next test.\n", deviceText); // For this test turn on ALL mouse movement events geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEUPMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER); @@ -148,17 +176,16 @@ StepRawJitter: // mind missing events for this test. gfxSleepMilliseconds(100); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); - if (calibrated) { - if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { - if ((pem->meta & GMETA_MOUSE_UP)) { - if (pem->x >= swidth-bWidth) - break; - goto StepDeviceType; - } - } - } else if ((pem->meta & GMETA_MOUSE_UP)) + if ((pem->buttons & GMETA_MOUSE_UP)) break; - gwinPrintf(ghc, "%u:%u z=%u b=0x%04x m=%04x\n", pem->x, pem->y, pem->z, pem->current_buttons, pem->meta); + gwinPrintf(ghc, "%u, %u z=%u b=0x%04x\n", pem->x, pem->y, pem->z, pem->buttons & ~GINPUT_MISSED_MOUSE_EVENT); + } + + // Reset to calibrated + if (isCalibrated) { + m->flags |= GMOUSE_FLG_CLIP; + if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE)) + m->flags |= GMOUSE_FLG_CALIBRATE; } // Reset to just changed movements. @@ -171,42 +198,44 @@ StepRawJitter: StepCalibrate: gwinClear(ghc); gwinSetColor(ghc, Yellow); - gwinPrintf(ghc, "\n3. GINPUT_MOUSE_CALIBRATION_ERROR\n\n"); - gwinSetColor(ghc, Gray); - gwinPrintf(ghc, "Ensure GINPUT_MOUSE_NEED_CALIBRATION = TRUE and GINPUT_MOUSE_CALIBRATION_ERROR is >= 0\n\n"); + gwinPrintf(ghc, "\n3. Calibration Jitter\n\n"); gwinSetColor(ghc, White); - gwinPrintf(ghc, "You will be presented with a number of points to touch.\nPress them in turn.\n\n" - "If the calibration repeatedly fails, increase GINPUT_MOUSE_CALIBRATION_ERROR and try again.\n\n"); - - if (calibrated) - gwinPrintf(ghc, "Press Next to start the calibration.\n"); - else if (deviceType == GEVENT_MOUSE) - gwinPrintf(ghc, "Click the mouse button to start the calibration.\n"); + if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE)) { + gwinPrintf(ghc, "You will be presented with a number of points to touch.\nPress them in turn.\n\n" + "If the calibration repeatedly fails, increase the jitter for %s calibration and try again.\n\n", isFingerText); + gwinPrintf(ghc, "Press and release your %s to start the calibration.\n", deviceText); + } else { + gwinPrintf(ghc, "This device does not need calibration.\n\n"); + } + if (isCalibrated) + gwinPrintf(ghc, "Press Next or Back to continue.\n"); else - gwinPrintf(ghc, "Press and release your finger to start the calibration.\n"); + gwinPrintf(ghc, "Press and release your %s to move on to the next test.\n", deviceText); while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); - if (calibrated) { + if (isCalibrated) { if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { - if ((pem->meta & GMETA_MOUSE_UP)) { + if ((pem->buttons & GMETA_MOUSE_UP)) { if (pem->x >= swidth-bWidth) break; - goto StepRawJitter; + goto StepRawReading; } } - } else if ((pem->meta & GMETA_MOUSE_UP)) + } else if ((pem->buttons & GMETA_MOUSE_UP)) break; } // Calibrate - ginputCalibrateMouse(0); - calibrated = TRUE; + if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE)) { + ginputCalibrateMouse(0); + isCalibrated = TRUE; - // Calibration used the whole screen - re-establish our title and Next and Previous Buttons - gdispFillStringBox(0, 0, swidth, bHeight, "Touch Calibration", font, Green, White, justifyLeft); - gdispFillStringBox(swidth-2*bWidth, 0, bWidth-1, bHeight, "Prev", font, Black, Gray, justifyCenter); - gdispFillStringBox(swidth-1*bWidth, 0, bWidth , bHeight, "Next", font, Black, Gray, justifyCenter); + // Calibration used the whole screen - re-establish our title and Next and Previous Buttons + gdispFillStringBox(0, 0, swidth, bHeight, "Touch Calibration", font, Green, White, justifyLeft); + gdispFillStringBox(swidth-2*bWidth, 0, bWidth-1, bHeight, "Prev", font, Black, Gray, justifyCenter); + gdispFillStringBox(swidth-1*bWidth, 0, bWidth , bHeight, "Next", font, Black, Gray, justifyCenter); + } /* * Test: Mouse coords @@ -218,10 +247,10 @@ StepMouseCoords: gwinPrintf(ghc, "\n4. Show Mouse Coordinates\n\n"); gwinSetColor(ghc, White); - if (deviceType == GEVENT_MOUSE) - gwinPrintf(ghc, "Press and hold the mouse button.\n\n"); - else + if (isTouch) gwinPrintf(ghc, "Press and hold on the surface.\n\n"); + else + gwinPrintf(ghc, "Press and hold the mouse button.\n\n"); gwinPrintf(ghc, "Numbers will display in this window.\n" "Check the coordinates against where it should be on the screen.\n\n"); @@ -236,14 +265,13 @@ StepMouseCoords: gfxSleepMilliseconds(100); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { - if ((pem->meta & GMETA_MOUSE_UP)) { + if ((pem->buttons & GMETA_MOUSE_UP)) { if (pem->x >= swidth-bWidth) break; goto StepCalibrate; } } - if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT)) - gwinPrintf(ghc, "%u:%u z=%u\n", pem->x, pem->y, pem->z); + gwinPrintf(ghc, "%u, %u\n", pem->x, pem->y); } // Reset to just changed movements. @@ -253,66 +281,35 @@ StepMouseCoords: * Test: Mouse movement jitter */ -StepJitter: +StepMovementJitter: gwinClear(ghc); gwinSetColor(ghc, Yellow); - gwinPrintf(ghc, "\n4. GINPUT_MOUSE_MOVE_JITTER\n\n"); + gwinPrintf(ghc, "\n5. Movement Jitter\n\n"); gwinSetColor(ghc, White); - if (deviceType == GEVENT_MOUSE) - gwinPrintf(ghc, "Press and hold the mouse button and move around as if to draw.\n\n"); - else + if (isTouch) gwinPrintf(ghc, "Press firmly on the surface and move around as if to draw.\n\n"); + else + gwinPrintf(ghc, "Press and hold the mouse button and move around as if to draw.\n\n"); - gwinPrintf(ghc, "Dots will display in this window. Ensure that when you stop moving your finger that " - "new dots stop displaying.\nNew dots should only display when your finger is moving.\n\n" - "Adjust GINPUT_MOUSE_MOVE_JITTER to the smallest value that this reliably works for.\n\n"); + gwinPrintf(ghc, "Dots will display in this window. Ensure that when you stop moving your %s that " + "new dots stop displaying.\nNew dots should only display when your %s is moving.\n\n" + "Adjust %s movement jitter to the smallest value that this reliably works for.\n\n", deviceText, deviceText, isFingerText); gwinPrintf(ghc, "Press Next or Back to continue.\n\n"); while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { - if ((pem->meta & GMETA_MOUSE_UP)) { + if ((pem->buttons & GMETA_MOUSE_UP)) { if (pem->x >= swidth-bWidth) break; goto StepMouseCoords; } } - if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT)) + if ((pem->buttons & GINPUT_MOUSE_BTN_LEFT)) gwinPrintf(ghc, "."); } - /* - * Test: Polling frequency - */ - -StepPolling: - gwinClear(ghc); - gwinSetColor(ghc, Yellow); - gwinPrintf(ghc, "\n5. GINPUT_MOUSE_POLL_PERIOD\n\n"); - - gwinSetColor(ghc, White); - gwinPrintf(ghc, "Press firmly on the surface (or press and hold the mouse button) and move around as if to draw.\n\n"); - gwinPrintf(ghc, "A green line will follow your finger.\n" - "Adjust GINPUT_MOUSE_POLL_PERIOD to the highest value that provides a line without " - "gaps that are too big.\nDecreasing the value increases CPU usage.\n" - "About 25 (millisecs) normally produces good results." - "This test can be ignored for interrupt driven drivers.\n\n"); - gwinPrintf(ghc, "Press Next or Back to continue.\n\n"); - - while(1) { - pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); - if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { - if ((pem->meta & GMETA_MOUSE_UP)) { - if (pem->x >= swidth-bWidth) - break; - goto StepJitter; - } - } - if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT)) - gdispDrawPixel(pem->x, pem->y, Green); - } - /* * Test: Click Jitter */ @@ -320,38 +317,65 @@ StepPolling: StepClickJitter: gwinClear(ghc); gwinSetColor(ghc, Yellow); - gwinPrintf(ghc, "\n6. GINPUT_MOUSE_MAX_CLICK_JITTER\n\n"); + gwinPrintf(ghc, "\n6. Click Jitter\n\n"); gwinSetColor(ghc, White); - gwinPrintf(ghc, "Press and release the touch surface to \"click\".\nTry both short and long presses.\n"); - gwinPrintf(ghc, "For a mouse click with the left and right buttons.\n\n"); + if (isTouch) + gwinPrintf(ghc, "Press and release the touch surface to \"click\".\nTry both short and long presses.\n"); + else + gwinPrintf(ghc, "Click the mouse with the left and right buttons.\n\n"); gwinPrintf(ghc, "Dots will display in this window. A yellow dash is a left (or short) click. " "A red x is a right (or long) click.\n\n" - "Adjust GINPUT_MOUSE_CLICK_JITTER to the smallest value that this reliably works for.\n" - "Adjust GINPUT_MOUSE_CLICK_TIME to adjust distinguishing short vs long presses.\n" - "TIME_INFINITE means there are no long presses (although a right mouse button will still work).\n\n" - "Note: moving your finger (mouse) during a click cancels it.\n\n"); - gwinPrintf(ghc, "This is the last test but you can press Next or Back to continue.\n\n"); + "Adjust %s click jitter to the smallest value that this reliably works for.\n" + "Note: moving your %s during a click cancels it.\n\n", isFingerText, deviceText); + gwinPrintf(ghc, "Press Next or Back to continue.\n\n"); while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { - if ((pem->meta & GMETA_MOUSE_UP)) { + if ((pem->buttons & GMETA_MOUSE_UP)) { if (pem->x >= swidth-bWidth) break; - goto StepPolling; + goto StepMovementJitter; } } - if ((pem->meta & GMETA_MOUSE_CLICK)) { + if ((pem->buttons & GMETA_MOUSE_CLICK)) { gwinSetColor(ghc, Yellow); gwinPrintf(ghc, "-"); } - if ((pem->meta & GMETA_MOUSE_CXTCLICK)) { + if ((pem->buttons & GMETA_MOUSE_CXTCLICK)) { gwinSetColor(ghc, Red); gwinPrintf(ghc, "x"); } } + /* + * Test: Polling frequency + */ + +StepDrawing: + gwinClear(ghc); + gwinSetColor(ghc, Yellow); + gwinPrintf(ghc, "\n7. Drawing\n\n"); + + gwinSetColor(ghc, White); + gwinPrintf(ghc, "Press firmly on the surface (or press and hold the mouse button) and move around as if to draw.\n\n"); + gwinPrintf(ghc, "A green line will follow your %s.\n\n", deviceText); + gwinPrintf(ghc, "This is the last test but you can press Next or Back to continue.\n\n"); + + while(1) { + pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); + if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { + if ((pem->buttons & GMETA_MOUSE_UP)) { + if (pem->x >= swidth-bWidth) + break; + goto StepClickJitter; + } + } + gdispDrawPixel(pem->x, pem->y, Green); + } + // Can't let this really exit + isFirstTime = FALSE; goto StepDeviceType; } From 3e6c0348aee684d92568f7c55cb8238c2d014867 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 9 Oct 2014 12:29:26 +1000 Subject: [PATCH 50/87] Fixes bug with printf formatting of zero filled fields --- src/gfile/gfile_printg.c | 2 +- src/gwin/gwin_console.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gfile/gfile_printg.c b/src/gfile/gfile_printg.c index 33db8bc8..d11bb24d 100644 --- a/src/gfile/gfile_printg.c +++ b/src/gfile/gfile_printg.c @@ -90,7 +90,7 @@ int vfnprintg(GFILE *f, int maxlen, const char *fmt, va_list arg) { fmt++; left_align = TRUE; } - if (*fmt == '.') { + if (*fmt == '0') { fmt++; filler = '0'; } diff --git a/src/gwin/gwin_console.c b/src/gwin/gwin_console.c index 4c17034d..11359626 100644 --- a/src/gwin/gwin_console.c +++ b/src/gwin/gwin_console.c @@ -684,7 +684,7 @@ void gwinPrintf(GHandle gh, const char *fmt, ...) { left_align = TRUE; } filler = ' '; - if (*fmt == '.') { + if (*fmt == '0') { fmt++; filler = '0'; } From a8f9151931d8257d8065337ce64d949466cc3eb7 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 9 Oct 2014 12:29:55 +1000 Subject: [PATCH 51/87] ChibiOS 3 error message update --- src/gos/gos_chibios.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gos/gos_chibios.c b/src/gos/gos_chibios.c index 9d1a86da..faa007b5 100644 --- a/src/gos/gos_chibios.c +++ b/src/gos/gos_chibios.c @@ -23,10 +23,10 @@ #elif CH_KERNEL_MAJOR == 3 #if !CH_CFG_USE_MUTEXES - #error "GOS: CH_USE_MUTEXES must be defined in chconf.h" + #error "GOS: CH_CFG_USE_MUTEXES must be defined in chconf.h" #endif #if !CH_CFG_USE_SEMAPHORES - #error "GOS: CH_USE_SEMAPHORES must be defined in chconf.h" + #error "GOS: CH_CFG_USE_SEMAPHORES must be defined in chconf.h" #endif #endif From 38b4af7e202c36f9cade67293283936c246d0b8a Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 9 Oct 2014 12:30:19 +1000 Subject: [PATCH 52/87] Newmouse updates to calibration routine --- src/ginput/ginput_mouse.c | 244 ++++++++++++++++++++------------------ src/ginput/ginput_mouse.h | 5 +- 2 files changed, 130 insertions(+), 119 deletions(-) diff --git a/src/ginput/ginput_mouse.c b/src/ginput/ginput_mouse.c index 94d5e5ef..c04eda6a 100644 --- a/src/ginput/ginput_mouse.c +++ b/src/ginput/ginput_mouse.c @@ -38,7 +38,8 @@ #define CALIBRATION_TITLE_COLOR White #define CALIBRATION_TITLE_BACKGROUND Blue -#define CALIBRATION_ERROR_TEXT "Failed - Please try again!" +#define CALIBRATION_ERROR_TEXT "Calibration Failed!" +#define CALIBRATION_ERROR_DELAY 3000 #define CALIBRATION_ERROR_COLOR Red #define CALIBRATION_ERROR_BACKGROUND Yellow #define CALIBRATION_ERROR_Y 35 @@ -438,14 +439,18 @@ static void MousePoll(void *param) { + c2 * ((float)points[0].x * (float)points[1].y - (float)points[1].x * (float)points[0].y)) / dx; } - static void CalibrateMouse(GMouse *m) { + static uint32_t CalibrateMouse(GMouse *m) { coord_t w, h; point cross[4]; // The locations of the test points on the display point points[4]; // The x, y readings obtained from the mouse for each test point font_t font1, font2; + uint32_t err; + err = 0; font1 = gdispOpenFont(CALIBRATION_FONT); + if (!font1) font1 = gdispOpenFont("*"); font2 = gdispOpenFont(CALIBRATION_FONT2); + if (!font2) font2 = gdispOpenFont("*"); w = gdispGGetWidth(m->display); h = gdispGGetHeight(m->display); #if GDISP_NEED_CLIP @@ -468,145 +473,142 @@ static void MousePoll(void *param) { cross[3].x = w/2; cross[3].y = h/2; } - // Perform calibration until we get a valid result - while(1) { + // Set up the calibration display + gdispGClear(m->display, Blue); + gdispGFillStringBox(m->display, + 0, CALIBRATION_TITLE_Y, w, CALIBRATION_TITLE_HEIGHT, + CALIBRATION_TITLE, font1, CALIBRATION_TITLE_COLOR, CALIBRATION_TITLE_BACKGROUND, + justifyCenter); - // Set up the calibration display - gdispGClear(m->display, Blue); - gdispGFillStringBox(m->display, - 0, CALIBRATION_TITLE_Y, w, CALIBRATION_TITLE_HEIGHT, - CALIBRATION_TITLE, font1, CALIBRATION_TITLE_COLOR, CALIBRATION_TITLE_BACKGROUND, - justifyCenter); + // Calculate the calibration + { + unsigned i, maxpoints; - // Calculate the calibration - { - unsigned i, maxpoints; + maxpoints = (gmvmt(m)->d.flags & GMOUSE_VFLG_CAL_TEST) ? 4 : 3; - maxpoints = (gmvmt(m)->d.flags & GMOUSE_VFLG_CAL_TEST) ? 4 : 3; + // Loop through the calibration points + for(i = 0; i < maxpoints; i++) { + int32_t px, py; + unsigned j; - // Loop through the calibration points - for(i = 0; i < maxpoints; i++) { - int32_t px, py; - unsigned j; + // Draw the current calibration point + CalibrationCrossDraw(m, &cross[i]); - // Draw the current calibration point - CalibrationCrossDraw(m, &cross[i]); + // Get a valid "point pressed" average reading + do { + // Wait for the mouse to be pressed + while(!(m->r.buttons & GINPUT_MOUSE_BTN_LEFT)) + gfxSleepMilliseconds(CALIBRATION_POLL_PERIOD); - // Get a valid "point pressed" average reading - do { - // Wait for the mouse to be pressed - while(!(m->r.buttons & GINPUT_MOUSE_BTN_LEFT)) - gfxSleepMilliseconds(CALIBRATION_POLL_PERIOD); - - // Sum samples taken every CALIBRATION_POLL_PERIOD milliseconds while the mouse is down - px = py = j = 0; - while((m->r.buttons & GINPUT_MOUSE_BTN_LEFT)) { - // Limit sampling period to prevent overflow - if (j < CALIBRATION_MAXPRESS_PERIOD/CALIBRATION_POLL_PERIOD) { - px += m->r.x; - py += m->r.y; - j++; - } - gfxSleepMilliseconds(CALIBRATION_POLL_PERIOD); - } - - // Ignore presses less than CALIBRATION_MAXPRESS_PERIOD milliseconds - } while(j < CALIBRATION_MINPRESS_PERIOD/CALIBRATION_POLL_PERIOD); - points[i].x = px / j; - points[i].y = py / j; - - // Clear the current calibration point - CalibrationCrossClear(m, &cross[i]); - } - - // Apply 3 point calibration algorithm - CalibrationCalculate(m, cross, points); - - // Skip the 4th point tests if we don't want them - if (maxpoints < 4) - break; - } - - /* Verification of correctness of calibration (optional) : - * See if the 4th point (Middle of the screen) coincides with the calibrated - * result. If point is within +/- Squareroot(ERROR) pixel margin, then successful calibration - * Else, start from the beginning. - */ - { - const GMouseJitter *pj; - uint32_t err; - - // Are we in pen or finger mode - pj = (m->flags & GMOUSE_FLG_FINGERMODE) ? &gmvmt(m)->finger_jitter : &gmvmt(m)->pen_jitter; - - // Transform the co-ordinates - CalibrationTransform((GMouseReading *)&points[3], &m->caldata); - - // Do we need to rotate the reading to match the display - #if GDISP_NEED_CONTROL - if (!(gmvmt(m)->d.flags & GMOUSE_VFLG_SELFROTATION)) { - coord_t t; - - switch(gdispGGetOrientation(m->display)) { - case GDISP_ROTATE_0: - break; - case GDISP_ROTATE_90: - t = points[3].x; - points[3].x = w - 1 - points[3].y; - points[3].y = t; - break; - case GDISP_ROTATE_180: - points[3].x = w - 1 - points[3].x; - points[3].y = h - 1 - points[3].y; - break; - case GDISP_ROTATE_270: - t = points[3].y; - points[3].y = h - 1 - points[3].x; - points[3].x = t; - break; - default: - break; + // Sum samples taken every CALIBRATION_POLL_PERIOD milliseconds while the mouse is down + px = py = j = 0; + while((m->r.buttons & GINPUT_MOUSE_BTN_LEFT)) { + // Limit sampling period to prevent overflow + if (j < CALIBRATION_MAXPRESS_PERIOD/CALIBRATION_POLL_PERIOD) { + px += m->r.x; + py += m->r.y; + j++; } + gfxSleepMilliseconds(CALIBRATION_POLL_PERIOD); } - #endif - // Is this accurate enough? - err = (points[3].x - cross[3].x) * (points[3].x - cross[3].x) + (points[3].y - cross[3].y) * (points[3].y - cross[3].y); - if (err <= (uint32_t)pj->calibrate * (uint32_t)pj->calibrate) - break; + // Ignore presses less than CALIBRATION_MAXPRESS_PERIOD milliseconds + } while(j < CALIBRATION_MINPRESS_PERIOD/CALIBRATION_POLL_PERIOD); + points[i].x = px / j; + points[i].y = py / j; - // No - Display error and try again + // Clear the current calibration point + CalibrationCrossClear(m, &cross[i]); + } + } + + // Apply 3 point calibration algorithm + CalibrationCalculate(m, cross, points); + + /* Verification of correctness of calibration (optional) : + * See if the 4th point (Middle of the screen) coincides with the calibrated + * result. If point is within +/- Squareroot(ERROR) pixel margin, then successful calibration + * Else return the error. + */ + if ((gmvmt(m)->d.flags & GMOUSE_VFLG_CAL_TEST)) { + const GMouseJitter *pj; + + // Are we in pen or finger mode + pj = (m->flags & GMOUSE_FLG_FINGERMODE) ? &gmvmt(m)->finger_jitter : &gmvmt(m)->pen_jitter; + + // Transform the co-ordinates + CalibrationTransform((GMouseReading *)&points[3], &m->caldata); + + // Do we need to rotate the reading to match the display + #if GDISP_NEED_CONTROL + if (!(gmvmt(m)->d.flags & GMOUSE_VFLG_SELFROTATION)) { + coord_t t; + + switch(gdispGGetOrientation(m->display)) { + case GDISP_ROTATE_0: + break; + case GDISP_ROTATE_90: + t = points[3].x; + points[3].x = w - 1 - points[3].y; + points[3].y = t; + break; + case GDISP_ROTATE_180: + points[3].x = w - 1 - points[3].x; + points[3].y = h - 1 - points[3].y; + break; + case GDISP_ROTATE_270: + t = points[3].y; + points[3].y = h - 1 - points[3].x; + points[3].x = t; + break; + default: + break; + } + } + #endif + + // Is this accurate enough? + err = (points[3].x - cross[3].x) * (points[3].x - cross[3].x) + (points[3].y - cross[3].y) * (points[3].y - cross[3].y); + if (err > (uint32_t)pj->calibrate * (uint32_t)pj->calibrate) { + // No - Display error and return gdispGFillStringBox(m->display, 0, CALIBRATION_ERROR_Y, w, CALIBRATION_ERROR_HEIGHT, CALIBRATION_ERROR_TEXT, font2, CALIBRATION_ERROR_COLOR, CALIBRATION_ERROR_BACKGROUND, justifyCenter); - gfxSleepMilliseconds(5000); - } + gfxSleepMilliseconds(CALIBRATION_ERROR_DELAY); + } else + err = 0; } // We are done calibrating gdispCloseFont(font1); gdispCloseFont(font2); - m->flags |= GMOUSE_FLG_CALIBRATE|GMOUSE_FLG_CLIP; m->flags &= ~GMOUSE_FLG_IN_CAL; + m->flags |= GMOUSE_FLG_CLIP; + + // Save the calibration data (if possible) + if (!err) { + m->flags |= GMOUSE_FLG_CALIBRATE; + + #if GINPUT_TOUCH_USER_CALIBRATION_SAVE + SaveMouseCalibration(gdriverGetDriverInstanceNumber((GDriver *)m), &m->caldata, sizeof(GMouseCalibration)); + #endif + if (gmvmt(m)->calsave) + gmvmt(m)->calsave(m, &m->caldata, sizeof(GMouseCalibration)); + } // Force an initial reading m->r.buttons = 0; GetMouseReading(m); - // Save the calibration data (if possible) - #if GINPUT_TOUCH_USER_CALIBRATION_SAVE - SaveMouseCalibration(gdriverGetDriverInstanceNumber((GDriver *)m), &m->caldata, sizeof(GMouseCalibration)); - #endif - if (gmvmt(m)->calsave) - gmvmt(m)->calsave(m, &m->caldata, sizeof(GMouseCalibration)); - // Clear the screen using the GWIN default background color #if GFX_USE_GWIN gdispGClear(m->display, gwinGetDefaultBgColor()); #else gdispGClear(m->display, GDISP_STARTUP_COLOR); #endif + + return err; } #endif @@ -670,6 +672,10 @@ bool_t _gmouseInitDriver(GDriver *g, void *display, unsigned driverinstance, uns void _gmousePostInitDriver(GDriver *g) { #define m ((GMouse *)g) + #if !GINPUT_TOUCH_STARTRAW + m->flags |= GMOUSE_FLG_CLIP; + #endif + #if !GINPUT_TOUCH_NOCALIBRATE && !GINPUT_TOUCH_STARTRAW if ((gmvmt(m)->d.flags & GMOUSE_VFLG_CALIBRATE)) { GMouseCalibration *pc; @@ -680,18 +686,18 @@ void _gmousePostInitDriver(GDriver *g) { #if GINPUT_TOUCH_USER_CALIBRATION_FREE gfxFree(pc); #endif - m->flags |= GMOUSE_FLG_CALIBRATE|GMOUSE_FLG_CLIP; + m->flags |= GMOUSE_FLG_CALIBRATE; } else #endif if (gmvmt(m)->calload && (pc = (GMouseCalibration *)gmvmt(m)->calload(m, sizeof(GMouseCalibration)))) { memcpy(&m->caldata, pc, sizeof(GMouseCalibration)); if ((gmvmt(m)->d.flags & GMOUSE_VFLG_CAL_LOADFREE)) gfxFree(pc); - m->flags |= GMOUSE_FLG_CALIBRATE|GMOUSE_FLG_CLIP; + m->flags |= GMOUSE_FLG_CALIBRATE; } #if !GINPUT_TOUCH_NOCALIBRATE_GUI else - CalibrateMouse(m); + while (CalibrateMouse(m)); #endif } #endif @@ -774,14 +780,18 @@ bool_t ginputGetMouseStatus(unsigned instance, GEventMouse *pe) { #endif #if !GINPUT_TOUCH_NOCALIBRATE_GUI - bool_t ginputCalibrateMouse(unsigned instance) { + uint32_t ginputCalibrateMouse(unsigned instance) { GMouse *m; + // Find the instance if (!(m = (GMouse *)gdriverGetInstance(GDRIVER_TYPE_MOUSE, instance))) - return FALSE; + return 0; - CalibrateMouse(m); - return TRUE; + // Check it needs calibration + if (!(gmvmt(m)->d.flags & GMOUSE_VFLG_CALIBRATE)) + return 0; + + return CalibrateMouse(m); } #endif diff --git a/src/ginput/ginput_mouse.h b/src/ginput/ginput_mouse.h index 3e9c017b..29405e50 100644 --- a/src/ginput/ginput_mouse.h +++ b/src/ginput/ginput_mouse.h @@ -146,9 +146,10 @@ extern "C" { * * @param[in] instance The ID of the mouse input instance * - * @return FALSE if the driver dosen't support a calibration of if the handle is invalid + * @return The calibration error squared if calibration fails, or 0 on success or if the driver dosen't need calibration. + * @note An invalid instance will also return 0. */ - bool_t ginputCalibrateMouse(unsigned instance); + uint32_t ginputCalibrateMouse(unsigned instance); /** * @brief Load a set of mouse calibration data From 4766b060a857260ae92189c382dab660e83675d1 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 9 Oct 2014 12:30:41 +1000 Subject: [PATCH 53/87] Update the touch driver test program for newmouse. --- tools/touch_driver_test/main.c | 274 +++++++++++++++++++++------------ 1 file changed, 177 insertions(+), 97 deletions(-) diff --git a/tools/touch_driver_test/main.c b/tools/touch_driver_test/main.c index 85a79bf2..13136a57 100644 --- a/tools/touch_driver_test/main.c +++ b/tools/touch_driver_test/main.c @@ -38,6 +38,48 @@ static GConsoleObject gc; static GListener gl; static font_t font; +static coord_t bWidth, bWidth2, bHeight; +static GHandle ghc; +static coord_t swidth, sheight; + +static void DrawHeader(const char *title, bool_t btnNext, bool_t btnPrev, bool_t btnPlusMinus) { + #if GDISP_NEED_CLIP + gdispSetClip(0, 0, swidth, sheight); + #endif + gdispFillStringBox(0, 0, swidth, bHeight, "Touch Calibration", font, Red, White, justifyLeft); + if (btnNext) + gdispFillStringBox(swidth-1*bWidth, 0, bWidth , bHeight, "Next", font, Black, Gray, justifyCenter); + if (btnPrev) + gdispFillStringBox(swidth-2*bWidth, 0, bWidth-1, bHeight, "Prev", font, Black, Gray, justifyCenter); + if (btnPlusMinus) { + gdispFillStringBox(swidth-2*bWidth-1*bWidth2, 0, bWidth2-1, bHeight, "+", font, Black, Gray, justifyCenter); + gdispFillStringBox(swidth-2*bWidth-2*bWidth2, 0, bWidth2-1, bHeight, "-", font, Black, Gray, justifyCenter); + } + gwinClear(ghc); + gwinSetColor(ghc, Yellow); + gwinPrintf(ghc, "\n%s\n\n", title); + gwinSetColor(ghc, White); +} + +#define BTN_NONE 0 +#define BTN_NEXT 1 +#define BTN_PREV 2 +#define BTN_PLUS 3 +#define BTN_MINUS 4 + +static int CheckButtons(GEventMouse *pem) { + if (pem->y < bHeight && (pem->buttons & GMETA_MOUSE_UP)) { + if (pem->x >= swidth-1*bWidth) + return BTN_NEXT; + if (pem->x >= swidth-2*bWidth) + return BTN_PREV; + if (pem->x >= swidth-2*bWidth-1*bWidth2) + return BTN_PLUS; + if (pem->x >= swidth-2*bWidth-2*bWidth2) + return BTN_MINUS; + } + return BTN_NONE; +} /*------------------------------------------------------------------------* * GINPUT Touch Driver Calibrator. * @@ -45,17 +87,16 @@ static font_t font; int main(void) { GSourceHandle gs; GEventMouse *pem; - coord_t swidth, sheight; - GHandle ghc; bool_t isFirstTime; bool_t isCalibrated; bool_t isTouch; bool_t isFinger; const char * isFingerText; const char * deviceText; - coord_t bWidth, bHeight; GMouse * m; GMouseVMT * vmt; + GMouseJitter * pjit; + uint32_t calerr; gfxInit(); // Initialize the display @@ -70,8 +111,11 @@ int main(void) { bHeight = gdispGetStringWidth("Prev", font); if (bHeight > bWidth) bWidth = bHeight; bWidth += 4; - bHeight = gdispGetFontMetric(font, fontHeight)+2; - gdispFillStringBox(0, 0, swidth, bHeight, "Touch Calibration", font, Red, White, justifyLeft); + bWidth2 = gdispGetStringWidth("+", font)*2; + bHeight = gdispGetStringWidth("-", font)*2; + if (bHeight > bWidth2) bWidth2 = bHeight; + bWidth2 += 4; + bHeight = gdispGetFontMetric(font, fontHeight)*2+2; // Create our main display window { @@ -81,7 +125,6 @@ int main(void) { wi.show = TRUE; wi.x = 0; wi.y = bHeight; wi.width = swidth; wi.height = sheight-bHeight; ghc = gwinConsoleCreate(&gc, &wi); } - gwinClear(ghc); // Initialize the listener geventListenerInit(&gl); @@ -100,50 +143,60 @@ int main(void) { gs = ginputGetMouse(0); geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA); - // Is the mouse good enough initially for buttons? + // Get initial display settings for buttons isFirstTime = TRUE; isCalibrated = (vmt->d.flags & GMOUSE_VFLG_CALIBRATE) ? FALSE : TRUE; - if (isCalibrated) - gdispFillStringBox(swidth-1*bWidth, 0, bWidth , bHeight, "Next", font, Black, Gray, justifyCenter); + calerr = 0; /* * Test: Device Type */ StepDeviceType: - gwinClear(ghc); - gwinSetColor(ghc, Yellow); - gwinPrintf(ghc, "\n1. Device Type\n\n"); + DrawHeader("1. Device Type", isCalibrated, isCalibrated && !isFirstTime, isCalibrated); // Get the type of device and the current mode isTouch = (vmt->d.flags & GMOUSE_VFLG_TOUCH) ? TRUE : FALSE; isFinger = (m->flags & GMOUSE_FLG_FINGERMODE) ? TRUE : FALSE; + pjit = isFinger ? &vmt->finger_jitter : &vmt->pen_jitter; isFingerText = isFinger ? "finger" : "pen"; deviceText = isTouch ? isFingerText : "mouse"; - gwinSetColor(ghc, White); gwinPrintf(ghc, "This is detected as a %s device\n\n", isTouch ? "TOUCH" : "MOUSE"); gwinPrintf(ghc, "It is currently in %s mode\n\n", isFinger ? "FINGER" : "PEN"); if (!isCalibrated) gwinPrintf(ghc, "Press and release your %s to move on to the next test.\n", deviceText); - else if (isFirstTime) - gwinPrintf(ghc, "Press Next to continue.\n"); - else - gwinPrintf(ghc, "Press Next or Back to continue.\n"); + else { + gwinPrintf(ghc, "Press + for pen or - for finger.\n"); + if (isFirstTime) + gwinPrintf(ghc, "Press Next to continue.\n"); + else + gwinPrintf(ghc, "Press Next or Back to continue.\n"); + } while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); if (isCalibrated) { - if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { - if ((pem->buttons & GMETA_MOUSE_UP)) { - if (pem->x >= swidth-bWidth) - break; - if (!isFirstTime) - goto StepDrawing; - } + switch (CheckButtons(pem)) { + case BTN_NEXT: + break; + case BTN_PREV: + if (!isFirstTime) + goto StepDrawing; + continue; + case BTN_PLUS: + m->flags &= ~GMOUSE_FLG_FINGERMODE; + goto StepDeviceType; + case BTN_MINUS: + m->flags |= GMOUSE_FLG_FINGERMODE; + goto StepDeviceType; + default: + continue; } - } else if ((pem->buttons & GMETA_MOUSE_UP)) + break; + } + if ((pem->buttons & GMETA_MOUSE_UP)) break; } @@ -152,22 +205,19 @@ StepDeviceType: */ StepRawReading: - gwinClear(ghc); - gwinSetColor(ghc, Yellow); - gwinPrintf(ghc, "\n2. Raw Mouse Output\n\n"); - - // Make sure we are in uncalibrated mode - m->flags &= ~(GMOUSE_FLG_CALIBRATE|GMOUSE_FLG_CLIP); - - gwinSetColor(ghc, White); + DrawHeader("2. Raw Mouse Output", FALSE, FALSE, FALSE); if (isTouch) gwinPrintf(ghc, "Press and hold on the surface.\n\n"); else gwinPrintf(ghc, "Press and hold the mouse button.\n\n"); gwinPrintf(ghc, "The raw values coming from your mouse driver will display.\n\n"); + gwinPrintf(ghc, "Make sure the x and y values change as you move.\n\n"); gwinPrintf(ghc, "Release your %s to move on to the next test.\n", deviceText); + // Make sure we are in uncalibrated mode + m->flags &= ~(GMOUSE_FLG_CALIBRATE|GMOUSE_FLG_CLIP); + // For this test turn on ALL mouse movement events geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEUPMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER); @@ -176,12 +226,12 @@ StepRawReading: // mind missing events for this test. gfxSleepMilliseconds(100); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); + gwinPrintf(ghc, "%u, %u z=%u b=0x%04x\n", pem->x, pem->y, pem->z, pem->buttons & ~GINPUT_MISSED_MOUSE_EVENT); if ((pem->buttons & GMETA_MOUSE_UP)) break; - gwinPrintf(ghc, "%u, %u z=%u b=0x%04x\n", pem->x, pem->y, pem->z, pem->buttons & ~GINPUT_MISSED_MOUSE_EVENT); } - // Reset to calibrated + // Reset to calibrated condition if (isCalibrated) { m->flags |= GMOUSE_FLG_CLIP; if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE)) @@ -196,45 +246,53 @@ StepRawReading: */ StepCalibrate: - gwinClear(ghc); - gwinSetColor(ghc, Yellow); - gwinPrintf(ghc, "\n3. Calibration Jitter\n\n"); - gwinSetColor(ghc, White); + DrawHeader("3. Calibration Jitter", isCalibrated, isCalibrated, isCalibrated); if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE)) { gwinPrintf(ghc, "You will be presented with a number of points to touch.\nPress them in turn.\n\n" "If the calibration repeatedly fails, increase the jitter for %s calibration and try again.\n\n", isFingerText); - gwinPrintf(ghc, "Press and release your %s to start the calibration.\n", deviceText); + gwinPrintf(ghc, "Pressing the surface for longer gives more accurate results.\n\n"); + if (calerr) + gwinPrintf(ghc, "Last calibration error ^ 2 = %u\n", calerr); + gwinPrintf(ghc, "Calibration jitter (%s) = %u\n", isFingerText, pjit->calibrate); + if (isCalibrated) + gwinPrintf(ghc, "Press + or - to adjust.\n"); } else { gwinPrintf(ghc, "This device does not need calibration.\n\n"); } if (isCalibrated) gwinPrintf(ghc, "Press Next or Back to continue.\n"); else - gwinPrintf(ghc, "Press and release your %s to move on to the next test.\n", deviceText); + gwinPrintf(ghc, "Press and release your %s to move on to start calibration.\n", deviceText); while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); if (isCalibrated) { - if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { - if ((pem->buttons & GMETA_MOUSE_UP)) { - if (pem->x >= swidth-bWidth) - break; - goto StepRawReading; - } + switch (CheckButtons(pem)) { + case BTN_NEXT: + break; + case BTN_PREV: + goto StepRawReading; + case BTN_PLUS: + gwinPrintf(ghc, "Calibration jitter (%s) = %u", isFingerText, ++pjit->calibrate); + continue; + case BTN_MINUS: + gwinPrintf(ghc, "Calibration jitter (%s) = %u", isFingerText, --pjit->calibrate); + continue; + default: + continue; } - } else if ((pem->buttons & GMETA_MOUSE_UP)) + break; + } + if ((pem->buttons & GMETA_MOUSE_UP)) break; } // Calibrate if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE)) { - ginputCalibrateMouse(0); + calerr = ginputCalibrateMouse(0); + if (calerr) + goto StepCalibrate; isCalibrated = TRUE; - - // Calibration used the whole screen - re-establish our title and Next and Previous Buttons - gdispFillStringBox(0, 0, swidth, bHeight, "Touch Calibration", font, Green, White, justifyLeft); - gdispFillStringBox(swidth-2*bWidth, 0, bWidth-1, bHeight, "Prev", font, Black, Gray, justifyCenter); - gdispFillStringBox(swidth-1*bWidth, 0, bWidth , bHeight, "Next", font, Black, Gray, justifyCenter); } /* @@ -242,18 +300,14 @@ StepCalibrate: */ StepMouseCoords: - gwinClear(ghc); - gwinSetColor(ghc, Yellow); - gwinPrintf(ghc, "\n4. Show Mouse Coordinates\n\n"); - - gwinSetColor(ghc, White); + DrawHeader("4. Show Mouse Coordinates", TRUE, TRUE, TRUE); if (isTouch) gwinPrintf(ghc, "Press and hold on the surface.\n\n"); else gwinPrintf(ghc, "Press and hold the mouse button.\n\n"); - gwinPrintf(ghc, "Numbers will display in this window.\n" - "Check the coordinates against where it should be on the screen.\n\n"); - + gwinPrintf(ghc, "Check the coordinates against where it should be on the screen.\n\n"); + gwinPrintf(ghc, "X should be 0 to %u\nY should be 0 to %u\n\n", swidth-1, sheight-1); + gwinPrintf(ghc, "Press + to retry using extremes or - for normal calibration.\n"); gwinPrintf(ghc, "Press Next or Back to continue.\n"); // For this test normal mouse movement events @@ -264,14 +318,23 @@ StepMouseCoords: // mind missing events for this test. gfxSleepMilliseconds(100); pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); - if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { - if ((pem->buttons & GMETA_MOUSE_UP)) { - if (pem->x >= swidth-bWidth) - break; - goto StepCalibrate; - } + + switch (CheckButtons(pem)) { + case BTN_NEXT: + break; + case BTN_PREV: + goto StepCalibrate; + case BTN_PLUS: + vmt->d.flags |= GMOUSE_VFLG_CAL_EXTREMES; + goto StepCalibrate; + case BTN_MINUS: + vmt->d.flags &= ~GMOUSE_VFLG_CAL_EXTREMES; + goto StepCalibrate; + default: + gwinPrintf(ghc, "%u, %u\n", pem->x, pem->y); + continue; } - gwinPrintf(ghc, "%u, %u\n", pem->x, pem->y); + break; } // Reset to just changed movements. @@ -282,11 +345,7 @@ StepMouseCoords: */ StepMovementJitter: - gwinClear(ghc); - gwinSetColor(ghc, Yellow); - gwinPrintf(ghc, "\n5. Movement Jitter\n\n"); - - gwinSetColor(ghc, White); + DrawHeader("5. Movement Jitter", TRUE, TRUE, TRUE); if (isTouch) gwinPrintf(ghc, "Press firmly on the surface and move around as if to draw.\n\n"); else @@ -295,19 +354,29 @@ StepMovementJitter: gwinPrintf(ghc, "Dots will display in this window. Ensure that when you stop moving your %s that " "new dots stop displaying.\nNew dots should only display when your %s is moving.\n\n" "Adjust %s movement jitter to the smallest value that this reliably works for.\n\n", deviceText, deviceText, isFingerText); + gwinPrintf(ghc, "Movement jitter (%s) = %u\n", isFingerText, pjit->move); + gwinPrintf(ghc, "Press + or - to adjust.\n"); gwinPrintf(ghc, "Press Next or Back to continue.\n\n"); while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); - if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { - if ((pem->buttons & GMETA_MOUSE_UP)) { - if (pem->x >= swidth-bWidth) - break; - goto StepMouseCoords; - } + switch (CheckButtons(pem)) { + case BTN_NEXT: + break; + case BTN_PREV: + goto StepMouseCoords; + case BTN_PLUS: + gwinPrintf(ghc, "Movement jitter (%s) = %u", isFingerText, ++pjit->move); + continue; + case BTN_MINUS: + gwinPrintf(ghc, "Movement jitter (%s) = %u", isFingerText, --pjit->move); + continue; + default: + if ((pem->buttons & GINPUT_MOUSE_BTN_LEFT)) + gwinPrintf(ghc, "."); + continue; } - if ((pem->buttons & GINPUT_MOUSE_BTN_LEFT)) - gwinPrintf(ghc, "."); + break; } /* @@ -324,29 +393,39 @@ StepClickJitter: gwinPrintf(ghc, "Press and release the touch surface to \"click\".\nTry both short and long presses.\n"); else gwinPrintf(ghc, "Click the mouse with the left and right buttons.\n\n"); - gwinPrintf(ghc, "Dots will display in this window. A yellow dash is a left (or short) click. " + gwinPrintf(ghc, "A yellow dash is a left (or short) click.\n" "A red x is a right (or long) click.\n\n" "Adjust %s click jitter to the smallest value that this reliably works for.\n" "Note: moving your %s during a click cancels it.\n\n", isFingerText, deviceText); + gwinPrintf(ghc, "Click jitter (%s) = %u\n", isFingerText, pjit->click); + gwinPrintf(ghc, "Press + or - to adjust.\n"); gwinPrintf(ghc, "Press Next or Back to continue.\n\n"); while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); - if (pem->y < bHeight && pem->x >= swidth-2*bWidth) { - if ((pem->buttons & GMETA_MOUSE_UP)) { - if (pem->x >= swidth-bWidth) - break; - goto StepMovementJitter; + switch (CheckButtons(pem)) { + case BTN_NEXT: + break; + case BTN_PREV: + goto StepMovementJitter; + case BTN_PLUS: + gwinPrintf(ghc, "Click jitter (%s) = %u", isFingerText, ++pjit->click); + continue; + case BTN_MINUS: + gwinPrintf(ghc, "Click jitter (%s) = %u", isFingerText, --pjit->click); + continue; + default: + if ((pem->buttons & GMETA_MOUSE_CLICK)) { + gwinSetColor(ghc, Yellow); + gwinPrintf(ghc, "-"); } + if ((pem->buttons & GMETA_MOUSE_CXTCLICK)) { + gwinSetColor(ghc, Red); + gwinPrintf(ghc, "x"); + } + continue; } - if ((pem->buttons & GMETA_MOUSE_CLICK)) { - gwinSetColor(ghc, Yellow); - gwinPrintf(ghc, "-"); - } - if ((pem->buttons & GMETA_MOUSE_CXTCLICK)) { - gwinSetColor(ghc, Red); - gwinPrintf(ghc, "x"); - } + break; } /* @@ -361,7 +440,8 @@ StepDrawing: gwinSetColor(ghc, White); gwinPrintf(ghc, "Press firmly on the surface (or press and hold the mouse button) and move around as if to draw.\n\n"); gwinPrintf(ghc, "A green line will follow your %s.\n\n", deviceText); - gwinPrintf(ghc, "This is the last test but you can press Next or Back to continue.\n\n"); + gwinPrintf(ghc, "Pressing Next will start the tests again but with the option of changing pen/finger mode.\n\n"); + gwinPrintf(ghc, "Press Next or Back to continue.\n\n"); while(1) { pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); From 20f235c1f1947dac5cf287b28748b6b0ee83ce0a Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 9 Oct 2014 12:31:23 +1000 Subject: [PATCH 54/87] Fine tuning the MCU driver parameters for the Mikromedia STM32 M4 --- .../Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h b/boards/base/Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h index 94333067..7624cdf3 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h @@ -10,11 +10,11 @@ // We directly define the jitter settings #define GMOUSE_MCU_PEN_CALIBRATE_ERROR 8 -#define GMOUSE_MCU_PEN_CLICK_ERROR 4 +#define GMOUSE_MCU_PEN_CLICK_ERROR 6 #define GMOUSE_MCU_PEN_MOVE_ERROR 4 #define GMOUSE_MCU_FINGER_CALIBRATE_ERROR 14 -#define GMOUSE_MCU_FINGER_CLICK_ERROR 8 -#define GMOUSE_MCU_FINGER_MOVE_ERROR 8 +#define GMOUSE_MCU_FINGER_CLICK_ERROR 18 +#define GMOUSE_MCU_FINGER_MOVE_ERROR 14 // Now board specific settings... @@ -40,7 +40,7 @@ static const ADCConversionGroup adcgrpcfg = { #define Z_MIN 0 // The minimum Z reading #define Z_MAX 4095 // The maximum Z reading (12 bits) -#define Z_TOUCHON 4000 // Values between this and Z_MAX are definitely pressed +#define Z_TOUCHON 3090 // Values between this and Z_MAX are definitely pressed #define Z_TOUCHOFF 400 // Values between this and Z_MIN are definitely not pressed static bool_t init_board(GMouse *m, unsigned driverinstance) { From 527ebbff48f6bc16bd5433b9ca6d0d6294138aca Mon Sep 17 00:00:00 2001 From: inmarket Date: Sun, 12 Oct 2014 00:34:32 +1000 Subject: [PATCH 55/87] Update Olimex-STM32-LCD mouse board file for newmouse MCU driver. Still to be tested and tuned on real hardware. --- .../Olimex-STM32-LCD/ginput_lld_mouse_board.h | 126 ---------------- .../ginput_lld_mouse_config.h | 22 --- .../Olimex-STM32-LCD/gmouse_lld_MCU_board.h | 137 ++++++++++++++++++ 3 files changed, 137 insertions(+), 148 deletions(-) delete mode 100644 boards/base/Olimex-STM32-LCD/ginput_lld_mouse_board.h delete mode 100644 boards/base/Olimex-STM32-LCD/ginput_lld_mouse_config.h create mode 100644 boards/base/Olimex-STM32-LCD/gmouse_lld_MCU_board.h diff --git a/boards/base/Olimex-STM32-LCD/ginput_lld_mouse_board.h b/boards/base/Olimex-STM32-LCD/ginput_lld_mouse_board.h deleted file mode 100644 index 91575527..00000000 --- a/boards/base/Olimex-STM32-LCD/ginput_lld_mouse_board.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _GINPUT_LLD_MOUSE_BOARD_H -#define _GINPUT_LLD_MOUSE_BOARD_H - -#define ADC_NUM_CHANNELS 2 -#define ADC_BUF_DEPTH 1 - -static const ADCConversionGroup adc_y_config = { - FALSE, - ADC_NUM_CHANNELS, - 0, - 0, - 0, 0, - 0, 0, - ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS), - 0, - ADC_SQR3_SQ2_N(ADC_CHANNEL_IN12) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN13) -}; - -static const ADCConversionGroup adc_x_config = { - FALSE, - ADC_NUM_CHANNELS, - 0, - 0, - 0, 0, - 0, 0, - ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS), - 0, - ADC_SQR3_SQ2_N(ADC_CHANNEL_IN10) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11) -}; - -static inline void init_board(void) { - adcStart(&ADCD1, 0); -} - -static inline void aquire_bus(void) { - -} - -static inline void release_bus(void) { - -} - -static inline void setup_x(void) { - palSetPadMode(GPIOC, 0, PAL_MODE_INPUT_ANALOG); - palSetPadMode(GPIOC, 1, PAL_MODE_INPUT_ANALOG); - palSetPadMode(GPIOC, 2, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOC, 3, PAL_MODE_OUTPUT_PUSHPULL); - - palSetPad(GPIOC, 2); - palClearPad(GPIOC, 3); - gfxSleepMilliseconds(1); -} - -static inline void setup_y(void) { - palSetPadMode(GPIOC, 2, PAL_MODE_INPUT_ANALOG); - palSetPadMode(GPIOC, 3, PAL_MODE_INPUT_ANALOG); - palSetPadMode(GPIOC, 0, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOC, 1, PAL_MODE_OUTPUT_PUSHPULL); - - palSetPad(GPIOC, 1); - palClearPad(GPIOC, 0); - gfxSleepMilliseconds(1); -} - -static inline void setup_z(void) { - palSetPadMode(GPIOC, 0, PAL_MODE_INPUT_PULLDOWN); - palSetPadMode(GPIOC, 1, PAL_MODE_INPUT); - palSetPadMode(GPIOC, 2, PAL_MODE_INPUT); - palSetPadMode(GPIOC, 3, PAL_MODE_OUTPUT_PUSHPULL); - palSetPad(GPIOC, 3); -} - -static inline uint16_t read_x(void) { - uint16_t val1, val2; - adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH]; - - palSetPad(GPIOC, 2); - palClearPad(GPIOC, 3); - gfxSleepMilliseconds(1); - adcConvert(&ADCD1, &adc_x_config, samples, ADC_BUF_DEPTH); - val1 = ((samples[0] + samples[1])/2); - - palClearPad(GPIOC, 2); - palSetPad(GPIOC, 3); - gfxSleepMilliseconds(1); - adcConvert(&ADCD1, &adc_x_config, samples, ADC_BUF_DEPTH); - val2 = ((samples[0] + samples[1])/2); - - return ((val1+((1<<12)-val2))/4); -} - -static inline uint16_t read_y(void) { - uint16_t val1, val2; - adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH]; - - palSetPad(GPIOC, 1); - palClearPad(GPIOC, 0); - gfxSleepMilliseconds(1); - adcConvert(&ADCD1, &adc_y_config, samples, ADC_BUF_DEPTH); - val1 = ((samples[0] + samples[1])/2); - - palClearPad(GPIOC, 1); - palSetPad(GPIOC, 0); - gfxSleepMilliseconds(1); - adcConvert(&ADCD1, &adc_y_config, samples, ADC_BUF_DEPTH); - val2 = ((samples[0] + samples[1])/2); - - return ((val1+((1<<12)-val2))/4); -} - -static inline uint16_t read_z(void) { - if (palReadPad(GPIOC, 0)) - return 100; - else - return 0; -} - -#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ - diff --git a/boards/base/Olimex-STM32-LCD/ginput_lld_mouse_config.h b/boards/base/Olimex-STM32-LCD/ginput_lld_mouse_config.h deleted file mode 100644 index e8362219..00000000 --- a/boards/base/Olimex-STM32-LCD/ginput_lld_mouse_config.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _LLD_GINPUT_MOUSE_CONFIG_H -#define _LLD_GINPUT_MOUSE_CONFIG_H - -#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH -#define GINPUT_MOUSE_NEED_CALIBRATION TRUE -#define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE -#define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 12 -#define GINPUT_MOUSE_READ_CYCLES 1 -#define GINPUT_MOUSE_POLL_PERIOD 25 -#define GINPUT_MOUSE_MAX_CLICK_JITTER 2 -#define GINPUT_MOUSE_MAX_MOVE_JITTER 2 -#define GINPUT_MOUSE_CLICK_TIME 500 - -#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ - diff --git a/boards/base/Olimex-STM32-LCD/gmouse_lld_MCU_board.h b/boards/base/Olimex-STM32-LCD/gmouse_lld_MCU_board.h new file mode 100644 index 00000000..8f085f84 --- /dev/null +++ b/boards/base/Olimex-STM32-LCD/gmouse_lld_MCU_board.h @@ -0,0 +1,137 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _LLD_GMOUSE_MCU_BOARD_H +#define _LLD_GMOUSE_MCU_BOARD_H + +// We directly define the jitter settings +#define GMOUSE_MCU_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_MCU_PEN_CLICK_ERROR 6 +#define GMOUSE_MCU_PEN_MOVE_ERROR 4 +#define GMOUSE_MCU_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_MCU_FINGER_CLICK_ERROR 18 +#define GMOUSE_MCU_FINGER_MOVE_ERROR 14 + +// Now board specific settings... + +#define ADC_NUM_CHANNELS 2 +#define ADC_BUF_DEPTH 1 + +static const ADCConversionGroup adc_y_config = { + FALSE, + ADC_NUM_CHANNELS, + 0, + 0, + 0, 0, + 0, 0, + ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS), + 0, + ADC_SQR3_SQ2_N(ADC_CHANNEL_IN12) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN13) +}; + +static const ADCConversionGroup adc_x_config = { + FALSE, + ADC_NUM_CHANNELS, + 0, + 0, + 0, 0, + 0, 0, + ADC_SQR1_NUM_CH(ADC_NUM_CHANNELS), + 0, + ADC_SQR3_SQ2_N(ADC_CHANNEL_IN10) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11) +}; + +#define BOARD_DATA_SIZE 0 // How many extra bytes to add on the end of the mouse structure for the board's use + +#define Z_MIN 0 // The minimum Z reading +#define Z_MAX 1 // The maximum Z reading +#define Z_TOUCHON 1 // Values between this and Z_MAX are definitely pressed +#define Z_TOUCHOFF 0 // Values between this and Z_MIN are definitely not pressed + +static inline void setup_z(void) { + palSetPadMode(GPIOC, 0, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOC, 1, PAL_MODE_INPUT); + palSetPadMode(GPIOC, 2, PAL_MODE_INPUT); + palSetPadMode(GPIOC, 3, PAL_MODE_OUTPUT_PUSHPULL); + palSetPad(GPIOC, 3); +} + +static bool_t init_board(GMouse *m, unsigned driverinstance) { + (void) m; + + // Only one touch interface on this board + if (driverinstance) + return FALSE; + + adcStart(&ADCD1, 0); + + // Set up for reading Z + setup_z(); + chThdSleepMilliseconds(1); // Settling time + return TRUE; +} + +static void read_xyz(GMouse *m, GMouseReading *prd) { + adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH]; + uint16_t val1, val2; + (void) m; + + // No buttons and assume touch off + prd->buttons = 0; + prd->z = 0; + + // Get the z reading (assumes we are ready to read z) + // Take a shortcut and don't read x, y if we know we are definitely not touched. + if (palReadPad(GPIOC, 0)) { + prd->z = 1; + + // Get the x reading - Weird but it works. Optimize later. + palSetPadMode(GPIOC, 0, PAL_MODE_INPUT_ANALOG); + palSetPadMode(GPIOC, 1, PAL_MODE_INPUT_ANALOG); + palSetPadMode(GPIOC, 2, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOC, 3, PAL_MODE_OUTPUT_PUSHPULL); + + palSetPad(GPIOC, 2); + palClearPad(GPIOC, 3); + gfxSleepMilliseconds(1); + adcConvert(&ADCD1, &adc_x_config, samples, ADC_BUF_DEPTH); + val1 = ((samples[0] + samples[1])/2); + + palClearPad(GPIOC, 2); + palSetPad(GPIOC, 3); + gfxSleepMilliseconds(1); + adcConvert(&ADCD1, &adc_x_config, samples, ADC_BUF_DEPTH); + val2 = ((samples[0] + samples[1])/2); + + prd->x = ((val1+((1<<12)-val2))/4); + + // Get the y reading - Weird but it works. Optimize later. + palSetPadMode(GPIOC, 2, PAL_MODE_INPUT_ANALOG); + palSetPadMode(GPIOC, 3, PAL_MODE_INPUT_ANALOG); + palSetPadMode(GPIOC, 0, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOC, 1, PAL_MODE_OUTPUT_PUSHPULL); + + palSetPad(GPIOC, 1); + palClearPad(GPIOC, 0); + gfxSleepMilliseconds(1); + adcConvert(&ADCD1, &adc_y_config, samples, ADC_BUF_DEPTH); + val1 = ((samples[0] + samples[1])/2); + + palClearPad(GPIOC, 1); + palSetPad(GPIOC, 0); + gfxSleepMilliseconds(1); + adcConvert(&ADCD1, &adc_y_config, samples, ADC_BUF_DEPTH); + val2 = ((samples[0] + samples[1])/2); + + prd->y = ((val1+((1<<12)-val2))/4); + + // Set up for reading z again. We know it will be 20ms before we get called again so don't worry about settling time + setup_z(); + } +} + +#endif /* _LLD_GMOUSE_MCU_BOARD_H */ From 097bce6aa4df5f4bacef3976cd7b7fab26a72c4a Mon Sep 17 00:00:00 2001 From: inmarket Date: Sun, 12 Oct 2014 00:55:32 +1000 Subject: [PATCH 56/87] Board File can now request extra data bytes in the GMouse structure. --- drivers/ginput/touch/MCU/gmouse_lld_MCU.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/ginput/touch/MCU/gmouse_lld_MCU.c b/drivers/ginput/touch/MCU/gmouse_lld_MCU.c index 87b39ae4..222b759b 100644 --- a/drivers/ginput/touch/MCU/gmouse_lld_MCU.c +++ b/drivers/ginput/touch/MCU/gmouse_lld_MCU.c @@ -15,6 +15,11 @@ // Get the hardware interface #include "gmouse_lld_MCU_board.h" +// If the board file doesn't specify how many extra bytes it wants - assume 0 +#ifndef BOARD_DATA_SIZE + #define BOARD_DATA_SIZE 0 +#endif + const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ { GDRIVER_TYPE_TOUCH, @@ -23,7 +28,7 @@ const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ // Extra flags for testing only //GMOUSE_VFLG_DEFAULTFINGER|GMOUSE_VFLG_CAL_EXTREMES - Possible //GMOUSE_VFLG_NOPOLL|GMOUSE_VFLG_DYNAMICONLY|GMOUSE_VFLG_SELFROTATION|GMOUSE_VFLG_CAL_LOADFREE - unlikely - sizeof(GMouse), + sizeof(GMouse)+BOARD_DATA_SIZE, _gmouseInitDriver, _gmousePostInitDriver, _gmouseDeInitDriver }, Z_MAX, // z_max From d9f93a31bb5fd7ba5de69f2593e2dacb8218dd63 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 11 Oct 2014 18:24:12 +0200 Subject: [PATCH 57/87] ADS7843 porting - not tested yet! --- .../ginput_lld_mouse_config.h | 22 ----- ...use_board.h => gmouse_lld_ADS7843_board.h} | 23 ++++- drivers/ginput/touch/ADS7843/driver.mk | 2 +- .../ginput/touch/ADS7843/ginput_lld_mouse.c | 94 ------------------- .../touch/ADS7843/ginput_lld_mouse_config.h | 21 ----- .../ginput/touch/ADS7843/gmouse_lld_ADS7843.c | 77 +++++++++++++++ ....h => gmouse_lld_ADS7843_board_template.h} | 2 +- 7 files changed, 100 insertions(+), 141 deletions(-) delete mode 100644 boards/base/FireBull-STM32F103-FB/ginput_lld_mouse_config.h rename boards/base/FireBull-STM32F103-FB/{ginput_lld_mouse_board.h => gmouse_lld_ADS7843_board.h} (64%) delete mode 100644 drivers/ginput/touch/ADS7843/ginput_lld_mouse.c delete mode 100644 drivers/ginput/touch/ADS7843/ginput_lld_mouse_config.h create mode 100644 drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c rename drivers/ginput/touch/ADS7843/{ginput_lld_mouse_board_template.h => gmouse_lld_ADS7843_board_template.h} (88%) diff --git a/boards/base/FireBull-STM32F103-FB/ginput_lld_mouse_config.h b/boards/base/FireBull-STM32F103-FB/ginput_lld_mouse_config.h deleted file mode 100644 index f3a89208..00000000 --- a/boards/base/FireBull-STM32F103-FB/ginput_lld_mouse_config.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _LLD_GINPUT_MOUSE_CONFIG_H -#define _LLD_GINPUT_MOUSE_CONFIG_H - -#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH -#define GINPUT_MOUSE_NEED_CALIBRATION TRUE -#define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE -#define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 12 -#define GINPUT_MOUSE_READ_CYCLES 4 -#define GINPUT_MOUSE_POLL_PERIOD 3 -#define GINPUT_MOUSE_MAX_CLICK_JITTER 2 -#define GINPUT_MOUSE_MAX_MOVE_JITTER 2 -#define GINPUT_MOUSE_CLICK_TIME 500 - -#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ - diff --git a/boards/base/FireBull-STM32F103-FB/ginput_lld_mouse_board.h b/boards/base/FireBull-STM32F103-FB/gmouse_lld_ADS7843_board.h similarity index 64% rename from boards/base/FireBull-STM32F103-FB/ginput_lld_mouse_board.h rename to boards/base/FireBull-STM32F103-FB/gmouse_lld_ADS7843_board.h index 6ca1a897..aa3a41e7 100644 --- a/boards/base/FireBull-STM32F103-FB/ginput_lld_mouse_board.h +++ b/boards/base/FireBull-STM32F103-FB/gmouse_lld_ADS7843_board.h @@ -8,6 +8,13 @@ #ifndef _GINPUT_LLD_MOUSE_BOARD_H #define _GINPUT_LLD_MOUSE_BOARD_H +#define GMOUSE_ADS7843_PEN_CALIBRATE_ERROR 2 +#define GMOUSE_ADS7843_PEN_CLICK_ERROR 2 +#define GMOUSE_ADS7843_PEN_MOVE_ERROR 2 +#define GMOUSE_ADS7843_FINGER_CALIBRATE_ERROR 4 +#define GMOUSE_ADS7843_FINGER_CLICK_ERROR 4 +#define GMOUSE_ADS7843_FINGER_MOVE_ERROR 4 + static const SPIConfig spicfg = { 0, GPIOC, @@ -15,13 +22,25 @@ static const SPIConfig spicfg = { /* SPI_CR1_BR_2 |*/ SPI_CR1_BR_1 | SPI_CR1_BR_0, }; -static inline void init_board(void) +static bool_t init_board(GMouse* m, unsigned driverinstance) { + (void)m; + + // Only one touch interface on this board + if (driverinstance) + return FALSE; + + // Set the GPIO modes + palSetPadMode(GPIOC, 4, PAL_MODE_INPUT); + + // Start the SPI peripheral spiStart(&SPID1, &spicfg); + + return TRUE; } static inline bool_t getpin_pressed(void) -{ +{ return (!palReadPad(GPIOC, 4)); } diff --git a/drivers/ginput/touch/ADS7843/driver.mk b/drivers/ginput/touch/ADS7843/driver.mk index 31e9ab2c..221dd4fc 100644 --- a/drivers/ginput/touch/ADS7843/driver.mk +++ b/drivers/ginput/touch/ADS7843/driver.mk @@ -1,5 +1,5 @@ # List the required driver. -GFXSRC += $(GFXLIB)/drivers/ginput/touch/ADS7843/ginput_lld_mouse.c +GFXSRC += $(GFXLIB)/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c # Required include directories GFXINC += $(GFXLIB)/drivers/ginput/touch/ADS7843 diff --git a/drivers/ginput/touch/ADS7843/ginput_lld_mouse.c b/drivers/ginput/touch/ADS7843/ginput_lld_mouse.c deleted file mode 100644 index cb9b6f4e..00000000 --- a/drivers/ginput/touch/ADS7843/ginput_lld_mouse.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#include "gfx.h" - -#if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) /*|| defined(__DOXYGEN__)*/ - -#include "src/ginput/driver_mouse.h" - -#include "ginput_lld_mouse_board.h" - -#if defined(GINPUT_MOUSE_YX_INVERTED) && GINPUT_MOUSE_YX_INVERTED - #define CMD_X 0x91 - #define CMD_Y 0xD1 -#else - #define CMD_X 0xD1 - #define CMD_Y 0x91 -#endif - - -static uint16_t sampleBuf[7]; -static coord_t lastx, lasty; - -static void filter(void) { - uint16_t temp; - int i,j; - - for(i = 0; i < 4; i++) { - for(j = i; j < 7; j++) { - if(sampleBuf[i] > sampleBuf[j]) { - /* Swap the values */ - temp = sampleBuf[i]; - sampleBuf[i] = sampleBuf[j]; - sampleBuf[j] = temp; - } - } - } -} - -void ginput_lld_mouse_init(void) { - init_board(); -} - -void ginput_lld_mouse_get_reading(MouseReading *pt) { - uint16_t i; - - // If touch-off return the previous results - if (!getpin_pressed()) { - pt->x = lastx; - pt->y = lasty; - pt->z = 0; - pt->buttons = 0; - return; - } - - // Read the port to get the touch settings - aquire_bus(); - - /* Get the X value - * Discard the first conversion - very noisy and keep the ADC on hereafter - * till we are done with the sampling. Note that PENIRQ is disabled while reading. - * Finally switch on PENIRQ once again - perform a dummy read. - * Once we have the readings, find the medium using our filter function - */ - read_value(CMD_X); - for(i = 0; i < 7; i++) - sampleBuf[i] = read_value(CMD_X); - read_value(CMD_X-1); - filter(); - lastx = (coord_t)sampleBuf[3]; - - /* Get the Y value using the same process as above */ - read_value(CMD_Y); - for(i = 0; i < 7; i++) - sampleBuf[i] = read_value(CMD_Y); - read_value(CMD_Y-1); - filter(); - lasty = (coord_t)sampleBuf[3]; - - // Release the bus - release_bus(); - - // Return the results - pt->x = lastx; - pt->y = lasty; - pt->z = 100; - pt->buttons = GINPUT_TOUCH_PRESSED; -} - -#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */ diff --git a/drivers/ginput/touch/ADS7843/ginput_lld_mouse_config.h b/drivers/ginput/touch/ADS7843/ginput_lld_mouse_config.h deleted file mode 100644 index 31840a51..00000000 --- a/drivers/ginput/touch/ADS7843/ginput_lld_mouse_config.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _LLD_GINPUT_MOUSE_CONFIG_H -#define _LLD_GINPUT_MOUSE_CONFIG_H - -#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH -#define GINPUT_MOUSE_NEED_CALIBRATION TRUE -#define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE -#define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 5 -#define GINPUT_MOUSE_READ_CYCLES 4 -#define GINPUT_MOUSE_POLL_PERIOD 25 -#define GINPUT_MOUSE_MAX_CLICK_JITTER 10 -#define GINPUT_MOUSE_MAX_MOVE_JITTER 2 -#define GINPUT_MOUSE_CLICK_TIME 500 - -#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ diff --git a/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c new file mode 100644 index 00000000..a58ca938 --- /dev/null +++ b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c @@ -0,0 +1,77 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#include "gfx.h" + +#if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) + +#define GMOUSE_DRIVER_VMT GMOUSEVMT_ADS7843 +#include "src/ginput/driver_mouse.h" + +// Get the hardware interface +#include "gmouse_lld_ADS7843_board.h" + +// If the board file doesn't specify how many extra bytes it wants - assume 0 +#ifndef BOARD_DATA_SIZE + #define BOARD_DATA_SIZE 0 +#endif + +#define CMD_X 0xD1 +#define CMD_Y 0x91 + +void read_xyz(GMouse* m, GMouseReading* pdr) +{ + (void)m; + + // No buttons + pdr->buttons = 0; + + if (getpin_pressed()) { + aquire_bus(); + pdr->x = read_value(CMD_X); + pdr->y = read_value(CMD_Y); + pdr->z = 1; + release_bus(); + } else { + // Don't touch x and y values here + pdr->z = 0; + } +} + +const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ + { + GDRIVER_TYPE_TOUCH, + GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_CALIBRATE | GMOUSE_VFLG_CAL_TEST | + GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN, + sizeof(GMouse)+BOARD_DATA_SIZE, + _gmouseInitDriver, + _gmousePostInitDriver, + _gmouseDeInitDriver + }, + 1, // z_max - (currently?) not supported + 0, // z_min - (currently?) not supported + 1, // z_touchon + 0, // z_touchoff + { // pen_jitter + GMOUSE_ADS7843_PEN_CALIBRATE_ERROR, // calibrate + GMOUSE_ADS7843_PEN_CLICK_ERROR, // click + GMOUSE_ADS7843_PEN_MOVE_ERROR // move + }, + { // finger_jitter + GMOUSE_ADS7843_FINGER_CALIBRATE_ERROR, // calibrate + GMOUSE_ADS7843_FINGER_CLICK_ERROR, // click + GMOUSE_ADS7843_FINGER_MOVE_ERROR // move + }, + init_board, // init + 0, // deinit + read_xyz, // get + 0, // calsave + 0 // calload +}}; + +#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */ + diff --git a/drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_template.h b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843_board_template.h similarity index 88% rename from drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_template.h rename to drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843_board_template.h index 09783adf..2e3dee65 100644 --- a/drivers/ginput/touch/ADS7843/ginput_lld_mouse_board_template.h +++ b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843_board_template.h @@ -8,7 +8,7 @@ #ifndef _GINPUT_LLD_MOUSE_BOARD_H #define _GINPUT_LLD_MOUSE_BOARD_H -static inline void init_board(void) { +static bool_t init_board(GMouse* m, unsigned driverinstance) { } From 5b897baae7d6c102e73176e2229b19c70839a26e Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 11 Oct 2014 17:45:53 +0200 Subject: [PATCH 58/87] Added missing defines to board template of ADS7843 --- .../touch/ADS7843/gmouse_lld_ADS7843_board_template.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843_board_template.h b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843_board_template.h index 2e3dee65..7b762310 100644 --- a/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843_board_template.h +++ b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843_board_template.h @@ -8,6 +8,13 @@ #ifndef _GINPUT_LLD_MOUSE_BOARD_H #define _GINPUT_LLD_MOUSE_BOARD_H +#define GMOUSE_ADS7843_PEN_CALIBRATE_ERROR 2 +#define GMOUSE_ADS7843_PEN_CLICK_ERROR 2 +#define GMOUSE_ADS7843_PEN_MOVE_ERROR 2 +#define GMOUSE_ADS7843_FINGER_CALIBRATE_ERROR 4 +#define GMOUSE_ADS7843_FINGER_CLICK_ERROR 4 +#define GMOUSE_ADS7843_FINGER_MOVE_ERROR 4 + static bool_t init_board(GMouse* m, unsigned driverinstance) { } From dc1ff7afa843b08a82874fcab7e06037aa663bac Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 11 Oct 2014 23:54:50 +0200 Subject: [PATCH 59/87] fixing ADS7843 driver - tested --- .../gmouse_lld_ADS7843_board.h | 4 ++-- .../ginput/touch/ADS7843/gmouse_lld_ADS7843.c | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/boards/base/FireBull-STM32F103-FB/gmouse_lld_ADS7843_board.h b/boards/base/FireBull-STM32F103-FB/gmouse_lld_ADS7843_board.h index aa3a41e7..e4f30818 100644 --- a/boards/base/FireBull-STM32F103-FB/gmouse_lld_ADS7843_board.h +++ b/boards/base/FireBull-STM32F103-FB/gmouse_lld_ADS7843_board.h @@ -11,7 +11,7 @@ #define GMOUSE_ADS7843_PEN_CALIBRATE_ERROR 2 #define GMOUSE_ADS7843_PEN_CLICK_ERROR 2 #define GMOUSE_ADS7843_PEN_MOVE_ERROR 2 -#define GMOUSE_ADS7843_FINGER_CALIBRATE_ERROR 4 +#define GMOUSE_ADS7843_FINGER_CALIBRATE_ERROR 20 #define GMOUSE_ADS7843_FINGER_CLICK_ERROR 4 #define GMOUSE_ADS7843_FINGER_MOVE_ERROR 4 @@ -31,7 +31,7 @@ static bool_t init_board(GMouse* m, unsigned driverinstance) return FALSE; // Set the GPIO modes - palSetPadMode(GPIOC, 4, PAL_MODE_INPUT); + palSetPadMode(GPIOC, 4, PAL_MODE_INPUT_PULLUP); // Start the SPI peripheral spiStart(&SPID1, &spicfg); diff --git a/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c index a58ca938..72cd6f67 100644 --- a/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c +++ b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c @@ -20,8 +20,9 @@ #define BOARD_DATA_SIZE 0 #endif -#define CMD_X 0xD1 -#define CMD_Y 0x91 +#define CMD_X 0xD1 +#define CMD_Y 0x91 +#define CMD_ENABLE_IRQ 0x80 void read_xyz(GMouse* m, GMouseReading* pdr) { @@ -31,10 +32,18 @@ void read_xyz(GMouse* m, GMouseReading* pdr) pdr->buttons = 0; if (getpin_pressed()) { + pdr->z = 1; // Set to Z_MAX as we are pressed + aquire_bus(); - pdr->x = read_value(CMD_X); - pdr->y = read_value(CMD_Y); - pdr->z = 1; + + read_value(CMD_X); // Dummy read - disable PenIRQ + pdr->x = read_value(CMD_X); // Read X-Value + + read_value(CMD_Y); // Dummy read - disable PenIRQ + pdr->y = read_value(CMD_Y); // Read Y-Value + + read_value(CMD_ENABLE_IRQ); // Enable IRQ + release_bus(); } else { // Don't touch x and y values here From eb0cc2187236fb0eac18bee536cf0d8f8cb7b7f8 Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 13 Oct 2014 16:35:57 +1000 Subject: [PATCH 60/87] Tidy up MCU mouse defines --- .../gmouse_lld_MCU_board.h | 18 +++++------ .../Olimex-STM32-LCD/gmouse_lld_MCU_board.h | 16 ++++------ drivers/ginput/touch/MCU/gmouse_lld_MCU.c | 15 +++------ .../touch/MCU/gmouse_lld_MCU_board_template.h | 32 ++++++++----------- 4 files changed, 33 insertions(+), 48 deletions(-) diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h b/boards/base/Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h index 7624cdf3..15c00e66 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h @@ -8,15 +8,20 @@ #ifndef _LLD_GMOUSE_MCU_BOARD_H #define _LLD_GMOUSE_MCU_BOARD_H -// We directly define the jitter settings +// Resolution and Accuracy Settings #define GMOUSE_MCU_PEN_CALIBRATE_ERROR 8 #define GMOUSE_MCU_PEN_CLICK_ERROR 6 #define GMOUSE_MCU_PEN_MOVE_ERROR 4 #define GMOUSE_MCU_FINGER_CALIBRATE_ERROR 14 #define GMOUSE_MCU_FINGER_CLICK_ERROR 18 #define GMOUSE_MCU_FINGER_MOVE_ERROR 14 +#define GMOUSE_MCU_Z_MIN 0 +#define GMOUSE_MCU_Z_MAX 4095 +#define GMOUSE_MCU_Z_TOUCHON 3090 +#define GMOUSE_MCU_Z_TOUCHOFF 400 -// Now board specific settings... +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_MCU_BOARD_DATA_SIZE 0 #define ADC_NUM_CHANNELS 2 #define ADC_BUF_DEPTH 1 @@ -36,13 +41,6 @@ static const ADCConversionGroup adcgrpcfg = { ADC_SQR3_SQ2_N(ADC_CHANNEL_IN8) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN9) }; -#define BOARD_DATA_SIZE 0 // How many extra bytes to add on the end of the mouse structure for the board's use - -#define Z_MIN 0 // The minimum Z reading -#define Z_MAX 4095 // The maximum Z reading (12 bits) -#define Z_TOUCHON 3090 // Values between this and Z_MAX are definitely pressed -#define Z_TOUCHOFF 400 // Values between this and Z_MIN are definitely not pressed - static bool_t init_board(GMouse *m, unsigned driverinstance) { (void) m; @@ -71,7 +69,7 @@ static void read_xyz(GMouse *m, GMouseReading *prd) { prd->z = samples[0]; // Take a shortcut and don't read x, y if we know we are definitely not touched. - if (prd->z >= Z_TOUCHOFF) { + if (prd->z >= GMOUSE_MCU_Z_TOUCHOFF) { // Get the x reading palSetPad(GPIOB, GPIOB_DRIVEA); diff --git a/boards/base/Olimex-STM32-LCD/gmouse_lld_MCU_board.h b/boards/base/Olimex-STM32-LCD/gmouse_lld_MCU_board.h index 8f085f84..8c90946f 100644 --- a/boards/base/Olimex-STM32-LCD/gmouse_lld_MCU_board.h +++ b/boards/base/Olimex-STM32-LCD/gmouse_lld_MCU_board.h @@ -8,15 +8,20 @@ #ifndef _LLD_GMOUSE_MCU_BOARD_H #define _LLD_GMOUSE_MCU_BOARD_H -// We directly define the jitter settings +// Resolution and Accuracy Settings #define GMOUSE_MCU_PEN_CALIBRATE_ERROR 8 #define GMOUSE_MCU_PEN_CLICK_ERROR 6 #define GMOUSE_MCU_PEN_MOVE_ERROR 4 #define GMOUSE_MCU_FINGER_CALIBRATE_ERROR 14 #define GMOUSE_MCU_FINGER_CLICK_ERROR 18 #define GMOUSE_MCU_FINGER_MOVE_ERROR 14 +#define GMOUSE_MCU_Z_MIN 0 +#define GMOUSE_MCU_Z_MAX 1 +#define GMOUSE_MCU_Z_TOUCHON 1 +#define GMOUSE_MCU_Z_TOUCHOFF 0 -// Now board specific settings... +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_MCU_BOARD_DATA_SIZE 0 #define ADC_NUM_CHANNELS 2 #define ADC_BUF_DEPTH 1 @@ -45,13 +50,6 @@ static const ADCConversionGroup adc_x_config = { ADC_SQR3_SQ2_N(ADC_CHANNEL_IN10) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11) }; -#define BOARD_DATA_SIZE 0 // How many extra bytes to add on the end of the mouse structure for the board's use - -#define Z_MIN 0 // The minimum Z reading -#define Z_MAX 1 // The maximum Z reading -#define Z_TOUCHON 1 // Values between this and Z_MAX are definitely pressed -#define Z_TOUCHOFF 0 // Values between this and Z_MIN are definitely not pressed - static inline void setup_z(void) { palSetPadMode(GPIOC, 0, PAL_MODE_INPUT_PULLDOWN); palSetPadMode(GPIOC, 1, PAL_MODE_INPUT); diff --git a/drivers/ginput/touch/MCU/gmouse_lld_MCU.c b/drivers/ginput/touch/MCU/gmouse_lld_MCU.c index 222b759b..babf8bc3 100644 --- a/drivers/ginput/touch/MCU/gmouse_lld_MCU.c +++ b/drivers/ginput/touch/MCU/gmouse_lld_MCU.c @@ -15,11 +15,6 @@ // Get the hardware interface #include "gmouse_lld_MCU_board.h" -// If the board file doesn't specify how many extra bytes it wants - assume 0 -#ifndef BOARD_DATA_SIZE - #define BOARD_DATA_SIZE 0 -#endif - const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ { GDRIVER_TYPE_TOUCH, @@ -28,13 +23,13 @@ const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ // Extra flags for testing only //GMOUSE_VFLG_DEFAULTFINGER|GMOUSE_VFLG_CAL_EXTREMES - Possible //GMOUSE_VFLG_NOPOLL|GMOUSE_VFLG_DYNAMICONLY|GMOUSE_VFLG_SELFROTATION|GMOUSE_VFLG_CAL_LOADFREE - unlikely - sizeof(GMouse)+BOARD_DATA_SIZE, + sizeof(GMouse) + GMOUSE_MCU_BOARD_DATA_SIZE, _gmouseInitDriver, _gmousePostInitDriver, _gmouseDeInitDriver }, - Z_MAX, // z_max - Z_MIN, // z_min - Z_TOUCHON, // z_touchon - Z_TOUCHOFF, // z_touchoff + GMOUSE_MCU_Z_MAX, // z_max + GMOUSE_MCU_Z_MIN, // z_min + GMOUSE_MCU_Z_TOUCHON, // z_touchon + GMOUSE_MCU_Z_TOUCHOFF, // z_touchoff { // pen_jitter GMOUSE_MCU_PEN_CALIBRATE_ERROR, // calibrate GMOUSE_MCU_PEN_CLICK_ERROR, // click diff --git a/drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h b/drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h index 5366b16c..07583fa9 100644 --- a/drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h +++ b/drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h @@ -8,26 +8,20 @@ #ifndef _LLD_GMOUSE_MCU_BOARD_H #define _LLD_GMOUSE_MCU_BOARD_H -// Either define your jitter settings here or define them in the config include file -#if 0 - #include "gmouse_lld_MCU_config.h" -#else - #define GMOUSE_MCU_PEN_CALIBRATE_ERROR 2 - #define GMOUSE_MCU_PEN_CLICK_ERROR 2 - #define GMOUSE_MCU_PEN_MOVE_ERROR 2 - #define GMOUSE_MCU_FINGER_CALIBRATE_ERROR 4 - #define GMOUSE_MCU_FINGER_CLICK_ERROR 4 - #define GMOUSE_MCU_FINGER_MOVE_ERROR 4 -#endif +// Resolution and Accuracy Settings +#define GMOUSE_MCU_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_MCU_PEN_CLICK_ERROR 6 +#define GMOUSE_MCU_PEN_MOVE_ERROR 4 +#define GMOUSE_MCU_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_MCU_FINGER_CLICK_ERROR 18 +#define GMOUSE_MCU_FINGER_MOVE_ERROR 14 +#define GMOUSE_MCU_Z_MIN 0 // The minimum Z reading +#define GMOUSE_MCU_Z_MAX 100 // The maximum Z reading +#define GMOUSE_MCU_Z_TOUCHON 80 // Values between this and Z_MAX are definitely pressed +#define GMOUSE_MCU_Z_TOUCHOFF 70 // Values between this and Z_MIN are definitely not pressed -// Now board specific settings... - -#define BOARD_DATA_SIZE 0 // How many extra bytes to add on the end of the mouse structure for the board's use - -#define Z_MIN 0 // The minimum Z reading -#define Z_MAX 100 // The maximum Z reading -#define Z_TOUCHON 80 // Values between this and Z_MAX are definitely pressed -#define Z_TOUCHOFF 70 // Values between this and Z_MIN are definitely not pressed +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_MCU_BOARD_DATA_SIZE 0 static bool_t init_board(GMouse *m, unsigned driverinstance) { } From cf3b8e4ed25d74d03cc6e246fe0f4ee129b17bc1 Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 13 Oct 2014 16:37:04 +1000 Subject: [PATCH 61/87] Add GMouse parameter to ADS7843 mouse driver to enable multiple drivers. Tidy up naming. --- .../gmouse_lld_ADS7843_board.h | 21 ++++++++++---- .../ginput/touch/ADS7843/gmouse_lld_ADS7843.c | 29 +++++++------------ .../gmouse_lld_ADS7843_board_template.h | 12 +++++--- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/boards/base/FireBull-STM32F103-FB/gmouse_lld_ADS7843_board.h b/boards/base/FireBull-STM32F103-FB/gmouse_lld_ADS7843_board.h index e4f30818..b202dd85 100644 --- a/boards/base/FireBull-STM32F103-FB/gmouse_lld_ADS7843_board.h +++ b/boards/base/FireBull-STM32F103-FB/gmouse_lld_ADS7843_board.h @@ -8,6 +8,7 @@ #ifndef _GINPUT_LLD_MOUSE_BOARD_H #define _GINPUT_LLD_MOUSE_BOARD_H +// Resolution and Accuracy Settings #define GMOUSE_ADS7843_PEN_CALIBRATE_ERROR 2 #define GMOUSE_ADS7843_PEN_CLICK_ERROR 2 #define GMOUSE_ADS7843_PEN_MOVE_ERROR 2 @@ -15,6 +16,9 @@ #define GMOUSE_ADS7843_FINGER_CLICK_ERROR 4 #define GMOUSE_ADS7843_FINGER_MOVE_ERROR 4 +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_ADS7843_BOARD_DATA_SIZE 0 + static const SPIConfig spicfg = { 0, GPIOC, @@ -39,28 +43,35 @@ static bool_t init_board(GMouse* m, unsigned driverinstance) return TRUE; } -static inline bool_t getpin_pressed(void) -{ +static inline bool_t getpin_pressed(GMouse* m) +{ + (void) m; + return (!palReadPad(GPIOC, 4)); } -static inline void aquire_bus(void) +static inline void aquire_bus(GMouse* m) { + (void) m; + spiAcquireBus(&SPID1); palClearPad(GPIOC, 6); } -static inline void release_bus(void) +static inline void release_bus(GMouse* m) { + (void) m; + palSetPad(GPIOC, 6); spiReleaseBus(&SPID1); } -static inline uint16_t read_value(uint16_t port) +static inline uint16_t read_value(GMouse* m, uint16_t port) { static uint8_t txbuf[3] = {0}; static uint8_t rxbuf[3] = {0}; uint16_t ret; + (void) m; txbuf[0] = port; diff --git a/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c index 72cd6f67..ac315262 100644 --- a/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c +++ b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c @@ -15,39 +15,32 @@ // Get the hardware interface #include "gmouse_lld_ADS7843_board.h" -// If the board file doesn't specify how many extra bytes it wants - assume 0 -#ifndef BOARD_DATA_SIZE - #define BOARD_DATA_SIZE 0 -#endif - #define CMD_X 0xD1 #define CMD_Y 0x91 #define CMD_ENABLE_IRQ 0x80 -void read_xyz(GMouse* m, GMouseReading* pdr) +static void MouseXYZ(GMouse* m, GMouseReading* pdr) { (void)m; // No buttons pdr->buttons = 0; + pdr->z = 0; - if (getpin_pressed()) { + if (getpin_pressed(m)) { pdr->z = 1; // Set to Z_MAX as we are pressed - aquire_bus(); + aquire_bus(m); - read_value(CMD_X); // Dummy read - disable PenIRQ - pdr->x = read_value(CMD_X); // Read X-Value + read_value(m, CMD_X); // Dummy read - disable PenIRQ + pdr->x = read_value(m, CMD_X); // Read X-Value - read_value(CMD_Y); // Dummy read - disable PenIRQ - pdr->y = read_value(CMD_Y); // Read Y-Value + read_value(m, CMD_Y); // Dummy read - disable PenIRQ + pdr->y = read_value(m, CMD_Y); // Read Y-Value - read_value(CMD_ENABLE_IRQ); // Enable IRQ + read_value(m, CMD_ENABLE_IRQ); // Enable IRQ - release_bus(); - } else { - // Don't touch x and y values here - pdr->z = 0; + release_bus(m); } } @@ -77,7 +70,7 @@ const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ }, init_board, // init 0, // deinit - read_xyz, // get + MouseXYZ, // get 0, // calsave 0 // calload }}; diff --git a/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843_board_template.h b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843_board_template.h index 7b762310..5a09b5bd 100644 --- a/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843_board_template.h +++ b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843_board_template.h @@ -8,6 +8,7 @@ #ifndef _GINPUT_LLD_MOUSE_BOARD_H #define _GINPUT_LLD_MOUSE_BOARD_H +// Resolution and Accuracy Settings #define GMOUSE_ADS7843_PEN_CALIBRATE_ERROR 2 #define GMOUSE_ADS7843_PEN_CLICK_ERROR 2 #define GMOUSE_ADS7843_PEN_MOVE_ERROR 2 @@ -15,23 +16,26 @@ #define GMOUSE_ADS7843_FINGER_CLICK_ERROR 4 #define GMOUSE_ADS7843_FINGER_MOVE_ERROR 4 +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_ADS7843_BOARD_DATA_SIZE 0 + static bool_t init_board(GMouse* m, unsigned driverinstance) { } -static inline bool_t getpin_pressed(void) { +static inline bool_t getpin_pressed(GMouse* m) { } -static inline void aquire_bus(void) { +static inline void aquire_bus(GMouse* m) { } -static inline void release_bus(void) { +static inline void release_bus(GMouse* m) { } -static inline uint16_t read_value(uint16_t port) { +static inline uint16_t read_value(GMouse* m, uint16_t port) { } From b7baee596b7fe1689db3ed4d02decd96cf2fe28f Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 13 Oct 2014 16:37:48 +1000 Subject: [PATCH 62/87] Convert FT5x06 mouse driver to newmouse (untested) --- boards/base/Marlin/ginput_lld_mouse_board.h | 111 ---------------- boards/base/Marlin/ginput_lld_mouse_config.h | 32 ----- boards/base/Marlin/gmouse_lld_FT5x06_board.h | 93 ++++++++++++++ .../ginput/touch/FT5x06/ginput_lld_mouse.c | 88 ------------- .../FT5x06/ginput_lld_mouse_board_template.h | 27 ---- .../touch/FT5x06/ginput_lld_mouse_config.h | 21 --- .../ginput/touch/FT5x06/gmouse_lld_FT5x06.c | 120 ++++++++++++++++++ .../FT5x06/gmouse_lld_FT5x06_board_template.h | 46 +++++++ 8 files changed, 259 insertions(+), 279 deletions(-) delete mode 100644 boards/base/Marlin/ginput_lld_mouse_board.h delete mode 100644 boards/base/Marlin/ginput_lld_mouse_config.h create mode 100644 boards/base/Marlin/gmouse_lld_FT5x06_board.h delete mode 100644 drivers/ginput/touch/FT5x06/ginput_lld_mouse.c delete mode 100644 drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_template.h delete mode 100644 drivers/ginput/touch/FT5x06/ginput_lld_mouse_config.h create mode 100644 drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c create mode 100644 drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06_board_template.h diff --git a/boards/base/Marlin/ginput_lld_mouse_board.h b/boards/base/Marlin/ginput_lld_mouse_board.h deleted file mode 100644 index d787d224..00000000 --- a/boards/base/Marlin/ginput_lld_mouse_board.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -/** - * @file drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_marlin.h - * @brief GINPUT Touch low level driver source for the FT5x06. - * - * @defgroup Mouse Mouse - * @ingroup GINPUT - * @{ - */ - -#ifndef _GINPUT_LLD_MOUSE_BOARD_H -#define _GINPUT_LLD_MOUSE_BOARD_H - -/* I2C interface #2 - Touchscreen controller */ -static const I2CConfig i2ccfg2 = { - OPMODE_I2C, - 400000, - FAST_DUTY_CYCLE_2, -}; - -/** - * @brief Initialise the board for the touch. - * - * @notapi - */ -static void init_board(void) { - -} - - -/** - * @brief Write a value into a certain register - * - * @param[in] reg The register address - * @param[in] n The amount of bytes (one or two) - * @param[in] val The value - * - * @notapi - */ -static void write_reg(uint8_t reg, uint8_t n, uint16_t val) { - uint8_t txbuf[3]; - - i2cAcquireBus(&I2CD2); - - txbuf[0] = reg; - - if (n == 1) { - txbuf[1] = val; - i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, txbuf, 2, 0, 0, MS2ST(FT5x06_TIMEOUT)); - } else if (n == 2) { - txbuf[1] = ((val & 0xFF00) >> 8); - txbuf[2] = (val & 0x00FF); - i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, txbuf, 3, 0, 0, MS2ST(FT5x06_TIMEOUT)); - } - - i2cReleaseBus(&I2CD2); -} - -/** - * @brief Read the value of a certain register - * - * @param[in] reg The register address - * @param[in] n The amount of bytes (one or two) - * - * @return Data read from device (one byte or two depending on n param) - * - * @notapi - */ -static uint16_t read_reg(uint8_t reg, uint8_t n) { - uint8_t txbuf[1], rxbuf[2]; - uint16_t ret; - - rxbuf[0] = 0; - rxbuf[1] = 0; - - i2cAcquireBus(&I2CD2); - - txbuf[0] = reg; - i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, txbuf, 1, rxbuf, n, MS2ST(FT5x06_TIMEOUT)); - - if (n == 1) { - ret = rxbuf[0]; - } else if (n == 2) { - ret = ((rxbuf[0] << 8) | (rxbuf[1] & 0xFF)); - } - - i2cReleaseBus(&I2CD2); - - return ret; -} - -static void read_reg_n(uint8_t reg, uint8_t n, uint8_t *rxbuf) { - uint8_t txbuf[1]; - - i2cAcquireBus(&I2CD2); - - txbuf[0] = reg; - i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, txbuf, 1, rxbuf, n, MS2ST(FT5x06_TIMEOUT)); - - i2cReleaseBus(&I2CD2); -} - -#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ -/** @} */ - diff --git a/boards/base/Marlin/ginput_lld_mouse_config.h b/boards/base/Marlin/ginput_lld_mouse_config.h deleted file mode 100644 index 57d3f135..00000000 --- a/boards/base/Marlin/ginput_lld_mouse_config.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -/** - * @file drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h - * @brief GINPUT LLD header file for mouse/touch driver. - * - * @defgroup Mouse Mouse - * @ingroup GINPUT - * - * @{ - */ - -#ifndef _LLD_GINPUT_MOUSE_CONFIG_H -#define _LLD_GINPUT_MOUSE_CONFIG_H - -#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH -#define GINPUT_MOUSE_NEED_CALIBRATION TRUE -#define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE -#define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 15 -#define GINPUT_MOUSE_READ_CYCLES 1 -#define GINPUT_MOUSE_POLL_PERIOD 25 -#define GINPUT_MOUSE_MAX_CLICK_JITTER 10 -#define GINPUT_MOUSE_MAX_MOVE_JITTER 5 -#define GINPUT_MOUSE_CLICK_TIME 450 - -#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ -/** @} */ diff --git a/boards/base/Marlin/gmouse_lld_FT5x06_board.h b/boards/base/Marlin/gmouse_lld_FT5x06_board.h new file mode 100644 index 00000000..ac961d0e --- /dev/null +++ b/boards/base/Marlin/gmouse_lld_FT5x06_board.h @@ -0,0 +1,93 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _GINPUT_LLD_MOUSE_BOARD_H +#define _GINPUT_LLD_MOUSE_BOARD_H + +// Resolution and Accuracy Settings +#define GMOUSE_FT5x06_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_FT5x06_PEN_CLICK_ERROR 6 +#define GMOUSE_FT5x06_PEN_MOVE_ERROR 4 +#define GMOUSE_FT5x06_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_FT5x06_FINGER_CLICK_ERROR 18 +#define GMOUSE_FT5x06_FINGER_MOVE_ERROR 14 + +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_FT5x06_BOARD_DATA_SIZE 0 + +// Set this to TRUE if you want self-calibration. +// NOTE: This is not as accurate as real calibration. +// It requires the orientation of the touch panel to match the display. +// It requires the active area of the touch panel to exactly match the display size. +#define GMOUSE_FT5x06_SELF_CALIBRATE FALSE + +/* I2C interface #2 - Touchscreen controller */ +static const I2CConfig i2ccfg2 = { + OPMODE_I2C, + 400000, + FAST_DUTY_CYCLE_2, +}; + +static bool_t init_board(GMouse* m, unsigned driverinstance) { + (void) m; + + // We only support one of these on this board + if (driverinstance) + return FALSE; + return TRUE; +} + +static inline void aquire_bus(GMouse* m) { + (void) m; + +} + +static inline void release_bus(GMouse* m) { + (void) m; + +} + +static void write_reg(GMouse* m, uint8_t reg, uint8_t val) { + uint8_t txbuf[2]; + (void) m; + + txbuf[0] = reg; + txbuf[1] = val; + + i2cAcquireBus(&I2CD2); + i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, txbuf, 2, 0, 0, MS2ST(FT5x06_TIMEOUT)); + i2cReleaseBus(&I2CD2); +} + +static uint8_t read_byte(GMouse* m, uint8_t reg) { + uint8_t rxbuf[1]; + (void) m; + + rxbuf[0] = 0; + + i2cAcquireBus(&I2CD2); + i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, ®, 1, rxbuf, 1, MS2ST(FT5x06_TIMEOUT)); + i2cReleaseBus(&I2CD2); + + return rxbuf[0]; +} + +static uint16_t read_word(GMouse* m, uint8_t reg) { + uint8_t rxbuf[2]; + (void) m; + + rxbuf[0] = 0; + rxbuf[1] = 0; + + i2cAcquireBus(&I2CD2); + i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, ®, 1, rxbuf, 2, MS2ST(FT5x06_TIMEOUT)); + i2cReleaseBus(&I2CD2); + + return (((uint16_t)rxbuf[0]) << 8) | rxbuf[1]; +} + +#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ diff --git a/drivers/ginput/touch/FT5x06/ginput_lld_mouse.c b/drivers/ginput/touch/FT5x06/ginput_lld_mouse.c deleted file mode 100644 index 7a50c5f6..00000000 --- a/drivers/ginput/touch/FT5x06/ginput_lld_mouse.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#include "gfx.h" - -#if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) /*|| defined(__DOXYGEN__)*/ - -#include "src/ginput/driver_mouse.h" - -#include "drivers/ginput/touch/FT5x06/ft5x06.h" - -// include board abstraction -#include "ginput_lld_mouse_board.h" - -static coord_t x, y, z; -static uint8_t touched; - -void ginput_lld_mouse_init(void) { - init_board(); - - // Init default values. (From NHD-3.5-320240MF-ATXL-CTP-1 datasheet) - // Valid touching detect threshold - write_reg(FT5x06_ID_G_THGROUP, 1, 0x16); - - // valid touching peak detect threshold - write_reg(FT5x06_ID_G_THPEAK, 1, 0x3C); - - // Touch focus threshold - write_reg(FT5x06_ID_G_THCAL, 1, 0xE9); - - // threshold when there is surface water - write_reg(FT5x06_ID_G_THWATER, 1, 0x01); - - // threshold of temperature compensation - write_reg(FT5x06_ID_G_THTEMP, 1, 0x01); - - // Touch difference threshold - write_reg(FT5x06_ID_G_THDIFF, 1, 0xA0); - - // Delay to enter 'Monitor' status (s) - write_reg(FT5x06_ID_G_TIME_ENTER_MONITOR, 1, 0x0A); - - // Period of 'Active' status (ms) - write_reg(FT5x06_ID_G_PERIODACTIVE, 1, 0x06); - - // Timer to enter ÔidleŐ when in 'Monitor' (ms) - write_reg(FT5x06_ID_G_PERIODMONITOR, 1, 0x28); -} - -void ginput_lld_mouse_get_reading(MouseReading *pt) { - // Poll to get the touched status - uint8_t last_touched; - - last_touched = touched; - touched = (uint8_t)read_reg(FT5x06_TOUCH_POINTS, 1) & 0x07; - - // If not touched, return the previous results - if (touched == 0) { - pt->x = x; - pt->y = y; - pt->z = 0; - pt->buttons = 0; - return; - } - - /* Get the X, Y, Z values */ - x = (coord_t)(read_reg(FT5x06_TOUCH1_XH, 2) & 0x0fff); - y = (coord_t)read_reg(FT5x06_TOUCH1_YH, 2); - z = 100; - - // Rescale X,Y,Z - X & Y don't need scaling when you are using calibration! -#if !GINPUT_MOUSE_NEED_CALIBRATION - x = gdispGetWidth() - x / (4096/gdispGetWidth()); - y = y / (4096/gdispGetHeight()); -#endif - - // Return the results. ADC gives values from 0 to 2^12 (4096) - pt->x = x; - pt->y = y; - pt->z = z; - pt->buttons = GINPUT_TOUCH_PRESSED; -} - -#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */ diff --git a/drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_template.h b/drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_template.h deleted file mode 100644 index b7744a49..00000000 --- a/drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_template.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _GINPUT_LLD_MOUSE_BOARD_H -#define _GINPUT_LLD_MOUSE_BOARD_H - -static void init_board(void) { - -} - -static inline bool_t getpin_irq(void) { - -} - -static void write_reg(uint8_t reg, uint8_t n, uint16_t val) { - -} - -static uint16_t read_reg(uint8_t reg, uint8_t n) { - -} - -#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ diff --git a/drivers/ginput/touch/FT5x06/ginput_lld_mouse_config.h b/drivers/ginput/touch/FT5x06/ginput_lld_mouse_config.h deleted file mode 100644 index 24335a0a..00000000 --- a/drivers/ginput/touch/FT5x06/ginput_lld_mouse_config.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _LLD_GINPUT_MOUSE_CONFIG_H -#define _LLD_GINPUT_MOUSE_CONFIG_H - -#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH -#define GINPUT_MOUSE_NEED_CALIBRATION TRUE -#define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE -#define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 15 -#define GINPUT_MOUSE_READ_CYCLES 1 -#define GINPUT_MOUSE_POLL_PERIOD 25 -#define GINPUT_MOUSE_MAX_CLICK_JITTER 10 -#define GINPUT_MOUSE_MAX_MOVE_JITTER 5 -#define GINPUT_MOUSE_CLICK_TIME 450 - -#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ diff --git a/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c b/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c new file mode 100644 index 00000000..ed2e68fa --- /dev/null +++ b/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c @@ -0,0 +1,120 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#include "gfx.h" + +#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE + +#define GMOUSE_DRIVER_VMT GMOUSEVMT_FT5x06 +#include "src/ginput/driver_mouse.h" + +// Get the hardware interface +#include "gmouse_lld_FT5x06_board.h" + +// Hardware definitions +#include "drivers/ginput/touch/FT5x06/ft5x06.h" + +static bool_t MouseInit(GMouse* m, unsigned driverinstance) { + if (!init_board(m, driverinstance)) + return FALSE; + + aquire_bus(m); + + // Init default values. (From NHD-3.5-320240MF-ATXL-CTP-1 datasheet) + // Valid touching detect threshold + write_reg(m, FT5x06_ID_G_THGROUP, 0x16); + + // valid touching peak detect threshold + write_reg(m, FT5x06_ID_G_THPEAK, 0x3C); + + // Touch focus threshold + write_reg(m, FT5x06_ID_G_THCAL, 0xE9); + + // threshold when there is surface water + write_reg(m, FT5x06_ID_G_THWATER, 0x01); + + // threshold of temperature compensation + write_reg(m, FT5x06_ID_G_THTEMP, 0x01); + + // Touch difference threshold + write_reg(m, FT5x06_ID_G_THDIFF, 0xA0); + + // Delay to enter 'Monitor' status (s) + write_reg(m, FT5x06_ID_G_TIME_ENTER_MONITOR, 0x0A); + + // Period of 'Active' status (ms) + write_reg(m, FT5x06_ID_G_PERIODACTIVE, 0x06); + + // Timer to enter 'idle' when in 'Monitor' (ms) + write_reg(m, FT5x06_ID_G_PERIODMONITOR, 0x28); + + release_bus(m); + return TRUE; +} + +static void MouseXYZ(GMouse* m, GMouseReading* pdr) +{ + // Assume not touched. + pdr->buttons = 0; + pdr->z = 0; + + aquire_bus(m); + + // Only take a reading if we are touched. + if ((read_byte(m, FT5x06_TOUCH_POINTS) & 0x07)) { + + /* Get the X, Y, Z values */ + pdr->x = (coord_t)(read_word(m, FT5x06_TOUCH1_XH) & 0x0fff); + pdr->y = (coord_t)read_word(m, FT5x06_TOUCH1_YH); + pdr->z = 1; + + #if GMOUSE_FT5x06_SELF_CALIBRATE + // Rescale X,Y,Z - If we are using self-calibration + pdr->x = gdispGGetWidth(m->display) - pdr->x / (4096/gdispGGetWidth(m->display)); + pdr->y = pdr->y / (4096/gdispGGetHeight(m->display)); + #endif + } + + release_bus(m); +} + +const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ + { + GDRIVER_TYPE_TOUCH, + #if GMOUSE_FT5x06_SELF_CALIBRATE + GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN, + #else + GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN | GMOUSE_VFLG_CALIBRATE | GMOUSE_VFLG_CAL_TEST, + #endif + sizeof(GMouse) + GMOUSE_FT5x06_BOARD_DATA_SIZE, + _gmouseInitDriver, + _gmousePostInitDriver, + _gmouseDeInitDriver + }, + 1, // z_max - (currently?) not supported + 0, // z_min - (currently?) not supported + 1, // z_touchon + 0, // z_touchoff + { // pen_jitter + GMOUSE_FT5x06_PEN_CALIBRATE_ERROR, // calibrate + GMOUSE_FT5x06_PEN_CLICK_ERROR, // click + GMOUSE_FT5x06_PEN_MOVE_ERROR // move + }, + { // finger_jitter + GMOUSE_FT5x06_FINGER_CALIBRATE_ERROR, // calibrate + GMOUSE_FT5x06_FINGER_CLICK_ERROR, // click + GMOUSE_FT5x06_FINGER_MOVE_ERROR // move + }, + MouseInit, // init + 0, // deinit + read_xyz, // get + 0, // calsave + 0 // calload +}}; + +#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */ + diff --git a/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06_board_template.h b/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06_board_template.h new file mode 100644 index 00000000..46680a16 --- /dev/null +++ b/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06_board_template.h @@ -0,0 +1,46 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _GINPUT_LLD_MOUSE_BOARD_H +#define _GINPUT_LLD_MOUSE_BOARD_H + +// Resolution and Accuracy Settings +#define GMOUSE_FT5x06_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_FT5x06_PEN_CLICK_ERROR 6 +#define GMOUSE_FT5x06_PEN_MOVE_ERROR 4 +#define GMOUSE_FT5x06_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_FT5x06_FINGER_CLICK_ERROR 18 +#define GMOUSE_FT5x06_FINGER_MOVE_ERROR 14 + +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_FT5x06_BOARD_DATA_SIZE 0 + +// Set this to TRUE if you want self-calibration. +// NOTE: This is not as accurate as real calibration. +// It requires the orientation of the touch panel to match the display. +// It requires the active area of the touch panel to exactly match the display size. +#define GMOUSE_FT5x06_SELF_CALIBRATE FALSE + +static bool_t init_board(GMouse* m, unsigned driverinstance) { +} + +static inline void aquire_bus(GMouse* m) { +} + +static inline void release_bus(GMouse* m) { +} + +static void write_reg(GMouse* m, uint8_t reg, uint8_t val) { +} + +static uint8_t read_byte(GMouse* m, uint8_t reg) { +} + +static uint16_t read_word(GMouse* m, uint8_t reg) { +} + +#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ From 65a165f1e01cc5b52b1a46f3a56dec452fdfa943 Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 13 Oct 2014 17:42:43 +1000 Subject: [PATCH 63/87] Update newmouse driver makefiles --- drivers/ginput/touch/ADS7843/driver.mk | 3 --- drivers/ginput/touch/FT5x06/driver.mk | 5 +---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/ginput/touch/ADS7843/driver.mk b/drivers/ginput/touch/ADS7843/driver.mk index 221dd4fc..1a0eaf8e 100644 --- a/drivers/ginput/touch/ADS7843/driver.mk +++ b/drivers/ginput/touch/ADS7843/driver.mk @@ -1,5 +1,2 @@ # List the required driver. GFXSRC += $(GFXLIB)/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c - -# Required include directories -GFXINC += $(GFXLIB)/drivers/ginput/touch/ADS7843 diff --git a/drivers/ginput/touch/FT5x06/driver.mk b/drivers/ginput/touch/FT5x06/driver.mk index 17d38c61..741464e8 100644 --- a/drivers/ginput/touch/FT5x06/driver.mk +++ b/drivers/ginput/touch/FT5x06/driver.mk @@ -1,5 +1,2 @@ # List the required driver. -GFXSRC += $(GFXLIB)/drivers/ginput/touch/FT5x06/ginput_lld_mouse.c - -# Required include directories -GFXINC += $(GFXLIB)/drivers/ginput/touch/FT5x06 +GFXSRC += $(GFXLIB)/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c From 386cbe90b8e50b96945141af6640ba68e97b93dc Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 13 Oct 2014 17:43:10 +1000 Subject: [PATCH 64/87] New flag for newmouse driver use --- src/ginput/driver_mouse.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ginput/driver_mouse.h b/src/ginput/driver_mouse.h index 4a61d46b..037f9c0f 100644 --- a/src/ginput/driver_mouse.h +++ b/src/ginput/driver_mouse.h @@ -49,6 +49,7 @@ typedef struct GMouse { #define GMOUSE_FLG_IN_CAL 0x0010 // Currently in calibration routine #define GMOUSE_FLG_FINGERMODE 0x0020 // Mouse is currently in finger mode #define GMOUSE_FLG_NEEDREAD 0x0040 // The mouse needs reading + #define GMOUSE_FLG_DRIVER_FIRST 0x0100 // The first flag available for the driver point clickpos; // The position of the last click event systemticks_t clicktime; // The time of the last click event GDisplay * display; // The display the mouse is associated with From 39c4d3207ca790aedb34217e6864e6f14ca62b2f Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 13 Oct 2014 17:43:37 +1000 Subject: [PATCH 65/87] Remove unnecessary file --- .../touch/MCU/gmouse_lld_MCU_config_template.h | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 drivers/ginput/touch/MCU/gmouse_lld_MCU_config_template.h diff --git a/drivers/ginput/touch/MCU/gmouse_lld_MCU_config_template.h b/drivers/ginput/touch/MCU/gmouse_lld_MCU_config_template.h deleted file mode 100644 index 303557b4..00000000 --- a/drivers/ginput/touch/MCU/gmouse_lld_MCU_config_template.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _LLD_GMOUSE_MCU_CONFIG_H -#define _LLD_GMOUSE_MCU_CONFIG_H - -#define GMOUSE_MCU_PEN_CALIBRATE_ERROR 2 -#define GMOUSE_MCU_PEN_CLICK_ERROR 2 -#define GMOUSE_MCU_PEN_MOVE_ERROR 2 -#define GMOUSE_MCU_FINGER_CALIBRATE_ERROR 4 -#define GMOUSE_MCU_FINGER_CLICK_ERROR 4 -#define GMOUSE_MCU_FINGER_MOVE_ERROR 4 - -#endif /* _LLD_GMOUSE_MCU_CONFIG_H */ From 7c9e3e5a4206a9bfee1928dbdeb3a1db92b9514b Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 13 Oct 2014 17:44:15 +1000 Subject: [PATCH 66/87] Port SMTPE811 mouse driver to newmouse (and supported boards) --- .../ginput_lld_mouse_board.h | 88 ---------- .../ginput_lld_mouse_config.h | 22 --- .../gmouse_lld_STMPE811_board.h | 112 ++++++++++++ drivers/ginput/touch/STMPE811/driver.mk | 5 +- .../ginput/touch/STMPE811/ginput_lld_mouse.c | 132 -------------- .../ginput_lld_mouse_board_template.h | 27 --- .../touch/STMPE811/ginput_lld_mouse_config.h | 25 --- .../touch/STMPE811/gmouse_lld_STMPE811.c | 164 ++++++++++++++++++ .../gmouse_lld_STMPE811_board_template.h | 58 +++++++ 9 files changed, 335 insertions(+), 298 deletions(-) delete mode 100644 boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_board.h delete mode 100644 boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_config.h create mode 100644 boards/base/Embest-STM32-DMSTF4BB/gmouse_lld_STMPE811_board.h delete mode 100644 drivers/ginput/touch/STMPE811/ginput_lld_mouse.c delete mode 100644 drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_template.h delete mode 100644 drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h create mode 100644 drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c create mode 100644 drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811_board_template.h diff --git a/boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_board.h b/boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_board.h deleted file mode 100644 index d525e268..00000000 --- a/boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_board.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _GINPUT_LLD_MOUSE_BOARD_H -#define _GINPUT_LLD_MOUSE_BOARD_H - -static const I2CConfig i2ccfg = { - OPMODE_I2C, - 400000, - FAST_DUTY_CYCLE_2, -}; - -static void init_board(void) -{ - palSetPadMode(GPIOC, 13, PAL_MODE_INPUT | PAL_STM32_PUDR_FLOATING); /* TP IRQ */ - palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SCL */ - palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SDA */ - - i2cStart(&I2CD1, &i2ccfg); -} - -static inline bool_t getpin_irq(void) -{ - return (!(palReadPad(GPIOC, 13))); -} - -static void write_reg(uint8_t reg, uint8_t n, uint16_t val) -{ - uint8_t txbuf[3]; - - i2cAcquireBus(&I2CD1); - - txbuf[0] = reg; - - if (n == 1) { - txbuf[1] = val; - i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 2, 0, 0, MS2ST(STMPE811_TIMEOUT)); - } else if (n == 2) { - txbuf[1] = ((val & 0xFF00) >> 8); - txbuf[2] = (val & 0x00FF); - i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 3, 0, 0, MS2ST(STMPE811_TIMEOUT)); - } - - i2cReleaseBus(&I2CD1); -} - -static uint16_t read_reg(uint8_t reg, uint8_t n) -{ - uint8_t txbuf[1], rxbuf[2]; - uint16_t ret; - - rxbuf[0] = 0; - rxbuf[1] = 0; - - i2cAcquireBus(&I2CD1); - - txbuf[0] = reg; - i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 1, rxbuf, n, MS2ST(STMPE811_TIMEOUT)); - - if (n == 1) { - ret = rxbuf[0]; - } else if (n == 2) { - ret = ((rxbuf[0] << 8) | (rxbuf[1] & 0xFF)); - } - - i2cReleaseBus(&I2CD1); - - return ret; -} - -static void read_reg_n(uint8_t reg, uint8_t n, uint8_t *rxbuf) -{ - uint8_t txbuf[1]; - - i2cAcquireBus(&I2CD1); - - txbuf[0] = reg; - i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 1, rxbuf, n, MS2ST(STMPE811_TIMEOUT)); - - i2cReleaseBus(&I2CD1); -} - -#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ - diff --git a/boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_config.h b/boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_config.h deleted file mode 100644 index f3a89208..00000000 --- a/boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_config.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _LLD_GINPUT_MOUSE_CONFIG_H -#define _LLD_GINPUT_MOUSE_CONFIG_H - -#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH -#define GINPUT_MOUSE_NEED_CALIBRATION TRUE -#define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE -#define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 12 -#define GINPUT_MOUSE_READ_CYCLES 4 -#define GINPUT_MOUSE_POLL_PERIOD 3 -#define GINPUT_MOUSE_MAX_CLICK_JITTER 2 -#define GINPUT_MOUSE_MAX_MOVE_JITTER 2 -#define GINPUT_MOUSE_CLICK_TIME 500 - -#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ - diff --git a/boards/base/Embest-STM32-DMSTF4BB/gmouse_lld_STMPE811_board.h b/boards/base/Embest-STM32-DMSTF4BB/gmouse_lld_STMPE811_board.h new file mode 100644 index 00000000..ebbe0d5b --- /dev/null +++ b/boards/base/Embest-STM32-DMSTF4BB/gmouse_lld_STMPE811_board.h @@ -0,0 +1,112 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _GINPUT_LLD_MOUSE_BOARD_H +#define _GINPUT_LLD_MOUSE_BOARD_H + +// Resolution and Accuracy Settings +#define GMOUSE_STMPE811_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_STMPE811_PEN_CLICK_ERROR 6 +#define GMOUSE_STMPE811_PEN_MOVE_ERROR 4 +#define GMOUSE_STMPE811_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_STMPE811_FINGER_CLICK_ERROR 18 +#define GMOUSE_STMPE811_FINGER_MOVE_ERROR 14 + +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_STMPE811_BOARD_DATA_SIZE 0 + +// Set this to TRUE if you want self-calibration. +// NOTE: This is not as accurate as real calibration. +// It requires the orientation of the touch panel to match the display. +// It requires the active area of the touch panel to exactly match the display size. +#define GMOUSE_STMPE811_SELF_CALIBRATE FALSE + +// If TRUE this board has the STMPE811 IRQ pin connected to a GPIO. +#define GMOUSE_STMPE811_GPIO_IRQPIN TRUE + +// If TRUE this is a really slow CPU and we should always clear the FIFO between reads. +#define GMOUSE_STMPE811_SLOW_CPU FALSE + +static const I2CConfig i2ccfg = { + OPMODE_I2C, + 400000, + FAST_DUTY_CYCLE_2, +}; + +static bool_t init_board(GMouse* m, unsigned driverinstance) { + (void) m; + + // This board only supports one touch panel + if (driverInstance) + return FALSE; + + palSetPadMode(GPIOC, 13, PAL_MODE_INPUT | PAL_STM32_PUDR_FLOATING); /* TP IRQ */ + palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SCL */ + palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SDA */ + + i2cStart(&I2CD1, &i2ccfg); + return TRUE; +} + +#if GMOUSE_STMPE811_GPIO_IRQPIN + static bool_t getpin_irq(GMouse* m) { + (void) m; + + return !palReadPad(GPIOC, 13); + } +#endif + +static inline void aquire_bus(GMouse* m) { + (void) m; + +} + +static inline void release_bus(GMouse* m) { + (void) m; + +} + +static void write_reg(GMouse* m, uint8_t reg, uint8_t val) { + uint8_t txbuf[2]; + (void) m; + + txbuf[0] = reg; + txbuf[1] = val; + + i2cAcquireBus(&I2CD1); + i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 2, 0, 0, MS2ST(STMPE811_TIMEOUT)); + i2cReleaseBus(&I2CD1); +} + +static uint8_t read_byte(GMouse* m, uint8_t reg) { + uint8_t rxbuf[1]; + (void) m; + + rxbuf[0] = 0; + + i2cAcquireBus(&I2CD1); + i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, ®, 1, rxbuf, 1, MS2ST(STMPE811_TIMEOUT)); + i2cReleaseBus(&I2CD1); + + return rxbuf[0]; +} + +static uint16_t read_word(GMouse* m, uint8_t reg) { + uint8_t rxbuf[2]; + (void) m; + + rxbuf[0] = 0; + rxbuf[1] = 0; + + i2cAcquireBus(&I2CD1); + i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, ®, 1, rxbuf, 2, MS2ST(STMPE811_TIMEOUT)); + i2cReleaseBus(&I2CD1); + + return (((uint16_t)rxbuf[0]) << 8) | rxbuf[1]; +} + +#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ diff --git a/drivers/ginput/touch/STMPE811/driver.mk b/drivers/ginput/touch/STMPE811/driver.mk index 5147e989..cf12507b 100644 --- a/drivers/ginput/touch/STMPE811/driver.mk +++ b/drivers/ginput/touch/STMPE811/driver.mk @@ -1,5 +1,2 @@ # List the required driver. -GFXSRC += $(GFXLIB)/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c - -# Required include directories -GFXINC += $(GFXLIB)/drivers/ginput/touch/STMPE811 +GFXSRC += $(GFXLIB)/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c deleted file mode 100644 index e658fae2..00000000 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#include "gfx.h" - -#if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) /*|| defined(__DOXYGEN__)*/ - -#include "src/ginput/driver_mouse.h" - -#include "drivers/ginput/touch/STMPE811/stmpe811.h" - -#include "ginput_lld_mouse_board.h" - -#ifndef STMP811_NO_GPIO_IRQPIN - #define STMP811_NO_GPIO_IRQPIN FALSE -#endif -#ifndef STMP811_SLOW_CPU - #define STMP811_SLOW_CPU FALSE -#endif - -static coord_t x, y, z; -static uint8_t touched; - -/* set the active window of the stmpe811. bl is bottom left, tr is top right */ -static void setActiveWindow(uint16_t bl_x, uint16_t bl_y, uint16_t tr_x, uint16_t tr_y) -{ - write_reg(STMPE811_REG_WDW_TR_X, 2, tr_x); - write_reg(STMPE811_REG_WDW_TR_Y, 2, tr_y); - write_reg(STMPE811_REG_WDW_BL_X, 2, bl_x); - write_reg(STMPE811_REG_WDW_BL_Y, 2, bl_y); -} - -void ginput_lld_mouse_init(void) -{ - init_board(); - - write_reg(STMPE811_REG_SYS_CTRL1, 1, 0x02); // Software chip reset - 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 - write_reg(STMPE811_REG_INT_EN, 1, 0x00); // Interrupt on INT pin when touch is detected -#else - 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 - 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 - write_reg(STMPE811_REG_TSC_CFG, 1, 0x9A); // Averaging 4, touch detect delay 500 us, panel driver settling time 500 us - write_reg(STMPE811_REG_FIFO_TH, 1, 0x40); // FIFO threshold = 64 - write_reg(STMPE811_REG_FIFO_STA, 1, 0x01); // FIFO reset enable - write_reg(STMPE811_REG_FIFO_STA, 1, 0x00); // FIFO reset disable - write_reg(STMPE811_REG_TSC_FRACT_XYZ, 1, 0x07); // Z axis data format - write_reg(STMPE811_REG_TSC_I_DRIVE, 1, 0x01); // 50mA touchscreen line current - write_reg(STMPE811_REG_TSC_CTRL, 1, 0x00); // X&Y&Z - write_reg(STMPE811_REG_TSC_CTRL, 1, 0x01); // X&Y&Z, TSC enable - write_reg(STMPE811_REG_INT_STA, 1, 0xFF); // Clear all interrupts -#if !STMP811_NO_GPIO_IRQPIN - touched = (uint8_t)read_reg(STMPE811_REG_TSC_CTRL, 1) & 0x80; -#endif - write_reg(STMPE811_REG_INT_CTRL, 1, 0x01); // Level interrupt, enable intrrupts -} - -void ginput_lld_mouse_get_reading(MouseReading *pt) -{ - bool_t clearfifo; // Do we need to clear the FIFO - -#if STMP811_NO_GPIO_IRQPIN - // Poll to get the touched status - uint8_t last_touched; - - last_touched = touched; - touched = (uint8_t)read_reg(STMPE811_REG_TSC_CTRL, 1) & 0x80; - clearfifo = (touched != last_touched); -#else - // Check if the touch controller IRQ pin has gone off - clearfifo = false; - if(getpin_irq()) { // please rename this to getpin_irq - write_reg(STMPE811_REG_INT_STA, 1, 0xFF); // clear all interrupts - touched = (uint8_t)read_reg(STMPE811_REG_TSC_CTRL, 1) & 0x80; // set the new touched status - clearfifo = true; // only take the last FIFO reading - } -#endif - - // If not touched, return the previous results - if (!touched) { - pt->x = x; - pt->y = y; - pt->z = 0; - pt->buttons = 0; - return; - } - -#if !STMP811_SLOW_CPU - if (!clearfifo && (read_reg(STMPE811_REG_FIFO_STA, 1) & 0xD0)) -#endif - clearfifo = true; - - do { - /* Get the X, Y, Z values */ - /* This could be done in a single 4 byte read to STMPE811_REG_TSC_DATA_XYZ (incr or non-incr) */ - x = (coord_t)read_reg(STMPE811_REG_TSC_DATA_X, 2); - y = (coord_t)read_reg(STMPE811_REG_TSC_DATA_Y, 2); - z = (coord_t)read_reg(STMPE811_REG_TSC_DATA_Z, 1); - } while(clearfifo && !(read_reg(STMPE811_REG_FIFO_STA, 1) & 0x20)); - - // Rescale X,Y,Z - X & Y don't need scaling when you are using calibration! -#if !GINPUT_MOUSE_NEED_CALIBRATION - x = gdispGetWidth() - x / (4096/gdispGetWidth()); - y = y / (4096/gdispGetHeight()); -#endif - z = (((z&0xFF) * 100)>>8) + 1; - - // Return the results. ADC gives values from 0 to 2^12 (4096) - pt->x = x; - pt->y = y; - pt->z = z; - pt->buttons = GINPUT_TOUCH_PRESSED; - - /* Force another read if we have more results */ - if (!clearfifo && !(read_reg(STMPE811_REG_FIFO_STA, 1) & 0x20)) - ginputMouseWakeup(); - -} - -#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */ diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_template.h b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_template.h deleted file mode 100644 index b7744a49..00000000 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_template.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _GINPUT_LLD_MOUSE_BOARD_H -#define _GINPUT_LLD_MOUSE_BOARD_H - -static void init_board(void) { - -} - -static inline bool_t getpin_irq(void) { - -} - -static void write_reg(uint8_t reg, uint8_t n, uint16_t val) { - -} - -static uint16_t read_reg(uint8_t reg, uint8_t n) { - -} - -#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h deleted file mode 100644 index 5cd512eb..00000000 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _LLD_GINPUT_MOUSE_CONFIG_H -#define _LLD_GINPUT_MOUSE_CONFIG_H - -#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH -#define GINPUT_MOUSE_NEED_CALIBRATION TRUE -#define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE -#define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 5 -#define GINPUT_MOUSE_READ_CYCLES 1 -#define GINPUT_MOUSE_POLL_PERIOD 25 -#define GINPUT_MOUSE_MAX_CLICK_JITTER 10 -#define GINPUT_MOUSE_MAX_MOVE_JITTER 5 -#define GINPUT_MOUSE_CLICK_TIME 450 - -/* default values - over write these in your boad files */ -#define STMP811_SLOWER_RESPONSE FALSE -#define STMP811_NO_GPIO_IRQPIN FALSE - -#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ diff --git a/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c new file mode 100644 index 00000000..396e9eb0 --- /dev/null +++ b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c @@ -0,0 +1,164 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#include "gfx.h" + +#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE + +#define GMOUSE_DRIVER_VMT GMOUSEVMT_STMPE811 +#include "src/ginput/driver_mouse.h" + +#define GMOUSE_STMPE811_FLG_TOUCHED (GMOUSE_FLG_DRIVER_FIRST<<0) + +// Get the hardware interface +#include "gmouse_lld_STMPE811_board.h" + +// Hardware definitions +#include "drivers/ginput/touch/STMPE811/stmpe811.h" + +static bool_t MouseInit(GMouse* m, unsigned driverinstance) { + if (!init_board(m, driverinstance)) + return FALSE; + + aquire_bus(m); + + write_reg(m, STMPE811_REG_SYS_CTRL1, 0x02); // Software chip reset + gfxSleepMilliseconds(10); + + write_reg(m, STMPE811_REG_SYS_CTRL2, 0x0C); // Temperature sensor clock off, GPIO clock off, touch clock on, ADC clock on + + #if GMOUSE_STMPE811_GPIO_IRQPIN + write_reg(m, STMPE811_REG_INT_EN, 0x01); // Interrupt on INT pin when touch is detected + #else + write_reg(m, STMPE811_REG_INT_EN, 0x00); // Don't Interrupt on INT pin when touch is detected + #endif + + write_reg(m, STMPE811_REG_ADC_CTRL1, 0x48); // ADC conversion time = 80 clock ticks, 12-bit ADC, internal voltage refernce + gfxSleepMilliseconds(2); + + write_reg(m, STMPE811_REG_ADC_CTRL2, 0x01); // ADC speed 3.25MHz + write_reg(m, STMPE811_REG_GPIO_AF, 0x00); // GPIO alternate function - OFF + write_reg(m, STMPE811_REG_TSC_CFG, 0x9A); // Averaging 4, touch detect delay 500 us, panel driver settling time 500 us + write_reg(m, STMPE811_REG_FIFO_TH, 0x40); // FIFO threshold = 64 + write_reg(m, STMPE811_REG_FIFO_STA, 0x01); // FIFO reset enable + write_reg(m, STMPE811_REG_FIFO_STA, 0x00); // FIFO reset disable + write_reg(m, STMPE811_REG_TSC_FRACT_XYZ, 0x07); // Z axis data format + write_reg(m, STMPE811_REG_TSC_I_DRIVE, 0x01); // 50mA touchscreen line current + write_reg(m, STMPE811_REG_TSC_CTRL, 0x00); // X&Y&Z + write_reg(m, STMPE811_REG_TSC_CTRL, 0x01); // X&Y&Z, TSC enable + write_reg(m, STMPE811_REG_INT_STA, 0xFF); // Clear all interrupts + #if GMOUSE_STMPE811_GPIO_IRQPIN + if (read_byte(m, STMPE811_REG_TSC_CTRL) & 0x80) + m->flags |= GMOUSE_STMPE811_FLG_TOUCHED; + #endif + write_reg(m, STMPE811_REG_INT_CTRL, 0x01); // Level interrupt, enable interrupts + + release_bus(m); + return TRUE; +} + +static void MouseXYZ(GMouse* m, GMouseReading* pdr) +{ + bool_t clearfifo; // Do we need to clear the FIFO + + // Assume not touched. + pdr->buttons = 0; + pdr->z = 0; + + aquire_bus(m); + + #if GMOUSE_STMPE811_GPIO_IRQPIN + // Check if the touch controller IRQ pin has gone off + clearfifo = false; + if(getpin_irq(m)) { + write_reg(m, STMPE811_REG_INT_STA, 0xFF); // clear all interrupts + if (read_byte(STMPE811_REG_TSC_CTRL) & 0x80) // set the new touched status + m->flags |= GMOUSE_STMPE811_FLG_TOUCHED; + else + m->flags &= ~GMOUSE_STMPE811_FLG_TOUCHED; + clearfifo = TRUE; // only take the last FIFO reading + } + + #else + // Poll to get the touched status + uint16_t last_touched; + + last_touched = m->flags; + if (read_byte(m, STMPE811_REG_TSC_CTRL) & 0x80) // set the new touched status + m->flags |= GMOUSE_STMPE811_FLG_TOUCHED; + else + m->flags &= ~GMOUSE_STMPE811_FLG_TOUCHED; + clearfifo = ((m->flags ^ last_touched) & GMOUSE_STMPE811_FLG_TOUCHED) ? TRUE : FALSE; + #endif + + // If not touched don't do any more + if ((m->flags &= ~GMOUSE_STMPE811_FLG_TOUCHED)) { + + // Clear the fifo if it is too full + #if !GMOUSE_STMPE811_SLOW_CPU + if (!clearfifo && (read_byte(m, STMPE811_REG_FIFO_STA) & 0xD0)) + #endif + clearfifo = true; + + do { + /* Get the X, Y, Z values */ + /* This could be done in a single 4 byte read to STMPE811_REG_TSC_DATA_XYZ (incr or non-incr) */ + pdr->x = (coord_t)read_word(m, STMPE811_REG_TSC_DATA_X); + pdr->y = (coord_t)read_word(m, STMPE811_REG_TSC_DATA_Y); + pdr->z = (coord_t)read_byte(m, STMPE811_REG_TSC_DATA_Z); + } while(clearfifo && !(read_byte(m, STMPE811_REG_FIFO_STA) & 0x20)); + + #if GMOUSE_STMPE811_SELF_CALIBRATE + // Rescale X,Y,Z - If we are using self-calibration + pdr->x = gdispGGetWidth(m->display) - pdr->x / (4096/gdispGGetWidth(m->display)); + pdr->y = pdr->y / (4096/gdispGGetHeight(m->display)); + #endif + + /* Force another read if we have more results */ + if (!clearfifo && !(read_byte(m, STMPE811_REG_FIFO_STA) & 0x20)) + _gmouseWakeup(m); + } + + release_bus(m); +} + +const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ + { + GDRIVER_TYPE_TOUCH, + #if GMOUSE_STMPE811_SELF_CALIBRATE + GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN, + #else + GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN | GMOUSE_VFLG_CALIBRATE | GMOUSE_VFLG_CAL_TEST, + #endif + sizeof(GMouse) + GMOUSE_STMPE811_BOARD_DATA_SIZE, + _gmouseInitDriver, + _gmousePostInitDriver, + _gmouseDeInitDriver + }, + 255, // z_max + 0, // z_min + 200, // z_touchon + 20, // z_touchoff + { // pen_jitter + GMOUSE_STMPE811_PEN_CALIBRATE_ERROR, // calibrate + GMOUSE_STMPE811_PEN_CLICK_ERROR, // click + GMOUSE_STMPE811_PEN_MOVE_ERROR // move + }, + { // finger_jitter + GMOUSE_STMPE811_FINGER_CALIBRATE_ERROR, // calibrate + GMOUSE_STMPE811_FINGER_CLICK_ERROR, // click + GMOUSE_STMPE811_FINGER_MOVE_ERROR // move + }, + MouseInit, // init + 0, // deinit + read_xyz, // get + 0, // calsave + 0 // calload +}}; + +#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */ + diff --git a/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811_board_template.h b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811_board_template.h new file mode 100644 index 00000000..437abc09 --- /dev/null +++ b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811_board_template.h @@ -0,0 +1,58 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _GINPUT_LLD_MOUSE_BOARD_H +#define _GINPUT_LLD_MOUSE_BOARD_H + +// Resolution and Accuracy Settings +#define GMOUSE_STMPE811_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_STMPE811_PEN_CLICK_ERROR 6 +#define GMOUSE_STMPE811_PEN_MOVE_ERROR 4 +#define GMOUSE_STMPE811_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_STMPE811_FINGER_CLICK_ERROR 18 +#define GMOUSE_STMPE811_FINGER_MOVE_ERROR 14 + +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_STMPE811_BOARD_DATA_SIZE 0 + +// Set this to TRUE if you want self-calibration. +// NOTE: This is not as accurate as real calibration. +// It requires the orientation of the touch panel to match the display. +// It requires the active area of the touch panel to exactly match the display size. +#define GMOUSE_STMPE811_SELF_CALIBRATE FALSE + +// If TRUE this board has the STMPE811 IRQ pin connected to a GPIO. +#define GMOUSE_STMPE811_GPIO_IRQPIN FALSE + +// If TRUE this is a really slow CPU and we should always clear the FIFO between reads. +#define GMOUSE_STMPE811_SLOW_CPU FALSE + +static bool_t init_board(GMouse* m, unsigned driverinstance) { +} + +#if GMOUSE_STMPE811_GPIO_IRQPIN + static bool_t getpin_irq(GMouse* m) { + + } +#endif + +static inline void aquire_bus(GMouse* m) { +} + +static inline void release_bus(GMouse* m) { +} + +static void write_reg(GMouse* m, uint8_t reg, uint8_t val) { +} + +static uint8_t read_byte(GMouse* m, uint8_t reg) { +} + +static uint16_t read_word(GMouse* m, uint8_t reg) { +} + +#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ From d6b4af4ff6685dfef62ec93042c85286ad29d81f Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Mon, 13 Oct 2014 23:01:01 +0200 Subject: [PATCH 67/87] Fixing STMPE811 driver --- drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c index 396e9eb0..6951f3ab 100644 --- a/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c +++ b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c @@ -14,12 +14,12 @@ #define GMOUSE_STMPE811_FLG_TOUCHED (GMOUSE_FLG_DRIVER_FIRST<<0) -// Get the hardware interface -#include "gmouse_lld_STMPE811_board.h" - // Hardware definitions #include "drivers/ginput/touch/STMPE811/stmpe811.h" +// Get the hardware interface +#include "gmouse_lld_STMPE811_board.h" + static bool_t MouseInit(GMouse* m, unsigned driverinstance) { if (!init_board(m, driverinstance)) return FALSE; @@ -61,7 +61,7 @@ static bool_t MouseInit(GMouse* m, unsigned driverinstance) { return TRUE; } -static void MouseXYZ(GMouse* m, GMouseReading* pdr) +static void read_xyz(GMouse* m, GMouseReading* pdr) { bool_t clearfifo; // Do we need to clear the FIFO @@ -76,7 +76,7 @@ static void MouseXYZ(GMouse* m, GMouseReading* pdr) clearfifo = false; if(getpin_irq(m)) { write_reg(m, STMPE811_REG_INT_STA, 0xFF); // clear all interrupts - if (read_byte(STMPE811_REG_TSC_CTRL) & 0x80) // set the new touched status + if (read_byte(m, STMPE811_REG_TSC_CTRL) & 0x80) // set the new touched status m->flags |= GMOUSE_STMPE811_FLG_TOUCHED; else m->flags &= ~GMOUSE_STMPE811_FLG_TOUCHED; From 6343a2e844bb41b88a94d05507e4e3ac0b7d0810 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Mon, 13 Oct 2014 23:12:18 +0200 Subject: [PATCH 68/87] STMPE811 fixes - still not working --- .../base/Embest-STM32-DMSTF4BB/gmouse_lld_STMPE811_board.h | 6 +++++- drivers/ginput/touch/STMPE811/stmpe811.h | 3 --- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/boards/base/Embest-STM32-DMSTF4BB/gmouse_lld_STMPE811_board.h b/boards/base/Embest-STM32-DMSTF4BB/gmouse_lld_STMPE811_board.h index ebbe0d5b..f6d0e74c 100644 --- a/boards/base/Embest-STM32-DMSTF4BB/gmouse_lld_STMPE811_board.h +++ b/boards/base/Embest-STM32-DMSTF4BB/gmouse_lld_STMPE811_board.h @@ -31,6 +31,9 @@ // If TRUE this is a really slow CPU and we should always clear the FIFO between reads. #define GMOUSE_STMPE811_SLOW_CPU FALSE +// Maximum timeout +#define STMPE811_TIMEOUT 0x3000 + static const I2CConfig i2ccfg = { OPMODE_I2C, 400000, @@ -41,7 +44,7 @@ static bool_t init_board(GMouse* m, unsigned driverinstance) { (void) m; // This board only supports one touch panel - if (driverInstance) + if (driverinstance) return FALSE; palSetPadMode(GPIOC, 13, PAL_MODE_INPUT | PAL_STM32_PUDR_FLOATING); /* TP IRQ */ @@ -49,6 +52,7 @@ static bool_t init_board(GMouse* m, unsigned driverinstance) { palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SDA */ i2cStart(&I2CD1, &i2ccfg); + return TRUE; } diff --git a/drivers/ginput/touch/STMPE811/stmpe811.h b/drivers/ginput/touch/STMPE811/stmpe811.h index 1ee9c211..f0d2df42 100644 --- a/drivers/ginput/touch/STMPE811/stmpe811.h +++ b/drivers/ginput/touch/STMPE811/stmpe811.h @@ -11,9 +11,6 @@ // Slave address #define STMPE811_ADDR (0x82 >> 1) -// Maximum timeout -#define STMPE811_TIMEOUT 0x3000 - // Identification registers #define STMPE811_REG_CHP_ID 0x00 // 16-bit #define STMPE811_REG_ID_VER 0x02 From 105e50dcd4fa51f5adaad05992e04b9b8a07fcc1 Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 27 Oct 2014 16:52:50 +1000 Subject: [PATCH 69/87] Allow calibration to work in newmouse even if there is no text / font support. --- src/ginput/ginput_mouse.c | 44 ++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/src/ginput/ginput_mouse.c b/src/ginput/ginput_mouse.c index c04eda6a..9cdcaec2 100644 --- a/src/ginput/ginput_mouse.c +++ b/src/ginput/ginput_mouse.c @@ -443,14 +443,18 @@ static void MousePoll(void *param) { coord_t w, h; point cross[4]; // The locations of the test points on the display point points[4]; // The x, y readings obtained from the mouse for each test point - font_t font1, font2; uint32_t err; + #if GDISP_NEED_TEXT + font_t font1, font2; + #endif + #if GDISP_NEED_TEXT + font1 = gdispOpenFont(CALIBRATION_FONT); + if (!font1) font1 = gdispOpenFont("*"); + font2 = gdispOpenFont(CALIBRATION_FONT2); + if (!font2) font2 = gdispOpenFont("*"); + #endif err = 0; - font1 = gdispOpenFont(CALIBRATION_FONT); - if (!font1) font1 = gdispOpenFont("*"); - font2 = gdispOpenFont(CALIBRATION_FONT2); - if (!font2) font2 = gdispOpenFont("*"); w = gdispGGetWidth(m->display); h = gdispGGetHeight(m->display); #if GDISP_NEED_CLIP @@ -475,10 +479,12 @@ static void MousePoll(void *param) { // Set up the calibration display gdispGClear(m->display, Blue); - gdispGFillStringBox(m->display, - 0, CALIBRATION_TITLE_Y, w, CALIBRATION_TITLE_HEIGHT, - CALIBRATION_TITLE, font1, CALIBRATION_TITLE_COLOR, CALIBRATION_TITLE_BACKGROUND, - justifyCenter); + #if GDISP_NEED_TEXT + gdispGFillStringBox(m->display, + 0, CALIBRATION_TITLE_Y, w, CALIBRATION_TITLE_HEIGHT, + CALIBRATION_TITLE, font1, CALIBRATION_TITLE_COLOR, CALIBRATION_TITLE_BACKGROUND, + justifyCenter); + #endif // Calculate the calibration { @@ -570,19 +576,23 @@ static void MousePoll(void *param) { // Is this accurate enough? err = (points[3].x - cross[3].x) * (points[3].x - cross[3].x) + (points[3].y - cross[3].y) * (points[3].y - cross[3].y); if (err > (uint32_t)pj->calibrate * (uint32_t)pj->calibrate) { - // No - Display error and return - gdispGFillStringBox(m->display, - 0, CALIBRATION_ERROR_Y, w, CALIBRATION_ERROR_HEIGHT, - CALIBRATION_ERROR_TEXT, font2, CALIBRATION_ERROR_COLOR, CALIBRATION_ERROR_BACKGROUND, - justifyCenter); - gfxSleepMilliseconds(CALIBRATION_ERROR_DELAY); + #if GDISP_NEED_TEXT + // No - Display error and return + gdispGFillStringBox(m->display, + 0, CALIBRATION_ERROR_Y, w, CALIBRATION_ERROR_HEIGHT, + CALIBRATION_ERROR_TEXT, font2, CALIBRATION_ERROR_COLOR, CALIBRATION_ERROR_BACKGROUND, + justifyCenter); + gfxSleepMilliseconds(CALIBRATION_ERROR_DELAY); + #endif } else err = 0; } // We are done calibrating - gdispCloseFont(font1); - gdispCloseFont(font2); + #if GDISP_NEED_TEXT + gdispCloseFont(font1); + gdispCloseFont(font2); + #endif m->flags &= ~GMOUSE_FLG_IN_CAL; m->flags |= GMOUSE_FLG_CLIP; From d4c68c5afefbbee7fd5926a242b73f223c8ff3a2 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Mon, 27 Oct 2014 23:54:20 +0100 Subject: [PATCH 70/87] Adding GDISP_NEED_ARCSECTOR stuff that was missing --- gfxconf.example.h | 1 + src/gdisp/sys_options.h | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/gfxconf.example.h b/gfxconf.example.h index 0ff436ca..cea9bba7 100644 --- a/gfxconf.example.h +++ b/gfxconf.example.h @@ -55,6 +55,7 @@ //#define GDISP_NEED_CIRCLE FALSE //#define GDISP_NEED_ELLIPSE FALSE //#define GDISP_NEED_ARC FALSE +//#define GDISP_NEED_ARCSECTORS FALSE //#define GDISP_NEED_CONVEX_POLYGON FALSE //#define GDISP_NEED_SCROLL FALSE //#define GDISP_NEED_PIXELREAD FALSE diff --git a/src/gdisp/sys_options.h b/src/gdisp/sys_options.h index f3d8875d..98be1a46 100644 --- a/src/gdisp/sys_options.h +++ b/src/gdisp/sys_options.h @@ -101,6 +101,14 @@ #ifndef GDISP_NEED_ELLIPSE #define GDISP_NEED_ELLIPSE FALSE #endif + /** + * @brief Are arc sector functions needed. + * @details Defaults to FALSE + * @note Uses integer algorithms only. It does not use any trig or floating point. + */ + #ifndef GDISP_NEED_ARCSECTORS + #define GDISP_NEED_ARCSECTORS FALSE + #endif /** * @brief Are arc functions needed. * @details Defaults to FALSE From 08292eb7d0a0f71e222ae5e4f3fd0a7619bf29c6 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Tue, 28 Oct 2014 00:10:19 +0100 Subject: [PATCH 71/87] Simplifying gdisp/arcsectors demo to only use the GDISP module --- demos/modules/gdisp/arcsectors/gfxconf.h | 4 ---- demos/modules/gdisp/arcsectors/main.c | 26 ++++++------------------ 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/demos/modules/gdisp/arcsectors/gfxconf.h b/demos/modules/gdisp/arcsectors/gfxconf.h index 49470b2f..df6d85c0 100644 --- a/demos/modules/gdisp/arcsectors/gfxconf.h +++ b/demos/modules/gdisp/arcsectors/gfxconf.h @@ -38,15 +38,11 @@ /* GFX sub-systems to turn on */ #define GFX_USE_GDISP TRUE -#define GFX_USE_GINPUT TRUE -#define GFX_USE_GEVENT TRUE -#define GFX_USE_GTIMER TRUE /* Features for the GDISP subsystem. */ #define GDISP_NEED_VALIDATION TRUE #define GDISP_NEED_ARCSECTORS TRUE -#define GINPUT_NEED_MOUSE TRUE #endif /* _GFXCONF_H */ diff --git a/demos/modules/gdisp/arcsectors/main.c b/demos/modules/gdisp/arcsectors/main.c index 9d282207..9908523f 100644 --- a/demos/modules/gdisp/arcsectors/main.c +++ b/demos/modules/gdisp/arcsectors/main.c @@ -29,12 +29,9 @@ #include "gfx.h" -GListener gl; - int main(void) { coord_t width, height, r1, r2, cx, cy; uint8_t sectors; - GEventMouse *pme; // Initialize and clear the display gfxInit(); @@ -42,35 +39,24 @@ int main(void) { // Get the screen size width = gdispGetWidth(); height = gdispGetHeight(); + + // Initialize some variables r1 = width > height ? height/3 : width/3; r2 = r1*3/4; cx = width/2; cy = height/2; sectors = 1; - // We want to listen for mouse button events - geventListenerInit(&gl); - geventAttachSource(&gl, ginputGetMouse(0), GLISTEN_MOUSEMETA); - while(1) { // Draw the arc sectors gdispClear(White); gdispDrawArcSectors(cx, cy, r1, sectors, Blue); gdispFillArcSectors(cx, cy, r2, sectors, Red); - // Get an Event - pme = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); + // Increase the sectors counter + sectors++; - // Change our sectors based on the event. - switch(pme->type) { - case GEVENT_MOUSE: - case GEVENT_TOUCH: - if (pme->buttons & GMETA_MOUSE_CLICK) - sectors++; - else if (pme->buttons & GMETA_MOUSE_CXTCLICK) - sectors--; - break; - } + // Waste some time + gfxSleepMilliseconds(250); } } - From edc254c080b514ea8ea85f432f666b9116f4037c Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Tue, 28 Oct 2014 00:20:11 +0100 Subject: [PATCH 72/87] Adding missing GWIN wrapper for ArcSectors functions --- src/gwin/gwin_gwin.c | 14 +++++++++++++ src/gwin/sys_defs.h | 50 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/gwin/gwin_gwin.c b/src/gwin/gwin_gwin.c index 26e23f32..03902c9b 100644 --- a/src/gwin/gwin_gwin.c +++ b/src/gwin/gwin_gwin.c @@ -299,6 +299,20 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor } #endif +#if GDISP_NEED_ARCSECTORS + void gwinDrawArcSectors(GHandle gh, coord_t x, coord_t y, coord_t radius, uint8_t sectors) { + if (!_gwinDrawStart(gh)) return; + gdispGDrawArcSectors(gh->display, gh->x+x, gh->y+y, radius, sectors, gh->color); + _gwinDrawEnd(gh); + } + + void gwinFillArcSectors(GHandle gh, coord_t x, coord_t y, coord_t radius, uint8_t sectors) { + if (!_gwinDrawStart(gh)) return; + gdispGFillArcSectors(gh->display, gh->x+x, gh->y+y, radius, sectors, gh->color); + _gwinDrawEnd(gh); + } +#endif + #if GDISP_NEED_PIXELREAD color_t gwinGetPixelColor(GHandle gh, coord_t x, coord_t y) { if (!_gwinDrawStart(gh)) return (color_t)0; diff --git a/src/gwin/sys_defs.h b/src/gwin/sys_defs.h index 5e08f7a2..fefa909e 100644 --- a/src/gwin/sys_defs.h +++ b/src/gwin/sys_defs.h @@ -646,7 +646,7 @@ extern "C" { void gwinBlitArea(GHandle gh, 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); /*------------------------------------------------- - * Circle, ellipse and arc functions + * Circle, ellipse, arc and arc-sectors functions *-------------------------------------------------*/ #if GDISP_NEED_CIRCLE || defined(__DOXYGEN__) @@ -737,6 +737,54 @@ extern "C" { void gwinFillArc(GHandle gh, coord_t x, coord_t y, coord_t radius, coord_t startangle, coord_t endangle); #endif + #if GDISP_NEED_ARCSECTORS || defined(__DOXYGEN__) + /* + * @brief Draw a selection of 45 degree arcs of a circle in the window. + * @note Uses the current foreground color to draw the arc sector + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x,y The center of the circle + * @param[in] radius The radius of the circle + * @param[in] sectors Bits determine which sectors are drawn. + * Bits go anti-clockwise from the 0 degree mark (y = 0, x is positive), as follows: + * bit 0 - upper right right ----- + * bit 1 - upper upper right /2 1\ + * bit 2 - upper upper left /3 0\ + * bit 3 - upper left left \4 7/ + * bit 4 - lower left left \5 6/ + * bit 5 - lower lower left ----- + * bit 6 - lower lower right + * bit 7 - lower left left + * + * @api + */ + void gwinDrawArcSectors(GHandle gh, coord_t x, coord_t y, coord_t radius, uint8_t sectors); + + /* + * @brief Draw a filled selection of 45 degree arcs of a circle in the window. + * @note Uses the current foreground color to draw the arc sector + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x,y The center of the circle + * @param[in] radius The radius of the circle + * @param[in] sectors Bits determine which sectors are drawn. + * Bits go anti-clockwise from the 0 degree mark (y = 0, x is positive), as follows: + * bit 0 - upper right right ----- + * bit 1 - upper upper right /2 1\ + * bit 2 - upper upper left /3 0\ + * bit 3 - upper left left \4 7/ + * bit 4 - lower left left \5 6/ + * bit 5 - lower lower left ----- + * bit 6 - lower lower right + * bit 7 - lower left left + * + * @api + */ + void gwinFillArcSectors(GHandle gh, coord_t x, coord_t y, coord_t radius, uint8_t sectors); + #endif + /*------------------------------------------------- * Pixel read-back functions *-------------------------------------------------*/ From 0129ba3dfe6b24e925741f0a018c4ef09cdc6c9d Mon Sep 17 00:00:00 2001 From: inmarket Date: Tue, 28 Oct 2014 11:11:58 +1000 Subject: [PATCH 73/87] Bug fix newmouse SMTPE811 touch driver --- drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c index 6951f3ab..6c07ef12 100644 --- a/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c +++ b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c @@ -96,7 +96,7 @@ static void read_xyz(GMouse* m, GMouseReading* pdr) #endif // If not touched don't do any more - if ((m->flags &= ~GMOUSE_STMPE811_FLG_TOUCHED)) { + if ((m->flags & GMOUSE_STMPE811_FLG_TOUCHED)) { // Clear the fifo if it is too full #if !GMOUSE_STMPE811_SLOW_CPU From 804fcc7c6ab8f2e0932c65a0fc7a967337f431d6 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Tue, 28 Oct 2014 10:06:24 +0100 Subject: [PATCH 74/87] small fix --- drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c index 6c07ef12..71c3c5d7 100644 --- a/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c +++ b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c @@ -73,7 +73,7 @@ static void read_xyz(GMouse* m, GMouseReading* pdr) #if GMOUSE_STMPE811_GPIO_IRQPIN // Check if the touch controller IRQ pin has gone off - clearfifo = false; + clearfifo = FALSE; if(getpin_irq(m)) { write_reg(m, STMPE811_REG_INT_STA, 0xFF); // clear all interrupts if (read_byte(m, STMPE811_REG_TSC_CTRL) & 0x80) // set the new touched status @@ -102,7 +102,7 @@ static void read_xyz(GMouse* m, GMouseReading* pdr) #if !GMOUSE_STMPE811_SLOW_CPU if (!clearfifo && (read_byte(m, STMPE811_REG_FIFO_STA) & 0xD0)) #endif - clearfifo = true; + clearfifo = TRUE; do { /* Get the X, Y, Z values */ From b6d183832e2301ae5bef577f27f97ae5d8e7ee7f Mon Sep 17 00:00:00 2001 From: inmarket Date: Wed, 5 Nov 2014 19:32:47 +1000 Subject: [PATCH 75/87] STM32F429i-Discovery board is now a supported board with an example project. New gdisp driver (currently non-accelerated) Mouse and other drivers still to come. The board file is currently ChibiOS specific however the gdisp driver is suitable for any OS. --- boards/base/STM32F429i-Discovery/board.mk | 8 + .../board_STM32F429iDiscovery.h | 153 ++ .../example_chibios_2.x/Makefile | 56 + .../example_chibios_2.x/chconf.h | 531 +++++++ .../example_chibios_2.x/halconf.h | 312 ++++ .../example_chibios_2.x/mcuconf.h | 303 ++++ .../example_chibios_2.x/openocd.cfg | 81 + .../stm32f429i_discovery_sdram.c | 332 ++++ .../stm32f429i_discovery_sdram.h | 96 ++ .../base/STM32F429i-Discovery/stm32f4xx_fmc.c | 1376 +++++++++++++++++ .../base/STM32F429i-Discovery/stm32f4xx_fmc.h | 1140 ++++++++++++++ .../board_STM32F429iDiscovery_template.h | 66 + drivers/gdisp/STM32F429iDiscovery/driver.mk | 2 + .../gdisp_lld_STM32F429iDiscovery.c | 410 +++++ .../STM32F429iDiscovery/gdisp_lld_config.h | 24 + drivers/gdisp/STM32F429iDiscovery/ili9341.h | 412 +++++ drivers/gdisp/STM32F429iDiscovery/readme.txt | 11 + .../gdisp/STM32F429iDiscovery/stm32_ltdc.h | 551 +++++++ 18 files changed, 5864 insertions(+) create mode 100644 boards/base/STM32F429i-Discovery/board.mk create mode 100644 boards/base/STM32F429i-Discovery/board_STM32F429iDiscovery.h create mode 100644 boards/base/STM32F429i-Discovery/example_chibios_2.x/Makefile create mode 100644 boards/base/STM32F429i-Discovery/example_chibios_2.x/chconf.h create mode 100644 boards/base/STM32F429i-Discovery/example_chibios_2.x/halconf.h create mode 100644 boards/base/STM32F429i-Discovery/example_chibios_2.x/mcuconf.h create mode 100644 boards/base/STM32F429i-Discovery/example_chibios_2.x/openocd.cfg create mode 100644 boards/base/STM32F429i-Discovery/stm32f429i_discovery_sdram.c create mode 100644 boards/base/STM32F429i-Discovery/stm32f429i_discovery_sdram.h create mode 100644 boards/base/STM32F429i-Discovery/stm32f4xx_fmc.c create mode 100644 boards/base/STM32F429i-Discovery/stm32f4xx_fmc.h create mode 100644 drivers/gdisp/STM32F429iDiscovery/board_STM32F429iDiscovery_template.h create mode 100644 drivers/gdisp/STM32F429iDiscovery/driver.mk create mode 100644 drivers/gdisp/STM32F429iDiscovery/gdisp_lld_STM32F429iDiscovery.c create mode 100644 drivers/gdisp/STM32F429iDiscovery/gdisp_lld_config.h create mode 100644 drivers/gdisp/STM32F429iDiscovery/ili9341.h create mode 100644 drivers/gdisp/STM32F429iDiscovery/readme.txt create mode 100644 drivers/gdisp/STM32F429iDiscovery/stm32_ltdc.h diff --git a/boards/base/STM32F429i-Discovery/board.mk b/boards/base/STM32F429i-Discovery/board.mk new file mode 100644 index 00000000..c8dc7117 --- /dev/null +++ b/boards/base/STM32F429i-Discovery/board.mk @@ -0,0 +1,8 @@ +GFXINC += $(GFXLIB)/boards/base/STM32F429i-Discovery +GFXSRC += $(GFXLIB)/boards/base/STM32F429i-Discovery/stm32f429i_discovery_sdram.c \ + $(GFXLIB)/boards/base/STM32F429i-Discovery/stm32f4xx_fmc.c + +GFXDEFS += -DGFX_USE_OS_CHIBIOS=TRUE +include $(GFXLIB)/drivers/gdisp/STM32F429iDiscovery/driver.mk +#include $(GFXLIB)/drivers/ginput/touch/MCU/driver.mk +#include $(GFXLIB)/drivers/gaudio/vs1053/driver.mk diff --git a/boards/base/STM32F429i-Discovery/board_STM32F429iDiscovery.h b/boards/base/STM32F429i-Discovery/board_STM32F429iDiscovery.h new file mode 100644 index 00000000..e0b2dcb6 --- /dev/null +++ b/boards/base/STM32F429i-Discovery/board_STM32F429iDiscovery.h @@ -0,0 +1,153 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _GDISP_LLD_BOARD_H +#define _GDISP_LLD_BOARD_H + +#include "stm32f4xx_fmc.h" +#include "stm32f429i_discovery_sdram.h" +#include + +#define SPI_PORT &SPID5 +#define DC_PORT GPIOD +#define DC_PIN GPIOD_LCD_WRX + +static const SPIConfig spi_cfg = { + NULL, + GPIOC, + GPIOC_SPI5_LCD_CS, + ((1 << 3) & SPI_CR1_BR) | SPI_CR1_SSM | SPI_CR1_SSI | SPI_CR1_MSTR +}; + +static const ltdcConfig driverCfg = { + 240, 320, + 10, 2, + 20, 2, + 10, 4, + 0, + 0x000000, + { + (LLDCOLOR_TYPE *)SDRAM_BANK_ADDR, // frame + 240, 320, // width, height + 240 * LTDC_PIXELBYTES, // pitch + LTDC_PIXELFORMAT, // fmt + 0, 0, // x, y + 240, 320, // cx, cy + LTDC_COLOR_FUCHSIA, // defcolor + 0x980088, // keycolor + LTDC_BLEND_FIX1_FIX2, // blending + 0, // palette + 0, // palettelen + 0xFF, // alpha + LTDC_LEF_ENABLE // flags + }, + LTDC_UNUSED_LAYER_CONFIG +}; + +static inline void init_board(GDisplay *g) { + + // As we are not using multiple displays we set g->board to NULL as we don't use it. + g->board = 0; + + switch(g->controllerdisplay) { + case 0: // Set up for Display 0 + palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(7)); // UART_TX + palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(7)); // UART_RX + palSetPadMode(GPIOF, GPIOF_LCD_DCX, PAL_MODE_ALTERNATE(5)); + palSetPadMode(GPIOF, GPIOF_LCD_DE, PAL_MODE_ALTERNATE(14)); + +#define STM32_SAISRC_NOCLOCK (0 << 23) /**< No clock. */ +#define STM32_SAISRC_PLL (1 << 23) /**< SAI_CKIN is PLL. */ +#define STM32_SAIR_DIV2 (0 << 16) /**< R divided by 2. */ +#define STM32_SAIR_DIV4 (1 << 16) /**< R divided by 4. */ +#define STM32_SAIR_DIV8 (2 << 16) /**< R divided by 8. */ +#define STM32_SAIR_DIV16 (3 << 16) /**< R divided by 16. */ + +#define STM32_PLLSAIN_VALUE 192 +#define STM32_PLLSAIQ_VALUE 7 +#define STM32_PLLSAIR_VALUE 4 +#define STM32_PLLSAIR_POST STM32_SAIR_DIV4 + + /* PLLSAI activation.*/ + RCC->PLLSAICFGR = (STM32_PLLSAIN_VALUE << 6) | (STM32_PLLSAIR_VALUE << 28) | (STM32_PLLSAIQ_VALUE << 24); + RCC->DCKCFGR = (RCC->DCKCFGR & ~RCC_DCKCFGR_PLLSAIDIVR) | STM32_PLLSAIR_POST; + RCC->CR |= RCC_CR_PLLSAION; + + // Initialise the SDRAM + SDRAM_Init(); + + // Clear the SDRAM + memset((void *)SDRAM_BANK_ADDR, 0, 0x400000); + + spiStart(SPI_PORT, &spi_cfg); + break; + } +} + +static inline void post_init_board(GDisplay *g) { + (void) g; +} + +static inline void setpin_reset(GDisplay *g, bool_t state) { + (void) g; + (void) state; + /* + if(state) { + // reset lcd + palClearPad(GPIOE, GPIOE_LCD_RST); + } else { + palSetPad(GPIOE, GPIOE_LCD_RST); + } + */ +} + +static inline void set_backlight(GDisplay *g, uint8_t percent) { + (void) g; + (void) percent; + // TODO: can probably pwm this + /* + if(percent) { + // turn back light on + palSetPad(GPIOE, GPIOE_LCD_BLED); + } else { + // turn off + palClearPad(GPIOE, GPIOE_LCD_BLED); + } + */ +} + +static inline void acquire_bus(GDisplay *g) { + (void) g; + + spiSelect(SPI_PORT); +} + +static inline void release_bus(GDisplay *g) { + (void) g; + + spiUnselect(SPI_PORT); +} + +static inline void write_index(GDisplay *g, uint8_t index) { + static uint8_t sindex; + (void) g; + + palClearPad(DC_PORT, DC_PIN); + sindex = index; + spiSend(SPI_PORT, 1, &sindex); +} + +static inline void write_data(GDisplay *g, uint8_t data) { + static uint8_t sdata; + (void) g; + + palSetPad(DC_PORT, DC_PIN); + sdata = data; + spiSend(SPI_PORT, 1, &sdata); +} + +#endif /* _GDISP_LLD_BOARD_H */ diff --git a/boards/base/STM32F429i-Discovery/example_chibios_2.x/Makefile b/boards/base/STM32F429i-Discovery/example_chibios_2.x/Makefile new file mode 100644 index 00000000..2512c62a --- /dev/null +++ b/boards/base/STM32F429i-Discovery/example_chibios_2.x/Makefile @@ -0,0 +1,56 @@ +# Possible Targets: all clean Debug cleanDebug Release cleanRelease + +############################################################################################## +# Settings +# + +# General settings + # See $(GFXLIB)/tools/gmake_scripts/readme.txt for the list of variables + OPT_OS = chibios + OPT_THUMB = yes + OPT_LINK_OPTIMIZE = yes + OPT_CPU = stm32m4 + +# uGFX settings + # See $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk for the list of variables + GFXLIB = ../uGFX + GFXBOARD = STM32F429i-Discovery + GFXDEMO = modules/gdisp/basics + +# ChibiOS settings +ifeq ($(OPT_OS),chibios) + # See $(GFXLIB)/tools/gmake_scripts/os_chibios.mk for the list of variables + CHIBIOS = ../ChibiOS + CHIBIOS_BOARD = ST_STM32F429I_DISCOVERY + CHIBIOS_PLATFORM = STM32F4xx + CHIBIOS_PORT = GCC/ARMCMx/STM32F4xx + CHIBIOS_LDSCRIPT = STM32F407xG.ld +endif + +############################################################################################## +# Set these for your project +# + +ARCH = arm-none-eabi- +SRCFLAGS = -ggdb -O0 +CFLAGS = +CXXFLAGS = -fno-rtti +ASFLAGS = +LDFLAGS = + +SRC = +OBJS = +DEFS = +LIBS = +INCPATH = +LIBPATH = +LDSCRIPT = + +############################################################################################## +# These should be at the end +# + +include $(GFXLIB)/tools/gmake_scripts/library_ugfx.mk +include $(GFXLIB)/tools/gmake_scripts/os_$(OPT_OS).mk +include $(GFXLIB)/tools/gmake_scripts/compiler_gcc.mk +# *** EOF *** diff --git a/boards/base/STM32F429i-Discovery/example_chibios_2.x/chconf.h b/boards/base/STM32F429i-Discovery/example_chibios_2.x/chconf.h new file mode 100644 index 00000000..f4682cb9 --- /dev/null +++ b/boards/base/STM32F429i-Discovery/example_chibios_2.x/chconf.h @@ -0,0 +1,531 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/** + * @file templates/chconf.h + * @brief Configuration file template. + * @details A copy of this file must be placed in each project directory, it + * contains the application specific kernel settings. + * + * @addtogroup config + * @details Kernel related settings and hooks. + * @{ + */ + +#ifndef _CHCONF_H_ +#define _CHCONF_H_ + +/*===========================================================================*/ +/** + * @name Kernel parameters and options + * @{ + */ +/*===========================================================================*/ + +/** + * @brief System tick frequency. + * @details Frequency of the system timer that drives the system ticks. This + * setting also defines the system tick time unit. + */ +#if !defined(CH_FREQUENCY) || defined(__DOXYGEN__) +#define CH_FREQUENCY 1000 +#endif + +/** + * @brief Round robin interval. + * @details This constant is the number of system ticks allowed for the + * threads before preemption occurs. Setting this value to zero + * disables the preemption for threads with equal priority and the + * round robin becomes cooperative. Note that higher priority + * threads can still preempt, the kernel is always preemptive. + * + * @note Disabling the round robin preemption makes the kernel more compact + * and generally faster. + */ +#if !defined(CH_TIME_QUANTUM) || defined(__DOXYGEN__) +#define CH_TIME_QUANTUM 20 +#endif + +/** + * @brief Managed RAM size. + * @details Size of the RAM area to be managed by the OS. If set to zero + * then the whole available RAM is used. The core memory is made + * available to the heap allocator and/or can be used directly through + * the simplified core memory allocator. + * + * @note In order to let the OS manage the whole RAM the linker script must + * provide the @p __heap_base__ and @p __heap_end__ symbols. + * @note Requires @p CH_USE_MEMCORE. + */ +#if !defined(CH_MEMCORE_SIZE) || defined(__DOXYGEN__) +#define CH_MEMCORE_SIZE 0 +#endif + +/** + * @brief Idle thread automatic spawn suppression. + * @details When this option is activated the function @p chSysInit() + * does not spawn the idle thread automatically. The application has + * then the responsibility to do one of the following: + * - Spawn a custom idle thread at priority @p IDLEPRIO. + * - Change the main() thread priority to @p IDLEPRIO then enter + * an endless loop. In this scenario the @p main() thread acts as + * the idle thread. + * . + * @note Unless an idle thread is spawned the @p main() thread must not + * enter a sleep state. + */ +#if !defined(CH_NO_IDLE_THREAD) || defined(__DOXYGEN__) +#define CH_NO_IDLE_THREAD FALSE +#endif + +/** @} */ + +/*===========================================================================*/ +/** + * @name Performance options + * @{ + */ +/*===========================================================================*/ + +/** + * @brief OS optimization. + * @details If enabled then time efficient rather than space efficient code + * is used when two possible implementations exist. + * + * @note This is not related to the compiler optimization options. + * @note The default is @p TRUE. + */ +#if !defined(CH_OPTIMIZE_SPEED) || defined(__DOXYGEN__) +#define CH_OPTIMIZE_SPEED TRUE +#endif + +/** @} */ + +/*===========================================================================*/ +/** + * @name Subsystem options + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Threads registry APIs. + * @details If enabled then the registry APIs are included in the kernel. + * + * @note The default is @p TRUE. + */ +#if !defined(CH_USE_REGISTRY) || defined(__DOXYGEN__) +#define CH_USE_REGISTRY TRUE +#endif + +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#if !defined(CH_USE_WAITEXIT) || defined(__DOXYGEN__) +#define CH_USE_WAITEXIT TRUE +#endif + +/** + * @brief Semaphores APIs. + * @details If enabled then the Semaphores APIs are included in the kernel. + * + * @note The default is @p TRUE. + */ +#if !defined(CH_USE_SEMAPHORES) || defined(__DOXYGEN__) +#define CH_USE_SEMAPHORES TRUE +#endif + +/** + * @brief Semaphores queuing mode. + * @details If enabled then the threads are enqueued on semaphores by + * priority rather than in FIFO order. + * + * @note The default is @p FALSE. Enable this if you have special requirements. + * @note Requires @p CH_USE_SEMAPHORES. + */ +#if !defined(CH_USE_SEMAPHORES_PRIORITY) || defined(__DOXYGEN__) +#define CH_USE_SEMAPHORES_PRIORITY FALSE +#endif + +/** + * @brief Atomic semaphore API. + * @details If enabled then the semaphores the @p chSemSignalWait() API + * is included in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_USE_SEMAPHORES. + */ +#if !defined(CH_USE_SEMSW) || defined(__DOXYGEN__) +#define CH_USE_SEMSW TRUE +#endif + +/** + * @brief Mutexes APIs. + * @details If enabled then the mutexes APIs are included in the kernel. + * + * @note The default is @p TRUE. + */ +#if !defined(CH_USE_MUTEXES) || defined(__DOXYGEN__) +#define CH_USE_MUTEXES TRUE +#endif + +/** + * @brief Conditional Variables APIs. + * @details If enabled then the conditional variables APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_USE_MUTEXES. + */ +#if !defined(CH_USE_CONDVARS) || defined(__DOXYGEN__) +#define CH_USE_CONDVARS TRUE +#endif + +/** + * @brief Conditional Variables APIs with timeout. + * @details If enabled then the conditional variables APIs with timeout + * specification are included in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_USE_CONDVARS. + */ +#if !defined(CH_USE_CONDVARS_TIMEOUT) || defined(__DOXYGEN__) +#define CH_USE_CONDVARS_TIMEOUT TRUE +#endif + +/** + * @brief Events Flags APIs. + * @details If enabled then the event flags APIs are included in the kernel. + * + * @note The default is @p TRUE. + */ +#if !defined(CH_USE_EVENTS) || defined(__DOXYGEN__) +#define CH_USE_EVENTS TRUE +#endif + +/** + * @brief Events Flags APIs with timeout. + * @details If enabled then the events APIs with timeout specification + * are included in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_USE_EVENTS. + */ +#if !defined(CH_USE_EVENTS_TIMEOUT) || defined(__DOXYGEN__) +#define CH_USE_EVENTS_TIMEOUT TRUE +#endif + +/** + * @brief Synchronous Messages APIs. + * @details If enabled then the synchronous messages APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + */ +#if !defined(CH_USE_MESSAGES) || defined(__DOXYGEN__) +#define CH_USE_MESSAGES TRUE +#endif + +/** + * @brief Synchronous Messages queuing mode. + * @details If enabled then messages are served by priority rather than in + * FIFO order. + * + * @note The default is @p FALSE. Enable this if you have special requirements. + * @note Requires @p CH_USE_MESSAGES. + */ +#if !defined(CH_USE_MESSAGES_PRIORITY) || defined(__DOXYGEN__) +#define CH_USE_MESSAGES_PRIORITY FALSE +#endif + +/** + * @brief Mailboxes APIs. + * @details If enabled then the asynchronous messages (mailboxes) APIs are + * included in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_USE_SEMAPHORES. + */ +#if !defined(CH_USE_MAILBOXES) || defined(__DOXYGEN__) +#define CH_USE_MAILBOXES TRUE +#endif + +/** + * @brief I/O Queues APIs. + * @details If enabled then the I/O queues APIs are included in the kernel. + * + * @note The default is @p TRUE. + */ +#if !defined(CH_USE_QUEUES) || defined(__DOXYGEN__) +#define CH_USE_QUEUES TRUE +#endif + +/** + * @brief Core Memory Manager APIs. + * @details If enabled then the core memory manager APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + */ +#if !defined(CH_USE_MEMCORE) || defined(__DOXYGEN__) +#define CH_USE_MEMCORE TRUE +#endif + +/** + * @brief Heap Allocator APIs. + * @details If enabled then the memory heap allocator APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_USE_MEMCORE and either @p CH_USE_MUTEXES or + * @p CH_USE_SEMAPHORES. + * @note Mutexes are recommended. + */ +#if !defined(CH_USE_HEAP) || defined(__DOXYGEN__) +#define CH_USE_HEAP TRUE +#endif + +/** + * @brief C-runtime allocator. + * @details If enabled the the heap allocator APIs just wrap the C-runtime + * @p malloc() and @p free() functions. + * + * @note The default is @p FALSE. + * @note Requires @p CH_USE_HEAP. + * @note The C-runtime may or may not require @p CH_USE_MEMCORE, see the + * appropriate documentation. + */ +#if !defined(CH_USE_MALLOC_HEAP) || defined(__DOXYGEN__) +#define CH_USE_MALLOC_HEAP FALSE +#endif + +/** + * @brief Memory Pools Allocator APIs. + * @details If enabled then the memory pools allocator APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + */ +#if !defined(CH_USE_MEMPOOLS) || defined(__DOXYGEN__) +#define CH_USE_MEMPOOLS TRUE +#endif + +/** + * @brief Dynamic Threads APIs. + * @details If enabled then the dynamic threads creation APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_USE_WAITEXIT. + * @note Requires @p CH_USE_HEAP and/or @p CH_USE_MEMPOOLS. + */ +#if !defined(CH_USE_DYNAMIC) || defined(__DOXYGEN__) +#define CH_USE_DYNAMIC TRUE +#endif + +/** @} */ + +/*===========================================================================*/ +/** + * @name Debug options + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Debug option, system state check. + * @details If enabled the correct call protocol for system APIs is checked + * at runtime. + * + * @note The default is @p FALSE. + */ +#if !defined(CH_DBG_SYSTEM_STATE_CHECK) || defined(__DOXYGEN__) +#define CH_DBG_SYSTEM_STATE_CHECK FALSE +#endif + +/** + * @brief Debug option, parameters checks. + * @details If enabled then the checks on the API functions input + * parameters are activated. + * + * @note The default is @p FALSE. + */ +#if !defined(CH_DBG_ENABLE_CHECKS) || defined(__DOXYGEN__) +#define CH_DBG_ENABLE_CHECKS FALSE +#endif + +/** + * @brief Debug option, consistency checks. + * @details If enabled then all the assertions in the kernel code are + * activated. This includes consistency checks inside the kernel, + * runtime anomalies and port-defined checks. + * + * @note The default is @p FALSE. + */ +#if !defined(CH_DBG_ENABLE_ASSERTS) || defined(__DOXYGEN__) +#define CH_DBG_ENABLE_ASSERTS FALSE +#endif + +/** + * @brief Debug option, trace buffer. + * @details If enabled then the context switch circular trace buffer is + * activated. + * + * @note The default is @p FALSE. + */ +#if !defined(CH_DBG_ENABLE_TRACE) || defined(__DOXYGEN__) +#define CH_DBG_ENABLE_TRACE FALSE +#endif + +/** + * @brief Debug option, stack checks. + * @details If enabled then a runtime stack check is performed. + * + * @note The default is @p FALSE. + * @note The stack check is performed in a architecture/port dependent way. + * It may not be implemented or some ports. + * @note The default failure mode is to halt the system with the global + * @p panic_msg variable set to @p NULL. + */ +#if !defined(CH_DBG_ENABLE_STACK_CHECK) || defined(__DOXYGEN__) +#define CH_DBG_ENABLE_STACK_CHECK FALSE +#endif + +/** + * @brief Debug option, stacks initialization. + * @details If enabled then the threads working area is filled with a byte + * value when a thread is created. This can be useful for the + * runtime measurement of the used stack. + * + * @note The default is @p FALSE. + */ +#if !defined(CH_DBG_FILL_THREADS) || defined(__DOXYGEN__) +#define CH_DBG_FILL_THREADS FALSE +#endif + +/** + * @brief Debug option, threads profiling. + * @details If enabled then a field is added to the @p Thread structure that + * counts the system ticks occurred while executing the thread. + * + * @note The default is @p TRUE. + * @note This debug option is defaulted to TRUE because it is required by + * some test cases into the test suite. + */ +#if !defined(CH_DBG_THREADS_PROFILING) || defined(__DOXYGEN__) +#define CH_DBG_THREADS_PROFILING TRUE +#endif + +/** @} */ + +/*===========================================================================*/ +/** + * @name Kernel hooks + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Threads descriptor structure extension. + * @details User fields added to the end of the @p Thread structure. + */ +#if !defined(THREAD_EXT_FIELDS) || defined(__DOXYGEN__) +#define THREAD_EXT_FIELDS \ + /* Add threads custom fields here.*/ +#endif + +/** + * @brief Threads initialization hook. + * @details User initialization code added to the @p chThdInit() API. + * + * @note It is invoked from within @p chThdInit() and implicitly from all + * the threads creation APIs. + */ +#if !defined(THREAD_EXT_INIT_HOOK) || defined(__DOXYGEN__) +#define THREAD_EXT_INIT_HOOK(tp) { \ + /* Add threads initialization code here.*/ \ +} +#endif + +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + * + * @note It is inserted into lock zone. + * @note It is also invoked when the threads simply return in order to + * terminate. + */ +#if !defined(THREAD_EXT_EXIT_HOOK) || defined(__DOXYGEN__) +#define THREAD_EXT_EXIT_HOOK(tp) { \ + /* Add threads finalization code here.*/ \ +} +#endif + +/** + * @brief Context switch hook. + * @details This hook is invoked just before switching between threads. + */ +#if !defined(THREAD_CONTEXT_SWITCH_HOOK) || defined(__DOXYGEN__) +#define THREAD_CONTEXT_SWITCH_HOOK(ntp, otp) { \ + /* System halt code here.*/ \ +} +#endif + +/** + * @brief Idle Loop hook. + * @details This hook is continuously invoked by the idle thread loop. + */ +#if !defined(IDLE_LOOP_HOOK) || defined(__DOXYGEN__) +#define IDLE_LOOP_HOOK() { \ + /* Idle loop code here.*/ \ +} +#endif + +/** + * @brief System tick event hook. + * @details This hook is invoked in the system tick handler immediately + * after processing the virtual timers queue. + */ +#if !defined(SYSTEM_TICK_EVENT_HOOK) || defined(__DOXYGEN__) +#define SYSTEM_TICK_EVENT_HOOK() { \ + /* System tick event code here.*/ \ +} +#endif + +/** + * @brief System halt hook. + * @details This hook is invoked in case to a system halting error before + * the system is halted. + */ +#if !defined(SYSTEM_HALT_HOOK) || defined(__DOXYGEN__) +#define SYSTEM_HALT_HOOK() { \ + /* System halt code here.*/ \ +} +#endif + +/** @} */ + +/*===========================================================================*/ +/* Port-specific settings (override port settings defaulted in chcore.h). */ +/*===========================================================================*/ + +#endif /* _CHCONF_H_ */ + +/** @} */ diff --git a/boards/base/STM32F429i-Discovery/example_chibios_2.x/halconf.h b/boards/base/STM32F429i-Discovery/example_chibios_2.x/halconf.h new file mode 100644 index 00000000..e0ef55fe --- /dev/null +++ b/boards/base/STM32F429i-Discovery/example_chibios_2.x/halconf.h @@ -0,0 +1,312 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/** + * @file templates/halconf.h + * @brief HAL configuration header. + * @details HAL configuration file, this file allows to enable or disable the + * various device drivers from your application. You may also use + * this file in order to override the device drivers default settings. + * + * @addtogroup HAL_CONF + * @{ + */ + +#ifndef _HALCONF_H_ +#define _HALCONF_H_ + +#include "mcuconf.h" + +/** + * @brief Enables the TM subsystem. + */ +#if !defined(HAL_USE_TM) || defined(__DOXYGEN__) +#define HAL_USE_TM FALSE +#endif + +/** + * @brief Enables the PAL subsystem. + */ +#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__) +#define HAL_USE_PAL TRUE +#endif + +/** + * @brief Enables the ADC subsystem. + */ +#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__) +#define HAL_USE_ADC FALSE +#endif + +/** + * @brief Enables the CAN subsystem. + */ +#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__) +#define HAL_USE_CAN FALSE +#endif + +/** + * @brief Enables the EXT subsystem. + */ +#if !defined(HAL_USE_EXT) || defined(__DOXYGEN__) +#define HAL_USE_EXT FALSE +#endif + +/** + * @brief Enables the GPT subsystem. + */ +#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__) +#define HAL_USE_GPT FALSE +#endif + +/** + * @brief Enables the I2C subsystem. + */ +#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__) +#define HAL_USE_I2C FALSE +#endif + +/** + * @brief Enables the ICU subsystem. + */ +#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__) +#define HAL_USE_ICU FALSE +#endif + +/** + * @brief Enables the MAC subsystem. + */ +#if !defined(HAL_USE_MAC) || defined(__DOXYGEN__) +#define HAL_USE_MAC FALSE +#endif + +/** + * @brief Enables the MMC_SPI subsystem. + */ +#if !defined(HAL_USE_MMC_SPI) || defined(__DOXYGEN__) +#define HAL_USE_MMC_SPI FALSE +#endif + +/** + * @brief Enables the PWM subsystem. + */ +#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__) +#define HAL_USE_PWM FALSE +#endif + +/** + * @brief Enables the RTC subsystem. + */ +#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__) +#define HAL_USE_RTC FALSE +#endif + +/** + * @brief Enables the SDC subsystem. + */ +#if !defined(HAL_USE_SDC) || defined(__DOXYGEN__) +#define HAL_USE_SDC FALSE +#endif + +/** + * @brief Enables the SERIAL subsystem. + */ +#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__) +#define HAL_USE_SERIAL FALSE +#endif + +/** + * @brief Enables the SERIAL over USB subsystem. + */ +#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__) +#define HAL_USE_SERIAL_USB FALSE +#endif + +/** + * @brief Enables the SPI subsystem. + */ +#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__) +#define HAL_USE_SPI TRUE +#endif + +/** + * @brief Enables the UART subsystem. + */ +#if !defined(HAL_USE_UART) || defined(__DOXYGEN__) +#define HAL_USE_UART FALSE +#endif + +/** + * @brief Enables the USB subsystem. + */ +#if !defined(HAL_USE_USB) || defined(__DOXYGEN__) +#define HAL_USE_USB FALSE +#endif + +/*===========================================================================*/ +/* ADC driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables synchronous APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(ADC_USE_WAIT) || defined(__DOXYGEN__) +#define ADC_USE_WAIT TRUE +#endif + +/** + * @brief Enables the @p adcAcquireBus() and @p adcReleaseBus() APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(ADC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) +#define ADC_USE_MUTUAL_EXCLUSION TRUE +#endif + +/*===========================================================================*/ +/* CAN driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Sleep mode related APIs inclusion switch. + */ +#if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__) +#define CAN_USE_SLEEP_MODE TRUE +#endif + +/*===========================================================================*/ +/* I2C driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables the mutual exclusion APIs on the I2C bus. + */ +#if !defined(I2C_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) +#define I2C_USE_MUTUAL_EXCLUSION TRUE +#endif + +/*===========================================================================*/ +/* MAC driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables an event sources for incoming packets. + */ +#if !defined(MAC_USE_ZERO_COPY) || defined(__DOXYGEN__) +#define MAC_USE_ZERO_COPY FALSE +#endif + +/** + * @brief Enables an event sources for incoming packets. + */ +#if !defined(MAC_USE_EVENTS) || defined(__DOXYGEN__) +#define MAC_USE_EVENTS TRUE +#endif + +/*===========================================================================*/ +/* MMC_SPI driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Delays insertions. + * @details If enabled this options inserts delays into the MMC waiting + * routines releasing some extra CPU time for the threads with + * lower priority, this may slow down the driver a bit however. + * This option is recommended also if the SPI driver does not + * use a DMA channel and heavily loads the CPU. + */ +#if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__) +#define MMC_NICE_WAITING TRUE +#endif + +/*===========================================================================*/ +/* SDC driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Number of initialization attempts before rejecting the card. + * @note Attempts are performed at 10mS intervals. + */ +#if !defined(SDC_INIT_RETRY) || defined(__DOXYGEN__) +#define SDC_INIT_RETRY 100 +#endif + +/** + * @brief Include support for MMC cards. + * @note MMC support is not yet implemented so this option must be kept + * at @p FALSE. + */ +#if !defined(SDC_MMC_SUPPORT) || defined(__DOXYGEN__) +#define SDC_MMC_SUPPORT FALSE +#endif + +/** + * @brief Delays insertions. + * @details If enabled this options inserts delays into the MMC waiting + * routines releasing some extra CPU time for the threads with + * lower priority, this may slow down the driver a bit however. + */ +#if !defined(SDC_NICE_WAITING) || defined(__DOXYGEN__) +#define SDC_NICE_WAITING TRUE +#endif + +/*===========================================================================*/ +/* SERIAL driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Default bit rate. + * @details Configuration parameter, this is the baud rate selected for the + * default configuration. + */ +#if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__) +#define SERIAL_DEFAULT_BITRATE 38400 +#endif + +/** + * @brief Serial buffers size. + * @details Configuration parameter, you can change the depth of the queue + * buffers depending on the requirements of your application. + * @note The default is 64 bytes for both the transmission and receive + * buffers. + */ +#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__) +#define SERIAL_BUFFERS_SIZE 16 +#endif + +/*===========================================================================*/ +/* SPI driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables synchronous APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(SPI_USE_WAIT) || defined(__DOXYGEN__) +#define SPI_USE_WAIT TRUE +#endif + +/** + * @brief Enables the @p spiAcquireBus() and @p spiReleaseBus() APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) +#define SPI_USE_MUTUAL_EXCLUSION TRUE +#endif + +#endif /* _HALCONF_H_ */ + +/** @} */ diff --git a/boards/base/STM32F429i-Discovery/example_chibios_2.x/mcuconf.h b/boards/base/STM32F429i-Discovery/example_chibios_2.x/mcuconf.h new file mode 100644 index 00000000..d0b1d6a4 --- /dev/null +++ b/boards/base/STM32F429i-Discovery/example_chibios_2.x/mcuconf.h @@ -0,0 +1,303 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/* + * STM32F4xx drivers configuration. + * The following settings override the default settings present in + * the various device driver implementation headers. + * Note that the settings for each driver only have effect if the whole + * driver is enabled in halconf.h. + * + * IRQ priorities: + * 15...0 Lowest...Highest. + * + * DMA priorities: + * 0...3 Lowest...Highest. + */ + +#define STM32F4xx_MCUCONF + +/* + * HAL driver system settings. + */ +#define STM32_NO_INIT FALSE +#define STM32_HSI_ENABLED TRUE +#define STM32_LSI_ENABLED TRUE +#define STM32_HSE_ENABLED TRUE +#define STM32_LSE_ENABLED FALSE +#define STM32_CLOCK48_REQUIRED TRUE +#define STM32_SW STM32_SW_PLL +#define STM32_PLLSRC STM32_PLLSRC_HSE +#define STM32_PLLM_VALUE 8 +#define STM32_PLLN_VALUE 336 +#define STM32_PLLP_VALUE 2 +#define STM32_PLLQ_VALUE 7 +#define STM32_HPRE STM32_HPRE_DIV1 +#define STM32_PPRE1 STM32_PPRE1_DIV4 +#define STM32_PPRE2 STM32_PPRE2_DIV2 +#define STM32_RTCSEL STM32_RTCSEL_LSI +#define STM32_RTCPRE_VALUE 8 +#define STM32_MCO1SEL STM32_MCO1SEL_HSI +#define STM32_MCO1PRE STM32_MCO1PRE_DIV1 +#define STM32_MCO2SEL STM32_MCO2SEL_SYSCLK +#define STM32_MCO2PRE STM32_MCO2PRE_DIV5 +#define STM32_I2SSRC STM32_I2SSRC_CKIN +#define STM32_PLLI2SN_VALUE 192 +#define STM32_PLLI2SR_VALUE 5 +#define STM32_PVD_ENABLE FALSE +#define STM32_PLS STM32_PLS_LEV0 +#define STM32_BKPRAM_ENABLE FALSE + +/* + * ADC driver system settings. + */ +#define STM32_ADC_ADCPRE ADC_CCR_ADCPRE_DIV4 +#define STM32_ADC_USE_ADC1 FALSE +#define STM32_ADC_USE_ADC2 FALSE +#define STM32_ADC_USE_ADC3 FALSE +#define STM32_ADC_ADC1_DMA_STREAM STM32_DMA_STREAM_ID(2, 4) +#define STM32_ADC_ADC2_DMA_STREAM STM32_DMA_STREAM_ID(2, 2) +#define STM32_ADC_ADC3_DMA_STREAM STM32_DMA_STREAM_ID(2, 1) +#define STM32_ADC_ADC1_DMA_PRIORITY 2 +#define STM32_ADC_ADC2_DMA_PRIORITY 2 +#define STM32_ADC_ADC3_DMA_PRIORITY 2 +#define STM32_ADC_IRQ_PRIORITY 6 +#define STM32_ADC_ADC1_DMA_IRQ_PRIORITY 6 +#define STM32_ADC_ADC2_DMA_IRQ_PRIORITY 6 +#define STM32_ADC_ADC3_DMA_IRQ_PRIORITY 6 + +/* + * CAN driver system settings. + */ +#define STM32_CAN_USE_CAN1 FALSE +#define STM32_CAN_USE_CAN2 FALSE +#define STM32_CAN_CAN1_IRQ_PRIORITY 11 +#define STM32_CAN_CAN2_IRQ_PRIORITY 11 + +/* + * EXT driver system settings. + */ +#define STM32_EXT_EXTI0_IRQ_PRIORITY 6 +#define STM32_EXT_EXTI1_IRQ_PRIORITY 6 +#define STM32_EXT_EXTI2_IRQ_PRIORITY 6 +#define STM32_EXT_EXTI3_IRQ_PRIORITY 6 +#define STM32_EXT_EXTI4_IRQ_PRIORITY 6 +#define STM32_EXT_EXTI5_9_IRQ_PRIORITY 6 +#define STM32_EXT_EXTI10_15_IRQ_PRIORITY 6 +#define STM32_EXT_EXTI16_IRQ_PRIORITY 6 +#define STM32_EXT_EXTI17_IRQ_PRIORITY 15 +#define STM32_EXT_EXTI18_IRQ_PRIORITY 6 +#define STM32_EXT_EXTI19_IRQ_PRIORITY 6 +#define STM32_EXT_EXTI20_IRQ_PRIORITY 6 +#define STM32_EXT_EXTI21_IRQ_PRIORITY 15 +#define STM32_EXT_EXTI22_IRQ_PRIORITY 15 + +/* + * GPT driver system settings. + */ +#define STM32_GPT_USE_TIM1 FALSE +#define STM32_GPT_USE_TIM2 FALSE +#define STM32_GPT_USE_TIM3 FALSE +#define STM32_GPT_USE_TIM4 FALSE +#define STM32_GPT_USE_TIM5 FALSE +#define STM32_GPT_USE_TIM6 FALSE +#define STM32_GPT_USE_TIM7 FALSE +#define STM32_GPT_USE_TIM8 FALSE +#define STM32_GPT_USE_TIM9 FALSE +#define STM32_GPT_USE_TIM11 FALSE +#define STM32_GPT_USE_TIM12 FALSE +#define STM32_GPT_USE_TIM14 FALSE +#define STM32_GPT_TIM1_IRQ_PRIORITY 7 +#define STM32_GPT_TIM2_IRQ_PRIORITY 7 +#define STM32_GPT_TIM3_IRQ_PRIORITY 7 +#define STM32_GPT_TIM4_IRQ_PRIORITY 7 +#define STM32_GPT_TIM5_IRQ_PRIORITY 7 +#define STM32_GPT_TIM6_IRQ_PRIORITY 7 +#define STM32_GPT_TIM7_IRQ_PRIORITY 7 +#define STM32_GPT_TIM8_IRQ_PRIORITY 7 +#define STM32_GPT_TIM9_IRQ_PRIORITY 7 +#define STM32_GPT_TIM11_IRQ_PRIORITY 7 +#define STM32_GPT_TIM12_IRQ_PRIORITY 7 +#define STM32_GPT_TIM14_IRQ_PRIORITY 7 + +/* + * I2C driver system settings. + */ +#define STM32_I2C_USE_I2C1 FALSE +#define STM32_I2C_USE_I2C2 FALSE +#define STM32_I2C_USE_I2C3 FALSE +#define STM32_I2C_I2C1_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0) +#define STM32_I2C_I2C1_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 6) +#define STM32_I2C_I2C2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2) +#define STM32_I2C_I2C2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7) +#define STM32_I2C_I2C3_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2) +#define STM32_I2C_I2C3_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4) +#define STM32_I2C_I2C1_IRQ_PRIORITY 5 +#define STM32_I2C_I2C2_IRQ_PRIORITY 5 +#define STM32_I2C_I2C3_IRQ_PRIORITY 5 +#define STM32_I2C_I2C1_DMA_PRIORITY 3 +#define STM32_I2C_I2C2_DMA_PRIORITY 3 +#define STM32_I2C_I2C3_DMA_PRIORITY 3 +#define STM32_I2C_I2C1_DMA_ERROR_HOOK() chSysHalt() +#define STM32_I2C_I2C2_DMA_ERROR_HOOK() chSysHalt() +#define STM32_I2C_I2C3_DMA_ERROR_HOOK() chSysHalt() + +/* + * ICU driver system settings. + */ +#define STM32_ICU_USE_TIM1 FALSE +#define STM32_ICU_USE_TIM2 FALSE +#define STM32_ICU_USE_TIM3 FALSE +#define STM32_ICU_USE_TIM4 FALSE +#define STM32_ICU_USE_TIM5 FALSE +#define STM32_ICU_USE_TIM8 FALSE +#define STM32_ICU_USE_TIM9 FALSE +#define STM32_ICU_TIM1_IRQ_PRIORITY 7 +#define STM32_ICU_TIM2_IRQ_PRIORITY 7 +#define STM32_ICU_TIM3_IRQ_PRIORITY 7 +#define STM32_ICU_TIM4_IRQ_PRIORITY 7 +#define STM32_ICU_TIM5_IRQ_PRIORITY 7 +#define STM32_ICU_TIM8_IRQ_PRIORITY 7 +#define STM32_ICU_TIM9_IRQ_PRIORITY 7 + +/* + * MAC driver system settings. + */ +#define STM32_MAC_TRANSMIT_BUFFERS 2 +#define STM32_MAC_RECEIVE_BUFFERS 4 +#define STM32_MAC_BUFFERS_SIZE 1522 +#define STM32_MAC_PHY_TIMEOUT 100 +#define STM32_MAC_ETH1_CHANGE_PHY_STATE TRUE +#define STM32_MAC_ETH1_IRQ_PRIORITY 13 +#define STM32_MAC_IP_CHECKSUM_OFFLOAD 0 + +/* + * PWM driver system settings. + */ +#define STM32_PWM_USE_ADVANCED FALSE +#define STM32_PWM_USE_TIM1 FALSE +#define STM32_PWM_USE_TIM2 FALSE +#define STM32_PWM_USE_TIM3 FALSE +#define STM32_PWM_USE_TIM4 FALSE +#define STM32_PWM_USE_TIM5 FALSE +#define STM32_PWM_USE_TIM8 FALSE +#define STM32_PWM_USE_TIM9 FALSE +#define STM32_PWM_TIM1_IRQ_PRIORITY 7 +#define STM32_PWM_TIM2_IRQ_PRIORITY 7 +#define STM32_PWM_TIM3_IRQ_PRIORITY 7 +#define STM32_PWM_TIM4_IRQ_PRIORITY 7 +#define STM32_PWM_TIM5_IRQ_PRIORITY 7 +#define STM32_PWM_TIM8_IRQ_PRIORITY 7 +#define STM32_PWM_TIM9_IRQ_PRIORITY 7 + +/* + * SERIAL driver system settings. + */ +#define STM32_SERIAL_USE_USART1 FALSE +#define STM32_SERIAL_USE_USART2 FALSE +#define STM32_SERIAL_USE_USART3 FALSE +#define STM32_SERIAL_USE_UART4 FALSE +#define STM32_SERIAL_USE_UART5 FALSE +#define STM32_SERIAL_USE_USART6 FALSE +#define STM32_SERIAL_USART1_PRIORITY 12 +#define STM32_SERIAL_USART2_PRIORITY 12 +#define STM32_SERIAL_USART3_PRIORITY 12 +#define STM32_SERIAL_UART4_PRIORITY 12 +#define STM32_SERIAL_UART5_PRIORITY 12 +#define STM32_SERIAL_USART6_PRIORITY 12 + +/* + * SPI driver system settings. + */ +#define STM32_SPI_USE_SPI1 FALSE +#define STM32_SPI_USE_SPI2 FALSE +#define STM32_SPI_USE_SPI3 FALSE +#define STM32_SPI_USE_SPI4 FALSE +#define STM32_SPI_USE_SPI5 TRUE +#define STM32_SPI_USE_SPI6 FALSE +#define STM32_SPI_SPI1_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 0) +#define STM32_SPI_SPI1_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 3) +#define STM32_SPI_SPI2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3) +#define STM32_SPI_SPI2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4) +#define STM32_SPI_SPI3_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0) +#define STM32_SPI_SPI3_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7) +#define STM32_SPI_SPI4_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 0) +#define STM32_SPI_SPI4_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 1) +#define STM32_SPI_SPI5_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 3) +#define STM32_SPI_SPI5_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 4) +#define STM32_SPI_SPI6_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 6) +#define STM32_SPI_SPI6_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 5) +#define STM32_SPI_SPI1_DMA_PRIORITY 1 +#define STM32_SPI_SPI2_DMA_PRIORITY 1 +#define STM32_SPI_SPI3_DMA_PRIORITY 1 +#define STM32_SPI_SPI4_DMA_PRIORITY 1 +#define STM32_SPI_SPI5_DMA_PRIORITY 1 +#define STM32_SPI_SPI6_DMA_PRIORITY 1 +#define STM32_SPI_SPI1_IRQ_PRIORITY 10 +#define STM32_SPI_SPI2_IRQ_PRIORITY 10 +#define STM32_SPI_SPI3_IRQ_PRIORITY 10 +#define STM32_SPI_SPI4_IRQ_PRIORITY 10 +#define STM32_SPI_SPI5_IRQ_PRIORITY 10 +#define STM32_SPI_SPI6_IRQ_PRIORITY 10 +#define STM32_SPI_DMA_ERROR_HOOK(spip) chSysHalt() + +/* + * UART driver system settings. + */ +#define STM32_UART_USE_USART1 FALSE +#define STM32_UART_USE_USART2 FALSE +#define STM32_UART_USE_USART3 FALSE +#define STM32_UART_USE_UART4 FALSE +#define STM32_UART_USE_UART5 FALSE +#define STM32_UART_USE_USART6 FALSE +#define STM32_UART_USART1_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 5) +#define STM32_UART_USART1_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 7) +#define STM32_UART_USART2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 5) +#define STM32_UART_USART2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 6) +#define STM32_UART_USART3_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 1) +#define STM32_UART_USART3_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3) +#define STM32_UART_UART4_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2) +#define STM32_UART_UART4_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4) +#define STM32_UART_UART5_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0) +#define STM32_UART_UART5_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7) +#define STM32_UART_USART6_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 2) +#define STM32_UART_USART6_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 7) +#define STM32_UART_USART1_IRQ_PRIORITY 12 +#define STM32_UART_USART2_IRQ_PRIORITY 12 +#define STM32_UART_USART3_IRQ_PRIORITY 12 +#define STM32_UART_UART4_IRQ_PRIORITY 12 +#define STM32_UART_UART5_IRQ_PRIORITY 12 +#define STM32_UART_USART6_IRQ_PRIORITY 12 +#define STM32_UART_USART1_DMA_PRIORITY 0 +#define STM32_UART_USART2_DMA_PRIORITY 0 +#define STM32_UART_USART3_DMA_PRIORITY 0 +#define STM32_UART_UART4_DMA_PRIORITY 0 +#define STM32_UART_UART5_DMA_PRIORITY 0 +#define STM32_UART_USART6_DMA_PRIORITY 0 +#define STM32_UART_DMA_ERROR_HOOK(uartp) chSysHalt() + +/* + * USB driver system settings. + */ +#define STM32_USB_USE_OTG1 FALSE +#define STM32_USB_USE_OTG2 TRUE +#define STM32_USB_OTG1_IRQ_PRIORITY 14 +#define STM32_USB_OTG2_IRQ_PRIORITY 14 +#define STM32_USB_OTG1_RX_FIFO_SIZE 512 +#define STM32_USB_OTG2_RX_FIFO_SIZE 1024 +#define STM32_USB_OTG_THREAD_PRIO LOWPRIO +#define STM32_USB_OTG_THREAD_STACK_SIZE 128 +#define STM32_USB_OTGFIFO_FILL_BASEPRI 0 diff --git a/boards/base/STM32F429i-Discovery/example_chibios_2.x/openocd.cfg b/boards/base/STM32F429i-Discovery/example_chibios_2.x/openocd.cfg new file mode 100644 index 00000000..f8b6a6f5 --- /dev/null +++ b/boards/base/STM32F429i-Discovery/example_chibios_2.x/openocd.cfg @@ -0,0 +1,81 @@ +# This is a script file for OpenOCD 0.7.0 +# +# It is set up for the Mikromedia-STM32M4 board using the ST-Link JTAG adaptor. +# +# Assuming the current directory is your project directory containing this openocd.cfg file... +# +# To program your device: +# +# openocd -f openocd.cfg -c "Burn yourfile.bin" -c shutdown +# +# To debug your device: +# +# openocd +# (This will run openocd in gdb server debug mode. Leave it running in the background) +# +# gdb yourfile.elf +# (To start gdb. Then run the following commands in gdb...) +# +# target remote 127.0.0.1:3333 +# monitor Debug +# stepi +# (This last stepi resynchronizes gdb). +# +# If you want to reprogram from within gdb: +# +# monitor Burn yourfile.bin +# + +echo "" +echo "##### Loading debugger..." +source [find interface/stlink-v2.cfg] + +echo "" +echo "##### Loading CPU..." +source [find target/stm32f4x_stlink.cfg] + +echo "" +echo "##### Configuring..." +reset_config srst_only srst_nogate +#cortex_m maskisr (auto|on|off) +#cortex_m vector_catch [all|none|list] +#cortex_m reset_config (srst|sysresetreq|vectreset) +#gdb_breakpoint_override hard + +proc Debug { } { + echo "" + echo "##### Debug Session Connected..." + reset init + echo "Ready..." +} + +proc Burn {file} { + echo "" + echo "##### Burning $file to device..." + halt + # Due to an issue with the combination of the ST-Link adapters and OpenOCD + # applying the stm32f2x unlock 0 command actaully applies read protection - VERY BAD! + # If this happens to you - use the ST-Link utility to set the option byte back to normal. + # If you are using a different debugger eg a FT2232 based adapter you can uncomment the line below. + #stm32f2x unlock 0 + flash protect 0 0 last off + reset init + flash write_image erase $file 0x08000000 + verify_image $file 0x0 + #flash protect 0 0 last on + reset + echo "Burning Complete!" +} + +echo "" +echo "##### Leaving Configuration Mode..." +init +reset init +flash probe 0 +flash banks +#flash info 0 + +echo "" +echo "##### Waiting for debug connections..." + + diff --git a/boards/base/STM32F429i-Discovery/stm32f429i_discovery_sdram.c b/boards/base/STM32F429i-Discovery/stm32f429i_discovery_sdram.c new file mode 100644 index 00000000..44e61415 --- /dev/null +++ b/boards/base/STM32F429i-Discovery/stm32f429i_discovery_sdram.c @@ -0,0 +1,332 @@ +#include "stm32f429i_discovery_sdram.h" +#include "stm32f4xx_fmc.h" +#include "ch.h" +#include "hal.h" + +/** + * @brief Configures the FMC and GPIOs to interface with the SDRAM memory. + * This function must be called before any read/write operation + * on the SDRAM. + * @param None + * @retval None + */ +void SDRAM_Init(void) +{ + FMC_SDRAMInitTypeDef FMC_SDRAMInitStructure; + FMC_SDRAMTimingInitTypeDef FMC_SDRAMTimingInitStructure; + + /* Enable FMC clock */ + rccEnableAHB3(RCC_AHB3ENR_FMCEN, FALSE); + +/* FMC Configuration ---------------------------------------------------------*/ +/* FMC SDRAM Bank configuration */ + /* Timing configuration for 84 Mhz of SD clock frequency (168Mhz/2) */ + /* TMRD: 2 Clock cycles */ + FMC_SDRAMTimingInitStructure.FMC_LoadToActiveDelay = 2; + /* TXSR: min=70ns (6x11.90ns) */ + FMC_SDRAMTimingInitStructure.FMC_ExitSelfRefreshDelay = 7; + /* TRAS: min=42ns (4x11.90ns) max=120k (ns) */ + FMC_SDRAMTimingInitStructure.FMC_SelfRefreshTime = 4; + /* TRC: min=63 (6x11.90ns) */ + FMC_SDRAMTimingInitStructure.FMC_RowCycleDelay = 7; + /* TWR: 2 Clock cycles */ + FMC_SDRAMTimingInitStructure.FMC_WriteRecoveryTime = 2; + /* TRP: 15ns => 2x11.90ns */ + FMC_SDRAMTimingInitStructure.FMC_RPDelay = 2; + /* TRCD: 15ns => 2x11.90ns */ + FMC_SDRAMTimingInitStructure.FMC_RCDDelay = 2; + +/* FMC SDRAM control configuration */ + FMC_SDRAMInitStructure.FMC_Bank = FMC_Bank2_SDRAM; + /* Row addressing: [7:0] */ + FMC_SDRAMInitStructure.FMC_ColumnBitsNumber = FMC_ColumnBits_Number_8b; + /* Column addressing: [11:0] */ + FMC_SDRAMInitStructure.FMC_RowBitsNumber = FMC_RowBits_Number_12b; + FMC_SDRAMInitStructure.FMC_SDMemoryDataWidth = SDRAM_MEMORY_WIDTH; + FMC_SDRAMInitStructure.FMC_InternalBankNumber = FMC_InternalBank_Number_4; + FMC_SDRAMInitStructure.FMC_CASLatency = SDRAM_CAS_LATENCY; + FMC_SDRAMInitStructure.FMC_WriteProtection = FMC_Write_Protection_Disable; + FMC_SDRAMInitStructure.FMC_SDClockPeriod = SDCLOCK_PERIOD; + FMC_SDRAMInitStructure.FMC_ReadBurst = SDRAM_READBURST; + FMC_SDRAMInitStructure.FMC_ReadPipeDelay = FMC_ReadPipe_Delay_1; + FMC_SDRAMInitStructure.FMC_SDRAMTimingStruct = &FMC_SDRAMTimingInitStructure; + + /* FMC SDRAM bank initialization */ + FMC_SDRAMInit(&FMC_SDRAMInitStructure); + + /* FMC SDRAM device initialization sequence */ + SDRAM_InitSequence(); + +} + +/*-- GPIOs Configuration -----------------------------------------------------*/ +/* + +-------------------+--------------------+--------------------+--------------------+ + + SDRAM pins assignment + + +-------------------+--------------------+--------------------+--------------------+ + | PD0 <-> FMC_D2 | PE0 <-> FMC_NBL0 | PF0 <-> FMC_A0 | PG0 <-> FMC_A10 | + | PD1 <-> FMC_D3 | PE1 <-> FMC_NBL1 | PF1 <-> FMC_A1 | PG1 <-> FMC_A11 | + | PD8 <-> FMC_D13 | PE7 <-> FMC_D4 | PF2 <-> FMC_A2 | PG8 <-> FMC_SDCLK | + | PD9 <-> FMC_D14 | PE8 <-> FMC_D5 | PF3 <-> FMC_A3 | PG15 <-> FMC_NCAS | + | PD10 <-> FMC_D15 | PE9 <-> FMC_D6 | PF4 <-> FMC_A4 |--------------------+ + | PD14 <-> FMC_D0 | PE10 <-> FMC_D7 | PF5 <-> FMC_A5 | + | PD15 <-> FMC_D1 | PE11 <-> FMC_D8 | PF11 <-> FMC_NRAS | + +-------------------| PE12 <-> FMC_D9 | PF12 <-> FMC_A6 | + | PE13 <-> FMC_D10 | PF13 <-> FMC_A7 | + | PE14 <-> FMC_D11 | PF14 <-> FMC_A8 | + | PE15 <-> FMC_D12 | PF15 <-> FMC_A9 | + +-------------------+--------------------+--------------------+ + | PB5 <-> FMC_SDCKE1| + | PB6 <-> FMC_SDNE1 | + | PC0 <-> FMC_SDNWE | + +-------------------+ + +*/ + +// /* Common GPIO configuration */ +// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; +// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; +// GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; +// GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; +// +// /* GPIOB configuration */ +// GPIO_PinAFConfig(GPIOB, GPIO_PinSource5 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOB, GPIO_PinSource6 , GPIO_AF_FMC); +// +// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6; +// +// GPIO_Init(GPIOB, &GPIO_InitStructure); +// +// /* GPIOC configuration */ +// GPIO_PinAFConfig(GPIOC, GPIO_PinSource0 , GPIO_AF_FMC); +// +// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; +// +// GPIO_Init(GPIOC, &GPIO_InitStructure); +// +// /* GPIOD configuration */ +// GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FMC); +// +// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | +// GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 | +// GPIO_Pin_15; +// +// GPIO_Init(GPIOD, &GPIO_InitStructure); +// +// /* GPIOE configuration */ +// GPIO_PinAFConfig(GPIOE, GPIO_PinSource0 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOE, GPIO_PinSource1 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOE, GPIO_PinSource7 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOE, GPIO_PinSource8 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOE, GPIO_PinSource9 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOE, GPIO_PinSource10 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOE, GPIO_PinSource11 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOE, GPIO_PinSource12 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOE, GPIO_PinSource13 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOE, GPIO_PinSource14 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOE, GPIO_PinSource15 , GPIO_AF_FMC); +// +// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_7 | +// GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | +// GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | +// GPIO_Pin_14 | GPIO_Pin_15; +// +// GPIO_Init(GPIOE, &GPIO_InitStructure); +// +// /* GPIOF configuration */ +// GPIO_PinAFConfig(GPIOF, GPIO_PinSource0 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOF, GPIO_PinSource1 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOF, GPIO_PinSource2 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOF, GPIO_PinSource3 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOF, GPIO_PinSource4 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOF, GPIO_PinSource5 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOF, GPIO_PinSource11 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOF, GPIO_PinSource12 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOF, GPIO_PinSource13 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOF, GPIO_PinSource14 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOF, GPIO_PinSource15 , GPIO_AF_FMC); +// +// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | +// GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | +// GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | +// GPIO_Pin_14 | GPIO_Pin_15; +// +// GPIO_Init(GPIOF, &GPIO_InitStructure); +// +// /* GPIOG configuration */ +// GPIO_PinAFConfig(GPIOG, GPIO_PinSource0 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOG, GPIO_PinSource1 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOG, GPIO_PinSource4 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOG, GPIO_PinSource5 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOG, GPIO_PinSource8 , GPIO_AF_FMC); +// GPIO_PinAFConfig(GPIOG, GPIO_PinSource15 , GPIO_AF_FMC); +// +// +// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | +// GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_15; +// +// GPIO_Init(GPIOG, &GPIO_InitStructure); + +/** + * @brief Executes the SDRAM memory initialization sequence. + * @param None. + * @retval None. + */ +void SDRAM_InitSequence(void) +{ + FMC_SDRAMCommandTypeDef FMC_SDRAMCommandStructure; + uint32_t tmpr = 0; + +/* Step 3 --------------------------------------------------------------------*/ + /* Configure a clock configuration enable command */ + FMC_SDRAMCommandStructure.FMC_CommandMode = FMC_Command_Mode_CLK_Enabled; + FMC_SDRAMCommandStructure.FMC_CommandTarget = FMC_Command_Target_bank2; + FMC_SDRAMCommandStructure.FMC_AutoRefreshNumber = 1; + FMC_SDRAMCommandStructure.FMC_ModeRegisterDefinition = 0; + /* Wait until the SDRAM controller is ready */ + while(FMC_GetFlagStatus(FMC_Bank2_SDRAM, FMC_FLAG_Busy) != RESET) + { + } + /* Send the command */ + FMC_SDRAMCmdConfig(&FMC_SDRAMCommandStructure); + + //In the ST example, this is 100ms, but the 429 RM says 100us is typical, and + //the ISSI datasheet confirms this. 1ms seems plenty, and is much shorter than + //refresh interval, meaning we won't risk losing contents if the SDRAM is in self-refresh + //mode +/* Step 4 --------------------------------------------------------------------*/ + /* Insert 1 ms delay */ + chThdSleepMilliseconds(1); + +/* Step 5 --------------------------------------------------------------------*/ + /* Configure a PALL (precharge all) command */ + FMC_SDRAMCommandStructure.FMC_CommandMode = FMC_Command_Mode_PALL; + FMC_SDRAMCommandStructure.FMC_CommandTarget = FMC_Command_Target_bank2; + FMC_SDRAMCommandStructure.FMC_AutoRefreshNumber = 1; + FMC_SDRAMCommandStructure.FMC_ModeRegisterDefinition = 0; + /* Wait until the SDRAM controller is ready */ + while(FMC_GetFlagStatus(FMC_Bank2_SDRAM, FMC_FLAG_Busy) != RESET) + { + } + /* Send the command */ + FMC_SDRAMCmdConfig(&FMC_SDRAMCommandStructure); + +/* Step 6 --------------------------------------------------------------------*/ + /* Configure a Auto-Refresh command */ + FMC_SDRAMCommandStructure.FMC_CommandMode = FMC_Command_Mode_AutoRefresh; + FMC_SDRAMCommandStructure.FMC_CommandTarget = FMC_Command_Target_bank2; + FMC_SDRAMCommandStructure.FMC_AutoRefreshNumber = 4; + FMC_SDRAMCommandStructure.FMC_ModeRegisterDefinition = 0; + /* Wait until the SDRAM controller is ready */ + while(FMC_GetFlagStatus(FMC_Bank2_SDRAM, FMC_FLAG_Busy) != RESET) + { + } + /* Send the first command */ + FMC_SDRAMCmdConfig(&FMC_SDRAMCommandStructure); + + /* Wait until the SDRAM controller is ready */ + while(FMC_GetFlagStatus(FMC_Bank2_SDRAM, FMC_FLAG_Busy) != RESET) + { + } + /* Send the second command */ + FMC_SDRAMCmdConfig(&FMC_SDRAMCommandStructure); + +/* Step 7 --------------------------------------------------------------------*/ + /* Program the external memory mode register */ + tmpr = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_2 | + SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL | + SDRAM_MODEREG_CAS_LATENCY_3 | + SDRAM_MODEREG_OPERATING_MODE_STANDARD | + SDRAM_MODEREG_WRITEBURST_MODE_SINGLE; + + /* Configure a load Mode register command*/ + FMC_SDRAMCommandStructure.FMC_CommandMode = FMC_Command_Mode_LoadMode; + FMC_SDRAMCommandStructure.FMC_CommandTarget = FMC_Command_Target_bank2; + FMC_SDRAMCommandStructure.FMC_AutoRefreshNumber = 1; + FMC_SDRAMCommandStructure.FMC_ModeRegisterDefinition = tmpr; + /* Wait until the SDRAM controller is ready */ + while(FMC_GetFlagStatus(FMC_Bank2_SDRAM, FMC_FLAG_Busy) != RESET) + { + } + /* Send the command */ + FMC_SDRAMCmdConfig(&FMC_SDRAMCommandStructure); + +/* Step 8 --------------------------------------------------------------------*/ + + /* Set the refresh rate counter */ + /* (7.81 us x Freq) - 20 */ + /* Set the device refresh counter */ + FMC_SetRefreshCount(683); + /* Wait until the SDRAM controller is ready */ + while(FMC_GetFlagStatus(FMC_Bank2_SDRAM, FMC_FLAG_Busy) != RESET) + { + } +} + + +/** + * @brief Writes a Entire-word buffer to the SDRAM memory. + * @param pBuffer: pointer to buffer. + * @param uwWriteAddress: SDRAM memory internal address from which the data will be + * written. + * @param uwBufferSize: number of words to write. + * @retval None. + */ +void SDRAM_WriteBuffer(uint32_t* pBuffer, uint32_t uwWriteAddress, uint32_t uwBufferSize) +{ + __IO uint32_t write_pointer = (uint32_t)uwWriteAddress; + + /* Disable write protection */ + FMC_SDRAMWriteProtectionConfig(FMC_Bank2_SDRAM, DISABLE); + + /* Wait until the SDRAM controller is ready */ + while(FMC_GetFlagStatus(FMC_Bank2_SDRAM, FMC_FLAG_Busy) != RESET) + { + } + + /* While there is data to write */ + for (; uwBufferSize != 0; uwBufferSize--) + { + /* Transfer data to the memory */ + *(uint32_t *) (SDRAM_BANK_ADDR + write_pointer) = *pBuffer++; + + /* Increment the address*/ + write_pointer += 4; + } + +} + +/** + * @brief Reads data buffer from the SDRAM memory. + * @param pBuffer: pointer to buffer. + * @param ReadAddress: SDRAM memory internal address from which the data will be + * read. + * @param uwBufferSize: number of words to write. + * @retval None. + */ +void SDRAM_ReadBuffer(uint32_t* pBuffer, uint32_t uwReadAddress, uint32_t uwBufferSize) +{ + __IO uint32_t write_pointer = (uint32_t)uwReadAddress; + + + /* Wait until the SDRAM controller is ready */ + while(FMC_GetFlagStatus(FMC_Bank2_SDRAM, FMC_FLAG_Busy) != RESET) + { + } + + /* Read data */ + for(; uwBufferSize != 0x00; uwBufferSize--) + { + *pBuffer++ = *(__IO uint32_t *)(SDRAM_BANK_ADDR + write_pointer ); + + /* Increment the address*/ + write_pointer += 4; + } +} + diff --git a/boards/base/STM32F429i-Discovery/stm32f429i_discovery_sdram.h b/boards/base/STM32F429i-Discovery/stm32f429i_discovery_sdram.h new file mode 100644 index 00000000..fba5115d --- /dev/null +++ b/boards/base/STM32F429i-Discovery/stm32f429i_discovery_sdram.h @@ -0,0 +1,96 @@ +/** + ****************************************************************************** + * @file stm32f429i_discovery_sdram.h + * @author MCD Application Team + * @version V1.0.0 + * @date 20-September-2013 + * @brief This file contains all the functions prototypes for the + * stm324x9i_disco_sdram.c driver. + ****************************************************************************** + * @attention + * + *

    © COPYRIGHT 2013 STMicroelectronics

    + * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32429I_DISCO_SDRAM_H +#define __STM32429I_DISCO_SDRAM_H + +#ifdef __cplusplus + extern "C" { +#endif + +//FIXME this should not be needed +#define STM32F429_439xx + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f4xx.h" + +/** + * @brief FMC SDRAM Bank address + */ +#define SDRAM_BANK_ADDR ((uint32_t)0xD0000000) + +/** + * @brief FMC SDRAM Memory Width + */ +/* #define SDRAM_MEMORY_WIDTH FMC_SDMemory_Width_8b */ +#define SDRAM_MEMORY_WIDTH FMC_SDMemory_Width_16b + +/** + * @brief FMC SDRAM CAS Latency + */ +/* #define SDRAM_CAS_LATENCY FMC_CAS_Latency_2 */ +#define SDRAM_CAS_LATENCY FMC_CAS_Latency_3 + +/** + * @brief FMC SDRAM Memory clock period + */ +#define SDCLOCK_PERIOD FMC_SDClock_Period_2 /* Default configuration used with LCD */ +/* #define SDCLOCK_PERIOD FMC_SDClock_Period_3 */ + +/** + * @brief FMC SDRAM Memory Read Burst feature + */ +#define SDRAM_READBURST FMC_Read_Burst_Disable /* Default configuration used with LCD */ +/* #define SDRAM_READBURST FMC_Read_Burst_Enable */ + +/** + * @brief FMC SDRAM Mode definition register defines + */ +#define SDRAM_MODEREG_BURST_LENGTH_1 ((uint16_t)0x0000) +#define SDRAM_MODEREG_BURST_LENGTH_2 ((uint16_t)0x0001) +#define SDRAM_MODEREG_BURST_LENGTH_4 ((uint16_t)0x0002) +#define SDRAM_MODEREG_BURST_LENGTH_8 ((uint16_t)0x0004) +#define SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL ((uint16_t)0x0000) +#define SDRAM_MODEREG_BURST_TYPE_INTERLEAVED ((uint16_t)0x0008) +#define SDRAM_MODEREG_CAS_LATENCY_2 ((uint16_t)0x0020) +#define SDRAM_MODEREG_CAS_LATENCY_3 ((uint16_t)0x0030) +#define SDRAM_MODEREG_OPERATING_MODE_STANDARD ((uint16_t)0x0000) +#define SDRAM_MODEREG_WRITEBURST_MODE_PROGRAMMED ((uint16_t)0x0000) +#define SDRAM_MODEREG_WRITEBURST_MODE_SINGLE ((uint16_t)0x0200) + +void SDRAM_Init(void); +void SDRAM_InitSequence(void); +void SDRAM_WriteBuffer(uint32_t* pBuffer, uint32_t uwWriteAddress, uint32_t uwBufferSize); +void SDRAM_ReadBuffer(uint32_t* pBuffer, uint32_t uwReadAddress, uint32_t uwBufferSize); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/boards/base/STM32F429i-Discovery/stm32f4xx_fmc.c b/boards/base/STM32F429i-Discovery/stm32f4xx_fmc.c new file mode 100644 index 00000000..10e73262 --- /dev/null +++ b/boards/base/STM32F429i-Discovery/stm32f4xx_fmc.c @@ -0,0 +1,1376 @@ +/** + ****************************************************************************** + * @file stm32f4xx_fmc.c + * @author MCD Application Team + * @version V1.2.1 + * @date 19-September-2013 + * @brief This file provides firmware functions to manage the following + * functionalities of the FMC peripheral: + * + Interface with SRAM, PSRAM, NOR and OneNAND memories + * + Interface with NAND memories + * + Interface with 16-bit PC Card compatible memories + * + Interface with SDRAM memories + * + Interrupts and flags management + * + ****************************************************************************** + * @attention + * + *

    © COPYRIGHT 2013 STMicroelectronics

    + * + * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.st.com/software_license_agreement_liberty_v2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f4xx_fmc.h" +#include "ch.h" +//#include "stm32f4xx_rcc.h" + +#define assert_param(expr) chDbgAssert(expr,"STPeriph FMC","") + +/** @addtogroup STM32F4xx_StdPeriph_Driver + * @{ + */ + +/** @defgroup FMC + * @brief FMC driver modules + * @{ + */ + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ + +/* --------------------- FMC registers bit mask ---------------------------- */ +/* FMC BCRx Mask */ +#define BCR_MBKEN_SET ((uint32_t)0x00000001) +#define BCR_MBKEN_RESET ((uint32_t)0x000FFFFE) +#define BCR_FACCEN_SET ((uint32_t)0x00000040) + +/* FMC PCRx Mask */ +#define PCR_PBKEN_SET ((uint32_t)0x00000004) +#define PCR_PBKEN_RESET ((uint32_t)0x000FFFFB) +#define PCR_ECCEN_SET ((uint32_t)0x00000040) +#define PCR_ECCEN_RESET ((uint32_t)0x000FFFBF) +#define PCR_MEMORYTYPE_NAND ((uint32_t)0x00000008) + +/* FMC SDCRx write protection Mask*/ +#define SDCR_WriteProtection_RESET ((uint32_t)0x00007DFF) + +/* FMC SDCMR Mask*/ +#define SDCMR_CTB1_RESET ((uint32_t)0x003FFFEF) +#define SDCMR_CTB2_RESET ((uint32_t)0x003FFFF7) +#define SDCMR_CTB1_2_RESET ((uint32_t)0x003FFFE7) + +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** @defgroup FMC_Private_Functions + * @{ + */ + +/** @defgroup FMC_Group1 NOR/SRAM Controller functions + * @brief NOR/SRAM Controller functions + * +@verbatim + =============================================================================== + ##### NOR and SRAM Controller functions ##### + =============================================================================== + + [..] The following sequence should be followed to configure the FMC to interface + with SRAM, PSRAM, NOR or OneNAND memory connected to the NOR/SRAM Bank: + + (#) Enable the clock for the FMC and associated GPIOs using the following functions: + RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE); + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE); + + (#) FMC pins configuration + (++) Connect the involved FMC pins to AF12 using the following function + GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FMC); + (++) Configure these FMC pins in alternate function mode by calling the function + GPIO_Init(); + + (#) Declare a FMC_NORSRAMInitTypeDef structure, for example: + FMC_NORSRAMInitTypeDef FMC_NORSRAMInitStructure; + and fill the FMC_NORSRAMInitStructure variable with the allowed values of + the structure member. + + (#) Initialize the NOR/SRAM Controller by calling the function + FMC_NORSRAMInit(&FMC_NORSRAMInitStructure); + + (#) Then enable the NOR/SRAM Bank, for example: + FMC_NORSRAMCmd(FMC_Bank1_NORSRAM2, ENABLE); + + (#) At this stage you can read/write from/to the memory connected to the NOR/SRAM Bank. + +@endverbatim + * @{ + */ + +/** + * @brief De-initializes the FMC NOR/SRAM Banks registers to their default + * reset values. + * @param FMC_Bank: specifies the FMC Bank to be used + * This parameter can be one of the following values: + * @arg FMC_Bank1_NORSRAM1: FMC Bank1 NOR/SRAM1 + * @arg FMC_Bank1_NORSRAM2: FMC Bank1 NOR/SRAM2 + * @arg FMC_Bank1_NORSRAM3: FMC Bank1 NOR/SRAM3 + * @arg FMC_Bank1_NORSRAM4: FMC Bank1 NOR/SRAM4 + * @retval None + */ +void FMC_NORSRAMDeInit(uint32_t FMC_Bank) +{ + /* Check the parameter */ + assert_param(IS_FMC_NORSRAM_BANK(FMC_Bank)); + + /* FMC_Bank1_NORSRAM1 */ + if(FMC_Bank == FMC_Bank1_NORSRAM1) + { + FMC_Bank1->BTCR[FMC_Bank] = 0x000030DB; + } + /* FMC_Bank1_NORSRAM2, FMC_Bank1_NORSRAM3 or FMC_Bank1_NORSRAM4 */ + else + { + FMC_Bank1->BTCR[FMC_Bank] = 0x000030D2; + } + FMC_Bank1->BTCR[FMC_Bank + 1] = 0x0FFFFFFF; + FMC_Bank1E->BWTR[FMC_Bank] = 0x0FFFFFFF; +} + +/** + * @brief Initializes the FMC NOR/SRAM Banks according to the specified + * parameters in the FMC_NORSRAMInitStruct. + * @param FMC_NORSRAMInitStruct : pointer to a FMC_NORSRAMInitTypeDef structure + * that contains the configuration information for the FMC NOR/SRAM + * specified Banks. + * @retval None + */ +void FMC_NORSRAMInit(FMC_NORSRAMInitTypeDef* FMC_NORSRAMInitStruct) +{ + uint32_t tmpr = 0; + + /* Check the parameters */ + assert_param(IS_FMC_NORSRAM_BANK(FMC_NORSRAMInitStruct->FMC_Bank)); + assert_param(IS_FMC_MUX(FMC_NORSRAMInitStruct->FMC_DataAddressMux)); + assert_param(IS_FMC_MEMORY(FMC_NORSRAMInitStruct->FMC_MemoryType)); + assert_param(IS_FMC_NORSRAM_MEMORY_WIDTH(FMC_NORSRAMInitStruct->FMC_MemoryDataWidth)); + assert_param(IS_FMC_BURSTMODE(FMC_NORSRAMInitStruct->FMC_BurstAccessMode)); + assert_param(IS_FMC_WAIT_POLARITY(FMC_NORSRAMInitStruct->FMC_WaitSignalPolarity)); + assert_param(IS_FMC_WRAP_MODE(FMC_NORSRAMInitStruct->FMC_WrapMode)); + assert_param(IS_FMC_WAIT_SIGNAL_ACTIVE(FMC_NORSRAMInitStruct->FMC_WaitSignalActive)); + assert_param(IS_FMC_WRITE_OPERATION(FMC_NORSRAMInitStruct->FMC_WriteOperation)); + assert_param(IS_FMC_WAITE_SIGNAL(FMC_NORSRAMInitStruct->FMC_WaitSignal)); + assert_param(IS_FMC_EXTENDED_MODE(FMC_NORSRAMInitStruct->FMC_ExtendedMode)); + assert_param(IS_FMC_ASYNWAIT(FMC_NORSRAMInitStruct->FMC_AsynchronousWait)); + assert_param(IS_FMC_WRITE_BURST(FMC_NORSRAMInitStruct->FMC_WriteBurst)); + assert_param(IS_FMC_CONTINOUS_CLOCK(FMC_NORSRAMInitStruct->FMC_ContinousClock)); + assert_param(IS_FMC_ADDRESS_SETUP_TIME(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AddressSetupTime)); + assert_param(IS_FMC_ADDRESS_HOLD_TIME(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AddressHoldTime)); + assert_param(IS_FMC_DATASETUP_TIME(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_DataSetupTime)); + assert_param(IS_FMC_TURNAROUND_TIME(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_BusTurnAroundDuration)); + assert_param(IS_FMC_CLK_DIV(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_CLKDivision)); + assert_param(IS_FMC_DATA_LATENCY(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_DataLatency)); + assert_param(IS_FMC_ACCESS_MODE(FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AccessMode)); + + /* NOR/SRAM Bank control register configuration */ + FMC_Bank1->BTCR[FMC_NORSRAMInitStruct->FMC_Bank] = + (uint32_t)FMC_NORSRAMInitStruct->FMC_DataAddressMux | + FMC_NORSRAMInitStruct->FMC_MemoryType | + FMC_NORSRAMInitStruct->FMC_MemoryDataWidth | + FMC_NORSRAMInitStruct->FMC_BurstAccessMode | + FMC_NORSRAMInitStruct->FMC_WaitSignalPolarity | + FMC_NORSRAMInitStruct->FMC_WrapMode | + FMC_NORSRAMInitStruct->FMC_WaitSignalActive | + FMC_NORSRAMInitStruct->FMC_WriteOperation | + FMC_NORSRAMInitStruct->FMC_WaitSignal | + FMC_NORSRAMInitStruct->FMC_ExtendedMode | + FMC_NORSRAMInitStruct->FMC_AsynchronousWait | + FMC_NORSRAMInitStruct->FMC_WriteBurst | + FMC_NORSRAMInitStruct->FMC_ContinousClock; + + + if(FMC_NORSRAMInitStruct->FMC_MemoryType == FMC_MemoryType_NOR) + { + FMC_Bank1->BTCR[FMC_NORSRAMInitStruct->FMC_Bank] |= (uint32_t)BCR_FACCEN_SET; + } + + /* Configure Continuous clock feature when bank2..4 is used */ + if((FMC_NORSRAMInitStruct->FMC_ContinousClock == FMC_CClock_SyncAsync) && (FMC_NORSRAMInitStruct->FMC_Bank != FMC_Bank1_NORSRAM1)) + { + tmpr = (uint32_t)((FMC_Bank1->BTCR[FMC_Bank1_NORSRAM1+1]) & ~(((uint32_t)0x0F) << 20)); + + FMC_Bank1->BTCR[FMC_Bank1_NORSRAM1] |= FMC_NORSRAMInitStruct->FMC_ContinousClock; + FMC_Bank1->BTCR[FMC_Bank1_NORSRAM1] |= FMC_BurstAccessMode_Enable; + FMC_Bank1->BTCR[FMC_Bank1_NORSRAM1+1] = (uint32_t)(tmpr | (((FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_CLKDivision)-1) << 20)); + } + + /* NOR/SRAM Bank timing register configuration */ + FMC_Bank1->BTCR[FMC_NORSRAMInitStruct->FMC_Bank+1] = + (uint32_t)FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AddressSetupTime | + (FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AddressHoldTime << 4) | + (FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_DataSetupTime << 8) | + (FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_BusTurnAroundDuration << 16) | + ((FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_CLKDivision) << 20) | + ((FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_DataLatency) << 24) | + FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AccessMode; + + /* NOR/SRAM Bank timing register for write configuration, if extended mode is used */ + if(FMC_NORSRAMInitStruct->FMC_ExtendedMode == FMC_ExtendedMode_Enable) + { + assert_param(IS_FMC_ADDRESS_SETUP_TIME(FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AddressSetupTime)); + assert_param(IS_FMC_ADDRESS_HOLD_TIME(FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AddressHoldTime)); + assert_param(IS_FMC_DATASETUP_TIME(FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_DataSetupTime)); + assert_param(IS_FMC_CLK_DIV(FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_CLKDivision)); + assert_param(IS_FMC_DATA_LATENCY(FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_DataLatency)); + assert_param(IS_FMC_ACCESS_MODE(FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AccessMode)); + + FMC_Bank1E->BWTR[FMC_NORSRAMInitStruct->FMC_Bank] = + (uint32_t)FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AddressSetupTime | + (FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AddressHoldTime << 4 )| + (FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_DataSetupTime << 8) | + ((FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_CLKDivision) << 20) | + ((FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_DataLatency) << 24) | + FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AccessMode; + } + else + { + FMC_Bank1E->BWTR[FMC_NORSRAMInitStruct->FMC_Bank] = 0x0FFFFFFF; + } + +} + +/** + * @brief Fills each FMC_NORSRAMInitStruct member with its default value. + * @param FMC_NORSRAMInitStruct: pointer to a FMC_NORSRAMInitTypeDef structure + * which will be initialized. + * @retval None + */ +void FMC_NORSRAMStructInit(FMC_NORSRAMInitTypeDef* FMC_NORSRAMInitStruct) +{ + /* Reset NOR/SRAM Init structure parameters values */ + FMC_NORSRAMInitStruct->FMC_Bank = FMC_Bank1_NORSRAM1; + FMC_NORSRAMInitStruct->FMC_DataAddressMux = FMC_DataAddressMux_Enable; + FMC_NORSRAMInitStruct->FMC_MemoryType = FMC_MemoryType_SRAM; + FMC_NORSRAMInitStruct->FMC_MemoryDataWidth = FMC_NORSRAM_MemoryDataWidth_16b; + FMC_NORSRAMInitStruct->FMC_BurstAccessMode = FMC_BurstAccessMode_Disable; + FMC_NORSRAMInitStruct->FMC_AsynchronousWait = FMC_AsynchronousWait_Disable; + FMC_NORSRAMInitStruct->FMC_WaitSignalPolarity = FMC_WaitSignalPolarity_Low; + FMC_NORSRAMInitStruct->FMC_WrapMode = FMC_WrapMode_Disable; + FMC_NORSRAMInitStruct->FMC_WaitSignalActive = FMC_WaitSignalActive_BeforeWaitState; + FMC_NORSRAMInitStruct->FMC_WriteOperation = FMC_WriteOperation_Enable; + FMC_NORSRAMInitStruct->FMC_WaitSignal = FMC_WaitSignal_Enable; + FMC_NORSRAMInitStruct->FMC_ExtendedMode = FMC_ExtendedMode_Disable; + FMC_NORSRAMInitStruct->FMC_WriteBurst = FMC_WriteBurst_Disable; + FMC_NORSRAMInitStruct->FMC_ContinousClock = FMC_CClock_SyncOnly; + + FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AddressSetupTime = 15; + FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AddressHoldTime = 15; + FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_DataSetupTime = 255; + FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_BusTurnAroundDuration = 15; + FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_CLKDivision = 15; + FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_DataLatency = 15; + FMC_NORSRAMInitStruct->FMC_ReadWriteTimingStruct->FMC_AccessMode = FMC_AccessMode_A; + FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AddressSetupTime = 15; + FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AddressHoldTime = 15; + FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_DataSetupTime = 255; + FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_BusTurnAroundDuration = 15; + FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_CLKDivision = 15; + FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_DataLatency = 15; + FMC_NORSRAMInitStruct->FMC_WriteTimingStruct->FMC_AccessMode = FMC_AccessMode_A; +} + +/** + * @brief Enables or disables the specified NOR/SRAM Memory Bank. + * @param FMC_Bank: specifies the FMC Bank to be used + * This parameter can be one of the following values: + * @arg FMC_Bank1_NORSRAM1: FMC Bank1 NOR/SRAM1 + * @arg FMC_Bank1_NORSRAM2: FMC Bank1 NOR/SRAM2 + * @arg FMC_Bank1_NORSRAM3: FMC Bank1 NOR/SRAM3 + * @arg FMC_Bank1_NORSRAM4: FMC Bank1 NOR/SRAM4 + * @param NewState: new state of the FMC_Bank. This parameter can be: ENABLE or DISABLE. + * @retval None + */ +void FMC_NORSRAMCmd(uint32_t FMC_Bank, FunctionalState NewState) +{ + assert_param(IS_FMC_NORSRAM_BANK(FMC_Bank)); + assert_param(IS_FUNCTIONAL_STATE(NewState)); + + if (NewState != DISABLE) + { + /* Enable the selected NOR/SRAM Bank by setting the PBKEN bit in the BCRx register */ + FMC_Bank1->BTCR[FMC_Bank] |= BCR_MBKEN_SET; + } + else + { + /* Disable the selected NOR/SRAM Bank by clearing the PBKEN bit in the BCRx register */ + FMC_Bank1->BTCR[FMC_Bank] &= BCR_MBKEN_RESET; + } +} +/** + * @} + */ + +/** @defgroup FMC_Group2 NAND Controller functions + * @brief NAND Controller functions + * +@verbatim + =============================================================================== + ##### NAND Controller functions ##### + =============================================================================== + + [..] The following sequence should be followed to configure the FMC to interface + with 8-bit or 16-bit NAND memory connected to the NAND Bank: + + (#) Enable the clock for the FMC and associated GPIOs using the following functions: + (++) RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE); + (++) RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE); + + (#) FMC pins configuration + (++) Connect the involved FMC pins to AF12 using the following function + GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FMC); + (++) Configure these FMC pins in alternate function mode by calling the function + GPIO_Init(); + + (#) Declare a FMC_NANDInitTypeDef structure, for example: + FMC_NANDInitTypeDef FMC_NANDInitStructure; + and fill the FMC_NANDInitStructure variable with the allowed values of + the structure member. + + (#) Initialize the NAND Controller by calling the function + FMC_NANDInit(&FMC_NANDInitStructure); + + (#) Then enable the NAND Bank, for example: + FMC_NANDCmd(FMC_Bank3_NAND, ENABLE); + + (#) At this stage you can read/write from/to the memory connected to the NAND Bank. + + [..] + (@) To enable the Error Correction Code (ECC), you have to use the function + FMC_NANDECCCmd(FMC_Bank3_NAND, ENABLE); + [..] + (@) and to get the current ECC value you have to use the function + ECCval = FMC_GetECC(FMC_Bank3_NAND); + +@endverbatim + * @{ + */ + +/** + * @brief De-initializes the FMC NAND Banks registers to their default reset values. + * @param FMC_Bank: specifies the FMC Bank to be used + * This parameter can be one of the following values: + * @arg FMC_Bank2_NAND: FMC Bank2 NAND + * @arg FMC_Bank3_NAND: FMC Bank3 NAND + * @retval None + */ +void FMC_NANDDeInit(uint32_t FMC_Bank) +{ + /* Check the parameter */ + assert_param(IS_FMC_NAND_BANK(FMC_Bank)); + + if(FMC_Bank == FMC_Bank2_NAND) + { + /* Set the FMC_Bank2 registers to their reset values */ + FMC_Bank2->PCR2 = 0x00000018; + FMC_Bank2->SR2 = 0x00000040; + FMC_Bank2->PMEM2 = 0xFCFCFCFC; + FMC_Bank2->PATT2 = 0xFCFCFCFC; + } + /* FMC_Bank3_NAND */ + else + { + /* Set the FMC_Bank3 registers to their reset values */ + FMC_Bank3->PCR3 = 0x00000018; + FMC_Bank3->SR3 = 0x00000040; + FMC_Bank3->PMEM3 = 0xFCFCFCFC; + FMC_Bank3->PATT3 = 0xFCFCFCFC; + } +} + +/** + * @brief Initializes the FMC NAND Banks according to the specified parameters + * in the FMC_NANDInitStruct. + * @param FMC_NANDInitStruct : pointer to a FMC_NANDInitTypeDef structure that + * contains the configuration information for the FMC NAND specified Banks. + * @retval None + */ +void FMC_NANDInit(FMC_NANDInitTypeDef* FMC_NANDInitStruct) +{ + uint32_t tmppcr = 0x00000000, tmppmem = 0x00000000, tmppatt = 0x00000000; + + /* Check the parameters */ + assert_param(IS_FMC_NAND_BANK(FMC_NANDInitStruct->FMC_Bank)); + assert_param(IS_FMC_WAIT_FEATURE(FMC_NANDInitStruct->FMC_Waitfeature)); + assert_param(IS_FMC_NAND_MEMORY_WIDTH(FMC_NANDInitStruct->FMC_MemoryDataWidth)); + assert_param(IS_FMC_ECC_STATE(FMC_NANDInitStruct->FMC_ECC)); + assert_param(IS_FMC_ECCPAGE_SIZE(FMC_NANDInitStruct->FMC_ECCPageSize)); + assert_param(IS_FMC_TCLR_TIME(FMC_NANDInitStruct->FMC_TCLRSetupTime)); + assert_param(IS_FMC_TAR_TIME(FMC_NANDInitStruct->FMC_TARSetupTime)); + assert_param(IS_FMC_SETUP_TIME(FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_SetupTime)); + assert_param(IS_FMC_WAIT_TIME(FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_WaitSetupTime)); + assert_param(IS_FMC_HOLD_TIME(FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HoldSetupTime)); + assert_param(IS_FMC_HIZ_TIME(FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HiZSetupTime)); + assert_param(IS_FMC_SETUP_TIME(FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_SetupTime)); + assert_param(IS_FMC_WAIT_TIME(FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_WaitSetupTime)); + assert_param(IS_FMC_HOLD_TIME(FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HoldSetupTime)); + assert_param(IS_FMC_HIZ_TIME(FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HiZSetupTime)); + + /* Set the tmppcr value according to FMC_NANDInitStruct parameters */ + tmppcr = (uint32_t)FMC_NANDInitStruct->FMC_Waitfeature | + PCR_MEMORYTYPE_NAND | + FMC_NANDInitStruct->FMC_MemoryDataWidth | + FMC_NANDInitStruct->FMC_ECC | + FMC_NANDInitStruct->FMC_ECCPageSize | + (FMC_NANDInitStruct->FMC_TCLRSetupTime << 9 )| + (FMC_NANDInitStruct->FMC_TARSetupTime << 13); + + /* Set tmppmem value according to FMC_CommonSpaceTimingStructure parameters */ + tmppmem = (uint32_t)FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_SetupTime | + (FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_WaitSetupTime << 8) | + (FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HoldSetupTime << 16)| + (FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HiZSetupTime << 24); + + /* Set tmppatt value according to FMC_AttributeSpaceTimingStructure parameters */ + tmppatt = (uint32_t)FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_SetupTime | + (FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_WaitSetupTime << 8) | + (FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HoldSetupTime << 16)| + (FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HiZSetupTime << 24); + + if(FMC_NANDInitStruct->FMC_Bank == FMC_Bank2_NAND) + { + /* FMC_Bank2_NAND registers configuration */ + FMC_Bank2->PCR2 = tmppcr; + FMC_Bank2->PMEM2 = tmppmem; + FMC_Bank2->PATT2 = tmppatt; + } + else + { + /* FMC_Bank3_NAND registers configuration */ + FMC_Bank3->PCR3 = tmppcr; + FMC_Bank3->PMEM3 = tmppmem; + FMC_Bank3->PATT3 = tmppatt; + } +} + + +/** + * @brief Fills each FMC_NANDInitStruct member with its default value. + * @param FMC_NANDInitStruct: pointer to a FMC_NANDInitTypeDef structure which + * will be initialized. + * @retval None + */ +void FMC_NANDStructInit(FMC_NANDInitTypeDef* FMC_NANDInitStruct) +{ + /* Reset NAND Init structure parameters values */ + FMC_NANDInitStruct->FMC_Bank = FMC_Bank2_NAND; + FMC_NANDInitStruct->FMC_Waitfeature = FMC_Waitfeature_Disable; + FMC_NANDInitStruct->FMC_MemoryDataWidth = FMC_NAND_MemoryDataWidth_16b; + FMC_NANDInitStruct->FMC_ECC = FMC_ECC_Disable; + FMC_NANDInitStruct->FMC_ECCPageSize = FMC_ECCPageSize_256Bytes; + FMC_NANDInitStruct->FMC_TCLRSetupTime = 0x0; + FMC_NANDInitStruct->FMC_TARSetupTime = 0x0; + FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_SetupTime = 252; + FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_WaitSetupTime = 252; + FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HoldSetupTime = 252; + FMC_NANDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HiZSetupTime = 252; + FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_SetupTime = 252; + FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_WaitSetupTime = 252; + FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HoldSetupTime = 252; + FMC_NANDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HiZSetupTime = 252; +} + +/** + * @brief Enables or disables the specified NAND Memory Bank. + * @param FMC_Bank: specifies the FMC Bank to be used + * This parameter can be one of the following values: + * @arg FMC_Bank2_NAND: FMC Bank2 NAND + * @arg FMC_Bank3_NAND: FMC Bank3 NAND + * @param NewState: new state of the FMC_Bank. This parameter can be: ENABLE or DISABLE. + * @retval None + */ +void FMC_NANDCmd(uint32_t FMC_Bank, FunctionalState NewState) +{ + assert_param(IS_FMC_NAND_BANK(FMC_Bank)); + assert_param(IS_FUNCTIONAL_STATE(NewState)); + + if (NewState != DISABLE) + { + /* Enable the selected NAND Bank by setting the PBKEN bit in the PCRx register */ + if(FMC_Bank == FMC_Bank2_NAND) + { + FMC_Bank2->PCR2 |= PCR_PBKEN_SET; + } + else + { + FMC_Bank3->PCR3 |= PCR_PBKEN_SET; + } + } + else + { + /* Disable the selected NAND Bank by clearing the PBKEN bit in the PCRx register */ + if(FMC_Bank == FMC_Bank2_NAND) + { + FMC_Bank2->PCR2 &= PCR_PBKEN_RESET; + } + else + { + FMC_Bank3->PCR3 &= PCR_PBKEN_RESET; + } + } +} +/** + * @brief Enables or disables the FMC NAND ECC feature. + * @param FMC_Bank: specifies the FMC Bank to be used + * This parameter can be one of the following values: + * @arg FMC_Bank2_NAND: FMC Bank2 NAND + * @arg FMC_Bank3_NAND: FMC Bank3 NAND + * @param NewState: new state of the FMC NAND ECC feature. + * This parameter can be: ENABLE or DISABLE. + * @retval None + */ +void FMC_NANDECCCmd(uint32_t FMC_Bank, FunctionalState NewState) +{ + assert_param(IS_FMC_NAND_BANK(FMC_Bank)); + assert_param(IS_FUNCTIONAL_STATE(NewState)); + + if (NewState != DISABLE) + { + /* Enable the selected NAND Bank ECC function by setting the ECCEN bit in the PCRx register */ + if(FMC_Bank == FMC_Bank2_NAND) + { + FMC_Bank2->PCR2 |= PCR_ECCEN_SET; + } + else + { + FMC_Bank3->PCR3 |= PCR_ECCEN_SET; + } + } + else + { + /* Disable the selected NAND Bank ECC function by clearing the ECCEN bit in the PCRx register */ + if(FMC_Bank == FMC_Bank2_NAND) + { + FMC_Bank2->PCR2 &= PCR_ECCEN_RESET; + } + else + { + FMC_Bank3->PCR3 &= PCR_ECCEN_RESET; + } + } +} + +/** + * @brief Returns the error correction code register value. + * @param FMC_Bank: specifies the FMC Bank to be used + * This parameter can be one of the following values: + * @arg FMC_Bank2_NAND: FMC Bank2 NAND + * @arg FMC_Bank3_NAND: FMC Bank3 NAND + * @retval The Error Correction Code (ECC) value. + */ +uint32_t FMC_GetECC(uint32_t FMC_Bank) +{ + uint32_t eccval = 0x00000000; + + if(FMC_Bank == FMC_Bank2_NAND) + { + /* Get the ECCR2 register value */ + eccval = FMC_Bank2->ECCR2; + } + else + { + /* Get the ECCR3 register value */ + eccval = FMC_Bank3->ECCR3; + } + /* Return the error correction code value */ + return(eccval); +} +/** + * @} + */ + +/** @defgroup FMC_Group3 PCCARD Controller functions + * @brief PCCARD Controller functions + * +@verbatim + =============================================================================== + ##### PCCARD Controller functions ##### + =============================================================================== + + [..] he following sequence should be followed to configure the FMC to interface + with 16-bit PC Card compatible memory connected to the PCCARD Bank: + + (#) Enable the clock for the FMC and associated GPIOs using the following functions: + (++) RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE); + (++) RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE); + + (#) FMC pins configuration + (++) Connect the involved FMC pins to AF12 using the following function + GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FMC); + (++) Configure these FMC pins in alternate function mode by calling the function + GPIO_Init(); + + (#) Declare a FMC_PCCARDInitTypeDef structure, for example: + FMC_PCCARDInitTypeDef FMC_PCCARDInitStructure; + and fill the FMC_PCCARDInitStructure variable with the allowed values of + the structure member. + + (#) Initialize the PCCARD Controller by calling the function + FMC_PCCARDInit(&FMC_PCCARDInitStructure); + + (#) Then enable the PCCARD Bank: + FMC_PCCARDCmd(ENABLE); + + (#) At this stage you can read/write from/to the memory connected to the PCCARD Bank. + +@endverbatim + * @{ + */ + +/** + * @brief De-initializes the FMC PCCARD Bank registers to their default reset values. + * @param None + * @retval None + */ +void FMC_PCCARDDeInit(void) +{ + /* Set the FMC_Bank4 registers to their reset values */ + FMC_Bank4->PCR4 = 0x00000018; + FMC_Bank4->SR4 = 0x00000000; + FMC_Bank4->PMEM4 = 0xFCFCFCFC; + FMC_Bank4->PATT4 = 0xFCFCFCFC; + FMC_Bank4->PIO4 = 0xFCFCFCFC; +} + +/** + * @brief Initializes the FMC PCCARD Bank according to the specified parameters + * in the FMC_PCCARDInitStruct. + * @param FMC_PCCARDInitStruct : pointer to a FMC_PCCARDInitTypeDef structure + * that contains the configuration information for the FMC PCCARD Bank. + * @retval None + */ +void FMC_PCCARDInit(FMC_PCCARDInitTypeDef* FMC_PCCARDInitStruct) +{ + /* Check the parameters */ + assert_param(IS_FMC_WAIT_FEATURE(FMC_PCCARDInitStruct->FMC_Waitfeature)); + assert_param(IS_FMC_TCLR_TIME(FMC_PCCARDInitStruct->FMC_TCLRSetupTime)); + assert_param(IS_FMC_TAR_TIME(FMC_PCCARDInitStruct->FMC_TARSetupTime)); + + assert_param(IS_FMC_SETUP_TIME(FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_SetupTime)); + assert_param(IS_FMC_WAIT_TIME(FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_WaitSetupTime)); + assert_param(IS_FMC_HOLD_TIME(FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HoldSetupTime)); + assert_param(IS_FMC_HIZ_TIME(FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HiZSetupTime)); + + assert_param(IS_FMC_SETUP_TIME(FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_SetupTime)); + assert_param(IS_FMC_WAIT_TIME(FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_WaitSetupTime)); + assert_param(IS_FMC_HOLD_TIME(FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HoldSetupTime)); + assert_param(IS_FMC_HIZ_TIME(FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HiZSetupTime)); + assert_param(IS_FMC_SETUP_TIME(FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_SetupTime)); + assert_param(IS_FMC_WAIT_TIME(FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_WaitSetupTime)); + assert_param(IS_FMC_HOLD_TIME(FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_HoldSetupTime)); + assert_param(IS_FMC_HIZ_TIME(FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_HiZSetupTime)); + + /* Set the PCR4 register value according to FMC_PCCARDInitStruct parameters */ + FMC_Bank4->PCR4 = (uint32_t)FMC_PCCARDInitStruct->FMC_Waitfeature | + FMC_NAND_MemoryDataWidth_16b | + (FMC_PCCARDInitStruct->FMC_TCLRSetupTime << 9) | + (FMC_PCCARDInitStruct->FMC_TARSetupTime << 13); + + /* Set PMEM4 register value according to FMC_CommonSpaceTimingStructure parameters */ + FMC_Bank4->PMEM4 = (uint32_t)FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_SetupTime | + (FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_WaitSetupTime << 8) | + (FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HoldSetupTime << 16)| + (FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HiZSetupTime << 24); + + /* Set PATT4 register value according to FMC_AttributeSpaceTimingStructure parameters */ + FMC_Bank4->PATT4 = (uint32_t)FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_SetupTime | + (FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_WaitSetupTime << 8) | + (FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HoldSetupTime << 16)| + (FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HiZSetupTime << 24); + + /* Set PIO4 register value according to FMC_IOSpaceTimingStructure parameters */ + FMC_Bank4->PIO4 = (uint32_t)FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_SetupTime | + (FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_WaitSetupTime << 8) | + (FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_HoldSetupTime << 16)| + (FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_HiZSetupTime << 24); +} + +/** + * @brief Fills each FMC_PCCARDInitStruct member with its default value. + * @param FMC_PCCARDInitStruct: pointer to a FMC_PCCARDInitTypeDef structure + * which will be initialized. + * @retval None + */ +void FMC_PCCARDStructInit(FMC_PCCARDInitTypeDef* FMC_PCCARDInitStruct) +{ + /* Reset PCCARD Init structure parameters values */ + FMC_PCCARDInitStruct->FMC_Waitfeature = FMC_Waitfeature_Disable; + FMC_PCCARDInitStruct->FMC_TCLRSetupTime = 0; + FMC_PCCARDInitStruct->FMC_TARSetupTime = 0; + FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_SetupTime = 252; + FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_WaitSetupTime = 252; + FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HoldSetupTime = 252; + FMC_PCCARDInitStruct->FMC_CommonSpaceTimingStruct->FMC_HiZSetupTime = 252; + FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_SetupTime = 252; + FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_WaitSetupTime = 252; + FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HoldSetupTime = 252; + FMC_PCCARDInitStruct->FMC_AttributeSpaceTimingStruct->FMC_HiZSetupTime = 252; + FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_SetupTime = 252; + FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_WaitSetupTime = 252; + FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_HoldSetupTime = 252; + FMC_PCCARDInitStruct->FMC_IOSpaceTimingStruct->FMC_HiZSetupTime = 252; +} + +/** + * @brief Enables or disables the PCCARD Memory Bank. + * @param NewState: new state of the PCCARD Memory Bank. + * This parameter can be: ENABLE or DISABLE. + * @retval None + */ +void FMC_PCCARDCmd(FunctionalState NewState) +{ + assert_param(IS_FUNCTIONAL_STATE(NewState)); + + if (NewState != DISABLE) + { + /* Enable the PCCARD Bank by setting the PBKEN bit in the PCR4 register */ + FMC_Bank4->PCR4 |= PCR_PBKEN_SET; + } + else + { + /* Disable the PCCARD Bank by clearing the PBKEN bit in the PCR4 register */ + FMC_Bank4->PCR4 &= PCR_PBKEN_RESET; + } +} + +/** + * @} + */ + +/** @defgroup FMC_Group4 SDRAM Controller functions + * @brief SDRAM Controller functions + * +@verbatim + =============================================================================== + ##### SDRAM Controller functions ##### + =============================================================================== + + [..] The following sequence should be followed to configure the FMC to interface + with SDRAM memory connected to the SDRAM Bank 1 or SDRAM bank 2: + + (#) Enable the clock for the FMC and associated GPIOs using the following functions: + (++) RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FMC, ENABLE); + (++) RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE); + + (#) FMC pins configuration + (++) Connect the involved FMC pins to AF12 using the following function + GPIO_PinAFConfig(GPIOx, GPIO_PinSourcex, GPIO_AF_FMC); + (++) Configure these FMC pins in alternate function mode by calling the function + GPIO_Init(); + + (#) Declare a FMC_SDRAMInitTypeDef structure, for example: + FMC_SDRAMInitTypeDef FMC_SDRAMInitStructure; + and fill the FMC_SDRAMInitStructure variable with the allowed values of + the structure member. + + (#) Initialize the SDRAM Controller by calling the function + FMC_SDRAMInit(&FMC_SDRAMInitStructure); + + (#) Declare a FMC_SDRAMCommandTypeDef structure, for example: + FMC_SDRAMCommandTypeDef FMC_SDRAMCommandStructure; + and fill the FMC_SDRAMCommandStructure variable with the allowed values of + the structure member. + + (#) Configure the SDCMR register with the desired command parameters by calling + the function FMC_SDRAMCmdConfig(&FMC_SDRAMCommandStructure); + + (#) At this stage, the SDRAM memory is ready for any valid command. + +@endverbatim + * @{ + */ + +/** + * @brief De-initializes the FMC SDRAM Banks registers to their default + * reset values. + * @param FMC_Bank: specifies the FMC Bank to be used + * This parameter can be one of the following values: + * @arg FMC_Bank1_SDRAM: FMC Bank1 SDRAM + * @arg FMC_Bank2_SDRAM: FMC Bank2 SDRAM + * @retval None + */ +void FMC_SDRAMDeInit(uint32_t FMC_Bank) +{ + /* Check the parameter */ + assert_param(IS_FMC_SDRAM_BANK(FMC_Bank)); + + FMC_Bank5_6->SDCR[FMC_Bank] = 0x000002D0; + FMC_Bank5_6->SDTR[FMC_Bank] = 0x0FFFFFFF; + FMC_Bank5_6->SDCMR = 0x00000000; + FMC_Bank5_6->SDRTR = 0x00000000; + FMC_Bank5_6->SDSR = 0x00000000; +} + +/** + * @brief Initializes the FMC SDRAM Banks according to the specified + * parameters in the FMC_SDRAMInitStruct. + * @param FMC_SDRAMInitStruct : pointer to a FMC_SDRAMInitTypeDef structure + * that contains the configuration information for the FMC SDRAM + * specified Banks. + * @retval None + */ +void FMC_SDRAMInit(FMC_SDRAMInitTypeDef* FMC_SDRAMInitStruct) +{ + /* temporary registers */ + uint32_t tmpr1 = 0; + uint32_t tmpr2 = 0; + uint32_t tmpr3 = 0; + uint32_t tmpr4 = 0; + + /* Check the parameters */ + + /* Control parameters */ + assert_param(IS_FMC_SDRAM_BANK(FMC_SDRAMInitStruct->FMC_Bank)); + assert_param(IS_FMC_COLUMNBITS_NUMBER(FMC_SDRAMInitStruct->FMC_ColumnBitsNumber)); + assert_param(IS_FMC_ROWBITS_NUMBER(FMC_SDRAMInitStruct->FMC_RowBitsNumber)); + assert_param(IS_FMC_SDMEMORY_WIDTH(FMC_SDRAMInitStruct->FMC_SDMemoryDataWidth)); + assert_param(IS_FMC_INTERNALBANK_NUMBER(FMC_SDRAMInitStruct->FMC_InternalBankNumber)); + assert_param(IS_FMC_CAS_LATENCY(FMC_SDRAMInitStruct->FMC_CASLatency)); + assert_param(IS_FMC_WRITE_PROTECTION(FMC_SDRAMInitStruct->FMC_WriteProtection)); + assert_param(IS_FMC_SDCLOCK_PERIOD(FMC_SDRAMInitStruct->FMC_SDClockPeriod)); + assert_param(IS_FMC_READ_BURST(FMC_SDRAMInitStruct->FMC_ReadBurst)); + assert_param(IS_FMC_READPIPE_DELAY(FMC_SDRAMInitStruct->FMC_ReadPipeDelay)); + + /* Timing parameters */ + assert_param(IS_FMC_LOADTOACTIVE_DELAY(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_LoadToActiveDelay)); + assert_param(IS_FMC_EXITSELFREFRESH_DELAY(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_ExitSelfRefreshDelay)); + assert_param(IS_FMC_SELFREFRESH_TIME(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_SelfRefreshTime)); + assert_param(IS_FMC_ROWCYCLE_DELAY(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RowCycleDelay)); + assert_param(IS_FMC_WRITE_RECOVERY_TIME(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_WriteRecoveryTime)); + assert_param(IS_FMC_RP_DELAY(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RPDelay)); + assert_param(IS_FMC_RCD_DELAY(FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RCDDelay)); + + /* SDRAM bank control register configuration */ + tmpr1 = (uint32_t)FMC_SDRAMInitStruct->FMC_ColumnBitsNumber | + FMC_SDRAMInitStruct->FMC_RowBitsNumber | + FMC_SDRAMInitStruct->FMC_SDMemoryDataWidth | + FMC_SDRAMInitStruct->FMC_InternalBankNumber | + FMC_SDRAMInitStruct->FMC_CASLatency | + FMC_SDRAMInitStruct->FMC_WriteProtection | + FMC_SDRAMInitStruct->FMC_SDClockPeriod | + FMC_SDRAMInitStruct->FMC_ReadBurst | + FMC_SDRAMInitStruct->FMC_ReadPipeDelay; + + if(FMC_SDRAMInitStruct->FMC_Bank == FMC_Bank1_SDRAM ) + { + FMC_Bank5_6->SDCR[FMC_SDRAMInitStruct->FMC_Bank] = tmpr1; + } + else /* SDCR2 "don't care" bits configuration */ + { + tmpr3 = (uint32_t)FMC_SDRAMInitStruct->FMC_SDClockPeriod | + FMC_SDRAMInitStruct->FMC_ReadBurst | + FMC_SDRAMInitStruct->FMC_ReadPipeDelay; + + FMC_Bank5_6->SDCR[FMC_Bank1_SDRAM] = tmpr3; + FMC_Bank5_6->SDCR[FMC_SDRAMInitStruct->FMC_Bank] = tmpr1; + } + /* SDRAM bank timing register configuration */ + if(FMC_SDRAMInitStruct->FMC_Bank == FMC_Bank1_SDRAM ) + { + tmpr2 = (uint32_t)((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_LoadToActiveDelay)-1) | + (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_ExitSelfRefreshDelay)-1) << 4) | + (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_SelfRefreshTime)-1) << 8) | + (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RowCycleDelay)-1) << 12) | + (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_WriteRecoveryTime)-1) << 16) | + (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RPDelay)-1) << 20) | + (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RCDDelay)-1) << 24); + + FMC_Bank5_6->SDTR[FMC_SDRAMInitStruct->FMC_Bank] = tmpr2; + } + else /* SDTR "don't care bits configuration */ + { + tmpr2 = (uint32_t)((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_LoadToActiveDelay)-1) | + (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_ExitSelfRefreshDelay)-1) << 4) | + (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_SelfRefreshTime)-1) << 8) | + (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_WriteRecoveryTime)-1) << 16); + + tmpr4 = (uint32_t)(((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RowCycleDelay)-1) << 12) | + (((FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RPDelay)-1) << 20); + + FMC_Bank5_6->SDTR[FMC_Bank1_SDRAM] = tmpr4; + FMC_Bank5_6->SDTR[FMC_SDRAMInitStruct->FMC_Bank] = tmpr2; + } + +} + +/** + * @brief Fills each FMC_SDRAMInitStruct member with its default value. + * @param FMC_SDRAMInitStruct: pointer to a FMC_SDRAMInitTypeDef structure + * which will be initialized. + * @retval None + */ +void FMC_SDRAMStructInit(FMC_SDRAMInitTypeDef* FMC_SDRAMInitStruct) +{ + /* Reset SDRAM Init structure parameters values */ + FMC_SDRAMInitStruct->FMC_Bank = FMC_Bank1_SDRAM; + FMC_SDRAMInitStruct->FMC_ColumnBitsNumber = FMC_ColumnBits_Number_8b; + FMC_SDRAMInitStruct->FMC_RowBitsNumber = FMC_RowBits_Number_11b; + FMC_SDRAMInitStruct->FMC_SDMemoryDataWidth = FMC_SDMemory_Width_16b; + FMC_SDRAMInitStruct->FMC_InternalBankNumber = FMC_InternalBank_Number_4; + FMC_SDRAMInitStruct->FMC_CASLatency = FMC_CAS_Latency_1; + FMC_SDRAMInitStruct->FMC_WriteProtection = FMC_Write_Protection_Enable; + FMC_SDRAMInitStruct->FMC_SDClockPeriod = FMC_SDClock_Disable; + FMC_SDRAMInitStruct->FMC_ReadBurst = FMC_Read_Burst_Disable; + FMC_SDRAMInitStruct->FMC_ReadPipeDelay = FMC_ReadPipe_Delay_0; + + FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_LoadToActiveDelay = 16; + FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_ExitSelfRefreshDelay = 16; + FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_SelfRefreshTime = 16; + FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RowCycleDelay = 16; + FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_WriteRecoveryTime = 16; + FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RPDelay = 16; + FMC_SDRAMInitStruct->FMC_SDRAMTimingStruct->FMC_RCDDelay = 16; + +} + +/** + * @brief Configures the SDRAM memory command issued when the device is accessed. + * @param FMC_SDRAMCommandStruct: pointer to a FMC_SDRAMCommandTypeDef structure + * which will be configured. + * @retval None + */ +void FMC_SDRAMCmdConfig(FMC_SDRAMCommandTypeDef* FMC_SDRAMCommandStruct) +{ + uint32_t tmpr = 0x0; + + /* check parameters */ + assert_param(IS_FMC_COMMAND_MODE(FMC_SDRAMCommandStruct->FMC_CommandMode)); + assert_param(IS_FMC_COMMAND_TARGET(FMC_SDRAMCommandStruct->FMC_CommandTarget)); + assert_param(IS_FMC_AUTOREFRESH_NUMBER(FMC_SDRAMCommandStruct->FMC_AutoRefreshNumber)); + assert_param(IS_FMC_MODE_REGISTER(FMC_SDRAMCommandStruct->FMC_ModeRegisterDefinition)); + + tmpr = (uint32_t)(FMC_SDRAMCommandStruct->FMC_CommandMode | + FMC_SDRAMCommandStruct->FMC_CommandTarget | + (((FMC_SDRAMCommandStruct->FMC_AutoRefreshNumber)-1)<<5) | + ((FMC_SDRAMCommandStruct->FMC_ModeRegisterDefinition)<<9)); + + FMC_Bank5_6->SDCMR = tmpr; + +} + + +/** + * @brief Returns the indicated FMC SDRAM bank mode status. + * @param SDRAM_Bank: Defines the FMC SDRAM bank. This parameter can be + * FMC_Bank1_SDRAM or FMC_Bank2_SDRAM. + * @retval The FMC SDRAM bank mode status + */ +uint32_t FMC_GetModeStatus(uint32_t SDRAM_Bank) +{ + uint32_t tmpreg = 0; + + /* Check the parameter */ + assert_param(IS_FMC_SDRAM_BANK(SDRAM_Bank)); + + /* Get the busy flag status */ + if(SDRAM_Bank == FMC_Bank1_SDRAM) + { + tmpreg = (uint32_t)(FMC_Bank5_6->SDSR & FMC_SDSR_MODES1); + } + else + { + tmpreg = ((uint32_t)(FMC_Bank5_6->SDSR & FMC_SDSR_MODES2) >> 2); + } + + /* Return the mode status */ + return tmpreg; +} + +/** + * @brief defines the SDRAM Memory Refresh rate. + * @param FMC_Count: specifies the Refresh timer count. + * @retval None + */ +void FMC_SetRefreshCount(uint32_t FMC_Count) +{ + /* check the parameters */ + assert_param(IS_FMC_REFRESH_COUNT(FMC_Count)); + + FMC_Bank5_6->SDRTR |= (FMC_Count<<1); + +} + +/** + * @brief Sets the Number of consecutive SDRAM Memory auto Refresh commands. + * @param FMC_Number: specifies the auto Refresh number. + * @retval None + */ +void FMC_SetAutoRefresh_Number(uint32_t FMC_Number) +{ + /* check the parameters */ + assert_param(IS_FMC_AUTOREFRESH_NUMBER(FMC_Number)); + + FMC_Bank5_6->SDCMR |= (FMC_Number << 5); +} + +/** + * @brief Enables or disables write protection to the specified FMC SDRAM Bank. + * @param SDRAM_Bank: Defines the FMC SDRAM bank. This parameter can be + * FMC_Bank1_SDRAM or FMC_Bank2_SDRAM. + * @param NewState: new state of the write protection flag. + * This parameter can be: ENABLE or DISABLE. + * @retval None + */ +void FMC_SDRAMWriteProtectionConfig(uint32_t SDRAM_Bank, FunctionalState NewState) +{ + /* Check the parameter */ + assert_param(IS_FUNCTIONAL_STATE(NewState)); + assert_param(IS_FMC_SDRAM_BANK(SDRAM_Bank)); + + if (NewState != DISABLE) + { + FMC_Bank5_6->SDCR[SDRAM_Bank] |= FMC_Write_Protection_Enable; + } + else + { + FMC_Bank5_6->SDCR[SDRAM_Bank] &= SDCR_WriteProtection_RESET; + } + +} + +/** + * @} + */ + +/** @defgroup FMC_Group5 Interrupts and flags management functions + * @brief Interrupts and flags management functions + * +@verbatim + =============================================================================== + ##### Interrupts and flags management functions ##### + =============================================================================== + +@endverbatim + * @{ + */ + +/** + * @brief Enables or disables the specified FMC interrupts. + * @param FMC_Bank: specifies the FMC Bank to be used + * This parameter can be one of the following values: + * @arg FMC_Bank2_NAND: FMC Bank2 NAND + * @arg FMC_Bank3_NAND: FMC Bank3 NAND + * @arg FMC_Bank4_PCCARD: FMC Bank4 PCCARD + * @arg FMC_Bank1_SDRAM: FMC Bank1 SDRAM + * @arg FMC_Bank2_SDRAM: FMC Bank2 SDRAM + * @param FMC_IT: specifies the FMC interrupt sources to be enabled or disabled. + * This parameter can be any combination of the following values: + * @arg FMC_IT_RisingEdge: Rising edge detection interrupt. + * @arg FMC_IT_Level: Level edge detection interrupt. + * @arg FMC_IT_FallingEdge: Falling edge detection interrupt. + * @arg FMC_IT_Refresh: Refresh error detection interrupt. + * @param NewState: new state of the specified FMC interrupts. + * This parameter can be: ENABLE or DISABLE. + * @retval None + */ +void FMC_ITConfig(uint32_t FMC_Bank, uint32_t FMC_IT, FunctionalState NewState) +{ + assert_param(IS_FMC_IT_BANK(FMC_Bank)); + assert_param(IS_FMC_IT(FMC_IT)); + assert_param(IS_FUNCTIONAL_STATE(NewState)); + + if (NewState != DISABLE) + { + /* Enable the selected FMC_Bank2 interrupts */ + if(FMC_Bank == FMC_Bank2_NAND) + { + FMC_Bank2->SR2 |= FMC_IT; + } + /* Enable the selected FMC_Bank3 interrupts */ + else if (FMC_Bank == FMC_Bank3_NAND) + { + FMC_Bank3->SR3 |= FMC_IT; + } + /* Enable the selected FMC_Bank4 interrupts */ + else if (FMC_Bank == FMC_Bank4_PCCARD) + { + FMC_Bank4->SR4 |= FMC_IT; + } + /* Enable the selected FMC_Bank5_6 interrupt */ + else + { + /* Enables the interrupt if the refresh error flag is set */ + FMC_Bank5_6->SDRTR |= FMC_IT; + } + } + else + { + /* Disable the selected FMC_Bank2 interrupts */ + if(FMC_Bank == FMC_Bank2_NAND) + { + + FMC_Bank2->SR2 &= (uint32_t)~FMC_IT; + } + /* Disable the selected FMC_Bank3 interrupts */ + else if (FMC_Bank == FMC_Bank3_NAND) + { + FMC_Bank3->SR3 &= (uint32_t)~FMC_IT; + } + /* Disable the selected FMC_Bank4 interrupts */ + else if(FMC_Bank == FMC_Bank4_PCCARD) + { + FMC_Bank4->SR4 &= (uint32_t)~FMC_IT; + } + /* Disable the selected FMC_Bank5_6 interrupt */ + else + { + /* Disables the interrupt if the refresh error flag is not set */ + FMC_Bank5_6->SDRTR &= (uint32_t)~FMC_IT; + } + } +} + +/** + * @brief Checks whether the specified FMC flag is set or not. + * @param FMC_Bank: specifies the FMC Bank to be used + * This parameter can be one of the following values: + * @arg FMC_Bank2_NAND: FMC Bank2 NAND + * @arg FMC_Bank3_NAND: FMC Bank3 NAND + * @arg FMC_Bank4_PCCARD: FMC Bank4 PCCARD + * @arg FMC_Bank1_SDRAM: FMC Bank1 SDRAM + * @arg FMC_Bank2_SDRAM: FMC Bank2 SDRAM + * @arg FMC_Bank1_SDRAM | FMC_Bank2_SDRAM: FMC Bank1 or Bank2 SDRAM + * @param FMC_FLAG: specifies the flag to check. + * This parameter can be one of the following values: + * @arg FMC_FLAG_RisingEdge: Rising edge detection Flag. + * @arg FMC_FLAG_Level: Level detection Flag. + * @arg FMC_FLAG_FallingEdge: Falling edge detection Flag. + * @arg FMC_FLAG_FEMPT: Fifo empty Flag. + * @arg FMC_FLAG_Refresh: Refresh error Flag. + * @arg FMC_FLAG_Busy: Busy status Flag. + * @retval The new state of FMC_FLAG (SET or RESET). + */ +FlagStatus FMC_GetFlagStatus(uint32_t FMC_Bank, uint32_t FMC_FLAG) +{ + FlagStatus bitstatus = RESET; + uint32_t tmpsr = 0x00000000; + + /* Check the parameters */ + assert_param(IS_FMC_GETFLAG_BANK(FMC_Bank)); + assert_param(IS_FMC_GET_FLAG(FMC_FLAG)); + + if(FMC_Bank == FMC_Bank2_NAND) + { + tmpsr = FMC_Bank2->SR2; + } + else if(FMC_Bank == FMC_Bank3_NAND) + { + tmpsr = FMC_Bank3->SR3; + } + else if(FMC_Bank == FMC_Bank4_PCCARD) + { + tmpsr = FMC_Bank4->SR4; + } + else + { + tmpsr = FMC_Bank5_6->SDSR; + } + + /* Get the flag status */ + if ((tmpsr & FMC_FLAG) != FMC_FLAG ) + { + bitstatus = RESET; + } + else + { + bitstatus = SET; + } + /* Return the flag status */ + return bitstatus; +} + +/** + * @brief Clears the FMC's pending flags. + * @param FMC_Bank: specifies the FMC Bank to be used + * This parameter can be one of the following values: + * @arg FMC_Bank2_NAND: FMC Bank2 NAND + * @arg FMC_Bank3_NAND: FMC Bank3 NAND + * @arg FMC_Bank4_PCCARD: FMC Bank4 PCCARD + * @arg FMC_Bank1_SDRAM: FMC Bank1 SDRAM + * @arg FMC_Bank2_SDRAM: FMC Bank2 SDRAM + * @param FMC_FLAG: specifies the flag to clear. + * This parameter can be any combination of the following values: + * @arg FMC_FLAG_RisingEdge: Rising edge detection Flag. + * @arg FMC_FLAG_Level: Level detection Flag. + * @arg FMC_FLAG_FallingEdge: Falling edge detection Flag. + * @arg FMC_FLAG_Refresh: Refresh error Flag. + * @retval None + */ +void FMC_ClearFlag(uint32_t FMC_Bank, uint32_t FMC_FLAG) +{ + /* Check the parameters */ + assert_param(IS_FMC_GETFLAG_BANK(FMC_Bank)); + assert_param(IS_FMC_CLEAR_FLAG(FMC_FLAG)) ; + + if(FMC_Bank == FMC_Bank2_NAND) + { + FMC_Bank2->SR2 &= (~FMC_FLAG); + } + else if(FMC_Bank == FMC_Bank3_NAND) + { + FMC_Bank3->SR3 &= (~FMC_FLAG); + } + else if(FMC_Bank == FMC_Bank4_PCCARD) + { + FMC_Bank4->SR4 &= (~FMC_FLAG); + } + /* FMC_Bank5_6 SDRAM*/ + else + { + FMC_Bank5_6->SDRTR &= (~FMC_FLAG); + } + +} + +/** + * @brief Checks whether the specified FMC interrupt has occurred or not. + * @param FMC_Bank: specifies the FMC Bank to be used + * This parameter can be one of the following values: + * @arg FMC_Bank2_NAND: FMC Bank2 NAND + * @arg FMC_Bank3_NAND: FMC Bank3 NAND + * @arg FMC_Bank4_PCCARD: FMC Bank4 PCCARD + * @arg FMC_Bank1_SDRAM: FMC Bank1 SDRAM + * @arg FMC_Bank2_SDRAM: FMC Bank2 SDRAM + * @param FMC_IT: specifies the FMC interrupt source to check. + * This parameter can be one of the following values: + * @arg FMC_IT_RisingEdge: Rising edge detection interrupt. + * @arg FMC_IT_Level: Level edge detection interrupt. + * @arg FMC_IT_FallingEdge: Falling edge detection interrupt. + * @arg FMC_IT_Refresh: Refresh error detection interrupt. + * @retval The new state of FMC_IT (SET or RESET). + */ +ITStatus FMC_GetITStatus(uint32_t FMC_Bank, uint32_t FMC_IT) +{ + ITStatus bitstatus = RESET; + uint32_t tmpsr = 0x0; + uint32_t tmpsr2 = 0x0; + uint32_t itstatus = 0x0; + uint32_t itenable = 0x0; + + /* Check the parameters */ + assert_param(IS_FMC_IT_BANK(FMC_Bank)); + assert_param(IS_FMC_GET_IT(FMC_IT)); + + if(FMC_Bank == FMC_Bank2_NAND) + { + tmpsr = FMC_Bank2->SR2; + } + else if(FMC_Bank == FMC_Bank3_NAND) + { + tmpsr = FMC_Bank3->SR3; + } + else if(FMC_Bank == FMC_Bank4_PCCARD) + { + tmpsr = FMC_Bank4->SR4; + } + /* FMC_Bank5_6 SDRAM*/ + else + { + tmpsr = FMC_Bank5_6->SDRTR; + tmpsr2 = FMC_Bank5_6->SDSR; + } + + /* get the IT enable bit status*/ + itenable = tmpsr & FMC_IT; + + /* get the corresponding IT Flag status*/ + if((FMC_Bank == FMC_Bank1_SDRAM) || (FMC_Bank == FMC_Bank2_SDRAM)) + { + itstatus = tmpsr2 & FMC_SDSR_RE; + } + else + { + itstatus = tmpsr & (FMC_IT >> 3); + } + + if ((itstatus != (uint32_t)RESET) && (itenable != (uint32_t)RESET)) + { + bitstatus = SET; + } + else + { + bitstatus = RESET; + } + return bitstatus; +} + +/** + * @brief Clears the FMC's interrupt pending bits. + * @param FMC_Bank: specifies the FMC Bank to be used + * This parameter can be one of the following values: + * @arg FMC_Bank2_NAND: FMC Bank2 NAND + * @arg FMC_Bank3_NAND: FMC Bank3 NAND + * @arg FMC_Bank4_PCCARD: FMC Bank4 PCCARD + * @arg FMC_Bank1_SDRAM: FMC Bank1 SDRAM + * @arg FMC_Bank2_SDRAM: FMC Bank2 SDRAM + * @param FMC_IT: specifies the interrupt pending bit to clear. + * This parameter can be any combination of the following values: + * @arg FMC_IT_RisingEdge: Rising edge detection interrupt. + * @arg FMC_IT_Level: Level edge detection interrupt. + * @arg FMC_IT_FallingEdge: Falling edge detection interrupt. + * @arg FMC_IT_Refresh: Refresh error detection interrupt. + * @retval None + */ +void FMC_ClearITPendingBit(uint32_t FMC_Bank, uint32_t FMC_IT) +{ + /* Check the parameters */ + assert_param(IS_FMC_IT_BANK(FMC_Bank)); + assert_param(IS_FMC_IT(FMC_IT)); + + if(FMC_Bank == FMC_Bank2_NAND) + { + FMC_Bank2->SR2 &= ~(FMC_IT >> 3); + } + else if(FMC_Bank == FMC_Bank3_NAND) + { + FMC_Bank3->SR3 &= ~(FMC_IT >> 3); + } + else if(FMC_Bank == FMC_Bank4_PCCARD) + { + FMC_Bank4->SR4 &= ~(FMC_IT >> 3); + } + /* FMC_Bank5_6 SDRAM*/ + else + { + FMC_Bank5_6->SDRTR |= FMC_SDRTR_CRE; + } +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/boards/base/STM32F429i-Discovery/stm32f4xx_fmc.h b/boards/base/STM32F429i-Discovery/stm32f4xx_fmc.h new file mode 100644 index 00000000..3764c794 --- /dev/null +++ b/boards/base/STM32F429i-Discovery/stm32f4xx_fmc.h @@ -0,0 +1,1140 @@ +/** + ****************************************************************************** + * @file stm32f4xx_fmc.h + * @author MCD Application Team + * @version V1.2.1 + * @date 19-September-2013 + * @brief This file contains all the functions prototypes for the FMC firmware + * library. + ****************************************************************************** + * @attention + * + * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS + * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE + * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY + * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING + * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE + * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. + * + *

    © COPYRIGHT 2011 STMicroelectronics

    + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __STM32F4xx_FMC_H +#define __STM32F4xx_FMC_H + +#ifdef __cplusplus + extern "C" { +#endif + +//FIXME this should not be needed +#define STM32F429_439xx + +/* Includes ------------------------------------------------------------------*/ +#include "stm32f4xx.h" + +/** @addtogroup STM32F4xx_StdPeriph_Driver + * @{ + */ + +/** @addtogroup FMC + * @{ + */ + +/* Exported types ------------------------------------------------------------*/ + +/** + * @brief Timing parameters For NOR/SRAM Banks + */ +typedef struct +{ + uint32_t FMC_AddressSetupTime; /*!< Defines the number of HCLK cycles to configure + the duration of the address setup time. + This parameter can be a value between 0 and 15. + @note This parameter is not used with synchronous NOR Flash memories. */ + + uint32_t FMC_AddressHoldTime; /*!< Defines the number of HCLK cycles to configure + the duration of the address hold time. + This parameter can be a value between 1 and 15. + @note This parameter is not used with synchronous NOR Flash memories.*/ + + uint32_t FMC_DataSetupTime; /*!< Defines the number of HCLK cycles to configure + the duration of the data setup time. + This parameter can be a value between 1 and 255. + @note This parameter is used for SRAMs, ROMs and asynchronous multiplexed NOR Flash memories. */ + + uint32_t FMC_BusTurnAroundDuration; /*!< Defines the number of HCLK cycles to configure + the duration of the bus turnaround. + This parameter can be a value between 0 and 15. + @note This parameter is only used for multiplexed NOR Flash memories. */ + + uint32_t FMC_CLKDivision; /*!< Defines the period of CLK clock output signal, expressed in number of HCLK cycles. + This parameter can be a value between 1 and 15. + @note This parameter is not used for asynchronous NOR Flash, SRAM or ROM accesses. */ + + uint32_t FMC_DataLatency; /*!< Defines the number of memory clock cycles to issue + to the memory before getting the first data. + The parameter value depends on the memory type as shown below: + - It must be set to 0 in case of a CRAM + - It is don't care in asynchronous NOR, SRAM or ROM accesses + - It may assume a value between 0 and 15 in NOR Flash memories + with synchronous burst mode enable */ + + uint32_t FMC_AccessMode; /*!< Specifies the asynchronous access mode. + This parameter can be a value of @ref FMC_Access_Mode */ +}FMC_NORSRAMTimingInitTypeDef; + +/** + * @brief FMC NOR/SRAM Init structure definition + */ +typedef struct +{ + uint32_t FMC_Bank; /*!< Specifies the NOR/SRAM memory bank that will be used. + This parameter can be a value of @ref FMC_NORSRAM_Bank */ + + uint32_t FMC_DataAddressMux; /*!< Specifies whether the address and data values are + multiplexed on the databus or not. + This parameter can be a value of @ref FMC_Data_Address_Bus_Multiplexing */ + + uint32_t FMC_MemoryType; /*!< Specifies the type of external memory attached to + the corresponding memory bank. + This parameter can be a value of @ref FMC_Memory_Type */ + + uint32_t FMC_MemoryDataWidth; /*!< Specifies the external memory device width. + This parameter can be a value of @ref FMC_NORSRAM_Data_Width */ + + uint32_t FMC_BurstAccessMode; /*!< Enables or disables the burst access mode for Flash memory, + valid only with synchronous burst Flash memories. + This parameter can be a value of @ref FMC_Burst_Access_Mode */ + + uint32_t FMC_WaitSignalPolarity; /*!< Specifies the wait signal polarity, valid only when accessing + the Flash memory in burst mode. + This parameter can be a value of @ref FMC_Wait_Signal_Polarity */ + + uint32_t FMC_WrapMode; /*!< Enables or disables the Wrapped burst access mode for Flash + memory, valid only when accessing Flash memories in burst mode. + This parameter can be a value of @ref FMC_Wrap_Mode */ + + uint32_t FMC_WaitSignalActive; /*!< Specifies if the wait signal is asserted by the memory one + clock cycle before the wait state or during the wait state, + valid only when accessing memories in burst mode. + This parameter can be a value of @ref FMC_Wait_Timing */ + + uint32_t FMC_WriteOperation; /*!< Enables or disables the write operation in the selected bank by the FMC. + This parameter can be a value of @ref FMC_Write_Operation */ + + uint32_t FMC_WaitSignal; /*!< Enables or disables the wait state insertion via wait + signal, valid for Flash memory access in burst mode. + This parameter can be a value of @ref FMC_Wait_Signal */ + + uint32_t FMC_ExtendedMode; /*!< Enables or disables the extended mode. + This parameter can be a value of @ref FMC_Extended_Mode */ + + uint32_t FMC_AsynchronousWait; /*!< Enables or disables wait signal during asynchronous transfers, + valid only with asynchronous Flash memories. + This parameter can be a value of @ref FMC_AsynchronousWait */ + + uint32_t FMC_WriteBurst; /*!< Enables or disables the write burst operation. + This parameter can be a value of @ref FMC_Write_Burst */ + + uint32_t FMC_ContinousClock; /*!< Enables or disables the FMC clock output to external memory devices. + This parameter is only enabled through the FMC_BCR1 register, and don't care + through FMC_BCR2..4 registers. + This parameter can be a value of @ref FMC_Continous_Clock */ + + + FMC_NORSRAMTimingInitTypeDef* FMC_ReadWriteTimingStruct; /*!< Timing Parameters for write and read access if the Extended Mode is not used*/ + + FMC_NORSRAMTimingInitTypeDef* FMC_WriteTimingStruct; /*!< Timing Parameters for write access if the Extended Mode is used*/ +}FMC_NORSRAMInitTypeDef; + +/** + * @brief Timing parameters For FMC NAND and PCCARD Banks + */ +typedef struct +{ + uint32_t FMC_SetupTime; /*!< Defines the number of HCLK cycles to setup address before + the command assertion for NAND-Flash read or write access + to common/Attribute or I/O memory space (depending on + the memory space timing to be configured). + This parameter can be a value between 0 and 255.*/ + + uint32_t FMC_WaitSetupTime; /*!< Defines the minimum number of HCLK cycles to assert the + command for NAND-Flash read or write access to + common/Attribute or I/O memory space (depending on the + memory space timing to be configured). + This parameter can be a number between 0 and 255 */ + + uint32_t FMC_HoldSetupTime; /*!< Defines the number of HCLK clock cycles to hold address + (and data for write access) after the command de-assertion + for NAND-Flash read or write access to common/Attribute + or I/O memory space (depending on the memory space timing + to be configured). + This parameter can be a number between 0 and 255 */ + + uint32_t FMC_HiZSetupTime; /*!< Defines the number of HCLK clock cycles during which the + databus is kept in HiZ after the start of a NAND-Flash + write access to common/Attribute or I/O memory space (depending + on the memory space timing to be configured). + This parameter can be a number between 0 and 255 */ +}FMC_NAND_PCCARDTimingInitTypeDef; + +/** + * @brief FMC NAND Init structure definition + */ +typedef struct +{ + uint32_t FMC_Bank; /*!< Specifies the NAND memory bank that will be used. + This parameter can be a value of @ref FMC_NAND_Bank */ + + uint32_t FMC_Waitfeature; /*!< Enables or disables the Wait feature for the NAND Memory Bank. + This parameter can be any value of @ref FMC_Wait_feature */ + + uint32_t FMC_MemoryDataWidth; /*!< Specifies the external memory device width. + This parameter can be any value of @ref FMC_NAND_Data_Width */ + + uint32_t FMC_ECC; /*!< Enables or disables the ECC computation. + This parameter can be any value of @ref FMC_ECC */ + + uint32_t FMC_ECCPageSize; /*!< Defines the page size for the extended ECC. + This parameter can be any value of @ref FMC_ECC_Page_Size */ + + uint32_t FMC_TCLRSetupTime; /*!< Defines the number of HCLK cycles to configure the + delay between CLE low and RE low. + This parameter can be a value between 0 and 255. */ + + uint32_t FMC_TARSetupTime; /*!< Defines the number of HCLK cycles to configure the + delay between ALE low and RE low. + This parameter can be a number between 0 and 255 */ + + FMC_NAND_PCCARDTimingInitTypeDef* FMC_CommonSpaceTimingStruct; /*!< FMC Common Space Timing */ + + FMC_NAND_PCCARDTimingInitTypeDef* FMC_AttributeSpaceTimingStruct; /*!< FMC Attribute Space Timing */ +}FMC_NANDInitTypeDef; + +/** + * @brief FMC PCCARD Init structure definition + */ + +typedef struct +{ + uint32_t FMC_Waitfeature; /*!< Enables or disables the Wait feature for the Memory Bank. + This parameter can be any value of @ref FMC_Wait_feature */ + + uint32_t FMC_TCLRSetupTime; /*!< Defines the number of HCLK cycles to configure the + delay between CLE low and RE low. + This parameter can be a value between 0 and 255. */ + + uint32_t FMC_TARSetupTime; /*!< Defines the number of HCLK cycles to configure the + delay between ALE low and RE low. + This parameter can be a number between 0 and 255 */ + + + FMC_NAND_PCCARDTimingInitTypeDef* FMC_CommonSpaceTimingStruct; /*!< FMC Common Space Timing */ + + FMC_NAND_PCCARDTimingInitTypeDef* FMC_AttributeSpaceTimingStruct; /*!< FMC Attribute Space Timing */ + + FMC_NAND_PCCARDTimingInitTypeDef* FMC_IOSpaceTimingStruct; /*!< FMC IO Space Timing */ +}FMC_PCCARDInitTypeDef; + +/** + * @brief Timing parameters for FMC SDRAM Banks + */ + +typedef struct +{ + uint32_t FMC_LoadToActiveDelay; /*!< Defines the delay between a Load Mode Register command and + an active or Refresh command in number of memory clock cycles. + This parameter can be a value between 1 and 16. */ + + uint32_t FMC_ExitSelfRefreshDelay; /*!< Defines the delay from releasing the self refresh command to + issuing the Activate command in number of memory clock cycles. + This parameter can be a value between 1 and 16. */ + + uint32_t FMC_SelfRefreshTime; /*!< Defines the minimum Self Refresh period in number of memory clock + cycles. + This parameter can be a value between 1 and 16. */ + + uint32_t FMC_RowCycleDelay; /*!< Defines the delay between the Refresh command and the Activate command + and the delay between two consecutive Refresh commands in number of + memory clock cycles. + This parameter can be a value between 1 and 16. */ + + uint32_t FMC_WriteRecoveryTime; /*!< Defines the Write recovery Time in number of memory clock cycles. + This parameter can be a value between 1 and 16. */ + + uint32_t FMC_RPDelay; /*!< Defines the delay between a Precharge Command and an other command + in number of memory clock cycles. + This parameter can be a value between 1 and 16. */ + + uint32_t FMC_RCDDelay; /*!< Defines the delay between the Activate Command and a Read/Write command + in number of memory clock cycles. + This parameter can be a value between 1 and 16. */ + +}FMC_SDRAMTimingInitTypeDef; + +/** + * @brief Command parameters for FMC SDRAM Banks + */ + + +typedef struct +{ + uint32_t FMC_CommandMode; /*!< Defines the command issued to the SDRAM device. + This parameter can be a value of @ref FMC_Command_Mode. */ + + uint32_t FMC_CommandTarget; /*!< Defines which bank (1 or 2) the command will be issued to. + This parameter can be a value of @ref FMC_Command_Target. */ + + uint32_t FMC_AutoRefreshNumber; /*!< Defines the number of consecutive auto refresh command issued + in auto refresh mode. + This parameter can be a value between 1 and 16. */ + + uint32_t FMC_ModeRegisterDefinition; /*!< Defines the SDRAM Mode register content */ + +}FMC_SDRAMCommandTypeDef; + +/** + * @brief FMC SDRAM Init structure definition + */ + +typedef struct +{ + uint32_t FMC_Bank; /*!< Specifies the SDRAM memory bank that will be used. + This parameter can be a value of @ref FMC_SDRAM_Bank */ + + uint32_t FMC_ColumnBitsNumber; /*!< Defines the number of bits of column address. + This parameter can be a value of @ref FMC_ColumnBits_Number. */ + + uint32_t FMC_RowBitsNumber; /*!< Defines the number of bits of column address.. + This parameter can be a value of @ref FMC_RowBits_Number. */ + + uint32_t FMC_SDMemoryDataWidth; /*!< Defines the memory device width. + This parameter can be a value of @ref FMC_SDMemory_Data_Width. */ + + uint32_t FMC_InternalBankNumber; /*!< Defines the number of bits of column address. + This parameter can be of @ref FMC_InternalBank_Number. */ + + uint32_t FMC_CASLatency; /*!< Defines the SDRAM CAS latency in number of memory clock cycles. + This parameter can be a value of @ref FMC_CAS_Latency. */ + + uint32_t FMC_WriteProtection; /*!< Enables the SDRAM bank to be accessed in write mode. + This parameter can be a value of @ref FMC_Write_Protection. */ + + uint32_t FMC_SDClockPeriod; /*!< Define the SDRAM Clock Period for both SDRAM Banks and they allow to disable + the clock before changing frequency. + This parameter can be a value of @ref FMC_SDClock_Period. */ + + uint32_t FMC_ReadBurst; /*!< This bit enable the SDRAM controller to anticipate the next read commands + during the CAS latency and stores data in the Read FIFO. + This parameter can be a value of @ref FMC_Read_Burst. */ + + uint32_t FMC_ReadPipeDelay; /*!< Define the delay in system clock cycles on read data path. + This parameter can be a value of @ref FMC_ReadPipe_Delay. */ + + FMC_SDRAMTimingInitTypeDef* FMC_SDRAMTimingStruct; /*!< Timing Parameters for write and read access*/ + +}FMC_SDRAMInitTypeDef; + + +/* Exported constants --------------------------------------------------------*/ + +/** @defgroup FMC_Exported_Constants + * @{ + */ + +/** @defgroup FMC_NORSRAM_Bank + * @{ + */ +#define FMC_Bank1_NORSRAM1 ((uint32_t)0x00000000) +#define FMC_Bank1_NORSRAM2 ((uint32_t)0x00000002) +#define FMC_Bank1_NORSRAM3 ((uint32_t)0x00000004) +#define FMC_Bank1_NORSRAM4 ((uint32_t)0x00000006) + +#define IS_FMC_NORSRAM_BANK(BANK) (((BANK) == FMC_Bank1_NORSRAM1) || \ + ((BANK) == FMC_Bank1_NORSRAM2) || \ + ((BANK) == FMC_Bank1_NORSRAM3) || \ + ((BANK) == FMC_Bank1_NORSRAM4)) +/** + * @} + */ + +/** @defgroup FMC_NAND_Bank + * @{ + */ +#define FMC_Bank2_NAND ((uint32_t)0x00000010) +#define FMC_Bank3_NAND ((uint32_t)0x00000100) + +#define IS_FMC_NAND_BANK(BANK) (((BANK) == FMC_Bank2_NAND) || \ + ((BANK) == FMC_Bank3_NAND)) +/** + * @} + */ + +/** @defgroup FMC_PCCARD_Bank + * @{ + */ +#define FMC_Bank4_PCCARD ((uint32_t)0x00001000) +/** + * @} + */ + +/** @defgroup FMC_SDRAM_Bank + * @{ + */ +#define FMC_Bank1_SDRAM ((uint32_t)0x00000000) +#define FMC_Bank2_SDRAM ((uint32_t)0x00000001) + +#define IS_FMC_SDRAM_BANK(BANK) (((BANK) == FMC_Bank1_SDRAM) || \ + ((BANK) == FMC_Bank2_SDRAM)) + +/** + * @} + */ + + +/** @defgroup FMC_NOR_SRAM_Controller + * @{ + */ + +/** @defgroup FMC_Data_Address_Bus_Multiplexing + * @{ + */ + +#define FMC_DataAddressMux_Disable ((uint32_t)0x00000000) +#define FMC_DataAddressMux_Enable ((uint32_t)0x00000002) + +#define IS_FMC_MUX(MUX) (((MUX) == FMC_DataAddressMux_Disable) || \ + ((MUX) == FMC_DataAddressMux_Enable)) +/** + * @} + */ + +/** @defgroup FMC_Memory_Type + * @{ + */ + +#define FMC_MemoryType_SRAM ((uint32_t)0x00000000) +#define FMC_MemoryType_PSRAM ((uint32_t)0x00000004) +#define FMC_MemoryType_NOR ((uint32_t)0x00000008) + +#define IS_FMC_MEMORY(MEMORY) (((MEMORY) == FMC_MemoryType_SRAM) || \ + ((MEMORY) == FMC_MemoryType_PSRAM)|| \ + ((MEMORY) == FMC_MemoryType_NOR)) +/** + * @} + */ + +/** @defgroup FMC_NORSRAM_Data_Width + * @{ + */ + +#define FMC_NORSRAM_MemoryDataWidth_8b ((uint32_t)0x00000000) +#define FMC_NORSRAM_MemoryDataWidth_16b ((uint32_t)0x00000010) +#define FMC_NORSRAM_MemoryDataWidth_32b ((uint32_t)0x00000020) + +#define IS_FMC_NORSRAM_MEMORY_WIDTH(WIDTH) (((WIDTH) == FMC_NORSRAM_MemoryDataWidth_8b) || \ + ((WIDTH) == FMC_NORSRAM_MemoryDataWidth_16b) || \ + ((WIDTH) == FMC_NORSRAM_MemoryDataWidth_32b)) +/** + * @} + */ + +/** @defgroup FMC_Burst_Access_Mode + * @{ + */ + +#define FMC_BurstAccessMode_Disable ((uint32_t)0x00000000) +#define FMC_BurstAccessMode_Enable ((uint32_t)0x00000100) + +#define IS_FMC_BURSTMODE(STATE) (((STATE) == FMC_BurstAccessMode_Disable) || \ + ((STATE) == FMC_BurstAccessMode_Enable)) +/** + * @} + */ + +/** @defgroup FMC_AsynchronousWait + * @{ + */ +#define FMC_AsynchronousWait_Disable ((uint32_t)0x00000000) +#define FMC_AsynchronousWait_Enable ((uint32_t)0x00008000) + +#define IS_FMC_ASYNWAIT(STATE) (((STATE) == FMC_AsynchronousWait_Disable) || \ + ((STATE) == FMC_AsynchronousWait_Enable)) +/** + * @} + */ + +/** @defgroup FMC_Wait_Signal_Polarity + * @{ + */ +#define FMC_WaitSignalPolarity_Low ((uint32_t)0x00000000) +#define FMC_WaitSignalPolarity_High ((uint32_t)0x00000200) + +#define IS_FMC_WAIT_POLARITY(POLARITY) (((POLARITY) == FMC_WaitSignalPolarity_Low) || \ + ((POLARITY) == FMC_WaitSignalPolarity_High)) +/** + * @} + */ + +/** @defgroup FMC_Wrap_Mode + * @{ + */ +#define FMC_WrapMode_Disable ((uint32_t)0x00000000) +#define FMC_WrapMode_Enable ((uint32_t)0x00000400) + +#define IS_FMC_WRAP_MODE(MODE) (((MODE) == FMC_WrapMode_Disable) || \ + ((MODE) == FMC_WrapMode_Enable)) +/** + * @} + */ + +/** @defgroup FMC_Wait_Timing + * @{ + */ +#define FMC_WaitSignalActive_BeforeWaitState ((uint32_t)0x00000000) +#define FMC_WaitSignalActive_DuringWaitState ((uint32_t)0x00000800) + +#define IS_FMC_WAIT_SIGNAL_ACTIVE(ACTIVE) (((ACTIVE) == FMC_WaitSignalActive_BeforeWaitState) || \ + ((ACTIVE) == FMC_WaitSignalActive_DuringWaitState)) +/** + * @} + */ + +/** @defgroup FMC_Write_Operation + * @{ + */ +#define FMC_WriteOperation_Disable ((uint32_t)0x00000000) +#define FMC_WriteOperation_Enable ((uint32_t)0x00001000) + +#define IS_FMC_WRITE_OPERATION(OPERATION) (((OPERATION) == FMC_WriteOperation_Disable) || \ + ((OPERATION) == FMC_WriteOperation_Enable)) +/** + * @} + */ + +/** @defgroup FMC_Wait_Signal + * @{ + */ +#define FMC_WaitSignal_Disable ((uint32_t)0x00000000) +#define FMC_WaitSignal_Enable ((uint32_t)0x00002000) + +#define IS_FMC_WAITE_SIGNAL(SIGNAL) (((SIGNAL) == FMC_WaitSignal_Disable) || \ + ((SIGNAL) == FMC_WaitSignal_Enable)) +/** + * @} + */ + +/** @defgroup FMC_Extended_Mode + * @{ + */ +#define FMC_ExtendedMode_Disable ((uint32_t)0x00000000) +#define FMC_ExtendedMode_Enable ((uint32_t)0x00004000) + +#define IS_FMC_EXTENDED_MODE(MODE) (((MODE) == FMC_ExtendedMode_Disable) || \ + ((MODE) == FMC_ExtendedMode_Enable)) +/** + * @} + */ + +/** @defgroup FMC_Write_Burst + * @{ + */ + +#define FMC_WriteBurst_Disable ((uint32_t)0x00000000) +#define FMC_WriteBurst_Enable ((uint32_t)0x00080000) + +#define IS_FMC_WRITE_BURST(BURST) (((BURST) == FMC_WriteBurst_Disable) || \ + ((BURST) == FMC_WriteBurst_Enable)) +/** + * @} + */ + +/** @defgroup FMC_Continous_Clock + * @{ + */ + +#define FMC_CClock_SyncOnly ((uint32_t)0x00000000) +#define FMC_CClock_SyncAsync ((uint32_t)0x00100000) + +#define IS_FMC_CONTINOUS_CLOCK(CCLOCK) (((CCLOCK) == FMC_CClock_SyncOnly) || \ + ((CCLOCK) == FMC_CClock_SyncAsync)) +/** + * @} + */ + +/** @defgroup FMC_Address_Setup_Time + * @{ + */ +#define IS_FMC_ADDRESS_SETUP_TIME(TIME) ((TIME) <= 15) +/** + * @} + */ + +/** @defgroup FMC_Address_Hold_Time + * @{ + */ +#define IS_FMC_ADDRESS_HOLD_TIME(TIME) (((TIME) > 0) && ((TIME) <= 15)) +/** + * @} + */ + +/** @defgroup FMC_Data_Setup_Time + * @{ + */ +#define IS_FMC_DATASETUP_TIME(TIME) (((TIME) > 0) && ((TIME) <= 255)) +/** + * @} + */ + +/** @defgroup FMC_Bus_Turn_around_Duration + * @{ + */ +#define IS_FMC_TURNAROUND_TIME(TIME) ((TIME) <= 15) +/** + * @} + */ + +/** @defgroup FMC_CLK_Division + * @{ + */ +#define IS_FMC_CLK_DIV(DIV) (((DIV) > 0) && ((DIV) <= 15)) +/** + * @} + */ + +/** @defgroup FMC_Data_Latency + * @{ + */ +#define IS_FMC_DATA_LATENCY(LATENCY) ((LATENCY) <= 15) +/** + * @} + */ + +/** @defgroup FMC_Access_Mode + * @{ + */ +#define FMC_AccessMode_A ((uint32_t)0x00000000) +#define FMC_AccessMode_B ((uint32_t)0x10000000) +#define FMC_AccessMode_C ((uint32_t)0x20000000) +#define FMC_AccessMode_D ((uint32_t)0x30000000) + +#define IS_FMC_ACCESS_MODE(MODE) (((MODE) == FMC_AccessMode_A) || \ + ((MODE) == FMC_AccessMode_B) || \ + ((MODE) == FMC_AccessMode_C) || \ + ((MODE) == FMC_AccessMode_D)) +/** + * @} + */ + +/** + * @} + */ + +/** @defgroup FMC_NAND_PCCARD_Controller + * @{ + */ + +/** @defgroup FMC_Wait_feature + * @{ + */ +#define FMC_Waitfeature_Disable ((uint32_t)0x00000000) +#define FMC_Waitfeature_Enable ((uint32_t)0x00000002) + +#define IS_FMC_WAIT_FEATURE(FEATURE) (((FEATURE) == FMC_Waitfeature_Disable) || \ + ((FEATURE) == FMC_Waitfeature_Enable)) +/** + * @} + */ + +/** @defgroup FMC_NAND_Data_Width + * @{ + */ +#define FMC_NAND_MemoryDataWidth_8b ((uint32_t)0x00000000) +#define FMC_NAND_MemoryDataWidth_16b ((uint32_t)0x00000010) + +#define IS_FMC_NAND_MEMORY_WIDTH(WIDTH) (((WIDTH) == FMC_NAND_MemoryDataWidth_8b) || \ + ((WIDTH) == FMC_NAND_MemoryDataWidth_16b)) +/** + * @} + */ + +/** @defgroup FMC_ECC + * @{ + */ +#define FMC_ECC_Disable ((uint32_t)0x00000000) +#define FMC_ECC_Enable ((uint32_t)0x00000040) + +#define IS_FMC_ECC_STATE(STATE) (((STATE) == FMC_ECC_Disable) || \ + ((STATE) == FMC_ECC_Enable)) +/** + * @} + */ + +/** @defgroup FMC_ECC_Page_Size + * @{ + */ +#define FMC_ECCPageSize_256Bytes ((uint32_t)0x00000000) +#define FMC_ECCPageSize_512Bytes ((uint32_t)0x00020000) +#define FMC_ECCPageSize_1024Bytes ((uint32_t)0x00040000) +#define FMC_ECCPageSize_2048Bytes ((uint32_t)0x00060000) +#define FMC_ECCPageSize_4096Bytes ((uint32_t)0x00080000) +#define FMC_ECCPageSize_8192Bytes ((uint32_t)0x000A0000) + +#define IS_FMC_ECCPAGE_SIZE(SIZE) (((SIZE) == FMC_ECCPageSize_256Bytes) || \ + ((SIZE) == FMC_ECCPageSize_512Bytes) || \ + ((SIZE) == FMC_ECCPageSize_1024Bytes) || \ + ((SIZE) == FMC_ECCPageSize_2048Bytes) || \ + ((SIZE) == FMC_ECCPageSize_4096Bytes) || \ + ((SIZE) == FMC_ECCPageSize_8192Bytes)) +/** + * @} + */ + +/** @defgroup FMC_TCLR_Setup_Time + * @{ + */ +#define IS_FMC_TCLR_TIME(TIME) ((TIME) <= 255) +/** + * @} + */ + +/** @defgroup FMC_TAR_Setup_Time + * @{ + */ +#define IS_FMC_TAR_TIME(TIME) ((TIME) <= 255) +/** + * @} + */ + +/** @defgroup FMC_Setup_Time + * @{ + */ +#define IS_FMC_SETUP_TIME(TIME) ((TIME) <= 255) +/** + * @} + */ + +/** @defgroup FMC_Wait_Setup_Time + * @{ + */ +#define IS_FMC_WAIT_TIME(TIME) ((TIME) <= 255) +/** + * @} + */ + +/** @defgroup FMC_Hold_Setup_Time + * @{ + */ +#define IS_FMC_HOLD_TIME(TIME) ((TIME) <= 255) +/** + * @} + */ + +/** @defgroup FMC_HiZ_Setup_Time + * @{ + */ +#define IS_FMC_HIZ_TIME(TIME) ((TIME) <= 255) +/** + * @} + */ + +/** + * @} + */ + + +/** @defgroup FMC_NOR_SRAM_Controller + * @{ + */ + +/** @defgroup FMC_ColumnBits_Number + * @{ + */ +#define FMC_ColumnBits_Number_8b ((uint32_t)0x00000000) +#define FMC_ColumnBits_Number_9b ((uint32_t)0x00000001) +#define FMC_ColumnBits_Number_10b ((uint32_t)0x00000002) +#define FMC_ColumnBits_Number_11b ((uint32_t)0x00000003) + +#define IS_FMC_COLUMNBITS_NUMBER(COLUMN) (((COLUMN) == FMC_ColumnBits_Number_8b) || \ + ((COLUMN) == FMC_ColumnBits_Number_9b) || \ + ((COLUMN) == FMC_ColumnBits_Number_10b) || \ + ((COLUMN) == FMC_ColumnBits_Number_11b)) + +/** + * @} + */ + +/** @defgroup FMC_RowBits_Number + * @{ + */ +#define FMC_RowBits_Number_11b ((uint32_t)0x00000000) +#define FMC_RowBits_Number_12b ((uint32_t)0x00000004) +#define FMC_RowBits_Number_13b ((uint32_t)0x00000008) + +#define IS_FMC_ROWBITS_NUMBER(ROW) (((ROW) == FMC_RowBits_Number_11b) || \ + ((ROW) == FMC_RowBits_Number_12b) || \ + ((ROW) == FMC_RowBits_Number_13b)) + +/** + * @} + */ + +/** @defgroup FMC_SDMemory_Data_Width + * @{ + */ +#define FMC_SDMemory_Width_8b ((uint32_t)0x00000000) +#define FMC_SDMemory_Width_16b ((uint32_t)0x00000010) +#define FMC_SDMemory_Width_32b ((uint32_t)0x00000020) + +#define IS_FMC_SDMEMORY_WIDTH(WIDTH) (((WIDTH) == FMC_SDMemory_Width_8b) || \ + ((WIDTH) == FMC_SDMemory_Width_16b) || \ + ((WIDTH) == FMC_SDMemory_Width_32b)) + +/** + * @} + */ + +/** @defgroup FMC_InternalBank_Number + * @{ + */ +#define FMC_InternalBank_Number_2 ((uint32_t)0x00000000) +#define FMC_InternalBank_Number_4 ((uint32_t)0x00000040) + +#define IS_FMC_INTERNALBANK_NUMBER(NUMBER) (((NUMBER) == FMC_InternalBank_Number_2) || \ + ((NUMBER) == FMC_InternalBank_Number_4)) + +/** + * @} + */ + + +/** @defgroup FMC_CAS_Latency + * @{ + */ +#define FMC_CAS_Latency_1 ((uint32_t)0x00000080) +#define FMC_CAS_Latency_2 ((uint32_t)0x00000100) +#define FMC_CAS_Latency_3 ((uint32_t)0x00000180) + +#define IS_FMC_CAS_LATENCY(LATENCY) (((LATENCY) == FMC_CAS_Latency_1) || \ + ((LATENCY) == FMC_CAS_Latency_2) || \ + ((LATENCY) == FMC_CAS_Latency_3)) + +/** + * @} + */ + +/** @defgroup FMC_Write_Protection + * @{ + */ +#define FMC_Write_Protection_Disable ((uint32_t)0x00000000) +#define FMC_Write_Protection_Enable ((uint32_t)0x00000200) + +#define IS_FMC_WRITE_PROTECTION(WRITE) (((WRITE) == FMC_Write_Protection_Disable) || \ + ((WRITE) == FMC_Write_Protection_Enable)) + +/** + * @} + */ + + +/** @defgroup FMC_SDClock_Period + * @{ + */ +#define FMC_SDClock_Disable ((uint32_t)0x00000000) +#define FMC_SDClock_Period_2 ((uint32_t)0x00000800) +#define FMC_SDClock_Period_3 ((uint32_t)0x00000C00) + +#define IS_FMC_SDCLOCK_PERIOD(PERIOD) (((PERIOD) == FMC_SDClock_Disable) || \ + ((PERIOD) == FMC_SDClock_Period_2) || \ + ((PERIOD) == FMC_SDClock_Period_3)) + +/** + * @} + */ + +/** @defgroup FMC_Read_Burst + * @{ + */ +#define FMC_Read_Burst_Disable ((uint32_t)0x00000000) +#define FMC_Read_Burst_Enable ((uint32_t)0x00001000) + +#define IS_FMC_READ_BURST(RBURST) (((RBURST) == FMC_Read_Burst_Disable) || \ + ((RBURST) == FMC_Read_Burst_Enable)) + +/** + * @} + */ + +/** @defgroup FMC_ReadPipe_Delay + * @{ + */ +#define FMC_ReadPipe_Delay_0 ((uint32_t)0x00000000) +#define FMC_ReadPipe_Delay_1 ((uint32_t)0x00002000) +#define FMC_ReadPipe_Delay_2 ((uint32_t)0x00004000) + +#define IS_FMC_READPIPE_DELAY(DELAY) (((DELAY) == FMC_ReadPipe_Delay_0) || \ + ((DELAY) == FMC_ReadPipe_Delay_1) || \ + ((DELAY) == FMC_ReadPipe_Delay_2)) + +/** + * @} + */ + +/** @defgroup FMC_LoadToActive_Delay + * @{ + */ +#define IS_FMC_LOADTOACTIVE_DELAY(DELAY) (((DELAY) > 0) && ((DELAY) <= 16)) +/** + * @} + */ + +/** @defgroup FMC_ExitSelfRefresh_Delay + * @{ + */ +#define IS_FMC_EXITSELFREFRESH_DELAY(DELAY) (((DELAY) > 0) && ((DELAY) <= 16)) +/** + * @} + */ + +/** @defgroup FMC_SelfRefresh_Time + * @{ + */ +#define IS_FMC_SELFREFRESH_TIME(TIME) (((TIME) > 0) && ((TIME) <= 16)) +/** + * @} + */ + +/** @defgroup FMC_RowCycle_Delay + * @{ + */ +#define IS_FMC_ROWCYCLE_DELAY(DELAY) (((DELAY) > 0) && ((DELAY) <= 16)) +/** + * @} + */ + +/** @defgroup FMC_Write_Recovery_Time + * @{ + */ +#define IS_FMC_WRITE_RECOVERY_TIME(TIME) (((TIME) > 0) && ((TIME) <= 16)) +/** + * @} + */ + +/** @defgroup FMC_RP_Delay + * @{ + */ +#define IS_FMC_RP_DELAY(DELAY) (((DELAY) > 0) && ((DELAY) <= 16)) +/** + * @} + */ + +/** @defgroup FMC_RCD_Delay + * @{ + */ +#define IS_FMC_RCD_DELAY(DELAY) (((DELAY) > 0) && ((DELAY) <= 16)) + +/** + * @} + */ + +/** @defgroup FMC_Command_Mode + * @{ + */ +#define FMC_Command_Mode_normal ((uint32_t)0x00000000) +#define FMC_Command_Mode_CLK_Enabled ((uint32_t)0x00000001) +#define FMC_Command_Mode_PALL ((uint32_t)0x00000002) +#define FMC_Command_Mode_AutoRefresh ((uint32_t)0x00000003) +#define FMC_Command_Mode_LoadMode ((uint32_t)0x00000004) +#define FMC_Command_Mode_Selfrefresh ((uint32_t)0x00000005) +#define FMC_Command_Mode_PowerDown ((uint32_t)0x00000006) + +#define IS_FMC_COMMAND_MODE(COMMAND) (((COMMAND) == FMC_Command_Mode_normal) || \ + ((COMMAND) == FMC_Command_Mode_CLK_Enabled) || \ + ((COMMAND) == FMC_Command_Mode_PALL) || \ + ((COMMAND) == FMC_Command_Mode_AutoRefresh) || \ + ((COMMAND) == FMC_Command_Mode_LoadMode) || \ + ((COMMAND) == FMC_Command_Mode_Selfrefresh) || \ + ((COMMAND) == FMC_Command_Mode_PowerDown)) + +/** + * @} + */ + +/** @defgroup FMC_Command_Target + * @{ + */ +#define FMC_Command_Target_bank2 ((uint32_t)0x00000008) +#define FMC_Command_Target_bank1 ((uint32_t)0x00000010) +#define FMC_Command_Target_bank1_2 ((uint32_t)0x00000018) + +#define IS_FMC_COMMAND_TARGET(TARGET) (((TARGET) == FMC_Command_Target_bank1) || \ + ((TARGET) == FMC_Command_Target_bank2) || \ + ((TARGET) == FMC_Command_Target_bank1_2)) + +/** + * @} + */ + +/** @defgroup FMC_AutoRefresh_Number + * @{ + */ +#define IS_FMC_AUTOREFRESH_NUMBER(NUMBER) (((NUMBER) > 0) && ((NUMBER) <= 16)) + +/** + * @} + */ + +/** @defgroup FMC_ModeRegister_Definition + * @{ + */ +#define IS_FMC_MODE_REGISTER(CONTENT) ((CONTENT) <= 8191) + +/** + * @} + */ + + +/** @defgroup FMC_Mode_Status + * @{ + */ +#define FMC_NormalMode_Status ((uint32_t)0x00000000) +#define FMC_SelfRefreshMode_Status FMC_SDSR_MODES1_0 +#define FMC_PowerDownMode_Status FMC_SDSR_MODES1_1 + +#define IS_FMC_MODE_STATUS(STATUS) (((STATUS) == FMC_NormalMode_Status) || \ + ((STATUS) == FMC_SelfRefreshMode_Status) || \ + ((STATUS) == FMC_PowerDownMode_Status)) + + +/** + * @} + */ + +/** + * @} + */ + +/** @defgroup FMC_Interrupt_sources + * @{ + */ +#define FMC_IT_RisingEdge ((uint32_t)0x00000008) +#define FMC_IT_Level ((uint32_t)0x00000010) +#define FMC_IT_FallingEdge ((uint32_t)0x00000020) +#define FMC_IT_Refresh ((uint32_t)0x00004000) + +#define IS_FMC_IT(IT) ((((IT) & (uint32_t)0xFFFFBFC7) == 0x00000000) && ((IT) != 0x00000000)) +#define IS_FMC_GET_IT(IT) (((IT) == FMC_IT_RisingEdge) || \ + ((IT) == FMC_IT_Level) || \ + ((IT) == FMC_IT_FallingEdge) || \ + ((IT) == FMC_IT_Refresh)) + +#define IS_FMC_IT_BANK(BANK) (((BANK) == FMC_Bank2_NAND) || \ + ((BANK) == FMC_Bank3_NAND) || \ + ((BANK) == FMC_Bank4_PCCARD) || \ + ((BANK) == FMC_Bank1_SDRAM) || \ + ((BANK) == FMC_Bank2_SDRAM)) +/** + * @} + */ + +/** @defgroup FMC_Flags + * @{ + */ +#define FMC_FLAG_RisingEdge ((uint32_t)0x00000001) +#define FMC_FLAG_Level ((uint32_t)0x00000002) +#define FMC_FLAG_FallingEdge ((uint32_t)0x00000004) +#define FMC_FLAG_FEMPT ((uint32_t)0x00000040) +#define FMC_FLAG_Refresh FMC_SDSR_RE +#define FMC_FLAG_Busy FMC_SDSR_BUSY + +#define IS_FMC_GET_FLAG(FLAG) (((FLAG) == FMC_FLAG_RisingEdge) || \ + ((FLAG) == FMC_FLAG_Level) || \ + ((FLAG) == FMC_FLAG_FallingEdge) || \ + ((FLAG) == FMC_FLAG_FEMPT) || \ + ((FLAG) == FMC_FLAG_Refresh) || \ + ((FLAG) == FMC_SDSR_BUSY)) + +#define IS_FMC_GETFLAG_BANK(BANK) (((BANK) == FMC_Bank2_NAND) || \ + ((BANK) == FMC_Bank3_NAND) || \ + ((BANK) == FMC_Bank4_PCCARD) || \ + ((BANK) == FMC_Bank1_SDRAM) || \ + ((BANK) == FMC_Bank2_SDRAM) || \ + ((BANK) == (FMC_Bank1_SDRAM | FMC_Bank2_SDRAM))) + +#define IS_FMC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFFF8) == 0x00000000) && ((FLAG) != 0x00000000)) + + +/** + * @} + */ + +/** @defgroup FMC_Refresh_count + * @{ + */ +#define IS_FMC_REFRESH_COUNT(COUNT) ((COUNT) <= 8191) + +/** + * @} + */ + +/** + * @} + */ + + +/* Exported macro ------------------------------------------------------------*/ +/* Exported functions --------------------------------------------------------*/ + +/* NOR/SRAM Controller functions **********************************************/ +void FMC_NORSRAMDeInit(uint32_t FMC_Bank); +void FMC_NORSRAMInit(FMC_NORSRAMInitTypeDef* FMC_NORSRAMInitStruct); +void FMC_NORSRAMStructInit(FMC_NORSRAMInitTypeDef* FMC_NORSRAMInitStruct); +void FMC_NORSRAMCmd(uint32_t FMC_Bank, FunctionalState NewState); + +/* NAND Controller functions **************************************************/ +void FMC_NANDDeInit(uint32_t FMC_Bank); +void FMC_NANDInit(FMC_NANDInitTypeDef* FMC_NANDInitStruct); +void FMC_NANDStructInit(FMC_NANDInitTypeDef* FMC_NANDInitStruct); +void FMC_NANDCmd(uint32_t FMC_Bank, FunctionalState NewState); +void FMC_NANDECCCmd(uint32_t FMC_Bank, FunctionalState NewState); +uint32_t FMC_GetECC(uint32_t FMC_Bank); + +/* PCCARD Controller functions ************************************************/ +void FMC_PCCARDDeInit(void); +void FMC_PCCARDInit(FMC_PCCARDInitTypeDef* FMC_PCCARDInitStruct); +void FMC_PCCARDStructInit(FMC_PCCARDInitTypeDef* FMC_PCCARDInitStruct); +void FMC_PCCARDCmd(FunctionalState NewState); + +/* SDRAM Controller functions ************************************************/ +void FMC_SDRAMDeInit(uint32_t FMC_Bank); +void FMC_SDRAMInit(FMC_SDRAMInitTypeDef* FMC_SDRAMInitStruct); +void FMC_SDRAMStructInit(FMC_SDRAMInitTypeDef* FMC_SDRAMInitStruct); +void FMC_SDRAMCmdConfig(FMC_SDRAMCommandTypeDef* FMC_SDRAMCommandStruct); +uint32_t FMC_GetModeStatus(uint32_t SDRAM_Bank); +void FMC_SetRefreshCount(uint32_t FMC_Count); +void FMC_SetAutoRefresh_Number(uint32_t FMC_Number); +void FMC_SDRAMWriteProtectionConfig(uint32_t SDRAM_Bank, FunctionalState NewState); + +/* Interrupts and flags management functions **********************************/ +void FMC_ITConfig(uint32_t FMC_Bank, uint32_t FMC_IT, FunctionalState NewState); +FlagStatus FMC_GetFlagStatus(uint32_t FMC_Bank, uint32_t FMC_FLAG); +void FMC_ClearFlag(uint32_t FMC_Bank, uint32_t FMC_FLAG); +ITStatus FMC_GetITStatus(uint32_t FMC_Bank, uint32_t FMC_IT); +void FMC_ClearITPendingBit(uint32_t FMC_Bank, uint32_t FMC_IT); + +#ifdef __cplusplus +} +#endif + +#endif /*__STM32F4xx_FMC_H */ +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/drivers/gdisp/STM32F429iDiscovery/board_STM32F429iDiscovery_template.h b/drivers/gdisp/STM32F429iDiscovery/board_STM32F429iDiscovery_template.h new file mode 100644 index 00000000..54c797af --- /dev/null +++ b/drivers/gdisp/STM32F429iDiscovery/board_STM32F429iDiscovery_template.h @@ -0,0 +1,66 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _GDISP_LLD_BOARD_H +#define _GDISP_LLD_BOARD_H + +static const ltdcConfig driverCfg = { + 240, 320, + 10, 2, + 20, 2, + 10, 4, + 0, + 0x000000, + { + (LLDCOLOR_TYPE *)SDRAM_BANK_ADDR, // frame + 240, 320, // width, height + 240 * LTDC_PIXELBYTES, // pitch + LTDC_PIXELFORMAT, // fmt + 0, 0, // x, y + 240, 320, // cx, cy + LTDC_COLOR_FUCHSIA, // defcolor + 0x980088, // keycolor + LTDC_BLEND_FIX1_FIX2, // blending + 0, // palette + 0, // palettelen + 0xFF, // alpha + LTDC_LEF_ENABLE // flags + }, + LTDC_UNUSED_LAYER_CONFIG +}; + +static inline void init_board(GDisplay *g) { + + // As we are not using multiple displays we set g->board to NULL as we don't use it. + g->board = 0; + + switch(g->controllerdisplay) { + case 0: // Set up for Display 0 + // Your init here + break; + } +} + +static inline void post_init_board(GDisplay *g) { +} + +static inline void set_backlight(GDisplay *g, uint8_t percent) { +} + +static inline void acquire_bus(GDisplay *g) { +} + +static inline void release_bus(GDisplay *g) { +} + +static inline void write_index(GDisplay *g, uint8_t index) { +} + +static inline void write_data(GDisplay *g, uint8_t data) { +} + +#endif /* _GDISP_LLD_BOARD_H */ diff --git a/drivers/gdisp/STM32F429iDiscovery/driver.mk b/drivers/gdisp/STM32F429iDiscovery/driver.mk new file mode 100644 index 00000000..afad5b85 --- /dev/null +++ b/drivers/gdisp/STM32F429iDiscovery/driver.mk @@ -0,0 +1,2 @@ +GFXINC += $(GFXLIB)/drivers/gdisp/STM32F429iDiscovery +GFXSRC += $(GFXLIB)/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_STM32F429iDiscovery.c diff --git a/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_STM32F429iDiscovery.c b/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_STM32F429iDiscovery.c new file mode 100644 index 00000000..aae21a8e --- /dev/null +++ b/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_STM32F429iDiscovery.c @@ -0,0 +1,410 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#include "gfx.h" + +#if GFX_USE_GDISP + +#if defined(GDISP_SCREEN_HEIGHT) + #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored." + #undef GISP_SCREEN_HEIGHT +#endif +#if defined(GDISP_SCREEN_WIDTH) + #warning "GDISP: This low level driver does not support setting a screen size. It is being ignored." + #undef GDISP_SCREEN_WIDTH +#endif + +#define GDISP_DRIVER_VMT GDISPVMT_STM32F429iDiscovery +#include "drivers/gdisp/STM32F429iDiscovery/gdisp_lld_config.h" +#include "src/gdisp/driver.h" + +#include "stm32_ltdc.h" + +typedef struct ltdcLayerConfig { + // frame + LLDCOLOR_TYPE *frame; // Frame buffer address + coord_t width, height; // Frame size in pixels + coord_t pitch; // Line pitch, in bytes + ltdc_pixfmt_t fmt; // Pixel format in LTDC format + + // window + coord_t x, y; // Start pixel position of the virtual layer + coord_t cx, cy; // Size of the virtual layer + + uint32_t defcolor; // Default color, ARGB8888 + uint32_t keycolor; // Color key, RGB888 + uint32_t blending; // Blending factors + const uint32_t *palette; // The palette, RGB888 (can be NULL) + uint16_t palettelen; // Palette length + uint8_t alpha; // Constant alpha factor + uint8_t layerflags; // Layer configuration +} ltdcLayerConfig; + +#define LTDC_UNUSED_LAYER_CONFIG { 0, 1, 1, 1, LTDC_FMT_L8, 0, 0, 1, 1, 0x000000, 0x000000, LTDC_BLEND_FIX1_FIX2, 0, 0, 0, 0 } + +typedef struct ltdcConfig { + coord_t width, height; // Screen size + coord_t hsync, vsync; // Horizontal and Vertical sync pixels + coord_t hbackporch, vbackporch; // Horizontal and Vertical back porch pixels + coord_t hfrontporch, vfrontporch; // Horizontal and Vertical front porch pixels + uint8_t syncflags; // Sync flags + uint32_t bgcolor; // Clear screen color RGB888 + + ltdcLayerConfig bglayer; // Background layer config + ltdcLayerConfig fglayer; // Foreground layer config +} ltdcConfig; + +#if GDISP_LLD_PIXELFORMAT == GDISP_PIXELFORMAT_RGB565 + #define LTDC_PIXELFORMAT LTDC_FMT_RGB565 + #define LTDC_PIXELBYTES 2 + #define LTDC_PIXELBITS 16 +#elif GDISP_LLD_PIXELFORMAT == GDISP_PIXELFORMAT_RGB888 + #define LTDC_PIXELFORMAT LTDC_FMT_RGB888 + #define LTDC_PIXELBYTES 3 + #define LTDC_PIXELBITS 24 +#else + #error "GDISP: STM32F4iDiscovery - unsupported pixel format" +#endif + +#include "board_STM32F429iDiscovery.h" + +#include "ili9341.h" + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +#ifndef GDISP_INITIAL_CONTRAST + #define GDISP_INITIAL_CONTRAST 50 +#endif +#ifndef GDISP_INITIAL_BACKLIGHT + #define GDISP_INITIAL_BACKLIGHT 100 +#endif + +/*===========================================================================*/ +/* Driver local routines . */ +/*===========================================================================*/ + +#define PIXIL_POS(g, x, y) ((y) * driverCfg.bglayer.pitch + (x) * LTDC_PIXELBYTES) +#define PIXEL_ADDR(g, pos) ((LLDCOLOR_TYPE *)((uint8_t *)driverCfg.bglayer.frame+pos)) + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +static void InitController(GDisplay *g) { + #define REG_TYPEMASK 0xFF00 + #define REG_DATAMASK 0x00FF + + #define REG_DATA 0x0000 + #define REG_COMMAND 0x0100 + #define REG_DELAY 0x0200 + + static const uint16_t initdata[] = { + REG_COMMAND | ILI9341_CMD_RESET, + REG_DELAY | 5, + REG_COMMAND | ILI9341_CMD_DISPLAY_OFF, + REG_COMMAND | ILI9341_SET_FRAME_CTL_NORMAL, 0x00, 0x1B, + REG_COMMAND | ILI9341_SET_FUNCTION_CTL, 0x0A, 0xA2, + REG_COMMAND | ILI9341_SET_POWER_CTL_1, 0x10, + REG_COMMAND | ILI9341_SET_POWER_CTL_2, 0x10, + REG_COMMAND | ILI9341_SET_VCOM_CTL_1, 0x45, 0x15, + REG_COMMAND | ILI9341_SET_VCOM_CTL_2, 0x90, + REG_COMMAND | ILI9341_SET_MEM_ACS_CTL, 0xC8, + REG_COMMAND | ILI9341_SET_RGB_IF_SIG_CTL, 0xC2, + REG_COMMAND | ILI9341_SET_FUNCTION_CTL, 0x0A, 0xA7, 0x27, 0x04, + REG_COMMAND | ILI9341_SET_COL_ADDR, 0x00, 0x00, 0x00, 0xEF, + REG_COMMAND | ILI9341_SET_PAGE_ADDR, 0x00, 0x00, 0x01, 0x3F, + REG_COMMAND | ILI9341_SET_IF_CTL, 0x01, 0x00, 0x06, + REG_COMMAND | ILI9341_SET_GAMMA, 0x01, + REG_COMMAND | ILI9341_SET_PGAMMA, + 0x0F, 0x29, 0x24, 0x0C, 0x0E, 0x09, 0x4E, 0x78, + 0x3C, 0x09, 0x13, 0x05, 0x17, 0x11, 0x00, + REG_COMMAND | ILI9341_SET_NGAMMA, + 0x00, 0x16, 0x1B, 0x04, 0x11, 0x07, 0x31, 0x33, + 0x42, 0x05, 0x0C, 0x0A, 0x28, 0x2F, 0x0F, + REG_COMMAND | ILI9341_CMD_SLEEP_OFF, + REG_DELAY | 10, + REG_COMMAND | ILI9341_CMD_DISPLAY_ON, + REG_COMMAND | ILI9341_SET_MEM + }; + + const uint16_t *p; + + acquire_bus(g); + for(p = initdata; p < &initdata[sizeof(initdata)/sizeof(initdata[0])]; p++) { + switch(*p & REG_TYPEMASK) { + case REG_DATA: write_data(g, *p); break; + case REG_COMMAND: write_index(g, *p); break; + case REG_DELAY: gfxSleepMilliseconds(*p & 0xFF); break; + } + } + release_bus(g); +} + +static void LTDC_Reload(void) { + LTDC->SRCR |= LTDC_SRCR_IMR; + while (LTDC->SRCR & (LTDC_SRCR_IMR | LTDC_SRCR_VBR)) + gfxYield(); +} + +static void LTDC_LayerInit(LTDC_Layer_TypeDef *pLayReg, const ltdcLayerConfig * pCfg) { + static const uint8_t fmt2Bpp[] = { + 4, /* LTDC_FMT_ARGB8888 */ + 3, /* LTDC_FMT_RGB888 */ + 2, /* LTDC_FMT_RGB565 */ + 2, /* LTDC_FMT_ARGB1555 */ + 2, /* LTDC_FMT_ARGB4444 */ + 1, /* LTDC_FMT_L8 */ + 1, /* LTDC_FMT_AL44 */ + 2 /* LTDC_FMT_AL88 */ + }; + uint32_t start, stop; + + // Set the framebuffer dimensions and format + pLayReg->PFCR = (pLayReg->PFCR & ~LTDC_LxPFCR_PF) | ((uint32_t)pCfg->fmt & LTDC_LxPFCR_PF); + pLayReg->CFBAR = (uint32_t)pCfg->frame & LTDC_LxCFBAR_CFBADD; + pLayReg->CFBLR = ((((uint32_t)pCfg->pitch << 16) & LTDC_LxCFBLR_CFBP) | (((uint32_t)fmt2Bpp[pCfg->fmt] * pCfg->width + 3) & LTDC_LxCFBLR_CFBLL)); + pLayReg->CFBLNR = (uint32_t)pCfg->height & LTDC_LxCFBLNR_CFBLNBR; + + // Set the display window boundaries + start = (uint32_t)pCfg->x + driverCfg.hsync + driverCfg.hbackporch; + stop = start + pCfg->cx - 1; + pLayReg->WHPCR = ((start << 0) & LTDC_LxWHPCR_WHSTPOS) | ((stop << 16) & LTDC_LxWHPCR_WHSPPOS); + start = (uint32_t)pCfg->y + driverCfg.vsync + driverCfg.vbackporch; + stop = start + pCfg->cy - 1; + pLayReg->WVPCR = ((start << 0) & LTDC_LxWVPCR_WVSTPOS) | ((stop << 16) & LTDC_LxWVPCR_WVSPPOS); + + // Set colors + pLayReg->DCCR = pCfg->defcolor; + pLayReg->CKCR = (pLayReg->CKCR & ~0x00FFFFFF) | (pCfg->keycolor & 0x00FFFFFF); + pLayReg->CACR = (pLayReg->CACR & ~LTDC_LxCACR_CONSTA) | ((uint32_t)pCfg->alpha & LTDC_LxCACR_CONSTA); + pLayReg->BFCR = (pLayReg->BFCR & ~(LTDC_LxBFCR_BF1 | LTDC_LxBFCR_BF2)) | ((uint32_t)pCfg->blending & (LTDC_LxBFCR_BF1 | LTDC_LxBFCR_BF2)); + for (start = 0; start < pCfg->palettelen; start++) + pLayReg->CLUTWR = ((uint32_t)start << 24) | (pCfg->palette[start] & 0x00FFFFFF); + + // Final flags + pLayReg->CR = (pLayReg->CR & ~LTDC_LEF_MASK) | ((uint32_t)pCfg->layerflags & LTDC_LEF_MASK); +} + +static void LTDC_Init(void) { + // Set up the display scanning + uint32_t hacc, vacc; + + /* Reset the LTDC hardware module.*/ + RCC->APB2RSTR |= RCC_APB2RSTR_LTDCRST; + RCC->APB2RSTR = 0; + + /* Enable the LTDC clock.*/ + RCC->DCKCFGR = (RCC->DCKCFGR & ~RCC_DCKCFGR_PLLSAIDIVR) | (2 << 16); /* /8 */ + + // Enable the module + RCC->APB2ENR |= RCC_APB2ENR_LTDCEN; + + // Turn off the controller and its interrupts. + LTDC->GCR = 0; + LTDC->IER = 0; + LTDC_Reload(); + + // Set synchronization params + hacc = driverCfg.hsync - 1; + vacc = driverCfg.vsync - 1; + LTDC->SSCR = ((hacc << 16) & LTDC_SSCR_HSW) | ((vacc << 0) & LTDC_SSCR_VSH); + + // Set accumulated back porch params + hacc += driverCfg.hbackporch; + vacc += driverCfg.vbackporch; + LTDC->BPCR = ((hacc << 16) & LTDC_BPCR_AHBP) | ((vacc << 0) & LTDC_BPCR_AVBP); + + // Set accumulated active params + hacc += driverCfg.width; + vacc += driverCfg.height; + LTDC->AWCR = ((hacc << 16) & LTDC_AWCR_AAW) | ((vacc << 0) & LTDC_AWCR_AAH); + + // Set accumulated total params + hacc += driverCfg.hfrontporch; + vacc += driverCfg.vfrontporch; + LTDC->TWCR = ((hacc << 16) & LTDC_TWCR_TOTALW) | ((vacc << 0) & LTDC_TWCR_TOTALH); + + // Set signal polarities and other flags + LTDC->GCR = driverCfg.syncflags & (LTDC_EF_MASK & ~LTDC_EF_ENABLE); + + // Set background color + LTDC->BCCR = (LTDC->BCCR & ~0x00FFFFFF) | (driverCfg.bgcolor & 0x00FFFFFF); + + // Load the background layer + LTDC_LayerInit(LTDC_Layer1, &driverCfg.bglayer); + + // Load the foreground layer + LTDC_LayerInit(LTDC_Layer2, &driverCfg.fglayer); + + // Interrupt handling + //nvicEnableVector(STM32_LTDC_EV_NUMBER, CORTEX_PRIORITY_MASK(STM32_LTDC_EV_IRQ_PRIORITY)); + //nvicEnableVector(STM32_LTDC_ER_NUMBER, CORTEX_PRIORITY_MASK(STM32_LTDC_ER_IRQ_PRIORITY)); + // Possible flags - LTDC_IER_RRIE, LTDC_IER_LIE, LTDC_IER_FUIE, LTDC_IER_TERRIE etc + LTDC->IER = 0; + + // Set everything going + LTDC_Reload(); + LTDC->GCR |= LTDC_GCR_LTDCEN; + LTDC_Reload(); +} + +LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { + + // Initialize the private structure + g->priv = 0; + g->board = 0; + //if (!(g->priv = gfxAlloc(sizeof(fbPriv)))) + // gfxHalt("GDISP Framebuffer: Failed to allocate private memory"); + + // Init the board + init_board(g); + //((fbPriv *)g->priv)->fbi.cfg = init_board(g); + + // Initialise the ILI9341 controller + InitController(g); + + // Initialise the LTDC controller + LTDC_Init(); + + // Initialise DMA2D + //dma2dStart(&DMA2DD1, &dma2d_cfg); + //dma2d_test(); + + // Finish Init the board + post_init_board(g); + + /* Turn on the back-light */ + set_backlight(g, GDISP_INITIAL_BACKLIGHT); + + /* Initialise the GDISP structure */ + g->g.Width = driverCfg.bglayer.width; + g->g.Height = driverCfg.bglayer.height; + g->g.Orientation = GDISP_ROTATE_0; + g->g.Powermode = powerOn; + g->g.Backlight = GDISP_INITIAL_BACKLIGHT; + g->g.Contrast = GDISP_INITIAL_CONTRAST; + return TRUE; +} + +LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) { + unsigned pos; + + #if GDISP_NEED_CONTROL + switch(g->g.Orientation) { + case GDISP_ROTATE_0: + default: + pos = PIXIL_POS(g, g->p.x, g->p.y); + break; + case GDISP_ROTATE_90: + pos = PIXIL_POS(g, g->p.y, g->g.Width-g->p.x-1); + break; + case GDISP_ROTATE_180: + pos = PIXIL_POS(g, g->g.Width-g->p.x-1, g->g.Height-g->p.y-1); + break; + case GDISP_ROTATE_270: + pos = PIXIL_POS(g, g->g.Height-g->p.y-1, g->p.x); + break; + } + #else + pos = PIXIL_POS(g, g->p.x, g->p.y); + #endif + + PIXEL_ADDR(g, pos)[0] = gdispColor2Native(g->p.color); +} + +LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) { + unsigned pos; + LLDCOLOR_TYPE color; + + #if GDISP_NEED_CONTROL + switch(g->g.Orientation) { + case GDISP_ROTATE_0: + default: + pos = PIXIL_POS(g, g->p.x, g->p.y); + break; + case GDISP_ROTATE_90: + pos = PIXIL_POS(g, g->p.y, g->g.Width-g->p.x-1); + break; + case GDISP_ROTATE_180: + pos = PIXIL_POS(g, g->g.Width-g->p.x-1, g->g.Height-g->p.y-1); + break; + case GDISP_ROTATE_270: + pos = PIXIL_POS(g, g->g.Height-g->p.y-1, g->p.x); + break; + } + #else + pos = PIXIL_POS(g, g->p.x, g->p.y); + #endif + + color = PIXEL_ADDR(g, pos)[0]; + return gdispNative2Color(color); +} + +#if GDISP_NEED_CONTROL + LLDSPEC void gdisp_lld_control(GDisplay *g) { + switch(g->p.x) { + case GDISP_CONTROL_POWER: + if (g->g.Powermode == (powermode_t)g->p.ptr) + return; + switch((powermode_t)g->p.ptr) { + case powerOff: case powerOn: case powerSleep: case powerDeepSleep: + board_power(g, (powermode_t)g->p.ptr); + break; + default: + return; + } + g->g.Powermode = (powermode_t)g->p.ptr; + return; + + case GDISP_CONTROL_ORIENTATION: + if (g->g.Orientation == (orientation_t)g->p.ptr) + return; + switch((orientation_t)g->p.ptr) { + case GDISP_ROTATE_0: + case GDISP_ROTATE_180: + if (g->g.Orientation == GDISP_ROTATE_90 || g->g.Orientation == GDISP_ROTATE_270) { + coord_t tmp; + + tmp = g->g.Width; + g->g.Width = g->g.Height; + g->g.Height = tmp; + } + break; + case GDISP_ROTATE_90: + case GDISP_ROTATE_270: + if (g->g.Orientation == GDISP_ROTATE_0 || g->g.Orientation == GDISP_ROTATE_180) { + coord_t tmp; + + tmp = g->g.Width; + g->g.Width = g->g.Height; + g->g.Height = tmp; + } + break; + default: + return; + } + g->g.Orientation = (orientation_t)g->p.ptr; + return; + + case GDISP_CONTROL_BACKLIGHT: + if ((unsigned)g->p.ptr > 100) g->p.ptr = (void *)100; + board_backlight(g, (unsigned)g->p.ptr); + g->g.Backlight = (unsigned)g->p.ptr; + return; + + case GDISP_CONTROL_CONTRAST: + if ((unsigned)g->p.ptr > 100) g->p.ptr = (void *)100; + board_contrast(g, (unsigned)g->p.ptr); + g->g.Contrast = (unsigned)g->p.ptr; + return; + } + } +#endif + +#endif /* GFX_USE_GDISP */ diff --git a/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_config.h b/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_config.h new file mode 100644 index 00000000..29e016ce --- /dev/null +++ b/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_config.h @@ -0,0 +1,24 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _GDISP_LLD_CONFIG_H +#define _GDISP_LLD_CONFIG_H + +#if GFX_USE_GDISP + +/*===========================================================================*/ +/* Driver hardware support. */ +/*===========================================================================*/ + +#define GDISP_HARDWARE_DRAWPIXEL TRUE +#define GDISP_HARDWARE_PIXELREAD TRUE +#define GDISP_HARDWARE_CONTROL TRUE +#define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_RGB565 + +#endif /* GFX_USE_GDISP */ + +#endif /* _GDISP_LLD_CONFIG_H */ diff --git a/drivers/gdisp/STM32F429iDiscovery/ili9341.h b/drivers/gdisp/STM32F429iDiscovery/ili9341.h new file mode 100644 index 00000000..17ad488c --- /dev/null +++ b/drivers/gdisp/STM32F429iDiscovery/ili9341.h @@ -0,0 +1,412 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef ILI9341_H +#define ILI9341_H + +// ILI9341 commands +#define ILI9341_CMD_NOP 0x00 /**< No operation.*/ +#define ILI9341_CMD_RESET 0x01 /**< Software reset.*/ +#define ILI9341_GET_ID_INFO 0x04 /**< Get ID information.*/ +#define ILI9341_GET_STATUS 0x09 /**< Get status.*/ +#define ILI9341_GET_PWR_MODE 0x0A /**< Get power mode.*/ +#define ILI9341_GET_MADCTL 0x0B /**< Get MADCTL.*/ +#define ILI9341_GET_PIX_FMT 0x0C /**< Get pixel format.*/ +#define ILI9341_GET_IMG_FMT 0x0D /**< Get image format.*/ +#define ILI9341_GET_SIG_MODE 0x0E /**< Get signal mode.*/ +#define ILI9341_GET_SELF_DIAG 0x0F /**< Get self-diagnostics.*/ +#define ILI9341_CMD_SLEEP_ON 0x10 /**< Enter sleep mode.*/ +#define ILI9341_CMD_SLEEP_OFF 0x11 /**< Exist sleep mode.*/ +#define ILI9341_CMD_PARTIAL_ON 0x12 /**< Enter partial mode.*/ +#define ILI9341_CMD_PARTIAL_OFF 0x13 /**< Exit partial mode.*/ +#define ILI9341_CMD_INVERT_ON 0x20 /**< Enter inverted mode.*/ +#define ILI9341_CMD_INVERT_OFF 0x21 /**< Exit inverted mode.*/ +#define ILI9341_SET_GAMMA 0x26 /**< Set gamma params.*/ +#define ILI9341_CMD_DISPLAY_OFF 0x28 /**< Disable display.*/ +#define ILI9341_CMD_DISPLAY_ON 0x29 /**< Enable display.*/ +#define ILI9341_SET_COL_ADDR 0x2A /**< Set column address.*/ +#define ILI9341_SET_PAGE_ADDR 0x2B /**< Set page address.*/ +#define ILI9341_SET_MEM 0x2C /**< Set memory.*/ +#define ILI9341_SET_COLOR 0x2D /**< Set color.*/ +#define ILI9341_GET_MEM 0x2E /**< Get memory.*/ +#define ILI9341_SET_PARTIAL_AREA 0x30 /**< Set partial area.*/ +#define ILI9341_SET_VSCROLL 0x33 /**< Set vertical scroll def.*/ +#define ILI9341_CMD_TEARING_ON 0x34 /**< Tearing line enabled.*/ +#define ILI9341_CMD_TEARING_OFF 0x35 /**< Tearing line disabled.*/ +#define ILI9341_SET_MEM_ACS_CTL 0x36 /**< Set mem access ctl.*/ +#define ILI9341_SET_VSCROLL_ADDR 0x37 /**< Set vscroll start addr.*/ +#define ILI9341_CMD_IDLE_OFF 0x38 /**< Exit idle mode.*/ +#define ILI9341_CMD_IDLE_ON 0x39 /**< Enter idle mode.*/ +#define ILI9341_SET_PIX_FMT 0x3A /**< Set pixel format.*/ +#define ILI9341_SET_MEM_CONT 0x3C /**< Set memory continue.*/ +#define ILI9341_GET_MEM_CONT 0x3E /**< Get memory continue.*/ +#define ILI9341_SET_TEAR_SCANLINE 0x44 /**< Set tearing scanline.*/ +#define ILI9341_GET_TEAR_SCANLINE 0x45 /**< Get tearing scanline.*/ +#define ILI9341_SET_BRIGHTNESS 0x51 /**< Set brightness.*/ +#define ILI9341_GET_BRIGHTNESS 0x52 /**< Get brightness.*/ +#define ILI9341_SET_DISPLAY_CTL 0x53 /**< Set display ctl.*/ +#define ILI9341_GET_DISPLAY_CTL 0x54 /**< Get display ctl.*/ +#define ILI9341_SET_CABC 0x55 /**< Set CABC.*/ +#define ILI9341_GET_CABC 0x56 /**< Get CABC.*/ +#define ILI9341_SET_CABC_MIN 0x5E /**< Set CABC min.*/ +#define ILI9341_GET_CABC_MIN 0x5F /**< Set CABC max.*/ +#define ILI9341_GET_ID1 0xDA /**< Get ID1.*/ +#define ILI9341_GET_ID2 0xDB /**< Get ID2.*/ +#define ILI9341_GET_ID3 0xDC /**< Get ID3.*/ + +// ILI9341 extended commands +#define ILI9341_SET_RGB_IF_SIG_CTL 0xB0 /**< RGB IF signal ctl.*/ +#define ILI9341_SET_FRAME_CTL_NORMAL 0xB1 /**< Set frame ctl (normal).*/ +#define ILI9341_SET_FRAME_CTL_IDLE 0xB2 /**< Set frame ctl (idle).*/ +#define ILI9341_SET_FRAME_CTL_PARTIAL 0xB3 /**< Set frame ctl (partial).*/ +#define ILI9341_SET_INVERSION_CTL 0xB4 /**< Set inversion ctl.*/ +#define ILI9341_SET_BLANKING_PORCH_CTL 0xB5 /**< Set blanking porch ctl.*/ +#define ILI9341_SET_FUNCTION_CTL 0xB6 /**< Set function ctl.*/ +#define ILI9341_SET_ENTRY_MODE 0xB7 /**< Set entry mode.*/ +#define ILI9341_SET_LIGHT_CTL_1 0xB8 /**< Set backlight ctl 1.*/ +#define ILI9341_SET_LIGHT_CTL_2 0xB9 /**< Set backlight ctl 2.*/ +#define ILI9341_SET_LIGHT_CTL_3 0xBA /**< Set backlight ctl 3.*/ +#define ILI9341_SET_LIGHT_CTL_4 0xBB /**< Set backlight ctl 4.*/ +#define ILI9341_SET_LIGHT_CTL_5 0xBC /**< Set backlight ctl 5.*/ +#define ILI9341_SET_LIGHT_CTL_7 0xBE /**< Set backlight ctl 7.*/ +#define ILI9341_SET_LIGHT_CTL_8 0xBF /**< Set backlight ctl 8.*/ +#define ILI9341_SET_POWER_CTL_1 0xC0 /**< Set power ctl 1.*/ +#define ILI9341_SET_POWER_CTL_2 0xC1 /**< Set power ctl 2.*/ +#define ILI9341_SET_VCOM_CTL_1 0xC5 /**< Set VCOM ctl 1.*/ +#define ILI9341_SET_VCOM_CTL_2 0xC6 /**< Set VCOM ctl 2.*/ +#define ILI9341_SET_NVMEM 0xD0 /**< Set NVMEM data.*/ +#define ILI9341_GET_NVMEM_KEY 0xD1 /**< Get NVMEM protect key.*/ +#define ILI9341_GET_NVMEM_STATUS 0xD2 /**< Get NVMEM status.*/ +#define ILI9341_GET_ID4 0xD3 /**< Get ID4.*/ +#define ILI9341_SET_PGAMMA 0xE0 /**< Set positive gamma.*/ +#define ILI9341_SET_NGAMMA 0xE1 /**< Set negative gamma.*/ +#define ILI9341_SET_DGAMMA_CTL_1 0xE2 /**< Set digital gamma ctl 1.*/ +#define ILI9341_SET_DGAMMA_CTL_2 0xE3 /**< Set digital gamma ctl 2.*/ +#define ILI9341_SET_IF_CTL 0xF6 /**< Set interface control.*/ + +// ILI9341 interface modes +#define ILI9341_IM_3LSI_1 0x5 /**< 3-line serial, mode 1.*/ +#define ILI9341_IM_3LSI_2 0xD /**< 3-line serial, mode 2.*/ +#define ILI9341_IM_4LSI_1 0x6 /**< 4-line serial, mode 1.*/ +#define ILI9341_IM_4LSI_2 0xE /**< 4-line serial, mode 2.*/ + +// ILI9341 command params (little endian) + +#pragma pack(push, 1) + +typedef union { + struct ILI9341ParamBits_GET_ID_INFO { + uint8_t reserved_; + uint8_t ID1; + uint8_t ID2; + uint8_t ID3; + } bits; + uint8_t bytes[4]; +} ILI9341Params_GET_ID_INFO; + +typedef union { + struct ILI9341ParamBits_GET_STATUS { + unsigned _reserved_1 : 5; /* D[ 4: 0] */ + unsigned tearing_mode : 1; /* D[ 5] */ + unsigned gamma_curve : 3; /* D[ 8: 6] */ + unsigned tearing : 1; /* D[ 9] */ + unsigned display : 1; /* D[10] */ + unsigned all_on : 1; /* D[11] */ + unsigned all_off : 1; /* D[12] */ + unsigned invert : 1; /* D[13] */ + unsigned _reserved_2 : 1; /* D[14] */ + unsigned vscroll : 1; /* D[15] */ + unsigned normal : 1; /* D[16] */ + unsigned sleep : 1; /* D[17] */ + unsigned partial : 1; /* D[18] */ + unsigned idle : 1; /* D[19] */ + unsigned pixel_format : 3; /* D[22:20] */ + unsigned _reserved_3 : 2; /* D[24:23] */ + unsigned hrefr_rtl_nltr : 1; /* D[25] */ + unsigned bgr_nrgb : 1; /* D[26] */ + unsigned vrefr_btt_nttb : 1; /* D[27] */ + unsigned transpose : 1; /* D[28] */ + unsigned coladr_rtl_nltr : 1; /* D[29] */ + unsigned rowadr_btt_nttb : 1; /* D[30] */ + unsigned booster : 1; /* D[31] */ + } bits; + uint8_t bytes[4]; +} ILI9341Params_GET_STATUS; + +typedef union { + struct ILI9341ParamBits_GET_PWR_MODE { + unsigned _reserved_1 : 2; /* D[1:0] */ + unsigned display : 1; /* D[2] */ + unsigned normal : 1; /* D[3] */ + unsigned sleep : 1; /* D[4] */ + unsigned partial : 1; /* D[5] */ + unsigned idle : 1; /* D[6] */ + unsigned booster : 1; /* D[7] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_GET_PWR_MODE; + +typedef union { + struct ILI9341ParamBits_GET_MADCTL { + unsigned _reserved_1 : 2; /* D[1:0] */ + unsigned refr_rtl_nltr : 1; /* D[2] */ + unsigned bgr_nrgb : 1; /* D[3] */ + unsigned refr_btt_nttb : 1; /* D[4] */ + unsigned invert : 1; /* D[5] */ + unsigned rtl_nltr : 1; /* D[6] */ + unsigned btt_nttb : 1; /* D[7] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_GET_MADCTL; + +typedef union { + struct ILI9341ParamBits_GET_PIX_FMT { + unsigned DBI : 3; /* D[2:0] */ + unsigned _reserved_1 : 1; /* D[3] */ + unsigned DPI : 3; /* D[6:4] */ + unsigned RIM : 1; /* D[7] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_GET_PIX_FMT; + +typedef union { + struct ILI9341ParamBits_GET_IMG_FMT { + unsigned gamma_curve : 3; /* D[2:0] */ + unsigned _reserved_1 : 5; /* D[7:3] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_GET_IMG_FMT; + +typedef union { + struct ILI9341ParamBits_GET_SIG_MODE { + unsigned _reserved_1 : 2; /* D[1:0] */ + unsigned data_enable : 1; /* D[2] */ + unsigned pixel_clock : 1; /* D[3] */ + unsigned vsync : 1; /* D[4] */ + unsigned hsync : 1; /* D[5] */ + unsigned tearing_mode : 1; /* D[6] */ + unsigned tearing : 1; /* D[7] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_GET_SIG_MODE; + +typedef union { + struct ILI9341ParamBits_GET_SELF_DIAG { + unsigned _reserved_1 : 6; /* D[5:0] */ + unsigned func_err : 1; /* D[6] */ + unsigned reg_err : 1; /* D[7] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_GET_SELF_DIAG; + +typedef union { + struct ILI9341ParamBits_SET_GAMMA { + uint8_t gamma_curve; /* D[7:0] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_SET_GAMMA; + +typedef union { + struct ILI9341ParamBits_SET_COL_ADDR { + uint8_t SC_15_8; /* D[ 7: 0] */ + uint8_t SC_7_0; /* D[15: 8] */ + uint8_t EC_15_8; /* D[23:16] */ + uint8_t EC_7_0; /* D[31:24] */ + } bits; + uint8_t bytes[4]; +} ILI9341Params_SET_COL_ADDR; + +typedef union { + struct ILI9341ParamBits_SET_PAGE_ADDR { + uint8_t SP_15_8; /* D[ 7: 0] */ + uint8_t SP_7_0; /* D[15: 8] */ + uint8_t EP_15_8; /* D[23:16] */ + uint8_t EP_7_0; /* D[31:24] */ + } bits; + uint8_t bytes[4]; +} ILI9341Params_SET_PAGE_ADDR; + +typedef union { + struct ILI9341ParamBits_SET_PARTIAL_AREA { + uint8_t SR_15_8; /* D[ 7: 0] */ + uint8_t SR_7_0; /* D[15: 8] */ + uint8_t ER_15_8; /* D[23:16] */ + uint8_t ER_7_0; /* D[31:24] */ + } bits; + uint8_t bytes[4]; +} ILI9341Params_SET_PARTIAL_AREA; + +typedef union { + struct ILI9341ParamBits_SET_VSCROLL { + uint8_t TFA_15_8; /* D[ 7: 0] */ + uint8_t TFA_7_0; /* D[15: 8] */ + uint8_t VSA_15_8; /* D[23:16] */ + uint8_t VSA_7_0; /* D[31:24] */ + uint8_t BFA_15_8; /* D[39:32] */ + uint8_t BFA_7_0; /* D[47:40] */ + } bits; + uint8_t bytes[6]; +} ILI9341Params_SET_VSCROLL; + +typedef union { + struct ILI9341ParamBits_CMD_TEARING_ON { + unsigned M : 1; /* D[0] */ + unsigned _reserved_1 : 7; /* D[7:1] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_CMD_TEARING_ON; + +typedef union { + struct ILI9341ParamBits_SET_MEM_ACS_CTL { + unsigned _reserved_1 : 2; /* D[1:0] */ + unsigned MH : 1; /* D[2] */ + unsigned BGR : 1; /* D[3] */ + unsigned ML : 1; /* D[4] */ + unsigned MV : 1; /* D[5] */ + unsigned MX : 1; /* D[6] */ + unsigned MY : 1; /* D[7] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_SET_MEM_ACS_CTL; + +typedef union { + struct ILI9341ParamBits_SET_VSCROLL_ADDR { + uint8_t VSP_15_8; /* D[ 7: 0] */ + uint8_t VSP_7_0; /* D[15: 8] */ + } bits; + uint8_t bytes[2]; +} ILI9341Params_SET_VSCROLL_ADDR; + +typedef union { + struct ILI9341ParamBits_SET_PIX_FMT { + unsigned DBI : 3; /* D[2:0] */ + unsigned _reserved_1 : 1; /* D[3] */ + unsigned DPI : 3; /* D[4:6] */ + unsigned _reserved_2 : 1; /* D[7] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_SET_PIX_FMT; + +typedef union { + struct ILI9341ParamBits_SET_TEAR_SCANLINE { + uint8_t STS_8; /* D[ 7: 0] */ + uint8_t STS_7_0; /* D[15: 8] */ + } bits; + uint8_t bytes[4]; +} ILI9341Params_SET_TEAR_SCANLINE; + +typedef union { + struct ILI9341ParamBits_GET_TEAR_SCANLINE { + uint8_t GTS_9_8; /* D[ 7: 0] */ + uint8_t GTS_7_0; /* D[15: 8] */ + } bits; + uint8_t bytes[2]; +} ILI9341Params_GET_TEAR_SCANLINE; + +typedef union { + struct ILI9341ParamBits_SET_BRIGHTNESS { + uint8_t DBV; /* D[7:0] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_SET_BRIGHTNESS; + +typedef union { + struct ILI9341ParamBits_GET_BRIGHTNESS { + uint8_t DBV; /* D[7:0] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_GET_BRIGHTNESS; + +typedef union { + struct ILI9341ParamBits_SET_DISPLAY_CTL { + unsigned _reserved_1 : 2; /* D[1:0] */ + unsigned BL : 1; /* D[2] */ + unsigned DD : 1; /* D[3] */ + unsigned _reserved_2 : 1; /* D[4] */ + unsigned BCTRL : 1; /* D[5] */ + unsigned _reserved_3 : 1; /* D[7:6] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_SET_DISPLAY_CTL; + +typedef union { + struct ILI9341ParamBits_GET_DISPLAY_CTL { + unsigned _reserved_1 : 2; /* D[1:0] */ + unsigned BL : 1; /* D[2] */ + unsigned DD : 1; /* D[3] */ + unsigned _reserved_2 : 1; /* D[4] */ + unsigned BCTRL : 1; /* D[5] */ + unsigned _reserved_3 : 1; /* D[7:6] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_GET_DISPLAY_CTL; + +typedef union { + struct ILI9341ParamBits_SET_CABC { + unsigned C : 2; /* D[1:0] */ + unsigned _reserved_1 : 6; /* D[7:2] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_SET_CABC; + +typedef union { + struct ILI9341ParamBits_GET_CABC { + unsigned C : 2; /* D[1:0] */ + unsigned _reserved_1 : 6; /* D[7:2] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_GET_CABC; + +typedef union { + struct ILI9341ParamBits_SET_CABC_MIN { + uint8_t CMB; /* D[7:0] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_SET_CABC_MIN; + +typedef union { + struct ILI9341ParamBits_GET_CABC_MIN { + uint8_t CMB; /* D[7:0] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_GET_CABC_MIN; + +#if 0 /* TODO: Extended command structs.*/ + +typedef union { + struct ILI9341ParamBits { + unsigned : 1; /* D[] */ + unsigned : 1; /* D[] */ + unsigned : 1; /* D[] */ + unsigned : 1; /* D[] */ + unsigned : 1; /* D[] */ + unsigned : 1; /* D[] */ + unsigned : 1; /* D[] */ + unsigned : 1; /* D[] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_; + +typedef union { + struct ILI9341ParamBits { + unsigned : 1; /* D[] */ + unsigned : 1; /* D[] */ + unsigned : 1; /* D[] */ + unsigned : 1; /* D[] */ + unsigned : 1; /* D[] */ + unsigned : 1; /* D[] */ + unsigned : 1; /* D[] */ + unsigned : 1; /* D[] */ + } bits; + uint8_t bytes[1]; +} ILI9341Params_; + +#endif /*0*/ + +#pragma pack(pop) + +#endif /* ILI9341_H */ diff --git a/drivers/gdisp/STM32F429iDiscovery/readme.txt b/drivers/gdisp/STM32F429iDiscovery/readme.txt new file mode 100644 index 00000000..ce2dd03b --- /dev/null +++ b/drivers/gdisp/STM32F429iDiscovery/readme.txt @@ -0,0 +1,11 @@ +To use this driver: + +1. Add in your gfxconf.h: + a) #define GFX_USE_GDISP TRUE + +2. To your makefile add the following lines: + include $(GFXLIB)/gfx.mk + include $(GFXLIB)/drivers/gdisp/STM32F429iDiscovery/driver.mk + +3. Add a board_STM32F429iDiscovery.h to you project directory (or board directory) + base on one of the templates. diff --git a/drivers/gdisp/STM32F429iDiscovery/stm32_ltdc.h b/drivers/gdisp/STM32F429iDiscovery/stm32_ltdc.h new file mode 100644 index 00000000..dd7c94e8 --- /dev/null +++ b/drivers/gdisp/STM32F429iDiscovery/stm32_ltdc.h @@ -0,0 +1,551 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef STM32_LTDC_H +#define STM32_LTDC_H + +// LTDC enable flags +#define LTDC_EF_ENABLE (1 << 0) /**< LTDC enabled.*/ +#define LTDC_EF_DITHER (1 << 16) /**< Dithering enabled.*/ +#define LTDC_EF_PIXCLK_INVERT (1 << 28) /**< Inverted pixel clock.*/ +#define LTDC_EF_DATAEN_HIGH (1 << 29) /**< Active-high data enable.*/ +#define LTDC_EF_VSYNC_HIGH (1 << 30) /**< Active-high vsync.*/ +#define LTDC_EF_HSYNC_HIGH (1 << 31) /**< Active-high hsync.*/ + +#define LTDC_EF_MASK (LTDC_EF_ENABLE | LTDC_EF_DITHER | LTDC_EF_PIXCLK_INVERT | LTDC_EF_DATAEN_HIGH | LTDC_EF_VSYNC_HIGH | LTDC_EF_HSYNC_HIGH) + +// LTDC layer enable flags +#define LTDC_LEF_ENABLE (1 << 0) /**< Layer enabled*/ +#define LTDC_LEF_KEYING (1 << 1) /**< Color keying enabled.*/ +#define LTDC_LEF_PALETTE (1 << 4) /**< Palette enabled.*/ + +#define LTDC_LEF_MASK (LTDC_LEF_ENABLE | LTDC_LEF_KEYING | LTDC_LEF_PALETTE) + +// LTDC pixel formats +#define LTDC_FMT_ARGB8888 0 /**< ARGB-8888 format.*/ +#define LTDC_FMT_RGB888 1 /**< RGB-888 format.*/ +#define LTDC_FMT_RGB565 2 /**< RGB-565 format.*/ +#define LTDC_FMT_ARGB1555 3 /**< ARGB-1555 format.*/ +#define LTDC_FMT_ARGB4444 4 /**< ARGB-4444 format.*/ +#define LTDC_FMT_L8 5 /**< L-8 format.*/ +#define LTDC_FMT_AL44 6 /**< AL-44 format.*/ +#define LTDC_FMT_AL88 7 /**< AL-88 format.*/ + +// LTDC pixel format aliased raw masks +#define LTDC_XMASK_ARGB8888 0xFFFFFFFF /**< ARGB-8888 aliased mask.*/ +#define LTDC_XMASK_RGB888 0x00FFFFFF /**< RGB-888 aliased mask.*/ +#define LTDC_XMASK_RGB565 0x00F8FCF8 /**< RGB-565 aliased mask.*/ +#define LTDC_XMASK_ARGB1555 0x80F8F8F8 /**< ARGB-1555 aliased mask.*/ +#define LTDC_XMASK_ARGB4444 0xF0F0F0F0 /**< ARGB-4444 aliased mask.*/ +#define LTDC_XMASK_L8 0x000000FF /**< L-8 aliased mask.*/ +#define LTDC_XMASK_AL44 0xF00000F0 /**< AL-44 aliased mask.*/ +#define LTDC_XMASK_AL88 0xFF0000FF /**< AL-88 aliased mask.*/ + +// LTDC blending factors +#define LTDC_BLEND_FIX1_FIX2 0x0405 /**< cnst1; 1 - cnst2 */ +#define LTDC_BLEND_FIX1_MOD2 0x0407 /**< cnst1; 1 - a2 * cnst2 */ +#define LTDC_BLEND_MOD1_FIX2 0x0605 /**< a1 * cnst1; 1 - cnst2 */ +#define LTDC_BLEND_MOD1_MOD2 0x0607 /**< a1 * cnst1; 1 - a2 * cnst2 */ + +// LTDC parameter bounds +#define LTDC_MIN_SCREEN_WIDTH 1 +#define LTDC_MIN_SCREEN_HEIGHT 1 +#define LTDC_MAX_SCREEN_WIDTH 800 +#define LTDC_MAX_SCREEN_HEIGHT 600 + +#define LTDC_MIN_HSYNC_WIDTH 1 +#define LTDC_MIN_VSYNC_HEIGHT 1 +#define LTDC_MAX_HSYNC_WIDTH (1 << 12) +#define LTDC_MAX_VSYNC_HEIGHT (1 << 11) + +#define LTDC_MIN_HBP_WIDTH 0 +#define LTDC_MIN_VBP_HEIGHT 0 +#define LTDC_MAX_HBP_WIDTH (1 << 12) +#define LTDC_MAX_VBP_HEIGHT (1 << 11) + +#define LTDC_MIN_ACC_HBP_WIDTH 1 +#define LTDC_MIN_ACC_VBP_HEIGHT 1 +#define LTDC_MAX_ACC_HBP_WIDTH (1 << 12) +#define LTDC_MAX_ACC_VBP_HEIGHT (1 << 11) + +#define LTDC_MIN_HFP_WIDTH 0 +#define LTDC_MIN_VFP_HEIGHT 0 +#define LTDC_MAX_HFP_WIDTH (1 << 12) +#define LTDC_MAX_VFP_HEIGHT (1 << 11) + +#define LTDC_MIN_ACTIVE_WIDTH 0 +#define LTDC_MIN_ACTIVE_HEIGHT 0 +#define LTDC_MAX_ACTIVE_WIDTH (1 << 12) +#define LTDC_MAX_ACTIVE_HEIGHT (1 << 11) + +#define LTDC_MIN_ACC_ACTIVE_WIDTH 1 +#define LTDC_MIN_ACC_ACTIVE_HEIGHT 1 +#define LTDC_MAX_ACC_ACTIVE_WIDTH (1 << 12) +#define LTDC_MAX_ACC_ACTIVE_HEIGHT (1 << 11) + +#define LTDC_MIN_ACC_TOTAL_WIDTH 1 +#define LTDC_MIN_ACC_TOTAL_HEIGHT 1 +#define LTDC_MAX_ACC_TOTAL_WIDTH (1 << 12) +#define LTDC_MAX_ACC_TOTAL_HEIGHT (1 << 11) + +#define LTDC_MIN_LINE_INTERRUPT_POS 0 +#define LTDC_MAX_LINE_INTERRUPT_POS ((1 << 11) - 1) + +#define LTDC_MIN_WINDOW_HSTART 0 +#define LTDC_MIN_WINDOW_HSTART 0 +#define LTDC_MAX_WINDOW_HSTOP ((1 << 12) - 1) +#define LTDC_MAX_WINDOW_HSTOP ((1 << 12) - 1) + +#define LTDC_MIN_WINDOW_VSTART 0 +#define LTDC_MIN_WINDOW_VSTART 0 +#define LTDC_MAX_WINDOW_VSTOP ((1 << 11) - 1) +#define LTDC_MAX_WINDOW_VSTOP ((1 << 11) - 1) + +#define LTDC_MIN_FRAME_WIDTH_BYTES 0 +#define LTDC_MIN_FRAME_HEIGHT_LINES 0 +#define LTDC_MIN_FRAME_PITCH_BYTES 0 +#define LTDC_MAX_FRAME_WIDTH_BYTES ((1 << 13) - 1 - 3) +#define LTDC_MAX_FRAME_HEIGHT_LINES ((1 << 11) - 1) +#define LTDC_MAX_FRAME_PITCH_BYTES ((1 << 13) - 1) + +#define LTDC_MIN_PIXFMT_ID 0 +#define LTDC_MAX_PIXFMT_ID 7 + +#define LTDC_MAX_PALETTE_LENGTH 256 + +// LTDC basic ARGB-8888 colors. +#define LTDC_COLOR_BLACK 0xFF000000 +#define LTDC_COLOR_MAROON 0xFF800000 +#define LTDC_COLOR_GREEN 0xFF008000 +#define LTDC_COLOR_OLIVE 0xFF808000 +#define LTDC_COLOR_NAVY 0xFF000080 +#define LTDC_COLOR_PURPLE 0xFF800080 +#define LTDC_COLOR_TEAL 0xFF008080 +#define LTDC_COLOR_SILVER 0xFFC0C0C0 +#define LTDC_COLOR_GRAY 0xFF808080 +#define LTDC_COLOR_RED 0xFFFF0000 +#define LTDC_COLOR_LIME 0xFF00FF00 +#define LTDC_COLOR_YELLOW 0xFFFFFF00 +#define LTDC_COLOR_BLUE 0xFF0000FF +#define LTDC_COLOR_FUCHSIA 0xFFFF00FF +#define LTDC_COLOR_AQUA 0xFF00FFFF +#define LTDC_COLOR_WHITE 0xFFFFFFFF + +/**/ +#define STM32_LTDC_EV_HANDLER LTDC_EV_IRQHandler +#define STM32_LTDC_ER_HANDLER LTDC_ER_IRQHandler +#define STM32_LTDC_EV_NUMBER LTDC_IRQn +#define STM32_LTDC_ER_NUMBER LTDC_ER_IRQn +#define LTDC_EV_IRQHandler Vector1A0 +#define LTDC_ER_IRQHandler Vector1A4 + +#define STM32_LTDC_EV_IRQ_PRIORITY 11 +#define STM32_LTDC_ER_IRQ_PRIORITY 11 +#define LTDC_USE_WAIT TRUE +#define LTDC_USE_SOFTWARE_CONVERSIONS TRUE + +#ifndef STM32F429_439xx +#error "Currently only STM32F429xx and STM32F439xx are supported" +#endif + +/*===========================================================================*/ +/* Driver data structures and types. */ +/*===========================================================================*/ + +/* Complex types forwarding.*/ +typedef union ltdc_coloralias_t ltdc_coloralias_t; +typedef struct ltdc_window_t ltdc_window_t; +typedef struct ltdc_frame_t ltdc_frame_t; +typedef struct ltdc_laycfg_t ltdc_laycfg_t; +typedef struct LTDCConfig LTDCConfig; +typedef enum ltdc_state_t ltdc_state_t; +typedef struct LTDCDriver LTDCDriver; + +/** + * @name LTDC Data types + * @{ + */ + +/** + * @brief LTDC generic color. + */ +typedef uint32_t ltdc_color_t; + +/** + * @brief LTDC color aliases. + * @detail Mapped with ARGB-8888, except for luminance (L mapped onto B). + * Padding fields prefixed with 'x', which should be clear + * (all 0) before compression and set (all 1) after expansion. + */ +typedef union ltdc_coloralias_t { + struct { + unsigned b : 8; + unsigned g : 8; + unsigned r : 8; + unsigned a : 8; + } argb8888; /**< Mapped ARGB-8888 bits.*/ + struct { + unsigned b : 8; + unsigned g : 8; + unsigned r : 8; + unsigned xa : 8; + } rgb888; /**< Mapped RGB-888 bits.*/ + struct { + unsigned xb : 3; + unsigned b : 5; + unsigned xg : 2; + unsigned g : 6; + unsigned xr : 3; + unsigned r : 5; + unsigned xa : 8; + } rgb565; /**< Mapped RGB-565 bits.*/ + struct { + unsigned xb : 3; + unsigned b : 5; + unsigned xg : 3; + unsigned g : 5; + unsigned xr : 3; + unsigned r : 5; + unsigned xa : 7; + unsigned a : 1; + } argb1555; /**< Mapped ARGB-1555 values.*/ + struct { + unsigned xb : 4; + unsigned b : 4; + unsigned xg : 4; + unsigned g : 4; + unsigned xr : 4; + unsigned r : 4; + unsigned xa : 4; + unsigned a : 4; + } argb4444; /**< Mapped ARGB-4444 values.*/ + struct { + unsigned l : 8; + unsigned x : 16; + unsigned xa : 8; + } l8; /**< Mapped L-8 bits.*/ + struct { + unsigned xl : 4; + unsigned l : 4; + unsigned x : 16; + unsigned xa : 4; + unsigned a : 4; + } al44; /**< Mapped AL-44 bits.*/ + struct { + unsigned l : 8; + unsigned x : 16; + unsigned a : 8; + } al88; /**< Mapped AL-88 bits.*/ + ltdc_color_t aliased; /**< Aliased raw bits.*/ +} ltdc_coloralias_t; + +/** + * @brief LTDC layer identifier. + */ +typedef uint32_t ltdc_layerid_t; + +/** + * @brief LTDC pixel format. + */ +typedef uint32_t ltdc_pixfmt_t; + +/** + * @brief LTDC blending factor. + */ +typedef uint32_t ltdc_blendf_t; + +/** + * @brief LTDC ISR callback. + */ +typedef void (*ltdc_isrcb_t)(LTDCDriver *ltdcp); + +/** + * @brief LTDC window specifications. + */ +typedef struct ltdc_window_t { + uint16_t hstart; /**< Horizontal start pixel (left).*/ + uint16_t hstop; /**< Horizontal stop pixel (right).*/ + uint16_t vstart; /**< Vertical start pixel (top).*/ + uint16_t vstop; /**< Vertical stop pixel (bottom).*/ +} ltdc_window_t; + +/** + * @brief LTDC frame specifications. + */ +typedef struct ltdc_frame_t { + void *bufferp; /**< Frame buffer address.*/ + uint16_t width; /**< Frame width, in pixels.*/ + uint16_t height; /**< Frame height, in pixels.*/ + size_t pitch; /**< Line pitch, in bytes.*/ + ltdc_pixfmt_t fmt; /**< Pixel format.*/ +} ltdc_frame_t; + +/** + * @brief LTDC configuration flags. + */ +typedef uint8_t ltdc_flags_t; + +/** + * @brief LTDC startup layer configuration. + */ +typedef struct ltdc_laycfg_t { + const ltdc_frame_t *frame; /**< Frame buffer specifications.*/ + const ltdc_window_t *window; /**< Window specifications.*/ + ltdc_color_t def_color; /**< Default color, ARGB-8888.*/ + uint8_t const_alpha; /**< Constant alpha factor.*/ + ltdc_color_t key_color; /**< Color key.*/ + const ltdc_color_t *pal_colors; /**< Palette colors, or @p NULL.*/ + uint16_t pal_length; /**< Palette length, or @p 0.*/ + ltdc_blendf_t blending; /**< Blending factors.*/ + ltdc_flags_t flags; /**< Layer configuration flags.*/ +} ltdc_laycfg_t; + +/** + * @brief LTDC driver configuration. + */ +typedef struct LTDCConfig { + /* Display specifications.*/ + uint16_t screen_width; /**< Screen pixel width.*/ + uint16_t screen_height; /**< Screen pixel height.*/ + uint16_t hsync_width; /**< Horizontal sync pixel width.*/ + uint16_t vsync_height; /**< Vertical sync pixel height.*/ + uint16_t hbp_width; /**< Horizontal back porch pixel width.*/ + uint16_t vbp_height; /**< Vertical back porch pixel height.*/ + uint16_t hfp_width; /**< Horizontal front porch pixel width.*/ + uint16_t vfp_height; /**< Vertical front porch pixel height.*/ + ltdc_flags_t flags; /**< Driver configuration flags.*/ + + /* ISR callbacks.*/ + ltdc_isrcb_t line_isr; /**< Line Interrupt ISR, or @p NULL.*/ + ltdc_isrcb_t rr_isr; /**< Register Reload ISR, or @p NULL.*/ + ltdc_isrcb_t fuerr_isr; /**< FIFO Underrun ISR, or @p NULL.*/ + ltdc_isrcb_t terr_isr; /**< Transfer Error ISR, or @p NULL.*/ + + /* Layer and color settings.*/ + ltdc_color_t clear_color; /**< Clear screen color, RGB-888.*/ + const ltdc_laycfg_t *bg_laycfg; /**< Background layer specs, or @p NULL.*/ + const ltdc_laycfg_t *fg_laycfg; /**< Foreground layer specs, or @p NULL.*/ +} LTDCConfig; + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/** + * @brief Makes an ARGB-8888 value from byte components. + * + * @param[in] a alpha byte component + * @param[in] r red byte component + * @param[in] g green byte component + * @param[in] b blue byte component + * + * @return color in ARGB-8888 format + * + * @api + */ +#define ltdcMakeARGB8888(a, r, g, b) \ + ((((ltdc_color_t)(a) & 0xFF) << 24) | \ + (((ltdc_color_t)(r) & 0xFF) << 16) | \ + (((ltdc_color_t)(g) & 0xFF) << 8) | \ + (((ltdc_color_t)(b) & 0xFF) << 0)) + +/** + * @brief Compute bytes per pixel. + * @details Computes the bytes per pixel for the specified pixel format. + * Rounds to the ceiling. + * + * @param[in] fmt pixel format + * + * @return bytes per pixel + * + * @api + */ +#define ltdcBytesPerPixel(fmt) \ + ((ltdcBitsPerPixel(fmt) + 7) >> 3) + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + + /* Global methods.*/ + ltdc_flags_t ltdcGetEnableFlagsI(LTDCDriver *ltdcp); + ltdc_flags_t ltdcGetEnableFlags(LTDCDriver *ltdcp); + void ltdcSetEnableFlagsI(LTDCDriver *ltdcp, ltdc_flags_t flags); + void ltdcSetEnableFlags(LTDCDriver *ltdcp, ltdc_flags_t flags); + bool_t ltdcIsReloadingI(LTDCDriver *ltdcp); + bool_t ltdcIsReloading(LTDCDriver *ltdcp); + void ltdcStartReloadI(LTDCDriver *ltdcp, bool_t immediately); + void ltdcStartReload(LTDCDriver *ltdcp, bool_t immediately); + void ltdcReloadS(LTDCDriver *ltdcp, bool_t immediately); + void ltdcReload(LTDCDriver *ltdcp, bool_t immediately); + bool_t ltdcIsDitheringEnabledI(LTDCDriver *ltdcp); + bool_t ltdcIsDitheringEnabled(LTDCDriver *ltdcp); + void ltdcEnableDitheringI(LTDCDriver *ltdcp); + void ltdcEnableDithering(LTDCDriver *ltdcp); + void ltdcDisableDitheringI(LTDCDriver *ltdcp); + void ltdcDisableDithering(LTDCDriver *ltdcp); + ltdc_color_t ltdcGetClearColorI(LTDCDriver *ltdcp); + ltdc_color_t ltdcGetClearColor(LTDCDriver *ltdcp); + void ltdcSetClearColorI(LTDCDriver *ltdcp, ltdc_color_t c); + void ltdcSetClearColor(LTDCDriver *ltdcp, ltdc_color_t c); + uint16_t ltdcGetLineInterruptPosI(LTDCDriver *ltdcp); + uint16_t ltdcGetLineInterruptPos(LTDCDriver *ltdcp); + void ltdcSetLineInterruptPosI(LTDCDriver *ltdcp, uint16_t line); + void ltdcSetLineInterruptPos(LTDCDriver *ltdcp, uint16_t line); + bool_t ltdcIsLineInterruptEnabledI(LTDCDriver *ltdcp); + bool_t ltdcIsLineInterruptEnabled(LTDCDriver *ltdcp); + void ltdcEnableLineInterruptI(LTDCDriver *ltdcp); + void ltdcEnableLineInterrupt(LTDCDriver *ltdcp); + void ltdcDisableLineInterruptI(LTDCDriver *ltdcp); + void ltdcDisableLineInterrupt(LTDCDriver *ltdcp); + void ltdcGetCurrentPosI(LTDCDriver *ltdcp, uint16_t *xp, uint16_t *yp); + void ltdcGetCurrentPos(LTDCDriver *ltdcp, uint16_t *xp, uint16_t *yp); + + /* Background layer methods.*/ + ltdc_flags_t ltdcBgGetEnableFlagsI(LTDCDriver *ltdcp); + ltdc_flags_t ltdcBgGetEnableFlags(LTDCDriver *ltdcp); + void ltdcBgSetEnableFlagsI(LTDCDriver *ltdcp, ltdc_flags_t flags); + void ltdcBgSetEnableFlags(LTDCDriver *ltdcp, ltdc_flags_t flags); + bool_t ltdcBgIsEnabledI(LTDCDriver *ltdcp); + bool_t ltdcBgIsEnabled(LTDCDriver *ltdcp); + void ltdcBgEnableI(LTDCDriver *ltdcp); + void ltdcBgEnable(LTDCDriver *ltdcp); + void ltdcBgDisableI(LTDCDriver *ltdcp); + void ltdcBgDisable(LTDCDriver *ltdcp); + bool_t ltdcBgIsPaletteEnabledI(LTDCDriver *ltdcp); + bool_t ltdcBgIsPaletteEnabled(LTDCDriver *ltdcp); + void ltdcBgEnablePaletteI(LTDCDriver *ltdcp); + void ltdcBgEnablePalette(LTDCDriver *ltdcp); + void ltdcBgDisablePaletteI(LTDCDriver *ltdcp); + void ltdcBgDisablePalette(LTDCDriver *ltdcp); + void ltdcBgSetPaletteColorI(LTDCDriver *ltdcp, uint8_t slot, ltdc_color_t c); + void ltdcBgSetPaletteColor(LTDCDriver *ltdcp, uint8_t slot, ltdc_color_t c); + void ltdcBgSetPaletteI(LTDCDriver *ltdcp, const ltdc_color_t colors[], + uint16_t length); + void ltdcBgSetPalette(LTDCDriver *ltdcp, const ltdc_color_t colors[], + uint16_t length); + ltdc_pixfmt_t ltdcBgGetPixelFormatI(LTDCDriver *ltdcp); + ltdc_pixfmt_t ltdcBgGetPixelFormat(LTDCDriver *ltdcp); + void ltdcBgSetPixelFormatI(LTDCDriver *ltdcp, ltdc_pixfmt_t fmt); + void ltdcBgSetPixelFormat(LTDCDriver *ltdcp, ltdc_pixfmt_t fmt); + bool_t ltdcBgIsKeyingEnabledI(LTDCDriver *ltdcp); + bool_t ltdcBgIsKeyingEnabled(LTDCDriver *ltdcp); + void ltdcBgEnableKeyingI(LTDCDriver *ltdcp); + void ltdcBgEnableKeying(LTDCDriver *ltdcp); + void ltdcBgDisableKeyingI(LTDCDriver *ltdcp); + void ltdcBgDisableKeying(LTDCDriver *ltdcp); + ltdc_color_t ltdcBgGetKeyingColorI(LTDCDriver *ltdcp); + ltdc_color_t ltdcBgGetKeyingColor(LTDCDriver *ltdcp); + void ltdcBgSetKeyingColorI(LTDCDriver *ltdcp, ltdc_color_t c); + void ltdcBgSetKeyingColor(LTDCDriver *ltdcp, ltdc_color_t c); + uint8_t ltdcBgGetConstantAlphaI(LTDCDriver *ltdcp); + uint8_t ltdcBgGetConstantAlpha(LTDCDriver *ltdcp); + void ltdcBgSetConstantAlphaI(LTDCDriver *ltdcp, uint8_t a); + void ltdcBgSetConstantAlpha(LTDCDriver *ltdcp, uint8_t a); + ltdc_color_t ltdcBgGetDefaultColorI(LTDCDriver *ltdcp); + ltdc_color_t ltdcBgGetDefaultColor(LTDCDriver *ltdcp); + void ltdcBgSetDefaultColorI(LTDCDriver *ltdcp, ltdc_color_t c); + void ltdcBgSetDefaultColor(LTDCDriver *ltdcp, ltdc_color_t c); + ltdc_blendf_t ltdcBgGetBlendingFactorsI(LTDCDriver *ltdcp); + ltdc_blendf_t ltdcBgGetBlendingFactors(LTDCDriver *ltdcp); + void ltdcBgSetBlendingFactorsI(LTDCDriver *ltdcp, ltdc_blendf_t bf); + void ltdcBgSetBlendingFactors(LTDCDriver *ltdcp, ltdc_blendf_t bf); + void ltdcBgGetWindowI(LTDCDriver *ltdcp, ltdc_window_t *windowp); + void ltdcBgGetWindow(LTDCDriver *ltdcp, ltdc_window_t *windowp); + void ltdcBgSetWindowI(LTDCDriver *ltdcp, const ltdc_window_t *windowp); + void ltdcBgSetWindow(LTDCDriver *ltdcp, const ltdc_window_t *windowp); + void ltdcBgSetInvalidWindowI(LTDCDriver *ltdcp); + void ltdcBgSetInvalidWindow(LTDCDriver *ltdcp); + void ltdcBgGetFrameI(LTDCDriver *ltdcp, ltdc_frame_t *framep); + void ltdcBgGetFrame(LTDCDriver *ltdcp, ltdc_frame_t *framep); + void ltdcBgSetFrameI(LTDCDriver *ltdcp, const ltdc_frame_t *framep); + void ltdcBgSetFrame(LTDCDriver *ltdcp, const ltdc_frame_t *framep); + void *ltdcBgGetFrameAddressI(LTDCDriver *ltdcp); + void *ltdcBgGetFrameAddress(LTDCDriver *ltdcp); + void ltdcBgSetFrameAddressI(LTDCDriver *ltdcp, void *bufferp); + void ltdcBgSetFrameAddress(LTDCDriver *ltdcp, void *bufferp); + void ltdcBgGetLayerI(LTDCDriver *ltdcp, ltdc_laycfg_t *cfgp); + void ltdcBgGetLayer(LTDCDriver *ltdcp, ltdc_laycfg_t *cfgp); + void ltdcBgSetConfigI(LTDCDriver *ltdcp, const ltdc_laycfg_t *cfgp); + void ltdcBgSetConfig(LTDCDriver *ltdcp, const ltdc_laycfg_t *cfgp); + + /* Foreground layer methods.*/ + ltdc_flags_t ltdcFgGetEnableFlagsI(LTDCDriver *ltdcp); + ltdc_flags_t ltdcFgGetEnableFlags(LTDCDriver *ltdcp); + void ltdcFgSetEnableFlagsI(LTDCDriver *ltdcp, ltdc_flags_t flags); + void ltdcFgSetEnableFlags(LTDCDriver *ltdcp, ltdc_flags_t flags); + bool_t ltdcFgIsEnabledI(LTDCDriver *ltdcp); + bool_t ltdcFgIsEnabled(LTDCDriver *ltdcp); + void ltdcFgEnableI(LTDCDriver *ltdcp); + void ltdcFgEnable(LTDCDriver *ltdcp); + void ltdcFgDisableI(LTDCDriver *ltdcp); + void ltdcFgDisable(LTDCDriver *ltdcp); + bool_t ltdcFgIsPaletteEnabledI(LTDCDriver *ltdcp); + bool_t ltdcFgIsPaletteEnabled(LTDCDriver *ltdcp); + void ltdcFgEnablePaletteI(LTDCDriver *ltdcp); + void ltdcFgEnablePalette(LTDCDriver *ltdcp); + void ltdcFgDisablePaletteI(LTDCDriver *ltdcp); + void ltdcFgDisablePalette(LTDCDriver *ltdcp); + void ltdcFgSetPaletteColorI(LTDCDriver *ltdcp, uint8_t slot, ltdc_color_t c); + void ltdcFgSetPaletteColor(LTDCDriver *ltdcp, uint8_t slot, ltdc_color_t c); + void ltdcFgSetPaletteI(LTDCDriver *ltdcp, const ltdc_color_t colors[], + uint16_t length); + void ltdcFgSetPalette(LTDCDriver *ltdcp, const ltdc_color_t colors[], + uint16_t length); + ltdc_pixfmt_t ltdcFgGetPixelFormatI(LTDCDriver *ltdcp); + ltdc_pixfmt_t ltdcFgGetPixelFormat(LTDCDriver *ltdcp); + void ltdcFgSetPixelFormatI(LTDCDriver *ltdcp, ltdc_pixfmt_t fmt); + void ltdcFgSetPixelFormat(LTDCDriver *ltdcp, ltdc_pixfmt_t fmt); + bool_t ltdcFgIsKeyingEnabledI(LTDCDriver *ltdcp); + bool_t ltdcFgIsKeyingEnabled(LTDCDriver *ltdcp); + void ltdcFgEnableKeyingI(LTDCDriver *ltdcp); + void ltdcFgEnableKeying(LTDCDriver *ltdcp); + void ltdcFgDisableKeyingI(LTDCDriver *ltdcp); + void ltdcFgDisableKeying(LTDCDriver *ltdcp); + ltdc_color_t ltdcFgGetKeyingColorI(LTDCDriver *ltdcp); + ltdc_color_t ltdcFgGetKeyingColor(LTDCDriver *ltdcp); + void ltdcFgSetKeyingColorI(LTDCDriver *ltdcp, ltdc_color_t c); + void ltdcFgSetKeyingColor(LTDCDriver *ltdcp, ltdc_color_t c); + uint8_t ltdcFgGetConstantAlphaI(LTDCDriver *ltdcp); + uint8_t ltdcFgGetConstantAlpha(LTDCDriver *ltdcp); + void ltdcFgSetConstantAlphaI(LTDCDriver *ltdcp, uint8_t a); + void ltdcFgSetConstantAlpha(LTDCDriver *ltdcp, uint8_t a); + ltdc_color_t ltdcFgGetDefaultColorI(LTDCDriver *ltdcp); + ltdc_color_t ltdcFgGetDefaultColor(LTDCDriver *ltdcp); + void ltdcFgSetDefaultColorI(LTDCDriver *ltdcp, ltdc_color_t c); + void ltdcFgSetDefaultColor(LTDCDriver *ltdcp, ltdc_color_t c); + ltdc_blendf_t ltdcFgGetBlendingFactorsI(LTDCDriver *ltdcp); + ltdc_blendf_t ltdcFgGetBlendingFactors(LTDCDriver *ltdcp); + void ltdcFgSetBlendingFactorsI(LTDCDriver *ltdcp, ltdc_blendf_t bf); + void ltdcFgSetBlendingFactors(LTDCDriver *ltdcp, ltdc_blendf_t bf); + void ltdcFgGetWindowI(LTDCDriver *ltdcp, ltdc_window_t *windowp); + void ltdcFgGetWindow(LTDCDriver *ltdcp, ltdc_window_t *windowp); + void ltdcFgSetWindowI(LTDCDriver *ltdcp, const ltdc_window_t *windowp); + void ltdcFgSetWindow(LTDCDriver *ltdcp, const ltdc_window_t *windowp); + void ltdcFgSetInvalidWindowI(LTDCDriver *ltdcp); + void ltdcFgSetInvalidWindow(LTDCDriver *ltdcp); + void ltdcFgGetFrameI(LTDCDriver *ltdcp, ltdc_frame_t *framep); + void ltdcFgGetFrame(LTDCDriver *ltdcp, ltdc_frame_t *framep); + void ltdcFgSetFrameI(LTDCDriver *ltdcp, const ltdc_frame_t *framep); + void ltdcFgSetFrame(LTDCDriver *ltdcp, const ltdc_frame_t *framep); + void *ltdcFgGetFrameAddressI(LTDCDriver *ltdcp); + void *ltdcFgGetFrameAddress(LTDCDriver *ltdcp); + void ltdcFgSetFrameAddressI(LTDCDriver *ltdcp, void *bufferp); + void ltdcFgSetFrameAddress(LTDCDriver *ltdcp, void *bufferp); + void ltdcFgGetLayerI(LTDCDriver *ltdcp, ltdc_laycfg_t *cfgp); + void ltdcFgGetLayer(LTDCDriver *ltdcp, ltdc_laycfg_t *cfgp); + void ltdcFgSetConfigI(LTDCDriver *ltdcp, const ltdc_laycfg_t *cfgp); + void ltdcFgSetConfig(LTDCDriver *ltdcp, const ltdc_laycfg_t *cfgp); + + /* Helper functions.*/ + size_t ltdcBitsPerPixel(ltdc_pixfmt_t fmt); +#if LTDC_USE_SOFTWARE_CONVERSIONS || defined(__DOXYGEN__) + ltdc_color_t ltdcFromARGB8888(ltdc_color_t c, ltdc_pixfmt_t fmt); + ltdc_color_t ltdcToARGB8888(ltdc_color_t c, ltdc_pixfmt_t fmt); +#endif /* LTDC_USE_SOFTWARE_CONVERSIONS */ + +#endif /* STM32_LTDC_H */ From 541975a396cf4107e91bd782cc18412c8d898292 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Wed, 5 Nov 2014 21:32:12 +0100 Subject: [PATCH 76/87] Adding STM32F429i-Discovery touch support (not working yet) --- boards/base/STM32F429i-Discovery/board.mk | 3 +- .../example_chibios_2.x/halconf.h | 2 +- .../example_chibios_2.x/mcuconf.h | 2 +- .../gmouse_lld_STMPE811_board.h | 116 ++++++++++++++++++ 4 files changed, 119 insertions(+), 4 deletions(-) create mode 100644 boards/base/STM32F429i-Discovery/gmouse_lld_STMPE811_board.h diff --git a/boards/base/STM32F429i-Discovery/board.mk b/boards/base/STM32F429i-Discovery/board.mk index c8dc7117..09116393 100644 --- a/boards/base/STM32F429i-Discovery/board.mk +++ b/boards/base/STM32F429i-Discovery/board.mk @@ -4,5 +4,4 @@ GFXSRC += $(GFXLIB)/boards/base/STM32F429i-Discovery/stm32f429i_discovery_sdram GFXDEFS += -DGFX_USE_OS_CHIBIOS=TRUE include $(GFXLIB)/drivers/gdisp/STM32F429iDiscovery/driver.mk -#include $(GFXLIB)/drivers/ginput/touch/MCU/driver.mk -#include $(GFXLIB)/drivers/gaudio/vs1053/driver.mk +include $(GFXLIB)/drivers/ginput/touch/STMPE811/driver.mk diff --git a/boards/base/STM32F429i-Discovery/example_chibios_2.x/halconf.h b/boards/base/STM32F429i-Discovery/example_chibios_2.x/halconf.h index e0ef55fe..8c45a63b 100644 --- a/boards/base/STM32F429i-Discovery/example_chibios_2.x/halconf.h +++ b/boards/base/STM32F429i-Discovery/example_chibios_2.x/halconf.h @@ -76,7 +76,7 @@ * @brief Enables the I2C subsystem. */ #if !defined(HAL_USE_I2C) || defined(__DOXYGEN__) -#define HAL_USE_I2C FALSE +#define HAL_USE_I2C TRUE #endif /** diff --git a/boards/base/STM32F429i-Discovery/example_chibios_2.x/mcuconf.h b/boards/base/STM32F429i-Discovery/example_chibios_2.x/mcuconf.h index d0b1d6a4..222958fe 100644 --- a/boards/base/STM32F429i-Discovery/example_chibios_2.x/mcuconf.h +++ b/boards/base/STM32F429i-Discovery/example_chibios_2.x/mcuconf.h @@ -138,7 +138,7 @@ */ #define STM32_I2C_USE_I2C1 FALSE #define STM32_I2C_USE_I2C2 FALSE -#define STM32_I2C_USE_I2C3 FALSE +#define STM32_I2C_USE_I2C3 TRUE #define STM32_I2C_I2C1_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0) #define STM32_I2C_I2C1_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 6) #define STM32_I2C_I2C2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2) diff --git a/boards/base/STM32F429i-Discovery/gmouse_lld_STMPE811_board.h b/boards/base/STM32F429i-Discovery/gmouse_lld_STMPE811_board.h new file mode 100644 index 00000000..53c15e86 --- /dev/null +++ b/boards/base/STM32F429i-Discovery/gmouse_lld_STMPE811_board.h @@ -0,0 +1,116 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _GINPUT_LLD_MOUSE_BOARD_H +#define _GINPUT_LLD_MOUSE_BOARD_H + +// Resolution and Accuracy Settings +#define GMOUSE_STMPE811_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_STMPE811_PEN_CLICK_ERROR 6 +#define GMOUSE_STMPE811_PEN_MOVE_ERROR 4 +#define GMOUSE_STMPE811_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_STMPE811_FINGER_CLICK_ERROR 18 +#define GMOUSE_STMPE811_FINGER_MOVE_ERROR 14 + +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_STMPE811_BOARD_DATA_SIZE 0 + +// Set this to TRUE if you want self-calibration. +// NOTE: This is not as accurate as real calibration. +// It requires the orientation of the touch panel to match the display. +// It requires the active area of the touch panel to exactly match the display size. +#define GMOUSE_STMPE811_SELF_CALIBRATE FALSE + +// If TRUE this board has the STMPE811 IRQ pin connected to a GPIO. +#define GMOUSE_STMPE811_GPIO_IRQPIN TRUE + +// If TRUE this is a really slow CPU and we should always clear the FIFO between reads. +#define GMOUSE_STMPE811_SLOW_CPU FALSE + +// Maximum timeout +#define STMPE811_TIMEOUT 0x3000 + +static const I2CConfig i2ccfg = { + OPMODE_I2C, + 400000, + FAST_DUTY_CYCLE_2, +}; + +static bool_t init_board(GMouse* m, unsigned driverinstance) { + (void) m; + + // This board only supports one touch panel + if (driverinstance) + return FALSE; + + palSetPadMode(GPIOA, 15, PAL_MODE_INPUT | PAL_STM32_PUDR_FLOATING); /* TP IRQ */ + palSetPadMode(GPIOA, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SCL */ + palSetPadMode(GPIOC, 9, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SDA */ + + i2cStart(&I2CD3, &i2ccfg); + + return TRUE; +} + +#if GMOUSE_STMPE811_GPIO_IRQPIN + static bool_t getpin_irq(GMouse* m) { + (void) m; + + return !palReadPad(GPIOA, 15); + } +#endif + +static inline void aquire_bus(GMouse* m) { + (void) m; + +} + +static inline void release_bus(GMouse* m) { + (void) m; + +} + +static void write_reg(GMouse* m, uint8_t reg, uint8_t val) { + uint8_t txbuf[2]; + (void) m; + + txbuf[0] = reg; + txbuf[1] = val; + + i2cAcquireBus(&I2CD3); + i2cMasterTransmitTimeout(&I2CD3, STMPE811_ADDR, txbuf, 2, 0, 0, MS2ST(STMPE811_TIMEOUT)); + i2cReleaseBus(&I2CD3); +} + +static uint8_t read_byte(GMouse* m, uint8_t reg) { + uint8_t rxbuf[1]; + (void) m; + + rxbuf[0] = 0; + + i2cAcquireBus(&I2CD3); + i2cMasterTransmitTimeout(&I2CD3, STMPE811_ADDR, ®, 1, rxbuf, 1, MS2ST(STMPE811_TIMEOUT)); + i2cReleaseBus(&I2CD3); + + return rxbuf[0]; +} + +static uint16_t read_word(GMouse* m, uint8_t reg) { + uint8_t rxbuf[2]; + (void) m; + + rxbuf[0] = 0; + rxbuf[1] = 0; + + i2cAcquireBus(&I2CD3); + i2cMasterTransmitTimeout(&I2CD3, STMPE811_ADDR, ®, 1, rxbuf, 2, MS2ST(STMPE811_TIMEOUT)); + i2cReleaseBus(&I2CD3); + + return (((uint16_t)rxbuf[0]) << 8) | rxbuf[1]; +} + +#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ From f552ba62afc6cdb72fbb1b4dcdcc96000895a1cd Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 7 Nov 2014 12:00:46 +1000 Subject: [PATCH 77/87] New touch testing tool which displays raw readings from the touch driver --- tools/touch_raw_readings/gfxconf.h | 62 ++++++++++++++++ tools/touch_raw_readings/main.c | 110 +++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 tools/touch_raw_readings/gfxconf.h create mode 100644 tools/touch_raw_readings/main.c diff --git a/tools/touch_raw_readings/gfxconf.h b/tools/touch_raw_readings/gfxconf.h new file mode 100644 index 00000000..3d93a138 --- /dev/null +++ b/tools/touch_raw_readings/gfxconf.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2012, 2013, Joel Bodenmann aka Tectu + * Copyright (c) 2012, 2013, Andrew Hannam aka inmarket + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _GFXCONF_H +#define _GFXCONF_H + +/* The operating system to use. One of these must be defined - preferably in your Makefile */ +//#define GFX_USE_OS_CHIBIOS FALSE +//#define GFX_USE_OS_WIN32 FALSE +//#define GFX_USE_OS_LINUX FALSE +//#define GFX_USE_OS_OSX FALSE + +/* GFX sub-systems to turn on */ +#define GFX_USE_GDISP TRUE +#define GFX_USE_GWIN TRUE +#define GFX_USE_GEVENT TRUE +#define GFX_USE_GTIMER TRUE +#define GFX_USE_GINPUT TRUE + +/* Features for the GDISP sub-system. */ +#define GDISP_NEED_VALIDATION TRUE +#define GDISP_NEED_CLIP TRUE +#define GDISP_NEED_TEXT TRUE +#define GDISP_NEED_MULTITHREAD TRUE + +/* Builtin Fonts */ +#define GDISP_INCLUDE_FONT_UI2 TRUE + +/* Features for the GWIN sub-system. */ +#define GWIN_NEED_CONSOLE TRUE + +/* Features for the GINPUT sub-system. */ +#define GINPUT_NEED_MOUSE TRUE +#define GINPUT_TOUCH_STARTRAW TRUE + +#endif /* _GFXCONF_H */ diff --git a/tools/touch_raw_readings/main.c b/tools/touch_raw_readings/main.c new file mode 100644 index 00000000..d6c97920 --- /dev/null +++ b/tools/touch_raw_readings/main.c @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2012, 2013, Joel Bodenmann aka Tectu + * Copyright (c) 2012, 2013, Andrew Hannam aka inmarket + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "gfx.h" + +// We get nasty and look at some internal structures - get the relevant information +#include "src/gdriver/sys_defs.h" +#include "src/ginput/driver_mouse.h" + +#include + +static GConsoleObject gc; +static GListener gl; +static font_t font; +static coord_t bHeight; +static GHandle ghc; +static coord_t swidth, sheight; + +/*------------------------------------------------------------------------* + * GINPUT Touch Driver Calibrator. * + *------------------------------------------------------------------------*/ +int main(void) { + GSourceHandle gs; + GEventMouse *pem; + GMouse * m; + GMouseVMT * vmt; + + gfxInit(); // Initialize the display + + // Get the display dimensions + swidth = gdispGetWidth(); + sheight = gdispGetHeight(); + + // Create our title + font = gdispOpenFont("UI2"); + gwinSetDefaultFont(font); + bHeight = gdispGetFontMetric(font, fontHeight)+4; + gdispFillStringBox(0, 0, swidth, bHeight, "Raw Touch Readings", font, Red, White, justifyCenter); + + // Create our main display writing window + { + GWindowInit wi; + + gwinClearInit(&wi); + wi.show = TRUE; wi.x = 0; wi.y = bHeight; wi.width = swidth; wi.height = sheight-bHeight; + ghc = gwinConsoleCreate(&gc, &wi); + } + + // Initialize the listener + geventListenerInit(&gl); + + // Copy the current mouse's VMT so we can play with it. + m = (GMouse *)gdriverGetInstance(GDRIVER_TYPE_MOUSE, 0); + if (!m) gfxHalt("No mouse instance 0"); + vmt = gfxAlloc(sizeof(GMouseVMT)); + if (!vmt) gfxHalt("Could not allocate memory for mouse VMT"); + memcpy(vmt, m->d.vmt, sizeof(GMouseVMT)); + + // Swap VMT's on the current mouse to our RAM copy + m->d.vmt = (const GDriverVMT *)vmt; + + // Listen for events + gs = ginputGetMouse(0); + geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA); + + // Make sure we are in uncalibrated pen mode + m->flags &= ~(GMOUSE_FLG_CALIBRATE|GMOUSE_FLG_CLIP|GMOUSE_FLG_FINGERMODE); + + // Pretend we are a mouse, turn off all touch processing, turn off move and click filtering + vmt->d.flags &= ~(GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN); + vmt->pen_jitter.move = 0; + vmt->pen_jitter.click = 0; + + // For this test turn on ALL mouse movement events + geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEUPMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER); + + while(1) { + pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE); + gwinPrintf(ghc, "%u, %u z=%u b=0x%04x\n", pem->x, pem->y, pem->z, pem->buttons & ~GINPUT_MISSED_MOUSE_EVENT); + + // Always sleep a bit first to enable other events. We actually don't mind missing events. + gfxSleepMilliseconds(100); + } +} From bd041926b43676e2bf597c98149f9a6df8f8004b Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 7 Nov 2014 12:02:41 +1000 Subject: [PATCH 78/87] Allow a mouse driver to not return any results when it is polled. --- .../Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h | 3 ++- boards/base/Olimex-STM32-LCD/gmouse_lld_MCU_board.h | 3 ++- drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c | 3 ++- drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c | 3 ++- drivers/multiple/Win32/gdisp_lld_Win32.c | 6 ++++-- drivers/multiple/X/gdisp_lld_X.c | 5 +++-- drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c | 5 +++-- src/ginput/driver_mouse.h | 8 ++++---- src/ginput/ginput_mouse.c | 5 +++-- 9 files changed, 25 insertions(+), 16 deletions(-) diff --git a/boards/base/Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h b/boards/base/Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h index 15c00e66..bad8b9ab 100644 --- a/boards/base/Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h +++ b/boards/base/Mikromedia-STM32-M4-ILI9341/gmouse_lld_MCU_board.h @@ -57,7 +57,7 @@ static bool_t init_board(GMouse *m, unsigned driverinstance) { return TRUE; } -static void read_xyz(GMouse *m, GMouseReading *prd) { +static bool_t read_xyz(GMouse *m, GMouseReading *prd) { adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH]; (void) m; @@ -89,6 +89,7 @@ static void read_xyz(GMouse *m, GMouseReading *prd) { palClearPad(GPIOB, GPIOB_DRIVEA); palClearPad(GPIOB, GPIOB_DRIVEB); } + return TRUE; } #endif /* _LLD_GMOUSE_MCU_BOARD_H */ diff --git a/boards/base/Olimex-STM32-LCD/gmouse_lld_MCU_board.h b/boards/base/Olimex-STM32-LCD/gmouse_lld_MCU_board.h index 8c90946f..414587cf 100644 --- a/boards/base/Olimex-STM32-LCD/gmouse_lld_MCU_board.h +++ b/boards/base/Olimex-STM32-LCD/gmouse_lld_MCU_board.h @@ -73,7 +73,7 @@ static bool_t init_board(GMouse *m, unsigned driverinstance) { return TRUE; } -static void read_xyz(GMouse *m, GMouseReading *prd) { +static bool_t read_xyz(GMouse *m, GMouseReading *prd) { adcsample_t samples[ADC_NUM_CHANNELS * ADC_BUF_DEPTH]; uint16_t val1, val2; (void) m; @@ -130,6 +130,7 @@ static void read_xyz(GMouse *m, GMouseReading *prd) { // Set up for reading z again. We know it will be 20ms before we get called again so don't worry about settling time setup_z(); } + return TRUE; } #endif /* _LLD_GMOUSE_MCU_BOARD_H */ diff --git a/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c index ac315262..5f1eb226 100644 --- a/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c +++ b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843.c @@ -19,7 +19,7 @@ #define CMD_Y 0x91 #define CMD_ENABLE_IRQ 0x80 -static void MouseXYZ(GMouse* m, GMouseReading* pdr) +static bool_t MouseXYZ(GMouse* m, GMouseReading* pdr) { (void)m; @@ -42,6 +42,7 @@ static void MouseXYZ(GMouse* m, GMouseReading* pdr) release_bus(m); } + return TRUE; } const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ diff --git a/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c b/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c index ed2e68fa..6b0bcdb2 100644 --- a/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c +++ b/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c @@ -56,7 +56,7 @@ static bool_t MouseInit(GMouse* m, unsigned driverinstance) { return TRUE; } -static void MouseXYZ(GMouse* m, GMouseReading* pdr) +static bool_t MouseXYZ(GMouse* m, GMouseReading* pdr) { // Assume not touched. pdr->buttons = 0; @@ -80,6 +80,7 @@ static void MouseXYZ(GMouse* m, GMouseReading* pdr) } release_bus(m); + return TRUE; } const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ diff --git a/drivers/multiple/Win32/gdisp_lld_Win32.c b/drivers/multiple/Win32/gdisp_lld_Win32.c index ecb100f6..13c5e544 100644 --- a/drivers/multiple/Win32/gdisp_lld_Win32.c +++ b/drivers/multiple/Win32/gdisp_lld_Win32.c @@ -69,7 +69,7 @@ // Forward definitions static bool_t Win32MouseInit(GMouse *m, unsigned driverinstance); - static void Win32MouseRead(GMouse *m, GMouseReading *prd); + static bool_t Win32MouseRead(GMouse *m, GMouseReading *prd); const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ { @@ -1169,7 +1169,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { (void) driverinstance; return TRUE; } - static void Win32MouseRead(GMouse *m, GMouseReading *pt) { + static bool_t Win32MouseRead(GMouse *m, GMouseReading *pt) { GDisplay * g; winPriv * priv; @@ -1207,6 +1207,8 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { } } #endif + + return TRUE; } #endif /* GINPUT_NEED_MOUSE */ diff --git a/drivers/multiple/X/gdisp_lld_X.c b/drivers/multiple/X/gdisp_lld_X.c index 6e0233ba..d62f52e6 100644 --- a/drivers/multiple/X/gdisp_lld_X.c +++ b/drivers/multiple/X/gdisp_lld_X.c @@ -33,7 +33,7 @@ // Forward definitions static bool_t XMouseInit(GMouse *m, unsigned driverinstance); - static void XMouseRead(GMouse *m, GMouseReading *prd); + static bool_t XMouseRead(GMouse *m, GMouseReading *prd); const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ { @@ -364,7 +364,7 @@ LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) (void) driverinstance; return TRUE; } - static void XMouseRead(GMouse *m, GMouseReading *pt) { + static bool_t XMouseRead(GMouse *m, GMouseReading *pt) { xPriv * priv; priv = m->display->priv; @@ -372,6 +372,7 @@ LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) pt->y = priv->mousey; pt->z = (priv->buttons & GINPUT_MOUSE_BTN_LEFT) ? 1 : 0; pt->buttons = priv->buttons; + return TRUE; } #endif /* GINPUT_NEED_MOUSE */ diff --git a/drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c b/drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c index 559b0c69..3b42bcda 100644 --- a/drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c +++ b/drivers/multiple/uGFXnet/gdisp_lld_uGFXnet.c @@ -40,7 +40,7 @@ // Forward definitions static bool_t NMouseInit(GMouse *m, unsigned driverinstance); - static void NMouseRead(GMouse *m, GMouseReading *prd); + static bool_t NMouseRead(GMouse *m, GMouseReading *prd); const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ { @@ -710,7 +710,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { (void) driverinstance; return TRUE; } - static void NMouseRead(GMouse *m, GMouseReading *pt) { + static bool_t NMouseRead(GMouse *m, GMouseReading *pt) { GDisplay * g; netPriv * priv; @@ -721,6 +721,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { pt->y = priv->mousey; pt->z = (priv->mousebuttons & GINPUT_MOUSE_BTN_LEFT) ? 1 : 0; pt->buttons = priv->mousebuttons; + return TRUE; } #endif /* GINPUT_NEED_MOUSE */ diff --git a/src/ginput/driver_mouse.h b/src/ginput/driver_mouse.h index 037f9c0f..836ae1de 100644 --- a/src/ginput/driver_mouse.h +++ b/src/ginput/driver_mouse.h @@ -86,10 +86,10 @@ typedef struct GMouseVMT { GMouseJitter pen_jitter; // PEN MODE: Jitter settings GMouseJitter finger_jitter; // FINGER MODE: Jitter settings - bool_t (*init)(GMouse *m, unsigned driverinstance); // Required - void (*deinit)(GMouse *m); // Optional - void (*get)(GMouse *m, GMouseReading *prd); // Required - void (*calsave)(GMouse *m, void *buf, size_t sz); // Optional + bool_t (*init)(GMouse *m, unsigned driverinstance); // Required + void (*deinit)(GMouse *m); // Optional + bool_t (*get)(GMouse *m, GMouseReading *prd); // Required + void (*calsave)(GMouse *m, void *buf, size_t sz); // Optional const char *(*calload)(GMouse *m, size_t sz); // Optional: Can return NULL if no data is saved. } GMouseVMT; diff --git a/src/ginput/ginput_mouse.c b/src/ginput/ginput_mouse.c index 9cdcaec2..570839a2 100644 --- a/src/ginput/ginput_mouse.c +++ b/src/ginput/ginput_mouse.c @@ -78,7 +78,7 @@ static void SendMouseEvent(GSourceListener *psl, GMouse *m, GMouseReading *r) { // Send the event only if we are listening for it if (!((r->buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEDOWNMOVES)) - && !((r->buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEUPMOVES)) + && !(!(r->buttons & GINPUT_MOUSE_BTN_LEFT) && (psl->listenflags & GLISTEN_MOUSEUPMOVES)) && !((r->buttons & GMETA_MASK) && (psl->listenflags & GLISTEN_MOUSEMETA))) return; @@ -102,7 +102,8 @@ static void GetMouseReading(GMouse *m) { // Step 1 - Get the Raw Reading { m->flags &= ~GMOUSE_FLG_NEEDREAD; - gmvmt(m)->get(m, &r); + if (!gmvmt(m)->get(m, &r)) + return; } // Step 2 - Handle touch and button 0 debouncing From d0f8c12a2d79d6328269a7931fdf673bd23f4dc7 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 7 Nov 2014 12:04:03 +1000 Subject: [PATCH 79/87] Cleanups and updates to the STM32F429i-Discovery gdisp driver --- .../gdisp_lld_STM32F429iDiscovery.c | 2 +- drivers/gdisp/STM32F429iDiscovery/ili9341.h | 315 -------------- .../gdisp/STM32F429iDiscovery/stm32_ltdc.h | 409 ------------------ 3 files changed, 1 insertion(+), 725 deletions(-) diff --git a/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_STM32F429iDiscovery.c b/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_STM32F429iDiscovery.c index aae21a8e..88d50114 100644 --- a/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_STM32F429iDiscovery.c +++ b/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_STM32F429iDiscovery.c @@ -29,7 +29,7 @@ typedef struct ltdcLayerConfig { LLDCOLOR_TYPE *frame; // Frame buffer address coord_t width, height; // Frame size in pixels coord_t pitch; // Line pitch, in bytes - ltdc_pixfmt_t fmt; // Pixel format in LTDC format + uint16_t fmt; // Pixel format in LTDC format // window coord_t x, y; // Start pixel position of the virtual layer diff --git a/drivers/gdisp/STM32F429iDiscovery/ili9341.h b/drivers/gdisp/STM32F429iDiscovery/ili9341.h index 17ad488c..ae1620c0 100644 --- a/drivers/gdisp/STM32F429iDiscovery/ili9341.h +++ b/drivers/gdisp/STM32F429iDiscovery/ili9341.h @@ -94,319 +94,4 @@ #define ILI9341_IM_4LSI_1 0x6 /**< 4-line serial, mode 1.*/ #define ILI9341_IM_4LSI_2 0xE /**< 4-line serial, mode 2.*/ -// ILI9341 command params (little endian) - -#pragma pack(push, 1) - -typedef union { - struct ILI9341ParamBits_GET_ID_INFO { - uint8_t reserved_; - uint8_t ID1; - uint8_t ID2; - uint8_t ID3; - } bits; - uint8_t bytes[4]; -} ILI9341Params_GET_ID_INFO; - -typedef union { - struct ILI9341ParamBits_GET_STATUS { - unsigned _reserved_1 : 5; /* D[ 4: 0] */ - unsigned tearing_mode : 1; /* D[ 5] */ - unsigned gamma_curve : 3; /* D[ 8: 6] */ - unsigned tearing : 1; /* D[ 9] */ - unsigned display : 1; /* D[10] */ - unsigned all_on : 1; /* D[11] */ - unsigned all_off : 1; /* D[12] */ - unsigned invert : 1; /* D[13] */ - unsigned _reserved_2 : 1; /* D[14] */ - unsigned vscroll : 1; /* D[15] */ - unsigned normal : 1; /* D[16] */ - unsigned sleep : 1; /* D[17] */ - unsigned partial : 1; /* D[18] */ - unsigned idle : 1; /* D[19] */ - unsigned pixel_format : 3; /* D[22:20] */ - unsigned _reserved_3 : 2; /* D[24:23] */ - unsigned hrefr_rtl_nltr : 1; /* D[25] */ - unsigned bgr_nrgb : 1; /* D[26] */ - unsigned vrefr_btt_nttb : 1; /* D[27] */ - unsigned transpose : 1; /* D[28] */ - unsigned coladr_rtl_nltr : 1; /* D[29] */ - unsigned rowadr_btt_nttb : 1; /* D[30] */ - unsigned booster : 1; /* D[31] */ - } bits; - uint8_t bytes[4]; -} ILI9341Params_GET_STATUS; - -typedef union { - struct ILI9341ParamBits_GET_PWR_MODE { - unsigned _reserved_1 : 2; /* D[1:0] */ - unsigned display : 1; /* D[2] */ - unsigned normal : 1; /* D[3] */ - unsigned sleep : 1; /* D[4] */ - unsigned partial : 1; /* D[5] */ - unsigned idle : 1; /* D[6] */ - unsigned booster : 1; /* D[7] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_GET_PWR_MODE; - -typedef union { - struct ILI9341ParamBits_GET_MADCTL { - unsigned _reserved_1 : 2; /* D[1:0] */ - unsigned refr_rtl_nltr : 1; /* D[2] */ - unsigned bgr_nrgb : 1; /* D[3] */ - unsigned refr_btt_nttb : 1; /* D[4] */ - unsigned invert : 1; /* D[5] */ - unsigned rtl_nltr : 1; /* D[6] */ - unsigned btt_nttb : 1; /* D[7] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_GET_MADCTL; - -typedef union { - struct ILI9341ParamBits_GET_PIX_FMT { - unsigned DBI : 3; /* D[2:0] */ - unsigned _reserved_1 : 1; /* D[3] */ - unsigned DPI : 3; /* D[6:4] */ - unsigned RIM : 1; /* D[7] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_GET_PIX_FMT; - -typedef union { - struct ILI9341ParamBits_GET_IMG_FMT { - unsigned gamma_curve : 3; /* D[2:0] */ - unsigned _reserved_1 : 5; /* D[7:3] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_GET_IMG_FMT; - -typedef union { - struct ILI9341ParamBits_GET_SIG_MODE { - unsigned _reserved_1 : 2; /* D[1:0] */ - unsigned data_enable : 1; /* D[2] */ - unsigned pixel_clock : 1; /* D[3] */ - unsigned vsync : 1; /* D[4] */ - unsigned hsync : 1; /* D[5] */ - unsigned tearing_mode : 1; /* D[6] */ - unsigned tearing : 1; /* D[7] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_GET_SIG_MODE; - -typedef union { - struct ILI9341ParamBits_GET_SELF_DIAG { - unsigned _reserved_1 : 6; /* D[5:0] */ - unsigned func_err : 1; /* D[6] */ - unsigned reg_err : 1; /* D[7] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_GET_SELF_DIAG; - -typedef union { - struct ILI9341ParamBits_SET_GAMMA { - uint8_t gamma_curve; /* D[7:0] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_SET_GAMMA; - -typedef union { - struct ILI9341ParamBits_SET_COL_ADDR { - uint8_t SC_15_8; /* D[ 7: 0] */ - uint8_t SC_7_0; /* D[15: 8] */ - uint8_t EC_15_8; /* D[23:16] */ - uint8_t EC_7_0; /* D[31:24] */ - } bits; - uint8_t bytes[4]; -} ILI9341Params_SET_COL_ADDR; - -typedef union { - struct ILI9341ParamBits_SET_PAGE_ADDR { - uint8_t SP_15_8; /* D[ 7: 0] */ - uint8_t SP_7_0; /* D[15: 8] */ - uint8_t EP_15_8; /* D[23:16] */ - uint8_t EP_7_0; /* D[31:24] */ - } bits; - uint8_t bytes[4]; -} ILI9341Params_SET_PAGE_ADDR; - -typedef union { - struct ILI9341ParamBits_SET_PARTIAL_AREA { - uint8_t SR_15_8; /* D[ 7: 0] */ - uint8_t SR_7_0; /* D[15: 8] */ - uint8_t ER_15_8; /* D[23:16] */ - uint8_t ER_7_0; /* D[31:24] */ - } bits; - uint8_t bytes[4]; -} ILI9341Params_SET_PARTIAL_AREA; - -typedef union { - struct ILI9341ParamBits_SET_VSCROLL { - uint8_t TFA_15_8; /* D[ 7: 0] */ - uint8_t TFA_7_0; /* D[15: 8] */ - uint8_t VSA_15_8; /* D[23:16] */ - uint8_t VSA_7_0; /* D[31:24] */ - uint8_t BFA_15_8; /* D[39:32] */ - uint8_t BFA_7_0; /* D[47:40] */ - } bits; - uint8_t bytes[6]; -} ILI9341Params_SET_VSCROLL; - -typedef union { - struct ILI9341ParamBits_CMD_TEARING_ON { - unsigned M : 1; /* D[0] */ - unsigned _reserved_1 : 7; /* D[7:1] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_CMD_TEARING_ON; - -typedef union { - struct ILI9341ParamBits_SET_MEM_ACS_CTL { - unsigned _reserved_1 : 2; /* D[1:0] */ - unsigned MH : 1; /* D[2] */ - unsigned BGR : 1; /* D[3] */ - unsigned ML : 1; /* D[4] */ - unsigned MV : 1; /* D[5] */ - unsigned MX : 1; /* D[6] */ - unsigned MY : 1; /* D[7] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_SET_MEM_ACS_CTL; - -typedef union { - struct ILI9341ParamBits_SET_VSCROLL_ADDR { - uint8_t VSP_15_8; /* D[ 7: 0] */ - uint8_t VSP_7_0; /* D[15: 8] */ - } bits; - uint8_t bytes[2]; -} ILI9341Params_SET_VSCROLL_ADDR; - -typedef union { - struct ILI9341ParamBits_SET_PIX_FMT { - unsigned DBI : 3; /* D[2:0] */ - unsigned _reserved_1 : 1; /* D[3] */ - unsigned DPI : 3; /* D[4:6] */ - unsigned _reserved_2 : 1; /* D[7] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_SET_PIX_FMT; - -typedef union { - struct ILI9341ParamBits_SET_TEAR_SCANLINE { - uint8_t STS_8; /* D[ 7: 0] */ - uint8_t STS_7_0; /* D[15: 8] */ - } bits; - uint8_t bytes[4]; -} ILI9341Params_SET_TEAR_SCANLINE; - -typedef union { - struct ILI9341ParamBits_GET_TEAR_SCANLINE { - uint8_t GTS_9_8; /* D[ 7: 0] */ - uint8_t GTS_7_0; /* D[15: 8] */ - } bits; - uint8_t bytes[2]; -} ILI9341Params_GET_TEAR_SCANLINE; - -typedef union { - struct ILI9341ParamBits_SET_BRIGHTNESS { - uint8_t DBV; /* D[7:0] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_SET_BRIGHTNESS; - -typedef union { - struct ILI9341ParamBits_GET_BRIGHTNESS { - uint8_t DBV; /* D[7:0] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_GET_BRIGHTNESS; - -typedef union { - struct ILI9341ParamBits_SET_DISPLAY_CTL { - unsigned _reserved_1 : 2; /* D[1:0] */ - unsigned BL : 1; /* D[2] */ - unsigned DD : 1; /* D[3] */ - unsigned _reserved_2 : 1; /* D[4] */ - unsigned BCTRL : 1; /* D[5] */ - unsigned _reserved_3 : 1; /* D[7:6] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_SET_DISPLAY_CTL; - -typedef union { - struct ILI9341ParamBits_GET_DISPLAY_CTL { - unsigned _reserved_1 : 2; /* D[1:0] */ - unsigned BL : 1; /* D[2] */ - unsigned DD : 1; /* D[3] */ - unsigned _reserved_2 : 1; /* D[4] */ - unsigned BCTRL : 1; /* D[5] */ - unsigned _reserved_3 : 1; /* D[7:6] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_GET_DISPLAY_CTL; - -typedef union { - struct ILI9341ParamBits_SET_CABC { - unsigned C : 2; /* D[1:0] */ - unsigned _reserved_1 : 6; /* D[7:2] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_SET_CABC; - -typedef union { - struct ILI9341ParamBits_GET_CABC { - unsigned C : 2; /* D[1:0] */ - unsigned _reserved_1 : 6; /* D[7:2] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_GET_CABC; - -typedef union { - struct ILI9341ParamBits_SET_CABC_MIN { - uint8_t CMB; /* D[7:0] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_SET_CABC_MIN; - -typedef union { - struct ILI9341ParamBits_GET_CABC_MIN { - uint8_t CMB; /* D[7:0] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_GET_CABC_MIN; - -#if 0 /* TODO: Extended command structs.*/ - -typedef union { - struct ILI9341ParamBits { - unsigned : 1; /* D[] */ - unsigned : 1; /* D[] */ - unsigned : 1; /* D[] */ - unsigned : 1; /* D[] */ - unsigned : 1; /* D[] */ - unsigned : 1; /* D[] */ - unsigned : 1; /* D[] */ - unsigned : 1; /* D[] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_; - -typedef union { - struct ILI9341ParamBits { - unsigned : 1; /* D[] */ - unsigned : 1; /* D[] */ - unsigned : 1; /* D[] */ - unsigned : 1; /* D[] */ - unsigned : 1; /* D[] */ - unsigned : 1; /* D[] */ - unsigned : 1; /* D[] */ - unsigned : 1; /* D[] */ - } bits; - uint8_t bytes[1]; -} ILI9341Params_; - -#endif /*0*/ - -#pragma pack(pop) - #endif /* ILI9341_H */ diff --git a/drivers/gdisp/STM32F429iDiscovery/stm32_ltdc.h b/drivers/gdisp/STM32F429iDiscovery/stm32_ltdc.h index dd7c94e8..866b9d89 100644 --- a/drivers/gdisp/STM32F429iDiscovery/stm32_ltdc.h +++ b/drivers/gdisp/STM32F429iDiscovery/stm32_ltdc.h @@ -135,417 +135,8 @@ #define LTDC_COLOR_AQUA 0xFF00FFFF #define LTDC_COLOR_WHITE 0xFFFFFFFF -/**/ -#define STM32_LTDC_EV_HANDLER LTDC_EV_IRQHandler -#define STM32_LTDC_ER_HANDLER LTDC_ER_IRQHandler -#define STM32_LTDC_EV_NUMBER LTDC_IRQn -#define STM32_LTDC_ER_NUMBER LTDC_ER_IRQn -#define LTDC_EV_IRQHandler Vector1A0 -#define LTDC_ER_IRQHandler Vector1A4 - -#define STM32_LTDC_EV_IRQ_PRIORITY 11 -#define STM32_LTDC_ER_IRQ_PRIORITY 11 -#define LTDC_USE_WAIT TRUE -#define LTDC_USE_SOFTWARE_CONVERSIONS TRUE - #ifndef STM32F429_439xx #error "Currently only STM32F429xx and STM32F439xx are supported" #endif -/*===========================================================================*/ -/* Driver data structures and types. */ -/*===========================================================================*/ - -/* Complex types forwarding.*/ -typedef union ltdc_coloralias_t ltdc_coloralias_t; -typedef struct ltdc_window_t ltdc_window_t; -typedef struct ltdc_frame_t ltdc_frame_t; -typedef struct ltdc_laycfg_t ltdc_laycfg_t; -typedef struct LTDCConfig LTDCConfig; -typedef enum ltdc_state_t ltdc_state_t; -typedef struct LTDCDriver LTDCDriver; - -/** - * @name LTDC Data types - * @{ - */ - -/** - * @brief LTDC generic color. - */ -typedef uint32_t ltdc_color_t; - -/** - * @brief LTDC color aliases. - * @detail Mapped with ARGB-8888, except for luminance (L mapped onto B). - * Padding fields prefixed with 'x', which should be clear - * (all 0) before compression and set (all 1) after expansion. - */ -typedef union ltdc_coloralias_t { - struct { - unsigned b : 8; - unsigned g : 8; - unsigned r : 8; - unsigned a : 8; - } argb8888; /**< Mapped ARGB-8888 bits.*/ - struct { - unsigned b : 8; - unsigned g : 8; - unsigned r : 8; - unsigned xa : 8; - } rgb888; /**< Mapped RGB-888 bits.*/ - struct { - unsigned xb : 3; - unsigned b : 5; - unsigned xg : 2; - unsigned g : 6; - unsigned xr : 3; - unsigned r : 5; - unsigned xa : 8; - } rgb565; /**< Mapped RGB-565 bits.*/ - struct { - unsigned xb : 3; - unsigned b : 5; - unsigned xg : 3; - unsigned g : 5; - unsigned xr : 3; - unsigned r : 5; - unsigned xa : 7; - unsigned a : 1; - } argb1555; /**< Mapped ARGB-1555 values.*/ - struct { - unsigned xb : 4; - unsigned b : 4; - unsigned xg : 4; - unsigned g : 4; - unsigned xr : 4; - unsigned r : 4; - unsigned xa : 4; - unsigned a : 4; - } argb4444; /**< Mapped ARGB-4444 values.*/ - struct { - unsigned l : 8; - unsigned x : 16; - unsigned xa : 8; - } l8; /**< Mapped L-8 bits.*/ - struct { - unsigned xl : 4; - unsigned l : 4; - unsigned x : 16; - unsigned xa : 4; - unsigned a : 4; - } al44; /**< Mapped AL-44 bits.*/ - struct { - unsigned l : 8; - unsigned x : 16; - unsigned a : 8; - } al88; /**< Mapped AL-88 bits.*/ - ltdc_color_t aliased; /**< Aliased raw bits.*/ -} ltdc_coloralias_t; - -/** - * @brief LTDC layer identifier. - */ -typedef uint32_t ltdc_layerid_t; - -/** - * @brief LTDC pixel format. - */ -typedef uint32_t ltdc_pixfmt_t; - -/** - * @brief LTDC blending factor. - */ -typedef uint32_t ltdc_blendf_t; - -/** - * @brief LTDC ISR callback. - */ -typedef void (*ltdc_isrcb_t)(LTDCDriver *ltdcp); - -/** - * @brief LTDC window specifications. - */ -typedef struct ltdc_window_t { - uint16_t hstart; /**< Horizontal start pixel (left).*/ - uint16_t hstop; /**< Horizontal stop pixel (right).*/ - uint16_t vstart; /**< Vertical start pixel (top).*/ - uint16_t vstop; /**< Vertical stop pixel (bottom).*/ -} ltdc_window_t; - -/** - * @brief LTDC frame specifications. - */ -typedef struct ltdc_frame_t { - void *bufferp; /**< Frame buffer address.*/ - uint16_t width; /**< Frame width, in pixels.*/ - uint16_t height; /**< Frame height, in pixels.*/ - size_t pitch; /**< Line pitch, in bytes.*/ - ltdc_pixfmt_t fmt; /**< Pixel format.*/ -} ltdc_frame_t; - -/** - * @brief LTDC configuration flags. - */ -typedef uint8_t ltdc_flags_t; - -/** - * @brief LTDC startup layer configuration. - */ -typedef struct ltdc_laycfg_t { - const ltdc_frame_t *frame; /**< Frame buffer specifications.*/ - const ltdc_window_t *window; /**< Window specifications.*/ - ltdc_color_t def_color; /**< Default color, ARGB-8888.*/ - uint8_t const_alpha; /**< Constant alpha factor.*/ - ltdc_color_t key_color; /**< Color key.*/ - const ltdc_color_t *pal_colors; /**< Palette colors, or @p NULL.*/ - uint16_t pal_length; /**< Palette length, or @p 0.*/ - ltdc_blendf_t blending; /**< Blending factors.*/ - ltdc_flags_t flags; /**< Layer configuration flags.*/ -} ltdc_laycfg_t; - -/** - * @brief LTDC driver configuration. - */ -typedef struct LTDCConfig { - /* Display specifications.*/ - uint16_t screen_width; /**< Screen pixel width.*/ - uint16_t screen_height; /**< Screen pixel height.*/ - uint16_t hsync_width; /**< Horizontal sync pixel width.*/ - uint16_t vsync_height; /**< Vertical sync pixel height.*/ - uint16_t hbp_width; /**< Horizontal back porch pixel width.*/ - uint16_t vbp_height; /**< Vertical back porch pixel height.*/ - uint16_t hfp_width; /**< Horizontal front porch pixel width.*/ - uint16_t vfp_height; /**< Vertical front porch pixel height.*/ - ltdc_flags_t flags; /**< Driver configuration flags.*/ - - /* ISR callbacks.*/ - ltdc_isrcb_t line_isr; /**< Line Interrupt ISR, or @p NULL.*/ - ltdc_isrcb_t rr_isr; /**< Register Reload ISR, or @p NULL.*/ - ltdc_isrcb_t fuerr_isr; /**< FIFO Underrun ISR, or @p NULL.*/ - ltdc_isrcb_t terr_isr; /**< Transfer Error ISR, or @p NULL.*/ - - /* Layer and color settings.*/ - ltdc_color_t clear_color; /**< Clear screen color, RGB-888.*/ - const ltdc_laycfg_t *bg_laycfg; /**< Background layer specs, or @p NULL.*/ - const ltdc_laycfg_t *fg_laycfg; /**< Foreground layer specs, or @p NULL.*/ -} LTDCConfig; - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ - -/** - * @brief Makes an ARGB-8888 value from byte components. - * - * @param[in] a alpha byte component - * @param[in] r red byte component - * @param[in] g green byte component - * @param[in] b blue byte component - * - * @return color in ARGB-8888 format - * - * @api - */ -#define ltdcMakeARGB8888(a, r, g, b) \ - ((((ltdc_color_t)(a) & 0xFF) << 24) | \ - (((ltdc_color_t)(r) & 0xFF) << 16) | \ - (((ltdc_color_t)(g) & 0xFF) << 8) | \ - (((ltdc_color_t)(b) & 0xFF) << 0)) - -/** - * @brief Compute bytes per pixel. - * @details Computes the bytes per pixel for the specified pixel format. - * Rounds to the ceiling. - * - * @param[in] fmt pixel format - * - * @return bytes per pixel - * - * @api - */ -#define ltdcBytesPerPixel(fmt) \ - ((ltdcBitsPerPixel(fmt) + 7) >> 3) - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - - /* Global methods.*/ - ltdc_flags_t ltdcGetEnableFlagsI(LTDCDriver *ltdcp); - ltdc_flags_t ltdcGetEnableFlags(LTDCDriver *ltdcp); - void ltdcSetEnableFlagsI(LTDCDriver *ltdcp, ltdc_flags_t flags); - void ltdcSetEnableFlags(LTDCDriver *ltdcp, ltdc_flags_t flags); - bool_t ltdcIsReloadingI(LTDCDriver *ltdcp); - bool_t ltdcIsReloading(LTDCDriver *ltdcp); - void ltdcStartReloadI(LTDCDriver *ltdcp, bool_t immediately); - void ltdcStartReload(LTDCDriver *ltdcp, bool_t immediately); - void ltdcReloadS(LTDCDriver *ltdcp, bool_t immediately); - void ltdcReload(LTDCDriver *ltdcp, bool_t immediately); - bool_t ltdcIsDitheringEnabledI(LTDCDriver *ltdcp); - bool_t ltdcIsDitheringEnabled(LTDCDriver *ltdcp); - void ltdcEnableDitheringI(LTDCDriver *ltdcp); - void ltdcEnableDithering(LTDCDriver *ltdcp); - void ltdcDisableDitheringI(LTDCDriver *ltdcp); - void ltdcDisableDithering(LTDCDriver *ltdcp); - ltdc_color_t ltdcGetClearColorI(LTDCDriver *ltdcp); - ltdc_color_t ltdcGetClearColor(LTDCDriver *ltdcp); - void ltdcSetClearColorI(LTDCDriver *ltdcp, ltdc_color_t c); - void ltdcSetClearColor(LTDCDriver *ltdcp, ltdc_color_t c); - uint16_t ltdcGetLineInterruptPosI(LTDCDriver *ltdcp); - uint16_t ltdcGetLineInterruptPos(LTDCDriver *ltdcp); - void ltdcSetLineInterruptPosI(LTDCDriver *ltdcp, uint16_t line); - void ltdcSetLineInterruptPos(LTDCDriver *ltdcp, uint16_t line); - bool_t ltdcIsLineInterruptEnabledI(LTDCDriver *ltdcp); - bool_t ltdcIsLineInterruptEnabled(LTDCDriver *ltdcp); - void ltdcEnableLineInterruptI(LTDCDriver *ltdcp); - void ltdcEnableLineInterrupt(LTDCDriver *ltdcp); - void ltdcDisableLineInterruptI(LTDCDriver *ltdcp); - void ltdcDisableLineInterrupt(LTDCDriver *ltdcp); - void ltdcGetCurrentPosI(LTDCDriver *ltdcp, uint16_t *xp, uint16_t *yp); - void ltdcGetCurrentPos(LTDCDriver *ltdcp, uint16_t *xp, uint16_t *yp); - - /* Background layer methods.*/ - ltdc_flags_t ltdcBgGetEnableFlagsI(LTDCDriver *ltdcp); - ltdc_flags_t ltdcBgGetEnableFlags(LTDCDriver *ltdcp); - void ltdcBgSetEnableFlagsI(LTDCDriver *ltdcp, ltdc_flags_t flags); - void ltdcBgSetEnableFlags(LTDCDriver *ltdcp, ltdc_flags_t flags); - bool_t ltdcBgIsEnabledI(LTDCDriver *ltdcp); - bool_t ltdcBgIsEnabled(LTDCDriver *ltdcp); - void ltdcBgEnableI(LTDCDriver *ltdcp); - void ltdcBgEnable(LTDCDriver *ltdcp); - void ltdcBgDisableI(LTDCDriver *ltdcp); - void ltdcBgDisable(LTDCDriver *ltdcp); - bool_t ltdcBgIsPaletteEnabledI(LTDCDriver *ltdcp); - bool_t ltdcBgIsPaletteEnabled(LTDCDriver *ltdcp); - void ltdcBgEnablePaletteI(LTDCDriver *ltdcp); - void ltdcBgEnablePalette(LTDCDriver *ltdcp); - void ltdcBgDisablePaletteI(LTDCDriver *ltdcp); - void ltdcBgDisablePalette(LTDCDriver *ltdcp); - void ltdcBgSetPaletteColorI(LTDCDriver *ltdcp, uint8_t slot, ltdc_color_t c); - void ltdcBgSetPaletteColor(LTDCDriver *ltdcp, uint8_t slot, ltdc_color_t c); - void ltdcBgSetPaletteI(LTDCDriver *ltdcp, const ltdc_color_t colors[], - uint16_t length); - void ltdcBgSetPalette(LTDCDriver *ltdcp, const ltdc_color_t colors[], - uint16_t length); - ltdc_pixfmt_t ltdcBgGetPixelFormatI(LTDCDriver *ltdcp); - ltdc_pixfmt_t ltdcBgGetPixelFormat(LTDCDriver *ltdcp); - void ltdcBgSetPixelFormatI(LTDCDriver *ltdcp, ltdc_pixfmt_t fmt); - void ltdcBgSetPixelFormat(LTDCDriver *ltdcp, ltdc_pixfmt_t fmt); - bool_t ltdcBgIsKeyingEnabledI(LTDCDriver *ltdcp); - bool_t ltdcBgIsKeyingEnabled(LTDCDriver *ltdcp); - void ltdcBgEnableKeyingI(LTDCDriver *ltdcp); - void ltdcBgEnableKeying(LTDCDriver *ltdcp); - void ltdcBgDisableKeyingI(LTDCDriver *ltdcp); - void ltdcBgDisableKeying(LTDCDriver *ltdcp); - ltdc_color_t ltdcBgGetKeyingColorI(LTDCDriver *ltdcp); - ltdc_color_t ltdcBgGetKeyingColor(LTDCDriver *ltdcp); - void ltdcBgSetKeyingColorI(LTDCDriver *ltdcp, ltdc_color_t c); - void ltdcBgSetKeyingColor(LTDCDriver *ltdcp, ltdc_color_t c); - uint8_t ltdcBgGetConstantAlphaI(LTDCDriver *ltdcp); - uint8_t ltdcBgGetConstantAlpha(LTDCDriver *ltdcp); - void ltdcBgSetConstantAlphaI(LTDCDriver *ltdcp, uint8_t a); - void ltdcBgSetConstantAlpha(LTDCDriver *ltdcp, uint8_t a); - ltdc_color_t ltdcBgGetDefaultColorI(LTDCDriver *ltdcp); - ltdc_color_t ltdcBgGetDefaultColor(LTDCDriver *ltdcp); - void ltdcBgSetDefaultColorI(LTDCDriver *ltdcp, ltdc_color_t c); - void ltdcBgSetDefaultColor(LTDCDriver *ltdcp, ltdc_color_t c); - ltdc_blendf_t ltdcBgGetBlendingFactorsI(LTDCDriver *ltdcp); - ltdc_blendf_t ltdcBgGetBlendingFactors(LTDCDriver *ltdcp); - void ltdcBgSetBlendingFactorsI(LTDCDriver *ltdcp, ltdc_blendf_t bf); - void ltdcBgSetBlendingFactors(LTDCDriver *ltdcp, ltdc_blendf_t bf); - void ltdcBgGetWindowI(LTDCDriver *ltdcp, ltdc_window_t *windowp); - void ltdcBgGetWindow(LTDCDriver *ltdcp, ltdc_window_t *windowp); - void ltdcBgSetWindowI(LTDCDriver *ltdcp, const ltdc_window_t *windowp); - void ltdcBgSetWindow(LTDCDriver *ltdcp, const ltdc_window_t *windowp); - void ltdcBgSetInvalidWindowI(LTDCDriver *ltdcp); - void ltdcBgSetInvalidWindow(LTDCDriver *ltdcp); - void ltdcBgGetFrameI(LTDCDriver *ltdcp, ltdc_frame_t *framep); - void ltdcBgGetFrame(LTDCDriver *ltdcp, ltdc_frame_t *framep); - void ltdcBgSetFrameI(LTDCDriver *ltdcp, const ltdc_frame_t *framep); - void ltdcBgSetFrame(LTDCDriver *ltdcp, const ltdc_frame_t *framep); - void *ltdcBgGetFrameAddressI(LTDCDriver *ltdcp); - void *ltdcBgGetFrameAddress(LTDCDriver *ltdcp); - void ltdcBgSetFrameAddressI(LTDCDriver *ltdcp, void *bufferp); - void ltdcBgSetFrameAddress(LTDCDriver *ltdcp, void *bufferp); - void ltdcBgGetLayerI(LTDCDriver *ltdcp, ltdc_laycfg_t *cfgp); - void ltdcBgGetLayer(LTDCDriver *ltdcp, ltdc_laycfg_t *cfgp); - void ltdcBgSetConfigI(LTDCDriver *ltdcp, const ltdc_laycfg_t *cfgp); - void ltdcBgSetConfig(LTDCDriver *ltdcp, const ltdc_laycfg_t *cfgp); - - /* Foreground layer methods.*/ - ltdc_flags_t ltdcFgGetEnableFlagsI(LTDCDriver *ltdcp); - ltdc_flags_t ltdcFgGetEnableFlags(LTDCDriver *ltdcp); - void ltdcFgSetEnableFlagsI(LTDCDriver *ltdcp, ltdc_flags_t flags); - void ltdcFgSetEnableFlags(LTDCDriver *ltdcp, ltdc_flags_t flags); - bool_t ltdcFgIsEnabledI(LTDCDriver *ltdcp); - bool_t ltdcFgIsEnabled(LTDCDriver *ltdcp); - void ltdcFgEnableI(LTDCDriver *ltdcp); - void ltdcFgEnable(LTDCDriver *ltdcp); - void ltdcFgDisableI(LTDCDriver *ltdcp); - void ltdcFgDisable(LTDCDriver *ltdcp); - bool_t ltdcFgIsPaletteEnabledI(LTDCDriver *ltdcp); - bool_t ltdcFgIsPaletteEnabled(LTDCDriver *ltdcp); - void ltdcFgEnablePaletteI(LTDCDriver *ltdcp); - void ltdcFgEnablePalette(LTDCDriver *ltdcp); - void ltdcFgDisablePaletteI(LTDCDriver *ltdcp); - void ltdcFgDisablePalette(LTDCDriver *ltdcp); - void ltdcFgSetPaletteColorI(LTDCDriver *ltdcp, uint8_t slot, ltdc_color_t c); - void ltdcFgSetPaletteColor(LTDCDriver *ltdcp, uint8_t slot, ltdc_color_t c); - void ltdcFgSetPaletteI(LTDCDriver *ltdcp, const ltdc_color_t colors[], - uint16_t length); - void ltdcFgSetPalette(LTDCDriver *ltdcp, const ltdc_color_t colors[], - uint16_t length); - ltdc_pixfmt_t ltdcFgGetPixelFormatI(LTDCDriver *ltdcp); - ltdc_pixfmt_t ltdcFgGetPixelFormat(LTDCDriver *ltdcp); - void ltdcFgSetPixelFormatI(LTDCDriver *ltdcp, ltdc_pixfmt_t fmt); - void ltdcFgSetPixelFormat(LTDCDriver *ltdcp, ltdc_pixfmt_t fmt); - bool_t ltdcFgIsKeyingEnabledI(LTDCDriver *ltdcp); - bool_t ltdcFgIsKeyingEnabled(LTDCDriver *ltdcp); - void ltdcFgEnableKeyingI(LTDCDriver *ltdcp); - void ltdcFgEnableKeying(LTDCDriver *ltdcp); - void ltdcFgDisableKeyingI(LTDCDriver *ltdcp); - void ltdcFgDisableKeying(LTDCDriver *ltdcp); - ltdc_color_t ltdcFgGetKeyingColorI(LTDCDriver *ltdcp); - ltdc_color_t ltdcFgGetKeyingColor(LTDCDriver *ltdcp); - void ltdcFgSetKeyingColorI(LTDCDriver *ltdcp, ltdc_color_t c); - void ltdcFgSetKeyingColor(LTDCDriver *ltdcp, ltdc_color_t c); - uint8_t ltdcFgGetConstantAlphaI(LTDCDriver *ltdcp); - uint8_t ltdcFgGetConstantAlpha(LTDCDriver *ltdcp); - void ltdcFgSetConstantAlphaI(LTDCDriver *ltdcp, uint8_t a); - void ltdcFgSetConstantAlpha(LTDCDriver *ltdcp, uint8_t a); - ltdc_color_t ltdcFgGetDefaultColorI(LTDCDriver *ltdcp); - ltdc_color_t ltdcFgGetDefaultColor(LTDCDriver *ltdcp); - void ltdcFgSetDefaultColorI(LTDCDriver *ltdcp, ltdc_color_t c); - void ltdcFgSetDefaultColor(LTDCDriver *ltdcp, ltdc_color_t c); - ltdc_blendf_t ltdcFgGetBlendingFactorsI(LTDCDriver *ltdcp); - ltdc_blendf_t ltdcFgGetBlendingFactors(LTDCDriver *ltdcp); - void ltdcFgSetBlendingFactorsI(LTDCDriver *ltdcp, ltdc_blendf_t bf); - void ltdcFgSetBlendingFactors(LTDCDriver *ltdcp, ltdc_blendf_t bf); - void ltdcFgGetWindowI(LTDCDriver *ltdcp, ltdc_window_t *windowp); - void ltdcFgGetWindow(LTDCDriver *ltdcp, ltdc_window_t *windowp); - void ltdcFgSetWindowI(LTDCDriver *ltdcp, const ltdc_window_t *windowp); - void ltdcFgSetWindow(LTDCDriver *ltdcp, const ltdc_window_t *windowp); - void ltdcFgSetInvalidWindowI(LTDCDriver *ltdcp); - void ltdcFgSetInvalidWindow(LTDCDriver *ltdcp); - void ltdcFgGetFrameI(LTDCDriver *ltdcp, ltdc_frame_t *framep); - void ltdcFgGetFrame(LTDCDriver *ltdcp, ltdc_frame_t *framep); - void ltdcFgSetFrameI(LTDCDriver *ltdcp, const ltdc_frame_t *framep); - void ltdcFgSetFrame(LTDCDriver *ltdcp, const ltdc_frame_t *framep); - void *ltdcFgGetFrameAddressI(LTDCDriver *ltdcp); - void *ltdcFgGetFrameAddress(LTDCDriver *ltdcp); - void ltdcFgSetFrameAddressI(LTDCDriver *ltdcp, void *bufferp); - void ltdcFgSetFrameAddress(LTDCDriver *ltdcp, void *bufferp); - void ltdcFgGetLayerI(LTDCDriver *ltdcp, ltdc_laycfg_t *cfgp); - void ltdcFgGetLayer(LTDCDriver *ltdcp, ltdc_laycfg_t *cfgp); - void ltdcFgSetConfigI(LTDCDriver *ltdcp, const ltdc_laycfg_t *cfgp); - void ltdcFgSetConfig(LTDCDriver *ltdcp, const ltdc_laycfg_t *cfgp); - - /* Helper functions.*/ - size_t ltdcBitsPerPixel(ltdc_pixfmt_t fmt); -#if LTDC_USE_SOFTWARE_CONVERSIONS || defined(__DOXYGEN__) - ltdc_color_t ltdcFromARGB8888(ltdc_color_t c, ltdc_pixfmt_t fmt); - ltdc_color_t ltdcToARGB8888(ltdc_color_t c, ltdc_pixfmt_t fmt); -#endif /* LTDC_USE_SOFTWARE_CONVERSIONS */ - #endif /* STM32_LTDC_H */ From 2a1c7785ccd0cb0b4675c06c2c48e270e7d926e4 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 7 Nov 2014 12:05:23 +1000 Subject: [PATCH 80/87] Fix the newmouse STMPE811 driver. Finalise the STM32F429i-Discovery board file for that touch controller --- .../gmouse_lld_STMPE811_board.h | 15 +- .../gmouse_lld_STMPE811_board.h | 18 +- .../touch/STMPE811/gmouse_lld_STMPE811.c | 231 ++++++++++++------ .../gmouse_lld_STMPE811_board_template.h | 12 +- drivers/ginput/touch/STMPE811/readme.txt | 11 + drivers/ginput/touch/STMPE811/stmpe811.h | 3 - 6 files changed, 198 insertions(+), 92 deletions(-) create mode 100644 drivers/ginput/touch/STMPE811/readme.txt diff --git a/boards/base/Embest-STM32-DMSTF4BB/gmouse_lld_STMPE811_board.h b/boards/base/Embest-STM32-DMSTF4BB/gmouse_lld_STMPE811_board.h index f6d0e74c..bbb17010 100644 --- a/boards/base/Embest-STM32-DMSTF4BB/gmouse_lld_STMPE811_board.h +++ b/boards/base/Embest-STM32-DMSTF4BB/gmouse_lld_STMPE811_board.h @@ -19,18 +19,21 @@ // How much extra data to allocate at the end of the GMouse structure for the board's use #define GMOUSE_STMPE811_BOARD_DATA_SIZE 0 -// Set this to TRUE if you want self-calibration. -// NOTE: This is not as accurate as real calibration. -// It requires the orientation of the touch panel to match the display. -// It requires the active area of the touch panel to exactly match the display size. -#define GMOUSE_STMPE811_SELF_CALIBRATE FALSE +// Options - Leave these commented to make it user configurable in the gfxconf.h +//#define GMOUSE_STMPE811_READ_PRESSURE FALSE +//#define GMOUSE_STMPE811_SELF_CALIBRATE FALSE +//#define GMOUSE_STMPE811_TEST_MODE FALSE // If TRUE this board has the STMPE811 IRQ pin connected to a GPIO. -#define GMOUSE_STMPE811_GPIO_IRQPIN TRUE +// Note: Although this board has such a pin its reliability has not been tested on this board!!!!! +#define GMOUSE_STMPE811_GPIO_IRQPIN FALSE // If TRUE this is a really slow CPU and we should always clear the FIFO between reads. #define GMOUSE_STMPE811_SLOW_CPU FALSE +// Slave address +#define STMPE811_ADDR (0x82 >> 1) + // Maximum timeout #define STMPE811_TIMEOUT 0x3000 diff --git a/boards/base/STM32F429i-Discovery/gmouse_lld_STMPE811_board.h b/boards/base/STM32F429i-Discovery/gmouse_lld_STMPE811_board.h index 53c15e86..f5bab2b9 100644 --- a/boards/base/STM32F429i-Discovery/gmouse_lld_STMPE811_board.h +++ b/boards/base/STM32F429i-Discovery/gmouse_lld_STMPE811_board.h @@ -19,18 +19,20 @@ // How much extra data to allocate at the end of the GMouse structure for the board's use #define GMOUSE_STMPE811_BOARD_DATA_SIZE 0 -// Set this to TRUE if you want self-calibration. -// NOTE: This is not as accurate as real calibration. -// It requires the orientation of the touch panel to match the display. -// It requires the active area of the touch panel to exactly match the display size. -#define GMOUSE_STMPE811_SELF_CALIBRATE FALSE +// Options - Leave these commented to make it user configurable in the gfxconf.h +//#define GMOUSE_STMPE811_READ_PRESSURE FALSE +//#define GMOUSE_STMPE811_SELF_CALIBRATE FALSE +//#define GMOUSE_STMPE811_TEST_MODE FALSE -// If TRUE this board has the STMPE811 IRQ pin connected to a GPIO. -#define GMOUSE_STMPE811_GPIO_IRQPIN TRUE +// Set to FALSE because it does not work properly on this board even though the pin exists. +#define GMOUSE_STMPE811_GPIO_IRQPIN FALSE // If TRUE this is a really slow CPU and we should always clear the FIFO between reads. #define GMOUSE_STMPE811_SLOW_CPU FALSE +// Slave address +#define STMPE811_ADDR 0x41 + // Maximum timeout #define STMPE811_TIMEOUT 0x3000 @@ -47,10 +49,12 @@ static bool_t init_board(GMouse* m, unsigned driverinstance) { if (driverinstance) return FALSE; + // Set pin modes palSetPadMode(GPIOA, 15, PAL_MODE_INPUT | PAL_STM32_PUDR_FLOATING); /* TP IRQ */ palSetPadMode(GPIOA, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SCL */ palSetPadMode(GPIOC, 9, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SDA */ + // Start the I2C i2cStart(&I2CD3, &i2ccfg); return TRUE; diff --git a/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c index 71c3c5d7..27bc280e 100644 --- a/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c +++ b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c @@ -12,14 +12,51 @@ #define GMOUSE_DRIVER_VMT GMOUSEVMT_STMPE811 #include "src/ginput/driver_mouse.h" -#define GMOUSE_STMPE811_FLG_TOUCHED (GMOUSE_FLG_DRIVER_FIRST<<0) - // Hardware definitions #include "drivers/ginput/touch/STMPE811/stmpe811.h" // Get the hardware interface #include "gmouse_lld_STMPE811_board.h" +// Extra settings for the users gfxconf.h file. See readme.txt +#ifndef GMOUSE_STMPE811_SELF_CALIBRATE + #define GMOUSE_STMPE811_SELF_CALIBRATE FALSE +#endif +#ifndef GMOUSE_STMPE811_READ_PRESSURE + #define GMOUSE_STMPE811_READ_PRESSURE FALSE +#endif +#ifndef GMOUSE_STMPE811_TEST_MODE + #define GMOUSE_STMPE811_TEST_MODE FALSE +#endif + +/** + * Notes: + * + * This chip has some problems which required careful coding to overcome. + * + * The interrupt pin seems to be unreliable, at least on some boards, so we at most + * use the pin for filtering results to reduce cpu load. + * The symptoms are that readings will just stop due to the irq not being asserted + * even though there are items in the fifo. Another interrupt source such as a + * touch transition will restart the irq. + * + * There is no fifo entry created when a touch up event occurs. We must therefore + * generate a pseudo result on touch up. Fortunately the touch detection appears + * reliable and so we turn off the driver GMOUSE_VFLG_POORUPDOWN setting. In practice + * if touch is up we always return a pseudo event as this saves having to remember the + * previous touch state. + * + * Z readings range from around 90 (fully touched) to around 150 (on the verge of non-touched). + * Note the above is on the STM32F429i-Discovery board. Other boards may be different. + * To be conservative we use 255 as touch off, anything else is a touch on. + * + * GMOUSE_STMPE811_TEST_MODE is designed to be used with the "touch_raw_readings" tool which shows + * a steady stream of raw readings. + * + * Settings that may need tweaking on other hardware: + * The settling times. We have set these conservatively at 1ms. + * The reading window. We set this to 16 just to reduce noise. High-res panels may need a lower value. + */ static bool_t MouseInit(GMouse* m, unsigned driverinstance) { if (!init_board(m, driverinstance)) return FALSE; @@ -32,120 +69,172 @@ static bool_t MouseInit(GMouse* m, unsigned driverinstance) { write_reg(m, STMPE811_REG_SYS_CTRL2, 0x0C); // Temperature sensor clock off, GPIO clock off, touch clock on, ADC clock on #if GMOUSE_STMPE811_GPIO_IRQPIN - write_reg(m, STMPE811_REG_INT_EN, 0x01); // Interrupt on INT pin when touch is detected + write_reg(m, STMPE811_REG_INT_EN, 0x03); // Interrupt on INT pin when there is a sample or a touch transition. #else - write_reg(m, STMPE811_REG_INT_EN, 0x00); // Don't Interrupt on INT pin when touch is detected + write_reg(m, STMPE811_REG_INT_EN, 0x00); // Don't Interrupt on INT pin #endif write_reg(m, STMPE811_REG_ADC_CTRL1, 0x48); // ADC conversion time = 80 clock ticks, 12-bit ADC, internal voltage refernce gfxSleepMilliseconds(2); - write_reg(m, STMPE811_REG_ADC_CTRL2, 0x01); // ADC speed 3.25MHz write_reg(m, STMPE811_REG_GPIO_AF, 0x00); // GPIO alternate function - OFF - write_reg(m, STMPE811_REG_TSC_CFG, 0x9A); // Averaging 4, touch detect delay 500 us, panel driver settling time 500 us - write_reg(m, STMPE811_REG_FIFO_TH, 0x40); // FIFO threshold = 64 + write_reg(m, STMPE811_REG_TSC_CFG, 0xA3); // Averaging 4, touch detect delay 1ms, panel driver settling time 1ms + write_reg(m, STMPE811_REG_FIFO_TH, 0x01); // FIFO threshold = 1 write_reg(m, STMPE811_REG_FIFO_STA, 0x01); // FIFO reset enable write_reg(m, STMPE811_REG_FIFO_STA, 0x00); // FIFO reset disable write_reg(m, STMPE811_REG_TSC_FRACT_XYZ, 0x07); // Z axis data format - write_reg(m, STMPE811_REG_TSC_I_DRIVE, 0x01); // 50mA touchscreen line current - write_reg(m, STMPE811_REG_TSC_CTRL, 0x00); // X&Y&Z - write_reg(m, STMPE811_REG_TSC_CTRL, 0x01); // X&Y&Z, TSC enable - write_reg(m, STMPE811_REG_INT_STA, 0xFF); // Clear all interrupts - #if GMOUSE_STMPE811_GPIO_IRQPIN - if (read_byte(m, STMPE811_REG_TSC_CTRL) & 0x80) - m->flags |= GMOUSE_STMPE811_FLG_TOUCHED; + write_reg(m, STMPE811_REG_TSC_I_DRIVE, 0x01); // max 50mA touchscreen line current + #if GMOUSE_STMPE811_READ_PRESSURE + write_reg(m, STMPE811_REG_TSC_CTRL, 0x30); // X&Y&Z, 16 reading window + write_reg(m, STMPE811_REG_TSC_CTRL, 0x31); // X&Y&Z, 16 reading window, TSC enable + #else + write_reg(m, STMPE811_REG_TSC_CTRL, 0x32); // X&Y, 16 reading window + write_reg(m, STMPE811_REG_TSC_CTRL, 0x33); // X&Y, 16 reading window, TSC enable #endif - write_reg(m, STMPE811_REG_INT_CTRL, 0x01); // Level interrupt, enable interrupts + write_reg(m, STMPE811_REG_INT_STA, 0xFF); // Clear all interrupts + write_reg(m, STMPE811_REG_INT_CTRL, 0x01); // Level interrupt, enable interrupts release_bus(m); return TRUE; } -static void read_xyz(GMouse* m, GMouseReading* pdr) +static bool_t read_xyz(GMouse* m, GMouseReading* pdr) { - bool_t clearfifo; // Do we need to clear the FIFO + #if GMOUSE_STMPE811_TEST_MODE + static GMouseReading n; + #endif + uint8_t status; - // Assume not touched. + // Button information will be regenerated pdr->buttons = 0; - pdr->z = 0; - - aquire_bus(m); - #if GMOUSE_STMPE811_GPIO_IRQPIN - // Check if the touch controller IRQ pin has gone off - clearfifo = FALSE; - if(getpin_irq(m)) { - write_reg(m, STMPE811_REG_INT_STA, 0xFF); // clear all interrupts - if (read_byte(m, STMPE811_REG_TSC_CTRL) & 0x80) // set the new touched status - m->flags |= GMOUSE_STMPE811_FLG_TOUCHED; - else - m->flags &= ~GMOUSE_STMPE811_FLG_TOUCHED; - clearfifo = TRUE; // only take the last FIFO reading + #if GMOUSE_STMPE811_TEST_MODE + aquire_bus(m); + + // Set the buttons to match various touch signals + if ((read_byte(m, STMPE811_REG_TSC_CTRL) & 0x80)) + pdr->buttons |= 0x02; + + status = read_byte(m, STMPE811_REG_FIFO_STA); + if (!(status & 0x20)) + pdr->buttons |= 0x04; + + #if GMOUSE_STMPE811_GPIO_IRQPIN + if (getpin_irq(m)) + pdr->buttons |= 0x08; + #endif + + if ((status & 0x20)) { + // Nothing in the fifo - just return the last position and pressure + pdr->x = n.x; + pdr->y = n.y; + pdr->z = n.z; + #if GMOUSE_STMPE811_GPIO_IRQPIN + write_reg(m, STMPE811_REG_INT_STA, 0xFF); + #endif + release_bus(m); + return TRUE; } #else - // Poll to get the touched status - uint16_t last_touched; + // Is there a new sample or a touch transition + #if GMOUSE_STMPE811_GPIO_IRQPIN + if(!getpin_irq(m)) + return FALSE; + #endif + + // Is there something in the fifo + status = read_byte(m, STMPE811_REG_FIFO_STA); + if ((status & 0x20)) { + + // Nothing in the fifo. + + // If not touched return the pseudo result + if (!(read_byte(m, STMPE811_REG_TSC_CTRL) & 0x80)) { + + pdr->z = gmvmt(m)->z_min; + #if GMOUSE_STMPE811_GPIO_IRQPIN + write_reg(m, STMPE811_REG_INT_STA, 0xFF); + #endif + release_bus(m); + return TRUE; + } + + // No new result + #if GMOUSE_STMPE811_GPIO_IRQPIN + write_reg(m, STMPE811_REG_INT_STA, 0xFF); + #endif + release_bus(m); + return FALSE; + } - last_touched = m->flags; - if (read_byte(m, STMPE811_REG_TSC_CTRL) & 0x80) // set the new touched status - m->flags |= GMOUSE_STMPE811_FLG_TOUCHED; - else - m->flags &= ~GMOUSE_STMPE811_FLG_TOUCHED; - clearfifo = ((m->flags ^ last_touched) & GMOUSE_STMPE811_FLG_TOUCHED) ? TRUE : FALSE; #endif - // If not touched don't do any more - if ((m->flags & GMOUSE_STMPE811_FLG_TOUCHED)) { + // Time to get some readings + pdr->x = (coord_t)read_word(m, STMPE811_REG_TSC_DATA_X); + pdr->y = (coord_t)read_word(m, STMPE811_REG_TSC_DATA_Y); + #if GMOUSE_STMPE811_READ_PRESSURE + pdr->z = (coord_t)read_byte(m, STMPE811_REG_TSC_DATA_Z); + #else + pdr->z = gmvmt(m)->z_max; + #endif - // Clear the fifo if it is too full - #if !GMOUSE_STMPE811_SLOW_CPU - if (!clearfifo && (read_byte(m, STMPE811_REG_FIFO_STA) & 0xD0)) - #endif - clearfifo = TRUE; + #if !GMOUSE_STMPE811_SLOW_CPU + if (!(status & 0xC0)) { + // Is there more data to come + if (!(read_byte(m, STMPE811_REG_FIFO_STA) & 0x20)) + _gmouseWakeup(m); + } else + #endif - do { - /* Get the X, Y, Z values */ - /* This could be done in a single 4 byte read to STMPE811_REG_TSC_DATA_XYZ (incr or non-incr) */ - pdr->x = (coord_t)read_word(m, STMPE811_REG_TSC_DATA_X); - pdr->y = (coord_t)read_word(m, STMPE811_REG_TSC_DATA_Y); - pdr->z = (coord_t)read_byte(m, STMPE811_REG_TSC_DATA_Z); - } while(clearfifo && !(read_byte(m, STMPE811_REG_FIFO_STA) & 0x20)); - - #if GMOUSE_STMPE811_SELF_CALIBRATE - // Rescale X,Y,Z - If we are using self-calibration - pdr->x = gdispGGetWidth(m->display) - pdr->x / (4096/gdispGGetWidth(m->display)); - pdr->y = pdr->y / (4096/gdispGGetHeight(m->display)); - #endif - - /* Force another read if we have more results */ - if (!clearfifo && !(read_byte(m, STMPE811_REG_FIFO_STA) & 0x20)) - _gmouseWakeup(m); + // Clear the rest of the fifo + { + write_reg(m, STMPE811_REG_FIFO_STA, 0x01); // FIFO reset enable + write_reg(m, STMPE811_REG_FIFO_STA, 0x00); // FIFO reset disable } + // All done + #if GMOUSE_STMPE811_GPIO_IRQPIN + write_reg(m, STMPE811_REG_INT_STA, 0xFF); + #endif release_bus(m); + + #if GMOUSE_STMPE811_TEST_MODE + // Save the result for later + n.x = pdr->x; + n.y = pdr->y; + n.z = pdr->z; + #endif + + // Rescale X,Y if we are using self-calibration + #if GMOUSE_STMPE811_SELF_CALIBRATE + pdr->x = gdispGGetWidth(m->display) - pdr->x / (4096/gdispGGetWidth(m->display)); + pdr->y = pdr->y / (4096/gdispGGetHeight(m->display)); + #endif + + return TRUE; } const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ { GDRIVER_TYPE_TOUCH, #if GMOUSE_STMPE811_SELF_CALIBRATE - GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN, + GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN, #else - GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN | GMOUSE_VFLG_CALIBRATE | GMOUSE_VFLG_CAL_TEST, + GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_CALIBRATE | GMOUSE_VFLG_CAL_TEST, #endif sizeof(GMouse) + GMOUSE_STMPE811_BOARD_DATA_SIZE, _gmouseInitDriver, _gmousePostInitDriver, _gmouseDeInitDriver }, - 255, // z_max - 0, // z_min - 200, // z_touchon - 20, // z_touchoff + 0, // z_max - 0 indicates full touch + 255, // z_min + 150, // z_touchon + 255, // z_touchoff { // pen_jitter - GMOUSE_STMPE811_PEN_CALIBRATE_ERROR, // calibrate - GMOUSE_STMPE811_PEN_CLICK_ERROR, // click + GMOUSE_STMPE811_PEN_CALIBRATE_ERROR, // calibrate + GMOUSE_STMPE811_PEN_CLICK_ERROR, // click GMOUSE_STMPE811_PEN_MOVE_ERROR // move }, { // finger_jitter diff --git a/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811_board_template.h b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811_board_template.h index 437abc09..4520cf67 100644 --- a/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811_board_template.h +++ b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811_board_template.h @@ -19,13 +19,15 @@ // How much extra data to allocate at the end of the GMouse structure for the board's use #define GMOUSE_STMPE811_BOARD_DATA_SIZE 0 -// Set this to TRUE if you want self-calibration. -// NOTE: This is not as accurate as real calibration. -// It requires the orientation of the touch panel to match the display. -// It requires the active area of the touch panel to exactly match the display size. -#define GMOUSE_STMPE811_SELF_CALIBRATE FALSE +// Options - Leave these commented to make it user configurable in the gfxconf.h +//#define GMOUSE_STMPE811_READ_PRESSURE FALSE +//#define GMOUSE_STMPE811_SELF_CALIBRATE FALSE +//#define GMOUSE_STMPE811_TEST_MODE FALSE // If TRUE this board has the STMPE811 IRQ pin connected to a GPIO. +// Note: For tested hardware this is unreliable and should be set to FALSE until tested. +// Symptoms are that mouse readings just appear to stop for a bit. Lifting the touch +// and re-applying the touch cause readings to start again. #define GMOUSE_STMPE811_GPIO_IRQPIN FALSE // If TRUE this is a really slow CPU and we should always clear the FIFO between reads. diff --git a/drivers/ginput/touch/STMPE811/readme.txt b/drivers/ginput/touch/STMPE811/readme.txt new file mode 100644 index 00000000..60d7f603 --- /dev/null +++ b/drivers/ginput/touch/STMPE811/readme.txt @@ -0,0 +1,11 @@ +This driver has a number of optional settings which can be specified in gfxconf.h: + +#define GMOUSE_STMPE811_READ_PRESSURE TRUE + Returns pressure values when the touch is down. On tested boards this ranges from 90 to 150. 255 is touch off. + +#define GMOUSE_STMPE811_SELF_CALIBRATE TRUE + Scale the touch readings to avoid calibration. This is not as accurate as real calibration. + +#define GMOUSE_STMPE811_TEST_MODE TRUE + Return raw readings for diagnostic use with the "touch_raw_readings" tool. + diff --git a/drivers/ginput/touch/STMPE811/stmpe811.h b/drivers/ginput/touch/STMPE811/stmpe811.h index f0d2df42..df85889f 100644 --- a/drivers/ginput/touch/STMPE811/stmpe811.h +++ b/drivers/ginput/touch/STMPE811/stmpe811.h @@ -8,9 +8,6 @@ #ifndef _STMPE811_H #define _STMPE811_H -// Slave address -#define STMPE811_ADDR (0x82 >> 1) - // Identification registers #define STMPE811_REG_CHP_ID 0x00 // 16-bit #define STMPE811_REG_ID_VER 0x02 From baebbad6237f657762523624016cd7d6d5926999 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 7 Nov 2014 13:06:02 +1000 Subject: [PATCH 81/87] Fix GDISP_NEED_CONTROL for the STM32F429i-Discovery board. --- .../board_STM32F429iDiscovery.h | 43 +++++-------------- .../gdisp_lld_STM32F429iDiscovery.c | 6 +-- 2 files changed, 13 insertions(+), 36 deletions(-) diff --git a/boards/base/STM32F429i-Discovery/board_STM32F429iDiscovery.h b/boards/base/STM32F429i-Discovery/board_STM32F429iDiscovery.h index e0b2dcb6..274c97cd 100644 --- a/boards/base/STM32F429i-Discovery/board_STM32F429iDiscovery.h +++ b/boards/base/STM32F429i-Discovery/board_STM32F429iDiscovery.h @@ -60,17 +60,17 @@ static inline void init_board(GDisplay *g) { palSetPadMode(GPIOF, GPIOF_LCD_DCX, PAL_MODE_ALTERNATE(5)); palSetPadMode(GPIOF, GPIOF_LCD_DE, PAL_MODE_ALTERNATE(14)); -#define STM32_SAISRC_NOCLOCK (0 << 23) /**< No clock. */ -#define STM32_SAISRC_PLL (1 << 23) /**< SAI_CKIN is PLL. */ -#define STM32_SAIR_DIV2 (0 << 16) /**< R divided by 2. */ -#define STM32_SAIR_DIV4 (1 << 16) /**< R divided by 4. */ -#define STM32_SAIR_DIV8 (2 << 16) /**< R divided by 8. */ -#define STM32_SAIR_DIV16 (3 << 16) /**< R divided by 16. */ + #define STM32_SAISRC_NOCLOCK (0 << 23) /**< No clock. */ + #define STM32_SAISRC_PLL (1 << 23) /**< SAI_CKIN is PLL. */ + #define STM32_SAIR_DIV2 (0 << 16) /**< R divided by 2. */ + #define STM32_SAIR_DIV4 (1 << 16) /**< R divided by 4. */ + #define STM32_SAIR_DIV8 (2 << 16) /**< R divided by 8. */ + #define STM32_SAIR_DIV16 (3 << 16) /**< R divided by 16. */ -#define STM32_PLLSAIN_VALUE 192 -#define STM32_PLLSAIQ_VALUE 7 -#define STM32_PLLSAIR_VALUE 4 -#define STM32_PLLSAIR_POST STM32_SAIR_DIV4 + #define STM32_PLLSAIN_VALUE 192 + #define STM32_PLLSAIQ_VALUE 7 + #define STM32_PLLSAIR_VALUE 4 + #define STM32_PLLSAIR_POST STM32_SAIR_DIV4 /* PLLSAI activation.*/ RCC->PLLSAICFGR = (STM32_PLLSAIN_VALUE << 6) | (STM32_PLLSAIR_VALUE << 28) | (STM32_PLLSAIQ_VALUE << 24); @@ -92,32 +92,9 @@ static inline void post_init_board(GDisplay *g) { (void) g; } -static inline void setpin_reset(GDisplay *g, bool_t state) { - (void) g; - (void) state; - /* - if(state) { - // reset lcd - palClearPad(GPIOE, GPIOE_LCD_RST); - } else { - palSetPad(GPIOE, GPIOE_LCD_RST); - } - */ -} - static inline void set_backlight(GDisplay *g, uint8_t percent) { (void) g; (void) percent; - // TODO: can probably pwm this - /* - if(percent) { - // turn back light on - palSetPad(GPIOE, GPIOE_LCD_BLED); - } else { - // turn off - palClearPad(GPIOE, GPIOE_LCD_BLED); - } - */ } static inline void acquire_bus(GDisplay *g) { diff --git a/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_STM32F429iDiscovery.c b/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_STM32F429iDiscovery.c index 88d50114..65e582b2 100644 --- a/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_STM32F429iDiscovery.c +++ b/drivers/gdisp/STM32F429iDiscovery/gdisp_lld_STM32F429iDiscovery.c @@ -354,7 +354,7 @@ LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) { return; switch((powermode_t)g->p.ptr) { case powerOff: case powerOn: case powerSleep: case powerDeepSleep: - board_power(g, (powermode_t)g->p.ptr); + // TODO break; default: return; @@ -394,13 +394,13 @@ LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) { case GDISP_CONTROL_BACKLIGHT: if ((unsigned)g->p.ptr > 100) g->p.ptr = (void *)100; - board_backlight(g, (unsigned)g->p.ptr); + set_backlight(g, (unsigned)g->p.ptr); g->g.Backlight = (unsigned)g->p.ptr; return; case GDISP_CONTROL_CONTRAST: if ((unsigned)g->p.ptr > 100) g->p.ptr = (void *)100; - board_contrast(g, (unsigned)g->p.ptr); + // TODO g->g.Contrast = (unsigned)g->p.ptr; return; } From f65b1896733e3f8cfa2e0f074585e5c5d7657331 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sun, 9 Nov 2014 21:55:15 +0100 Subject: [PATCH 82/87] Added MAX11802 driver - NOT WORKING YET - read_xyz() not ported yet --- docs/releases.txt | 1 + drivers/ginput/touch/MAX11802/driver.mk | 2 + .../touch/MAX11802/gmouse_lld_MAX11802.c | 172 ++++++++++++++++++ .../gmouse_lld_MAX11802_board_template.h | 71 ++++++++ drivers/ginput/touch/MAX11802/max11802.h | 31 ++++ 5 files changed, 277 insertions(+) create mode 100644 drivers/ginput/touch/MAX11802/driver.mk create mode 100644 drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802.c create mode 100644 drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802_board_template.h create mode 100644 drivers/ginput/touch/MAX11802/max11802.h diff --git a/docs/releases.txt b/docs/releases.txt index b97b17d5..ef1e4547 100644 --- a/docs/releases.txt +++ b/docs/releases.txt @@ -35,6 +35,7 @@ FEATURE: Added gdispDrawArcSectors() and gdispFillArcSectors(). FEATURE: Ported GINPUT MOUSE to GDRIVER infrastructure. FEATURE: Mouse/Touch now support both pen and finger mode. DEPRECATE: gwinAttachMouse() is now handled automaticly. +FEATURE: Added MAX11802 touch driver by user steved *** Release 2.1 *** diff --git a/drivers/ginput/touch/MAX11802/driver.mk b/drivers/ginput/touch/MAX11802/driver.mk new file mode 100644 index 00000000..246e48b3 --- /dev/null +++ b/drivers/ginput/touch/MAX11802/driver.mk @@ -0,0 +1,2 @@ +# List the required driver. +GFXSRC += $(GFXLIB)/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802.c diff --git a/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802.c b/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802.c new file mode 100644 index 00000000..0adeddf5 --- /dev/null +++ b/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802.c @@ -0,0 +1,172 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#include "gfx.h" + +#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE + +#define GMOUSE_DRIVER_VMT GMOUSEVMT_MAX11802 +#include "src/ginput/driver_mouse.h" + +#define GMOUSE_MAX11802_FLG_TOUCHED (GMOUSE_FLG_DRIVER_FIRST << 0) + +// Hardware definitions +#include "drivers/ginput/touch/MAX11802/max11802.h" + +// Get the hardware interface +#include "gmouse_lld_MAX11802_board.h" + +// Last values read from A-D channels +static uint16_t lastx, lasty; +static uint16_t lastz = { 100 << 4 }; // This may not be used, so initialise it (value is bits 15..4) + +static bool_t MouseInit(GMouse* m, unsigned driverinstance) +{ + uint8_t ret; + + const uint8_t commandList[][2] = { + { MAX11802_CMD_GEN_WR, 0xf0 }, // General config - leave TIRQ enabled, even though we ignore it ATM + { MAX11802_CMD_RES_WR, 0x00 }, // A-D resolution, hardware config - rewriting default; all 12-bit resolution + { MAX11802_CMD_AVG_WR, MAX11802_AVG }, // A-D averaging - 8 samples, average four median samples + { MAX11802_CMD_SAMPLE_WR, 0x00 }, // A-D sample time - use default + { MAX11802_CMD_TIMING_WR, MAX11802_TIMING }, // Setup timing + { MAX11802_CMD_DELAY_WR, MAX11802_DELAY }, // Conversion delays + { MAX11802_CMD_TDPULL_WR, 0x00 }, // A-D resolution, hardware config - rewrite default + //{ MAX11802_CMD_MDTIM_WR, 0x00 }, // Autonomous mode timing - write default + //{ MAX11802_CMD_APCONF_WR, 0x00 }, // Aperture config register - rewrite default + // Ignore aux config register - not used + { MAX11802_CMD_MODE_WR, MAX11802_MODE }, // Set mode last + }; + + if (!init_board(m, driverinstance)) + return FALSE; + + aquire_bus(m); + + for (ret = 0; ret < (sizeof(commandList) / (2 * sizeof(uint8_t))); ret++) { + write_command(m, commandList[ret][0], commandList[ret][1]); + } + + ret = write_command(m, MAX11802_CMD_MODE_RD, 0); // Read something as a test + if (ret != MAX11802_MODE) { + // Error here - @TODO: What can we do about it? + } + + release_bus(m); +} + +static void read_xyz(GMouse* m, GMouseReading* pdr) +{ + uint8_t readyCount; + uint8_t notReadyCount; + + // Assume not touched. + pdr->buttons = 0; + pdr->z = 0; + + aquire_bus(m); + +#if MAX11802_READ_Z_VALUE + gfintWriteCommand(m, MAX11802_CMD_MEASUREXYZ); // just write command +#else + gfintWriteCommand(m, MAX11802_CMD_MEASUREXY); // just write command +#endif + + /** + * put a delay in here, since conversion will take a finite time - longer if reading Z as well + * Potentially 1msec for 3 axes with 8us conversion time per sample, 8 samples per average + * Note Maxim AN5435-software to do calculation (www.maximintegrated.com/design/tools/appnotes/5435/AN5435-software.zip) + * + * We'll just use a fixed delay to avoid too much polling/bus activity + */ + gfxSleepMilliseconds(2); // Was 1 - try 2 + + /* Wait for data ready + * Note: MAX11802 signals the readiness of the results using the lowest 4 bits of the result. However, these are the + * last bits to be read out of the device. It is possible for the hardware value to change in the middle of the read, + * causing the analog value to still be invalid even though the tags indicate a valid result. + * + * We work around this by reading the registers once more after the tags indicate they are ready. + * There's also a separate counter to guard against never getting valid readings. + * + * Read the two or three readings required in a single burst, swapping x and y order if necessary + */ + + readyCount = 0; + notReadyCount = 0; + do { + gfintWriteCommand(m, MAX11802_CMD_XPOSITION); // This sets pointer to first byte of block + +#if defined(GINPUT_MOUSE_YX_INVERTED) && GINPUT_MOUSE_YX_INVERTED + lasty = read_value(m); + lastx = read_value(m); +#else + lastx = read_value(m); + lasty = read_value(m)); +#endif +#if MAX11802_READ_Z_VALUE + lastz = read_value(m); + if (((lastx & 0x0f) != 0xF) && ((lasty * 0xf0) != 0xF) && ((lastz * 0xf0) != 0xF)) +#else + if (((lastx & 0x0f) != 0xF) && ((lasty * 0xf0) != 0xF)) +#endif + { + readyCount++; + } + else + { + notReadyCount++; // Protect against infinite loops + } + } while ((readyCount < 2) && (notReadyCount < 20)); + + + /** + * format of each value returned by MAX11802: + * Bits 15..4 - analog value + * Bits 3..2 - tag value - measurement type (X, Y, Z1, Z2) + * Bits 1..0 - tag value - event type (00 = valid touch, 10 - no touch, 11 - measurement in progress) + */ + pt->x = lastx >> 4; // Delete the tags + pt->y = lasty >> 4; + pt->z = lastz >> 4; // If no Z-axis, lastz has been initialised to return 100 + + pt->buttons = ((0 == (lastx & 3)) && (0 == (lasty & 3)) && (0 == (lastz & 3))) ? GINPUT_TOUCH_PRESSED : 0; + + release_bus(m); +} + +const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ + { + GDRIVER_TYPE_TOUCH, + GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN | GMOUSE_VFLG_CALIBRATE | GMOUSE_VFLG_CAL_TEST, + sizeof(GMouse) + GMOUSE_MAX11802_BOARD_DATA_SIZE, + _gmouseInitDriver, + _gmousePostInitDriver, + _gmouseDeInitDriver + }, + 255, // z_max + 0, // z_min + 20, // z_touchoff + 200, // z_touchon + { // pen_jitter + GMOUSE_MAX11802_PEN_CALIBRATE_ERROR, // calibrate + GMOUSE_MAX11802_PEN_CLICK_ERROR, // click + GMOUSE_MAX11802_PEN_MOVE_ERROR // move + }, + { // finger_jitter + GMOUSE_MAX11802_FINGER_CALIBRATE_ERROR, // calibrate + GMOUSE_MAX11802_FINGER_CLICK_ERROR, // click + GMOUSE_MAX11802_FINGER_MOVE_ERROR // move + }, + MouseInit, // init + 0, // deinit + read_xyz, // get + 0, // calsave + 0 // calload +}}; + +#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */ diff --git a/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802_board_template.h b/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802_board_template.h new file mode 100644 index 00000000..113b2a01 --- /dev/null +++ b/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802_board_template.h @@ -0,0 +1,71 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _GINPUT_LLD_MOUSE_BOARD_H +#define _GINPUT_LLD_MOUSE_BOARD_H + +// Experimental to read pressure on Z1 as well +#define MAX11802_READ_Z_VALUE FALSE + +// Resolution and Accuracy Settings +#define GMOUSE_MAX11802_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_MAX11802_PEN_CLICK_ERROR 6 +#define GMOUSE_MAX11802_PEN_MOVE_ERROR 4 +#define GMOUSE_MAX11802_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_MAX11802_FINGER_CLICK_ERROR 18 +#define GMOUSE_MAX11802_FINGER_MOVE_ERROR 14 + +// Register values to set +#define MAX11802_MODE 0x0E // Direct conversion with averaging +#define MAX11802_AVG 0x55 +#define MAX11802_TIMING 0x77 +#define MAX11802_DELAY 0x55 + +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_MAX11802_BOARD_DATA_SIZE 0 + +static inline void init_board(GMouse* m) { + +} + +static inline bool_t getpin_pressed(GMouse* m) { + +} + +static inline void aquire_bus(GMouse* m) { + +} + +static inline void release_bus(GMouse* m) { + +} + +/** + * Send command (with parameter) to the MAX11802 + * + * Return the second byte read in case of interest + */ +static inline uint8_t write_command(GMouse* m, uint8_t command, uint8_t value) { +} + +/** + * Send command (no parameter) to the MAX11802 + * + * Return the byte read in case of interest + */ +static inline uint8_t gfintWriteCommand(GMouse* m, uint8_t command) { +} + +/* + * Read 2 bytes as 16-bit value (command to read must have been sent previously) + * Note: Analog value is in bits 15..4, tags (reading status) in bits 3..0 +*/ +static inline uint16_t read_value(GMouse* m) { + +} + +#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ diff --git a/drivers/ginput/touch/MAX11802/max11802.h b/drivers/ginput/touch/MAX11802/max11802.h new file mode 100644 index 00000000..2266bfa1 --- /dev/null +++ b/drivers/ginput/touch/MAX11802/max11802.h @@ -0,0 +1,31 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _MAX11802_H +#define _MAX11802_H + +#define MAX11802_CMD_XPOSITION ((0x52 << 1) | 1) +#define MAX11802_CMD_YPOSITION ((0x54 << 1) | 1) +#define MAX11802_CMD_ZPOSITION ((0x56 << 1) | 1) + +// LSB of register addresses specifies read (1) or write (0) +#define MAX11802_CMD_MEASUREXY (0x70 << 1) +#define MAX11802_CMD_MEASUREXYZ (0x72 << 1) +#define MAX11802_CMD_GEN_WR (0x01 << 1) // General config register +#define MAX11802_CMD_RES_WR (0x02 << 1) +#define MAX11802_CMD_AVG_WR (0x03 << 1) +#define MAX11802_CMD_SAMPLE_WR (0x04 << 1) +#define MAX11802_CMD_TIMING_WR (0x05 << 1) +#define MAX11802_CMD_DELAY_WR (0x06 << 1) +#define MAX11802_CMD_TDPULL_WR (0x07 << 1) +#define MAX11802_CMD_MDTIM_WR (0x08 << 1) +#define MAX11802_CMD_APCONF_WR (0x09 << 1) +#define MAX11802_CMD_MODE_WR (0x0B << 1) +#define MAX11802_CMD_MODE_RD ((0x0B << 1) | 1) +#define MAX11802_CMD_GSR_RD ((0x00 << 1) | 1) // General status register - read-only + +#endif /* _MAX11802_H */ From 069c791fc1be91464154327718bbd3a36d09661c Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 10 Nov 2014 13:54:19 +1000 Subject: [PATCH 83/87] Update to MAX11802 touch driver. To be tested. --- .../touch/MAX11802/gmouse_lld_MAX11802.c | 135 ++++++++++-------- .../gmouse_lld_MAX11802_board_template.h | 3 - 2 files changed, 73 insertions(+), 65 deletions(-) diff --git a/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802.c b/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802.c index 0adeddf5..73d8d4e6 100644 --- a/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802.c +++ b/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802.c @@ -12,34 +12,31 @@ #define GMOUSE_DRIVER_VMT GMOUSEVMT_MAX11802 #include "src/ginput/driver_mouse.h" -#define GMOUSE_MAX11802_FLG_TOUCHED (GMOUSE_FLG_DRIVER_FIRST << 0) - // Hardware definitions #include "drivers/ginput/touch/MAX11802/max11802.h" // Get the hardware interface #include "gmouse_lld_MAX11802_board.h" -// Last values read from A-D channels -static uint16_t lastx, lasty; -static uint16_t lastz = { 100 << 4 }; // This may not be used, so initialise it (value is bits 15..4) +#define Z_MIN 0 +#define Z_MAX 1 static bool_t MouseInit(GMouse* m, unsigned driverinstance) { - uint8_t ret; + uint8_t *p; - const uint8_t commandList[][2] = { - { MAX11802_CMD_GEN_WR, 0xf0 }, // General config - leave TIRQ enabled, even though we ignore it ATM - { MAX11802_CMD_RES_WR, 0x00 }, // A-D resolution, hardware config - rewriting default; all 12-bit resolution - { MAX11802_CMD_AVG_WR, MAX11802_AVG }, // A-D averaging - 8 samples, average four median samples - { MAX11802_CMD_SAMPLE_WR, 0x00 }, // A-D sample time - use default - { MAX11802_CMD_TIMING_WR, MAX11802_TIMING }, // Setup timing - { MAX11802_CMD_DELAY_WR, MAX11802_DELAY }, // Conversion delays - { MAX11802_CMD_TDPULL_WR, 0x00 }, // A-D resolution, hardware config - rewrite default - //{ MAX11802_CMD_MDTIM_WR, 0x00 }, // Autonomous mode timing - write default - //{ MAX11802_CMD_APCONF_WR, 0x00 }, // Aperture config register - rewrite default - // Ignore aux config register - not used - { MAX11802_CMD_MODE_WR, MAX11802_MODE }, // Set mode last + static const uint8_t commandList[] = { + MAX11802_CMD_GEN_WR, 0xf0, // General config - leave TIRQ enabled, even though we ignore it ATM + MAX11802_CMD_RES_WR, 0x00, // A-D resolution, hardware config - rewriting default; all 12-bit resolution + MAX11802_CMD_AVG_WR, MAX11802_AVG, // A-D averaging - 8 samples, average four median samples + MAX11802_CMD_SAMPLE_WR, 0x00, // A-D sample time - use default + MAX11802_CMD_TIMING_WR, MAX11802_TIMING, // Setup timing + MAX11802_CMD_DELAY_WR, MAX11802_DELAY, // Conversion delays + MAX11802_CMD_TDPULL_WR, 0x00, // A-D resolution, hardware config - rewrite default + // MAX11802_CMD_MDTIM_WR, 0x00, // Autonomous mode timing - write default - only for MAX11800, MAX11801 + // MAX11802_CMD_APCONF_WR, 0x00, // Aperture config register - rewrite default - only for MAX11800, MAX11801 + // Ignore aux config register - not used + MAX11802_CMD_MODE_WR, MAX11802_MODE // Set mode last }; if (!init_board(m, driverinstance)) @@ -47,19 +44,21 @@ static bool_t MouseInit(GMouse* m, unsigned driverinstance) aquire_bus(m); - for (ret = 0; ret < (sizeof(commandList) / (2 * sizeof(uint8_t))); ret++) { - write_command(m, commandList[ret][0], commandList[ret][1]); - } + for (p = commandList; p < commandList+sizeof(commandList); p += 2) + write_command(m, p[0], p[1]); - ret = write_command(m, MAX11802_CMD_MODE_RD, 0); // Read something as a test - if (ret != MAX11802_MODE) { - // Error here - @TODO: What can we do about it? + // Read something as a test + if (write_command(m, MAX11802_CMD_MODE_RD, 0) != MAX11802_MODE) { + release_bus(m); + return FALSE; } release_bus(m); + + return TRUE; } -static void read_xyz(GMouse* m, GMouseReading* pdr) +static bool_t read_xyz(GMouse* m, GMouseReading* pdr) { uint8_t readyCount; uint8_t notReadyCount; @@ -70,11 +69,8 @@ static void read_xyz(GMouse* m, GMouseReading* pdr) aquire_bus(m); -#if MAX11802_READ_Z_VALUE - gfintWriteCommand(m, MAX11802_CMD_MEASUREXYZ); // just write command -#else + // Start the conversion gfintWriteCommand(m, MAX11802_CMD_MEASUREXY); // just write command -#endif /** * put a delay in here, since conversion will take a finite time - longer if reading Z as well @@ -94,49 +90,64 @@ static void read_xyz(GMouse* m, GMouseReading* pdr) * There's also a separate counter to guard against never getting valid readings. * * Read the two or three readings required in a single burst, swapping x and y order if necessary + * + * Reading Z is possible but complicated requiring two z readings, multiplication and division, various constant ratio's, + * and interpolation in relation to the X and Y readings. It is not a simple pressure reading. + * In other words, don't bother trying. */ - readyCount = 0; - notReadyCount = 0; + readyCount = notReadyCount = 0; do { - gfintWriteCommand(m, MAX11802_CMD_XPOSITION); // This sets pointer to first byte of block + // Get a set of readings + gfintWriteCommand(m, MAX11802_CMD_XPOSITION); + #if defined(GINPUT_MOUSE_YX_INVERTED) && GINPUT_MOUSE_YX_INVERTED + pdr->y = read_value(m); + pdr->x = read_value(m); + #else + pdr->x = read_value(m); + pdr->y = read_value(m); + #endif -#if defined(GINPUT_MOUSE_YX_INVERTED) && GINPUT_MOUSE_YX_INVERTED - lasty = read_value(m); - lastx = read_value(m); -#else - lastx = read_value(m); - lasty = read_value(m)); -#endif -#if MAX11802_READ_Z_VALUE - lastz = read_value(m); - if (((lastx & 0x0f) != 0xF) && ((lasty * 0xf0) != 0xF) && ((lastz * 0xf0) != 0xF)) -#else - if (((lastx & 0x0f) != 0xF) && ((lasty * 0xf0) != 0xF)) -#endif - { - readyCount++; + // Test the result validity + if (((pdr->x | pdr->y) & 0x03) == 0x03) { + + // Has it been too long? If so give up + if (++notReadyCount >= 5) { + release_bus(m); + return FALSE; + } + + // Give up the time slice to someone else and then try again + gfxYield(); + continue; } - else - { - notReadyCount++; // Protect against infinite loops - } - } while ((readyCount < 2) && (notReadyCount < 20)); - + + // We have a result but we need two valid results to believe it + readyCount++; + + } while (readyCount < 2); + release_bus(m); + /** * format of each value returned by MAX11802: * Bits 15..4 - analog value * Bits 3..2 - tag value - measurement type (X, Y, Z1, Z2) * Bits 1..0 - tag value - event type (00 = valid touch, 10 - no touch, 11 - measurement in progress) */ - pt->x = lastx >> 4; // Delete the tags - pt->y = lasty >> 4; - pt->z = lastz >> 4; // If no Z-axis, lastz has been initialised to return 100 - pt->buttons = ((0 == (lastx & 3)) && (0 == (lasty & 3)) && (0 == (lastz & 3))) ? GINPUT_TOUCH_PRESSED : 0; + // Was there a valid touch? + if ((pt->x & 0x03) == 0x02) { + pdr->z = Z_MIN; + return TRUE; + } - release_bus(m); + // Strip the tags + pt->x >>= 4; + pt->y >>= 4; + pdr->z = Z_MAX; + + return TRUE; } const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ @@ -148,10 +159,10 @@ const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ _gmousePostInitDriver, _gmouseDeInitDriver }, - 255, // z_max - 0, // z_min - 20, // z_touchoff - 200, // z_touchon + Z_MAX, // z_max + Z_MIN, // z_min + Z_MIN, // z_touchoff + Z_MAX, // z_touchon { // pen_jitter GMOUSE_MAX11802_PEN_CALIBRATE_ERROR, // calibrate GMOUSE_MAX11802_PEN_CLICK_ERROR, // click diff --git a/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802_board_template.h b/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802_board_template.h index 113b2a01..bea6cc6b 100644 --- a/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802_board_template.h +++ b/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802_board_template.h @@ -8,9 +8,6 @@ #ifndef _GINPUT_LLD_MOUSE_BOARD_H #define _GINPUT_LLD_MOUSE_BOARD_H -// Experimental to read pressure on Z1 as well -#define MAX11802_READ_Z_VALUE FALSE - // Resolution and Accuracy Settings #define GMOUSE_MAX11802_PEN_CALIBRATE_ERROR 8 #define GMOUSE_MAX11802_PEN_CLICK_ERROR 6 From 2904cd326bd8996b2c9781bbc636dac57a602c31 Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 10 Nov 2014 14:39:59 +1000 Subject: [PATCH 84/87] Conversion of some addon board files to newmouse --- ...ginput_lld_mouse_board_olimex_stm32_e407.h | 72 ++++---- ...put_lld_mouse_board_st_stm32f4_discovery.h | 40 +++-- ...input_lld_mouse_board_olimex_pic32mx_lcd.h | 157 +++++++----------- 3 files changed, 124 insertions(+), 145 deletions(-) diff --git a/boards/addons/ginput/touch/ADS7843/ginput_lld_mouse_board_olimex_stm32_e407.h b/boards/addons/ginput/touch/ADS7843/ginput_lld_mouse_board_olimex_stm32_e407.h index f17d6e8e..af5f1282 100644 --- a/boards/addons/ginput/touch/ADS7843/ginput_lld_mouse_board_olimex_stm32_e407.h +++ b/boards/addons/ginput/touch/ADS7843/ginput_lld_mouse_board_olimex_stm32_e407.h @@ -16,6 +16,14 @@ #ifndef _GINPUT_LLD_MOUSE_BOARD_H #define _GINPUT_LLD_MOUSE_BOARD_H +// Resolution and Accuracy Settings +#define GMOUSE_ADS7843_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_ADS7843_PEN_CLICK_ERROR 6 +#define GMOUSE_ADS7843_PEN_MOVE_ERROR 4 +#define GMOUSE_ADS7843_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_ADS7843_FINGER_CLICK_ERROR 18 +#define GMOUSE_ADS7843_FINGER_MOVE_ERROR 14 + static const SPIConfig spicfg = { 0, GPIOG, @@ -23,67 +31,49 @@ static const SPIConfig spicfg = { /* SPI_CR1_BR_2 |*/ SPI_CR1_BR_1 | SPI_CR1_BR_0, }; -/** - * @brief Initialise the board for the touch. - * - * @notapi - */ -static inline void init_board(void) { +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_ADS7843_BOARD_DATA_SIZE 0 + +static bool_t init_board(GMouse* m, unsigned driverinstance) { + (void) m; + + if (driverinstance) + return FALSE; + spiStart(&SPID2, &spicfg); + return TRUE; } -/** - * @brief Check whether the surface is currently touched - * @return TRUE if the surface is currently touched - * - * @notapi - */ -static inline bool_t getpin_pressed(void) { +static inline bool_t getpin_pressed(GMouse* m) { + (void) m; + return (!palReadPad(GPIOG, 0)); } -/** - * @brief Aquire the bus ready for readings - * - * @notapi - */ -static inline void aquire_bus(void) { + +static inline void aquire_bus(GMouse* m) { + (void) m; + spiAcquireBus(&SPID2); //TOUCHSCREEN_SPI_PROLOGUE(); palClearPad(GPIOG, 10); } -/** - * @brief Release the bus after readings - * - * @notapi - */ -static inline void release_bus(void) { +static inline void release_bus(GMouse* m) { + (void) m; + palSetPad(GPIOG, 10); spiReleaseBus(&SPID2); //TOUCHSCREEN_SPI_EPILOGUE(); } -/** - * @brief Read a value from touch controller - * @return The value read from the controller - * - * params[in] port The controller port to read. - * - * @notapi - */ -static inline uint16_t read_value(uint16_t port) { +static inline uint16_t read_value(GMouse* m, uint16_t port) { static uint8_t txbuf[3] = {0}; static uint8_t rxbuf[3] = {0}; - uint16_t ret; + (void) m; txbuf[0] = port; - spiExchange(&SPID2, 3, txbuf, rxbuf); - - ret = (rxbuf[1] << 5) | (rxbuf[2] >> 3); - - return ret; + return ((uint16_t)rxbuf[1] << 5) | (rxbuf[2] >> 3); } #endif /* _GINPUT_LLD_MOUSE_BOARD_H */ - diff --git a/boards/addons/ginput/touch/ADS7843/ginput_lld_mouse_board_st_stm32f4_discovery.h b/boards/addons/ginput/touch/ADS7843/ginput_lld_mouse_board_st_stm32f4_discovery.h index 6c3e2124..b4478d2b 100644 --- a/boards/addons/ginput/touch/ADS7843/ginput_lld_mouse_board_st_stm32f4_discovery.h +++ b/boards/addons/ginput/touch/ADS7843/ginput_lld_mouse_board_st_stm32f4_discovery.h @@ -34,41 +34,61 @@ static const SPIConfig spicfg = { /* SPI_CR1_BR_2 |*/ SPI_CR1_BR_1 | SPI_CR1_BR_0, }; -static inline void init_board(void) { +// Resolution and Accuracy Settings +#define GMOUSE_ADS7843_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_ADS7843_PEN_CLICK_ERROR 6 +#define GMOUSE_ADS7843_PEN_MOVE_ERROR 4 +#define GMOUSE_ADS7843_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_ADS7843_FINGER_CLICK_ERROR 18 +#define GMOUSE_ADS7843_FINGER_MOVE_ERROR 14 + +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_ADS7843_BOARD_DATA_SIZE 0 + +static bool_t init_board(GMouse* m, unsigned driverinstance) { + (void) m; + + if (driverinstance) + return FALSE; + palSetPadMode(GPIOB, 13, PAL_MODE_ALTERNATE(5) ); /* SCK */ palSetPadMode(GPIOB, 14, PAL_MODE_ALTERNATE(5) ); /* MISO */ palSetPadMode(GPIOB, 15, PAL_MODE_ALTERNATE(5) ); /* MOSI */ palSetPadMode(GPIOC, 4, PAL_MODE_OUTPUT_PUSHPULL); /* CS */ spiStart(&SPID2, &spicfg); + return TRUE; } -static inline bool_t getpin_pressed(void) { +static inline bool_t getpin_pressed(GMouse* m) { + (void) m; + return (!palReadPad(GPIOC, 5)); } -static inline void aquire_bus(void) { +static inline void aquire_bus(GMouse* m) { + (void) m; + spiAcquireBus(&SPID2); palClearPad(GPIOC, 4); } -static inline void release_bus(void) { +static inline void release_bus(GMouse* m) { + (void) m; + palSetPad(GPIOC, 4); spiReleaseBus(&SPID2); } -static inline uint16_t read_value(uint16_t port) { +static inline uint16_t read_value(GMouse* m, uint16_t port) { static uint8_t txbuf[3] = {0}; static uint8_t rxbuf[3] = {0}; - uint16_t ret; + (void) m; txbuf[0] = port; - spiExchange(&SPID2, 3, txbuf, rxbuf); - ret = (rxbuf[1] << 5) | (rxbuf[2] >> 3); - - return ret; + return ((uint16_t)rxbuf[1] << 5) | (rxbuf[2] >> 3); } #endif /* _GINPUT_LLD_MOUSE_BOARD_H */ diff --git a/boards/addons/ginput/touch/MCU/ginput_lld_mouse_board_olimex_pic32mx_lcd.h b/boards/addons/ginput/touch/MCU/ginput_lld_mouse_board_olimex_pic32mx_lcd.h index 87e2a93c..391eba9c 100644 --- a/boards/addons/ginput/touch/MCU/ginput_lld_mouse_board_olimex_pic32mx_lcd.h +++ b/boards/addons/ginput/touch/MCU/ginput_lld_mouse_board_olimex_pic32mx_lcd.h @@ -16,6 +16,24 @@ #ifndef _GINPUT_LLD_MOUSE_BOARD_H #define _GINPUT_LLD_MOUSE_BOARD_H +#define ADC_MAX 1023 + +// Resolution and Accuracy Settings +#define GMOUSE_MCU_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_MCU_PEN_CLICK_ERROR 6 +#define GMOUSE_MCU_PEN_MOVE_ERROR 4 +#define GMOUSE_MCU_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_MCU_FINGER_CLICK_ERROR 18 +#define GMOUSE_MCU_FINGER_MOVE_ERROR 14 + +#define GMOUSE_MCU_Z_MIN 0 // The minimum Z reading +#define GMOUSE_MCU_Z_MAX ADC_MAX // The maximum Z reading +#define GMOUSE_MCU_Z_TOUCHON 60 // Values between this and Z_MAX are definitely pressed +#define GMOUSE_MCU_Z_TOUCHOFF 30 // Values between this and Z_MIN are definitely not pressed + +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_MCU_BOARD_DATA_SIZE 0 + static const ADCConfig ADCC = { .vref = ADC_VREF_CFG_AVDD_AVSS, .stime = 15, @@ -29,10 +47,6 @@ static struct ADCDriver ADCD; #define XPOS 12 // L #define YPOS 11 // D -#define ADC_MAX 1023 - -#define TOUCH_THRESHOULD 50 - static const ADCConversionGroup ADC_X_CG = { .circular = FALSE, .num_channels = 1, @@ -45,104 +59,59 @@ static const ADCConversionGroup ADC_Y_CG = { .channels = 1 << YPOS, }; -/** - * @brief Initialise the board for the touch. - * - * @notapi - */ -static inline void init_board(void) { - adcObjectInit(&ADCD); - adcStart(&ADCD, &ADCC); +static bool_t init_board(GMouse *m, unsigned driverinstance) { + (void) m; + + if (driverinstance) + return FALSE; + + adcObjectInit(&ADCD); + adcStart(&ADCD, &ADCC); + return TRUE; } -/** - * @brief Check whether the surface is currently touched - * @return TRUE if the surface is currently touched - * - * @notapi - */ -static inline bool_t getpin_pressed(void) { - adcsample_t samples[2] = {0, }; +static bool_t read_xyz(GMouse *m, GMouseReading *prd) { + adcsample_t samples[2]; - // Set X+ to ground - palSetPadMode(IOPORTB, XPOS, PAL_MODE_OUTPUT); - palClearPad(IOPORTB, XPOS); + prd->buttons = 0; - // Set Y- to VCC - palSetPadMode(IOPORTB, YNEG, PAL_MODE_OUTPUT); - palSetPad(IOPORTB, YNEG); + // Read the z value first. + // Set X+ to ground and Y- to VCC + palSetPadMode(IOPORTB, XPOS, PAL_MODE_OUTPUT); + palClearPad(IOPORTB, XPOS); + palSetPadMode(IOPORTB, YNEG, PAL_MODE_OUTPUT); + palSetPad(IOPORTB, YNEG); + palSetPadMode(IOPORTB, XNEG, PAL_MODE_INPUT_ANALOG); + palSetPadMode(IOPORTB, YPOS, PAL_MODE_INPUT_ANALOG); + adcConvert(&ADCD, &ADC_X_CG, &samples[0], 1); + adcConvert(&ADCD, &ADC_Y_CG, &samples[1], 1); + pdr->z = ADC_MAX - (samples[1] - samples[0]); - palSetPadMode(IOPORTB, XNEG, PAL_MODE_INPUT_ANALOG); - palSetPadMode(IOPORTB, YPOS, PAL_MODE_INPUT_ANALOG); + // Shortcut - no need to read X or Y if the touch is off. + if (pdr->z < GMOUSE_MCU_Z_TOUCHON) + return TRUE; - adcConvert(&ADCD, &ADC_X_CG, &samples[0], 1); - adcConvert(&ADCD, &ADC_Y_CG, &samples[1], 1); + // Read X + palSetPadMode(IOPORTB, XPOS, PAL_MODE_OUTPUT); + palSetPad(IOPORTB, XPOS); + palSetPadMode(IOPORTB, XNEG, PAL_MODE_OUTPUT); + palClearPad(IOPORTB, XNEG); + palSetPadMode(IOPORTB, YNEG, PAL_MODE_INPUT); + palSetPadMode(IOPORTB, YPOS, PAL_MODE_INPUT_ANALOG); + adcConvert(&ADCD, &ADC_Y_CG, &samples[0], 1); + pdr->x = ADC_MAX - samples[0]; - return (ADC_MAX - (samples[1] - samples[0])) > TOUCH_THRESHOULD; -} + // Read Y + palSetPadMode(IOPORTB, YNEG, PAL_MODE_OUTPUT); + palClearPad(IOPORTB, YNEG); + palSetPadMode(IOPORTB, YPOS, PAL_MODE_OUTPUT); + palSetPad(IOPORTB, YPOS); + palSetPadMode(IOPORTB, XPOS, PAL_MODE_INPUT); + palSetPadMode(IOPORTB, XNEG, PAL_MODE_INPUT_ANALOG); + adcConvert(&ADCD, &ADC_X_CG, &samples[0], 1); + pdr->y = ADC_MAX - samples[0]; -/** - * @brief Aquire the bus ready for readings - * - * @notapi - */ -static inline void aquire_bus(void) { -} - -/** - * @brief Release the bus after readings - * - * @notapi - */ -static inline void release_bus(void) { -} - -/** - * @brief Read an x value from touch controller - * @return The value read from the controller - * - * @notapi - */ -static inline uint16_t read_x_value(void) { - adcsample_t sample; - - palSetPadMode(IOPORTB, XPOS, PAL_MODE_OUTPUT); - palSetPad(IOPORTB, XPOS); - - palSetPadMode(IOPORTB, XNEG, PAL_MODE_OUTPUT); - palClearPad(IOPORTB, XNEG); - - palSetPadMode(IOPORTB, YNEG, PAL_MODE_INPUT); - - palSetPadMode(IOPORTB, YPOS, PAL_MODE_INPUT_ANALOG); - - adcConvert(&ADCD, &ADC_Y_CG, &sample, 1); - - return ADC_MAX - sample; -} - -/** - * @brief Read an y value from touch controller - * @return The value read from the controller - * - * @notapi - */ -static inline uint16_t read_y_value(void) { - adcsample_t sample; - - palSetPadMode(IOPORTB, YNEG, PAL_MODE_OUTPUT); - palClearPad(IOPORTB, YNEG); - - palSetPadMode(IOPORTB, YPOS, PAL_MODE_OUTPUT); - palSetPad(IOPORTB, YPOS); - - palSetPadMode(IOPORTB, XPOS, PAL_MODE_INPUT); - - palSetPadMode(IOPORTB, XNEG, PAL_MODE_INPUT_ANALOG); - - adcConvert(&ADCD, &ADC_X_CG, &sample, 1); - - return ADC_MAX - sample; + return TRUE; } #endif /* _GINPUT_LLD_MOUSE_BOARD_H */ From 00de9255232e2d7c0c0b1742ff0b5d489023dc5d Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 10 Nov 2014 14:40:47 +1000 Subject: [PATCH 85/87] Update default settings in the board file for the ADS7843 touch --- .../ADS7843/gmouse_lld_ADS7843_board_template.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843_board_template.h b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843_board_template.h index 5a09b5bd..0b9cc71b 100644 --- a/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843_board_template.h +++ b/drivers/ginput/touch/ADS7843/gmouse_lld_ADS7843_board_template.h @@ -9,12 +9,12 @@ #define _GINPUT_LLD_MOUSE_BOARD_H // Resolution and Accuracy Settings -#define GMOUSE_ADS7843_PEN_CALIBRATE_ERROR 2 -#define GMOUSE_ADS7843_PEN_CLICK_ERROR 2 -#define GMOUSE_ADS7843_PEN_MOVE_ERROR 2 -#define GMOUSE_ADS7843_FINGER_CALIBRATE_ERROR 4 -#define GMOUSE_ADS7843_FINGER_CLICK_ERROR 4 -#define GMOUSE_ADS7843_FINGER_MOVE_ERROR 4 +#define GMOUSE_ADS7843_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_ADS7843_PEN_CLICK_ERROR 6 +#define GMOUSE_ADS7843_PEN_MOVE_ERROR 4 +#define GMOUSE_ADS7843_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_ADS7843_FINGER_CLICK_ERROR 18 +#define GMOUSE_ADS7843_FINGER_MOVE_ERROR 14 // How much extra data to allocate at the end of the GMouse structure for the board's use #define GMOUSE_ADS7843_BOARD_DATA_SIZE 0 From bc75dbc24cf7abe698b2b60396a55a4d007243a5 Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 10 Nov 2014 14:41:27 +1000 Subject: [PATCH 86/87] MCU touch template fix --- drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h b/drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h index 07583fa9..440d81fe 100644 --- a/drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h +++ b/drivers/ginput/touch/MCU/gmouse_lld_MCU_board_template.h @@ -26,7 +26,7 @@ static bool_t init_board(GMouse *m, unsigned driverinstance) { } -static void read_xyz(GMouse *m, GMouseReading *prd) { +static bool_t read_xyz(GMouse *m, GMouseReading *prd) { } #endif /* _LLD_GMOUSE_MCU_BOARD_H */ From 04334f284c8c4236e2a07b6611ddb790ee05db72 Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 10 Nov 2014 14:42:07 +1000 Subject: [PATCH 87/87] Some MAX11802 fixes. --- .../touch/MAX11802/gmouse_lld_MAX11802.c | 6 +++++ .../gmouse_lld_MAX11802_board_template.h | 23 ++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802.c b/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802.c index 73d8d4e6..d1435628 100644 --- a/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802.c +++ b/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802.c @@ -18,6 +18,12 @@ // Get the hardware interface #include "gmouse_lld_MAX11802_board.h" +// Register values to set +#define MAX11802_MODE 0x0E // Direct conversion with averaging +#define MAX11802_AVG 0x55 +#define MAX11802_TIMING 0x77 +#define MAX11802_DELAY 0x55 + #define Z_MIN 0 #define Z_MAX 1 diff --git a/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802_board_template.h b/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802_board_template.h index bea6cc6b..6171089f 100644 --- a/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802_board_template.h +++ b/drivers/ginput/touch/MAX11802/gmouse_lld_MAX11802_board_template.h @@ -16,27 +16,28 @@ #define GMOUSE_MAX11802_FINGER_CLICK_ERROR 18 #define GMOUSE_MAX11802_FINGER_MOVE_ERROR 14 -// Register values to set -#define MAX11802_MODE 0x0E // Direct conversion with averaging -#define MAX11802_AVG 0x55 -#define MAX11802_TIMING 0x77 -#define MAX11802_DELAY 0x55 - // How much extra data to allocate at the end of the GMouse structure for the board's use #define GMOUSE_MAX11802_BOARD_DATA_SIZE 0 -static inline void init_board(GMouse* m) { - -} - -static inline bool_t getpin_pressed(GMouse* m) { +/** + * Init the board + * + * Returns TRUE on success, FALSE on failure + */ +static inline bool_t init_board(GMouse* m, unsigned driverinstance) { } +/** + * Acquire the bus + */ static inline void aquire_bus(GMouse* m) { } +/** + * Release the bus + */ static inline void release_bus(GMouse* m) { }