-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibtft.h
More file actions
204 lines (181 loc) · 4.66 KB
/
libtft.h
File metadata and controls
204 lines (181 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
* File: tft.h
* Author: torsten.roemer@luniks.net
*
* Created on 6. November 2023, 18:45
*/
#ifndef LIBTFT_H
#define LIBTFT_H
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include "font.h"
#define TFT_SWRESET 0x01
#define TFT_SLPIN 0x10
#define TFT_SLPOUT 0x11
#define TFT_NORON 0x13
#define TFT_INVOFF 0x20
#define TFT_INVON 0x21
#define TFT_DISPON 0x29
#define TFT_CASET 0x2a
#define TFT_RASET 0x2b
#define TFT_RAMWR 0x2c
#define TFT_MADCTL 0x36
#define TFT_COLMOD 0x3a
/**
* F_CPU dependent delay of 60 milliseconds.
* _delay_ms(60);
*/
void _tftDelay60(void);
/**
* Selects the display to talk to via SPI.
* PORTB &= ~(1 << PB1);
*/
void _tftSel(void);
/**
* Deselects the display to talk to via SPI.
* PORTB |= (1 << PB1);
*/
void _tftDes(void);
/**
* Sets display to send a command.
* PORTB &= ~(1 << PB2);
*/
void _tftSetCmd(void);
/**
* Sets display to send data.
* PORTB |= (1 << PB2);
*/
void _tftSetData(void);
/**
* Does a hardware reset.
* PORTB &= ~(1 << PB3);
* _delay_ms(10);
* PORTB |= (1 << PB3);
*/
void _tftReset(void);
/**
* SPI transmits/receives given data/returns it.
*
* @param data
* @return data
*/
uint8_t _tftTx(uint8_t data);
/**
* Initializes the display.
*
* @param width display width
* @param height display height
* @param hflip horizontal flip
* @param vflip vertical flip
* @param bgr BGR or RGB
* @param invert invert display
*/
void tftInit(width_t width, height_t height,
bool hflip, bool vflip,
bool bgr, bool invert);
/**
* Sets to write data to display RAM.
*/
void tftWriteStart(void);
/**
* Restart writing to display after SPI deselecting it.
*/
void tftWriteRestart(void);
/**
* Writes the given byte to display RAM.
*
* @param byte
*/
void tftWriteByte(uint8_t byte);
/**
* Completes writing data to display RAM.
*/
void tftWriteEnd(void);
/**
* Sets the given color in the given area of the display.
*
* @param x in pixels, origin top left
* @param y in pixels, origin top left
* @param width width in pixels
* @param height height in pixels
* @param color 16-Bit (5/6/5) RGB color
*/
void tftFillArea(x_t x, y_t y,
width_t width, height_t height,
uint16_t color);
/**
* Sets the area to write image data to.
*
* @param x in pixels, origin top left
* @param y in pixels, origin top left
* @param width width in pixels
* @param height height in pixels
* @param hflip if image should be flipped horizontally
* @param vflip if image should be flipped vertically
*/
void tftSetArea(x_t x, y_t y,
width_t width, height_t height,
bool hflip, bool vflip);
/**
* Sets the whole display to the given 16-Bit (5/6/5) RGB color.
*
* @param color
*/
void tftSetFrame(uint16_t color);
/**
* Writes image data to the previously set area.
*
* @param bitmap pointer to bitmap data in program memory
* @param width width of the bitmap in pixels
* @param height height of the bitmap in pixels
* @param space color space of the bitmap
* @param bg background color (used only with SPACE_MONO1)
* @param fg foreground color (used only with SPACE_MONO1)
*/
void tftWriteData(const __flash uint8_t *bitmap,
width_t width, height_t height,
space_t space, uint16_t bg, uint16_t fg);
/**
* Writes the bitmap with the given index to the given row and column
* and returns the width of the bitmap.
*
* @param x
* @param y
* @param index
* @param bg background color (used only with SPACE_MONO1)
* @param fg foreground color (used only with SPACE_MONO1)
* @return bitmap width
*/
width_t tftWriteBitmap(x_t x, y_t y, uint16_t index,
uint16_t bg, uint16_t fg);
/**
* Writes the glyph with the given pseudo UTF-8 code point with the given
* font to the given row and column and returns the width of the glyph.
*
* @param x
* @param y
* @param font
* @param code
* @param bg background color (used only with SPACE_MONO1)
* @param fg foreground color (used only with SPACE_MONO1)
* @return glyph width
*/
width_t tftWriteGlyph(x_t x, y_t y, const __flash Font *font, code_t code,
uint16_t bg, uint16_t fg);
/**
* Writes the given string with the given font to the given row and column
* and returns the width of the string.
*
* @param x
* @param y
* @param font
* @param string
* @param bg background color (used only with SPACE_MONO1)
* @param fg foreground color (used only with SPACE_MONO1)
* @return glyph width
*/
width_t tftWriteString(x_t x, y_t y, const __flash Font *font, const char *string,
uint16_t bg, uint16_t fg);
#endif /* LIBTFT_H */