mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-24 23:38:09 +00:00
feat(core/rust): expose raw pixel access to rust
This commit is contained in:
parent
7b7318c3aa
commit
61482d0795
1
core/.changelog.d/2297.added
Normal file
1
core/.changelog.d/2297.added
Normal file
@ -0,0 +1 @@
|
|||||||
|
Expose raw pixel access to Rust
|
@ -68,7 +68,7 @@ static struct {
|
|||||||
|
|
||||||
static bool pixeldata_dirty = true;
|
static bool pixeldata_dirty = true;
|
||||||
|
|
||||||
void PIXELDATA(uint16_t c) {
|
void display_pixeldata(uint16_t c) {
|
||||||
if (PIXELWINDOW.pos.x <= PIXELWINDOW.end.x &&
|
if (PIXELWINDOW.pos.x <= PIXELWINDOW.end.x &&
|
||||||
PIXELWINDOW.pos.y <= PIXELWINDOW.end.y) {
|
PIXELWINDOW.pos.y <= PIXELWINDOW.end.y) {
|
||||||
// set to white if highest bits of all R, G, B values are set to 1
|
// set to white if highest bits of all R, G, B values are set to 1
|
||||||
@ -89,12 +89,13 @@ void PIXELDATA(uint16_t c) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define PIXELDATA(c) display_pixeldata(c)
|
||||||
|
|
||||||
static void display_reset_state() {}
|
static void display_reset_state() {}
|
||||||
|
|
||||||
void PIXELDATA_DIRTY() { pixeldata_dirty = true; }
|
void PIXELDATA_DIRTY() { pixeldata_dirty = true; }
|
||||||
|
|
||||||
static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1,
|
void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
|
||||||
uint16_t y1) {
|
|
||||||
PIXELWINDOW.start.x = x0;
|
PIXELWINDOW.start.x = x0;
|
||||||
PIXELWINDOW.start.y = y0;
|
PIXELWINDOW.start.y = y0;
|
||||||
PIXELWINDOW.end.x = x1;
|
PIXELWINDOW.end.x = x1;
|
||||||
|
@ -57,7 +57,7 @@ static void display_set_page_and_col(uint8_t page, uint8_t col) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PIXELDATA(uint16_t c) {
|
void display_pixeldata(uint16_t c) {
|
||||||
uint8_t data = DISPLAY_STATE.RAM[DISPLAY_STATE.row / 8][DISPLAY_STATE.col];
|
uint8_t data = DISPLAY_STATE.RAM[DISPLAY_STATE.row / 8][DISPLAY_STATE.col];
|
||||||
|
|
||||||
uint8_t bit = 1 << (DISPLAY_STATE.row % 8);
|
uint8_t bit = 1 << (DISPLAY_STATE.row % 8);
|
||||||
@ -93,6 +93,8 @@ void PIXELDATA(uint16_t c) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define PIXELDATA(c) display_pixeldata(c)
|
||||||
|
|
||||||
static void display_reset_state(void) {
|
static void display_reset_state(void) {
|
||||||
memset(DISPLAY_STATE.RAM, 0, sizeof(DISPLAY_STATE.RAM));
|
memset(DISPLAY_STATE.RAM, 0, sizeof(DISPLAY_STATE.RAM));
|
||||||
DISPLAY_STATE.row = 0;
|
DISPLAY_STATE.row = 0;
|
||||||
@ -115,8 +117,7 @@ static void display_unsleep(void) {
|
|||||||
CMD(0xAF); // Display ON
|
CMD(0xAF); // Display ON
|
||||||
}
|
}
|
||||||
|
|
||||||
static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1,
|
void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
|
||||||
uint16_t y1) {
|
|
||||||
if (x1 >= DISPLAY_RESX) {
|
if (x1 >= DISPLAY_RESX) {
|
||||||
x1 = DISPLAY_RESX - 1;
|
x1 = DISPLAY_RESX - 1;
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,8 @@ const volatile uint8_t DISPLAY_ST7789V_INVERT_COLORS = 0;
|
|||||||
// of ILI9341V datasheet
|
// of ILI9341V datasheet
|
||||||
#define DISPLAY_ID_ILI9341V 0x009341U
|
#define DISPLAY_ID_ILI9341V 0x009341U
|
||||||
|
|
||||||
|
void display_pixeldata(uint16_t c) { PIXELDATA(c); }
|
||||||
|
|
||||||
static uint32_t read_display_id(uint8_t command) {
|
static uint32_t read_display_id(uint8_t command) {
|
||||||
volatile uint8_t c = 0;
|
volatile uint8_t c = 0;
|
||||||
uint32_t id = 0;
|
uint32_t id = 0;
|
||||||
@ -117,8 +119,7 @@ static void display_unsleep(void) {
|
|||||||
|
|
||||||
static struct { uint16_t x, y; } BUFFER_OFFSET;
|
static struct { uint16_t x, y; } BUFFER_OFFSET;
|
||||||
|
|
||||||
static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1,
|
void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
|
||||||
uint16_t y1) {
|
|
||||||
x0 += BUFFER_OFFSET.x;
|
x0 += BUFFER_OFFSET.x;
|
||||||
x1 += BUFFER_OFFSET.x;
|
x1 += BUFFER_OFFSET.x;
|
||||||
y0 += BUFFER_OFFSET.y;
|
y0 += BUFFER_OFFSET.y;
|
||||||
|
@ -75,7 +75,7 @@ static struct {
|
|||||||
// noop on unix, display is refreshed every loop step
|
// noop on unix, display is refreshed every loop step
|
||||||
#define PIXELDATA_DIRTY()
|
#define PIXELDATA_DIRTY()
|
||||||
|
|
||||||
void PIXELDATA(uint16_t c) {
|
void display_pixeldata(uint16_t c) {
|
||||||
#if defined TREZOR_MODEL_1 || defined TREZOR_MODEL_R
|
#if defined TREZOR_MODEL_1 || defined TREZOR_MODEL_R
|
||||||
// set to white if highest bits of all R, G, B values are set to 1
|
// set to white if highest bits of all R, G, B values are set to 1
|
||||||
// bin(10000 100000 10000) = hex(0x8410)
|
// bin(10000 100000 10000) = hex(0x8410)
|
||||||
@ -98,6 +98,8 @@ void PIXELDATA(uint16_t c) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define PIXELDATA(c) display_pixeldata(c)
|
||||||
|
|
||||||
static void display_reset_state() {}
|
static void display_reset_state() {}
|
||||||
|
|
||||||
void display_init_seq(void) {}
|
void display_init_seq(void) {}
|
||||||
@ -208,8 +210,7 @@ void display_init(void) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1,
|
void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
|
||||||
uint16_t y1) {
|
|
||||||
if (!RENDERER) {
|
if (!RENDERER) {
|
||||||
display_init();
|
display_init();
|
||||||
}
|
}
|
||||||
|
@ -989,3 +989,5 @@ void display_utf8_substr(const char *buf_start, size_t buf_len, int char_off,
|
|||||||
*out_start = buf_start + i_start;
|
*out_start = buf_start + i_start;
|
||||||
*out_len = i - i_start;
|
*out_len = i - i_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void display_pixeldata_dirty(void) { PIXELDATA_DIRTY(); }
|
||||||
|
@ -107,3 +107,21 @@ pub fn loader(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn pixeldata(c: u16) {
|
||||||
|
unsafe {
|
||||||
|
ffi::display_pixeldata(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pixeldata_dirty() {
|
||||||
|
unsafe {
|
||||||
|
ffi::display_pixeldata_dirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_window(x0: u16, y0: u16, x1: u16, y1: u16) {
|
||||||
|
unsafe {
|
||||||
|
ffi::display_set_window(x0, y0, x1, y1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -183,6 +183,23 @@ pub fn text_right(baseline: Point, text: &str, font: Font, fg_color: Color, bg_c
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn pixeldata(color: Color) {
|
||||||
|
display::pixeldata(color.into());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pixeldata_dirty() {
|
||||||
|
display::pixeldata_dirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_window(window: Rect) {
|
||||||
|
display::set_window(
|
||||||
|
window.x0 as u16,
|
||||||
|
window.y0 as u16,
|
||||||
|
window.x1 as u16 - 1,
|
||||||
|
window.y1 as u16 - 1,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||||
pub struct Font(i32);
|
pub struct Font(i32);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user