split out display code

This commit is contained in:
Kyle Isom 2023-10-01 16:47:39 -07:00
parent 21ac50c94a
commit c30e469df9
4 changed files with 71 additions and 29 deletions

View File

@ -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

26
stage2/include/display.h Normal file
View File

@ -0,0 +1,26 @@
#pragma once
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <cstdint>
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);
}

38
stage2/src/display.cc Normal file
View File

@ -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);
}
}

View File

@ -2,15 +2,9 @@
#include <Adafruit_ILI9341.h>
#include <Fonts/FreeSans12pt7b.h>
#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(" \\ ");
}