mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 23:48:12 +00:00
legacy: fix SCA when displaying the words
This commit is contained in:
parent
5edffb3230
commit
f16c941ed4
@ -544,8 +544,9 @@ void layoutResetWord(const char *word, int pass, int word_pos, bool last) {
|
|||||||
oledDrawString(left, 0 * 9, action, FONT_STANDARD);
|
oledDrawString(left, 0 * 9, action, FONT_STANDARD);
|
||||||
oledDrawString(left, 2 * 9, word_pos < 10 ? index_str + 1 : index_str,
|
oledDrawString(left, 2 * 9, word_pos < 10 ? index_str + 1 : index_str,
|
||||||
FONT_STANDARD);
|
FONT_STANDARD);
|
||||||
oledDrawString(left, 3 * 9, word, FONT_STANDARD | FONT_DOUBLE);
|
oledDrawStringCenter(OLED_WIDTH / 2, 4 * 9 - 3, word,
|
||||||
oledHLine(OLED_HEIGHT - 13);
|
FONT_FIXED | FONT_DOUBLE);
|
||||||
|
oledSCA(4 * 9 - 3 - 2, 4 * 9 - 3 + 15 + 2, OLED_WIDTH / 2);
|
||||||
layoutButtonYes(btnYes);
|
layoutButtonYes(btnYes);
|
||||||
oledRefresh();
|
oledRefresh();
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,13 @@ static bool is_debug_link = 0;
|
|||||||
#define OLED_OFFSET(x, y) (OLED_BUFSIZE - 1 - (x) - ((y) / 8) * OLED_WIDTH)
|
#define OLED_OFFSET(x, y) (OLED_BUFSIZE - 1 - (x) - ((y) / 8) * OLED_WIDTH)
|
||||||
#define OLED_MASK(x, y) (1 << (7 - (y) % 8))
|
#define OLED_MASK(x, y) (1 << (7 - (y) % 8))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the state of the pixel at x, y
|
||||||
|
*/
|
||||||
|
bool oledGetPixel(int x, int y) {
|
||||||
|
return _oledbuffer[OLED_OFFSET(x, y)] & OLED_MASK(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Draws a white pixel at x, y
|
* Draws a white pixel at x, y
|
||||||
*/
|
*/
|
||||||
@ -239,11 +246,11 @@ void oledDrawChar(int x, int y, char c, int font) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int zoom = (font & FONT_DOUBLE ? 2 : 1);
|
int zoom = (font & FONT_DOUBLE) ? 2 : 1;
|
||||||
int char_width = fontCharWidth(font & 0x7f, c);
|
int char_width = fontCharWidth(font & 0x7f, c);
|
||||||
const uint8_t *char_data = fontCharData(font & 0x7f, c);
|
const uint8_t *char_data = fontCharData(font & 0x7f, c);
|
||||||
|
|
||||||
if (x <= -char_width * zoom) {
|
if (x <= -char_width) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +260,7 @@ void oledDrawChar(int x, int y, char c, int font) {
|
|||||||
if (zoom <= 1) {
|
if (zoom <= 1) {
|
||||||
oledDrawPixel(x + xo, y + yo);
|
oledDrawPixel(x + xo, y + yo);
|
||||||
} else {
|
} else {
|
||||||
oledBox(x + xo * zoom, y + yo * zoom, x + (xo + 1) * zoom - 1,
|
oledBox(x + xo, y + yo * zoom, x + (xo + 1) - 1,
|
||||||
y + (yo + 1) * zoom - 1, true);
|
y + (yo + 1) * zoom - 1, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -273,12 +280,12 @@ char oledConvertChar(const char c) {
|
|||||||
|
|
||||||
int oledStringWidth(const char *text, int font) {
|
int oledStringWidth(const char *text, int font) {
|
||||||
if (!text) return 0;
|
if (!text) return 0;
|
||||||
int size = (font & FONT_DOUBLE ? 2 : 1);
|
int space = (font & FONT_DOUBLE) ? 2 : 1;
|
||||||
int l = 0;
|
int l = 0;
|
||||||
for (; *text; text++) {
|
for (; *text; text++) {
|
||||||
char c = oledConvertChar(*text);
|
char c = oledConvertChar(*text);
|
||||||
if (c) {
|
if (c) {
|
||||||
l += size * (fontCharWidth(font & 0x7f, c) + 1);
|
l += fontCharWidth(font & 0x7f, c) + space;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return l;
|
return l;
|
||||||
@ -287,12 +294,12 @@ int oledStringWidth(const char *text, int font) {
|
|||||||
void oledDrawString(int x, int y, const char *text, int font) {
|
void oledDrawString(int x, int y, const char *text, int font) {
|
||||||
if (!text) return;
|
if (!text) return;
|
||||||
int l = 0;
|
int l = 0;
|
||||||
int size = (font & FONT_DOUBLE ? 2 : 1);
|
int space = (font & FONT_DOUBLE) ? 2 : 1;
|
||||||
for (; *text; text++) {
|
for (; *text; text++) {
|
||||||
char c = oledConvertChar(*text);
|
char c = oledConvertChar(*text);
|
||||||
if (c) {
|
if (c) {
|
||||||
oledDrawChar(x + l, y, c, font);
|
oledDrawChar(x + l, y, c, font);
|
||||||
l += size * (fontCharWidth(font & 0x7f, c) + 1);
|
l += fontCharWidth(font & 0x7f, c) + space;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -413,3 +420,21 @@ void oledSwipeRight(void) {
|
|||||||
oledRefresh();
|
oledRefresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Mitigate SCA on lines y1-y2 by setting exactly width pixels black
|
||||||
|
*/
|
||||||
|
void oledSCA(int y1, int y2, int width) {
|
||||||
|
y1 = MAX(y1, 0);
|
||||||
|
y2 = MIN(y2, OLED_HEIGHT - 1);
|
||||||
|
for (int y = y1; y <= y2; y++) {
|
||||||
|
int pix = 0;
|
||||||
|
for (int x = 0; x < OLED_WIDTH; x++) {
|
||||||
|
pix += oledGetPixel(x, y);
|
||||||
|
}
|
||||||
|
pix = MAX(width - pix, 0);
|
||||||
|
for (int x = 0 + (pix / 2); x < OLED_WIDTH - ((pix + 1) / 2); x++) {
|
||||||
|
oledInvertPixel(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -39,6 +39,7 @@ void oledInvertDebugLink(void);
|
|||||||
|
|
||||||
void oledSetBuffer(uint8_t *buf);
|
void oledSetBuffer(uint8_t *buf);
|
||||||
const uint8_t *oledGetBuffer(void);
|
const uint8_t *oledGetBuffer(void);
|
||||||
|
bool oledGetPixel(int x, int y);
|
||||||
void oledDrawPixel(int x, int y);
|
void oledDrawPixel(int x, int y);
|
||||||
void oledClearPixel(int x, int y);
|
void oledClearPixel(int x, int y);
|
||||||
void oledInvertPixel(int x, int y);
|
void oledInvertPixel(int x, int y);
|
||||||
@ -55,5 +56,6 @@ void oledHLine(int y);
|
|||||||
void oledFrame(int x1, int y1, int x2, int y2);
|
void oledFrame(int x1, int y1, int x2, int y2);
|
||||||
void oledSwipeLeft(void);
|
void oledSwipeLeft(void);
|
||||||
void oledSwipeRight(void);
|
void oledSwipeRight(void);
|
||||||
|
void oledSCA(int y1, int y2, int val);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user