summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2022-01-16 18:34:30 +0100
committerDaniel Friesel <derf@finalrewind.org>2022-01-16 18:34:30 +0100
commit84f2392ec92f63963912f18726d16e87d0d0925f (patch)
tree4a6517742e5c629e8c1614621c40dab58f6a6d43
parent7205332a95fad57d5f68885a3834319ecd48e457 (diff)
Add UART→DMX app
-rw-r--r--src/app/uart-to-dmx/Kconfig6
-rw-r--r--src/app/uart-to-dmx/Makefile.inc9
-rw-r--r--src/app/uart-to-dmx/main.cc76
3 files changed, 91 insertions, 0 deletions
diff --git a/src/app/uart-to-dmx/Kconfig b/src/app/uart-to-dmx/Kconfig
new file mode 100644
index 0000000..6fec582
--- /dev/null
+++ b/src/app/uart-to-dmx/Kconfig
@@ -0,0 +1,6 @@
+# Copyright 2020 Daniel Friesel
+#
+# SPDX-License-Identifier: CC0-1.0
+
+prompt "UART to DMX gateway"
+depends on !loop && !wakeup && meta_driver_dmx && meta_driver_stdin && meta_driver_timer
diff --git a/src/app/uart-to-dmx/Makefile.inc b/src/app/uart-to-dmx/Makefile.inc
new file mode 100644
index 0000000..0eea52a
--- /dev/null
+++ b/src/app/uart-to-dmx/Makefile.inc
@@ -0,0 +1,9 @@
+# vim:ft=make
+#
+# Copyright 2020 Daniel Friesel
+#
+# SPDX-License-Identifier: CC0-1.0
+
+ifdef app
+ loop = 1
+endif
diff --git a/src/app/uart-to-dmx/main.cc b/src/app/uart-to-dmx/main.cc
new file mode 100644
index 0000000..738173e
--- /dev/null
+++ b/src/app/uart-to-dmx/main.cc
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2022 Daniel Friesel
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+#include "arch.h"
+#include "driver/gpio.h"
+#include "driver/stdout.h"
+#include "driver/stdin.h"
+#include "driver/uptime.h"
+#include "driver/dmx.h"
+
+#include "driver/timer.h"
+volatile unsigned char timer_done = 0;
+char buffer[24];
+unsigned char buf_pos = 0;
+
+void input_to_dmx(void)
+{
+ unsigned char num = 0;
+ unsigned char dmx_frame = 1;
+ for (unsigned int i = 0; i < buf_pos; i++) {
+ if ((buffer[i] >= '0') && (buffer[i] <= '9')) {
+ num *= 10;
+ num += buffer[i] - '0';
+ }
+ else {
+ dmx.frames[dmx_frame++] = num;
+ num = 0;
+ }
+ }
+}
+
+int main(void)
+{
+ arch.setup();
+ gpio.setup();
+ kout.setup();
+ kin.setup();
+
+ for (unsigned char i = 0; i < 16; i++) {
+ dmx.frames[i] = 0;
+ }
+
+ dmx.setup();
+ timer.setup_hz(15);
+ timer.start(1);
+
+ while (1) {
+ while (!timer_done) {
+ arch.idle();
+ while (kin.hasKey() && (buf_pos < 24)) {
+ char key = kin.getKey();
+ buffer[buf_pos++] = key;
+ kout << key << flush;
+
+ if ((key == '\n') || (key == '\r')) {
+ input_to_dmx();
+ kout << endl << "DMX: " << dmx.frames[1] << " " << dmx.frames[2] << " " << dmx.frames[3] << " " << dmx.frames[4] << endl << "> ";
+ buf_pos = 0;
+ }
+ }
+ }
+ timer.stop();
+ timer_done = 0;
+ timer.start(1);
+
+ dmx.write();
+ }
+
+ return 0;
+}
+
+ON_TIMER_INTERRUPT_head
+ timer_done = 1;
+ON_TIMER_INTERRUPT_tail