aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@yeah.nah.nz>2021-02-27 22:09:06 +1300
committerDavid Phillips <david@yeah.nah.nz>2021-02-27 22:09:06 +1300
commit8f9cd223c74ce0b026ae3368701a443f62d7b3d5 (patch)
tree77d276b9904263d3c6833e213e677dbc0f16679a
parent27d6d2fc5a1647395a7a9074faf8362d6d0c358a (diff)
downloadaltimeter-8f9cd223c74ce0b026ae3368701a443f62d7b3d5.tar.xz
Migrate display to new peripheral model
-rw-r--r--altimeter.c6
-rw-r--r--display.h12
-rw-r--r--display_sim.c24
3 files changed, 29 insertions, 13 deletions
diff --git a/altimeter.c b/altimeter.c
index db45eb7..db18659 100644
--- a/altimeter.c
+++ b/altimeter.c
@@ -49,12 +49,14 @@ ISR(TIMER1_COMPA_vect)
int main(void)
{
+ struct display display;
struct barometer barometer;
struct timer timer;
/* Initialise display before enabling interrupts */
- display_init();
- display_clear();
+ get_system_display(&display);
+ display.init();
+ display.clear();
/* get descriptors for system default peripherals */
get_system_barometer(&barometer);
diff --git a/display.h b/display.h
index 771323c..ab8c078 100644
--- a/display.h
+++ b/display.h
@@ -8,7 +8,11 @@
#define C_IDLE (3)
#define C_ASC (4)
-void display_clear(void);
-void display_init(void);
-void display_write(const char *text);
-void display_set_cursor(int x, int y);
+struct display {
+ void (*clear)(void);
+ void (*init)(void);
+ void (*write)(const char *text);
+ void (*set_cursor)(int x, int y);
+};
+
+void get_system_display(struct display *);
diff --git a/display_sim.c b/display_sim.c
index c87329e..93e62c4 100644
--- a/display_sim.c
+++ b/display_sim.c
@@ -63,7 +63,7 @@ static FILE uart_out = FDEV_SETUP_STREAM(uart_putc, NULL, _FDEV_SETUP_WRITE);
/* internal function to dump the display contents to stdout, since there
* is no background thread for doing this constantly */
-void display_display(void)
+static void full_display(void)
{
int y = 0;
printf("\033[6A"); // hack: raw ANSI escape sequence to move up 6
@@ -74,7 +74,9 @@ void display_display(void)
printf("`--------------------'\n");
}
-void display_clear(void)
+/**/
+
+static void display_clear(void)
{
int x = 0;
int y = 0;
@@ -85,10 +87,10 @@ void display_clear(void)
display[y][x] = '\0';
}
- display_display();
+ full_display();
}
-void display_init(void)
+static void display_init(void)
{
uart_init();
/* FIXME hack: stdout not guaranteed to be assignable */
@@ -98,7 +100,7 @@ void display_init(void)
cursor_x = cursor_y = 0;
}
-void display_write(const char *text)
+static void display_write(const char *text)
{
char c = '\0';
while (cursor_x < LCD_WIDTH && *text) {
@@ -108,11 +110,19 @@ void display_write(const char *text)
c = '_';
display[cursor_y][cursor_x++] = c;
}
- display_display();
+ full_display();
}
-void display_set_cursor(int x, int y)
+static void display_set_cursor(int x, int y)
{
cursor_x = x;
cursor_y = y;
}
+
+void get_system_display(struct display *display)
+{
+ display->init = display_init;
+ display->clear = display_clear;
+ display->write = display_write;
+ display->set_cursor = display_set_cursor;
+}