Skip to content

Commit

Permalink
WIP - xdisplay
Browse files Browse the repository at this point in the history
  • Loading branch information
cepetr committed Mar 20, 2024
1 parent 0883e04 commit f5de3aa
Show file tree
Hide file tree
Showing 25 changed files with 5,994 additions and 3 deletions.
6 changes: 6 additions & 0 deletions core/embed/rust/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ pub use model_t1 as model;
pub use model_tr as model;
#[cfg(feature = "model_tt")]
pub use model_tt as model;

#[cfg(feature = "model_tt")]
pub mod drawlib_demo_t; // !!! REMOVE

#[cfg(feature = "model_tr")]
pub mod drawlib_demo_r; // !!! REMOVE
1 change: 0 additions & 1 deletion core/embed/rust/src/ui/shape/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ pub use model_tt::render_on_display;
pub mod model_t3t1;
#[cfg(feature = "model_t3t1")]
pub use model_t3t1::render_on_display;

3 changes: 1 addition & 2 deletions core/embed/rust/src/ui/shape/model/model_t3t1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ where
bump_b.reset();

let fb_addr = crate::trezorhal::display::get_fb_addr().0 as *mut u8;
let fb = unsafe { core::slice::from_raw_parts_mut(fb_addr, 240 * 240 * 2)};
let fb = unsafe { core::slice::from_raw_parts_mut(fb_addr, 240 * 240 * 2) };

let cache = DrawingCache::new(bump_a, bump_b);
let mut canvas = unwrap!(Rgb565Canvas::new(Offset::new(240, 240), None, fb));
Expand All @@ -40,4 +40,3 @@ where
display::refresh();
}
}

115 changes: 115 additions & 0 deletions core/embed/trezorhal/stm32f4/xdisplay/st-7789/panels/154a.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@


#include "displays/st7789v.h"

void _154a_init_seq(void) {
// most recent manual: https://www.newhavendisplay.com/app_notes/ILI9341.pdf
// TEON: Tearing Effect Line On; V-blanking only
CMD(0x35);
DATA(0x00);

// COLMOD: Interface Pixel format; 65K color: 16-bit/pixel (RGB 5-6-5 bits
// input)
CMD(0x3A);
DATA(0x55);

// Display Function Control: gate scan direction 319 -> 0
CMD(0xB6);
DATA(0x0A);
DATA(0xC2);
DATA(0x27);
DATA(0x00);

// Interface Control: XOR BGR as ST7789V does
CMD(0xF6);
DATA(0x09);
DATA(0x30);
DATA(0x00);

// the above config is the most important and definitely necessary

CMD(0xCF);
DATA(0x00);
DATA(0xC1);
DATA(0x30);

CMD(0xED);
DATA(0x64);
DATA(0x03);
DATA(0x12);
DATA(0x81);

CMD(0xE8);
DATA(0x85);
DATA(0x10);
DATA(0x7A);

CMD(0xF7);
DATA(0x20);

CMD(0xEA);
DATA(0x00);
DATA(0x00);

// power control VRH[5:0]
CMD(0xC0);
DATA(0x23);

// power control SAP[2:0] BT[3:0]
CMD(0xC1);
DATA(0x12);

// vcm control 1
CMD(0xC5);
DATA(0x60);
DATA(0x44);

// vcm control 2
CMD(0xC7);
DATA(0x8A);

// framerate
CMD(0xB1);
DATA(0x00);
DATA(0x18);

// 3 gamma func disable
CMD(0xF2);
DATA(0x00);

// gamma curve 1
CMD(0xE0);
DATA(0x0F);
DATA(0x2F);
DATA(0x2C);
DATA(0x0B);
DATA(0x0F);
DATA(0x09);
DATA(0x56);
DATA(0xD9);
DATA(0x4A);
DATA(0x0B);
DATA(0x14);
DATA(0x05);
DATA(0x0C);
DATA(0x06);
DATA(0x00);

// gamma curve 2
CMD(0xE1);
DATA(0x00);
DATA(0x10);
DATA(0x13);
DATA(0x04);
DATA(0x10);
DATA(0x06);
DATA(0x25);
DATA(0x26);
DATA(0x3B);
DATA(0x04);
DATA(0x0B);
DATA(0x0A);
DATA(0x33);
DATA(0x39);
DATA(0x0F);
}
8 changes: 8 additions & 0 deletions core/embed/trezorhal/stm32f4/xdisplay/st-7789/panels/154a.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef _154A_H_
#define _154A_H_

// ILI9341 IC controller

void _154a_init_seq(void);

#endif
82 changes: 82 additions & 0 deletions core/embed/trezorhal/stm32f4/xdisplay/st-7789/panels/lx154a2411.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

#include "displays/st7789v.h"

void lx154a2411_gamma(void) {
// positive voltage correction
CMD(0xE0);
DATA(0xD0);
DATA(0x03);
DATA(0x08);
DATA(0x0E);
DATA(0x11);
DATA(0x2B);
DATA(0x3B);
DATA(0x44);
DATA(0x4C);
DATA(0x2B);
DATA(0x16);
DATA(0x15);
DATA(0x1E);
DATA(0x21);

// negative voltage correction
CMD(0xE1);
DATA(0xD0);
DATA(0x03);
DATA(0x08);
DATA(0x0E);
DATA(0x11);
DATA(0x2B);
DATA(0x3B);
DATA(0x54);
DATA(0x4C);
DATA(0x2B);
DATA(0x16);
DATA(0x15);
DATA(0x1E);
DATA(0x21);
}

void lx154a2411_init_seq(void) {
// most recent manual:
// https://www.newhavendisplay.com/appnotes/datasheets/LCDs/ST7789V.pdf
// TEON: Tearing Effect Line On; V-blanking only
CMD(0x35);
DATA(0x00);

// COLMOD: Interface Pixel format; 65K color: 16-bit/pixel (RGB 5-6-5 bits
// input)
CMD(0x3A);
DATA(0x55);

// CMD2EN: Commands in command table 2 can be executed when EXTC level is Low
CMD(0xDF);
DATA(0x5A);
DATA(0x69);
DATA(0x02);
DATA(0x01);

// LCMCTRL: LCM Control: XOR RGB setting
CMD(0xC0);
DATA(0x20);

// GATECTRL: Gate Control; NL = 240 gate lines, first scan line is gate 80.;
// gate scan direction 319 -> 0
CMD(0xE4);
DATA(0x1D);
DATA(0x0A);
DATA(0x11);

// INVOFF (20h): Display Inversion Off
// INVON (21h): Display Inversion On
CMD(0x20);

// the above config is the most important and definitely necessary

// PWCTRL1: Power Control 1
CMD(0xD0);
DATA(0xA4);
DATA(0xA1);

lx154a2411_gamma();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef LX154A2411_H_
#define LX154A2411_H_

// ST7789_V IC controller
void lx154a2411_gamma(void);
void lx154a2411_init_seq(void);

#endif
148 changes: 148 additions & 0 deletions core/embed/trezorhal/stm32f4/xdisplay/st-7789/panels/lx154a2422.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@

#include "display.h"
#include "displays/st7789v.h"
#include "touch.h"

void lx154a2422_gamma(void) {
// positive voltage correction
CMD(0xE0);
DATA(0xD0);
DATA(0x0A);
DATA(0x10);
DATA(0x0A);
DATA(0x0A);
DATA(0x26);
DATA(0x36);
DATA(0x34);
DATA(0x4D);
DATA(0x18);
DATA(0x13);
DATA(0x14);
DATA(0x2F);
DATA(0x34);

// negative voltage correction
CMD(0xE1);
DATA(0xD0);
DATA(0x0A);
DATA(0x10);
DATA(0x0A);
DATA(0x09);
DATA(0x26);
DATA(0x36);
DATA(0x53);
DATA(0x4C);
DATA(0x18);
DATA(0x14);
DATA(0x14);
DATA(0x2F);
DATA(0x34);
}

void lx154a2422_init_seq(void) {
// most recent manual:
// https://www.newhavendisplay.com/appnotes/datasheets/LCDs/ST7789V.pdf
// TEON: Tearing Effect Line On; V-blanking only
CMD(0x35);
DATA(0x00);

// COLMOD: Interface Pixel format; 65K color: 16-bit/pixel (RGB 5-6-5 bits
// input)
CMD(0x3A);
DATA(0x55);

// CMD2EN: Commands in command table 2 can be executed when EXTC level is Low
CMD(0xDF);
DATA(0x5A);
DATA(0x69);
DATA(0x02);
DATA(0x01);

// LCMCTRL: LCM Control: XOR RGB setting
CMD(0xC0);
DATA(0x20);

// GATECTRL: Gate Control; NL = 240 gate lines, first scan line is gate 80.;
// gate scan direction 319 -> 0
CMD(0xE4);
DATA(0x1D);
DATA(0x0A);
DATA(0x11);

// INVOFF (20h): Display Inversion Off
// INVON (21h): Display Inversion On
CMD(0x21);

// the above config is the most important and definitely necessary

// PWCTRL1: Power Control 1
CMD(0xD0);
DATA(0xA4);
DATA(0xA1);

lx154a2422_gamma();
}

void lx154a2422_rotate(int degrees, display_padding_t* padding) {
uint16_t shift = 0;
char BX = 0, BY = 0;

#define RGB (1 << 3)
#define ML (1 << 4) // vertical refresh order
#define MH (1 << 2) // horizontal refresh order
#define MV (1 << 5)
#define MX (1 << 6)
#define MY (1 << 7)
// MADCTL: Memory Data Access Control - reference:
// section 8.12 in the ST7789V manual
uint8_t display_command_parameter = 0;
switch (degrees) {
case 0:
display_command_parameter = 0;
BY = 0;
break;
case 90:
display_command_parameter = MV | MX | MH | ML;
BX = 1;
shift = 1;
break;
case 180:
display_command_parameter = MX | MY | MH | ML;
BY = 0;
shift = 1;
break;
case 270:
display_command_parameter = MV | MY;
BX = 1;
break;
}

CMD(0x36);
DATA(display_command_parameter);

if (shift) {
// GATECTRL: Gate Control; NL = 240 gate lines, first scan line is
// gate 80.; gate scan direction 319 -> 0
CMD(0xE4);
DATA(0x1D);
DATA(0x00);
DATA(0x11);
} else {
// GATECTRL: Gate Control; NL = 240 gate lines, first scan line is
// gate 80.; gate scan direction 319 -> 0
CMD(0xE4);
DATA(0x1D);
DATA(0x0A);
DATA(0x11);
}

// reset the column and page extents
display_set_window(0, 0, DISPLAY_RESX - 1, DISPLAY_RESY - 1);

padding->x = BX ? (MAX_DISPLAY_RESY - DISPLAY_RESY) : 0;
padding->y = BY ? (MAX_DISPLAY_RESY - DISPLAY_RESY) : 0;
}

uint32_t lx154a2422_transform_touch_coords(uint16_t x, uint16_t y) {
return touch_pack_xy(x, y);
}
Loading

0 comments on commit f5de3aa

Please sign in to comment.