summaryrefslogtreecommitdiff
path: root/dali.c
diff options
context:
space:
mode:
Diffstat (limited to 'dali.c')
-rw-r--r--dali.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/dali.c b/dali.c
index 5b9d25d..83007a3 100644
--- a/dali.c
+++ b/dali.c
@@ -1,9 +1,17 @@
+/* invalid command, used as default/do-nothing value
+ * 101CCCCX == special commands, X must be 1.
+ * X is 0 below => invalid
+ */
+#define DALI_INVALID 0xa000
+
static uint16_t dali_word, dali_sendq;
static uint8_t dali_subctr, dali_state, dali_bit;
static uint8_t dali_prevpin;
enum dali_state {
DALI_IDLE = 0,
+ DALI_TX_SPACE,
+
DALI_TX_STARTBIT1,
DALI_TX_STARTBIT2,
@@ -22,7 +30,7 @@ ISR(TIMER0_COMPA_vect)
TCNT0 = 0; /* CTC mode didn't work, CBA to debug */
data = (PIND >> D_DALII) & 1;
- if (dali_state == DALI_IDLE && data) {
+ if (dali_state <= DALI_TX_SPACE && data) {
dali_state = DALI_RX_LEFT;
dali_subctr = 4;
dali_word = 1;
@@ -48,6 +56,18 @@ ISR(TIMER0_COMPA_vect)
switch (dali_state) {
/* idle */
case DALI_IDLE:
+ if (dali_sendq != DALI_INVALID) {
+ dali_word = dali_sendq;
+ dali_sendq = DALI_INVALID;
+ dali_state = DALI_TX_STARTBIT1;
+ }
+ return;
+
+ case DALI_TX_SPACE:
+ /* 12 ms inter-command spacing */
+ if (dali_bit > 28)
+ dali_state = DALI_IDLE;
+ dali_bit++;
return;
/* write */
@@ -109,6 +129,19 @@ ISR(TIMER0_COMPA_vect)
}
}
+static void dali_send(uint16_t word)
+{
+ cli();
+ dali_sendq = word;
+ sei();
+}
+
+static bool dali_queue_busy(void)
+{
+ asm volatile ("" : : : "memory");
+ return dali_sendq != DALI_INVALID;
+}
+
static void dali_init(void)
{
PORTD |= (1 << D_DALII);