summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2022-01-03 20:40:52 +0100
committerDaniel Friesel <derf@finalrewind.org>2022-01-03 20:40:52 +0100
commit19c0be347dcb62a76381c243beb1f0ff050211de (patch)
tree9a2698328f48b140e417f3c34cd09b6a184ec179
parentb78f595070a41037a7df04e103a959b6ad68a7bd (diff)
add preliminary arduino nano dmx driver
note that it disables stdout / kout support, as the ATMega328 only has one UART.
-rw-r--r--include/arch/arduino-nano/driver/dmx.h20
-rw-r--r--src/arch/arduino-nano/Kconfig9
-rw-r--r--src/arch/arduino-nano/Makefile.inc4
-rw-r--r--src/arch/arduino-nano/driver/dmx.cc52
-rw-r--r--src/driver/Kconfig2
5 files changed, 87 insertions, 0 deletions
diff --git a/include/arch/arduino-nano/driver/dmx.h b/include/arch/arduino-nano/driver/dmx.h
new file mode 100644
index 0000000..5822a0d
--- /dev/null
+++ b/include/arch/arduino-nano/driver/dmx.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2022 Daniel Friesel
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+class DMX {
+ private:
+ DMX(const DMX &copy);
+
+ public:
+ unsigned char frames[16];
+
+ DMX() {}
+
+ void setup();
+ void write();
+};
+
+extern DMX dmx;
diff --git a/src/arch/arduino-nano/Kconfig b/src/arch/arduino-nano/Kconfig
index cd4a917..99f72aa 100644
--- a/src/arch/arduino-nano/Kconfig
+++ b/src/arch/arduino-nano/Kconfig
@@ -35,6 +35,15 @@ config arch_arduino_nano_driver_timer
bool "Timer with Interrupts"
select meta_driver_timer
+config arch_arduino_nano_driver_dmx
+bool "DMX"
+select meta_driver_dmx
+
+config arch_arduino_nano_driver_dmx_pin
+string "DMX Pin"
+default "pb5"
+depends on arch_arduino_nano_driver_dmx
+
choice arch_arduino_nano_cpu
bool "CPU Type"
diff --git a/src/arch/arduino-nano/Makefile.inc b/src/arch/arduino-nano/Makefile.inc
index c8221e4..1455105 100644
--- a/src/arch/arduino-nano/Makefile.inc
+++ b/src/arch/arduino-nano/Makefile.inc
@@ -88,6 +88,10 @@ ifdef CONFIG_arch_arduino_nano_driver_adc
CXX_TARGETS += src/arch/arduino-nano/driver/adc.cc
endif
+ifdef CONFIG_arch_arduino_nano_driver_dmx
+ CXX_TARGETS += src/arch/arduino-nano/driver/dmx.cc
+endif
+
ifdef CONFIG_arch_arduino_nano_driver_spi
CXX_TARGETS += src/arch/arduino-nano/driver/spi.cc
endif
diff --git a/src/arch/arduino-nano/driver/dmx.cc b/src/arch/arduino-nano/driver/dmx.cc
new file mode 100644
index 0000000..20a7332
--- /dev/null
+++ b/src/arch/arduino-nano/driver/dmx.cc
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2022 Daniel Friesel
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+#include <avr/io.h>
+#include "arch.h"
+#include "driver/dmx.h"
+#include "driver/gpio.h"
+
+#define BAUD 250000UL
+#include <util/setbaud.h>
+
+void DMX::setup()
+{
+ UBRR0H = UBRRH_VALUE;
+ UBRR0L = UBRRL_VALUE;
+
+#if USE_2X
+ UCSR0A |= _BV(U2X0);
+#else
+ UCSR0A &= ~_BV(U2X0);
+#endif
+
+ UCSR0B |= _BV(TXEN0);
+ UCSR0C = _BV(USBS0) | _BV(UCSZ01) | _BV(UCSZ00); // 8 bits
+}
+
+void DMX::write()
+{
+ // Disable UART for reset and mark signals
+ UCSR0B &= ~_BV(TXEN0);
+ gpio.output(GPIO::pd1, 0);
+ arch.delay_us(88); // break
+ gpio.output(GPIO::pd1, 1);
+ arch.delay_us(8);
+ UCSR0B |= _BV(TXEN0); // causes line to go high
+ for (uint8_t i = 0; i < 16; i++) {
+ while (!(UCSR0A & _BV(UDRE0)));
+ UDR0 = frames[i];
+ }
+ for (uint8_t i = 0; i < 241; i++) {
+ while (!(UCSR0A & _BV(UDRE0)));
+ UDR0 = 0;
+ }
+ for (uint8_t i = 0; i < 255; i++) {
+ while (!(UCSR0A & _BV(UDRE0)));
+ UDR0 = 0;
+ }
+}
+
+DMX dmx;
diff --git a/src/driver/Kconfig b/src/driver/Kconfig
index 2b8a8d5..5f544ac 100644
--- a/src/driver/Kconfig
+++ b/src/driver/Kconfig
@@ -6,6 +6,8 @@ config meta_driver_adc
bool
config meta_driver_counter
bool
+config meta_driver_dmx
+bool
config meta_driver_hardware_i2c
bool
config meta_driver_i2c