summaryrefslogtreecommitdiff
path: root/src/display.cc
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2016-01-15 16:58:10 +0100
committerDaniel Friesel <derf@finalrewind.org>2016-01-15 16:58:10 +0100
commitec9cfa2de32efc03355d420159025da8266a0d94 (patch)
tree1d8d66dda7a196f877d5a23a0f92c0ee265de3c3 /src/display.cc
parentab36943fa7276d20f8b6e14ae2352db0a3daec04 (diff)
move display and system into separate files
Diffstat (limited to 'src/display.cc')
-rw-r--r--src/display.cc64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/display.cc b/src/display.cc
new file mode 100644
index 0000000..e06f271
--- /dev/null
+++ b/src/display.cc
@@ -0,0 +1,64 @@
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <avr/wdt.h>
+#include <util/delay.h>
+#include <stdlib.h>
+
+#include "display.h"
+
+Display display;
+
+extern volatile uint8_t disp[8];
+
+void Display::turn_off()
+{
+ TIMSK0 &= ~_BV(TOIE0);
+ PORTB = 0;
+ PORTD = 0;
+}
+
+void Display::turn_on()
+{
+ TIMSK0 |= _BV(TOIE0);
+}
+
+/*
+ * Draws a single display column. This function should be called at least once
+ * per millisecond.
+ *
+ * Current configuration:
+ * Called every 256 microseconds. The whole display is refreshed every 2048us,
+ * giving a refresh rate of ~500Hz
+ */
+ISR(TIMER0_OVF_vect)
+{
+ static uint8_t active_col = 0;
+ static uint16_t scroll = 0;
+ static uint8_t disp_offset = 0;
+
+ static uint8_t disp_buf[8];
+
+ uint8_t i;
+
+ if (++scroll == 512) {
+ scroll = 0;
+ if (++disp_offset == sizeof(disp)) {
+ disp_offset = 0;
+ }
+
+ for (i = 0; i < 8; i++) {
+ disp_buf[i] = ~disp[(disp_offset + i) % sizeof(disp)];
+ }
+ }
+
+ /*
+ * To avoid flickering, do not put any code (or expensive index
+ * calculations) between the following three lines.
+ */
+ PORTB = 0;
+ PORTD = disp_buf[active_col];
+ PORTB = _BV(active_col);
+
+ if (++active_col == 8)
+ active_col = 0;
+}