Browse Source

Adding Qt GOS port

Joel Bodenmann 3 years ago
parent
commit
e5f69dbcf4
7 changed files with 315 additions and 4 deletions
  1. 1 0
      docs/releases.txt
  2. 1 0
      gfxconf.example.h
  3. 4 2
      src/gos/gos.h
  4. 7 0
      src/gos/gos_options.h
  5. 222 0
      src/gos/gos_qt.cpp
  6. 78 0
      src/gos/gos_qt.h
  7. 2 2
      src/gos/gos_rules.h

+ 1 - 0
docs/releases.txt

@@ -11,6 +11,7 @@ FEATURE:	Added gwinPrintg()
11 11
 FIX:		Fix sprintg and related functions handling of NULL pointers.
12 12
 FIX:		Fixing width calculation of gdispGDrawString() and gdispGFillString().
13 13
 FEATURE:	Added QImage display driver.
14
+FEATURE:	Added support for Qt platform
14 15
 
15 16
 
16 17
 *** Release 2.5 ***

+ 1 - 0
gfxconf.example.h

@@ -39,6 +39,7 @@
39 39
 //#define GFX_USE_OS_CMSIS                             FALSE
40 40
 //#define GFX_USE_OS_RAW32                             FALSE
41 41
 //#define GFX_USE_OS_NIOS                              FALSE
42
+//#define GFX_USE_OS_QT                                FALSE
42 43
 //    #define INTERRUPTS_OFF()                         optional_code
43 44
 //    #define INTERRUPTS_ON()                          optional_code
44 45
 

+ 4 - 2
src/gos/gos.h

@@ -494,9 +494,11 @@
494 494
 #elif GFX_USE_OS_CMSIS
495 495
  	#include "gos_cmsis.h"
496 496
 #elif GFX_USE_OS_KEIL
497
- 	#include "gos_keil.h"
497
+    #include "gos_keil.h"
498 498
 #elif GFX_USE_OS_NIOS
499
- 	#include "gos_nios.h"
499
+    #include "gos_nios.h"
500
+#elif GFX_USE_OS_QT
501
+    #include "gos_qt.h"
500 502
 #else
501 503
 	#error "Your operating system is not supported yet"
502 504
 #endif

+ 7 - 0
src/gos/gos_options.h

@@ -104,6 +104,13 @@
104 104
 	#ifndef GFX_USE_OS_NIOS
105 105
 		#define GFX_USE_OS_NIOS			FALSE
106 106
 	#endif
