Cleaned up display code, and re-combined control code.
This commit is contained in:
parent
d041658da9
commit
d6d6007e62
6
build.d
6
build.d
|
@ -83,16 +83,20 @@ int flashCommand(string[] args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int build(bool force = false) {
|
int build(bool force = false) {
|
||||||
|
import std.datetime.stopwatch;
|
||||||
if (!exists(BUILD_DIR)) mkdir(BUILD_DIR);
|
if (!exists(BUILD_DIR)) mkdir(BUILD_DIR);
|
||||||
string[] sources = findFiles(SOURCE_DIR, ".c");
|
string[] sources = findFiles(SOURCE_DIR, ".c");
|
||||||
string[] objects;
|
string[] objects;
|
||||||
objects.reserve(sources.length);
|
objects.reserve(sources.length);
|
||||||
|
StopWatch sw = StopWatch(AutoStart.yes);
|
||||||
foreach (source; sources) {
|
foreach (source; sources) {
|
||||||
objects ~= compileSourceToObject(source, force);
|
objects ~= compileSourceToObject(source, force);
|
||||||
}
|
}
|
||||||
string elfFile = linkObjects(objects);
|
string elfFile = linkObjects(objects);
|
||||||
string hexFile = copyToHex(elfFile);
|
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);
|
runOrQuit("avr-size " ~ hexFile);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,33 @@
|
||||||
#include "display.h"
|
#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() {
|
void display_init() {
|
||||||
ST7735_Init (&display_lcd);
|
ST7735_Init(&lcd);
|
||||||
ST7735_CommandSend (&display_lcd, MADCTL);
|
|
||||||
ST7735_Data8BitsSend (&display_lcd, 0x00);
|
// Set the display as vertical (top is the wired side).
|
||||||
ST7735_ClearScreen (&display_lcd, BLACK);
|
ST7735_CommandSend(&lcd, MADCTL);
|
||||||
ST7735_SetPosition (5, 10);
|
ST7735_Data8BitsSend(&lcd, 0x00);
|
||||||
ST7735_DrawString (&display_lcd, "Testing", WHITE, X1);
|
|
||||||
|
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) {
|
void display_show_str(char* str) {
|
||||||
ST7735_ClearScreen(&display_lcd, BLACK);
|
ST7735_ClearScreen(&lcd, BLACK);
|
||||||
ST7735_SetPosition(5, 10);
|
ST7735_SetPosition(5, 10);
|
||||||
ST7735_DrawString(&display_lcd, str, WHITE, X1);
|
ST7735_DrawString(&lcd, str, WHITE, X1);
|
||||||
}
|
}
|
|
@ -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
|
#ifndef DISPLAY_H
|
||||||
#define DISPLAY_H
|
#define DISPLAY_H
|
||||||
|
|
||||||
#include "st7735.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.
|
* @brief Initializes the display.
|
||||||
*/
|
*/
|
||||||
void display_init();
|
void display_init();
|
||||||
|
|
||||||
|
struct st7735* display_get_lcd();
|
||||||
|
|
||||||
void display_show_str(char* str);
|
void display_show_str(char* str);
|
||||||
|
|
||||||
#endif
|
#endif
|
14
src/gympal.c
14
src/gympal.c
|
@ -7,12 +7,12 @@
|
||||||
int main() {
|
int main() {
|
||||||
display_init();
|
display_init();
|
||||||
ctl_init();
|
ctl_init();
|
||||||
while (1) {
|
// while (1) {
|
||||||
if (ctl_isButtonAPressed()) {
|
// if (ctl_isButtonAPressed()) {
|
||||||
display_show_str("button A");
|
// display_show_str("button A");
|
||||||
} else {
|
// } else {
|
||||||
display_show_str("Not button A");
|
// display_show_str("Not button A");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue