35 #include <sys/ioctl.h>
40 Black = 0b00000
'000000'00000,
41 Navy = 0b00000
'000000'10000,
42 Blue = 0b00000
'000000'11000,
43 Green = 0b00000
'011000'00000,
44 Teal = 0b00000
'010000'01000,
45 Lime = 0b00000
'111000'00000,
46 Aqua = 0b00000
'111000'11000,
47 Maroon = 0b01100
'000000'00000,
48 Purple = 0b01100
'000000'11000,
49 Olive = 0b01100
'011000'00000,
50 Gray = 0b01000
'010000'01000,
51 Red = 0b11100
'000000'00000,
52 Fuchsia = 0b11100
'000000'11000,
53 Yellow = 0b11100
'111000'00000,
54 Orange = 0b11100
'100000'00000,
55 White = 0b11100
'111000'11000,
68 template<auto Context>
78 static bool init() noexcept {
79 int fd = open(
"/dev/fb0", O_RDWR);
80 if (fd == -1)
return false;
84 if (ioctl(fd, FBIOGET_FSCREENINFO, &Display::s_finfo) == -1)
return false;
86 if (ioctl(fd, FBIOGET_VSCREENINFO, &Display::s_vinfo) == -1)
return false;
88 Display::s_xSize = Display::s_vinfo.xres;
89 Display::s_ySize = Display::s_vinfo.yres;
90 Display::s_bpp = Display::s_vinfo.bits_per_pixel;
92 Display::s_framebufferAddress = (
u32)mmap(
nullptr, Display::s_finfo.line_length * Display::s_vinfo.yres, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
93 if (Display::s_framebufferAddress == 0xFFFF
'FFFF) return false;
95 Display::clear(bsp::drv::Color::Black);
106 static bool deinit() {
107 munmap(getFramebufferAddress(), Display::s_xSize * Display::s_ySize * Display::s_bpp / 8);
112 * @brief Display reset
114 static void reset() noexcept {
119 * @brief Enable the display
121 static void turnOn() noexcept {
126 * @brief Disable the display
128 static void turnOff() noexcept {
133 * @brief Get the display width
135 * @return display width
137 static inline u16 getWidth() {
138 return Display::s_xSize;
142 * @brief Get the display height
144 * @return display height
146 static inline u16 getHeight() {
147 return Display::s_ySize;
151 * @brief Set the color palette
153 * @param palettet Color palette
155 static inline void setPalette(const std::array<u32, 256> &palette) {
160 * @brief Get the default color palette
162 * @return Default color palette
164 static std::array<u32, 256> getDefaultPalette() {
169 * @brief Get the framebuffer address
171 * @return framebuffer address
173 ALWAYS_INLINE static void* getFramebufferAddress() {
174 return reinterpret_cast<void*>(Display::s_framebufferAddress);
180 * @param x X coordinate
181 * @param y Y coordinate
182 * @param color Index for the color
184 ALWAYS_INLINE static void setPixel(u16 x, u16 y, u32 color) {
185 u32 offset = (x + Display::s_vinfo.xoffset) * (Display::s_bpp / 8) + (y + Display::s_vinfo.yoffset) * Display::s_finfo.line_length;
187 std::memcpy(reinterpret_cast<u8*>(getFramebufferAddress()) + offset, &color, Display::s_bpp / 8);
196 ALWAYS_INLINE static void clear(auto color) {
197 for (u32 x = 0; x < Display::s_xSize; x++)
198 for (u32 y = 0; y < Display::s_ySize; y++)
199 Display::setPixel(x, y, static_cast<u32>(color));
205 static inline u32 s_framebufferAddress;
207 static inline u16 s_xSize, s_ySize;
208 static inline u8 s_bpp;
210 static inline fb_fix_screeninfo s_finfo;
211 static inline fb_var_screeninfo s_vinfo;
216 template<auto, template<auto> typename>
217 friend struct bsp::drv::Display;