1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
//*****************************************************************************
//
// display_task.c - Task to display text and images on the LCD.
//
// Copyright (c) 2009-2014 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 2.1.0.12573 of the DK-TM4C129X Firmware Package.
//
//*****************************************************************************
#include <stdint.h>
#include <stdbool.h>
#include "grlib/grlib.h"
#include "drivers/kentec320x240x16_ssd2119.h"
#include "display_task.h"
#include "idle_task.h"
#include "priorities.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
//*****************************************************************************
//
// This structure defines the messages that are sent to the display task.
//
//*****************************************************************************
typedef struct
{
uint32_t ui32Type;
uint16_t ui16X;
uint16_t ui16Y;
const char *pcMessage;
}
tDisplayMessage;
xTaskHandle g_sDisplayTask; // FIXME
//*****************************************************************************
//
// The stack size for the display task.
//
//*****************************************************************************
#define STACKSIZE_DISPLAYTASK 128
//*****************************************************************************
//
// Defines to indicate the contents of the display message.
//
//*****************************************************************************
#define DISPLAY_IMAGE 1
#define DISPLAY_STRING 2
#define DISPLAY_MOVE 3
#define DISPLAY_DRAW 4
//*****************************************************************************
//
// The item size, queue size, and memory size for the display message queue.
//
//*****************************************************************************
#define DISPLAY_ITEM_SIZE sizeof(tDisplayMessage)
#define DISPLAY_QUEUE_SIZE 10
//*****************************************************************************
//
// The queue that holds messages sent to the display task.
//
//*****************************************************************************
static xQueueHandle g_pDisplayQueue;
//*****************************************************************************
//
// The most recent position of the display pen.
//
//*****************************************************************************
static uint32_t g_ui32DisplayX, g_ui32DisplayY;
//*****************************************************************************
//
// This task receives messages from the other tasks and updates the display as
// directed.
//
//*****************************************************************************
static void
DisplayTask(void *pvParameters)
{
tDisplayMessage sMessage;
tContext sContext;
//
// Initialize the graphics library context.
//
GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);
GrContextForegroundSet(&sContext, ClrWhite);
GrContextBackgroundSet(&sContext, ClrBlack);
GrContextFontSet(&sContext, g_psFontFixed6x8);
//
// Loop forever.
//
while(1)
{
//
// Read the next message from the queue.
//
if(xQueueReceive(g_pDisplayQueue, &sMessage, portMAX_DELAY) == pdPASS)
{
//
// Determine the message type.
//
switch(sMessage.ui32Type)
{
//
// The drawing of an image has been requested.
//
case DISPLAY_IMAGE:
{
//
// Draw this image on the display.
//
GrImageDraw(&sContext, (uint8_t *)sMessage.pcMessage,
sMessage.ui16X, sMessage.ui16Y);
//
// This message has been handled.
//
break;
}
//
// The drawing of a string has been requested.
//
case DISPLAY_STRING:
{
//
// Draw this string on the display.
//
GrStringDraw(&sContext, sMessage.pcMessage, -1,
sMessage.ui16X, sMessage.ui16Y, 1);
//
// This message has been handled.
//
break;
}
//
// A move of the pen has been requested.
//
case DISPLAY_MOVE:
{
//
// Save the new pen position.
//
g_ui32DisplayX = sMessage.ui16X;
g_ui32DisplayY = sMessage.ui16Y;
//
// This message has been handled.
//
break;
}
//
// A draw with the pen has been requested.
//
case DISPLAY_DRAW:
{
//
// Draw a line from the previous pen position to the new
// pen position.
//
GrLineDraw(&sContext, g_ui32DisplayX, g_ui32DisplayY,
sMessage.ui16X, sMessage.ui16Y);
//
// Save the new pen position.
//
g_ui32DisplayX = sMessage.ui16X;
g_ui32DisplayY = sMessage.ui16Y;
//
// This message has been handled.
//
break;
}
}
}
}
}
//*****************************************************************************
//
// Sends a request to the display task to draw an image on the display.
//
//*****************************************************************************
void
DisplayImage(uint32_t ui16X, uint32_t ui16Y, const uint8_t *pui8Image)
{
tDisplayMessage sMessage;
//
// Construct the message to be sent.
//
sMessage.ui32Type = DISPLAY_IMAGE;
sMessage.ui16X = ui16X;
sMessage.ui16Y = ui16Y;
sMessage.pcMessage = (char *)pui8Image;
//
// Send the image draw request to the display task.
//
xQueueSend(g_pDisplayQueue, &sMessage, portMAX_DELAY);
}
//*****************************************************************************
//
// Sends a request to the display task to draw a string on the display.
//
//*****************************************************************************
void
DisplayString(uint32_t ui16X, uint32_t ui16Y, const char *pcString)
{
tDisplayMessage sMessage;
//
// Construct the message to be sent.
//
sMessage.ui32Type = DISPLAY_STRING;
sMessage.ui16X = ui16X;
sMessage.ui16Y = ui16Y;
sMessage.pcMessage = pcString;
//
// Send the string draw request to the display task.
//
xQueueSend(g_pDisplayQueue, &sMessage, portMAX_DELAY);
}
//*****************************************************************************
//
// Sends a request to the display task to move the pen.
//
//*****************************************************************************
void
DisplayMove(uint32_t ui16X, uint32_t ui16Y)
{
tDisplayMessage sMessage;
//
// Construct the message to be sent.
//
sMessage.ui32Type = DISPLAY_MOVE;
sMessage.ui16X = ui16X;
sMessage.ui16Y = ui16Y;
//
// Send the pen move request to the display task.
//
xQueueSend(g_pDisplayQueue, &sMessage, portMAX_DELAY);
}
//*****************************************************************************
//
// Sends a request to the display task to draw with the pen.
//
//*****************************************************************************
void
DisplayDraw(uint32_t ui16X, uint32_t ui16Y)
{
tDisplayMessage sMessage;
//
// Construct the message to be sent.
//
sMessage.ui32Type = DISPLAY_DRAW;
sMessage.ui16X = ui16X;
sMessage.ui16Y = ui16Y;
//
// Send the pen draw request to the display task.
//
xQueueSend(g_pDisplayQueue, &sMessage, portMAX_DELAY);
}
//*****************************************************************************
//
// Initializes the display task.
//
//*****************************************************************************
uint32_t
DisplayTaskInit(void)
{
//
// Create a queue for sending messages to the display task.
//
g_pDisplayQueue = xQueueCreate(DISPLAY_QUEUE_SIZE, DISPLAY_ITEM_SIZE);
if(g_pDisplayQueue == NULL)
{
return(1);
}
//
// Create the display task.
//
if(xTaskCreate(DisplayTask, (signed portCHAR *)"Display",
STACKSIZE_DISPLAYTASK, NULL,
tskIDLE_PRIORITY + PRIORITY_DISPLAY_TASK, &g_sDisplayTask) != pdTRUE)
{ // FIXME
return(1);
}
//
// Success.
//
return(0);
}
|