summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/arch/atmega2560/Kconfig3
-rw-r--r--src/arch/atmega2560/Makefile.inc12
-rw-r--r--src/arch/atmega2560/driver/dmx1.cc53
-rw-r--r--src/arch/atmega2560/driver/dmx2.cc53
-rw-r--r--src/arch/atmega2560/driver/dmx3.cc (renamed from src/arch/atmega2560/driver/dmx.cc)8
-rw-r--r--src/driver/Kconfig6
6 files changed, 129 insertions, 6 deletions
diff --git a/src/arch/atmega2560/Kconfig b/src/arch/atmega2560/Kconfig
index d93a808..a2814b0 100644
--- a/src/arch/atmega2560/Kconfig
+++ b/src/arch/atmega2560/Kconfig
@@ -7,18 +7,21 @@ bool "DMX1 Output on PD3 (D18)"
help
TX: PD3 (UART1) (D18)
select meta_driver_dmx
+select meta_driver_dmx1
config arch_atmega2560_driver_dmx2
bool "DMX2 Output on PH1 (D16)"
help
TX: PH1 (UART2) (D16)
select meta_driver_dmx
+select meta_driver_dmx2
config arch_atmega2560_driver_dmx3
bool "DMX3 Output on PJ1 (D14)"
help
TX: PJ1 (UART3) (D14)
select meta_driver_dmx
+select meta_driver_dmx3
config arch_atmega2560_driver_i2c
bool "I2C"
diff --git a/src/arch/atmega2560/Makefile.inc b/src/arch/atmega2560/Makefile.inc
index 39821da..6d82a1c 100644
--- a/src/arch/atmega2560/Makefile.inc
+++ b/src/arch/atmega2560/Makefile.inc
@@ -83,8 +83,16 @@ ifdef CONFIG_arch_atmega2560_driver_adc
CXX_TARGETS += src/arch/atmega2560/driver/adc.cc
endif
-ifdef CONFIG_arch_atmega2560_driver_dmx
- CXX_TARGETS += src/arch/atmega2560/driver/dmx.cc
+ifdef CONFIG_arch_atmega2560_driver_dmx1
+ CXX_TARGETS += src/arch/atmega2560/driver/dmx1.cc
+endif
+
+ifdef CONFIG_arch_atmega2560_driver_dmx2
+ CXX_TARGETS += src/arch/atmega2560/driver/dmx2.cc
+endif
+
+ifdef CONFIG_arch_atmega2560_driver_dmx3
+ CXX_TARGETS += src/arch/atmega2560/driver/dmx3.cc
endif
ifdef CONFIG_arch_atmega2560_driver_spi
diff --git a/src/arch/atmega2560/driver/dmx1.cc b/src/arch/atmega2560/driver/dmx1.cc
new file mode 100644
index 0000000..1724591
--- /dev/null
+++ b/src/arch/atmega2560/driver/dmx1.cc
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2022 Birte Kristina Friesel
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+#include <avr/io.h>
+#include "arch.h"
+#include "driver/dmx1.h"
+#include "driver/gpio.h"
+
+#undef BAUD
+#define BAUD 250000UL
+#include <util/setbaud.h>
+
+void DMX1::setup()
+{
+ UBRR1H = UBRRH_VALUE;
+ UBRR1L = UBRRL_VALUE;
+
+#if USE_2X
+ UCSR1A |= _BV(U2X1);
+#else
+ UCSR1A &= ~_BV(U2X1);
+#endif
+
+ UCSR1B = _BV(TXEN1);
+ UCSR1C = _BV(USBS1) | _BV(UCSZ11) | _BV(UCSZ10); // MSB first, 8 data bits, 2 stop bits, no parity
+}
+
+void DMX1::write()
+{
+ // Disable UART for reset and mark signals
+ UCSR1B &= ~_BV(TXEN1);
+ gpio.output(GPIO::pd3, 0);
+ arch.delay_us(88); // break / reset
+ gpio.output(GPIO::pd3, 1);
+ arch.delay_us(8); // mark
+ UCSR1B |= _BV(TXEN1); // causes line to go high
+ for (uint8_t i = 0; i < 32; i++) {
+ while (!(UCSR1A & _BV(UDRE1)));
+ UDR1 = frames[i];
+ }
+ for (uint8_t i = 0; i < 258 - num_frames; i++) {
+ while (!(UCSR1A & _BV(UDRE1)));
+ UDR1 = 0;
+ }
+ for (uint8_t i = 0; i < 255; i++) {
+ while (!(UCSR1A & _BV(UDRE1)));
+ UDR1 = 0;
+ }
+}
+
+DMX1 dmx1;
diff --git a/src/arch/atmega2560/driver/dmx2.cc b/src/arch/atmega2560/driver/dmx2.cc
new file mode 100644
index 0000000..9b5d35f
--- /dev/null
+++ b/src/arch/atmega2560/driver/dmx2.cc
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2022 Birte Kristina Friesel
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+#include <avr/io.h>
+#include "arch.h"
+#include "driver/dmx2.h"
+#include "driver/gpio.h"
+
+#undef BAUD
+#define BAUD 250000UL
+#include <util/setbaud.h>
+
+void DMX2::setup()
+{
+ UBRR2H = UBRRH_VALUE;
+ UBRR2L = UBRRL_VALUE;
+
+#if USE_2X
+ UCSR2A |= _BV(U2X2);
+#else
+ UCSR2A &= ~_BV(U2X2);
+#endif
+
+ UCSR2B = _BV(TXEN2);
+ UCSR2C = _BV(USBS2) | _BV(UCSZ21) | _BV(UCSZ20); // MSB first, 8 data bits, 2 stop bits, no parity
+}
+
+void DMX2::write()
+{
+ // Disable UART for reset and mark signals
+ UCSR2B &= ~_BV(TXEN2);
+ gpio.output(GPIO::ph1, 0);
+ arch.delay_us(88); // break / reset
+ gpio.output(GPIO::ph1, 1);
+ arch.delay_us(8); // mark
+ UCSR2B |= _BV(TXEN2); // causes line to go high
+ for (uint8_t i = 0; i < 32; i++) {
+ while (!(UCSR2A & _BV(UDRE2)));
+ UDR2 = frames[i];
+ }
+ for (uint8_t i = 0; i < 258 - num_frames; i++) {
+ while (!(UCSR2A & _BV(UDRE2)));
+ UDR2 = 0;
+ }
+ for (uint8_t i = 0; i < 255; i++) {
+ while (!(UCSR2A & _BV(UDRE2)));
+ UDR2 = 0;
+ }
+}
+
+DMX2 dmx2;
diff --git a/src/arch/atmega2560/driver/dmx.cc b/src/arch/atmega2560/driver/dmx3.cc
index 894ef99..0f6db4e 100644
--- a/src/arch/atmega2560/driver/dmx.cc
+++ b/src/arch/atmega2560/driver/dmx3.cc
@@ -5,14 +5,14 @@
*/
#include <avr/io.h>
#include "arch.h"
-#include "driver/dmx.h"
+#include "driver/dmx3.h"
#include "driver/gpio.h"
#undef BAUD
#define BAUD 250000UL
#include <util/setbaud.h>
-void DMX::setup()
+void DMX3::setup()
{
UBRR3H = UBRRH_VALUE;
UBRR3L = UBRRL_VALUE;
@@ -27,7 +27,7 @@ void DMX::setup()
UCSR3C = _BV(USBS3) | _BV(UCSZ31) | _BV(UCSZ30); // MSB first, 8 data bits, 2 stop bits, no parity
}
-void DMX::write()
+void DMX3::write()
{
// Disable UART for reset and mark signals
UCSR3B &= ~_BV(TXEN3);
@@ -50,4 +50,4 @@ void DMX::write()
}
}
-DMX dmx;
+DMX3 dmx3;
diff --git a/src/driver/Kconfig b/src/driver/Kconfig
index 2d9f16b..b71b963 100644
--- a/src/driver/Kconfig
+++ b/src/driver/Kconfig
@@ -8,6 +8,12 @@ config meta_driver_counter
bool
config meta_driver_dmx
bool
+config meta_driver_dmx1
+bool
+config meta_driver_dmx2
+bool
+config meta_driver_dmx3
+bool
config meta_driver_hardware_i2c
bool
config meta_driver_i2c