107
+	/**
108
+	 * @brief   Use Qt
109
+	 * @details	Defaults to FALSE
110
+	 */
111
+	#ifndef GFX_USE_OS_QT
112
+		#define GFX_USE_OS_QT			FALSE
113
+	#endif
107 114
 /**
108 115
  * @}
109 116
  *

+ 222 - 0
src/gos/gos_qt.cpp

@@ -0,0 +1,222 @@
1
+/*
2
+ * This file is subject to the terms of the GFX License. If a copy of
3
+ * the license was not distributed with this file, you can obtain one at:
4
+ *
5
+ *              http://ugfx.org/license.html
6
+ */
7
+
8
+#include "../../gfx.h"
9
+
10
+#include <QMutex>
11
+#include <QSemaphore>
12
+#include <QThread>
13
+#include <QElapsedTimer>
14
+
15
+#if GFX_USE_OS_QT
16
+
17
+class Thread : public QThread
18
+{
19
+public:
20
+    typedef threadreturn_t (*fptr)(void* param);
21
+
22
+    void setFunction(fptr function, void* param)
23
+    {
24
+        _function = function;
25
+        _param = param;
26
+    }
27
+
28
+    threadreturn_t returnValue()
29
+    {
30
+        return _returnValue;
31
+    }
32
+
33
+    virtual void run() override
34
+    {
35
+        if (!_function) {
36
+            return;
37
+        }
38
+
39
+        _returnValue = _function(_param);
40
+    }
41
+
42
+private:
43
+    fptr _function;
44
+    void* _param;
45
+    threadreturn_t _returnValue;
46
+};
47
+
48
+static QElapsedTimer _systickTimer;
49
+static QMutex _systemMutex;
50
+
51
+void _gosInit(void)
52
+{
53
+    _systickTimer.start();
54
+}
55
+
56
+void _gosDeinit(void)
57
+{
58
+}
59
+
60
+void gfxHalt(const char *msg)
61
+{
62
+    volatile uint32_t dummy;
63
+
64
+    (void)msg;
65
+
66
+    while(1) {
67
+        dummy++;
68
+    }
69
+}
70
+
71
+void gfxExit(void)
72
+{
73
+    volatile uint32_t dummy;
74
+
75
+    while(1) {
76
+        dummy++;
77
+    }
78
+}
79
+
80
+void* gfxAlloc(size_t sz)
81
+{
82
+    return malloc(sz);
83
+}
84
+
85
+void gfxFree(void* ptr)
86
+{
87
+    free(ptr);
88
+}
89
+
90
+void gfxYield(void)
91
+{
92
+    QThread::msleep(0);
93
+}
94
+
95
+void gfxSleepMilliseconds(delaytime_t ms)
96
+{
97
+    QThread::msleep(ms);
98
+}
99
+
100
+void gfxSleepMicroseconds(delaytime_t us)
101
+{
102
+    QThread::usleep(us);
103
+}
104
+
105
+systemticks_t gfxSystemTicks(void)
106
+{
107
+    return _systickTimer.elapsed();
108
+}
109
+
110
+systemticks_t gfxMillisecondsToTicks(delaytime_t ms)
111
+{
112
+    return ms;
113
+}
114
+
115
+void gfxSystemLock(void)
116
+{
117
+    _systemMutex.lock();
118
+}
119
+
120
+void gfxSystemUnlock(void)
121
+{
122
+    _systemMutex.unlock();
123
+}
124
+
125
+void gfxMutexInit(gfxMutex *pmutex)
126
+{
127
+    *pmutex = new QMutex;
128
+}
129
+
130
+void gfxMutexDestroy(gfxMutex *pmutex)
131
+{
132
+    delete static_cast<QMutex*>(*pmutex);
133
+}
134
+
135
+void gfxMutexEnter(gfxMutex *pmutex)
136
+{
137
+    static_cast<QMutex*>(*pmutex)->lock();
138
+}
139
+
140
+void gfxMutexExit(gfxMutex *pmutex)
141
+{
142
+    static_cast<QMutex*>(*pmutex)->unlock();
143
+}
144
+
145
+void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit)
146
+{
147
+    *psem = new QSemaphore(limit);
148
+
149
+    static_cast<QSemaphore*>(*psem)->release(val);
150
+}
151
+
152
+void gfxSemDestroy(gfxSem *psem)
153
+{
154
+    delete static_cast<QSemaphore*>(*psem);
155
+}
156
+
157
+bool_t gfxSemWait(gfxSem *psem, delaytime_t ms)
158
+{
159
+    return static_cast<QSemaphore*>(*psem)->tryAcquire(1, ms);
160
+}
161
+
162
+bool_t gfxSemWaitI(gfxSem *psem)
163
+{
164
+    return static_cast<QSemaphore*>(*psem)->tryAcquire(1);
165
+}
166
+
167
+void gfxSemSignal(gfxSem *psem)
168
+{
169
+    static_cast<QSemaphore*>(*psem)->release(1);
170
+}
171
+
172
+void gfxSemSignalI(gfxSem *psem)
173
+{
174
+    static_cast<QSemaphore*>(*psem)->release(1);
175
+}
176
+
177
+semcount_t gfxSemCounter(gfxSem *psem)
178
+{
179
+    return static_cast<QSemaphore*>(*psem)->available();
180
+}
181
+
182
+semcount_t gfxSemCounterI(gfxSem *psem)
183
+{
184
+    return static_cast<QSemaphore*>(*psem)->available();
185
+}
186
+
187
+gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param)
188
+{
189
+    Q_UNUSED(stackarea)
190
+
191
+    Thread* thread = new Thread;
192
+    thread->setFunction(fn, param);
193
+    if (stacksz > 0) {
194
+        thread->setStackSize(stacksz);
195
+    }
196
+    thread->start(static_cast<QThread::Priority>(prio));
197
+
198
+    return static_cast<gfxThreadHandle>(thread);
199
+}
200
+
201
+threadreturn_t gfxThreadWait(gfxThreadHandle thread)
202
+{
203
+    Thread* t = static_cast<Thread*>(thread);
204
+
205
+    threadreturn_t returnValue = t->returnValue();
206
+    t->wait();
207
+    t->exit();
208
+
209
+    return returnValue;
210
+}
211
+
212
+gfxThreadHandle gfxThreadMe(void)
213
+{
214
+    return static_cast<Thread*>(QThread::currentThread());
215
+}
216
+
217
+void gfxThreadClose(gfxThreadHandle thread)
218
+{
219
+    static_cast<Thread*>(thread)->exit();
220
+}
221
+
222
+#endif /* GFX_USE_OS_QT */

