-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprotectedlcd.c
More file actions
executable file
·96 lines (78 loc) · 2.49 KB
/
protectedlcd.c
File metadata and controls
executable file
·96 lines (78 loc) · 2.49 KB
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
/** \file protectedlcd.c
*
* @brief Reentrant LCD driver.
*
*/
#include <assert.h>
#include <stdint.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/gates/GateMutexPri.h>
#include <ti/grlib/grlib.h>
#include "LcdDriver/Crystalfontz128x128_ST7735.h"
#include "Board.h"
#include "bsp.h"
#include "common.h"
#include "protectedlcd.h"
// Private mutex
static GateMutexPri_Handle g_lcd_mutex;
// Graphic library context
static Graphics_Context g_context;
/*!
* @brief Initialize the reentrant LCD driver.
*/
void protected_lcd_init(void)
{
GateMutexPri_Params mutex_params;
// Create the mutex that protects the hardware from race conditions.
/* Obtain instance handle */
GateMutexPri_Params_init(&mutex_params);
g_lcd_mutex = GateMutexPri_create(&mutex_params, NULL);
SYS_ASSERT(g_lcd_mutex != NULL);
/* Initializes display */
Crystalfontz128x128_Init();
/* Set default screen orientation */
Crystalfontz128x128_SetOrientation(LCD_ORIENTATION_UP);
/* Initializes graphics context */
Graphics_initContext(&g_context, &g_sCrystalfontz128x128,
&g_sCrystalfontz128x128_funcs);
Graphics_setForegroundColor(&g_context, GRAPHICS_COLOR_RED);
Graphics_setBackgroundColor(&g_context, GRAPHICS_COLOR_WHITE);
GrContextFontSet(&g_context, &g_sFontFixed6x8);
Graphics_clearDisplay(&g_context);
}
/*!
* @brief Display data on the LCD, safely.
* @param[in] Position and data.
*/
void protected_lcd_display(uint8_t position, char const *data)
{
int key;
// Try to acquire the mutex.
key = GateMutexPri_enter(g_lcd_mutex);
// Safely inside the critical section.
// Call the non-reentrant driver.
Graphics_drawString(&g_context,
(int8_t *)data,
AUTO_STRING_LENGTH,
10,
position*10 + 10,
OPAQUE_TEXT);
// Release the mutex.
GateMutexPri_leave(g_lcd_mutex, key);
}
/*!
* @brief Display data on the LCD, safely.
* @param[in] Position and data.
*/
void protected_lcd_clear(void)
{
int key;
// Try to acquire the mutex.
key = GateMutexPri_enter(g_lcd_mutex);
// Safely inside the critical section.
// Call the non-reentrant driver.
Graphics_clearDisplay(&g_context);
// Release the mutex.
GateMutexPri_leave(g_lcd_mutex, key);
}