commit 33838c5cceeb46c92d76d3e1c35e85aff466bf78
parent fa8322719236bd4326179f38b0aa26c718b54c49
Author: Henry Wilson <m3henry@googlemail.com>
Date: Sun, 11 Feb 2018 21:47:30 +0000
added preliminary font rendering
Diffstat:
A | font.h | | | 19 | +++++++++++++++++++ |
A | lcd.cpp | | | 135 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
M | lcd.h | | | 92 | +++++++++++++++++-------------------------------------------------------------- |
M | main.cpp | | | 10 | ++-------- |
4 files changed, 175 insertions(+), 81 deletions(-)
diff --git a/font.h b/font.h
@@ -0,0 +1,19 @@
+#pragma once
+#include <inttypes.h>
+
+namespace mash
+{
+ using glyph = uint8_t[8];
+
+ glyph X =
+ {
+ 0b11111000,
+ 0b00000100,
+ 0b00000010,
+ 0b11111111,
+ 0b11111111,
+ 0b00001110,
+ 0b00001100,
+ 0b00001000,
+ };
+}
diff --git a/lcd.cpp b/lcd.cpp
@@ -0,0 +1,135 @@
+#include "lcd.h"
+#include "hidModule.h"
+
+#include <util/delay.h>
+#include "font.h"
+
+/*
+ A0~ chip select
+ A1 Backlight
+ A2~ Reset
+ A3~ Write
+ A4~ Command
+ A5~ Read
+ A6~ Vsync
+ A7~ Hsync
+
+ C[0-7] DATA BUS
+*/
+namespace lcd {
+
+void send(const uint8_t d)
+{
+ control() = defaultControl & n_write;
+ data() = d;
+ control() = defaultControl;
+}
+
+void send(const uint16_t d)
+{
+ send(uint8_t(d >> 8));
+ send(uint8_t(d));
+}
+
+template <typename...Ts>
+void cmd(const uint8_t c, Ts... params)
+{
+ control() = defaultControl & n_command & n_write;
+ data() = c;
+ control() = defaultControl;
+
+ // https://stackoverflow.com/questions/25680461/variadic-template-pack-expansion#25683817
+ // TODO:(C++17) (send(params), ...);
+ char dummy[] __attribute__((unused)) {0, (send(uint8_t(params)), '\0')...};
+}
+
+void fillScreen(uint16_t colour)
+{
+ cmd(0x2C);
+ uint8_t j = (320ul * 240) / (256 * 2);
+ uint8_t i = 0; // uses wraparound
+ do
+ {
+ do {
+ lcd::send(colour);
+ lcd::send(colour);
+ } while (--i);
+ } while (--j);
+}
+
+void init()
+{
+ controlDir() = 0xFF;
+ dataDir() = 0xFF;
+
+ control() = defaultControl & n_reset;
+ _delay_us(16);
+ control() = defaultControl;
+ _delay_ms(128);
+
+
+ cmd(0x11); // awake
+ _delay_ms(6);
+
+ cmd(0x3A, 0x55); // 16 bits per pixel
+
+ fillScreen(0);
+
+ cmd(0x29); // display ON
+}
+
+[[noreturn]]
+void test()
+{
+ union pixel
+ {
+ struct __attribute__((packed)) {
+ uint8_t r:5;
+ uint8_t g:6;
+ uint8_t b:5;
+ };
+ uint16_t word;
+
+ pixel() : word(0) {}
+ } p;
+
+ static_assert(sizeof(pixel) == sizeof(uint16_t), "not correct size");
+
+ init();
+
+ cmd(0x2C);
+
+ for (;;)
+ {
+ //if (0 == ++p.r) if (0 == ++p.b) --p.g;
+
+ //send(p.word);
+ //send(uint16_t(0xF800));
+ auto x = hid::sampleInput();
+ send(x);
+ send(x);
+ }
+}
+
+void testFont()
+{
+ cmd(0x2A);
+ send(uint16_t(0));
+ send(uint16_t(7));
+
+ cmd(0x2C);
+
+ for (auto const r : mash::X)
+ {
+ send(r & bit(0) ? uint16_t(0xF800) : uint16_t(0x001F));
+ send(r & bit(1) ? uint16_t(0xF800) : uint16_t(0x001F));
+ send(r & bit(2) ? uint16_t(0xF800) : uint16_t(0x001F));
+ send(r & bit(3) ? uint16_t(0xF800) : uint16_t(0x001F));
+ send(r & bit(4) ? uint16_t(0xF800) : uint16_t(0x001F));
+ send(r & bit(5) ? uint16_t(0xF800) : uint16_t(0x001F));
+ send(r & bit(6) ? uint16_t(0xF800) : uint16_t(0x001F));
+ send(r & bit(7) ? uint16_t(0xF800) : uint16_t(0x001F));
+ }
+}
+
+}
diff --git a/lcd.h b/lcd.h
@@ -30,88 +30,34 @@ constexpr auto n_hsync = ~bit(7);
constexpr auto defaultControl = n_select;
-auto& control = io::out::A();
-auto& data = io::out::C();
-auto& controlDir = io::direction::A();
-auto& dataDir = io::direction::C();
-
-[[noreturn]] void test();
-
-void send(const uint8_t d)
+inline constexpr auto& control()
{
- control = defaultControl & n_write;
- data = d;
- control = defaultControl;
+ return io::out::A();
}
-
-void send(const uint16_t d)
+inline constexpr auto& data()
{
- send(uint8_t(d >> 8));
- send(uint8_t(d));
+ return io::out::C();
}
-
-template <typename...Ts>
-void cmd(const uint8_t c, Ts... params)
+inline constexpr auto& controlDir()
{
- control = defaultControl & n_command & n_write;
- data = c;
- control = defaultControl;
-
- // https://stackoverflow.com/questions/25680461/variadic-template-pack-expansion#25683817
- // TODO:(C++17) send(params), ...;
- char dummy[] __attribute__((unused)) {0, (send(uint8_t(params)), '\0')...};
+ return io::direction::A();
}
-
-void init()
+inline constexpr auto& dataDir()
{
- controlDir = 0xFF;
- dataDir = 0xFF;
-
- control = defaultControl & n_reset;
- _delay_us(16);
- control = defaultControl;
- _delay_ms(128);
-
-
- cmd(0x11); // awake
- _delay_ms(6);
-
- cmd(0x3A, 0x55); // 16 bits per pixel
-
- cmd(0x29); // display ON
+ return io::direction::C();
}
+constexpr uint16_t red = 0xF800;
+constexpr uint16_t green = 0x07E0;
+constexpr uint16_t blue = 0x001F;
+
+static_assert(red + green + blue == 0xFFFF, "RGB masks sum incorrectly");
+
+void init();
+
[[noreturn]]
-void test()
-{
- union pixel
- {
- struct __attribute__((packed)) {
- uint8_t r:5;
- uint8_t g:6;
- uint8_t b:5;
- };
- uint16_t word;
-
- pixel() : word(0) {}
- } p;
-
- static_assert(sizeof(pixel) == sizeof(uint16_t), "not correct size");
-
- init();
-
- cmd(0x2C);
-
- for (;;)
- {
- //if (0 == ++p.r) if (0 == ++p.b) --p.g;
-
- //send(p.word);
- //send(uint16_t(0xF800));
- auto x = hid::sampleInput();
- send(x);
- send(x);
- }
-}
+void test();
+
+void testFont();
}
diff --git a/main.cpp b/main.cpp
@@ -4,19 +4,13 @@
#include <util/delay.h>
-
-
int main(void)
{
ctrl::disableJTAG();
- hid::init();
-
- io::direction::C() = 0xFF;
-
- //hid::test();
+ lcd::init();
- lcd::test();
+ lcd::testFont();
/*
for (;;)
{