diff --git a/extmod/modTrezorUi/modTrezorUi-inflate.h b/extmod/modTrezorUi/modTrezorUi-inflate.h index ad8d0ad46e..a57a0c9ac1 100644 --- a/extmod/modTrezorUi/modTrezorUi-inflate.h +++ b/extmod/modTrezorUi/modTrezorUi-inflate.h @@ -36,10 +36,6 @@ #include -#ifndef SINF_WRITE -#error Must define SINF_WRITE(byte) macro -#endif - // maximum possible window size (in bits) used during compression/deflate #define SINF_WBITS 10 @@ -59,6 +55,7 @@ typedef struct { int cbufi; SINF_TREE ltree; /* dynamic length/symbol tree */ SINF_TREE dtree; /* dynamic distance tree */ + void (* write)(uint8_t byte); } SINF_DATA; /* --------------------------------------------------- * @@ -106,7 +103,7 @@ static void sinf_write(SINF_DATA *d, uint8_t byte) { d->cbuf[d->cbufi] = byte; d->cbufi = (d->cbufi + 1) % (1 << SINF_WBITS); - SINF_WRITE(byte); + d->write(byte); } /* build the fixed huffman trees */ @@ -394,7 +391,7 @@ static int sinf_inflate_dynamic_block(SINF_DATA *d) * ---------------------- */ /* inflate stream from source */ -static int sinf_inflate(uint8_t *data) +static int sinf_inflate(uint8_t *data, void (*write_callback)(uint8_t byte)) { SINF_DATA d; int bfinal; @@ -403,6 +400,7 @@ static int sinf_inflate(uint8_t *data) d.bitcount = 0; d.cbufi = 0; d.source = data; + d.write = write_callback; do { diff --git a/extmod/modTrezorUi/modTrezorUi-stmhal.h b/extmod/modTrezorUi/modTrezorUi-stmhal.h index bccbb47e49..91e04bf58e 100644 --- a/extmod/modTrezorUi/modTrezorUi-stmhal.h +++ b/extmod/modTrezorUi/modTrezorUi-stmhal.h @@ -10,6 +10,10 @@ #define CMD(X) (*((__IO uint8_t *)((uint32_t)(0x60000000))) = (X)) #define DATA(X) (*((__IO uint8_t *)((uint32_t)(0x60000000 | 0x10000))) = (X)) +static void DATAfunc(uint8_t x) { + DATA(x); +} + static void DATAS(void *bytes, int len); void sram_init(void) { diff --git a/extmod/modTrezorUi/modTrezorUi-unix.h b/extmod/modTrezorUi/modTrezorUi-unix.h index 482e6051f0..96a33f4138 100644 --- a/extmod/modTrezorUi/modTrezorUi-unix.h +++ b/extmod/modTrezorUi/modTrezorUi-unix.h @@ -14,7 +14,9 @@ static SDL_Texture *TEXTURE = 0; static int DATAODD = 0; static int POSX, POSY, SX, SY, EX, EY = 0; -static void DATA(uint8_t x) { +#define DATA(X) DATAfunc((X)) + +static void DATAfunc(uint8_t x) { if (!SDL_inited) return; if (POSX <= EX && POSY <= EY) { ((uint8_t *)SCREEN->pixels)[POSX * 2 + POSY * SCREEN->pitch + (DATAODD ^ 1)] = x; diff --git a/extmod/modTrezorUi/modTrezorUi.c b/extmod/modTrezorUi/modTrezorUi.c index 084e0cf196..4aa7fe905d 100644 --- a/extmod/modTrezorUi/modTrezorUi.c +++ b/extmod/modTrezorUi/modTrezorUi.c @@ -60,7 +60,7 @@ static void display_blit(uint8_t x, uint8_t y, uint8_t w, uint8_t h, void *data, static void display_image(uint8_t x, uint8_t y, uint8_t w, uint8_t h, void *data, int datalen) { display_set_window(x, y, w, h); - sinf_inflate(data); + sinf_inflate(data, DATAfunc); display_update(); }