mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-18 10:32:02 +00:00
cleanup oledDrawChar code
This commit is contained in:
parent
50c8811af9
commit
c71abf91a6
@ -21,6 +21,7 @@
|
|||||||
#define __BUTTONS_H__
|
#define __BUTTONS_H__
|
||||||
|
|
||||||
#include <libopencm3/stm32/gpio.h>
|
#include <libopencm3/stm32/gpio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
struct buttonState {
|
struct buttonState {
|
||||||
volatile bool YesUp;
|
volatile bool YesUp;
|
||||||
|
51
oled.c
51
oled.c
@ -74,7 +74,7 @@
|
|||||||
#define OLED_BUFTGL(X,Y) _oledbuffer[OLED_BUFSIZE - 1 - (X) - ((Y)/8)*OLED_WIDTH] ^= (1 << (7 - (Y)%8))
|
#define OLED_BUFTGL(X,Y) _oledbuffer[OLED_BUFSIZE - 1 - (X) - ((Y)/8)*OLED_WIDTH] ^= (1 << (7 - (Y)%8))
|
||||||
|
|
||||||
static uint8_t _oledbuffer[OLED_BUFSIZE];
|
static uint8_t _oledbuffer[OLED_BUFSIZE];
|
||||||
static char is_debug_mode = 0;
|
static bool is_debug_mode = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send a block of data via the SPI bus.
|
* Send a block of data via the SPI bus.
|
||||||
@ -193,7 +193,7 @@ const uint8_t *oledGetBuffer()
|
|||||||
return _oledbuffer;
|
return _oledbuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void oledSetDebug(char set)
|
void oledSetDebug(bool set)
|
||||||
{
|
{
|
||||||
is_debug_mode = set;
|
is_debug_mode = set;
|
||||||
oledRefresh();
|
oledRefresh();
|
||||||
@ -216,7 +216,7 @@ void oledClearPixel(int x, int y)
|
|||||||
OLED_BUFCLR(x,y);
|
OLED_BUFCLR(x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void oledDrawChar(int x, int y, char c)
|
void oledDrawChar(int x, int y, char c, int zoom)
|
||||||
{
|
{
|
||||||
int char_width;
|
int char_width;
|
||||||
const uint8_t *char_data;
|
const uint8_t *char_data;
|
||||||
@ -226,34 +226,18 @@ void oledDrawChar(int x, int y, char c)
|
|||||||
char_width = fontCharWidth(c);
|
char_width = fontCharWidth(c);
|
||||||
char_data = fontCharData(c);
|
char_data = fontCharData(c);
|
||||||
|
|
||||||
int xoffset, yoffset;
|
int xo, yo;
|
||||||
for (xoffset = 0; xoffset < char_width; xoffset++) {
|
for (xo = 0; xo < char_width; xo++) {
|
||||||
for (yoffset = 0; yoffset < FONT_HEIGHT; yoffset++) {
|
for (yo = 0; yo < FONT_HEIGHT; yo++) {
|
||||||
if (char_data[xoffset] & (1 << (FONT_HEIGHT - 1 - yoffset))) {
|
if (char_data[xo] & (1 << (FONT_HEIGHT - 1 - yo))) {
|
||||||
oledDrawPixel(x + xoffset, y + yoffset);
|
if (zoom <= 1) {
|
||||||
|
oledDrawPixel(x + xo, y + yo);
|
||||||
|
} else {
|
||||||
|
oledBox(x + xo * zoom, y + yo * zoom, x + (xo + 1) * zoom - 1, y + (yo + 1) * zoom - 1, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void oledDrawZoomedChar(int x, int y, int z, char c)
|
|
||||||
{
|
|
||||||
int char_width;
|
|
||||||
const uint8_t *char_data;
|
|
||||||
|
|
||||||
if ((x >= OLED_WIDTH) || (y >= OLED_HEIGHT)) return;
|
|
||||||
|
|
||||||
char_width = fontCharWidth(c);
|
|
||||||
char_data = fontCharData(c);
|
|
||||||
|
|
||||||
int xoffset, yoffset;
|
|
||||||
for (xoffset = 0; xoffset < char_width; xoffset++) {
|
|
||||||
for (yoffset = 0; yoffset < FONT_HEIGHT; yoffset++) {
|
|
||||||
if (char_data[xoffset] & (1 << (FONT_HEIGHT - 1 - yoffset))) {
|
|
||||||
oledBox(x + xoffset * z, y + yoffset * z, x + xoffset * z + z - 1, y + yoffset * z + z - 1, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char oledConvertChar(const char c) {
|
char oledConvertChar(const char c) {
|
||||||
@ -292,13 +276,8 @@ void oledDrawString(int x, int y, const char* text)
|
|||||||
for (; *text; text++) {
|
for (; *text; text++) {
|
||||||
c = oledConvertChar(*text);
|
c = oledConvertChar(*text);
|
||||||
if (c) {
|
if (c) {
|
||||||
if (size > 1) {
|
oledDrawChar(x + l, y, c, size);
|
||||||
oledDrawZoomedChar(x + l, y, size, c);
|
l += size * (fontCharWidth(c) + 1);
|
||||||
l += fontCharWidth(c) * size + 1;
|
|
||||||
} else {
|
|
||||||
oledDrawChar(x + l, y, c);
|
|
||||||
l += fontCharWidth(c) + 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -345,12 +324,12 @@ void oledInvert(int x1, int y1, int x2, int y2)
|
|||||||
/*
|
/*
|
||||||
* Draw a filled rectangle.
|
* Draw a filled rectangle.
|
||||||
*/
|
*/
|
||||||
void oledBox(int x1, int y1, int x2, int y2, char val)
|
void oledBox(int x1, int y1, int x2, int y2, bool set)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
for (x = x1; x <= x2; x++) {
|
for (x = x1; x <= x2; x++) {
|
||||||
for (y = y1; y <= y2; y++) {
|
for (y = y1; y <= y2; y++) {
|
||||||
val ? oledDrawPixel(x, y) : oledClearPixel(x, y);
|
set ? oledDrawPixel(x, y) : oledClearPixel(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
8
oled.h
8
oled.h
@ -21,6 +21,7 @@
|
|||||||
#define __OLED_H__
|
#define __OLED_H__
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "bitmaps.h"
|
#include "bitmaps.h"
|
||||||
#include "fonts.h"
|
#include "fonts.h"
|
||||||
@ -33,20 +34,19 @@ void oledInit(void);
|
|||||||
void oledClear(void);
|
void oledClear(void);
|
||||||
void oledRefresh(void);
|
void oledRefresh(void);
|
||||||
|
|
||||||
void oledSetDebug(char set);
|
void oledSetDebug(bool set);
|
||||||
void oledSetBuffer(uint8_t *buf);
|
void oledSetBuffer(uint8_t *buf);
|
||||||
const uint8_t *oledGetBuffer(void);
|
const uint8_t *oledGetBuffer(void);
|
||||||
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 oledDrawChar(int x, int y, char c);
|
void oledDrawChar(int x, int y, char c, int zoom);
|
||||||
void oledDrawZoomedChar(int x, int y, int z, char c);
|
|
||||||
int oledStringWidth(const char *text);
|
int oledStringWidth(const char *text);
|
||||||
void oledDrawString(int x, int y, const char* text);
|
void oledDrawString(int x, int y, const char* text);
|
||||||
void oledDrawStringCenter(int y, const char* text);
|
void oledDrawStringCenter(int y, const char* text);
|
||||||
void oledDrawStringRight(int x, int y, const char* text);
|
void oledDrawStringRight(int x, int y, const char* text);
|
||||||
void oledDrawBitmap(int x, int y, const BITMAP *bmp);
|
void oledDrawBitmap(int x, int y, const BITMAP *bmp);
|
||||||
void oledInvert(int x1, int y1, int x2, int y2);
|
void oledInvert(int x1, int y1, int x2, int y2);
|
||||||
void oledBox(int x1, int y1, int x2, int y2, char val);
|
void oledBox(int x1, int y1, int x2, int y2, bool set);
|
||||||
void oledHLine(int y);
|
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user