Skip to content

Commit 881aaa9

Browse files
arkadiuszwojcikArkadiusz Wójcik
andauthored
ST77xx LCD driver (#926)
ST7735 and ST7789 driver implementation. Tested against [Pico LCD 0.96](https://www.waveshare.com/wiki/Pico-LCD-0.96) [ST7735] and [Pico LCD 1.3](https://www.waveshare.com/wiki/Pico-LCD-1.3) [ST7789] --------- Co-authored-by: Arkadiusz Wójcik <wojcik.arkadiusz@outlook.com>
1 parent ef1eaba commit 881aaa9

4 files changed

Lines changed: 491 additions & 403 deletions

File tree

drivers/display/colors.zig

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,38 @@
11
//!
22
//! This file provides common color types found on the supported displays.
33
//!
4+
//!
5+
const std = @import("std");
46

57
/// A color type encoding only black and white.
68
pub const BlackWhite = enum(u1) {
79
black = 0,
810
white = 1,
911
};
1012

11-
pub const RGB565 = Color(.{ u5, u6, u5 });
12-
pub const RGB888 = Color(.{ u8, u8, u8 });
13-
14-
/// Provides a namespace with the default colors for the given `Color` type.
15-
pub fn Color(comptime Ts: [3]type) type {
16-
return packed struct {
13+
pub fn RGB565_Generic(desired_endianness: std.builtin.Endian) type {
14+
return struct {
1715
const Self = @This();
1816

19-
r: Ts[0],
20-
g: Ts[1],
21-
b: Ts[2],
17+
value: u16,
2218

23-
pub const black: Self = .from_rgb(0x00, 0x00, 0x00);
24-
pub const white: Self = .from_rgb(0xFF, 0xFF, 0xFF);
25-
pub const red: Self = .from_rgb(0xFF, 0x00, 0x00);
26-
pub const green: Self = .from_rgb(0x00, 0xFF, 0x00);
27-
pub const blue: Self = .from_rgb(0x00, 0x00, 0xFF);
28-
pub const cyan: Self = .from_rgb(0x00, 0xFF, 0xFF);
29-
pub const magenta: Self = .from_rgb(0xFF, 0x00, 0xFF);
30-
pub const yellow: Self = .from_rgb(0xFF, 0xFF, 0x00);
19+
pub const black: Self = from_rgb(0x00, 0x00, 0x00);
20+
pub const white: Self = from_rgb(0xFF, 0xFF, 0xFF);
21+
pub const red: Self = from_rgb(0xFF, 0x00, 0x00);
22+
pub const green: Self = from_rgb(0x00, 0xFF, 0x00);
23+
pub const blue: Self = from_rgb(0x00, 0x00, 0xFF);
24+
pub const cyan: Self = from_rgb(0x00, 0xFF, 0xFF);
25+
pub const magenta: Self = from_rgb(0xFF, 0x00, 0xFF);
26+
pub const yellow: Self = from_rgb(0xFF, 0xFF, 0x00);
3127

3228
pub fn from_rgb(r: u8, g: u8, b: u8) Self {
33-
return Self{
34-
.r = @truncate(r >> (8 - @bitSizeOf(Ts[0]))),
35-
.g = @truncate(g >> (8 - @bitSizeOf(Ts[1]))),
36-
.b = @truncate(b >> (8 - @bitSizeOf(Ts[2]))),
37-
};
29+
const r5: u16 = @as(u16, r) >> 3;
30+
const g6: u16 = @as(u16, g) >> 2;
31+
const b5: u16 = @as(u16, b) >> 3;
32+
33+
const v: u16 = (r5 << 11) | (g6 << 5) | b5;
34+
35+
return .{ .value = std.mem.nativeTo(u16, v, desired_endianness) };
3836
}
3937
};
4038
}

0 commit comments

Comments
 (0)