Skip to content

Commit a239752

Browse files
authored
Use libtft (#33)
* Initial attempt to use libtft * Add Tux to the display as bitmap example * Update libtft
1 parent 511c517 commit a239752

File tree

21 files changed

+444
-1840
lines changed

21 files changed

+444
-1840
lines changed

Makefile

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ LORA = 1
1717
# Display dimensions
1818
DISPLAY_WIDTH = 320
1919
DISPLAY_HEIGHT = 240
20-
# 1 = BGR, 0 = RGB
21-
BGR = 0
20+
# true = BGR, false = RGB
21+
BGR = true
2222
# Invert color
23-
INVERT = 1
23+
INVERT = true
2424
# Flip image
25-
HFLIP = 1
26-
VFLIP = 0
25+
HFLIP = true
26+
VFLIP = false
2727

2828
ifndef RFM
2929
override RFM = 0
@@ -34,8 +34,7 @@ override LORA = 1
3434
endif
3535

3636
MAIN = avrrfm.c
37-
SRC = bitmaps.c colorspace.c dejavu.c display.c font.c i2c.c mcp9808.c \
38-
spi.c tft.c unifont.c usart.c rfm.c sdc.c
37+
SRC = bitmaps.c dejavu.c i2c.c mcp9808.c spi.c usart.c rfm.c tft.c sdc.c
3938

4039
CC = avr-gcc
4140
OBJCOPY = avr-objcopy
@@ -58,14 +57,13 @@ CFLAGS += -std=gnu99
5857

5958
TARGET = $(strip $(basename $(MAIN)))
6059
SRC += $(TARGET).c
61-
SRC += librfm$(RFM).a libsdc.a
60+
SRC += librfm$(RFM).a libtft.a libsdc.a
6261

6362
OBJ = $(SRC:.c=.o)
6463
OBJ = $(SRC:.S=.o)
6564

66-
$(TARGET).elf: bitmaps.h colorspace.h dejavu.h display.h font.h i2c.h \
67-
mcp9808.h pins.h spi.h tft.h types.h unifont.h usart.h utils.h \
68-
librfm$(RFM).h libsdc.h Makefile
65+
$(TARGET).elf: dejavu.h i2c.h mcp9808.h pins.h spi.h types.h unifont.h usart.h \
66+
utils.h librfm$(RFM).h libtft.h libsdc.h Makefile
6967

7068
all: $(TARGET).hex
7169

avrrfm.c

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@
2828
#include "spi.h"
2929
#include "utils.h"
3030
#include "librfm95.h"
31+
#include "libtft.h"
3132
#include "libsdc.h"
3233
#include "mcp9808.h"
33-
#include "tft.h"
34-
#include "display.h"
3534
#include "dejavu.h"
3635
#include "unifont.h"
3736

@@ -73,6 +72,30 @@
7372
#define RECEIVER 1
7473
#endif
7574

75+
#ifndef DISPLAY_WIDTH
76+
#define DISPLAY_WIDTH 320
77+
#endif
78+
79+
#ifndef DISPLAY_HEIGHT
80+
#define DISPLAY_HEIGHT 240
81+
#endif
82+
83+
#ifndef BGR
84+
#define BGR false
85+
#endif
86+
87+
#ifndef INVERT
88+
#define INVERT false
89+
#endif
90+
91+
#ifndef HFLIP
92+
#define HFLIP false
93+
#endif
94+
95+
#ifndef VFLIP
96+
#define VFLIP false
97+
#endif
98+
7699
static volatile uint16_t watchdogInts = 0;
77100

78101
/* Temp. label coordinates */
@@ -227,17 +250,17 @@ static void displayTemp(uint8_t rssi, bool crc, Temperature *temp) {
227250
snprintf(buf, sizeof (buf), "RSSI: %4d dBm, CRC: %d, PA: %s dBm",
228251
-rssi, crc, crc ? paf : "---");
229252
const __flash Font *unifont = &unifontFont;
230-
writeString(0, 0, unifont, buf, BLACK, WHITE);
253+
tftWriteString(0, 0, unifont, buf, BLACK, WHITE);
231254

232255
// display temperature (floating, red if CRC failed)
233256
snprintf(buf, sizeof (buf), "%c%d.%d°", tempx10 < 0 ? '-' : ' ',
234257
abs(tdiv.quot), abs(tdiv.rem));
235258
const __flash Font *dejaVu = &dejaVuFont;
236-
if (width > 0) fillArea(xo, yo, width, dejaVu->height, WHITE);
259+
if (width > 0) tftFillArea(xo, yo, width, dejaVu->height, WHITE);
237260
if (yl == 0) yl = unifont->height;
238261
// FIXME required space should be calculated before writing the text
239262
// i.e. 9.9° -> 10.0° can go wrong
240-
width = writeString(xl, yl, dejaVu, buf, WHITE, crc ? BLACK : RED);
263+
width = tftWriteString(xl, yl, dejaVu, buf, WHITE, crc ? BLACK : RED);
241264
xo = xl;
242265
yo = yl;
243266
xl += LABEL_OFFSET;
@@ -360,9 +383,10 @@ int main(void) {
360383
}
361384

362385
if (RECEIVER) {
363-
initDisplay();
364-
setFrame(WHITE);
365-
fillArea(0, 0, DISPLAY_WIDTH, 16, BLACK);
386+
tftInit(DISPLAY_WIDTH, DISPLAY_HEIGHT, HFLIP, VFLIP, BGR, INVERT);
387+
tftSetFrame(WHITE);
388+
tftFillArea(0, 0, DISPLAY_WIDTH, 16, BLACK);
389+
tftWriteBitmap(0, 176, 0, 0xffff, 0x0000);
366390
// initial rx mode
367391
if (radio) {
368392
if (LORA) {

bitmaps.c

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,78 @@
22
* File: bitmaps.c
33
* Author: torsten.roemer@luniks.net
44
*
5-
* Created on 6. November 2023, 18:45
5+
* Created on 06/07/2023, 23:28
66
*/
77

8-
#include "bitmaps.h"
8+
#include "font.h"
99

10-
const __flash uint8_t SOME_DATA[] = {
11-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
12-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
13-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
14-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
10+
const __flash uint8_t TUX_DATA[] = {
11+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
12+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
13+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
14+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
15+
0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00,
16+
0x00, 0x00, 0x03, 0xff, 0x80, 0x00, 0x00,
17+
0x00, 0x00, 0x07, 0xff, 0xc0, 0x00, 0x00,
18+
0x00, 0x00, 0x07, 0xff, 0xe0, 0x00, 0x00,
19+
0x00, 0x00, 0x0f, 0xff, 0xf0, 0x00, 0x00,
20+
0x00, 0x00, 0x0f, 0xff, 0xf0, 0x00, 0x00,
21+
0x00, 0x00, 0x0f, 0xff, 0xf0, 0x00, 0x00,
22+
0x00, 0x00, 0x0f, 0xf9, 0xf0, 0x00, 0x00,
23+
0x00, 0x00, 0x0c, 0xf0, 0xf8, 0x00, 0x00,
24+
0x00, 0x00, 0x08, 0x60, 0x78, 0x00, 0x00,
25+
0x00, 0x00, 0x0a, 0x66, 0x70, 0x00, 0x00,
26+
0x00, 0x00, 0x0b, 0x6e, 0x70, 0x00, 0x00,
27+
0x00, 0x00, 0x0b, 0x06, 0x70, 0x00, 0x00,
28+
0x00, 0x00, 0x0c, 0x02, 0xf0, 0x00, 0x00,
29+
0x00, 0x00, 0x08, 0x00, 0xf8, 0x00, 0x00,
30+
0x00, 0x00, 0x08, 0x00, 0x78, 0x00, 0x00,
31+
0x00, 0x00, 0x0c, 0x00, 0x78, 0x00, 0x00,
32+
0x00, 0x00, 0x0e, 0x00, 0xf8, 0x00, 0x00,
33+
0x00, 0x00, 0x0e, 0x04, 0xfc, 0x00, 0x00,
34+
0x00, 0x00, 0x0b, 0x10, 0x7e, 0x00, 0x00,
35+
0x00, 0x00, 0x19, 0xe0, 0x3e, 0x00, 0x00,
36+
0x00, 0x00, 0x30, 0x00, 0x3f, 0x00, 0x00,
37+
0x00, 0x00, 0x30, 0x00, 0x1f, 0x80, 0x00,
38+
0x00, 0x00, 0x60, 0x00, 0x1f, 0xc0, 0x00,
39+
0x00, 0x00, 0xe0, 0x00, 0x1f, 0xc0, 0x00,
40+
0x00, 0x01, 0xe0, 0x00, 0x0f, 0xe0, 0x00,
41+
0x00, 0x03, 0xe0, 0x00, 0x0f, 0xf0, 0x00,
42+
0x00, 0x03, 0xc0, 0x00, 0x07, 0xf0, 0x00,
43+
0x00, 0x03, 0xc0, 0x00, 0x07, 0x78, 0x00,
44+
0x00, 0x07, 0x80, 0x00, 0x03, 0x78, 0x00,
45+
0x00, 0x07, 0x80, 0x00, 0x03, 0xbc, 0x00,
46+
0x00, 0x0f, 0x80, 0x00, 0x03, 0xbc, 0x00,
47+
0x00, 0x0f, 0x00, 0x00, 0x03, 0xbc, 0x00,
48+
0x00, 0x1f, 0x00, 0x00, 0x03, 0xbc, 0x00,
49+
0x00, 0x1f, 0x00, 0x00, 0x03, 0xbe, 0x00,
50+
0x00, 0x3f, 0x00, 0x00, 0x03, 0xbe, 0x00,
51+
0x00, 0x3b, 0x00, 0x00, 0x02, 0x3e, 0x00,
52+
0x00, 0x3d, 0x00, 0x00, 0x01, 0xfe, 0x00,
53+
0x00, 0x26, 0x00, 0x00, 0x03, 0xfe, 0x00,
54+
0x00, 0x03, 0x00, 0x00, 0x07, 0xfe, 0x00,
55+
0x00, 0x01, 0xc0, 0x00, 0x03, 0xf9, 0x00,
56+
0x00, 0x00, 0xe0, 0x00, 0x01, 0xf1, 0x00,
57+
0x00, 0x40, 0x70, 0x00, 0x00, 0xe1, 0x00,
58+
0x06, 0x00, 0x78, 0x00, 0x00, 0x01, 0x00,
59+
0x08, 0x00, 0x3c, 0x00, 0x08, 0x01, 0x00,
60+
0x00, 0x00, 0x3c, 0x00, 0x08, 0x00, 0x80,
61+
0x04, 0x00, 0x1c, 0x00, 0x08, 0x00, 0x20,
62+
0x04, 0x00, 0x08, 0x00, 0x08, 0x00, 0x10,
63+
0x04, 0x00, 0x08, 0x00, 0x68, 0x00, 0x10,
64+
0x00, 0x00, 0x04, 0x00, 0xe8, 0x00, 0x60,
65+
0x08, 0x00, 0x05, 0x03, 0xf8, 0x01, 0x80,
66+
0x08, 0x00, 0x05, 0xff, 0xf8, 0x06, 0x00,
67+
0x07, 0x00, 0x07, 0xff, 0xf8, 0x08, 0x00,
68+
0x00, 0x38, 0x06, 0x00, 0x18, 0x30, 0x00,
69+
0x00, 0x03, 0x0c, 0x00, 0x0c, 0x60, 0x00,
70+
0x00, 0x00, 0x70, 0x00, 0x07, 0x80, 0x00,
71+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
72+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
73+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
74+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1575
};
1676

1777
const __flash Bitmap bitmaps[] = {
18-
{16, 16, SPACE_MONO1, SOME_DATA}
19-
};
78+
{56, 64, SPACE_MONO1, TUX_DATA}
79+
};

bitmaps.h

Lines changed: 0 additions & 34 deletions
This file was deleted.

colorspace.c

Lines changed: 0 additions & 89 deletions
This file was deleted.

colorspace.h

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)