+ 78 - 0
src/gos/gos_qt.h

@@ -0,0 +1,78 @@
1
+/*
2
+ * This file is subject to the terms of the GFX License. If a copy of
3
+ * the license was not distributed with this file, you can obtain one at:
4
+ *
5
+ *              http://ugfx.org/license.html
6
+ */
7
+
8
+#ifndef _GOS_QT_H
9
+#define _GOS_QT_H
10
+
11
+#if GFX_USE_OS_QT
12
+
13
+#include <stdint.h>
14
+#include <stddef.h>
15
+#include <stdbool.h>
16
+
17
+#define DECLARE_THREAD_FUNCTION(fnName, param)	threadreturn_t fnName(void *param)
18
+#define DECLARE_THREAD_STACK(name, sz)          uint8_t name[0]
19
+#define THREAD_RETURN(retval)					return retval
20
+
21
+#define TIME_IMMEDIATE				0
22
+#define TIME_INFINITE				((delaytime_t)-1)
23
+#define MAX_SEMAPHORE_COUNT			((semcount_t)(((unsigned long)((semcount_t)(-1))) >> 1))
24
+#define LOW_PRIORITY				2
25
+#define NORMAL_PRIORITY				3
26
+#define HIGH_PRIORITY				4
27
+
28
+typedef bool bool_t;
29
+typedef int systemticks_t;
30
+typedef int delaytime_t;
31
+typedef void* gfxMutex;
32
+typedef void* gfxSem;
33
+typedef int semcount_t;
34
+typedef int threadreturn_t;
35
+typedef int threadpriority_t;
36
+typedef void* gfxThreadHandle;
37
+
38
+#ifdef __cplusplus
39
+extern "C" {
40
+#endif
41
+
42
+void _gosInit();
43
+void _gosDeinit();
44
+
45
+void gfxHalt(const char* msg);
46
+void gfxExit(void);
47
+void* gfxAlloc(size_t sz);
48
+void gfxFree(void* ptr);
49
+void gfxYield(void);
50
+void gfxSleepMilliseconds(delaytime_t ms);
51
+void gfxSleepMicroseconds(delaytime_t us);
52
+systemticks_t gfxSystemTicks(void);
53
+systemticks_t gfxMillisecondsToTicks(delaytime_t ms);
54
+void gfxSystemLock(void);
55
+void gfxSystemUnlock(void);
56
+void gfxMutexInit(gfxMutex *pmutex);
57
+void gfxMutexDestroy(gfxMutex *pmutex);
58
+void gfxMutexEnter(gfxMutex *pmutex);
59
+void gfxMutexExit(gfxMutex *pmutex);
60
+void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit);
61
+void gfxSemDestroy(gfxSem *psem);
62
+bool_t gfxSemWait(gfxSem *psem, delaytime_t ms);
63
+bool_t gfxSemWaitI(gfxSem *psem);
64
+void gfxSemSignal(gfxSem *psem);
65
+void gfxSemSignalI(gfxSem *psem);
66
+semcount_t gfxSemCounter(gfxSem *psem);
67
+semcount_t gfxSemCounterI(gfxSem *psem);
68
+gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param);
69
+threadreturn_t gfxThreadWait(gfxThreadHandle thread);
70
+gfxThreadHandle gfxThreadMe(void);
71
+void gfxThreadClose(gfxThreadHandle thread);
72
+
73
+#ifdef __cplusplus
74
+}
75
+#endif
76
+
77
+#endif /* GFX_USE_OS_QT */
78
+#endif /* _GOS_QT_H */

+ 2 - 2
src/gos/gos_rules.h

@@ -16,11 +16,11 @@
16 16
 #ifndef _GOS_RULES_H
17 17
 #define _GOS_RULES_H
18 18
 
19
-#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
19
+#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
20 20
 	#error "GOS: No operating system has been defined."
21 21
 #endif
22 22
 
23
-#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
23
+#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
24 24
 	#error "GOS: More than one operation system has been defined as TRUE."
25 25
 #endif
26 26