From d6d6007e62fd3df78b7877353d6796a9312cebf5 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Wed, 4 Jan 2023 08:48:45 +0100 Subject: [PATCH] Cleaned up display code, and re-combined control code. --- build.d | 6 +++++- src/display.c | 33 ++++++++++++++++++++++++--------- src/display.h | 22 ++++++++-------------- src/gympal.c | 14 +++++++------- 4 files changed, 44 insertions(+), 31 deletions(-) diff --git a/build.d b/build.d index be2efd1..e7311bc 100755 --- a/build.d +++ b/build.d @@ -83,16 +83,20 @@ int flashCommand(string[] args) { } int build(bool force = false) { + import std.datetime.stopwatch; if (!exists(BUILD_DIR)) mkdir(BUILD_DIR); string[] sources = findFiles(SOURCE_DIR, ".c"); string[] objects; objects.reserve(sources.length); + StopWatch sw = StopWatch(AutoStart.yes); foreach (source; sources) { objects ~= compileSourceToObject(source, force); } string elfFile = linkObjects(objects); string hexFile = copyToHex(elfFile); - writefln!"Built %s"(hexFile); + sw.stop(); + ulong durationMillis = sw.peek().total!"msecs"; + writefln!"Built %s in %d ms."(hexFile, durationMillis); runOrQuit("avr-size " ~ hexFile); return 0; } diff --git a/src/display.c b/src/display.c index dade3dd..2451c90 100644 --- a/src/display.c +++ b/src/display.c @@ -1,18 +1,33 @@ #include "display.h" -struct st7735 lcd; +struct signal cs = { .ddr = &DDRB, .port = &PORTB, .pin = 2 }; +// Back Light +struct signal bl = { .ddr = &DDRB, .port = &PORTB, .pin = 1 }; +// Data / Command +struct signal dc = { .ddr = &DDRB, .port = &PORTB, .pin = 0 }; +// Reset +struct signal rs = { .ddr = &DDRD, .port = &PORTD, .pin = 7 }; +// LCD struct +struct st7735 lcd = { .cs = &cs, .bl = &bl, .dc = &dc, .rs = &rs }; void display_init() { - ST7735_Init (&display_lcd); - ST7735_CommandSend (&display_lcd, MADCTL); - ST7735_Data8BitsSend (&display_lcd, 0x00); - ST7735_ClearScreen (&display_lcd, BLACK); - ST7735_SetPosition (5, 10); - ST7735_DrawString (&display_lcd, "Testing", WHITE, X1); + ST7735_Init(&lcd); + + // Set the display as vertical (top is the wired side). + ST7735_CommandSend(&lcd, MADCTL); + ST7735_Data8BitsSend(&lcd, 0x00); + + ST7735_ClearScreen(&lcd, WHITE); + ST7735_SetPosition(1, 1); + ST7735_DrawString(&lcd, "Gympal", BLACK, X1); +} + +struct st7735* display_get_lcd() { + return &lcd; } void display_show_str(char* str) { - ST7735_ClearScreen(&display_lcd, BLACK); + ST7735_ClearScreen(&lcd, BLACK); ST7735_SetPosition(5, 10); - ST7735_DrawString(&display_lcd, str, WHITE, X1); + ST7735_DrawString(&lcd, str, WHITE, X1); } \ No newline at end of file diff --git a/src/display.h b/src/display.h index 5045832..2505322 100644 --- a/src/display.h +++ b/src/display.h @@ -1,27 +1,21 @@ +/** + * @file display.h + * @author Andrew Lalis (andrewlalisofficial@gmail.com) + * @brief A wrapper around the hardware driver for the Gympal display which + * offers more abstract functions for controlling the state of the display. + */ #ifndef DISPLAY_H #define DISPLAY_H #include "st7735.h" -// A wrapper around the ST7735 library, which handles all of the gympal-specific display code. - -// Internal IO definition needed by the st7735 library. -// Chip Select -struct signal cs = { .ddr = &DDRB, .port = &PORTB, .pin = 2 }; -// Back Light -struct signal bl = { .ddr = &DDRB, .port = &PORTB, .pin = 1 }; -// Data / Command -struct signal dc = { .ddr = &DDRB, .port = &PORTB, .pin = 0 }; -// Reset -struct signal rs = { .ddr = &DDRD, .port = &PORTD, .pin = 7 }; -// LCD struct -struct st7735 display_lcd = { .cs = &cs, .bl = &bl, .dc = &dc, .rs = &rs }; - /** * @brief Initializes the display. */ void display_init(); +struct st7735* display_get_lcd(); + void display_show_str(char* str); #endif \ No newline at end of file diff --git a/src/gympal.c b/src/gympal.c index ceedfb4..e0d11c6 100644 --- a/src/gympal.c +++ b/src/gympal.c @@ -7,12 +7,12 @@ int main() { display_init(); ctl_init(); - while (1) { - if (ctl_isButtonAPressed()) { - display_show_str("button A"); - } else { - display_show_str("Not button A"); - } - } + // while (1) { + // if (ctl_isButtonAPressed()) { + // display_show_str("button A"); + // } else { + // display_show_str("Not button A"); + // } + // } return 0; } \ No newline at end of file