Repository navigation
Expand file tree
/
Copy pathdisplay.h
More file actions
65 lines (53 loc) · 2.72 KB
/
Copy pathdisplay.h
File metadata and controls
65 lines (53 loc) · 2.72 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
// display.h — ST7735 graphics and text rendering pipeline.
#ifndef DISPLAY_H
#define DISPLAY_H
#include <stdint.h>
// ---- Physical wiring ----------------------------------------------------
// Hardware SPI is used for the data bus: SCK=PB5, MOSI=PB3 (MISO/PB4 is
// unused -- the panel is write-only). NOTE: PB2 doubles as both the
// backlight pin (backlight.h) and the hardware SPI SS line; that's fine
// since SS only matters when configured as an input, and backlight.c
// already drives PB2 as an output, so there's no accidental slave-mode
// entry.
//
// TODO: CS/DC/RST below are placeholders on otherwise-unused PORTB/PORTC
// pins -- the project spec doesn't call out these three, so confirm them
// against the actual schematic/PCB silkscreen before flashing.
#define DISPLAY_CS_DDR DDRC
#define DISPLAY_CS_PORT PORTC
#define DISPLAY_CS_PIN PC0
#define DISPLAY_DC_DDR DDRC
#define DISPLAY_DC_PORT PORTC
#define DISPLAY_DC_PIN PC2
#define DISPLAY_RST_DDR DDRC
#define DISPLAY_RST_PORT PORTC
#define DISPLAY_RST_PIN PC1
#define DISPLAY_WIDTH 128
#define DISPLAY_HEIGHT 160
// 16-bit RGB565 colour helper + a few basics.
#define RGB565(r, g, b) ((uint16_t)((((r) & 0xF8) << 8) | (((g) & 0xFC) << 3) | ((b) >> 3)))
#define COLOR_BLACK RGB565(0, 0, 0)
#define COLOR_WHITE RGB565(255, 255, 255)
#define COLOR_RED RGB565(255, 0, 0)
#define COLOR_GREEN RGB565(0, 255, 0)
#define COLOR_BLUE RGB565(0, 0, 255)
#define COLOR_YELLOW RGB565(255, 255, 0)
#define COLOR_CYAN RGB565(0, 255, 255)
#define COLOR_MAGENTA RGB565(255, 0, 255)
#define COLOR_ORANGE RGB565(255, 165, 0)
// Runs the panel's hardware reset + init command sequence. This is the one
// place in the whole codebase where a blocking _delay_ms() is used -- it
// only runs once, before the main loop starts, so it doesn't violate the
// non-blocking runtime rule.
void displayInit(void);
void displayFillScreen(uint16_t color);
void displaySetAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1);
void displayDrawPixel(uint8_t x, uint8_t y, uint16_t color);
void displayFillRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t color);
// TODO: not implemented yet -- needs a glyph table (e.g. a 5x7 font in
// PROGMEM) and a per-character blit routine. Every screen currently draws
// placeholder rectangles instead of real labels.
void displayDrawText(uint8_t x, uint8_t y, const char *text, uint16_t color, uint16_t bg);
void displayDrawTextScaled(uint8_t x, uint8_t y, const char *text, uint16_t color, uint16_t bg, uint8_t scale);
void displayDrawThemedText(uint8_t x, uint8_t y, const char *text, const uint16_t *colors, uint8_t num_colors, uint16_t bg, uint8_t scale);
#endif // DISPLAY_H