Adding Qt GOS port
This commit is contained in:
parent
038a1f3630
commit
e5f69dbcf4
@ -11,6 +11,7 @@ FEATURE: Added gwinPrintg()
|
||||
FIX: Fix sprintg and related functions handling of NULL pointers.
|
||||
FIX: Fixing width calculation of gdispGDrawString() and gdispGFillString().
|
||||
FEATURE: Added QImage display driver.
|
||||
FEATURE: Added support for Qt platform
|
||||
|
||||
|
||||
*** Release 2.5 ***
|
||||
|
@ -39,6 +39,7 @@
|
||||
//#define GFX_USE_OS_CMSIS FALSE
|
||||
//#define GFX_USE_OS_RAW32 FALSE
|
||||
//#define GFX_USE_OS_NIOS FALSE
|
||||
//#define GFX_USE_OS_QT FALSE
|
||||
// #define INTERRUPTS_OFF() optional_code
|
||||
// #define INTERRUPTS_ON() optional_code
|
||||
|
||||
|
@ -494,9 +494,11 @@
|
||||
#elif GFX_USE_OS_CMSIS
|
||||
#include "gos_cmsis.h"
|
||||
#elif GFX_USE_OS_KEIL
|
||||
#include "gos_keil.h"
|
||||
#include "gos_keil.h"
|
||||
#elif GFX_USE_OS_NIOS
|
||||
#include "gos_nios.h"
|
||||
#include "gos_nios.h"
|
||||
#elif GFX_USE_OS_QT
|
||||
#include "gos_qt.h"
|
||||
#else
|
||||
#error "Your operating system is not supported yet"
|
||||
#endif
|
||||
|
@ -104,6 +104,13 @@
|
||||
#ifndef GFX_USE_OS_NIOS
|
||||
#define GFX_USE_OS_NIOS FALSE
|
||||
#endif
|
||||
/**
|
||||
* @brief Use Qt
|
||||
* @details Defaults to FALSE
|
||||
*/
|
||||
#ifndef GFX_USE_OS_QT
|
||||
#define GFX_USE_OS_QT FALSE
|
||||
#endif
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
|
222
src/gos/gos_qt.cpp
Normal file
222
src/gos/gos_qt.cpp
Normal file
@ -0,0 +1,222 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
#include <QMutex>
|
||||
#include <QSemaphore>
|
||||
#include <QThread>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
#if GFX_USE_OS_QT
|
||||
|
||||
class Thread : public QThread
|
||||
{
|
||||
public:
|
||||
typedef threadreturn_t (*fptr)(void* param);
|
||||
|
||||
void setFunction(fptr function, void* param)
|
||||
{
|
||||
_function = function;
|
||||
_param = param;
|
||||
}
|
||||
|
||||
threadreturn_t returnValue()
|
||||
{
|
||||
return _returnValue;
|
||||
}
|
||||
|
||||
virtual void run() override
|
||||
{
|
||||
if (!_function) {
|
||||
return;
|
||||
}
|
||||
|
||||
_returnValue = _function(_param);
|
||||
}
|
||||
|
||||
private:
|
||||
fptr _function;
|
||||
void* _param;
|
||||
threadreturn_t _returnValue;
|
||||
};
|
||||
|
||||
static QElapsedTimer _systickTimer;
|
||||
static QMutex _systemMutex;
|
||||
|
||||
void _gosInit(void)
|
||||
{
|
||||
_systickTimer.start();
|
||||
}
|
||||
|
||||
void _gosDeinit(void)
|
||||
{
|
||||
}
|
||||
|
||||
void gfxHalt(const char *msg)
|
||||
{
|
||||
volatile uint32_t dummy;
|
||||
|
||||
(void)msg;
|
||||
|
||||
while(1) {
|
||||
dummy++;
|
||||
}
|
||||
}
|
||||
|
||||
void gfxExit(void)
|
||||
{
|
||||
volatile uint32_t dummy;
|
||||
|
||||
while(1) {
|
||||
dummy++;
|
||||
}
|
||||
}
|
||||
|
||||
void* gfxAlloc(size_t sz)
|
||||
{
|
||||
return malloc(sz);
|
||||
}
|
||||
|
||||
void gfxFree(void* ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
void gfxYield(void)
|
||||
{
|
||||
QThread::msleep(0);
|
||||
}
|
||||
|
||||
void gfxSleepMilliseconds(delaytime_t ms)
|
||||
{
|
||||
QThread::msleep(ms);
|
||||
}
|
||||
|
||||
void gfxSleepMicroseconds(delaytime_t us)
|
||||
{
|
||||
QThread::usleep(us);
|
||||
}
|
||||
|
||||
systemticks_t gfxSystemTicks(void)
|
||||
{
|
||||
return _systickTimer.elapsed();
|
||||
}
|
||||
|
||||
systemticks_t gfxMillisecondsToTicks(delaytime_t ms)
|
||||
{
|
||||
return ms;
|
||||
}
|
||||
|
||||
void gfxSystemLock(void)
|
||||
{
|
||||
_systemMutex.lock();
|
||||
}
|
||||
|
||||
void gfxSystemUnlock(void)
|
||||
{
|
||||
_systemMutex.unlock();
|
||||
}
|
||||
|
||||
void gfxMutexInit(gfxMutex *pmutex)
|
||||
{
|
||||
*pmutex = new QMutex;
|
||||
}
|
||||
|
||||
void gfxMutexDestroy(gfxMutex *pmutex)
|
||||
{
|
||||
delete static_cast<QMutex*>(*pmutex);
|
||||
}
|
||||
|
||||
void gfxMutexEnter(gfxMutex *pmutex)
|
||||
{
|
||||
static_cast<QMutex*>(*pmutex)->lock();
|
||||
}
|
||||
|
||||
void gfxMutexExit(gfxMutex *pmutex)
|
||||
{
|
||||
static_cast<QMutex*>(*pmutex)->unlock();
|
||||
}
|
||||
|
||||
void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit)
|
||||
{
|
||||
*psem = new QSemaphore(limit);
|
||||
|
||||
static_cast<QSemaphore*>(*psem)->release(val);
|
||||
}
|
||||
|
||||
void gfxSemDestroy(gfxSem *psem)
|
||||
{
|
||||
delete static_cast<QSemaphore*>(*psem);
|
||||
}
|
||||
|
||||
bool_t gfxSemWait(gfxSem *psem, delaytime_t ms)
|
||||
{
|
||||
return static_cast<QSemaphore*>(*psem)->tryAcquire(1, ms);
|
||||
}
|
||||
|
||||
bool_t gfxSemWaitI(gfxSem *psem)
|
||||
{
|
||||
return static_cast<QSemaphore*>(*psem)->tryAcquire(1);
|
||||
}
|
||||
|
||||
void gfxSemSignal(gfxSem *psem)
|
||||
{
|
||||
static_cast<QSemaphore*>(*psem)->release(1);
|
||||
}
|
||||
|
||||
void gfxSemSignalI(gfxSem *psem)
|
||||
{
|
||||
static_cast<QSemaphore*>(*psem)->release(1);
|
||||
}
|
||||
|
||||
semcount_t gfxSemCounter(gfxSem *psem)
|
||||
{
|
||||
return static_cast<QSemaphore*>(*psem)->available();
|
||||
}
|
||||
|
||||
semcount_t gfxSemCounterI(gfxSem *psem)
|
||||
{
|
||||
return static_cast<QSemaphore*>(*psem)->available();
|
||||
}
|
||||
|
||||
gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param)
|
||||
{
|
||||
Q_UNUSED(stackarea)
|
||||
|
||||
Thread* thread = new Thread;
|
||||
thread->setFunction(fn, param);
|
||||
if (stacksz > 0) {
|
||||
thread->setStackSize(stacksz);
|
||||
}
|
||||
thread->start(static_cast<QThread::Priority>(prio));
|
||||
|
||||
return static_cast<gfxThreadHandle>(thread);
|
||||
}
|
||||
|
||||
threadreturn_t gfxThreadWait(gfxThreadHandle thread)
|
||||
{
|
||||
Thread* t = static_cast<Thread*>(thread);
|
||||
|
||||
threadreturn_t returnValue = t->returnValue();
|
||||
t->wait();
|
||||
t->exit();
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
gfxThreadHandle gfxThreadMe(void)
|
||||
{
|
||||
return static_cast<Thread*>(QThread::currentThread());
|
||||
}
|
||||
|
||||
void gfxThreadClose(gfxThreadHandle thread)
|
||||
{
|
||||
static_cast<Thread*>(thread)->exit();
|
||||
}
|
||||
|
||||
#endif /* GFX_USE_OS_QT */
|
78
src/gos/gos_qt.h
Normal file
78
src/gos/gos_qt.h
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 _GOS_QT_H
|
||||
#define _GOS_QT_H
|
||||
|
||||
#if GFX_USE_OS_QT
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void *param)
|
||||
#define DECLARE_THREAD_STACK(name, sz) uint8_t name[0]
|
||||
#define THREAD_RETURN(retval) return retval
|
||||
|
||||
#define TIME_IMMEDIATE 0
|
||||
#define TIME_INFINITE ((delaytime_t)-1)
|
||||
#define MAX_SEMAPHORE_COUNT ((semcount_t)(((unsigned long)((semcount_t)(-1))) >> 1))
|
||||
#define LOW_PRIORITY 2
|
||||
#define NORMAL_PRIORITY 3
|
||||
#define HIGH_PRIORITY 4
|
||||
|
||||
typedef bool bool_t;
|
||||
typedef int systemticks_t;
|
||||
typedef int delaytime_t;
|
||||
typedef void* gfxMutex;
|
||||
typedef void* gfxSem;
|
||||
typedef int semcount_t;
|
||||
typedef int threadreturn_t;
|
||||
typedef int threadpriority_t;
|
||||
typedef void* gfxThreadHandle;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void _gosInit();
|
||||
void _gosDeinit();
|
||||
|
||||
void gfxHalt(const char* msg);
|
||||
void gfxExit(void);
|
||||
void* gfxAlloc(size_t sz);
|
||||
void gfxFree(void* ptr);
|
||||
void gfxYield(void);
|
||||
void gfxSleepMilliseconds(delaytime_t ms);
|
||||
void gfxSleepMicroseconds(delaytime_t us);
|
||||
systemticks_t gfxSystemTicks(void);
|
||||
systemticks_t gfxMillisecondsToTicks(delaytime_t ms);
|
||||
void gfxSystemLock(void);
|
||||
void gfxSystemUnlock(void);
|
||||
void gfxMutexInit(gfxMutex *pmutex);
|
||||
void gfxMutexDestroy(gfxMutex *pmutex);
|
||||
void gfxMutexEnter(gfxMutex *pmutex);
|
||||
void gfxMutexExit(gfxMutex *pmutex);
|
||||
void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit);
|
||||
void gfxSemDestroy(gfxSem *psem);
|
||||
bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
|
||||
bool_t gfxSemWaitI(gfxSem *psem);
|
||||
void gfxSemSignal(gfxSem *psem);
|
||||
void gfxSemSignalI(gfxSem *psem);
|
||||
semcount_t gfxSemCounter(gfxSem *psem);
|
||||
semcount_t gfxSemCounterI(gfxSem *psem);
|
||||
gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
|
||||
threadreturn_t gfxThreadWait(gfxThreadHandle thread);
|
||||
gfxThreadHandle gfxThreadMe(void);
|
||||
void gfxThreadClose(gfxThreadHandle thread);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GFX_USE_OS_QT */
|
||||
#endif /* _GOS_QT_H */
|
@ -16,11 +16,11 @@
|
||||
#ifndef _GOS_RULES_H
|
||||
#define _GOS_RULES_H
|
||||
|
||||
#if !GFX_USE_OS_CHIBIOS && !GFX_USE_OS_WIN32 && !GFX_USE_OS_LINUX && !GFX_USE_OS_OSX && !GFX_USE_OS_RAW32 && !GFX_USE_OS_FREERTOS && !GFX_USE_OS_ECOS && !GFX_USE_OS_RAWRTOS && !GFX_USE_OS_ARDUINO && !GFX_USE_OS_CMSIS && !GFX_USE_OS_KEIL && !GFX_USE_OS_NIOS
|
||||
#if !GFX_USE_OS_CHIBIOS && !GFX_USE_OS_WIN32 && !GFX_USE_OS_LINUX && !GFX_USE_OS_OSX && !GFX_USE_OS_RAW32 && !GFX_USE_OS_FREERTOS && !GFX_USE_OS_ECOS && !GFX_USE_OS_RAWRTOS && !GFX_USE_OS_ARDUINO && !GFX_USE_OS_CMSIS && !GFX_USE_OS_KEIL && !GFX_USE_OS_NIOS && !GFX_USE_OS_QT
|
||||
#error "GOS: No operating system has been defined."
|
||||
#endif
|
||||
|
||||
#if GFX_USE_OS_CHIBIOS + GFX_USE_OS_WIN32 + GFX_USE_OS_LINUX + GFX_USE_OS_OSX + GFX_USE_OS_RAW32 + GFX_USE_OS_FREERTOS + GFX_USE_OS_ECOS + GFX_USE_OS_RAWRTOS + GFX_USE_OS_ARDUINO + GFX_USE_OS_CMSIS + GFX_USE_OS_KEIL + GFX_USE_OS_NIOS != 1 * TRUE
|
||||
#if GFX_USE_OS_CHIBIOS + GFX_USE_OS_WIN32 + GFX_USE_OS_LINUX + GFX_USE_OS_OSX + GFX_USE_OS_RAW32 + GFX_USE_OS_FREERTOS + GFX_USE_OS_ECOS + GFX_USE_OS_RAWRTOS + GFX_USE_OS_ARDUINO + GFX_USE_OS_CMSIS + GFX_USE_OS_KEIL + GFX_USE_OS_NIOS + GFX_USE_OS_QT != 1 * TRUE
|
||||
#error "GOS: More than one operation system has been defined as TRUE."
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user