-
Notifications
You must be signed in to change notification settings - Fork 0
/
LTDC_definition.h
141 lines (128 loc) · 3.03 KB
/
LTDC_definition.h
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
#include "lib_utils/peripheral_include.h"
//SOOL-LTDC-INCLUDES-BEGIN
#include "RCC.h"
//SOOL-LTDC-INCLUDES-END
namespace sool { namespace core {
class LTDC {
//SOOL-LTDC-SUB-TYPES-BEGIN
enum class Layer
{
Layer1,
Layer2
};
enum class PixelFormat
{
ARGB8888 = 0,
RGB888,
RGB565,
ARGB1555,
ARGB4444,
L8, //8bit luminance
AL44,//4bit alpha, 4bit luminance
AL88 //8bit alpha, 8bit luminance
};
//SOOL-LTDC-SUB-TYPES-END
//SOOL-LTDC-DECLARATIONS-BEGIN
constexpr volatile Reg32_t &get_clock_enable_reg(const uintptr_t addr) volatile;
constexpr uint32_t get_clock_enable_bit(const uintptr_t addr) volatile;
inline void enable_clock() volatile;
inline void clut_write(Layer l,uint8_t address, uint32_t color) volatile;
inline void clut_write(Layer l,uint8_t address, uint8_t r, uint8_t g, uint8_t b) volatile;
void clut_write(const Layer l,const uint32_t table[],const int table_length) volatile;
inline void enable_clut(Layer l) volatile;
inline void enable_color_keying(Layer l,uint32_t color) volatile;
inline void enable() volatile {GCR.LTDCEN = 1;};
inline void disable() volatile{GCR.LTDCEN = 0;};
inline void update_shadow_registers(bool immediate = false) volatile
{
if(immediate)
SRCR.IMR = 1;
else
SRCR.VBR = 1;
};
//SOOL-LTDC-DECLARATIONS-END
};
//SOOL-LTDC-DEFINITIONS-BEGIN
constexpr volatile Reg32_t& LTDC::get_clock_enable_reg(const uintptr_t addr) volatile
{
switch (addr)
{
//Output for LTDCEN
#ifdef LTDC_BASE_ADDR
case LTDC_BASE_ADDR :
#if defined(STM32H7 )
return RCC->APB3ENR;
#elif defined(STM32F4 ) || defined(STM32F7 )
return RCC->APB2ENR;
#endif
#endif
}
}
constexpr uint32_t LTDC::get_clock_enable_bit(const uintptr_t addr) volatile
{
switch (addr)
{
//Output for LTDCEN
#ifdef LTDC_BASE_ADDR
case LTDC_BASE_ADDR :
#if defined(STM32H7 )
return 1 << 3;
#elif defined(STM32F4 ) || defined(STM32F7 )
return 1 << 26;
#endif
#endif
}
return 0;
}
inline void LTDC::enable_clock() volatile
{
get_clock_enable_reg(get_addr()) |= get_clock_enable_bit(get_addr());
}
inline void LTDC::clut_write(LTDC::Layer l,uint8_t address, uint32_t color) volatile
{
switch (l)
{
case Layer::Layer1:
L1CLUTWR = address << 24 | (color & 0xFFFFFF);
return;
case Layer::Layer2:
L2CLUTWR = address << 24 | (color & 0xFFFFFF);
return;
}
}
inline void LTDC::clut_write(LTDC::Layer l,uint8_t address, uint8_t r, uint8_t g, uint8_t b) volatile
{
switch (l)
{
case Layer::Layer1:
L1CLUTWR = address << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF);
return;
case Layer::Layer2:
L2CLUTWR = address << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF);
return;
}
}
inline void LTDC::enable_clut(LTDC::Layer l) volatile
{
if(l == Layer::Layer1)
L1CR.CLUTEN = 1;
else
L2CR.CLUTEN = 1;
update_shadow_registers(true);
}
inline void LTDC::enable_color_keying(LTDC::Layer l,uint32_t color) volatile
{
if(l == Layer::Layer1)
{
L1CKCR = color & 0xFFFFFF;
L1CR.COLKEN = 1;
}
else
{
L2CKCR = color & 0xFFFFFF;
L2CR.COLKEN = 1;
}
update_shadow_registers(true);
}
//SOOL-LTDC-DEFINITIONS-END
} };