From c30e469df97bb8d60e772a2c0d6558a1bc69cc1c Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Sun, 1 Oct 2023 16:47:39 -0700 Subject: [PATCH] split out display code --- stage2/include/colors.h | 11 ----------- stage2/include/display.h | 26 ++++++++++++++++++++++++++ stage2/src/display.cc | 38 ++++++++++++++++++++++++++++++++++++++ stage2/src/main.cc | 25 +++++++------------------ 4 files changed, 71 insertions(+), 29 deletions(-) delete mode 100644 stage2/include/colors.h create mode 100644 stage2/include/display.h create mode 100644 stage2/src/display.cc diff --git a/stage2/include/colors.h b/stage2/include/colors.h deleted file mode 100644 index 47268ee..0000000 --- a/stage2/include/colors.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -// Color definitions -#define BLACK 0x0000 -#define BLUE 0x001F -#define RED 0xF800 -#define GREEN 0x07E0 -#define CYAN 0x07FF -#define MAGENTA 0xF81F -#define YELLOW 0xFFE0 -#define WHITE 0xFFFF \ No newline at end of file diff --git a/stage2/include/display.h b/stage2/include/display.h new file mode 100644 index 0000000..8213fd4 --- /dev/null +++ b/stage2/include/display.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include + +namespace tft { + + // Color definitions + constexpr uint16_t BLACK = 0x0000; + constexpr uint16_t BLUE = 0x001F; + constexpr uint16_t RED = 0xF800; + constexpr uint16_t GREEN = 0x07E0; + constexpr uint16_t CYAN = 0x07FF; + constexpr uint16_t MAGENTA = 0xF81F; + constexpr uint16_t YELLOW = 0xFFE0 ; + constexpr uint16_t WHITE = 0xFFFF; + constexpr uint16_t LIGHT_GREY = 0xDEFB; + constexpr uint16_t FOREGROUND = BLACK; + constexpr uint16_t BACKGROUND = LIGHT_GREY; + + void Setup(); + void Clear(); + void SetCursor(int16_t x, int16_t y); + void Println(const char *s); +} \ No newline at end of file diff --git a/stage2/src/display.cc b/stage2/src/display.cc new file mode 100644 index 0000000..7f234ff --- /dev/null +++ b/stage2/src/display.cc @@ -0,0 +1,38 @@ +#include "display.h" + + +namespace tft { + constexpr uint8_t TFT_CS = 9; + constexpr uint8_t TFT_DC = 10; + + static Adafruit_ILI9341 tft(TFT_CS, TFT_DC); + + + void + Setup() + { + tft.begin(); + tft.setRotation(1); + tft.setTextSize(1); + tft.setTextColor(FOREGROUND); + Clear(); + } + + void + Clear() + { + tft.fillScreen(BACKGROUND); + } + + void + SetCursor(int16_t x, int16_t y) + { + tft.setCursor(x, y); + } + + void + Println(const char *s) + { + tft.println(s); + } +} \ No newline at end of file diff --git a/stage2/src/main.cc b/stage2/src/main.cc index 758aef2..76b9b27 100644 --- a/stage2/src/main.cc +++ b/stage2/src/main.cc @@ -2,15 +2,9 @@ #include #include -#include "colors.h" +#include "display.h" #include "neopixel.h" -#define TFT_CS 9 -#define TFT_DC 10 -#define BACKGROUND_COLOR 0xDEFB -#define FOREGROUND_COLOR BLACK - -Adafruit_ILI9341 tft(TFT_CS, TFT_DC); void @@ -19,19 +13,14 @@ setup() Serial.begin(115200); neopxl::start(); + tft::Setup; + tft::SetCursor(0, 8); - tft.begin(); - tft.setRotation(1); - tft.setTextSize(1); - tft.setCursor(0, 8); - - tft.fillScreen(BACKGROUND_COLOR); - tft.setTextColor(FOREGROUND_COLOR); - tft.println(" \\ (define square (x) (* x ))"); - tft.println(" \\ (square 3)"); - tft.println(" 9"); - tft.println(" \\ "); + tft::Println(" \\ (define square (x) (* x ))"); + tft::Println(" \\ (square 3)"); + tft::Println(" 9"); + tft::Println(" \\ "); }