display.c 2.47 KB
Newer Older
Gerd's avatar
Gerd committed
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
#include "epicardium.h"
#include "tmr_utils.h"
#include "gpio.h"
#include "GUI_DEV/GUI_Paint.h"
#include "Fonts/fonts.h"
#include "tmr.h"
#include "FreeRTOS.h"
#include "task.h"

static TaskHandle_t lock = NULL;

static int check_lock()
{
	TaskHandle_t task = xTaskGetCurrentTaskHandle();
	if (task != lock) {
		return -EBUSY;
	} else {
		return 0;
	}
}

int epic_disp_print(
	uint16_t posx,
	uint16_t posy,
	const char *pString,
	uint16_t fg,
	uint16_t bg
) {
	int cl = check_lock();
	if (cl < 0) {
		return cl;
	} else {
		Paint_DrawString_EN(posx, posy, pString, &Font20, bg, fg);
		return 0;
	}
}

int epic_disp_clear(uint16_t color)
{
	int cl = check_lock();
	if (cl < 0) {
		return cl;
	} else {
		LCD_Clear(color);
		return 0;
	}
}

49
50
51
52
53
54
55
56
57
58
59
int epic_disp_pixel(uint16_t x, uint16_t y, uint16_t color)
{
	int cl = check_lock();
	if (cl < 0) {
		return cl;
	} else {
		Paint_SetPixel(x, y, color);
		return 0;
	}
}

Gerd's avatar
Gerd committed
60
61
62
63
64
65
int epic_disp_line(
	uint16_t xstart,
	uint16_t ystart,
	uint16_t xend,
	uint16_t yend,
	uint16_t color,
Rahix's avatar
Rahix committed
66
	enum disp_linestyle linestyle,
Gerd's avatar
Gerd committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
	uint16_t pixelsize
) {
	int cl = check_lock();
	if (cl < 0) {
		return cl;
	} else {
		Paint_DrawLine(
			xstart, ystart, xend, yend, color, linestyle, pixelsize
		);
		return 0;
	}
}

int epic_disp_rect(
	uint16_t xstart,
	uint16_t ystart,
	uint16_t xend,
	uint16_t yend,
	uint16_t color,
Rahix's avatar
Rahix committed
86
	enum disp_fillstyle fillstyle,
Gerd's avatar
Gerd committed
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
	uint16_t pixelsize
) {
	int cl = check_lock();
	if (cl < 0) {
		return cl;
	} else {
		Paint_DrawRectangle(
			xstart, ystart, xend, yend, color, fillstyle, pixelsize
		);
		return 0;
	}
}

int epic_disp_circ(
	uint16_t x,
	uint16_t y,
	uint16_t rad,
	uint16_t color,
Rahix's avatar
Rahix committed
105
	enum disp_fillstyle fillstyle,
Gerd's avatar
Gerd committed
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
	uint16_t pixelsize
) {
	int cl = check_lock();
	if (cl < 0) {
		return cl;
	} else {
		Paint_DrawCircle(x, y, rad, color, fillstyle, pixelsize);
		return 0;
	}
}

int epic_disp_update()
{
	int cl = check_lock();
	if (cl < 0) {
		return cl;
	}
123
124
125
126
127
128
129
130
131
132
133
134
135
136

	LCD_Update();
	return 0;
}

int epic_disp_framebuffer(union disp_framebuffer *fb)
{
	int cl = check_lock();
	if (cl < 0) {
		return cl;
	}

	LCD_Set(fb->raw, sizeof(fb->raw));
	return 0;
Gerd's avatar
Gerd committed
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
}

int epic_disp_open()
{
	TaskHandle_t task = xTaskGetCurrentTaskHandle();
	if (lock == task) {
		return 0;
	} else if (lock == NULL) {
		lock = task;
		return 0;
	} else {
		return -EBUSY;
	}
}

int epic_disp_close()
{
	if (check_lock() < 0 && lock != NULL) {
		return -EBUSY;
	} else {
		lock = NULL;
		return 0;
	}
}

void disp_forcelock()
{
	TaskHandle_t task = xTaskGetCurrentTaskHandle();
	lock              = task;
}