summaryrefslogtreecommitdiff
path: root/lightctrl.c
diff options
context:
space:
mode:
Diffstat (limited to 'lightctrl.c')
-rw-r--r--lightctrl.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/lightctrl.c b/lightctrl.c
new file mode 100644
index 0000000..c36f035
--- /dev/null
+++ b/lightctrl.c
@@ -0,0 +1,85 @@
+#define F_CPU 8000000
+#include <stdint.h>
+#include <stdbool.h>
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <avr/pgmspace.h>
+#include <util/delay.h>
+
+const uint8_t __signature[3] __attribute__((section (".signature"), used)) =
+ { SIGNATURE_2, SIGNATURE_1, SIGNATURE_0 };
+
+#define B_SCK 5
+#define B_MISO 4
+#define B_MOSI 3
+#define B_SS 2
+
+#define D_TXD 1
+#define D_DALII 3
+#define D_DALIO 4
+#define D_LED1 5
+#define D_LED2 6
+#define D_TAST 7
+
+#include "uart.c"
+#include "dali2.c"
+#include "dali_ctl.c"
+#include "dim.c"
+#include "can.c"
+
+int main(void)
+{
+ DDRD |= (1 << D_LED1) | (1 << D_LED2 ) | (1 << D_TXD) | (1 << D_DALIO);
+ PORTD |= (1 << D_LED1) | (1 << D_TAST);
+ PORTD &= ~(1 << D_LED1);
+
+ uart_init();
+ can_preinit();
+ dali_init();
+ dim_init();
+
+ sei();
+ uart_puts("\ninit done\n");
+
+ can_init();
+ can_CANSTAT();
+
+ dali_search();
+
+ uint8_t ctr = 0;
+ while (1) {
+ if (canint) {
+ canint = false;
+ can_int();
+ }
+ _delay_ms(5);
+ do_tick();
+
+ ctr++;
+ if (ctr % 64 == 0) {
+ dali_send(0xffa0);
+ if (dali_rx_avail) {
+ uart_puts("ll ");
+ uart_puthex(dali_rx);
+ uart_puts("\n");
+ } else
+ uart_puts("ll noans\n");
+ }
+
+ if (ctr == 255) {
+ uart_puts("dali stats: ");
+ uart_puthex16(dalistat_rxok);
+ uart_puts(" ok ");
+ uart_puthex16(dalistat_falsestart);
+ uart_puts(" f-start ");
+ uart_puthex16(dalistat_noise);
+ uart_puts(" noise ");
+ uart_puthex16(dalistat_manchester);
+ uart_puts(" mch-err\n");
+ }
+ }
+}
+
+void __do_copy_data(void) __attribute__((naked, section (".init4"), used));
+void __do_copy_data(void) { }
+