avr-something

Something something AVR side…
git clone git://henryandlizzy.uk/avr-something
Log | Files | Refs | README

commit d5012eb89ac1cca5be85720d6e3db1c29d4346d3
parent 70f89b714e090aff979fcd1d25663acc84e36cec
Author: Henry Wilson <m3henry@googlemail.com>
Date:   Mon, 12 Feb 2018 21:53:52 +0000

Introduced "Hello, World!"

Diffstat:
Mfont.h | 19+++++--------------
Mlcd.cpp | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
Mlcd.h | 7++++++-
3 files changed, 77 insertions(+), 31 deletions(-)

diff --git a/font.h b/font.h @@ -1,23 +1,14 @@ #pragma once #include <inttypes.h> +#include <avr/pgmspace.h> -namespace mash +namespace fonts { using glyph = uint8_t[8]; -glyph const X = -{ - 0b11111000, - 0b00000100, - 0b00000010, - 0b11111111, - 0b11111111, - 0b00001110, - 0b00001100, - 0b00001000, -}; +using font = glyph[] ; -glyph const mash[] = +font const mash [[gnu::__progmem__]] = { {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// space {0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00},// ! @@ -116,7 +107,7 @@ glyph const mash[] = {0x00, 0x00, 0x30, 0x49, 0x06, 0x00, 0x00, 0x00}// ~ }; -glyph const oryx[] = +font const oryxB [[gnu::__progmem__]] = { {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// space {0x00, 0x18, 0x18, 0x18, 0x08, 0x00, 0x18, 0x00},// ! diff --git a/lcd.cpp b/lcd.cpp @@ -40,7 +40,7 @@ void cmd(const uint8_t c, Ts... params) // 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')...}; + char dummy[] {0, (send(uint8_t(params)), '\0')...}; } void fillScreen(uint16_t colour) @@ -75,6 +75,8 @@ void init() fillScreen(0); + cmd(0x36, 0x20); // x/y -> y/x + cmd(0x29); // display ON } @@ -111,25 +113,73 @@ void test() } } -void testFont() +void setColumns(const uint16_t start, const uint16_t end) { cmd(0x2A); - send(uint16_t(0)); - send(uint16_t(7)); - - cmd(0x2C); - - for (auto const r : mash::X) + send(start); + send(end); +} + +void setRows(const uint16_t start, const uint16_t end) +{ + cmd(0x2B); + send(start); + send(end); +} + +struct drawSequence +{ + drawSequence() + { + cmd(0x2C); + } + ~drawSequence() { - 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)); + cmd(0); } +}; + +struct +{ + void putc(const char c) + { + setColumns(y, y + 7); + y += 8; + setRows(0, 7); + + auto g = drawSequence(); + + uint8_t const* bytePtr = fonts::mash[c - ' ']; + + uint8_t x = 8; + do + { + auto byte = pgm_read_byte(bytePtr++); + send(byte & bit(7) ? foreground : background); + send(byte & bit(6) ? foreground : background); + send(byte & bit(5) ? foreground : background); + send(byte & bit(4) ? foreground : background); + send(byte & bit(3) ? foreground : background); + send(byte & bit(2) ? foreground : background); + send(byte & bit(1) ? foreground : background); + send(byte & bit(0) ? foreground : background); + } + while (--x); + } + void puts(char const* str) + { + while (auto c = *str++) putc(c); + } + + uint16_t x = 0, y = 0; + uint16_t foreground = white; + uint16_t background = dgrey; + fonts::glyph const* glyphs = fonts::mash; +} lout; + +void testFont() +{ + lout.puts("Hello, World!"); } } diff --git a/lcd.h b/lcd.h @@ -51,7 +51,12 @@ 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"); +constexpr uint16_t black = 0; +constexpr uint16_t dgrey = 0x18E5; +constexpr uint16_t grey = 0x39E7; +constexpr uint16_t white = 0xFFFF; + +static_assert(red + green + blue == white, "RGB masks sum incorrectly"); void init();