You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trezor-firmware/core/embed/trezorhal/stm32f4/display/st-7789/display_nofb.c

108 lines
3.1 KiB

/*
* This file is part of the Trezor project, https://trezor.io/
*
* Copyright (c) SatoshiLabs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include TREZOR_BOARD
#ifdef XFRAMEBUFFER
#include <xdisplay.h>
#include "display_io.h"
#include "display_panel.h"
void display_refresh(void) {
// if the framebuffer is not used the implementation is empty
}
static inline void set_window(const gl_bitblt_t* bb) {
display_panel_set_window(bb->dst_x, bb->dst_y, bb->dst_x + bb->width - 1,
bb->dst_y + bb->height + 1);
}
// For future notice, if we ever want to do a new model using progressive
// rendering.
//
// Following functions can be optimized by using DMA (regular is likely enough)
// to copy the data, along with the fill function. If even more performance is
// needed, we could use double-slice similarly to double-framebuffer and render
// to one with DMA2D while copying the other to the display with DMA.
void display_fill(const gl_bitblt_t* bb) {
set_window(bb);
uint16_t height = bb->height;
while (height-- > 0) {
for (int x = 0; x < bb->width; x++) {
ISSUE_PIXEL_DATA(bb->src_fg);
}
}
}
void display_copy_rgb565(const gl_bitblt_t* bb) {
set_window(bb);
uint16_t* src_ptr = (uint16_t*)bb->src_row + bb->src_x;
uint16_t height = bb->height;
while (height-- > 0) {
for (int x = 0; x < bb->width; x++) {
ISSUE_PIXEL_DATA(src_ptr[x]);
}
src_ptr += bb->src_stride / sizeof(*src_ptr);
}
}
void display_copy_mono1p(const gl_bitblt_t* bb) {
set_window(bb);
uint8_t* src = (uint8_t*)bb->src_row;
uint16_t src_ofs = bb->src_stride * bb->src_y + bb->src_x;
uint16_t height = bb->height;
while (height-- > 0) {
for (int x = 0; x < bb->width; x++) {
uint8_t mask = 1 << (7 - ((src_ofs + x) & 7));
uint8_t data = src[(src_ofs + x) / 8];
ISSUE_PIXEL_DATA((data & mask) ? bb->src_fg : bb->src_bg);
}
src_ofs += bb->src_stride;
}
}
void display_copy_mono4(const gl_bitblt_t* bb) {
set_window(bb);
const gl_color16_t* gradient = gl_color16_gradient_a4(bb->src_fg, bb->src_bg);
uint8_t* src_row = (uint8_t*)bb->src_row;
uint16_t height = bb->height;
while (height-- > 0) {
for (int x = 0; x < bb->width; x++) {
uint8_t fg_data = src_row[(x + bb->src_x) / 2];
uint8_t fg_lum = (x + bb->src_x) & 1 ? fg_data >> 4 : fg_data & 0xF;
ISSUE_PIXEL_DATA(gradient[fg_lum]);
}
src_row += bb->src_stride / sizeof(*src_row);
}
}
#endif // XFRAMEBUFFER