-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssd1306_tests.c
91 lines (74 loc) · 1.88 KB
/
ssd1306_tests.c
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
#include "ssd1306.h"
#include <string.h>
void ssd1306_TestBorder()
{
ssd1306_Fill(Black);
uint32_t start = HAL_GetTick();
uint32_t end = start;
uint8_t x = 0;
uint8_t y = 0;
do
{
ssd1306_DrawPixel(x, y, Black);
if ((y == 0) && (x < 127))
x++;
else if ((x == 127) && (y < 31))
y++;
else if ((y == 31) && (x > 0))
x--;
else
y--;
ssd1306_DrawPixel(x, y, White);
ssd1306_UpdateScreen();
HAL_Delay(5);
end = HAL_GetTick();
} while ((end - start) < 10000);
HAL_Delay(1000);
}
void ssd1306_TestFonts()
{
ssd1306_Fill(Black);
ssd1306_SetCursor(2, 0);
ssd1306_WriteString("Font 11x18", Font_11x18, White);
ssd1306_SetCursor(2, 19);
ssd1306_WriteString("Font 7x10", Font_7x10, White);
ssd1306_UpdateScreen();
HAL_Delay(2000);
}
void ssd1306_TestFPS()
{
ssd1306_Fill(Black);
uint32_t start = HAL_GetTick();
uint32_t end = start;
int fps = 0;
char message[] = "ABCDEFGHIJK";
ssd1306_SetCursor(2, 0);
ssd1306_WriteString("Testing...", Font_11x18, White);
do
{
ssd1306_SetCursor(2, 0);
ssd1306_WriteString(message, Font_11x18, White);
ssd1306_UpdateScreen();
char ch = message[0];
memmove(message, message + 1, sizeof(message) - 2);
message[sizeof(message) - 2] = ch;
fps++;
end = HAL_GetTick();
} while ((end - start) < 3000);
HAL_Delay(100);
char buff[64];
fps = fps / ((end - start) / 1000);
snprintf(buff, sizeof(buff), "~%d FPS", fps);
ssd1306_Fill(Black);
ssd1306_SetCursor(2, 0);
ssd1306_WriteString(buff, Font_11x18, White);
ssd1306_UpdateScreen();
HAL_Delay(1000);
}
void ssd1306_TestAll()
{
//ssd1306_Init();
ssd1306_TestFPS();
ssd1306_TestBorder();
ssd1306_TestFonts();
}